OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 | 214 |
215 | 215 |
216 // ECMA-262 - 15.2.4.5 | 216 // ECMA-262 - 15.2.4.5 |
217 function ObjectHasOwnProperty(V) { | 217 function ObjectHasOwnProperty(V) { |
218 return %HasLocalProperty(ToObject(this), ToString(V)); | 218 return %HasLocalProperty(ToObject(this), ToString(V)); |
219 } | 219 } |
220 | 220 |
221 | 221 |
222 // ECMA-262 - 15.2.4.6 | 222 // ECMA-262 - 15.2.4.6 |
223 function ObjectIsPrototypeOf(V) { | 223 function ObjectIsPrototypeOf(V) { |
224 if (!IS_OBJECT(V) && !IS_FUNCTION(V)) return false; | 224 if (!IS_OBJECT(V) && !IS_FUNCTION(V) && !IS_UNDETECTABLE(V)) return false; |
225 return %IsInPrototypeChain(this, V); | 225 return %IsInPrototypeChain(this, V); |
226 } | 226 } |
227 | 227 |
228 | 228 |
229 // ECMA-262 - 15.2.4.6 | 229 // ECMA-262 - 15.2.4.6 |
230 function ObjectPropertyIsEnumerable(V) { | 230 function ObjectPropertyIsEnumerable(V) { |
231 if (this == null) return false; | 231 if (this == null) return false; |
232 if (!IS_OBJECT(this) && !IS_FUNCTION(this)) return false; | 232 if (!IS_OBJECT(this) && !IS_FUNCTION(this)) return false; |
233 return %IsPropertyEnumerable(this, ToString(V)); | 233 return %IsPropertyEnumerable(this, ToString(V)); |
234 } | 234 } |
235 | 235 |
236 | 236 |
237 // Extensions for providing property getters and setters. | 237 // Extensions for providing property getters and setters. |
238 function ObjectDefineGetter(name, fun) { | 238 function ObjectDefineGetter(name, fun) { |
239 if (this == null) { | 239 if (this == null && !IS_UNDETECTABLE(this)) { |
240 throw new $TypeError('Object.prototype.__defineGetter__: this is Null'); | 240 throw new $TypeError('Object.prototype.__defineGetter__: this is Null'); |
241 } | 241 } |
242 if (!IS_FUNCTION(fun)) { | 242 if (!IS_FUNCTION(fun)) { |
243 throw new $TypeError('Object.prototype.__defineGetter__: Expecting function'
); | 243 throw new $TypeError('Object.prototype.__defineGetter__: Expecting function'
); |
244 } | 244 } |
245 return %DefineAccessor(ToObject(this), ToString(name), GETTER, fun); | 245 return %DefineAccessor(ToObject(this), ToString(name), GETTER, fun); |
246 } | 246 } |
247 | 247 |
248 | 248 |
249 function ObjectLookupGetter(name) { | 249 function ObjectLookupGetter(name) { |
250 if (this == null) { | 250 if (this == null && !IS_UNDETECTABLE(this)) { |
251 throw new $TypeError('Object.prototype.__lookupGetter__: this is Null'); | 251 throw new $TypeError('Object.prototype.__lookupGetter__: this is Null'); |
252 } | 252 } |
253 return %LookupAccessor(ToObject(this), ToString(name), GETTER); | 253 return %LookupAccessor(ToObject(this), ToString(name), GETTER); |
254 } | 254 } |
255 | 255 |
256 | 256 |
257 function ObjectDefineSetter(name, fun) { | 257 function ObjectDefineSetter(name, fun) { |
258 if (this == null) { | 258 if (this == null && !IS_UNDETECTABLE(this)) { |
259 throw new $TypeError('Object.prototype.__defineSetter__: this is Null'); | 259 throw new $TypeError('Object.prototype.__defineSetter__: this is Null'); |
260 } | 260 } |
261 if (!IS_FUNCTION(fun)) { | 261 if (!IS_FUNCTION(fun)) { |
262 throw new $TypeError( | 262 throw new $TypeError( |
263 'Object.prototype.__defineSetter__: Expecting function'); | 263 'Object.prototype.__defineSetter__: Expecting function'); |
264 } | 264 } |
265 return %DefineAccessor(ToObject(this), ToString(name), SETTER, fun); | 265 return %DefineAccessor(ToObject(this), ToString(name), SETTER, fun); |
266 } | 266 } |
267 | 267 |
268 | 268 |
269 function ObjectLookupSetter(name) { | 269 function ObjectLookupSetter(name) { |
270 if (this == null) { | 270 if (this == null && !IS_UNDETECTABLE(this)) { |
271 throw new $TypeError('Object.prototype.__lookupSetter__: this is Null'); | 271 throw new $TypeError('Object.prototype.__lookupSetter__: this is Null'); |
272 } | 272 } |
273 return %LookupAccessor(ToObject(this), ToString(name), SETTER); | 273 return %LookupAccessor(ToObject(this), ToString(name), SETTER); |
274 } | 274 } |
275 | 275 |
276 | 276 |
277 function ObjectKeys(obj) { | 277 function ObjectKeys(obj) { |
278 if ((!IS_OBJECT(obj) || IS_NULL_OR_UNDEFINED(obj)) && !IS_FUNCTION(obj)) | 278 if ((!IS_OBJECT(obj) || IS_NULL_OR_UNDEFINED(obj)) && !IS_FUNCTION(obj) && |
| 279 !IS_UNDETECTABLE(obj)) |
279 throw MakeTypeError("obj_ctor_property_non_object", ["keys"]); | 280 throw MakeTypeError("obj_ctor_property_non_object", ["keys"]); |
280 return %LocalKeys(obj); | 281 return %LocalKeys(obj); |
281 } | 282 } |
282 | 283 |
283 | 284 |
284 // ES5 8.10.1. | 285 // ES5 8.10.1. |
285 function IsAccessorDescriptor(desc) { | 286 function IsAccessorDescriptor(desc) { |
286 if (IS_UNDEFINED(desc)) return false; | 287 if (IS_UNDEFINED(desc)) return false; |
287 return desc.hasGetter_ || desc.hasSetter_; | 288 return desc.hasGetter_ || desc.hasSetter_; |
288 } | 289 } |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 if (desc.hasSetter() && IS_FUNCTION(desc.getSet())) { | 588 if (desc.hasSetter() && IS_FUNCTION(desc.getSet())) { |
588 %DefineOrRedefineAccessorProperty(obj, p, SETTER, desc.getSet(), flag); | 589 %DefineOrRedefineAccessorProperty(obj, p, SETTER, desc.getSet(), flag); |
589 } | 590 } |
590 } | 591 } |
591 return true; | 592 return true; |
592 } | 593 } |
593 | 594 |
594 | 595 |
595 // ES5 section 15.2.3.2. | 596 // ES5 section 15.2.3.2. |
596 function ObjectGetPrototypeOf(obj) { | 597 function ObjectGetPrototypeOf(obj) { |
597 if ((!IS_OBJECT(obj) || IS_NULL_OR_UNDEFINED(obj)) && !IS_FUNCTION(obj)) | 598 if ((!IS_OBJECT(obj) || IS_NULL_OR_UNDEFINED(obj)) && !IS_FUNCTION(obj) && |
| 599 !IS_UNDETECTABLE(obj)) |
598 throw MakeTypeError("obj_ctor_property_non_object", ["getPrototypeOf"]); | 600 throw MakeTypeError("obj_ctor_property_non_object", ["getPrototypeOf"]); |
599 return obj.__proto__; | 601 return obj.__proto__; |
600 } | 602 } |
601 | 603 |
602 | 604 |
603 // ES5 section 15.2.3.3 | 605 // ES5 section 15.2.3.3 |
604 function ObjectGetOwnPropertyDescriptor(obj, p) { | 606 function ObjectGetOwnPropertyDescriptor(obj, p) { |
605 if ((!IS_OBJECT(obj) || IS_NULL_OR_UNDEFINED(obj)) && !IS_FUNCTION(obj)) | 607 if ((!IS_OBJECT(obj) || IS_NULL_OR_UNDEFINED(obj)) && !IS_FUNCTION(obj) && |
| 608 !IS_UNDETECTABLE(obj)) |
606 throw MakeTypeError("obj_ctor_property_non_object", ["getOwnPropertyDescript
or"]); | 609 throw MakeTypeError("obj_ctor_property_non_object", ["getOwnPropertyDescript
or"]); |
607 var desc = GetOwnProperty(obj, p); | 610 var desc = GetOwnProperty(obj, p); |
608 return FromPropertyDescriptor(desc); | 611 return FromPropertyDescriptor(desc); |
609 } | 612 } |
610 | 613 |
611 | 614 |
612 // ES5 section 15.2.3.4. | 615 // ES5 section 15.2.3.4. |
613 function ObjectGetOwnPropertyNames(obj) { | 616 function ObjectGetOwnPropertyNames(obj) { |
614 if ((!IS_OBJECT(obj) || IS_NULL_OR_UNDEFINED(obj)) && !IS_FUNCTION(obj)) | 617 if ((!IS_OBJECT(obj) || IS_NULL_OR_UNDEFINED(obj)) && !IS_FUNCTION(obj) && |
| 618 !IS_UNDETECTABLE(obj)) |
615 throw MakeTypeError("obj_ctor_property_non_object", ["getOwnPropertyNames"])
; | 619 throw MakeTypeError("obj_ctor_property_non_object", ["getOwnPropertyNames"])
; |
616 | 620 |
617 // Find all the indexed properties. | 621 // Find all the indexed properties. |
618 | 622 |
619 // Get the local element names. | 623 // Get the local element names. |
620 var propertyNames = %GetLocalElementNames(obj); | 624 var propertyNames = %GetLocalElementNames(obj); |
621 | 625 |
622 // Get names for indexed interceptor properties. | 626 // Get names for indexed interceptor properties. |
623 if (%GetInterceptorInfo(obj) & 1) { | 627 if (%GetInterceptorInfo(obj) & 1) { |
624 var indexedInterceptorNames = | 628 var indexedInterceptorNames = |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 } | 661 } |
658 var obj = new $Object(); | 662 var obj = new $Object(); |
659 obj.__proto__ = proto; | 663 obj.__proto__ = proto; |
660 if (!IS_UNDEFINED(properties)) ObjectDefineProperties(obj, properties); | 664 if (!IS_UNDEFINED(properties)) ObjectDefineProperties(obj, properties); |
661 return obj; | 665 return obj; |
662 } | 666 } |
663 | 667 |
664 | 668 |
665 // ES5 section 15.2.3.6. | 669 // ES5 section 15.2.3.6. |
666 function ObjectDefineProperty(obj, p, attributes) { | 670 function ObjectDefineProperty(obj, p, attributes) { |
667 if ((!IS_OBJECT(obj) || IS_NULL_OR_UNDEFINED(obj)) && !IS_FUNCTION(obj)) | 671 if ((!IS_OBJECT(obj) || IS_NULL_OR_UNDEFINED(obj)) && !IS_FUNCTION(obj) && |
| 672 !IS_UNDETECTABLE(obj)) |
668 throw MakeTypeError("obj_ctor_property_non_object", ["defineProperty"]); | 673 throw MakeTypeError("obj_ctor_property_non_object", ["defineProperty"]); |
669 var name = ToString(p); | 674 var name = ToString(p); |
670 var desc = ToPropertyDescriptor(attributes); | 675 var desc = ToPropertyDescriptor(attributes); |
671 DefineOwnProperty(obj, name, desc, true); | 676 DefineOwnProperty(obj, name, desc, true); |
672 return obj; | 677 return obj; |
673 } | 678 } |
674 | 679 |
675 | 680 |
676 // ES5 section 15.2.3.7. | 681 // ES5 section 15.2.3.7. |
677 function ObjectDefineProperties(obj, properties) { | 682 function ObjectDefineProperties(obj, properties) { |
678 if ((!IS_OBJECT(obj) || IS_NULL_OR_UNDEFINED(obj)) && !IS_FUNCTION(obj)) | 683 if ((!IS_OBJECT(obj) || IS_NULL_OR_UNDEFINED(obj)) && !IS_FUNCTION(obj) && |
| 684 !IS_UNDETECTABLE(obj)) |
679 throw MakeTypeError("obj_ctor_property_non_object", ["defineProperties"]); | 685 throw MakeTypeError("obj_ctor_property_non_object", ["defineProperties"]); |
680 var props = ToObject(properties); | 686 var props = ToObject(properties); |
681 var key_values = []; | 687 var key_values = []; |
682 for (var key in props) { | 688 for (var key in props) { |
683 if (%HasLocalProperty(props, key)) { | 689 if (%HasLocalProperty(props, key)) { |
684 key_values.push(key); | 690 key_values.push(key); |
685 var value = props[key]; | 691 var value = props[key]; |
686 var desc = ToPropertyDescriptor(value); | 692 var desc = ToPropertyDescriptor(value); |
687 key_values.push(desc); | 693 key_values.push(desc); |
688 } | 694 } |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
992 | 998 |
993 // ---------------------------------------------------------------------------- | 999 // ---------------------------------------------------------------------------- |
994 | 1000 |
995 function SetupFunction() { | 1001 function SetupFunction() { |
996 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1002 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
997 "toString", FunctionToString | 1003 "toString", FunctionToString |
998 )); | 1004 )); |
999 } | 1005 } |
1000 | 1006 |
1001 SetupFunction(); | 1007 SetupFunction(); |
OLD | NEW |