| 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_SPEC_OBJECT_OR_NULL(V) && !IS_UNDETECTABLE(V)) return false; | 228 if (!IS_SPEC_OBJECT(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 return %IsPropertyEnumerable(ToObject(this), ToString(V)); |
| 236 if (!IS_SPEC_OBJECT_OR_NULL(this)) return false; | |
| 237 return %IsPropertyEnumerable(this, ToString(V)); | |
| 238 } | 236 } |
| 239 | 237 |
| 240 | 238 |
| 241 // Extensions for providing property getters and setters. | 239 // Extensions for providing property getters and setters. |
| 242 function ObjectDefineGetter(name, fun) { | 240 function ObjectDefineGetter(name, fun) { |
| 243 if (this == null && !IS_UNDETECTABLE(this)) { | 241 if (this == null && !IS_UNDETECTABLE(this)) { |
| 244 throw new $TypeError('Object.prototype.__defineGetter__: this is Null'); | 242 throw new $TypeError('Object.prototype.__defineGetter__: this is Null'); |
| 245 } | 243 } |
| 246 if (!IS_FUNCTION(fun)) { | 244 if (!IS_FUNCTION(fun)) { |
| 247 throw new $TypeError('Object.prototype.__defineGetter__: Expecting function'
); | 245 throw new $TypeError('Object.prototype.__defineGetter__: Expecting function'
); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 272 | 270 |
| 273 function ObjectLookupSetter(name) { | 271 function ObjectLookupSetter(name) { |
| 274 if (this == null && !IS_UNDETECTABLE(this)) { | 272 if (this == null && !IS_UNDETECTABLE(this)) { |
| 275 throw new $TypeError('Object.prototype.__lookupSetter__: this is Null'); | 273 throw new $TypeError('Object.prototype.__lookupSetter__: this is Null'); |
| 276 } | 274 } |
| 277 return %LookupAccessor(ToObject(this), ToString(name), SETTER); | 275 return %LookupAccessor(ToObject(this), ToString(name), SETTER); |
| 278 } | 276 } |
| 279 | 277 |
| 280 | 278 |
| 281 function ObjectKeys(obj) { | 279 function ObjectKeys(obj) { |
| 282 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) && | 280 if (!IS_SPEC_OBJECT(obj)) |
| 283 !IS_UNDETECTABLE(obj)) | |
| 284 throw MakeTypeError("obj_ctor_property_non_object", ["keys"]); | 281 throw MakeTypeError("obj_ctor_property_non_object", ["keys"]); |
| 285 return %LocalKeys(obj); | 282 return %LocalKeys(obj); |
| 286 } | 283 } |
| 287 | 284 |
| 288 | 285 |
| 289 // ES5 8.10.1. | 286 // ES5 8.10.1. |
| 290 function IsAccessorDescriptor(desc) { | 287 function IsAccessorDescriptor(desc) { |
| 291 if (IS_UNDEFINED(desc)) return false; | 288 if (IS_UNDEFINED(desc)) return false; |
| 292 return desc.hasGetter_ || desc.hasSetter_; | 289 return desc.hasGetter_ || desc.hasSetter_; |
| 293 } | 290 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 322 obj.get = desc.getGet(); | 319 obj.get = desc.getGet(); |
| 323 obj.set = desc.getSet(); | 320 obj.set = desc.getSet(); |
| 324 } | 321 } |
| 325 obj.enumerable = desc.isEnumerable(); | 322 obj.enumerable = desc.isEnumerable(); |
| 326 obj.configurable = desc.isConfigurable(); | 323 obj.configurable = desc.isConfigurable(); |
| 327 return obj; | 324 return obj; |
| 328 } | 325 } |
| 329 | 326 |
| 330 // ES5 8.10.5. | 327 // ES5 8.10.5. |
| 331 function ToPropertyDescriptor(obj) { | 328 function ToPropertyDescriptor(obj) { |
| 332 if (!IS_SPEC_OBJECT_OR_NULL(obj)) { | 329 if (!IS_SPEC_OBJECT(obj)) { |
| 333 throw MakeTypeError("property_desc_object", [obj]); | 330 throw MakeTypeError("property_desc_object", [obj]); |
| 334 } | 331 } |
| 335 var desc = new PropertyDescriptor(); | 332 var desc = new PropertyDescriptor(); |
| 336 | 333 |
| 337 if ("enumerable" in obj) { | 334 if ("enumerable" in obj) { |
| 338 desc.setEnumerable(ToBoolean(obj.enumerable)); | 335 desc.setEnumerable(ToBoolean(obj.enumerable)); |
| 339 } | 336 } |
| 340 | 337 |
| 341 if ("configurable" in obj) { | 338 if ("configurable" in obj) { |
| 342 desc.setConfigurable(ToBoolean(obj.configurable)); | 339 desc.setConfigurable(ToBoolean(obj.configurable)); |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 if (desc.hasSetter() && IS_FUNCTION(desc.getSet())) { | 616 if (desc.hasSetter() && IS_FUNCTION(desc.getSet())) { |
| 620 %DefineOrRedefineAccessorProperty(obj, p, SETTER, desc.getSet(), flag); | 617 %DefineOrRedefineAccessorProperty(obj, p, SETTER, desc.getSet(), flag); |
| 621 } | 618 } |
| 622 } | 619 } |
| 623 return true; | 620 return true; |
| 624 } | 621 } |
| 625 | 622 |
| 626 | 623 |
| 627 // ES5 section 15.2.3.2. | 624 // ES5 section 15.2.3.2. |
| 628 function ObjectGetPrototypeOf(obj) { | 625 function ObjectGetPrototypeOf(obj) { |
| 629 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) && | 626 if (!IS_SPEC_OBJECT(obj)) |
| 630 !IS_UNDETECTABLE(obj)) | |
| 631 throw MakeTypeError("obj_ctor_property_non_object", ["getPrototypeOf"]); | 627 throw MakeTypeError("obj_ctor_property_non_object", ["getPrototypeOf"]); |
| 632 return obj.__proto__; | 628 return obj.__proto__; |
| 633 } | 629 } |
| 634 | 630 |
| 635 | 631 |
| 636 // ES5 section 15.2.3.3 | 632 // ES5 section 15.2.3.3 |
| 637 function ObjectGetOwnPropertyDescriptor(obj, p) { | 633 function ObjectGetOwnPropertyDescriptor(obj, p) { |
| 638 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) && | 634 if (!IS_SPEC_OBJECT(obj)) |
| 639 !IS_UNDETECTABLE(obj)) | |
| 640 throw MakeTypeError("obj_ctor_property_non_object", ["getOwnPropertyDescript
or"]); | 635 throw MakeTypeError("obj_ctor_property_non_object", ["getOwnPropertyDescript
or"]); |
| 641 var desc = GetOwnProperty(obj, p); | 636 var desc = GetOwnProperty(obj, p); |
| 642 return FromPropertyDescriptor(desc); | 637 return FromPropertyDescriptor(desc); |
| 643 } | 638 } |
| 644 | 639 |
| 645 | 640 |
| 646 // ES5 section 15.2.3.4. | 641 // ES5 section 15.2.3.4. |
| 647 function ObjectGetOwnPropertyNames(obj) { | 642 function ObjectGetOwnPropertyNames(obj) { |
| 648 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) && | 643 if (!IS_SPEC_OBJECT(obj)) |
| 649 !IS_UNDETECTABLE(obj)) | |
| 650 throw MakeTypeError("obj_ctor_property_non_object", ["getOwnPropertyNames"])
; | 644 throw MakeTypeError("obj_ctor_property_non_object", ["getOwnPropertyNames"])
; |
| 651 | 645 |
| 652 // Find all the indexed properties. | 646 // Find all the indexed properties. |
| 653 | 647 |
| 654 // Get the local element names. | 648 // Get the local element names. |
| 655 var propertyNames = %GetLocalElementNames(obj); | 649 var propertyNames = %GetLocalElementNames(obj); |
| 656 | 650 |
| 657 // Get names for indexed interceptor properties. | 651 // Get names for indexed interceptor properties. |
| 658 if (%GetInterceptorInfo(obj) & 1) { | 652 if (%GetInterceptorInfo(obj) & 1) { |
| 659 var indexedInterceptorNames = | 653 var indexedInterceptorNames = |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 propertyNames[j++] = name; | 685 propertyNames[j++] = name; |
| 692 } | 686 } |
| 693 propertyNames.length = j; | 687 propertyNames.length = j; |
| 694 | 688 |
| 695 return propertyNames; | 689 return propertyNames; |
| 696 } | 690 } |
| 697 | 691 |
| 698 | 692 |
| 699 // ES5 section 15.2.3.5. | 693 // ES5 section 15.2.3.5. |
| 700 function ObjectCreate(proto, properties) { | 694 function ObjectCreate(proto, properties) { |
| 701 if (!IS_SPEC_OBJECT_OR_NULL(proto)) { | 695 if (!IS_SPEC_OBJECT(proto) && proto !== null) { |
| 702 throw MakeTypeError("proto_object_or_null", [proto]); | 696 throw MakeTypeError("proto_object_or_null", [proto]); |
| 703 } | 697 } |
| 704 var obj = new $Object(); | 698 var obj = new $Object(); |
| 705 obj.__proto__ = proto; | 699 obj.__proto__ = proto; |
| 706 if (!IS_UNDEFINED(properties)) ObjectDefineProperties(obj, properties); | 700 if (!IS_UNDEFINED(properties)) ObjectDefineProperties(obj, properties); |
| 707 return obj; | 701 return obj; |
| 708 } | 702 } |
| 709 | 703 |
| 710 | 704 |
| 711 // ES5 section 15.2.3.6. | 705 // ES5 section 15.2.3.6. |
| 712 function ObjectDefineProperty(obj, p, attributes) { | 706 function ObjectDefineProperty(obj, p, attributes) { |
| 713 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) && | 707 if (!IS_SPEC_OBJECT(obj)) { |
| 714 !IS_UNDETECTABLE(obj)) { | |
| 715 throw MakeTypeError("obj_ctor_property_non_object", ["defineProperty"]); | 708 throw MakeTypeError("obj_ctor_property_non_object", ["defineProperty"]); |
| 716 } | 709 } |
| 717 var name = ToString(p); | 710 var name = ToString(p); |
| 718 var desc = ToPropertyDescriptor(attributes); | 711 var desc = ToPropertyDescriptor(attributes); |
| 719 DefineOwnProperty(obj, name, desc, true); | 712 DefineOwnProperty(obj, name, desc, true); |
| 720 return obj; | 713 return obj; |
| 721 } | 714 } |
| 722 | 715 |
| 723 | 716 |
| 724 // ES5 section 15.2.3.7. | 717 // ES5 section 15.2.3.7. |
| 725 function ObjectDefineProperties(obj, properties) { | 718 function ObjectDefineProperties(obj, properties) { |
| 726 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) && | 719 if (!IS_SPEC_OBJECT(obj)) |
| 727 !IS_UNDETECTABLE(obj)) | |
| 728 throw MakeTypeError("obj_ctor_property_non_object", ["defineProperties"]); | 720 throw MakeTypeError("obj_ctor_property_non_object", ["defineProperties"]); |
| 729 var props = ToObject(properties); | 721 var props = ToObject(properties); |
| 730 var key_values = []; | 722 var key_values = []; |
| 731 for (var key in props) { | 723 for (var key in props) { |
| 732 if (%HasLocalProperty(props, key)) { | 724 if (%HasLocalProperty(props, key)) { |
| 733 key_values.push(key); | 725 key_values.push(key); |
| 734 var value = props[key]; | 726 var value = props[key]; |
| 735 var desc = ToPropertyDescriptor(value); | 727 var desc = ToPropertyDescriptor(value); |
| 736 key_values.push(desc); | 728 key_values.push(desc); |
| 737 } | 729 } |
| 738 } | 730 } |
| 739 for (var i = 0; i < key_values.length; i += 2) { | 731 for (var i = 0; i < key_values.length; i += 2) { |
| 740 var key = key_values[i]; | 732 var key = key_values[i]; |
| 741 var desc = key_values[i + 1]; | 733 var desc = key_values[i + 1]; |
| 742 DefineOwnProperty(obj, key, desc, true); | 734 DefineOwnProperty(obj, key, desc, true); |
| 743 } | 735 } |
| 744 return obj; | 736 return obj; |
| 745 } | 737 } |
| 746 | 738 |
| 747 | 739 |
| 748 // ES5 section 15.2.3.8. | 740 // ES5 section 15.2.3.8. |
| 749 function ObjectSeal(obj) { | 741 function ObjectSeal(obj) { |
| 750 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) && | 742 if (!IS_SPEC_OBJECT(obj)) { |
| 751 !IS_UNDETECTABLE(obj)) { | |
| 752 throw MakeTypeError("obj_ctor_property_non_object", ["seal"]); | 743 throw MakeTypeError("obj_ctor_property_non_object", ["seal"]); |
| 753 } | 744 } |
| 754 var names = ObjectGetOwnPropertyNames(obj); | 745 var names = ObjectGetOwnPropertyNames(obj); |
| 755 for (var key in names) { | 746 for (var key in names) { |
| 756 var name = names[key]; | 747 var name = names[key]; |
| 757 var desc = GetOwnProperty(obj, name); | 748 var desc = GetOwnProperty(obj, name); |
| 758 if (desc.isConfigurable()) desc.setConfigurable(false); | 749 if (desc.isConfigurable()) desc.setConfigurable(false); |
| 759 DefineOwnProperty(obj, name, desc, true); | 750 DefineOwnProperty(obj, name, desc, true); |
| 760 } | 751 } |
| 761 ObjectPreventExtension(obj); | 752 ObjectPreventExtension(obj); |
| 762 } | 753 } |
| 763 | 754 |
| 764 | 755 |
| 765 // ES5 section 15.2.3.9. | 756 // ES5 section 15.2.3.9. |
| 766 function ObjectFreeze(obj) { | 757 function ObjectFreeze(obj) { |
| 767 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) && | 758 if (!IS_SPEC_OBJECT(obj)) { |
| 768 !IS_UNDETECTABLE(obj)) { | |
| 769 throw MakeTypeError("obj_ctor_property_non_object", ["freeze"]); | 759 throw MakeTypeError("obj_ctor_property_non_object", ["freeze"]); |
| 770 } | 760 } |
| 771 var names = ObjectGetOwnPropertyNames(obj); | 761 var names = ObjectGetOwnPropertyNames(obj); |
| 772 for (var key in names) { | 762 for (var key in names) { |
| 773 var name = names[key]; | 763 var name = names[key]; |
| 774 var desc = GetOwnProperty(obj, name); | 764 var desc = GetOwnProperty(obj, name); |
| 775 if (IsDataDescriptor(desc)) desc.setWritable(false); | 765 if (IsDataDescriptor(desc)) desc.setWritable(false); |
| 776 if (desc.isConfigurable()) desc.setConfigurable(false); | 766 if (desc.isConfigurable()) desc.setConfigurable(false); |
| 777 DefineOwnProperty(obj, name, desc, true); | 767 DefineOwnProperty(obj, name, desc, true); |
| 778 } | 768 } |
| 779 ObjectPreventExtension(obj); | 769 ObjectPreventExtension(obj); |
| 780 } | 770 } |
| 781 | 771 |
| 782 | 772 |
| 783 // ES5 section 15.2.3.10 | 773 // ES5 section 15.2.3.10 |
| 784 function ObjectPreventExtension(obj) { | 774 function ObjectPreventExtension(obj) { |
| 785 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) && | 775 if (!IS_SPEC_OBJECT(obj)) { |
| 786 !IS_UNDETECTABLE(obj)) { | |
| 787 throw MakeTypeError("obj_ctor_property_non_object", ["preventExtension"]); | 776 throw MakeTypeError("obj_ctor_property_non_object", ["preventExtension"]); |
| 788 } | 777 } |
| 789 %PreventExtensions(obj); | 778 %PreventExtensions(obj); |
| 790 return obj; | 779 return obj; |
| 791 } | 780 } |
| 792 | 781 |
| 793 | 782 |
| 794 // ES5 section 15.2.3.11 | 783 // ES5 section 15.2.3.11 |
| 795 function ObjectIsSealed(obj) { | 784 function ObjectIsSealed(obj) { |
| 796 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) && | 785 if (!IS_SPEC_OBJECT(obj)) { |
| 797 !IS_UNDETECTABLE(obj)) { | |
| 798 throw MakeTypeError("obj_ctor_property_non_object", ["isSealed"]); | 786 throw MakeTypeError("obj_ctor_property_non_object", ["isSealed"]); |
| 799 } | 787 } |
| 800 var names = ObjectGetOwnPropertyNames(obj); | 788 var names = ObjectGetOwnPropertyNames(obj); |
| 801 for (var key in names) { | 789 for (var key in names) { |
| 802 var name = names[key]; | 790 var name = names[key]; |
| 803 var desc = GetOwnProperty(obj, name); | 791 var desc = GetOwnProperty(obj, name); |
| 804 if (desc.isConfigurable()) return false; | 792 if (desc.isConfigurable()) return false; |
| 805 } | 793 } |
| 806 if (!ObjectIsExtensible(obj)) { | 794 if (!ObjectIsExtensible(obj)) { |
| 807 return true; | 795 return true; |
| 808 } | 796 } |
| 809 return false; | 797 return false; |
| 810 } | 798 } |
| 811 | 799 |
| 812 | 800 |
| 813 // ES5 section 15.2.3.12 | 801 // ES5 section 15.2.3.12 |
| 814 function ObjectIsFrozen(obj) { | 802 function ObjectIsFrozen(obj) { |
| 815 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) && | 803 if (!IS_SPEC_OBJECT(obj)) { |
| 816 !IS_UNDETECTABLE(obj)) { | |
| 817 throw MakeTypeError("obj_ctor_property_non_object", ["isFrozen"]); | 804 throw MakeTypeError("obj_ctor_property_non_object", ["isFrozen"]); |
| 818 } | 805 } |
| 819 var names = ObjectGetOwnPropertyNames(obj); | 806 var names = ObjectGetOwnPropertyNames(obj); |
| 820 for (var key in names) { | 807 for (var key in names) { |
| 821 var name = names[key]; | 808 var name = names[key]; |
| 822 var desc = GetOwnProperty(obj, name); | 809 var desc = GetOwnProperty(obj, name); |
| 823 if (IsDataDescriptor(desc) && desc.isWritable()) return false; | 810 if (IsDataDescriptor(desc) && desc.isWritable()) return false; |
| 824 if (desc.isConfigurable()) return false; | 811 if (desc.isConfigurable()) return false; |
| 825 } | 812 } |
| 826 if (!ObjectIsExtensible(obj)) { | 813 if (!ObjectIsExtensible(obj)) { |
| 827 return true; | 814 return true; |
| 828 } | 815 } |
| 829 return false; | 816 return false; |
| 830 } | 817 } |
| 831 | 818 |
| 832 | 819 |
| 833 // ES5 section 15.2.3.13 | 820 // ES5 section 15.2.3.13 |
| 834 function ObjectIsExtensible(obj) { | 821 function ObjectIsExtensible(obj) { |
| 835 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) && | 822 if (!IS_SPEC_OBJECT(obj)) { |
| 836 !IS_UNDETECTABLE(obj)) { | |
| 837 throw MakeTypeError("obj_ctor_property_non_object", ["preventExtension"]); | 823 throw MakeTypeError("obj_ctor_property_non_object", ["preventExtension"]); |
| 838 } | 824 } |
| 839 return %IsExtensible(obj); | 825 return %IsExtensible(obj); |
| 840 } | 826 } |
| 841 | 827 |
| 842 | 828 |
| 843 %SetCode($Object, function(x) { | 829 %SetCode($Object, function(x) { |
| 844 if (%_IsConstructCall()) { | 830 if (%_IsConstructCall()) { |
| 845 if (x == null) return this; | 831 if (x == null) return this; |
| 846 return ToObject(x); | 832 return ToObject(x); |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1142 | 1128 |
| 1143 // ---------------------------------------------------------------------------- | 1129 // ---------------------------------------------------------------------------- |
| 1144 | 1130 |
| 1145 function SetupFunction() { | 1131 function SetupFunction() { |
| 1146 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1132 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
| 1147 "toString", FunctionToString | 1133 "toString", FunctionToString |
| 1148 )); | 1134 )); |
| 1149 } | 1135 } |
| 1150 | 1136 |
| 1151 SetupFunction(); | 1137 SetupFunction(); |
| OLD | NEW |