OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 (function(global, utils) { | 5 (function(global, utils) { |
6 | 6 |
7 %CheckIsBootstrapping(); | 7 %CheckIsBootstrapping(); |
8 | 8 |
9 // ---------------------------------------------------------------------------- | 9 // ---------------------------------------------------------------------------- |
10 // Imports | 10 // Imports |
(...skipping 908 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
919 } | 919 } |
920 for (var i = 0; i < names.length; i++) { | 920 for (var i = 0; i < names.length; i++) { |
921 DefineOwnProperty(obj, names[i], descriptors[i], true); | 921 DefineOwnProperty(obj, names[i], descriptors[i], true); |
922 } | 922 } |
923 return obj; | 923 return obj; |
924 } | 924 } |
925 return %ObjectDefineProperties(obj, properties); | 925 return %ObjectDefineProperties(obj, properties); |
926 } | 926 } |
927 | 927 |
928 | 928 |
929 // ES5 section 15.2.3.8. | 929 // ES6 19.1.2.17 |
930 function ObjectSealJS(obj) { | 930 function ObjectSealJS(obj) { |
931 if (!IS_SPEC_OBJECT(obj)) return obj; | 931 if (!IS_SPEC_OBJECT(obj)) return obj; |
932 var isProxy = %_IsJSProxy(obj); | 932 return %ObjectSeal(obj); |
933 if (isProxy || %HasSloppyArgumentsElements(obj) || %IsObserved(obj)) { | |
934 // TODO(neis): For proxies, must call preventExtensions trap first. | |
935 var names = OwnPropertyKeys(obj); | |
936 for (var i = 0; i < names.length; i++) { | |
937 var name = names[i]; | |
938 var desc = GetOwnPropertyJS(obj, name); | |
939 if (desc.isConfigurable()) { | |
940 desc.setConfigurable(false); | |
941 DefineOwnProperty(obj, name, desc, true); | |
942 } | |
943 } | |
944 %PreventExtensions(obj); | |
945 } else { | |
946 // TODO(adamk): Is it worth going to this fast path if the | |
947 // object's properties are already in dictionary mode? | |
948 %ObjectSeal(obj); | |
949 } | |
950 return obj; | |
951 } | 933 } |
952 | 934 |
953 | 935 |
954 // ES5 section 15.2.3.9. | 936 // ES6 19.1.2.5 |
955 function ObjectFreezeJS(obj) { | 937 function ObjectFreezeJS(obj) { |
956 if (!IS_SPEC_OBJECT(obj)) return obj; | 938 if (!IS_SPEC_OBJECT(obj)) return obj; |
957 var isProxy = %_IsJSProxy(obj); | 939 return %ObjectFreeze(obj); |
958 // TODO(conradw): Investigate modifying the fast path to accommodate strong | |
959 // objects. | |
960 if (isProxy || %HasSloppyArgumentsElements(obj) || %IsObserved(obj) || | |
961 IS_STRONG(obj)) { | |
962 // TODO(neis): For proxies, must call preventExtensions trap first. | |
963 var names = OwnPropertyKeys(obj); | |
964 for (var i = 0; i < names.length; i++) { | |
965 var name = names[i]; | |
966 var desc = GetOwnPropertyJS(obj, name); | |
967 if (desc.isWritable() || desc.isConfigurable()) { | |
968 if (IsDataDescriptor(desc)) desc.setWritable(false); | |
969 desc.setConfigurable(false); | |
970 DefineOwnProperty(obj, name, desc, true); | |
971 } | |
972 } | |
973 %PreventExtensions(obj); | |
974 } else { | |
975 // TODO(adamk): Is it worth going to this fast path if the | |
976 // object's properties are already in dictionary mode? | |
977 %ObjectFreeze(obj); | |
978 } | |
979 return obj; | |
980 } | 940 } |
981 | 941 |
982 | 942 |
983 // ES5 section 15.2.3.10 | 943 // ES6 19.1.2.15 |
984 function ObjectPreventExtension(obj) { | 944 function ObjectPreventExtension(obj) { |
985 if (!IS_SPEC_OBJECT(obj)) return obj; | 945 if (!IS_SPEC_OBJECT(obj)) return obj; |
986 return %PreventExtensions(obj); | 946 return %PreventExtensions(obj); |
987 } | 947 } |
988 | 948 |
989 | 949 |
990 // ES5 section 15.2.3.11 | 950 // ES6 19.1.2.13 |
991 function ObjectIsSealed(obj) { | 951 function ObjectIsSealed(obj) { |
992 if (!IS_SPEC_OBJECT(obj)) return true; | 952 if (!IS_SPEC_OBJECT(obj)) return true; |
993 if (%_IsJSProxy(obj)) { | 953 return %ObjectIsSealed(obj); |
994 return false; // TODO(neis): Must call isExtensible trap and ownKeys trap. | |
995 } | |
996 if (%IsExtensible(obj)) { | |
997 return false; | |
998 } | |
999 var names = OwnPropertyKeys(obj); | |
1000 for (var i = 0; i < names.length; i++) { | |
1001 var name = names[i]; | |
1002 var desc = GetOwnPropertyJS(obj, name); | |
1003 if (desc.isConfigurable()) { | |
1004 return false; | |
1005 } | |
1006 } | |
1007 return true; | |
1008 } | 954 } |
1009 | 955 |
1010 | 956 |
1011 // ES5 section 15.2.3.12 | 957 // ES6 19.1.2.12 |
1012 function ObjectIsFrozen(obj) { | 958 function ObjectIsFrozen(obj) { |
1013 if (!IS_SPEC_OBJECT(obj)) return true; | 959 if (!IS_SPEC_OBJECT(obj)) return true; |
1014 if (%_IsJSProxy(obj)) { | 960 return %ObjectIsFrozen(obj); |
1015 return false; // TODO(neis): Must call isExtensible trap and ownKeys trap. | |
1016 } | |
1017 if (%IsExtensible(obj)) { | |
1018 return false; | |
1019 } | |
1020 var names = OwnPropertyKeys(obj); | |
1021 for (var i = 0; i < names.length; i++) { | |
1022 var name = names[i]; | |
1023 var desc = GetOwnPropertyJS(obj, name); | |
1024 if (IsDataDescriptor(desc) && desc.isWritable()) return false; | |
1025 if (desc.isConfigurable()) return false; | |
1026 } | |
1027 return true; | |
1028 } | 961 } |
1029 | 962 |
1030 | 963 |
1031 // ES5 section 15.2.3.13 | 964 // ES6 19.1.2.11 |
1032 function ObjectIsExtensible(obj) { | 965 function ObjectIsExtensible(obj) { |
1033 if (!IS_SPEC_OBJECT(obj)) return false; | 966 if (!IS_SPEC_OBJECT(obj)) return false; |
1034 return %IsExtensible(obj); | 967 return %IsExtensible(obj); |
1035 } | 968 } |
1036 | 969 |
1037 | 970 |
1038 // ECMA-262, Edition 6, section 19.1.2.1 | 971 // ECMA-262, Edition 6, section 19.1.2.1 |
1039 function ObjectAssign(target, sources) { | 972 function ObjectAssign(target, sources) { |
1040 // TODO(bmeurer): Move this to toplevel. | 973 // TODO(bmeurer): Move this to toplevel. |
1041 "use strict"; | 974 "use strict"; |
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1612 | 1545 |
1613 %InstallToContext([ | 1546 %InstallToContext([ |
1614 "global_eval_fun", GlobalEval, | 1547 "global_eval_fun", GlobalEval, |
1615 "object_value_of", ObjectValueOf, | 1548 "object_value_of", ObjectValueOf, |
1616 "object_to_string", ObjectToString, | 1549 "object_to_string", ObjectToString, |
1617 "object_get_own_property_descriptor", ObjectGetOwnPropertyDescriptor, | 1550 "object_get_own_property_descriptor", ObjectGetOwnPropertyDescriptor, |
1618 "to_complete_property_descriptor", ToCompletePropertyDescriptor, | 1551 "to_complete_property_descriptor", ToCompletePropertyDescriptor, |
1619 ]); | 1552 ]); |
1620 | 1553 |
1621 }) | 1554 }) |
OLD | NEW |