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 992 matching lines...) Loading... |
1003 } | 1003 } |
1004 var obj = {}; | 1004 var obj = {}; |
1005 %InternalSetPrototype(obj, proto); | 1005 %InternalSetPrototype(obj, proto); |
1006 if (!IS_UNDEFINED(properties)) ObjectDefineProperties(obj, properties); | 1006 if (!IS_UNDEFINED(properties)) ObjectDefineProperties(obj, properties); |
1007 return obj; | 1007 return obj; |
1008 } | 1008 } |
1009 | 1009 |
1010 | 1010 |
1011 // ES5 section 15.2.3.6. | 1011 // ES5 section 15.2.3.6. |
1012 function ObjectDefineProperty(obj, p, attributes) { | 1012 function ObjectDefineProperty(obj, p, attributes) { |
1013 // The new pure-C++ implementation doesn't support Proxies yet, nor O.o. | 1013 // The new pure-C++ implementation doesn't support O.o. |
1014 // TODO(jkummerow): Implement missing features and remove fallback path. | 1014 // TODO(jkummerow): Implement missing features and remove fallback path. |
1015 if (%_IsJSProxy(obj) || %IsObserved(obj)) { | 1015 if (%IsObserved(obj)) { |
1016 if (!IS_SPEC_OBJECT(obj)) { | 1016 if (!IS_SPEC_OBJECT(obj)) { |
1017 throw MakeTypeError(kCalledOnNonObject, "Object.defineProperty"); | 1017 throw MakeTypeError(kCalledOnNonObject, "Object.defineProperty"); |
1018 } | 1018 } |
1019 var name = TO_NAME(p); | 1019 var name = TO_NAME(p); |
1020 if (%_IsJSProxy(obj)) { | 1020 var desc = ToPropertyDescriptor(attributes); |
1021 // Clone the attributes object for protection. | 1021 DefineOwnProperty(obj, name, desc, true); |
1022 // TODO(rossberg): not spec'ed yet, so not sure if this should involve | |
1023 // non-own properties as it does (or non-enumerable ones, as it doesn't?). | |
1024 var attributesClone = { __proto__: null }; | |
1025 for (var a in attributes) { | |
1026 attributesClone[a] = attributes[a]; | |
1027 } | |
1028 DefineProxyProperty(obj, name, attributesClone, true); | |
1029 // The following would implement the spec as in the current proposal, | |
1030 // but after recent comments on es-discuss, is most likely obsolete. | |
1031 /* | |
1032 var defineObj = FromGenericPropertyDescriptor(desc); | |
1033 var names = ObjectGetOwnPropertyNames(attributes); | |
1034 var standardNames = | |
1035 {value: 0, writable: 0, get: 0, set: 0, enumerable: 0, configurable: 0}; | |
1036 for (var i = 0; i < names.length; i++) { | |
1037 var N = names[i]; | |
1038 if (!(%HasOwnProperty(standardNames, N))) { | |
1039 var attr = GetOwnPropertyJS(attributes, N); | |
1040 DefineOwnProperty(descObj, N, attr, true); | |
1041 } | |
1042 } | |
1043 // This is really confusing the types, but it is what the proxies spec | |
1044 // currently requires: | |
1045 desc = descObj; | |
1046 */ | |
1047 } else { | |
1048 var desc = ToPropertyDescriptor(attributes); | |
1049 DefineOwnProperty(obj, name, desc, true); | |
1050 } | |
1051 return obj; | 1022 return obj; |
1052 } | 1023 } |
1053 return %ObjectDefineProperty(obj, p, attributes); | 1024 return %ObjectDefineProperty(obj, p, attributes); |
1054 } | 1025 } |
1055 | 1026 |
1056 | 1027 |
1057 function GetOwnEnumerablePropertyNames(object) { | 1028 function GetOwnEnumerablePropertyNames(object) { |
1058 var names = new InternalArray(); | 1029 var names = new InternalArray(); |
1059 for (var key in object) { | 1030 for (var key in object) { |
1060 if (%HasOwnProperty(object, key)) { | 1031 if (%HasOwnProperty(object, key)) { |
(...skipping 10 matching lines...) Loading... |
1071 if (desc.enumerable) names.push(symbol); | 1042 if (desc.enumerable) names.push(symbol); |
1072 } | 1043 } |
1073 } | 1044 } |
1074 | 1045 |
1075 return names; | 1046 return names; |
1076 } | 1047 } |
1077 | 1048 |
1078 | 1049 |
1079 // ES5 section 15.2.3.7. | 1050 // ES5 section 15.2.3.7. |
1080 function ObjectDefineProperties(obj, properties) { | 1051 function ObjectDefineProperties(obj, properties) { |
1081 // The new pure-C++ implementation doesn't support Proxies yet, nor O.o. | 1052 // The new pure-C++ implementation doesn't support O.o. |
1082 // TODO(jkummerow): Implement missing features and remove fallback path. | 1053 // TODO(jkummerow): Implement missing features and remove fallback path. |
1083 if (%_IsJSProxy(obj) || %_IsJSProxy(properties) || %IsObserved(obj)) { | 1054 if (%IsObserved(obj)) { |
1084 if (!IS_SPEC_OBJECT(obj)) { | 1055 if (!IS_SPEC_OBJECT(obj)) { |
1085 throw MakeTypeError(kCalledOnNonObject, "Object.defineProperties"); | 1056 throw MakeTypeError(kCalledOnNonObject, "Object.defineProperties"); |
1086 } | 1057 } |
1087 var props = TO_OBJECT(properties); | 1058 var props = TO_OBJECT(properties); |
1088 var names = GetOwnEnumerablePropertyNames(props); | 1059 var names = GetOwnEnumerablePropertyNames(props); |
1089 var descriptors = new InternalArray(); | 1060 var descriptors = new InternalArray(); |
1090 for (var i = 0; i < names.length; i++) { | 1061 for (var i = 0; i < names.length; i++) { |
1091 descriptors.push(ToPropertyDescriptor(props[names[i]])); | 1062 descriptors.push(ToPropertyDescriptor(props[names[i]])); |
1092 } | 1063 } |
1093 for (var i = 0; i < names.length; i++) { | 1064 for (var i = 0; i < names.length; i++) { |
(...skipping 700 matching lines...) Loading... |
1794 | 1765 |
1795 %InstallToContext([ | 1766 %InstallToContext([ |
1796 "global_eval_fun", GlobalEval, | 1767 "global_eval_fun", GlobalEval, |
1797 "object_value_of", ObjectValueOf, | 1768 "object_value_of", ObjectValueOf, |
1798 "object_to_string", ObjectToString, | 1769 "object_to_string", ObjectToString, |
1799 "object_get_own_property_descriptor", ObjectGetOwnPropertyDescriptor, | 1770 "object_get_own_property_descriptor", ObjectGetOwnPropertyDescriptor, |
1800 "to_complete_property_descriptor", ToCompletePropertyDescriptor, | 1771 "to_complete_property_descriptor", ToCompletePropertyDescriptor, |
1801 ]); | 1772 ]); |
1802 | 1773 |
1803 }) | 1774 }) |
OLD | NEW |