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 // This file relies on the fact that the following declarations have been made | 5 // This file relies on the fact that the following declarations have been made |
6 // in runtime.js: | 6 // in runtime.js: |
7 // var $Object = global.Object; | 7 // var $Object = global.Object; |
8 // var $Boolean = global.Boolean; | 8 // var $Boolean = global.Boolean; |
9 // var $Number = global.Number; | 9 // var $Number = global.Number; |
10 // var $Function = global.Function; | 10 // var $Function = global.Function; |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 | 211 |
212 | 212 |
213 // ---------------------------------------------------------------------------- | 213 // ---------------------------------------------------------------------------- |
214 // Object | 214 // Object |
215 | 215 |
216 var DefaultObjectToString = NoSideEffectsObjectToString; | 216 var DefaultObjectToString = NoSideEffectsObjectToString; |
217 // ECMA-262 - 15.2.4.2 | 217 // ECMA-262 - 15.2.4.2 |
218 function NoSideEffectsObjectToString() { | 218 function NoSideEffectsObjectToString() { |
219 if (IS_UNDEFINED(this) && !IS_UNDETECTABLE(this)) return "[object Undefined]"; | 219 if (IS_UNDEFINED(this) && !IS_UNDETECTABLE(this)) return "[object Undefined]"; |
220 if (IS_NULL(this)) return "[object Null]"; | 220 if (IS_NULL(this)) return "[object Null]"; |
221 return "[object " + %_ClassOf(ToObject(this)) + "]"; | 221 return "[object " + %_ClassOf(TO_OBJECT_INLINE(this)) + "]"; |
222 } | 222 } |
223 | 223 |
224 | 224 |
225 // ECMA-262 - 15.2.4.3 | 225 // ECMA-262 - 15.2.4.3 |
226 function ObjectToLocaleString() { | 226 function ObjectToLocaleString() { |
227 CHECK_OBJECT_COERCIBLE(this, "Object.prototype.toLocaleString"); | 227 CHECK_OBJECT_COERCIBLE(this, "Object.prototype.toLocaleString"); |
228 return this.toString(); | 228 return this.toString(); |
229 } | 229 } |
230 | 230 |
231 | 231 |
232 // ECMA-262 - 15.2.4.4 | 232 // ECMA-262 - 15.2.4.4 |
233 function ObjectValueOf() { | 233 function ObjectValueOf() { |
234 return ToObject(this); | 234 return TO_OBJECT_INLINE(this); |
235 } | 235 } |
236 | 236 |
237 | 237 |
238 // ECMA-262 - 15.2.4.5 | 238 // ECMA-262 - 15.2.4.5 |
239 function ObjectHasOwnProperty(V) { | 239 function ObjectHasOwnProperty(V) { |
240 if (%_IsJSProxy(this)) { | 240 if (%_IsJSProxy(this)) { |
241 // TODO(rossberg): adjust once there is a story for symbols vs proxies. | 241 // TODO(rossberg): adjust once there is a story for symbols vs proxies. |
242 if (IS_SYMBOL(V)) return false; | 242 if (IS_SYMBOL(V)) return false; |
243 | 243 |
244 var handler = %GetHandler(this); | 244 var handler = %GetHandler(this); |
(...skipping 14 matching lines...) Expand all Loading... |
259 // ECMA-262 - 15.2.4.6 | 259 // ECMA-262 - 15.2.4.6 |
260 function ObjectPropertyIsEnumerable(V) { | 260 function ObjectPropertyIsEnumerable(V) { |
261 var P = ToName(V); | 261 var P = ToName(V); |
262 if (%_IsJSProxy(this)) { | 262 if (%_IsJSProxy(this)) { |
263 // TODO(rossberg): adjust once there is a story for symbols vs proxies. | 263 // TODO(rossberg): adjust once there is a story for symbols vs proxies. |
264 if (IS_SYMBOL(V)) return false; | 264 if (IS_SYMBOL(V)) return false; |
265 | 265 |
266 var desc = GetOwnPropertyJS(this, P); | 266 var desc = GetOwnPropertyJS(this, P); |
267 return IS_UNDEFINED(desc) ? false : desc.isEnumerable(); | 267 return IS_UNDEFINED(desc) ? false : desc.isEnumerable(); |
268 } | 268 } |
269 return %IsPropertyEnumerable(ToObject(this), P); | 269 return %IsPropertyEnumerable(TO_OBJECT_INLINE(this), P); |
270 } | 270 } |
271 | 271 |
272 | 272 |
273 // Extensions for providing property getters and setters. | 273 // Extensions for providing property getters and setters. |
274 function ObjectDefineGetter(name, fun) { | 274 function ObjectDefineGetter(name, fun) { |
275 var receiver = this; | 275 var receiver = this; |
276 if (receiver == null && !IS_UNDETECTABLE(receiver)) { | 276 if (receiver == null && !IS_UNDETECTABLE(receiver)) { |
277 receiver = %GlobalProxy(global); | 277 receiver = %GlobalProxy(global); |
278 } | 278 } |
279 if (!IS_SPEC_FUNCTION(fun)) { | 279 if (!IS_SPEC_FUNCTION(fun)) { |
280 throw new $TypeError( | 280 throw new $TypeError( |
281 'Object.prototype.__defineGetter__: Expecting function'); | 281 'Object.prototype.__defineGetter__: Expecting function'); |
282 } | 282 } |
283 var desc = new PropertyDescriptor(); | 283 var desc = new PropertyDescriptor(); |
284 desc.setGet(fun); | 284 desc.setGet(fun); |
285 desc.setEnumerable(true); | 285 desc.setEnumerable(true); |
286 desc.setConfigurable(true); | 286 desc.setConfigurable(true); |
287 DefineOwnProperty(ToObject(receiver), ToName(name), desc, false); | 287 DefineOwnProperty(TO_OBJECT_INLINE(receiver), ToName(name), desc, false); |
288 } | 288 } |
289 | 289 |
290 | 290 |
291 function ObjectLookupGetter(name) { | 291 function ObjectLookupGetter(name) { |
292 var receiver = this; | 292 var receiver = this; |
293 if (receiver == null && !IS_UNDETECTABLE(receiver)) { | 293 if (receiver == null && !IS_UNDETECTABLE(receiver)) { |
294 receiver = %GlobalProxy(global); | 294 receiver = %GlobalProxy(global); |
295 } | 295 } |
296 return %LookupAccessor(ToObject(receiver), ToName(name), GETTER); | 296 return %LookupAccessor(TO_OBJECT_INLINE(receiver), ToName(name), GETTER); |
297 } | 297 } |
298 | 298 |
299 | 299 |
300 function ObjectDefineSetter(name, fun) { | 300 function ObjectDefineSetter(name, fun) { |
301 var receiver = this; | 301 var receiver = this; |
302 if (receiver == null && !IS_UNDETECTABLE(receiver)) { | 302 if (receiver == null && !IS_UNDETECTABLE(receiver)) { |
303 receiver = %GlobalProxy(global); | 303 receiver = %GlobalProxy(global); |
304 } | 304 } |
305 if (!IS_SPEC_FUNCTION(fun)) { | 305 if (!IS_SPEC_FUNCTION(fun)) { |
306 throw new $TypeError( | 306 throw new $TypeError( |
307 'Object.prototype.__defineSetter__: Expecting function'); | 307 'Object.prototype.__defineSetter__: Expecting function'); |
308 } | 308 } |
309 var desc = new PropertyDescriptor(); | 309 var desc = new PropertyDescriptor(); |
310 desc.setSet(fun); | 310 desc.setSet(fun); |
311 desc.setEnumerable(true); | 311 desc.setEnumerable(true); |
312 desc.setConfigurable(true); | 312 desc.setConfigurable(true); |
313 DefineOwnProperty(ToObject(receiver), ToName(name), desc, false); | 313 DefineOwnProperty(TO_OBJECT_INLINE(receiver), ToName(name), desc, false); |
314 } | 314 } |
315 | 315 |
316 | 316 |
317 function ObjectLookupSetter(name) { | 317 function ObjectLookupSetter(name) { |
318 var receiver = this; | 318 var receiver = this; |
319 if (receiver == null && !IS_UNDETECTABLE(receiver)) { | 319 if (receiver == null && !IS_UNDETECTABLE(receiver)) { |
320 receiver = %GlobalProxy(global); | 320 receiver = %GlobalProxy(global); |
321 } | 321 } |
322 return %LookupAccessor(ToObject(receiver), ToName(name), SETTER); | 322 return %LookupAccessor(TO_OBJECT_INLINE(receiver), ToName(name), SETTER); |
323 } | 323 } |
324 | 324 |
325 | 325 |
326 function ObjectKeys(obj) { | 326 function ObjectKeys(obj) { |
327 obj = ToObject(obj); | 327 obj = TO_OBJECT_INLINE(obj); |
328 if (%_IsJSProxy(obj)) { | 328 if (%_IsJSProxy(obj)) { |
329 var handler = %GetHandler(obj); | 329 var handler = %GetHandler(obj); |
330 var names = CallTrap0(handler, "keys", DerivedKeysTrap); | 330 var names = CallTrap0(handler, "keys", DerivedKeysTrap); |
331 return ToNameArray(names, "keys", false); | 331 return ToNameArray(names, "keys", false); |
332 } | 332 } |
333 return %OwnKeys(obj); | 333 return %OwnKeys(obj); |
334 } | 334 } |
335 | 335 |
336 | 336 |
337 // ES5 8.10.1. | 337 // ES5 8.10.1. |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 if (!desc.isConfigurable()) { | 634 if (!desc.isConfigurable()) { |
635 throw MakeTypeError("proxy_prop_not_configurable", | 635 throw MakeTypeError("proxy_prop_not_configurable", |
636 [handler, "getOwnPropertyDescriptor", p, descriptor]); | 636 [handler, "getOwnPropertyDescriptor", p, descriptor]); |
637 } | 637 } |
638 return desc; | 638 return desc; |
639 } | 639 } |
640 | 640 |
641 // GetOwnProperty returns an array indexed by the constants | 641 // GetOwnProperty returns an array indexed by the constants |
642 // defined in macros.py. | 642 // defined in macros.py. |
643 // If p is not a property on obj undefined is returned. | 643 // If p is not a property on obj undefined is returned. |
644 var props = %GetOwnProperty(ToObject(obj), p); | 644 var props = %GetOwnProperty(TO_OBJECT_INLINE(obj), p); |
645 | 645 |
646 return ConvertDescriptorArrayToDescriptor(props); | 646 return ConvertDescriptorArrayToDescriptor(props); |
647 } | 647 } |
648 | 648 |
649 | 649 |
650 // ES5 section 8.12.7. | 650 // ES5 section 8.12.7. |
651 function Delete(obj, p, should_throw) { | 651 function Delete(obj, p, should_throw) { |
652 var desc = GetOwnPropertyJS(obj, p); | 652 var desc = GetOwnPropertyJS(obj, p); |
653 if (IS_UNDEFINED(desc)) return true; | 653 if (IS_UNDEFINED(desc)) return true; |
654 if (desc.isConfigurable()) { | 654 if (desc.isConfigurable()) { |
(...skipping 30 matching lines...) Expand all Loading... |
685 } else { | 685 } else { |
686 return false; | 686 return false; |
687 } | 687 } |
688 } | 688 } |
689 return true; | 689 return true; |
690 } | 690 } |
691 | 691 |
692 | 692 |
693 // ES5 8.12.9. | 693 // ES5 8.12.9. |
694 function DefineObjectProperty(obj, p, desc, should_throw) { | 694 function DefineObjectProperty(obj, p, desc, should_throw) { |
695 var current_array = %GetOwnProperty(ToObject(obj), ToName(p)); | 695 var current_array = %GetOwnProperty(obj, ToName(p)); |
696 var current = ConvertDescriptorArrayToDescriptor(current_array); | 696 var current = ConvertDescriptorArrayToDescriptor(current_array); |
697 var extensible = %IsExtensible(ToObject(obj)); | 697 var extensible = %IsExtensible(obj); |
698 | 698 |
699 // Error handling according to spec. | 699 // Error handling according to spec. |
700 // Step 3 | 700 // Step 3 |
701 if (IS_UNDEFINED(current) && !extensible) { | 701 if (IS_UNDEFINED(current) && !extensible) { |
702 if (should_throw) { | 702 if (should_throw) { |
703 throw MakeTypeError("define_disallowed", [p]); | 703 throw MakeTypeError("define_disallowed", [p]); |
704 } else { | 704 } else { |
705 return false; | 705 return false; |
706 } | 706 } |
707 } | 707 } |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1098 } | 1098 } |
1099 propertyNames.length = j; | 1099 propertyNames.length = j; |
1100 } | 1100 } |
1101 | 1101 |
1102 return propertyNames; | 1102 return propertyNames; |
1103 } | 1103 } |
1104 | 1104 |
1105 | 1105 |
1106 // ES5 section 15.2.3.4. | 1106 // ES5 section 15.2.3.4. |
1107 function ObjectGetOwnPropertyNames(obj) { | 1107 function ObjectGetOwnPropertyNames(obj) { |
1108 obj = ToObject(obj); | 1108 obj = TO_OBJECT_INLINE(obj); |
1109 // Special handling for proxies. | 1109 // Special handling for proxies. |
1110 if (%_IsJSProxy(obj)) { | 1110 if (%_IsJSProxy(obj)) { |
1111 var handler = %GetHandler(obj); | 1111 var handler = %GetHandler(obj); |
1112 var names = CallTrap0(handler, "getOwnPropertyNames", UNDEFINED); | 1112 var names = CallTrap0(handler, "getOwnPropertyNames", UNDEFINED); |
1113 return ToNameArray(names, "getOwnPropertyNames", false); | 1113 return ToNameArray(names, "getOwnPropertyNames", false); |
1114 } | 1114 } |
1115 | 1115 |
1116 return ObjectGetOwnPropertyKeys(obj, PROPERTY_ATTRIBUTES_SYMBOLIC); | 1116 return ObjectGetOwnPropertyKeys(obj, PROPERTY_ATTRIBUTES_SYMBOLIC); |
1117 } | 1117 } |
1118 | 1118 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1190 | 1190 |
1191 return names; | 1191 return names; |
1192 } | 1192 } |
1193 | 1193 |
1194 | 1194 |
1195 // ES5 section 15.2.3.7. | 1195 // ES5 section 15.2.3.7. |
1196 function ObjectDefineProperties(obj, properties) { | 1196 function ObjectDefineProperties(obj, properties) { |
1197 if (!IS_SPEC_OBJECT(obj)) { | 1197 if (!IS_SPEC_OBJECT(obj)) { |
1198 throw MakeTypeError("called_on_non_object", ["Object.defineProperties"]); | 1198 throw MakeTypeError("called_on_non_object", ["Object.defineProperties"]); |
1199 } | 1199 } |
1200 var props = ToObject(properties); | 1200 var props = TO_OBJECT_INLINE(properties); |
1201 var names = GetOwnEnumerablePropertyNames(props); | 1201 var names = GetOwnEnumerablePropertyNames(props); |
1202 var descriptors = new InternalArray(); | 1202 var descriptors = new InternalArray(); |
1203 for (var i = 0; i < names.length; i++) { | 1203 for (var i = 0; i < names.length; i++) { |
1204 descriptors.push(ToPropertyDescriptor(props[names[i]])); | 1204 descriptors.push(ToPropertyDescriptor(props[names[i]])); |
1205 } | 1205 } |
1206 for (var i = 0; i < names.length; i++) { | 1206 for (var i = 0; i < names.length; i++) { |
1207 DefineOwnProperty(obj, names[i], descriptors[i], true); | 1207 DefineOwnProperty(obj, names[i], descriptors[i], true); |
1208 } | 1208 } |
1209 return obj; | 1209 return obj; |
1210 } | 1210 } |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1369 | 1369 |
1370 | 1370 |
1371 // ECMA-262, Edition 6, section 19.1.2.10 | 1371 // ECMA-262, Edition 6, section 19.1.2.10 |
1372 function ObjectIs(obj1, obj2) { | 1372 function ObjectIs(obj1, obj2) { |
1373 return SameValue(obj1, obj2); | 1373 return SameValue(obj1, obj2); |
1374 } | 1374 } |
1375 | 1375 |
1376 | 1376 |
1377 // ECMA-262, Edition 6, section B.2.2.1.1 | 1377 // ECMA-262, Edition 6, section B.2.2.1.1 |
1378 function ObjectGetProto() { | 1378 function ObjectGetProto() { |
1379 return %_GetPrototype(ToObject(this)); | 1379 return %_GetPrototype(TO_OBJECT_INLINE(this)); |
1380 } | 1380 } |
1381 | 1381 |
1382 | 1382 |
1383 // ECMA-262, Edition 6, section B.2.2.1.2 | 1383 // ECMA-262, Edition 6, section B.2.2.1.2 |
1384 function ObjectSetProto(proto) { | 1384 function ObjectSetProto(proto) { |
1385 CHECK_OBJECT_COERCIBLE(this, "Object.prototype.__proto__"); | 1385 CHECK_OBJECT_COERCIBLE(this, "Object.prototype.__proto__"); |
1386 | 1386 |
1387 if ((IS_SPEC_OBJECT(proto) || IS_NULL(proto)) && IS_SPEC_OBJECT(this)) { | 1387 if ((IS_SPEC_OBJECT(proto) || IS_NULL(proto)) && IS_SPEC_OBJECT(this)) { |
1388 %SetPrototype(this, proto); | 1388 %SetPrototype(this, proto); |
1389 } | 1389 } |
1390 } | 1390 } |
1391 | 1391 |
1392 | 1392 |
1393 function ObjectConstructor(x) { | 1393 function ObjectConstructor(x) { |
1394 if (%_IsConstructCall()) { | 1394 if (%_IsConstructCall()) { |
1395 if (x == null) return this; | 1395 if (x == null) return this; |
1396 return ToObject(x); | 1396 return TO_OBJECT_INLINE(x); |
1397 } else { | 1397 } else { |
1398 if (x == null) return { }; | 1398 if (x == null) return { }; |
1399 return ToObject(x); | 1399 return TO_OBJECT_INLINE(x); |
1400 } | 1400 } |
1401 } | 1401 } |
1402 | 1402 |
1403 | 1403 |
1404 // ---------------------------------------------------------------------------- | 1404 // ---------------------------------------------------------------------------- |
1405 // Object | 1405 // Object |
1406 | 1406 |
1407 function SetUpObject() { | 1407 function SetUpObject() { |
1408 %CheckIsBootstrapping(); | 1408 %CheckIsBootstrapping(); |
1409 | 1409 |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1894 } | 1894 } |
1895 if (!IS_SPEC_FUNCTION(method)) { | 1895 if (!IS_SPEC_FUNCTION(method)) { |
1896 throw MakeTypeError('not_iterable', [obj]); | 1896 throw MakeTypeError('not_iterable', [obj]); |
1897 } | 1897 } |
1898 var iterator = %_CallFunction(obj, method); | 1898 var iterator = %_CallFunction(obj, method); |
1899 if (!IS_SPEC_OBJECT(iterator)) { | 1899 if (!IS_SPEC_OBJECT(iterator)) { |
1900 throw MakeTypeError('not_an_iterator', [iterator]); | 1900 throw MakeTypeError('not_an_iterator', [iterator]); |
1901 } | 1901 } |
1902 return iterator; | 1902 return iterator; |
1903 } | 1903 } |
OLD | NEW |