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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 | 218 |
219 | 219 |
220 // ECMA-262 - 15.2.4.5 | 220 // ECMA-262 - 15.2.4.5 |
221 function ObjectHasOwnProperty(V) { | 221 function ObjectHasOwnProperty(V) { |
222 return %HasLocalProperty(ToObject(this), ToString(V)); | 222 return %HasLocalProperty(ToObject(this), ToString(V)); |
223 } | 223 } |
224 | 224 |
225 | 225 |
226 // ECMA-262 - 15.2.4.6 | 226 // ECMA-262 - 15.2.4.6 |
227 function ObjectIsPrototypeOf(V) { | 227 function ObjectIsPrototypeOf(V) { |
228 if (!IS_OBJECT(V) && !IS_FUNCTION(V) && !IS_UNDETECTABLE(V)) return false; | 228 if (!IS_SPEC_OBJECT_OR_NULL(V) && !IS_UNDETECTABLE(V)) return false; |
229 return %IsInPrototypeChain(this, V); | 229 return %IsInPrototypeChain(this, V); |
230 } | 230 } |
231 | 231 |
232 | 232 |
233 // ECMA-262 - 15.2.4.6 | 233 // ECMA-262 - 15.2.4.6 |
234 function ObjectPropertyIsEnumerable(V) { | 234 function ObjectPropertyIsEnumerable(V) { |
235 if (this == null) return false; | 235 if (this == null) return false; |
236 if (!IS_OBJECT(this) && !IS_FUNCTION(this)) return false; | 236 if (!IS_SPEC_OBJECT_OR_NULL(this)) return false; |
237 return %IsPropertyEnumerable(this, ToString(V)); | 237 return %IsPropertyEnumerable(this, ToString(V)); |
238 } | 238 } |
239 | 239 |
240 | 240 |
241 // Extensions for providing property getters and setters. | 241 // Extensions for providing property getters and setters. |
242 function ObjectDefineGetter(name, fun) { | 242 function ObjectDefineGetter(name, fun) { |
243 if (this == null && !IS_UNDETECTABLE(this)) { | 243 if (this == null && !IS_UNDETECTABLE(this)) { |
244 throw new $TypeError('Object.prototype.__defineGetter__: this is Null'); | 244 throw new $TypeError('Object.prototype.__defineGetter__: this is Null'); |
245 } | 245 } |
246 if (!IS_FUNCTION(fun)) { | 246 if (!IS_FUNCTION(fun)) { |
(...skipping 25 matching lines...) Expand all Loading... |
272 | 272 |
273 function ObjectLookupSetter(name) { | 273 function ObjectLookupSetter(name) { |
274 if (this == null && !IS_UNDETECTABLE(this)) { | 274 if (this == null && !IS_UNDETECTABLE(this)) { |
275 throw new $TypeError('Object.prototype.__lookupSetter__: this is Null'); | 275 throw new $TypeError('Object.prototype.__lookupSetter__: this is Null'); |
276 } | 276 } |
277 return %LookupAccessor(ToObject(this), ToString(name), SETTER); | 277 return %LookupAccessor(ToObject(this), ToString(name), SETTER); |
278 } | 278 } |
279 | 279 |
280 | 280 |
281 function ObjectKeys(obj) { | 281 function ObjectKeys(obj) { |
282 if ((!IS_OBJECT(obj) || IS_NULL_OR_UNDEFINED(obj)) && !IS_FUNCTION(obj) && | 282 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) && |
283 !IS_UNDETECTABLE(obj)) | 283 !IS_UNDETECTABLE(obj)) |
284 throw MakeTypeError("obj_ctor_property_non_object", ["keys"]); | 284 throw MakeTypeError("obj_ctor_property_non_object", ["keys"]); |
285 return %LocalKeys(obj); | 285 return %LocalKeys(obj); |
286 } | 286 } |
287 | 287 |
288 | 288 |
289 // ES5 8.10.1. | 289 // ES5 8.10.1. |
290 function IsAccessorDescriptor(desc) { | 290 function IsAccessorDescriptor(desc) { |
291 if (IS_UNDEFINED(desc)) return false; | 291 if (IS_UNDEFINED(desc)) return false; |
292 return desc.hasGetter_ || desc.hasSetter_; | 292 return desc.hasGetter_ || desc.hasSetter_; |
(...skipping 29 matching lines...) Expand all Loading... |
322 obj.get = desc.getGet(); | 322 obj.get = desc.getGet(); |
323 obj.set = desc.getSet(); | 323 obj.set = desc.getSet(); |
324 } | 324 } |
325 obj.enumerable = desc.isEnumerable(); | 325 obj.enumerable = desc.isEnumerable(); |
326 obj.configurable = desc.isConfigurable(); | 326 obj.configurable = desc.isConfigurable(); |
327 return obj; | 327 return obj; |
328 } | 328 } |
329 | 329 |
330 // ES5 8.10.5. | 330 // ES5 8.10.5. |
331 function ToPropertyDescriptor(obj) { | 331 function ToPropertyDescriptor(obj) { |
332 if (!IS_OBJECT(obj)) { | 332 if (!IS_SPEC_OBJECT_OR_NULL(obj)) { |
333 throw MakeTypeError("property_desc_object", [obj]); | 333 throw MakeTypeError("property_desc_object", [obj]); |
334 } | 334 } |
335 var desc = new PropertyDescriptor(); | 335 var desc = new PropertyDescriptor(); |
336 | 336 |
337 if ("enumerable" in obj) { | 337 if ("enumerable" in obj) { |
338 desc.setEnumerable(ToBoolean(obj.enumerable)); | 338 desc.setEnumerable(ToBoolean(obj.enumerable)); |
339 } | 339 } |
340 | 340 |
341 if ("configurable" in obj) { | 341 if ("configurable" in obj) { |
342 desc.setConfigurable(ToBoolean(obj.configurable)); | 342 desc.setConfigurable(ToBoolean(obj.configurable)); |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 if (desc.hasSetter() && IS_FUNCTION(desc.getSet())) { | 592 if (desc.hasSetter() && IS_FUNCTION(desc.getSet())) { |
593 %DefineOrRedefineAccessorProperty(obj, p, SETTER, desc.getSet(), flag); | 593 %DefineOrRedefineAccessorProperty(obj, p, SETTER, desc.getSet(), flag); |
594 } | 594 } |
595 } | 595 } |
596 return true; | 596 return true; |
597 } | 597 } |
598 | 598 |
599 | 599 |
600 // ES5 section 15.2.3.2. | 600 // ES5 section 15.2.3.2. |
601 function ObjectGetPrototypeOf(obj) { | 601 function ObjectGetPrototypeOf(obj) { |
602 if ((!IS_OBJECT(obj) || IS_NULL_OR_UNDEFINED(obj)) && !IS_FUNCTION(obj) && | 602 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) && |
603 !IS_UNDETECTABLE(obj)) | 603 !IS_UNDETECTABLE(obj)) |
604 throw MakeTypeError("obj_ctor_property_non_object", ["getPrototypeOf"]); | 604 throw MakeTypeError("obj_ctor_property_non_object", ["getPrototypeOf"]); |
605 return obj.__proto__; | 605 return obj.__proto__; |
606 } | 606 } |
607 | 607 |
608 | 608 |
609 // ES5 section 15.2.3.3 | 609 // ES5 section 15.2.3.3 |
610 function ObjectGetOwnPropertyDescriptor(obj, p) { | 610 function ObjectGetOwnPropertyDescriptor(obj, p) { |
611 if ((!IS_OBJECT(obj) || IS_NULL_OR_UNDEFINED(obj)) && !IS_FUNCTION(obj) && | 611 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) && |
612 !IS_UNDETECTABLE(obj)) | 612 !IS_UNDETECTABLE(obj)) |
613 throw MakeTypeError("obj_ctor_property_non_object", ["getOwnPropertyDescript
or"]); | 613 throw MakeTypeError("obj_ctor_property_non_object", ["getOwnPropertyDescript
or"]); |
614 var desc = GetOwnProperty(obj, p); | 614 var desc = GetOwnProperty(obj, p); |
615 return FromPropertyDescriptor(desc); | 615 return FromPropertyDescriptor(desc); |
616 } | 616 } |
617 | 617 |
618 | 618 |
619 // ES5 section 15.2.3.4. | 619 // ES5 section 15.2.3.4. |
620 function ObjectGetOwnPropertyNames(obj) { | 620 function ObjectGetOwnPropertyNames(obj) { |
621 if ((!IS_OBJECT(obj) || IS_NULL_OR_UNDEFINED(obj)) && !IS_FUNCTION(obj) && | 621 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) && |
622 !IS_UNDETECTABLE(obj)) | 622 !IS_UNDETECTABLE(obj)) |
623 throw MakeTypeError("obj_ctor_property_non_object", ["getOwnPropertyNames"])
; | 623 throw MakeTypeError("obj_ctor_property_non_object", ["getOwnPropertyNames"])
; |
624 | 624 |
625 // Find all the indexed properties. | 625 // Find all the indexed properties. |
626 | 626 |
627 // Get the local element names. | 627 // Get the local element names. |
628 var propertyNames = %GetLocalElementNames(obj); | 628 var propertyNames = %GetLocalElementNames(obj); |
629 | 629 |
630 // Get names for indexed interceptor properties. | 630 // Get names for indexed interceptor properties. |
631 if (%GetInterceptorInfo(obj) & 1) { | 631 if (%GetInterceptorInfo(obj) & 1) { |
(...skipping 21 matching lines...) Expand all Loading... |
653 // Property names are expected to be strings. | 653 // Property names are expected to be strings. |
654 for (var i = 0; i < propertyNames.length; ++i) | 654 for (var i = 0; i < propertyNames.length; ++i) |
655 propertyNames[i] = ToString(propertyNames[i]); | 655 propertyNames[i] = ToString(propertyNames[i]); |
656 | 656 |
657 return propertyNames; | 657 return propertyNames; |
658 } | 658 } |
659 | 659 |
660 | 660 |
661 // ES5 section 15.2.3.5. | 661 // ES5 section 15.2.3.5. |
662 function ObjectCreate(proto, properties) { | 662 function ObjectCreate(proto, properties) { |
663 // IS_OBJECT will return true on null covering that case. | 663 if (!IS_SPEC_OBJECT_OR_NULL(proto)) { |
664 if (!IS_OBJECT(proto) && !IS_FUNCTION(proto)) { | |
665 throw MakeTypeError("proto_object_or_null", [proto]); | 664 throw MakeTypeError("proto_object_or_null", [proto]); |
666 } | 665 } |
667 var obj = new $Object(); | 666 var obj = new $Object(); |
668 obj.__proto__ = proto; | 667 obj.__proto__ = proto; |
669 if (!IS_UNDEFINED(properties)) ObjectDefineProperties(obj, properties); | 668 if (!IS_UNDEFINED(properties)) ObjectDefineProperties(obj, properties); |
670 return obj; | 669 return obj; |
671 } | 670 } |
672 | 671 |
673 | 672 |
674 // ES5 section 15.2.3.6. | 673 // ES5 section 15.2.3.6. |
675 function ObjectDefineProperty(obj, p, attributes) { | 674 function ObjectDefineProperty(obj, p, attributes) { |
676 if ((!IS_OBJECT(obj) || IS_NULL_OR_UNDEFINED(obj)) && !IS_FUNCTION(obj) && | 675 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) && |
677 !IS_UNDETECTABLE(obj)) | 676 !IS_UNDETECTABLE(obj)) |
678 throw MakeTypeError("obj_ctor_property_non_object", ["defineProperty"]); | 677 throw MakeTypeError("obj_ctor_property_non_object", ["defineProperty"]); |
679 var name = ToString(p); | 678 var name = ToString(p); |
680 var desc = ToPropertyDescriptor(attributes); | 679 var desc = ToPropertyDescriptor(attributes); |
681 DefineOwnProperty(obj, name, desc, true); | 680 DefineOwnProperty(obj, name, desc, true); |
682 return obj; | 681 return obj; |
683 } | 682 } |
684 | 683 |
685 | 684 |
686 // ES5 section 15.2.3.7. | 685 // ES5 section 15.2.3.7. |
687 function ObjectDefineProperties(obj, properties) { | 686 function ObjectDefineProperties(obj, properties) { |
688 if ((!IS_OBJECT(obj) || IS_NULL_OR_UNDEFINED(obj)) && !IS_FUNCTION(obj) && | 687 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) && |
689 !IS_UNDETECTABLE(obj)) | 688 !IS_UNDETECTABLE(obj)) |
690 throw MakeTypeError("obj_ctor_property_non_object", ["defineProperties"]); | 689 throw MakeTypeError("obj_ctor_property_non_object", ["defineProperties"]); |
691 var props = ToObject(properties); | 690 var props = ToObject(properties); |
692 var key_values = []; | 691 var key_values = []; |
693 for (var key in props) { | 692 for (var key in props) { |
694 if (%HasLocalProperty(props, key)) { | 693 if (%HasLocalProperty(props, key)) { |
695 key_values.push(key); | 694 key_values.push(key); |
696 var value = props[key]; | 695 var value = props[key]; |
697 var desc = ToPropertyDescriptor(value); | 696 var desc = ToPropertyDescriptor(value); |
698 key_values.push(desc); | 697 key_values.push(desc); |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1003 | 1002 |
1004 // ---------------------------------------------------------------------------- | 1003 // ---------------------------------------------------------------------------- |
1005 | 1004 |
1006 function SetupFunction() { | 1005 function SetupFunction() { |
1007 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1006 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
1008 "toString", FunctionToString | 1007 "toString", FunctionToString |
1009 )); | 1008 )); |
1010 } | 1009 } |
1011 | 1010 |
1012 SetupFunction(); | 1011 SetupFunction(); |
OLD | NEW |