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 var $functionSourceString; | 5 var $functionSourceString; |
6 var $globalEval; | 6 var $globalEval; |
7 var $objectDefineOwnProperty; | 7 var $objectDefineOwnProperty; |
8 var $objectGetOwnPropertyDescriptor; | 8 var $objectGetOwnPropertyDescriptor; |
9 var $toCompletePropertyDescriptor; | 9 var $toCompletePropertyDescriptor; |
10 | 10 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 ]); | 134 ]); |
135 | 135 |
136 | 136 |
137 // ---------------------------------------------------------------------------- | 137 // ---------------------------------------------------------------------------- |
138 // Object | 138 // Object |
139 | 139 |
140 // ECMA-262 - 15.2.4.2 | 140 // ECMA-262 - 15.2.4.2 |
141 function ObjectToString() { | 141 function ObjectToString() { |
142 if (IS_UNDEFINED(this) && !IS_UNDETECTABLE(this)) return "[object Undefined]"; | 142 if (IS_UNDEFINED(this) && !IS_UNDETECTABLE(this)) return "[object Undefined]"; |
143 if (IS_NULL(this)) return "[object Null]"; | 143 if (IS_NULL(this)) return "[object Null]"; |
144 var O = TO_OBJECT_INLINE(this); | 144 var O = TO_OBJECT(this); |
145 var builtinTag = %_ClassOf(O); | 145 var builtinTag = %_ClassOf(O); |
146 var tag; | 146 var tag; |
147 | 147 |
148 // TODO(caitp): cannot wait to get rid of this flag :> | 148 // TODO(caitp): cannot wait to get rid of this flag :> |
149 if (harmony_tostring) { | 149 if (harmony_tostring) { |
150 tag = O[symbolToStringTag]; | 150 tag = O[symbolToStringTag]; |
151 if (!IS_STRING(tag)) { | 151 if (!IS_STRING(tag)) { |
152 tag = builtinTag; | 152 tag = builtinTag; |
153 } | 153 } |
154 } else { | 154 } else { |
155 tag = builtinTag; | 155 tag = builtinTag; |
156 } | 156 } |
157 | 157 |
158 return `[object ${tag}]`; | 158 return `[object ${tag}]`; |
159 } | 159 } |
160 | 160 |
161 | 161 |
162 // ECMA-262 - 15.2.4.3 | 162 // ECMA-262 - 15.2.4.3 |
163 function ObjectToLocaleString() { | 163 function ObjectToLocaleString() { |
164 CHECK_OBJECT_COERCIBLE(this, "Object.prototype.toLocaleString"); | 164 CHECK_OBJECT_COERCIBLE(this, "Object.prototype.toLocaleString"); |
165 return this.toString(); | 165 return this.toString(); |
166 } | 166 } |
167 | 167 |
168 | 168 |
169 // ECMA-262 - 15.2.4.4 | 169 // ECMA-262 - 15.2.4.4 |
170 function ObjectValueOf() { | 170 function ObjectValueOf() { |
171 return TO_OBJECT_INLINE(this); | 171 return TO_OBJECT(this); |
172 } | 172 } |
173 | 173 |
174 | 174 |
175 // ECMA-262 - 15.2.4.5 | 175 // ECMA-262 - 15.2.4.5 |
176 function ObjectHasOwnProperty(value) { | 176 function ObjectHasOwnProperty(value) { |
177 var name = $toName(value); | 177 var name = $toName(value); |
178 var object = TO_OBJECT_INLINE(this); | 178 var object = TO_OBJECT(this); |
179 | 179 |
180 if (%_IsJSProxy(object)) { | 180 if (%_IsJSProxy(object)) { |
181 // TODO(rossberg): adjust once there is a story for symbols vs proxies. | 181 // TODO(rossberg): adjust once there is a story for symbols vs proxies. |
182 if (IS_SYMBOL(value)) return false; | 182 if (IS_SYMBOL(value)) return false; |
183 | 183 |
184 var handler = %GetHandler(object); | 184 var handler = %GetHandler(object); |
185 return CallTrap1(handler, "hasOwn", ProxyDerivedHasOwnTrap, name); | 185 return CallTrap1(handler, "hasOwn", ProxyDerivedHasOwnTrap, name); |
186 } | 186 } |
187 return %HasOwnProperty(object, name); | 187 return %HasOwnProperty(object, name); |
188 } | 188 } |
(...skipping 10 matching lines...) Expand all Loading... |
199 // ECMA-262 - 15.2.4.6 | 199 // ECMA-262 - 15.2.4.6 |
200 function ObjectPropertyIsEnumerable(V) { | 200 function ObjectPropertyIsEnumerable(V) { |
201 var P = $toName(V); | 201 var P = $toName(V); |
202 if (%_IsJSProxy(this)) { | 202 if (%_IsJSProxy(this)) { |
203 // TODO(rossberg): adjust once there is a story for symbols vs proxies. | 203 // TODO(rossberg): adjust once there is a story for symbols vs proxies. |
204 if (IS_SYMBOL(V)) return false; | 204 if (IS_SYMBOL(V)) return false; |
205 | 205 |
206 var desc = GetOwnPropertyJS(this, P); | 206 var desc = GetOwnPropertyJS(this, P); |
207 return IS_UNDEFINED(desc) ? false : desc.isEnumerable(); | 207 return IS_UNDEFINED(desc) ? false : desc.isEnumerable(); |
208 } | 208 } |
209 return %IsPropertyEnumerable(TO_OBJECT_INLINE(this), P); | 209 return %IsPropertyEnumerable(TO_OBJECT(this), P); |
210 } | 210 } |
211 | 211 |
212 | 212 |
213 // Extensions for providing property getters and setters. | 213 // Extensions for providing property getters and setters. |
214 function ObjectDefineGetter(name, fun) { | 214 function ObjectDefineGetter(name, fun) { |
215 var receiver = this; | 215 var receiver = this; |
216 if (receiver == null && !IS_UNDETECTABLE(receiver)) { | 216 if (receiver == null && !IS_UNDETECTABLE(receiver)) { |
217 receiver = %GlobalProxy(ObjectDefineGetter); | 217 receiver = %GlobalProxy(ObjectDefineGetter); |
218 } | 218 } |
219 if (!IS_SPEC_FUNCTION(fun)) { | 219 if (!IS_SPEC_FUNCTION(fun)) { |
220 throw MakeTypeError(kObjectGetterExpectingFunction); | 220 throw MakeTypeError(kObjectGetterExpectingFunction); |
221 } | 221 } |
222 var desc = new PropertyDescriptor(); | 222 var desc = new PropertyDescriptor(); |
223 desc.setGet(fun); | 223 desc.setGet(fun); |
224 desc.setEnumerable(true); | 224 desc.setEnumerable(true); |
225 desc.setConfigurable(true); | 225 desc.setConfigurable(true); |
226 DefineOwnProperty(TO_OBJECT_INLINE(receiver), $toName(name), desc, false); | 226 DefineOwnProperty(TO_OBJECT(receiver), $toName(name), desc, false); |
227 } | 227 } |
228 | 228 |
229 | 229 |
230 function ObjectLookupGetter(name) { | 230 function ObjectLookupGetter(name) { |
231 var receiver = this; | 231 var receiver = this; |
232 if (receiver == null && !IS_UNDETECTABLE(receiver)) { | 232 if (receiver == null && !IS_UNDETECTABLE(receiver)) { |
233 receiver = %GlobalProxy(ObjectLookupGetter); | 233 receiver = %GlobalProxy(ObjectLookupGetter); |
234 } | 234 } |
235 return %LookupAccessor(TO_OBJECT_INLINE(receiver), $toName(name), GETTER); | 235 return %LookupAccessor(TO_OBJECT(receiver), $toName(name), GETTER); |
236 } | 236 } |
237 | 237 |
238 | 238 |
239 function ObjectDefineSetter(name, fun) { | 239 function ObjectDefineSetter(name, fun) { |
240 var receiver = this; | 240 var receiver = this; |
241 if (receiver == null && !IS_UNDETECTABLE(receiver)) { | 241 if (receiver == null && !IS_UNDETECTABLE(receiver)) { |
242 receiver = %GlobalProxy(ObjectDefineSetter); | 242 receiver = %GlobalProxy(ObjectDefineSetter); |
243 } | 243 } |
244 if (!IS_SPEC_FUNCTION(fun)) { | 244 if (!IS_SPEC_FUNCTION(fun)) { |
245 throw MakeTypeError(kObjectSetterExpectingFunction); | 245 throw MakeTypeError(kObjectSetterExpectingFunction); |
246 } | 246 } |
247 var desc = new PropertyDescriptor(); | 247 var desc = new PropertyDescriptor(); |
248 desc.setSet(fun); | 248 desc.setSet(fun); |
249 desc.setEnumerable(true); | 249 desc.setEnumerable(true); |
250 desc.setConfigurable(true); | 250 desc.setConfigurable(true); |
251 DefineOwnProperty(TO_OBJECT_INLINE(receiver), $toName(name), desc, false); | 251 DefineOwnProperty(TO_OBJECT(receiver), $toName(name), desc, false); |
252 } | 252 } |
253 | 253 |
254 | 254 |
255 function ObjectLookupSetter(name) { | 255 function ObjectLookupSetter(name) { |
256 var receiver = this; | 256 var receiver = this; |
257 if (receiver == null && !IS_UNDETECTABLE(receiver)) { | 257 if (receiver == null && !IS_UNDETECTABLE(receiver)) { |
258 receiver = %GlobalProxy(ObjectLookupSetter); | 258 receiver = %GlobalProxy(ObjectLookupSetter); |
259 } | 259 } |
260 return %LookupAccessor(TO_OBJECT_INLINE(receiver), $toName(name), SETTER); | 260 return %LookupAccessor(TO_OBJECT(receiver), $toName(name), SETTER); |
261 } | 261 } |
262 | 262 |
263 | 263 |
264 function ObjectKeys(obj) { | 264 function ObjectKeys(obj) { |
265 obj = TO_OBJECT_INLINE(obj); | 265 obj = TO_OBJECT(obj); |
266 if (%_IsJSProxy(obj)) { | 266 if (%_IsJSProxy(obj)) { |
267 var handler = %GetHandler(obj); | 267 var handler = %GetHandler(obj); |
268 var names = CallTrap0(handler, "keys", ProxyDerivedKeysTrap); | 268 var names = CallTrap0(handler, "keys", ProxyDerivedKeysTrap); |
269 return ToNameArray(names, "keys", false); | 269 return ToNameArray(names, "keys", false); |
270 } | 270 } |
271 return %OwnKeys(obj); | 271 return %OwnKeys(obj); |
272 } | 272 } |
273 | 273 |
274 | 274 |
275 // ES5 8.10.1. | 275 // ES5 8.10.1. |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 if (!desc.isConfigurable()) { | 572 if (!desc.isConfigurable()) { |
573 throw MakeTypeError(kProxyPropNotConfigurable, | 573 throw MakeTypeError(kProxyPropNotConfigurable, |
574 handler, p, "getOwnPropertyDescriptor"); | 574 handler, p, "getOwnPropertyDescriptor"); |
575 } | 575 } |
576 return desc; | 576 return desc; |
577 } | 577 } |
578 | 578 |
579 // GetOwnProperty returns an array indexed by the constants | 579 // GetOwnProperty returns an array indexed by the constants |
580 // defined in macros.py. | 580 // defined in macros.py. |
581 // If p is not a property on obj undefined is returned. | 581 // If p is not a property on obj undefined is returned. |
582 var props = %GetOwnProperty(TO_OBJECT_INLINE(obj), p); | 582 var props = %GetOwnProperty(TO_OBJECT(obj), p); |
583 | 583 |
584 return ConvertDescriptorArrayToDescriptor(props); | 584 return ConvertDescriptorArrayToDescriptor(props); |
585 } | 585 } |
586 | 586 |
587 | 587 |
588 // ES5 section 8.12.7. | 588 // ES5 section 8.12.7. |
589 function Delete(obj, p, should_throw) { | 589 function Delete(obj, p, should_throw) { |
590 var desc = GetOwnPropertyJS(obj, p); | 590 var desc = GetOwnPropertyJS(obj, p); |
591 if (IS_UNDEFINED(desc)) return true; | 591 if (IS_UNDEFINED(desc)) return true; |
592 if (desc.isConfigurable()) { | 592 if (desc.isConfigurable()) { |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
861 writable: desc[0], | 861 writable: desc[0], |
862 enumerable: desc[1], | 862 enumerable: desc[1], |
863 configurable: desc[2] | 863 configurable: desc[2] |
864 }), | 864 }), |
865 false); | 865 false); |
866 } | 866 } |
867 | 867 |
868 | 868 |
869 // ES6 section 19.1.2.9 | 869 // ES6 section 19.1.2.9 |
870 function ObjectGetPrototypeOf(obj) { | 870 function ObjectGetPrototypeOf(obj) { |
871 return %_GetPrototype(TO_OBJECT_INLINE(obj)); | 871 return %_GetPrototype(TO_OBJECT(obj)); |
872 } | 872 } |
873 | 873 |
874 // ES6 section 19.1.2.19. | 874 // ES6 section 19.1.2.19. |
875 function ObjectSetPrototypeOf(obj, proto) { | 875 function ObjectSetPrototypeOf(obj, proto) { |
876 CHECK_OBJECT_COERCIBLE(obj, "Object.setPrototypeOf"); | 876 CHECK_OBJECT_COERCIBLE(obj, "Object.setPrototypeOf"); |
877 | 877 |
878 if (proto !== null && !IS_SPEC_OBJECT(proto)) { | 878 if (proto !== null && !IS_SPEC_OBJECT(proto)) { |
879 throw MakeTypeError(kProtoObjectOrNull, proto); | 879 throw MakeTypeError(kProtoObjectOrNull, proto); |
880 } | 880 } |
881 | 881 |
882 if (IS_SPEC_OBJECT(obj)) { | 882 if (IS_SPEC_OBJECT(obj)) { |
883 %SetPrototype(obj, proto); | 883 %SetPrototype(obj, proto); |
884 } | 884 } |
885 | 885 |
886 return obj; | 886 return obj; |
887 } | 887 } |
888 | 888 |
889 | 889 |
890 // ES6 section 19.1.2.6 | 890 // ES6 section 19.1.2.6 |
891 function ObjectGetOwnPropertyDescriptor(obj, p) { | 891 function ObjectGetOwnPropertyDescriptor(obj, p) { |
892 var desc = GetOwnPropertyJS(TO_OBJECT_INLINE(obj), p); | 892 var desc = GetOwnPropertyJS(TO_OBJECT(obj), p); |
893 return FromPropertyDescriptor(desc); | 893 return FromPropertyDescriptor(desc); |
894 } | 894 } |
895 | 895 |
896 | 896 |
897 // For Harmony proxies | 897 // For Harmony proxies |
898 function ToNameArray(obj, trap, includeSymbols) { | 898 function ToNameArray(obj, trap, includeSymbols) { |
899 if (!IS_SPEC_OBJECT(obj)) { | 899 if (!IS_SPEC_OBJECT(obj)) { |
900 throw MakeTypeError(kProxyNonObjectPropNames, trap, obj); | 900 throw MakeTypeError(kProxyNonObjectPropNames, trap, obj); |
901 } | 901 } |
902 var n = $toUint32(obj.length); | 902 var n = $toUint32(obj.length); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
994 // without an implementation of Direct Proxies. | 994 // without an implementation of Direct Proxies. |
995 var names = CallTrap0(handler, "ownKeys", UNDEFINED); | 995 var names = CallTrap0(handler, "ownKeys", UNDEFINED); |
996 return ToNameArray(names, "getOwnPropertyNames", false); | 996 return ToNameArray(names, "getOwnPropertyNames", false); |
997 } | 997 } |
998 return ObjectGetOwnPropertyKeys(obj, PROPERTY_ATTRIBUTES_PRIVATE_SYMBOL); | 998 return ObjectGetOwnPropertyKeys(obj, PROPERTY_ATTRIBUTES_PRIVATE_SYMBOL); |
999 } | 999 } |
1000 | 1000 |
1001 | 1001 |
1002 // ES5 section 15.2.3.4. | 1002 // ES5 section 15.2.3.4. |
1003 function ObjectGetOwnPropertyNames(obj) { | 1003 function ObjectGetOwnPropertyNames(obj) { |
1004 obj = TO_OBJECT_INLINE(obj); | 1004 obj = TO_OBJECT(obj); |
1005 // Special handling for proxies. | 1005 // Special handling for proxies. |
1006 if (%_IsJSProxy(obj)) { | 1006 if (%_IsJSProxy(obj)) { |
1007 var handler = %GetHandler(obj); | 1007 var handler = %GetHandler(obj); |
1008 var names = CallTrap0(handler, "getOwnPropertyNames", UNDEFINED); | 1008 var names = CallTrap0(handler, "getOwnPropertyNames", UNDEFINED); |
1009 return ToNameArray(names, "getOwnPropertyNames", false); | 1009 return ToNameArray(names, "getOwnPropertyNames", false); |
1010 } | 1010 } |
1011 | 1011 |
1012 return ObjectGetOwnPropertyKeys(obj, PROPERTY_ATTRIBUTES_SYMBOLIC); | 1012 return ObjectGetOwnPropertyKeys(obj, PROPERTY_ATTRIBUTES_SYMBOLIC); |
1013 } | 1013 } |
1014 | 1014 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1086 | 1086 |
1087 return names; | 1087 return names; |
1088 } | 1088 } |
1089 | 1089 |
1090 | 1090 |
1091 // ES5 section 15.2.3.7. | 1091 // ES5 section 15.2.3.7. |
1092 function ObjectDefineProperties(obj, properties) { | 1092 function ObjectDefineProperties(obj, properties) { |
1093 if (!IS_SPEC_OBJECT(obj)) { | 1093 if (!IS_SPEC_OBJECT(obj)) { |
1094 throw MakeTypeError(kCalledOnNonObject, "Object.defineProperties"); | 1094 throw MakeTypeError(kCalledOnNonObject, "Object.defineProperties"); |
1095 } | 1095 } |
1096 var props = TO_OBJECT_INLINE(properties); | 1096 var props = TO_OBJECT(properties); |
1097 var names = GetOwnEnumerablePropertyNames(props); | 1097 var names = GetOwnEnumerablePropertyNames(props); |
1098 var descriptors = new InternalArray(); | 1098 var descriptors = new InternalArray(); |
1099 for (var i = 0; i < names.length; i++) { | 1099 for (var i = 0; i < names.length; i++) { |
1100 descriptors.push(ToPropertyDescriptor(props[names[i]])); | 1100 descriptors.push(ToPropertyDescriptor(props[names[i]])); |
1101 } | 1101 } |
1102 for (var i = 0; i < names.length; i++) { | 1102 for (var i = 0; i < names.length; i++) { |
1103 DefineOwnProperty(obj, names[i], descriptors[i], true); | 1103 DefineOwnProperty(obj, names[i], descriptors[i], true); |
1104 } | 1104 } |
1105 return obj; | 1105 return obj; |
1106 } | 1106 } |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1256 | 1256 |
1257 | 1257 |
1258 // ECMA-262, Edition 6, section 19.1.2.10 | 1258 // ECMA-262, Edition 6, section 19.1.2.10 |
1259 function ObjectIs(obj1, obj2) { | 1259 function ObjectIs(obj1, obj2) { |
1260 return $sameValue(obj1, obj2); | 1260 return $sameValue(obj1, obj2); |
1261 } | 1261 } |
1262 | 1262 |
1263 | 1263 |
1264 // ECMA-262, Edition 6, section B.2.2.1.1 | 1264 // ECMA-262, Edition 6, section B.2.2.1.1 |
1265 function ObjectGetProto() { | 1265 function ObjectGetProto() { |
1266 return %_GetPrototype(TO_OBJECT_INLINE(this)); | 1266 return %_GetPrototype(TO_OBJECT(this)); |
1267 } | 1267 } |
1268 | 1268 |
1269 | 1269 |
1270 // ECMA-262, Edition 6, section B.2.2.1.2 | 1270 // ECMA-262, Edition 6, section B.2.2.1.2 |
1271 function ObjectSetProto(proto) { | 1271 function ObjectSetProto(proto) { |
1272 CHECK_OBJECT_COERCIBLE(this, "Object.prototype.__proto__"); | 1272 CHECK_OBJECT_COERCIBLE(this, "Object.prototype.__proto__"); |
1273 | 1273 |
1274 if ((IS_SPEC_OBJECT(proto) || IS_NULL(proto)) && IS_SPEC_OBJECT(this)) { | 1274 if ((IS_SPEC_OBJECT(proto) || IS_NULL(proto)) && IS_SPEC_OBJECT(this)) { |
1275 %SetPrototype(this, proto); | 1275 %SetPrototype(this, proto); |
1276 } | 1276 } |
1277 } | 1277 } |
1278 | 1278 |
1279 | 1279 |
1280 function ObjectConstructor(x) { | 1280 function ObjectConstructor(x) { |
1281 if (%_IsConstructCall()) { | 1281 if (%_IsConstructCall()) { |
1282 if (x == null) return this; | 1282 if (x == null) return this; |
1283 return TO_OBJECT_INLINE(x); | 1283 return TO_OBJECT(x); |
1284 } else { | 1284 } else { |
1285 if (x == null) return { }; | 1285 if (x == null) return { }; |
1286 return TO_OBJECT_INLINE(x); | 1286 return TO_OBJECT(x); |
1287 } | 1287 } |
1288 } | 1288 } |
1289 | 1289 |
1290 | 1290 |
1291 // ---------------------------------------------------------------------------- | 1291 // ---------------------------------------------------------------------------- |
1292 // Object | 1292 // Object |
1293 | 1293 |
1294 %SetNativeFlag(GlobalObject); | 1294 %SetNativeFlag(GlobalObject); |
1295 %SetCode(GlobalObject, ObjectConstructor); | 1295 %SetCode(GlobalObject, ObjectConstructor); |
1296 | 1296 |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1808 to.ObjectGetOwnPropertyKeys = ObjectGetOwnPropertyKeys; | 1808 to.ObjectGetOwnPropertyKeys = ObjectGetOwnPropertyKeys; |
1809 to.ObjectHasOwnProperty = ObjectHasOwnProperty; | 1809 to.ObjectHasOwnProperty = ObjectHasOwnProperty; |
1810 to.ObjectIsFrozen = ObjectIsFrozen; | 1810 to.ObjectIsFrozen = ObjectIsFrozen; |
1811 to.ObjectIsSealed = ObjectIsSealed; | 1811 to.ObjectIsSealed = ObjectIsSealed; |
1812 to.ObjectToString = ObjectToString; | 1812 to.ObjectToString = ObjectToString; |
1813 to.OwnPropertyKeys = OwnPropertyKeys; | 1813 to.OwnPropertyKeys = OwnPropertyKeys; |
1814 to.ToNameArray = ToNameArray; | 1814 to.ToNameArray = ToNameArray; |
1815 }); | 1815 }); |
1816 | 1816 |
1817 }) | 1817 }) |
OLD | NEW |