/
object-compat.js
3012 lines (2699 loc) · 78.6 KB
/
object-compat.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @fileOverview <title>Basic Object Library</title>
* @file $Id$
*
* @author (C) 2004-2014 Thomas Lahn <js@PointedEars.de>
*
* @partof PointedEars' JavaScript Extensions (JSX)
*
* JSX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* JSX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with JSX. If not, see <http://www.gnu.org/licenses/>.
*/
if (typeof jsx == "undefined")
{
/**
* @namespace
*/
var jsx = new Object();
}
/* allows for de.pointedears.jsx.object */
if (typeof de == "undefined")
{
/**
* @namespace
*/
var de = {};
}
if (typeof de.pointedears == "undefined")
{
/**
* @namespace
*/
de.pointedears = {};
}
/**
* @namespace
*/
de.pointedears.jsx = jsx;
/**
* Reference to the ECMAScript Global Object
* @type Global
*/
jsx.global = this;
/*
* NOTE: Cannot use jsx.object.extend() for the following
* because values have not been defined yet!
*
* TODO: Should syntactic sugar be provided to work around
* this issue? See Function.prototype.extend().
*/
jsx.MSG_INFO = "info";
jsx.MSG_WARN = "warn";
jsx.MSG_ERROR = "error";
jsx.MSG_DEBUG = "debug";
if (typeof jsx.options == "undefined")
{
/**
* @namespace
*/
jsx.options = new Object();
}
if (typeof jsx.options.emulate == "undefined")
{
/**
* If <code>false</code> missing language features are not emulated.
* The default is <code>true</code>.
* <p>
* WARNING: JSX features may depend on emulation; intended for
* testing only.
* </p>
* @type boolean
*/
jsx.options.emulate = true;
}
/**
* @namespace
*/
jsx.object = new Object();
/**
* @version
*/
jsx.object.version = "$Revision$ ($Date$)";
jsx.object.copyright = "Copyright \xA9 2004-2014";
jsx.object.author = "Thomas Lahn";
jsx.object.email = "js@PointedEars.de";
jsx.object.path = "http://PointedEars.de/scripts/";
/**
* @type number
* Used by {@link jsx.object#extend()} to overwrite existing
* properties.
*/
jsx.object.ADD_OVERWRITE = 1;
/**
* @type number
* Used by {@link jsx.object#extend()} and {@link jsx.object#clone()}
* to make a shallow copy of all enumerable properties (default).
*/
jsx.object.COPY_ENUM = 0;
/**
* @type number
* Used by {@link jsx.object#extend()} and {@link jsx.object#clone()}
* to make a deep copy of all enumerable properties.
*/
jsx.object.COPY_ENUM_DEEP = 2;
/**
* @type number
* Used by {@link jsx.object#extend()} and {@link jsx.object#clone()}
* to copy a property by inheritance.
*/
jsx.object.COPY_INHERIT = 4;
/**
* Determines whether an object is, or several objects are,
* likely to be callable.
*
* @author (C) 2003-2010 <a href="mailto:js@PointedEars.de">Thomas Lahn</a>
* @memberOf jsx.object
* @param {Object} obj
* Object which should be tested for a method, or checked
* for being a method if no further arguments are provided.
* <p>
* <em>NOTE: If you pass a primitive value for this argument,
* the properties of the object created from that value are considered.
* In particular, if you pass a string value containing
* a <i>MemberExpression</i>, the properties of the corresponding
* <code>String</code> instance are considered, not of the object that
* the <i>MemberExpression</i> might refer to. If you need to use such
* a string to refer to an object (e.g., if you do not know whether it
* is safe to refer to the object), use the return value of
* {@link jsx#tryThis jsx.tryThis("<var>MemberExpression</var>")}
* as argument to this method instead.</em>
* </p>
* @param {string|Array} prop (optional)
* Path of the property to be determined a method, i.e. a reference to
* a callable object assigned as property of another object.
* Use a string argument for each component of the path, e.g.
* the argument list <code>(o, "foo", "bar")</code> for testing whether
* <code>o.foo.bar</code> is a method.
* If the last argument is an {@link Array}, all elements of
* this array are used for property names; e.g.
* <code>(o, "foo", ["bar", "baz"])</code>. This allows for testing
* several properties of the same object with one call.
* @return {boolean}
* <code>true</code> if all arguments refer to methods,
* <code>false</code> otherwise.
* @see jsx.object#isMethodType()
*/
function jsx_object_isMethod (obj, prop)
{
var len = arguments.length;
if (len < 1)
{
jsx.throwThis("jsx.InvalidArgumentError",
["Not enough arguments", "saw 0", "(obj : Object[, prop : string])"]);
return false;
}
var rxUnknown = new RegExp("^\\s*unknown\\s*$", "i");
var rxNativeMethod = new RegExp("^\\s*function\\s*$", "i");
var rxMethod = new RegExp("^\\s*(function|object)\\s*$", "i");
/*
* Determine if we were called jsx.object.areNativeMethods;
*/
var me = jsx_object_isMethod;
var checkNative = (this == jsx_object_isNativeMethod);
var t = typeof obj;
/* When no property names are provided, test if the first argument is a method */
if (len < 2)
{
if (checkNative)
{
return t == "function" && obj && true || false;
}
return rxUnknown.test(t) || rxMethod.test(t) && obj && true || false;
}
/* otherwise the first argument must refer to a suitable object */
if (rxUnknown.test(t) || !obj)
{
return false;
}
for (var i = 1; i < len; i++)
{
prop = arguments[i];
/* NOTE: Handle null _and_ undefined */
if (prop == null)
{
return false;
}
var isLastSeg = (i == len - 1);
if (isLastSeg)
{
if (typeof prop.valueOf() == "string")
{
prop = [prop];
}
var aProp = prop;
}
for (var j = (isLastSeg && aProp.length || 1); j--;)
{
if (isLastSeg)
{
prop = aProp[j];
}
t = typeof obj[prop];
/*
* NOTE: Test for "unknown" required in any case;
* this order speeds up evaluation
*/
if (rxUnknown.test(t) || (rxMethod.test(t) && obj[prop]))
{
if (i < len - 1)
{
obj = obj[prop];
if (!(rxUnknown.test(typeof obj) || obj))
{
return false;
}
}
else if (checkNative && !rxNativeMethod.test(t))
{
return false;
}
}
else
{
return false;
}
}
}
return true;
}
jsx.object.isMethod = jsx_object_isMethod;
jsx.object.areMethods =
jsx.object.isHostMethod = jsx.object.areHostMethods = jsx.object.isMethod;
// jsx.object.docURL = jsx.object.path + "object.htm";
/**
* Determines if the passed value could be the result of
* <code>typeof <var>callable</var></code>.
* <p>
* NOTE: This method has previously been provided by {@link types.js};
* optimizations in code reuse moved it here.
* </p>
* @param {string} s (optional)
* String to be determined a method type, i.e. "object" or "unknown" in
* MSHTML, "function" otherwise. The type must have been retrieved with
* the `typeof' operator. Note that this method may also return
* <code>true</code> if the value of the <code>typeof</code> operand is
* <code>null</code>; to be sure that the operand is a method reference,
* you have to && (AND)-combine the <code>isMethodType(...)</code>
* expression with the method reference identifier unless `typeof' yielded
* `unknown' for <var>s</var>.
* @return {boolean}
* <code>true</code> if <var>s</var> is a method type,
* <code>false</code> otherwise.
* @author
* (C) 2003-2008 Thomas Lahn <types.js@PointedEars.de>
* Distributed under the GNU GPL v3 and later.
* @partof http://pointedears.de/scripts/types.js
* @deprecated since version 0.1.5a.2009070204
* in favor of {@link jsx.object#isMethod(Object)}
*/
jsx.object.isMethodType = function (s) {
return /^\s*(function|object|unknown)\s*$/i.test(s);
};
// jsx.object.docURL = jsx.object.path + "object.htm";
/**
* Determines whether an object is, or several objects are,
* likely to be a native method.
*
* @author (C) 2011 <a href="mailto:js@PointedEars.de">Thomas Lahn</a>
* @param {Object} obj
* Object which should be tested for a method, or checked
* for being a method if no further arguments are provided.
* <p>
* <em>NOTE: If you pass a primitive value for this argument,
* the properties of the object created from that value are considered.
* In particular, if you pass a string value containing
* a <i>MemberExpression</i>, the properties of the corresponding
* <code>String</code> instance are considered, not of the object that
* the <i>MemberExpression</i> might refer to. If you need to use such
* a string to refer to an object (e.g., if you do not know whether it
* is safe to refer to the object), use the return value of
* {@link jsx#tryThis jsx.tryThis("<var>MemberExpression</var>")}
* as argument to this method instead.</em>
* </p>
* @param {string|Array} prop (optional)
* Path of the property to be determined a method, i.e. a reference to
* a callable object assigned as property of another object.
* Use a string argument for each component of the path, e.g.
* the argument list <code>(o, "foo", "bar")</code> for testing whether
* <code>o.foo.bar</code> is a method.
* If the last argument is an {@link Array}, all elements of
* this array are used for property names; e.g.
* <code>(o, "foo", ["bar", "baz"])</code>. This allows for testing
* several properties of the same object with one call.
* @return {boolean}
* <code>true</code> if all arguments refer to methods,
* <code>false</code> otherwise.
* @see jsx.object#isMethodType()
*/
function jsx_object_isNativeMethod (obj, prop)
{
/* NOTE: Thread-safe, argument-safe code reuse -- `this' is our ID */
var _isMethod = jsx_object_isMethod;
if (typeof _isMethod.apply != "function")
{
_isMethod.apply = Function_prototype_apply;
}
return _isMethod.apply(jsx_object_isNativeMethod, arguments);
}
jsx.object.isNativeMethod = jsx.object.areNativeMethods = jsx_object_isNativeMethod;
/**
* Prints debug messages to the script console.
*
* NOTE: This method has previously been provided by
* {@link debug.js}; optimizations in code reuse
* moved it here.
*
* @param {string} sMsg
* Message to be printed
* @param {string} sType = "log"
* Type of the message. Supported values include
* <code>"log"</code> (default), <code>"info"</code>, <code>"warn"</code>,
* and <code>"debug"</code>. If a script console does not support
* a message type, the default value is used.
* @return {boolean}
* <code>true</code> if it was possible to cause the message to be printed;
* <code>false</code> otherwise.
*/
function jsx_dmsg (sMsg, sType)
{
var _isMethod = jsx.object.isMethod;
var msgMap = new Object();
msgMap.data = new Object();
msgMap.data.info = "INFO";
msgMap.data.warn = "WARNING";
msgMap.data.debug = "DEBUG";
function msgMap_getString (s)
{
var data = this.data;
if (typeof data[s] != "undefined")
{
return data[s] + ": ";
}
return "";
}
msgMap.getString = msgMap_getString;
/* Firebug 0.4+ and others */
if (typeof console != "undefined")
{
if (!sType || !_isMethod(console, sType) && sType != "log")
{
sMsg = msgMap.getString(sType) + sMsg;
sType = "log";
}
if (sType != "info")
{
sMsg += "\n" + jsx.getStackTrace();
}
if (_isMethod(console, sType))
{
/* MSHTML's console methods do not implement call() */
Function.prototype.call.call(console[sType], console, sMsg);
return true;
}
}
else if (typeof opera != "undefined"
&& _isMethod(opera, "postError"))
{
opera.postError(msgMap.getString(sType) + sMsg);
return true;
}
return false;
}
jsx.dmsg = jsx_dmsg;
/**
* Issues an info message, if possible.
*
* @param {String} sMsg
* Message
* @see jsx#dmsg
*/
function jsx_info (sMsg)
{
return jsx.dmsg(sMsg, jsx.MSG_INFO);
}
jsx.info = jsx_info;
/**
* Issues a warning, if possible.
*
* @param {String} sMsg
* Message
* @see jsx#dmsg
*/
function jsx_warn (sMsg)
{
return jsx.dmsg(sMsg, jsx.MSG_WARN);
}
jsx.warn = jsx_warn;
/**
* Issues an error message, if possible.
*
* @param {String} sMsg
* Message
* @see jsx#dmsg
*/
function jsx_error (sMsg)
{
return jsx.dmsg(sMsg, jsx.MSG_ERROR);
};
jsx.error = jsx_error;
/**
* Determines if an object has a (non-inherited) property
*
* @param {Object} obj (optional)
* Object which property should be checked for existence.
* @param {string} sProperty
* Name of the property to check.
* @return {boolean}
* <code>true</code> if there is such a property;
* <code>false</code> otherwise.
*/
jsx.object._hasOwnProperty = function (obj, sProperty) {
if (arguments.length < 2 && obj)
{
sProperty = obj;
obj = this;
}
var proto;
return (jsx.object.isMethod(obj, "hasOwnProperty")
? obj.hasOwnProperty(sProperty)
: (typeof obj[sProperty] != "undefined"
&& ((typeof obj.constructor != "undefined"
&& (proto = obj.constructor.prototype)
&& typeof proto[sProperty] == "undefined")
|| (typeof obj.constructor == "undefined"))));
};
/**
* Returns the own enumerable properties of an object
*/
function jsx_object_getKeys (obj)
{
if (jsx.object.isNativeMethod(jsx.global.Object, "keys")
&& !Object.keys._emulated)
{
return Object.keys(obj);
}
var a = new Array();
var _hasOwnProperty = jsx.object._hasOwnProperty;
for (var p in obj)
{
if (_hasOwnProperty(obj, p))
{
a[a.length] = p;
}
}
return a;
}
jsx.object.getKeys = jsx_object_getKeys;
/**
* Creates a duplicate (clone) of an object
*
* @param {Object} oSource (optional)
* Object to be cloned. If omitted or <code>null</code>,
* the calling object is cloned.
* @param {Number} iLevel (optional)
* Use the {@link #COPY_ENUM jsx.object.COPY_*}
* properties to specify the level of cloning.
* The default is {@link #COPY_ENUM}.
* @return {Object}
* A reference to the clone.
*/
function jsx_object_clone (oSource, iLevel)
{
var
_jsx_object = jsx.object,
_COPY_ENUM = _jsx_object.COPY_ENUM,
_COPY_ENUM_DEEP = _jsx_object.COPY_ENUM_DEEP,
_COPY_INHERIT = _jsx_object.COPY_INHERIT;
function createTypedObject (oOriginal)
{
if (oOriginal.constructor)
{
return jsx_object_inheritFrom(oOriginal.constructor.prototype);
}
return new Object();
}
function createRecursiveCloner (o2, i, oSource, iLevel)
{
function f ()
{
o2[i] = me(oSource[i], iLevel);
}
return f;
}
function createCopier (o2, p, oSource)
{
function f ()
{
o2[p] = oSource[p];
}
return f;
}
if (typeof oSource == "number")
{
var tmp = oSource;
oSource = iLevel;
iLevel = tmp;
}
if (!oSource)
{
oSource = _jsx_object;
}
if (typeof iLevel == "undefined")
{
iLevel = _COPY_ENUM;
}
var me = jsx_object_clone;
if (!iLevel || (iLevel & _COPY_ENUM_DEEP))
{
/*
* NOTE: For objects, valueOf() only copies the object reference,
* so we are creating an instance that inherits from the
* original's prototype, if possible.
*/
var o2 = (typeof oSource == "object" && oSource)
? createTypedObject(oSource)
: oSource.valueOf();
/* if "var p in ..." does not copy the array elements */
if (_jsx_object.isArray(o2))
{
for (var i = oSource.length; i--;)
{
if (iLevel && typeof oSource[i] == "object" && null != oSource[i])
{
jsx.tryThis(createRecursiveCloner(o2, i, oSource, iLevel));
}
else
{
jsx.tryThis(createCopier(o2, i, oSource));
}
}
}
for (var p in oSource)
{
if (iLevel && typeof oSource[p] == "object" && null != oSource[p])
{
jsx.tryThis(createRecursiveCloner(o2, p, oSource, iLevel));
}
else
{
jsx.tryThis(createCopier(o2, p, oSource));
}
}
return o2;
}
if (iLevel & _COPY_INHERIT)
{
return jsx_object_inheritFrom(oSource);
}
return null;
}
jsx.object.clone = jsx_object_clone;
/**
* Adds/replaces properties of an object
*
* @param {Object} oTarget
* Target object whose properties should be set.
* @param {Object} oSource
* Object specifying the properties to be set.
* The name of each property serves as the name for the
* property of the target object, its value as the value
* of that property.
* @param {Number} iFlags = 0
* Flags for the modification, see {@link #ADD_OVERWRITE}
* and {@link #COPY_ENUM jsx.object.COPY_*}.
* @return {Object}
* The extended object
*/
function jsx_object_extend (oTarget, oSource, iFlags)
{
var
_jsx_object = jsx.object,
_getKeys = _jsx_object.getKeys,
_clone = _jsx_object.clone,
_ADD_OVERWRITE = _jsx_object.ADD_OVERWRITE,
_COPY_ENUM_DEEP = _jsx_object.COPY_ENUM_DEEP,
_COPY_INHERIT = _jsx_object.COPY_INHERIT;
if (typeof iFlags == "undefined")
{
iFlags = 0;
}
var cloneLevel = (iFlags & (_COPY_ENUM_DEEP | _COPY_INHERIT));
for (var i = 0, keys = _getKeys(oSource), len = keys.length;
i < len; ++i)
{
var p = keys[i];
if (typeof oTarget[p] == "undefined" || (iFlags & _ADD_OVERWRITE))
{
jsx.tryThis(function () {
oTarget[p] = cloneLevel
? _clone(oSource[p], cloneLevel)
: oSource[p];
oTarget[p]._userDefined = true;
});
}
}
return oTarget;
}
jsx.object.setProperties = jsx_object_extend;
jsx.object.extend = jsx_object_extend;
/**
* Defines getters and setters for the properties of an object, if possible.
*
* Uses {@link Object.prototype#__defineGetter__} and
* {@link Object.prototype#__defineSetter__} (JavaScript only) as fallback.
*
* @param {Object} oTarget
* The object for which properties getters and setters should be defined.
* @param {Object} oProperties
* Definition of the getters and setters for each property. Must be of
* the form
* <code><pre>{
* propertyName: {
* get: function () {…},
* set: function (newValue) {…}
* },
* …
* }
* </pre></code> as specified in the ECMAScript Language Specification,
* Edition 5 Final, section 15.2.3.7.
* @param {string} sContext (optional)
* The context in which the property definition was attempted.
* Included in the info message in case getters and setters could not be
* defined.
* @todo Depending on ES Matrix results, replace with user-defined
* Object.defineProperties() if the implementation does not provide it.
*/
function jsx_object_defineProperties (oTarget, oProperties, sContext)
{
function Object_defineProperties ()
{
Object.defineProperties(oTarget, oProperties);
}
function Object_defineProperties_emulation_try ()
{
for (var propertyName in oProperties)
{
var propertyDescriptor = oProperties[propertyName];
if (typeof propertyDescriptor.value != "undefined")
{
oTarget[propertyName] = propertyDescriptor.value;
}
/* NOTE: Allow specified values to fail */
if (typeof propertyDescriptor.get != "undefined")
{
oTarget.__defineGetter__(propertyName, propertyDescriptor.get);
}
if (typeof propertyDescriptor.set != "undefined")
{
oTarget.__defineSetter__(propertyName, propertyDescriptor.set);
}
}
}
function Object_defineProperties_emulation_failed ()
{
jsx.info((sContext ? sContext + ": " : "")
+ "Could not define special properties."
+ " Please use explicit getters and setters instead.");
}
function Object_defineProperties_emulation ()
{
jsx.tryThis(
Object_defineProperties_emulation_try,
Object_defineProperties_emulation_failed
);
}
jsx.tryThis(
Object_defineProperties,
Object_defineProperties_emulation
);
};
jsx.object.defineProperties = jsx_object_defineProperties;
/**
* Determines if a (non-inherited) property of an object is enumerable
* @param {Object} obj (optional)
* Object which property should be checked for enumerability.
* @param {string} sProperty
* Name of the property to check.
* @return {boolean}
* <code>true</code> if there is such a property;
* <code>false</code> otherwise.
*/
function jsx_object_propertyIsEnumerable (obj, sProperty)
{
if (arguments.length < 2 && obj)
{
sProperty = obj;
obj = this;
}
if (jsx.object.isMethod(obj, "propertyIsEnumerable"))
{
return obj.propertyIsEnumerable(sProperty);
}
var _hasOwnProperty = jsx.object._hasOwnProperty;
for (var propertyName in obj)
{
if (propertyName == name && _hasOwnProperty(obj, propertyName))
{
return true;
}
}
return false;
}
jsx.object._propertyIsEnumerable = jsx_object_propertyIsEnumerable;
/**
* Returns the name of an unused property for an object.
*
* @function
* @param {Object} obj
* @param {number} iLength
* Maximum property name length up to which an unused name
* is searched. The default is 256.
* @return {string}
* The name of a non-existing property of <code>o</code> if
* {@link Object#prototype.hasOwnProperty()} is supported, or
* the name of a property with value <code>undefined</code>
* if it is not supported; the empty string
* if there is no such property.
*/
function jsx_object_findNewProperty (obj, iLength)
{
var _hasOwnProperty = jsx.object._hasOwnProperty;
if (!obj)
{
obj = this;
}
if (arguments.length < 2)
{
iLength = 256;
}
else
{
iLength = parseInt(iLength, 10);
}
var newName = "";
while (newName.length < iLength)
{
for (var i = "a".charCodeAt(0), max = "z".charCodeAt(0); i <= max; ++i)
{
var ch = String.fromCharCode(i);
if (!_hasOwnProperty(obj, newName + ch + "_"))
{
return newName + ch + "_";
}
}
newName += "a";
}
return "";
};
jsx.object.findNewProperty = jsx_object_findNewProperty;
/**
* Determines if an object, or the objects it refers to,
* has an enumerable property with a certain value
*
* @param {Object} obj
* @param needle
* The value to be searched for
* @param {Object} params
* Search parameters. The following properties are supported:
* <table>
* <thead>
* <tr>
* <th>Property</th>
* <th>Type</th>
* <th>Meaning</th>
* </tr>
* </thead>
* <tbody>
* <tr>
* <th><code><var>exclude</var></code></th>
* <td><code>Array</code></td>
* <td>Names of the properties that should not be searched</td>
* </tr>
* <tr>
* <th><code><var>recursive</var></code></th>
* <td><code>boolean</code></td>
* <td>If a true-value, search recursively.</td>
* </tr>
* <tr>
* <th><code><var>strict</var></code></th>
* <td><code>boolean</code></td>
* <td>If a true-value, perform a strict comparison
* without type conversion.</td>
* </tr>
* </tbody>
* </table>
*/
jsx.object.hasPropertyValue =
function jsx_object_hasPropertyValue (obj, needle, params) {
for (var property in obj)
{
if (params && params.exclude && params.exclude.indexOf(property) > -1)
{
continue;
}
var propertyValue = obj[property];
if (params && params.recursive)
{
if (typeof propertyValue == "object" && propertyValue !== null)
{
if (jsx_object_hasPropertyValue(propertyValue, needle, params))
{
return true;
}
}
}
if (params && params.strict)
{
if (propertyValue === needle)
{
return true;
}
}
else
{
/* Switch operands because of JScript quirk */
if (needle == propertyValue)
{
return true;
}
}
}
return false;
};
/**
* Clears the handler for the proprietary <code>error</code> event.
*
* NOTE: This method has previously been provided by {@link debug.js};
* optimizations in code reuse moved it here.
*
* @return {boolean} <code>true</code>
*/
/*
* NOTE: Initialization must come before the initialization of
* setErrorHandler() as it is used in a closure there,
* see Message-ID <2152411.FhMhkbZ0Pk@PointedEars.de>
*/
jsx.clearErrorHandler = function () {
if (typeof window != "undefined")
{
/*
* debug.js 0.99.5.2006041101 BUGFIX:
* onerror is defined as a property of window, not of the Global Object
*/
window.onerror = null;
}
return true;
};
/**
* Sets the handler for the proprietary <code>error</code> event.
*
* NOTE: This method has previously been provided by {@link debug.js};
* and {@link types.js}; optimizations in code reuse moved it here.
*
* @function
*/
jsx.setErrorHandler = (function () {
var
jsx_object = jsx.object,
jsx_clearErrorHandler = jsx.clearErrorHandler;
/**
* @param {Callable} fHandler
* @return {boolean}
* <code>true</code> if the error handler could be assigned to
* successfully, <code>false</code> otherwise. Note that one reason
* for failure can be that an event handler is no longer supported
* by the UA's DOM due to efforts towards adherence to Web standards.
*/
return function (fHandler) {
/*
* NOTE: There is no deadlock here because even if `fHandler' is a string,
* `isMethod(fHandler)' will call `setErrorHandler()' without arguments;
* so fHandler in that call will be `undefined' and `setErrorHandler()'
* is not called again.
*/
if (!jsx_object.isMethod(fHandler))