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 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1024 } | 1024 } |
1025 var obj = {}; | 1025 var obj = {}; |
1026 %InternalSetPrototype(obj, proto); | 1026 %InternalSetPrototype(obj, proto); |
1027 if (!IS_UNDEFINED(properties)) ObjectDefineProperties(obj, properties); | 1027 if (!IS_UNDEFINED(properties)) ObjectDefineProperties(obj, properties); |
1028 return obj; | 1028 return obj; |
1029 } | 1029 } |
1030 | 1030 |
1031 | 1031 |
1032 // ES5 section 15.2.3.6. | 1032 // ES5 section 15.2.3.6. |
1033 function ObjectDefineProperty(obj, p, attributes) { | 1033 function ObjectDefineProperty(obj, p, attributes) { |
1034 if (!IS_SPEC_OBJECT(obj)) { | 1034 // The new pure-C++ implementation doesn't support Proxies yet, nor O.o. |
1035 throw MakeTypeError(kCalledOnNonObject, "Object.defineProperty"); | 1035 // TODO(jkummerow): Implement missing features and remove fallback path. |
1036 if (%_IsJSProxy(obj) || %IsObserved(obj)) { | |
Jakob Kummerow
2015/10/15 13:54:26
This line is new; the body of the if-block is the
| |
1037 if (!IS_SPEC_OBJECT(obj)) { | |
1038 throw MakeTypeError(kCalledOnNonObject, "Object.defineProperty"); | |
1039 } | |
1040 var name = TO_NAME(p); | |
1041 if (%_IsJSProxy(obj)) { | |
1042 // Clone the attributes object for protection. | |
1043 // TODO(rossberg): not spec'ed yet, so not sure if this should involve | |
1044 // non-own properties as it does (or non-enumerable ones, as it doesn't?). | |
1045 var attributesClone = { __proto__: null }; | |
1046 for (var a in attributes) { | |
1047 attributesClone[a] = attributes[a]; | |
1048 } | |
1049 DefineProxyProperty(obj, name, attributesClone, true); | |
1050 // The following would implement the spec as in the current proposal, | |
1051 // but after recent comments on es-discuss, is most likely obsolete. | |
1052 /* | |
1053 var defineObj = FromGenericPropertyDescriptor(desc); | |
1054 var names = ObjectGetOwnPropertyNames(attributes); | |
1055 var standardNames = | |
1056 {value: 0, writable: 0, get: 0, set: 0, enumerable: 0, configurable: 0}; | |
1057 for (var i = 0; i < names.length; i++) { | |
1058 var N = names[i]; | |
1059 if (!(%HasOwnProperty(standardNames, N))) { | |
1060 var attr = GetOwnPropertyJS(attributes, N); | |
1061 DefineOwnProperty(descObj, N, attr, true); | |
1062 } | |
1063 } | |
1064 // This is really confusing the types, but it is what the proxies spec | |
1065 // currently requires: | |
1066 desc = descObj; | |
1067 */ | |
1068 } else { | |
1069 var desc = ToPropertyDescriptor(attributes); | |
1070 DefineOwnProperty(obj, name, desc, true); | |
1071 } | |
1072 return obj; | |
1036 } | 1073 } |
1037 var name = TO_NAME(p); | 1074 return %ObjectDefineProperty(obj, p, attributes); |
1038 if (%_IsJSProxy(obj)) { | |
1039 // Clone the attributes object for protection. | |
1040 // TODO(rossberg): not spec'ed yet, so not sure if this should involve | |
1041 // non-own properties as it does (or non-enumerable ones, as it doesn't?). | |
1042 var attributesClone = { __proto__: null }; | |
1043 for (var a in attributes) { | |
1044 attributesClone[a] = attributes[a]; | |
1045 } | |
1046 DefineProxyProperty(obj, name, attributesClone, true); | |
1047 // The following would implement the spec as in the current proposal, | |
1048 // but after recent comments on es-discuss, is most likely obsolete. | |
1049 /* | |
1050 var defineObj = FromGenericPropertyDescriptor(desc); | |
1051 var names = ObjectGetOwnPropertyNames(attributes); | |
1052 var standardNames = | |
1053 {value: 0, writable: 0, get: 0, set: 0, enumerable: 0, configurable: 0}; | |
1054 for (var i = 0; i < names.length; i++) { | |
1055 var N = names[i]; | |
1056 if (!(%HasOwnProperty(standardNames, N))) { | |
1057 var attr = GetOwnPropertyJS(attributes, N); | |
1058 DefineOwnProperty(descObj, N, attr, true); | |
1059 } | |
1060 } | |
1061 // This is really confusing the types, but it is what the proxies spec | |
1062 // currently requires: | |
1063 desc = descObj; | |
1064 */ | |
1065 } else { | |
1066 var desc = ToPropertyDescriptor(attributes); | |
1067 DefineOwnProperty(obj, name, desc, true); | |
1068 } | |
1069 return obj; | |
1070 } | 1075 } |
1071 | 1076 |
1072 | 1077 |
1073 function GetOwnEnumerablePropertyNames(object) { | 1078 function GetOwnEnumerablePropertyNames(object) { |
1074 var names = new InternalArray(); | 1079 var names = new InternalArray(); |
1075 for (var key in object) { | 1080 for (var key in object) { |
1076 if (%HasOwnProperty(object, key)) { | 1081 if (%HasOwnProperty(object, key)) { |
1077 names.push(key); | 1082 names.push(key); |
1078 } | 1083 } |
1079 } | 1084 } |
1080 | 1085 |
1081 var filter = PROPERTY_ATTRIBUTES_STRING | PROPERTY_ATTRIBUTES_PRIVATE_SYMBOL; | 1086 var filter = PROPERTY_ATTRIBUTES_STRING | PROPERTY_ATTRIBUTES_PRIVATE_SYMBOL; |
1082 var symbols = %GetOwnPropertyNames(object, filter); | 1087 var symbols = %GetOwnPropertyNames(object, filter); |
1083 for (var i = 0; i < symbols.length; ++i) { | 1088 for (var i = 0; i < symbols.length; ++i) { |
1084 var symbol = symbols[i]; | 1089 var symbol = symbols[i]; |
1085 if (IS_SYMBOL(symbol)) { | 1090 if (IS_SYMBOL(symbol)) { |
1086 var desc = ObjectGetOwnPropertyDescriptor(object, symbol); | 1091 var desc = ObjectGetOwnPropertyDescriptor(object, symbol); |
1087 if (desc.enumerable) names.push(symbol); | 1092 if (desc.enumerable) names.push(symbol); |
1088 } | 1093 } |
1089 } | 1094 } |
1090 | 1095 |
1091 return names; | 1096 return names; |
1092 } | 1097 } |
1093 | 1098 |
1094 | 1099 |
1095 // ES5 section 15.2.3.7. | 1100 // ES5 section 15.2.3.7. |
1096 function ObjectDefineProperties(obj, properties) { | 1101 function ObjectDefineProperties(obj, properties) { |
1097 if (!IS_SPEC_OBJECT(obj)) { | 1102 // The new pure-C++ implementation doesn't support Proxies yet, nor O.o. |
1098 throw MakeTypeError(kCalledOnNonObject, "Object.defineProperties"); | 1103 // TODO(jkummerow): Implement missing features and remove fallback path. |
1104 if (%_IsJSProxy(obj) || %_IsJSProxy(properties) || %IsObserved(obj)) { | |
Jakob Kummerow
2015/10/15 13:54:26
Same here: this line is new, the body of the block
| |
1105 if (!IS_SPEC_OBJECT(obj)) { | |
1106 throw MakeTypeError(kCalledOnNonObject, "Object.defineProperties"); | |
1107 } | |
1108 var props = TO_OBJECT(properties); | |
1109 var names = GetOwnEnumerablePropertyNames(props); | |
1110 var descriptors = new InternalArray(); | |
1111 for (var i = 0; i < names.length; i++) { | |
1112 descriptors.push(ToPropertyDescriptor(props[names[i]])); | |
1113 } | |
1114 for (var i = 0; i < names.length; i++) { | |
1115 DefineOwnProperty(obj, names[i], descriptors[i], true); | |
1116 } | |
1117 return obj; | |
1099 } | 1118 } |
1100 var props = TO_OBJECT(properties); | 1119 return %ObjectDefineProperties(obj, properties); |
1101 var names = GetOwnEnumerablePropertyNames(props); | |
1102 var descriptors = new InternalArray(); | |
1103 for (var i = 0; i < names.length; i++) { | |
1104 descriptors.push(ToPropertyDescriptor(props[names[i]])); | |
1105 } | |
1106 for (var i = 0; i < names.length; i++) { | |
1107 DefineOwnProperty(obj, names[i], descriptors[i], true); | |
1108 } | |
1109 return obj; | |
1110 } | 1120 } |
1111 | 1121 |
1112 | 1122 |
1113 // Harmony proxies. | 1123 // Harmony proxies. |
1114 function ProxyFix(obj) { | 1124 function ProxyFix(obj) { |
1115 var handler = %GetHandler(obj); | 1125 var handler = %GetHandler(obj); |
1116 var props = CallTrap0(handler, "fix", UNDEFINED); | 1126 var props = CallTrap0(handler, "fix", UNDEFINED); |
1117 if (IS_UNDEFINED(props)) { | 1127 if (IS_UNDEFINED(props)) { |
1118 throw MakeTypeError(kProxyHandlerReturned, handler, "undefined", "fix"); | 1128 throw MakeTypeError(kProxyHandlerReturned, handler, "undefined", "fix"); |
1119 } | 1129 } |
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1848 %InstallToContext([ | 1858 %InstallToContext([ |
1849 "global_eval_fun", GlobalEval, | 1859 "global_eval_fun", GlobalEval, |
1850 "object_value_of", ObjectValueOf, | 1860 "object_value_of", ObjectValueOf, |
1851 "object_to_string", ObjectToString, | 1861 "object_to_string", ObjectToString, |
1852 "object_define_own_property", DefineOwnPropertyFromAPI, | 1862 "object_define_own_property", DefineOwnPropertyFromAPI, |
1853 "object_get_own_property_descriptor", ObjectGetOwnPropertyDescriptor, | 1863 "object_get_own_property_descriptor", ObjectGetOwnPropertyDescriptor, |
1854 "to_complete_property_descriptor", ToCompletePropertyDescriptor, | 1864 "to_complete_property_descriptor", ToCompletePropertyDescriptor, |
1855 ]); | 1865 ]); |
1856 | 1866 |
1857 }) | 1867 }) |
OLD | NEW |