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