| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 // ECMA-262 - 15.2.4.2 | 240 // ECMA-262 - 15.2.4.2 |
| 241 function ObjectToString() { | 241 function ObjectToString() { |
| 242 if (IS_UNDEFINED(this) && !IS_UNDETECTABLE(this)) return "[object Undefined]"; | 242 if (IS_UNDEFINED(this) && !IS_UNDETECTABLE(this)) return "[object Undefined]"; |
| 243 if (IS_NULL(this)) return "[object Null]"; | 243 if (IS_NULL(this)) return "[object Null]"; |
| 244 return "[object " + %_ClassOf(ToObject(this)) + "]"; | 244 return "[object " + %_ClassOf(ToObject(this)) + "]"; |
| 245 } | 245 } |
| 246 | 246 |
| 247 | 247 |
| 248 // ECMA-262 - 15.2.4.3 | 248 // ECMA-262 - 15.2.4.3 |
| 249 function ObjectToLocaleString() { | 249 function ObjectToLocaleString() { |
| 250 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 250 CHECK_OBJECT_COERCIBLE(this, "Object.prototype.toLocaleString"); |
| 251 throw MakeTypeError("called_on_null_or_undefined", | |
| 252 ["Object.prototype.toLocaleString"]); | |
| 253 } | |
| 254 return this.toString(); | 251 return this.toString(); |
| 255 } | 252 } |
| 256 | 253 |
| 257 | 254 |
| 258 // ECMA-262 - 15.2.4.4 | 255 // ECMA-262 - 15.2.4.4 |
| 259 function ObjectValueOf() { | 256 function ObjectValueOf() { |
| 260 return ToObject(this); | 257 return ToObject(this); |
| 261 } | 258 } |
| 262 | 259 |
| 263 | 260 |
| 264 // ECMA-262 - 15.2.4.5 | 261 // ECMA-262 - 15.2.4.5 |
| 265 function ObjectHasOwnProperty(V) { | 262 function ObjectHasOwnProperty(V) { |
| 266 if (%IsJSProxy(this)) { | 263 if (%IsJSProxy(this)) { |
| 267 // TODO(rossberg): adjust once there is a story for symbols vs proxies. | 264 // TODO(rossberg): adjust once there is a story for symbols vs proxies. |
| 268 if (IS_SYMBOL(V)) return false; | 265 if (IS_SYMBOL(V)) return false; |
| 269 | 266 |
| 270 var handler = %GetHandler(this); | 267 var handler = %GetHandler(this); |
| 271 return CallTrap1(handler, "hasOwn", DerivedHasOwnTrap, ToName(V)); | 268 return CallTrap1(handler, "hasOwn", DerivedHasOwnTrap, ToName(V)); |
| 272 } | 269 } |
| 273 return %HasLocalProperty(TO_OBJECT_INLINE(this), ToName(V)); | 270 return %HasLocalProperty(TO_OBJECT_INLINE(this), ToName(V)); |
| 274 } | 271 } |
| 275 | 272 |
| 276 | 273 |
| 277 // ECMA-262 - 15.2.4.6 | 274 // ECMA-262 - 15.2.4.6 |
| 278 function ObjectIsPrototypeOf(V) { | 275 function ObjectIsPrototypeOf(V) { |
| 279 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 276 CHECK_OBJECT_COERCIBLE(this, "Object.prototype.isPrototypeOf"); |
| 280 throw MakeTypeError("called_on_null_or_undefined", | |
| 281 ["Object.prototype.isPrototypeOf"]); | |
| 282 } | |
| 283 if (!IS_SPEC_OBJECT(V)) return false; | 277 if (!IS_SPEC_OBJECT(V)) return false; |
| 284 return %IsInPrototypeChain(this, V); | 278 return %IsInPrototypeChain(this, V); |
| 285 } | 279 } |
| 286 | 280 |
| 287 | 281 |
| 288 // ECMA-262 - 15.2.4.6 | 282 // ECMA-262 - 15.2.4.6 |
| 289 function ObjectPropertyIsEnumerable(V) { | 283 function ObjectPropertyIsEnumerable(V) { |
| 290 var P = ToName(V); | 284 var P = ToName(V); |
| 291 if (%IsJSProxy(this)) { | 285 if (%IsJSProxy(this)) { |
| 292 // TODO(rossberg): adjust once there is a story for symbols vs proxies. | 286 // TODO(rossberg): adjust once there is a story for symbols vs proxies. |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 if (IS_UNDEFINED(desc)) return desc; | 390 if (IS_UNDEFINED(desc)) return desc; |
| 397 | 391 |
| 398 if (IsDataDescriptor(desc)) { | 392 if (IsDataDescriptor(desc)) { |
| 399 return { value: desc.getValue(), | 393 return { value: desc.getValue(), |
| 400 writable: desc.isWritable(), | 394 writable: desc.isWritable(), |
| 401 enumerable: desc.isEnumerable(), | 395 enumerable: desc.isEnumerable(), |
| 402 configurable: desc.isConfigurable() }; | 396 configurable: desc.isConfigurable() }; |
| 403 } | 397 } |
| 404 // Must be an AccessorDescriptor then. We never return a generic descriptor. | 398 // Must be an AccessorDescriptor then. We never return a generic descriptor. |
| 405 return { get: desc.getGet(), | 399 return { get: desc.getGet(), |
| 406 set: desc.getSet() === ObjectSetProto ? ObjectPoisonProto | 400 set: desc.getSet(), |
| 407 : desc.getSet(), | |
| 408 enumerable: desc.isEnumerable(), | 401 enumerable: desc.isEnumerable(), |
| 409 configurable: desc.isConfigurable() }; | 402 configurable: desc.isConfigurable() }; |
| 410 } | 403 } |
| 411 | 404 |
| 412 | 405 |
| 413 // Harmony Proxies | 406 // Harmony Proxies |
| 414 function FromGenericPropertyDescriptor(desc) { | 407 function FromGenericPropertyDescriptor(desc) { |
| 415 if (IS_UNDEFINED(desc)) return desc; | 408 if (IS_UNDEFINED(desc)) return desc; |
| 416 var obj = new $Object(); | 409 var obj = new $Object(); |
| 417 | 410 |
| (...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1008 | 1001 |
| 1009 | 1002 |
| 1010 // ES5 section 15.2.3.2. | 1003 // ES5 section 15.2.3.2. |
| 1011 function ObjectGetPrototypeOf(obj) { | 1004 function ObjectGetPrototypeOf(obj) { |
| 1012 if (!IS_SPEC_OBJECT(obj)) { | 1005 if (!IS_SPEC_OBJECT(obj)) { |
| 1013 throw MakeTypeError("called_on_non_object", ["Object.getPrototypeOf"]); | 1006 throw MakeTypeError("called_on_non_object", ["Object.getPrototypeOf"]); |
| 1014 } | 1007 } |
| 1015 return %GetPrototype(obj); | 1008 return %GetPrototype(obj); |
| 1016 } | 1009 } |
| 1017 | 1010 |
| 1011 // ES6 section 19.1.2.19. |
| 1012 function ObjectSetPrototypeOf(obj, proto) { |
| 1013 CHECK_OBJECT_COERCIBLE(obj, "Object.setPrototypeOf"); |
| 1014 |
| 1015 if (proto !== null && !IS_SPEC_OBJECT(proto)) { |
| 1016 throw MakeTypeError("proto_object_or_null", [proto]); |
| 1017 } |
| 1018 |
| 1019 if (IS_SPEC_OBJECT(obj)) { |
| 1020 %SetPrototype(obj, proto); |
| 1021 } |
| 1022 |
| 1023 return obj; |
| 1024 } |
| 1025 |
| 1018 | 1026 |
| 1019 // ES5 section 15.2.3.3 | 1027 // ES5 section 15.2.3.3 |
| 1020 function ObjectGetOwnPropertyDescriptor(obj, p) { | 1028 function ObjectGetOwnPropertyDescriptor(obj, p) { |
| 1021 if (!IS_SPEC_OBJECT(obj)) { | 1029 if (!IS_SPEC_OBJECT(obj)) { |
| 1022 throw MakeTypeError("called_on_non_object", | 1030 throw MakeTypeError("called_on_non_object", |
| 1023 ["Object.getOwnPropertyDescriptor"]); | 1031 ["Object.getOwnPropertyDescriptor"]); |
| 1024 } | 1032 } |
| 1025 var desc = GetOwnProperty(obj, p); | 1033 var desc = GetOwnProperty(obj, p); |
| 1026 return FromPropertyDescriptor(desc); | 1034 return FromPropertyDescriptor(desc); |
| 1027 } | 1035 } |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1369 // Harmony egal. | 1377 // Harmony egal. |
| 1370 function ObjectIs(obj1, obj2) { | 1378 function ObjectIs(obj1, obj2) { |
| 1371 if (obj1 === obj2) { | 1379 if (obj1 === obj2) { |
| 1372 return (obj1 !== 0) || (1 / obj1 === 1 / obj2); | 1380 return (obj1 !== 0) || (1 / obj1 === 1 / obj2); |
| 1373 } else { | 1381 } else { |
| 1374 return (obj1 !== obj1) && (obj2 !== obj2); | 1382 return (obj1 !== obj1) && (obj2 !== obj2); |
| 1375 } | 1383 } |
| 1376 } | 1384 } |
| 1377 | 1385 |
| 1378 | 1386 |
| 1379 // Harmony __proto__ getter. | 1387 // ECMA-262, Edition 6, section B.2.2.1.1 |
| 1380 function ObjectGetProto() { | 1388 function ObjectGetProto() { |
| 1381 return %GetPrototype(this); | 1389 return %GetPrototype(ToObject(this)); |
| 1382 } | 1390 } |
| 1383 | 1391 |
| 1384 | 1392 |
| 1385 // Harmony __proto__ setter. | 1393 // ECMA-262, Edition 6, section B.2.2.1.2 |
| 1386 function ObjectSetProto(obj) { | 1394 function ObjectSetProto(proto) { |
| 1387 return %SetPrototype(this, obj); | 1395 CHECK_OBJECT_COERCIBLE(this, "Object.prototype.__proto__"); |
| 1396 |
| 1397 if (IS_SPEC_OBJECT(proto) || IS_NULL(proto) && IS_SPEC_OBJECT(this)) { |
| 1398 %SetPrototype(this, proto); |
| 1399 } |
| 1388 } | 1400 } |
| 1389 | 1401 |
| 1390 | 1402 |
| 1391 // Harmony __proto__ poison pill. | |
| 1392 function ObjectPoisonProto(obj) { | |
| 1393 throw MakeTypeError("proto_poison_pill", []); | |
| 1394 } | |
| 1395 | |
| 1396 | |
| 1397 function ObjectConstructor(x) { | 1403 function ObjectConstructor(x) { |
| 1398 if (%_IsConstructCall()) { | 1404 if (%_IsConstructCall()) { |
| 1399 if (x == null) return this; | 1405 if (x == null) return this; |
| 1400 return ToObject(x); | 1406 return ToObject(x); |
| 1401 } else { | 1407 } else { |
| 1402 if (x == null) return { }; | 1408 if (x == null) return { }; |
| 1403 return ToObject(x); | 1409 return ToObject(x); |
| 1404 } | 1410 } |
| 1405 } | 1411 } |
| 1406 | 1412 |
| 1407 | 1413 |
| 1408 // ---------------------------------------------------------------------------- | 1414 // ---------------------------------------------------------------------------- |
| 1409 // Object | 1415 // Object |
| 1410 | 1416 |
| 1411 function SetUpObject() { | 1417 function SetUpObject() { |
| 1412 %CheckIsBootstrapping(); | 1418 %CheckIsBootstrapping(); |
| 1413 | 1419 |
| 1414 %SetNativeFlag($Object); | 1420 %SetNativeFlag($Object); |
| 1415 %SetCode($Object, ObjectConstructor); | 1421 %SetCode($Object, ObjectConstructor); |
| 1416 %FunctionSetName(ObjectPoisonProto, "__proto__"); | |
| 1417 %FunctionRemovePrototype(ObjectPoisonProto); | |
| 1418 %SetExpectedNumberOfProperties($Object, 4); | 1422 %SetExpectedNumberOfProperties($Object, 4); |
| 1419 | 1423 |
| 1420 %SetProperty($Object.prototype, "constructor", $Object, DONT_ENUM); | 1424 %SetProperty($Object.prototype, "constructor", $Object, DONT_ENUM); |
| 1421 | 1425 |
| 1422 // Set up non-enumerable functions on the Object.prototype object. | 1426 // Set up non-enumerable functions on the Object.prototype object. |
| 1423 InstallFunctions($Object.prototype, DONT_ENUM, $Array( | 1427 InstallFunctions($Object.prototype, DONT_ENUM, $Array( |
| 1424 "toString", ObjectToString, | 1428 "toString", ObjectToString, |
| 1425 "toLocaleString", ObjectToLocaleString, | 1429 "toLocaleString", ObjectToLocaleString, |
| 1426 "valueOf", ObjectValueOf, | 1430 "valueOf", ObjectValueOf, |
| 1427 "hasOwnProperty", ObjectHasOwnProperty, | 1431 "hasOwnProperty", ObjectHasOwnProperty, |
| 1428 "isPrototypeOf", ObjectIsPrototypeOf, | 1432 "isPrototypeOf", ObjectIsPrototypeOf, |
| 1429 "propertyIsEnumerable", ObjectPropertyIsEnumerable, | 1433 "propertyIsEnumerable", ObjectPropertyIsEnumerable, |
| 1430 "__defineGetter__", ObjectDefineGetter, | 1434 "__defineGetter__", ObjectDefineGetter, |
| 1431 "__lookupGetter__", ObjectLookupGetter, | 1435 "__lookupGetter__", ObjectLookupGetter, |
| 1432 "__defineSetter__", ObjectDefineSetter, | 1436 "__defineSetter__", ObjectDefineSetter, |
| 1433 "__lookupSetter__", ObjectLookupSetter | 1437 "__lookupSetter__", ObjectLookupSetter |
| 1434 )); | 1438 )); |
| 1435 InstallGetterSetter($Object.prototype, "__proto__", | 1439 InstallGetterSetter($Object.prototype, "__proto__", |
| 1436 ObjectGetProto, ObjectSetProto); | 1440 ObjectGetProto, ObjectSetProto); |
| 1437 | 1441 |
| 1438 // Set up non-enumerable functions in the Object object. | 1442 // Set up non-enumerable functions in the Object object. |
| 1439 InstallFunctions($Object, DONT_ENUM, $Array( | 1443 InstallFunctions($Object, DONT_ENUM, $Array( |
| 1440 "keys", ObjectKeys, | 1444 "keys", ObjectKeys, |
| 1441 "create", ObjectCreate, | 1445 "create", ObjectCreate, |
| 1442 "defineProperty", ObjectDefineProperty, | 1446 "defineProperty", ObjectDefineProperty, |
| 1443 "defineProperties", ObjectDefineProperties, | 1447 "defineProperties", ObjectDefineProperties, |
| 1444 "freeze", ObjectFreeze, | 1448 "freeze", ObjectFreeze, |
| 1445 "getPrototypeOf", ObjectGetPrototypeOf, | 1449 "getPrototypeOf", ObjectGetPrototypeOf, |
| 1450 "setPrototypeOf", ObjectSetPrototypeOf, |
| 1446 "getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor, | 1451 "getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor, |
| 1447 "getOwnPropertyNames", ObjectGetOwnPropertyNames, | 1452 "getOwnPropertyNames", ObjectGetOwnPropertyNames, |
| 1448 // getOwnPropertySymbols is added in symbol.js. | 1453 // getOwnPropertySymbols is added in symbol.js. |
| 1449 "is", ObjectIs, | 1454 "is", ObjectIs, |
| 1450 "isExtensible", ObjectIsExtensible, | 1455 "isExtensible", ObjectIsExtensible, |
| 1451 "isFrozen", ObjectIsFrozen, | 1456 "isFrozen", ObjectIsFrozen, |
| 1452 "isSealed", ObjectIsSealed, | 1457 "isSealed", ObjectIsSealed, |
| 1453 "preventExtensions", ObjectPreventExtension, | 1458 "preventExtensions", ObjectPreventExtension, |
| 1454 "seal", ObjectSeal | 1459 "seal", ObjectSeal |
| 1455 // deliverChangeRecords, getNotifier, observe and unobserve are added | 1460 // deliverChangeRecords, getNotifier, observe and unobserve are added |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1881 | 1886 |
| 1882 SetUpFunction(); | 1887 SetUpFunction(); |
| 1883 | 1888 |
| 1884 | 1889 |
| 1885 //---------------------------------------------------------------------------- | 1890 //---------------------------------------------------------------------------- |
| 1886 | 1891 |
| 1887 // TODO(rossberg): very simple abstraction for generic microtask queue. | 1892 // TODO(rossberg): very simple abstraction for generic microtask queue. |
| 1888 // Eventually, we should move to a real event queue that allows to maintain | 1893 // Eventually, we should move to a real event queue that allows to maintain |
| 1889 // relative ordering of different kinds of tasks. | 1894 // relative ordering of different kinds of tasks. |
| 1890 | 1895 |
| 1891 RunMicrotasks.runners = new InternalArray; | 1896 function GetMicrotaskQueue() { |
| 1897 var microtaskState = %GetMicrotaskState(); |
| 1898 if (IS_UNDEFINED(microtaskState.queue)) { |
| 1899 microtaskState.queue = new InternalArray; |
| 1900 } |
| 1901 return microtaskState.queue; |
| 1902 } |
| 1892 | 1903 |
| 1893 function RunMicrotasks() { | 1904 function RunMicrotasks() { |
| 1894 while (%SetMicrotaskPending(false)) { | 1905 while (%SetMicrotaskPending(false)) { |
| 1895 for (var i in RunMicrotasks.runners) RunMicrotasks.runners[i](); | 1906 var microtaskState = %GetMicrotaskState(); |
| 1907 if (IS_UNDEFINED(microtaskState.queue)) |
| 1908 return; |
| 1909 |
| 1910 var microtasks = microtaskState.queue; |
| 1911 microtaskState.queue = new InternalArray; |
| 1912 |
| 1913 for (var i = 0; i < microtasks.length; i++) { |
| 1914 microtasks[i](); |
| 1915 } |
| 1896 } | 1916 } |
| 1897 } | 1917 } |
| 1918 |
| 1919 function EnqueueExternalMicrotask(fn) { |
| 1920 GetMicrotaskQueue().push(fn); |
| 1921 %SetMicrotaskPending(true); |
| 1922 } |
| OLD | NEW |