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 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 } | 738 } |
739 for (var i = 0; i < key_values.length; i += 2) { | 739 for (var i = 0; i < key_values.length; i += 2) { |
740 var key = key_values[i]; | 740 var key = key_values[i]; |
741 var desc = key_values[i + 1]; | 741 var desc = key_values[i + 1]; |
742 DefineOwnProperty(obj, key, desc, true); | 742 DefineOwnProperty(obj, key, desc, true); |
743 } | 743 } |
744 return obj; | 744 return obj; |
745 } | 745 } |
746 | 746 |
747 | 747 |
| 748 // ES5 section 15.2.3.8. |
| 749 function ObjectSeal(obj) { |
| 750 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) && |
| 751 !IS_UNDETECTABLE(obj)) { |
| 752 throw MakeTypeError("obj_ctor_property_non_object", ["seal"]); |
| 753 } |
| 754 var names = ObjectGetOwnPropertyNames(obj); |
| 755 for (var key in names) { |
| 756 var name = names[key]; |
| 757 var desc = GetOwnProperty(obj, name); |
| 758 if (desc.isConfigurable()) desc.setConfigurable(false); |
| 759 DefineOwnProperty(obj, name, desc, true); |
| 760 } |
| 761 ObjectPreventExtension(obj); |
| 762 } |
| 763 |
| 764 |
748 // ES5 section 15.2.3.9. | 765 // ES5 section 15.2.3.9. |
749 function ObjectFreeze(obj) { | 766 function ObjectFreeze(obj) { |
750 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) && | 767 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) && |
751 !IS_UNDETECTABLE(obj)) { | 768 !IS_UNDETECTABLE(obj)) { |
752 throw MakeTypeError("obj_ctor_property_non_object", ["freeze"]); | 769 throw MakeTypeError("obj_ctor_property_non_object", ["freeze"]); |
753 } | 770 } |
754 var names = ObjectGetOwnPropertyNames(obj); | 771 var names = ObjectGetOwnPropertyNames(obj); |
755 for (var key in names) { | 772 for (var key in names) { |
756 var name = names[key]; | 773 var name = names[key]; |
757 var desc = GetOwnProperty(obj, name); | 774 var desc = GetOwnProperty(obj, name); |
758 if (IsDataDescriptor(desc)) desc.setWritable(false); | 775 if (IsDataDescriptor(desc)) desc.setWritable(false); |
759 if (desc.isConfigurable()) desc.setConfigurable(false); | 776 if (desc.isConfigurable()) desc.setConfigurable(false); |
760 DefineOwnProperty(obj, name, desc, true); | 777 DefineOwnProperty(obj, name, desc, true); |
761 } | 778 } |
762 ObjectPreventExtension(obj); | 779 ObjectPreventExtension(obj); |
763 } | 780 } |
764 | 781 |
765 | 782 |
766 // ES5 section 15.2.3.10 | 783 // ES5 section 15.2.3.10 |
767 function ObjectPreventExtension(obj) { | 784 function ObjectPreventExtension(obj) { |
768 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) && | 785 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) && |
769 !IS_UNDETECTABLE(obj)) { | 786 !IS_UNDETECTABLE(obj)) { |
770 throw MakeTypeError("obj_ctor_property_non_object", ["preventExtension"]); | 787 throw MakeTypeError("obj_ctor_property_non_object", ["preventExtension"]); |
771 } | 788 } |
772 %PreventExtensions(obj); | 789 %PreventExtensions(obj); |
773 return obj; | 790 return obj; |
774 } | 791 } |
775 | 792 |
776 | 793 |
| 794 // ES5 section 15.2.3.11 |
| 795 function ObjectIsSealed(obj) { |
| 796 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) && |
| 797 !IS_UNDETECTABLE(obj)) { |
| 798 throw MakeTypeError("obj_ctor_property_non_object", ["isSealed"]); |
| 799 } |
| 800 var names = ObjectGetOwnPropertyNames(obj); |
| 801 for (var key in names) { |
| 802 var name = names[key]; |
| 803 var desc = GetOwnProperty(obj, name); |
| 804 if (desc.isConfigurable()) return false; |
| 805 } |
| 806 if (!ObjectIsExtensible(obj)) { |
| 807 return true; |
| 808 } |
| 809 return false; |
| 810 } |
| 811 |
| 812 |
777 // ES5 section 15.2.3.12 | 813 // ES5 section 15.2.3.12 |
778 function ObjectIsFrozen(obj) { | 814 function ObjectIsFrozen(obj) { |
779 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) && | 815 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) && |
780 !IS_UNDETECTABLE(obj)) { | 816 !IS_UNDETECTABLE(obj)) { |
781 throw MakeTypeError("obj_ctor_property_non_object", ["isFrozen"]); | 817 throw MakeTypeError("obj_ctor_property_non_object", ["isFrozen"]); |
782 } | 818 } |
783 var names = ObjectGetOwnPropertyNames(obj); | 819 var names = ObjectGetOwnPropertyNames(obj); |
784 for (var key in names) { | 820 for (var key in names) { |
785 var name = names[key]; | 821 var name = names[key]; |
786 var desc = GetOwnProperty(obj, name); | 822 var desc = GetOwnProperty(obj, name); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
836 "keys", ObjectKeys, | 872 "keys", ObjectKeys, |
837 "create", ObjectCreate, | 873 "create", ObjectCreate, |
838 "defineProperty", ObjectDefineProperty, | 874 "defineProperty", ObjectDefineProperty, |
839 "defineProperties", ObjectDefineProperties, | 875 "defineProperties", ObjectDefineProperties, |
840 "freeze", ObjectFreeze, | 876 "freeze", ObjectFreeze, |
841 "getPrototypeOf", ObjectGetPrototypeOf, | 877 "getPrototypeOf", ObjectGetPrototypeOf, |
842 "getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor, | 878 "getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor, |
843 "getOwnPropertyNames", ObjectGetOwnPropertyNames, | 879 "getOwnPropertyNames", ObjectGetOwnPropertyNames, |
844 "isExtensible", ObjectIsExtensible, | 880 "isExtensible", ObjectIsExtensible, |
845 "isFrozen", ObjectIsFrozen, | 881 "isFrozen", ObjectIsFrozen, |
846 "preventExtensions", ObjectPreventExtension | 882 "isSealed", ObjectIsSealed, |
| 883 "preventExtensions", ObjectPreventExtension, |
| 884 "seal", ObjectSeal |
847 )); | 885 )); |
848 } | 886 } |
849 | 887 |
850 SetupObject(); | 888 SetupObject(); |
851 | 889 |
852 | 890 |
853 // ---------------------------------------------------------------------------- | 891 // ---------------------------------------------------------------------------- |
854 // Boolean | 892 // Boolean |
855 | 893 |
856 function BooleanToString() { | 894 function BooleanToString() { |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1104 | 1142 |
1105 // ---------------------------------------------------------------------------- | 1143 // ---------------------------------------------------------------------------- |
1106 | 1144 |
1107 function SetupFunction() { | 1145 function SetupFunction() { |
1108 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1146 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
1109 "toString", FunctionToString | 1147 "toString", FunctionToString |
1110 )); | 1148 )); |
1111 } | 1149 } |
1112 | 1150 |
1113 SetupFunction(); | 1151 SetupFunction(); |
OLD | NEW |