| 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 $delete; | 5 // This file relies on the fact that the following declarations have been made |
| 6 var $functionSourceString; | 6 // in runtime.js: |
| 7 var $getIterator; | 7 // var $Object = global.Object; |
| 8 var $getMethod; | 8 // var $Boolean = global.Boolean; |
| 9 var $globalEval; | 9 // var $Number = global.Number; |
| 10 var $installConstants; | 10 // var $Function = global.Function; |
| 11 var $installFunctions; | 11 // var $Array = global.Array; |
| 12 var $installGetter; | |
| 13 var $isFinite; | |
| 14 var $isNaN; | |
| 15 var $newFunctionString; | |
| 16 var $numberIsNaN; | |
| 17 var $objectDefineProperties; | |
| 18 var $objectDefineProperty; | |
| 19 var $objectFreeze; | |
| 20 var $objectGetOwnPropertyDescriptor; | |
| 21 var $objectGetOwnPropertyKeys; | |
| 22 var $objectHasOwnProperty; | |
| 23 var $objectIsFrozen; | |
| 24 var $objectIsSealed; | |
| 25 var $objectLookupGetter; | |
| 26 var $objectLookupSetter; | |
| 27 var $objectToString; | |
| 28 var $overrideFunction; | |
| 29 var $setFunctionName; | |
| 30 var $setUpLockedPrototype; | |
| 31 var $toCompletePropertyDescriptor; | |
| 32 var $toNameArray; | |
| 33 | 12 |
| 34 (function() { | 13 var $isNaN = GlobalIsNaN; |
| 35 | 14 var $isFinite = GlobalIsFinite; |
| 36 %CheckIsBootstrapping(); | |
| 37 | |
| 38 var GlobalArray = global.Array; | |
| 39 var GlobalBoolean = global.Boolean; | |
| 40 var GlobalFunction = global.Function; | |
| 41 var GlobalNumber = global.Number; | |
| 42 var GlobalObject = global.Object; | |
| 43 | 15 |
| 44 // ---------------------------------------------------------------------------- | 16 // ---------------------------------------------------------------------------- |
| 45 | 17 |
| 46 // ES6 - 9.2.11 SetFunctionName | 18 // ES6 - 9.2.11 SetFunctionName |
| 47 function SetFunctionName(f, name, prefix) { | 19 function SetFunctionName(f, name, prefix) { |
| 48 if (IS_SYMBOL(name)) { | 20 if (IS_SYMBOL(name)) { |
| 49 name = "[" + %SymbolDescription(name) + "]"; | 21 name = "[" + %SymbolDescription(name) + "]"; |
| 50 } | 22 } |
| 51 if (IS_UNDEFINED(prefix)) { | 23 if (IS_UNDEFINED(prefix)) { |
| 52 %FunctionSetName(f, name); | 24 %FunctionSetName(f, name); |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 var f = %CompileString(x, false); | 188 var f = %CompileString(x, false); |
| 217 if (!IS_FUNCTION(f)) return f; | 189 if (!IS_FUNCTION(f)) return f; |
| 218 | 190 |
| 219 return %_CallFunction(global_proxy, f); | 191 return %_CallFunction(global_proxy, f); |
| 220 } | 192 } |
| 221 | 193 |
| 222 | 194 |
| 223 // ---------------------------------------------------------------------------- | 195 // ---------------------------------------------------------------------------- |
| 224 | 196 |
| 225 // Set up global object. | 197 // Set up global object. |
| 226 var attributes = DONT_ENUM | DONT_DELETE | READ_ONLY; | 198 function SetUpGlobal() { |
| 199 %CheckIsBootstrapping(); |
| 227 | 200 |
| 228 InstallConstants(global, [ | 201 var attributes = DONT_ENUM | DONT_DELETE | READ_ONLY; |
| 202 |
| 229 // ECMA 262 - 15.1.1.1. | 203 // ECMA 262 - 15.1.1.1. |
| 230 "NaN", NAN, | 204 %AddNamedProperty(global, "NaN", NAN, attributes); |
| 205 |
| 231 // ECMA-262 - 15.1.1.2. | 206 // ECMA-262 - 15.1.1.2. |
| 232 "Infinity", INFINITY, | 207 %AddNamedProperty(global, "Infinity", INFINITY, attributes); |
| 233 // ECMA-262 - 15.1.1.2. | |
| 234 "undefined", UNDEFINED, | |
| 235 ]); | |
| 236 | 208 |
| 237 // Set up non-enumerable function on the global object. | 209 // ECMA-262 - 15.1.1.3. |
| 238 InstallFunctions(global, DONT_ENUM, [ | 210 %AddNamedProperty(global, "undefined", UNDEFINED, attributes); |
| 239 "isNaN", GlobalIsNaN, | 211 |
| 240 "isFinite", GlobalIsFinite, | 212 // Set up non-enumerable function on the global object. |
| 241 "parseInt", GlobalParseInt, | 213 InstallFunctions(global, DONT_ENUM, [ |
| 242 "parseFloat", GlobalParseFloat, | 214 "isNaN", GlobalIsNaN, |
| 243 "eval", GlobalEval | 215 "isFinite", GlobalIsFinite, |
| 244 ]); | 216 "parseInt", GlobalParseInt, |
| 217 "parseFloat", GlobalParseFloat, |
| 218 "eval", GlobalEval |
| 219 ]); |
| 220 } |
| 221 |
| 222 SetUpGlobal(); |
| 245 | 223 |
| 246 | 224 |
| 247 // ---------------------------------------------------------------------------- | 225 // ---------------------------------------------------------------------------- |
| 248 // Object | 226 // Object |
| 249 | 227 |
| 250 // ECMA-262 - 15.2.4.2 | 228 // ECMA-262 - 15.2.4.2 |
| 229 function NoSideEffectsObjectToString() { |
| 230 if (IS_UNDEFINED(this) && !IS_UNDETECTABLE(this)) return "[object Undefined]"; |
| 231 if (IS_NULL(this)) return "[object Null]"; |
| 232 return "[object " + %_ClassOf(TO_OBJECT_INLINE(this)) + "]"; |
| 233 } |
| 234 |
| 235 |
| 251 function ObjectToString() { | 236 function ObjectToString() { |
| 252 if (IS_UNDEFINED(this) && !IS_UNDETECTABLE(this)) return "[object Undefined]"; | 237 if (IS_UNDEFINED(this) && !IS_UNDETECTABLE(this)) return "[object Undefined]"; |
| 253 if (IS_NULL(this)) return "[object Null]"; | 238 if (IS_NULL(this)) return "[object Null]"; |
| 254 var O = TO_OBJECT_INLINE(this); | 239 var O = TO_OBJECT_INLINE(this); |
| 255 var builtinTag = %_ClassOf(O); | 240 var builtinTag = %_ClassOf(O); |
| 256 var tag; | 241 var tag; |
| 257 | 242 |
| 258 // TODO(caitp): cannot wait to get rid of this flag :> | 243 // TODO(caitp): cannot wait to get rid of this flag :> |
| 259 if (harmony_tostring) { | 244 if (harmony_tostring) { |
| 260 tag = O[symbolToStringTag]; | 245 var tag = O[symbolToStringTag]; |
| 261 if (!IS_STRING(tag)) { | 246 if (!IS_STRING(tag)) { |
| 262 tag = builtinTag; | 247 tag = builtinTag; |
| 263 } | 248 } |
| 264 } else { | 249 } else { |
| 265 tag = builtinTag; | 250 tag = builtinTag; |
| 266 } | 251 } |
| 267 | 252 |
| 268 return `[object ${tag}]`; | 253 return `[object ${tag}]`; |
| 269 } | 254 } |
| 270 | 255 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 return { get: desc.getGet(), | 404 return { get: desc.getGet(), |
| 420 set: desc.getSet(), | 405 set: desc.getSet(), |
| 421 enumerable: desc.isEnumerable(), | 406 enumerable: desc.isEnumerable(), |
| 422 configurable: desc.isConfigurable() }; | 407 configurable: desc.isConfigurable() }; |
| 423 } | 408 } |
| 424 | 409 |
| 425 | 410 |
| 426 // Harmony Proxies | 411 // Harmony Proxies |
| 427 function FromGenericPropertyDescriptor(desc) { | 412 function FromGenericPropertyDescriptor(desc) { |
| 428 if (IS_UNDEFINED(desc)) return desc; | 413 if (IS_UNDEFINED(desc)) return desc; |
| 429 var obj = new GlobalObject(); | 414 var obj = new $Object(); |
| 430 | 415 |
| 431 if (desc.hasValue()) { | 416 if (desc.hasValue()) { |
| 432 %AddNamedProperty(obj, "value", desc.getValue(), NONE); | 417 %AddNamedProperty(obj, "value", desc.getValue(), NONE); |
| 433 } | 418 } |
| 434 if (desc.hasWritable()) { | 419 if (desc.hasWritable()) { |
| 435 %AddNamedProperty(obj, "writable", desc.isWritable(), NONE); | 420 %AddNamedProperty(obj, "writable", desc.isWritable(), NONE); |
| 436 } | 421 } |
| 437 if (desc.hasGetter()) { | 422 if (desc.hasGetter()) { |
| 438 %AddNamedProperty(obj, "get", desc.getGet(), NONE); | 423 %AddNamedProperty(obj, "get", desc.getGet(), NONE); |
| 439 } | 424 } |
| (...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1048 return FromPropertyDescriptor(desc); | 1033 return FromPropertyDescriptor(desc); |
| 1049 } | 1034 } |
| 1050 | 1035 |
| 1051 | 1036 |
| 1052 // For Harmony proxies | 1037 // For Harmony proxies |
| 1053 function ToNameArray(obj, trap, includeSymbols) { | 1038 function ToNameArray(obj, trap, includeSymbols) { |
| 1054 if (!IS_SPEC_OBJECT(obj)) { | 1039 if (!IS_SPEC_OBJECT(obj)) { |
| 1055 throw MakeTypeError(kProxyNonObjectPropNames, trap, obj); | 1040 throw MakeTypeError(kProxyNonObjectPropNames, trap, obj); |
| 1056 } | 1041 } |
| 1057 var n = ToUint32(obj.length); | 1042 var n = ToUint32(obj.length); |
| 1058 var array = new GlobalArray(n); | 1043 var array = new $Array(n); |
| 1059 var realLength = 0; | 1044 var realLength = 0; |
| 1060 var names = { __proto__: null }; // TODO(rossberg): use sets once ready. | 1045 var names = { __proto__: null }; // TODO(rossberg): use sets once ready. |
| 1061 for (var index = 0; index < n; index++) { | 1046 for (var index = 0; index < n; index++) { |
| 1062 var s = ToName(obj[index]); | 1047 var s = ToName(obj[index]); |
| 1063 // TODO(rossberg): adjust once there is a story for symbols vs proxies. | 1048 // TODO(rossberg): adjust once there is a story for symbols vs proxies. |
| 1064 if (IS_SYMBOL(s) && !includeSymbols) continue; | 1049 if (IS_SYMBOL(s) && !includeSymbols) continue; |
| 1065 if (%HasOwnProperty(names, s)) { | 1050 if (%HasOwnProperty(names, s)) { |
| 1066 throw MakeTypeError(kProxyRepeatedPropName, trap, s); | 1051 throw MakeTypeError(kProxyRepeatedPropName, trap, s); |
| 1067 } | 1052 } |
| 1068 array[index] = s; | 1053 array[index] = s; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1257 } | 1242 } |
| 1258 | 1243 |
| 1259 if (%IsJSFunctionProxy(obj)) { | 1244 if (%IsJSFunctionProxy(obj)) { |
| 1260 var callTrap = %GetCallTrap(obj); | 1245 var callTrap = %GetCallTrap(obj); |
| 1261 var constructTrap = %GetConstructTrap(obj); | 1246 var constructTrap = %GetConstructTrap(obj); |
| 1262 var code = $proxyDelegateCallAndConstruct(callTrap, constructTrap); | 1247 var code = $proxyDelegateCallAndConstruct(callTrap, constructTrap); |
| 1263 %Fix(obj); // becomes a regular function | 1248 %Fix(obj); // becomes a regular function |
| 1264 %SetCode(obj, code); | 1249 %SetCode(obj, code); |
| 1265 // TODO(rossberg): What about length and other properties? Not specified. | 1250 // TODO(rossberg): What about length and other properties? Not specified. |
| 1266 // We just put in some half-reasonable defaults for now. | 1251 // We just put in some half-reasonable defaults for now. |
| 1267 var prototype = new GlobalObject(); | 1252 var prototype = new $Object(); |
| 1268 ObjectDefineProperty(prototype, "constructor", | 1253 $Object.defineProperty(prototype, "constructor", |
| 1269 {value: obj, writable: true, enumerable: false, configurable: true}); | 1254 {value: obj, writable: true, enumerable: false, configurable: true}); |
| 1270 // TODO(v8:1530): defineProperty does not handle prototype and length. | 1255 // TODO(v8:1530): defineProperty does not handle prototype and length. |
| 1271 %FunctionSetPrototype(obj, prototype); | 1256 %FunctionSetPrototype(obj, prototype); |
| 1272 obj.length = 0; | 1257 obj.length = 0; |
| 1273 } else { | 1258 } else { |
| 1274 %Fix(obj); | 1259 %Fix(obj); |
| 1275 } | 1260 } |
| 1276 ObjectDefineProperties(obj, props); | 1261 ObjectDefineProperties(obj, props); |
| 1277 } | 1262 } |
| 1278 | 1263 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1423 } else { | 1408 } else { |
| 1424 if (x == null) return { }; | 1409 if (x == null) return { }; |
| 1425 return TO_OBJECT_INLINE(x); | 1410 return TO_OBJECT_INLINE(x); |
| 1426 } | 1411 } |
| 1427 } | 1412 } |
| 1428 | 1413 |
| 1429 | 1414 |
| 1430 // ---------------------------------------------------------------------------- | 1415 // ---------------------------------------------------------------------------- |
| 1431 // Object | 1416 // Object |
| 1432 | 1417 |
| 1433 %SetNativeFlag(GlobalObject); | 1418 function SetUpObject() { |
| 1434 %SetCode(GlobalObject, ObjectConstructor); | 1419 %CheckIsBootstrapping(); |
| 1435 | 1420 |
| 1436 %AddNamedProperty(GlobalObject.prototype, "constructor", GlobalObject, | 1421 %SetNativeFlag($Object); |
| 1437 DONT_ENUM); | 1422 %SetCode($Object, ObjectConstructor); |
| 1438 | 1423 |
| 1439 // Set up non-enumerable functions on the Object.prototype object. | 1424 %AddNamedProperty($Object.prototype, "constructor", $Object, DONT_ENUM); |
| 1440 InstallFunctions(GlobalObject.prototype, DONT_ENUM, [ | |
| 1441 "toString", ObjectToString, | |
| 1442 "toLocaleString", ObjectToLocaleString, | |
| 1443 "valueOf", ObjectValueOf, | |
| 1444 "hasOwnProperty", ObjectHasOwnProperty, | |
| 1445 "isPrototypeOf", ObjectIsPrototypeOf, | |
| 1446 "propertyIsEnumerable", ObjectPropertyIsEnumerable, | |
| 1447 "__defineGetter__", ObjectDefineGetter, | |
| 1448 "__lookupGetter__", ObjectLookupGetter, | |
| 1449 "__defineSetter__", ObjectDefineSetter, | |
| 1450 "__lookupSetter__", ObjectLookupSetter | |
| 1451 ]); | |
| 1452 InstallGetterSetter(GlobalObject.prototype, "__proto__", ObjectGetProto, | |
| 1453 ObjectSetProto); | |
| 1454 | 1425 |
| 1455 // Set up non-enumerable functions in the Object object. | 1426 // Set up non-enumerable functions on the Object.prototype object. |
| 1456 InstallFunctions(GlobalObject, DONT_ENUM, [ | 1427 InstallFunctions($Object.prototype, DONT_ENUM, [ |
| 1457 "keys", ObjectKeys, | 1428 "toString", ObjectToString, |
| 1458 "create", ObjectCreate, | 1429 "toLocaleString", ObjectToLocaleString, |
| 1459 "defineProperty", ObjectDefineProperty, | 1430 "valueOf", ObjectValueOf, |
| 1460 "defineProperties", ObjectDefineProperties, | 1431 "hasOwnProperty", ObjectHasOwnProperty, |
| 1461 "freeze", ObjectFreezeJS, | 1432 "isPrototypeOf", ObjectIsPrototypeOf, |
| 1462 "getPrototypeOf", ObjectGetPrototypeOf, | 1433 "propertyIsEnumerable", ObjectPropertyIsEnumerable, |
| 1463 "setPrototypeOf", ObjectSetPrototypeOf, | 1434 "__defineGetter__", ObjectDefineGetter, |
| 1464 "getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor, | 1435 "__lookupGetter__", ObjectLookupGetter, |
| 1465 "getOwnPropertyNames", ObjectGetOwnPropertyNames, | 1436 "__defineSetter__", ObjectDefineSetter, |
| 1466 // getOwnPropertySymbols is added in symbol.js. | 1437 "__lookupSetter__", ObjectLookupSetter |
| 1467 "is", ObjectIs, | 1438 ]); |
| 1468 "isExtensible", ObjectIsExtensible, | 1439 InstallGetterSetter($Object.prototype, "__proto__", |
| 1469 "isFrozen", ObjectIsFrozen, | 1440 ObjectGetProto, ObjectSetProto); |
| 1470 "isSealed", ObjectIsSealed, | 1441 |
| 1471 "preventExtensions", ObjectPreventExtension, | 1442 // Set up non-enumerable functions in the Object object. |
| 1472 "seal", ObjectSealJS | 1443 InstallFunctions($Object, DONT_ENUM, [ |
| 1473 // deliverChangeRecords, getNotifier, observe and unobserve are added | 1444 "keys", ObjectKeys, |
| 1474 // in object-observe.js. | 1445 "create", ObjectCreate, |
| 1475 ]); | 1446 "defineProperty", ObjectDefineProperty, |
| 1447 "defineProperties", ObjectDefineProperties, |
| 1448 "freeze", ObjectFreezeJS, |
| 1449 "getPrototypeOf", ObjectGetPrototypeOf, |
| 1450 "setPrototypeOf", ObjectSetPrototypeOf, |
| 1451 "getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor, |
| 1452 "getOwnPropertyNames", ObjectGetOwnPropertyNames, |
| 1453 // getOwnPropertySymbols is added in symbol.js. |
| 1454 "is", ObjectIs, |
| 1455 "isExtensible", ObjectIsExtensible, |
| 1456 "isFrozen", ObjectIsFrozen, |
| 1457 "isSealed", ObjectIsSealed, |
| 1458 "preventExtensions", ObjectPreventExtension, |
| 1459 "seal", ObjectSealJS |
| 1460 // deliverChangeRecords, getNotifier, observe and unobserve are added |
| 1461 // in object-observe.js. |
| 1462 ]); |
| 1463 } |
| 1464 |
| 1465 SetUpObject(); |
| 1476 | 1466 |
| 1477 | 1467 |
| 1478 // ---------------------------------------------------------------------------- | 1468 // ---------------------------------------------------------------------------- |
| 1479 // Boolean | 1469 // Boolean |
| 1480 | 1470 |
| 1481 function BooleanConstructor(x) { | 1471 function BooleanConstructor(x) { |
| 1482 if (%_IsConstructCall()) { | 1472 if (%_IsConstructCall()) { |
| 1483 %_SetValueOf(this, ToBoolean(x)); | 1473 %_SetValueOf(this, ToBoolean(x)); |
| 1484 } else { | 1474 } else { |
| 1485 return ToBoolean(x); | 1475 return ToBoolean(x); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1506 // 'this'. This is not as dictated by ECMA-262. | 1496 // 'this'. This is not as dictated by ECMA-262. |
| 1507 if (!IS_BOOLEAN(this) && !IS_BOOLEAN_WRAPPER(this)) { | 1497 if (!IS_BOOLEAN(this) && !IS_BOOLEAN_WRAPPER(this)) { |
| 1508 throw MakeTypeError(kNotGeneric, 'Boolean.prototype.valueOf'); | 1498 throw MakeTypeError(kNotGeneric, 'Boolean.prototype.valueOf'); |
| 1509 } | 1499 } |
| 1510 return %_ValueOf(this); | 1500 return %_ValueOf(this); |
| 1511 } | 1501 } |
| 1512 | 1502 |
| 1513 | 1503 |
| 1514 // ---------------------------------------------------------------------------- | 1504 // ---------------------------------------------------------------------------- |
| 1515 | 1505 |
| 1516 %SetCode(GlobalBoolean, BooleanConstructor); | 1506 function SetUpBoolean () { |
| 1517 %FunctionSetPrototype(GlobalBoolean, new GlobalBoolean(false)); | 1507 %CheckIsBootstrapping(); |
| 1518 %AddNamedProperty(GlobalBoolean.prototype, "constructor", GlobalBoolean, | |
| 1519 DONT_ENUM); | |
| 1520 | 1508 |
| 1521 InstallFunctions(GlobalBoolean.prototype, DONT_ENUM, [ | 1509 %SetCode($Boolean, BooleanConstructor); |
| 1522 "toString", BooleanToString, | 1510 %FunctionSetPrototype($Boolean, new $Boolean(false)); |
| 1523 "valueOf", BooleanValueOf | 1511 %AddNamedProperty($Boolean.prototype, "constructor", $Boolean, DONT_ENUM); |
| 1524 ]); | 1512 |
| 1513 InstallFunctions($Boolean.prototype, DONT_ENUM, [ |
| 1514 "toString", BooleanToString, |
| 1515 "valueOf", BooleanValueOf |
| 1516 ]); |
| 1517 } |
| 1518 |
| 1519 SetUpBoolean(); |
| 1525 | 1520 |
| 1526 | 1521 |
| 1527 // ---------------------------------------------------------------------------- | 1522 // ---------------------------------------------------------------------------- |
| 1528 // Number | 1523 // Number |
| 1529 | 1524 |
| 1530 function NumberConstructor(x) { | 1525 function NumberConstructor(x) { |
| 1531 var value = %_ArgumentsLength() == 0 ? 0 : ToNumber(x); | 1526 var value = %_ArgumentsLength() == 0 ? 0 : ToNumber(x); |
| 1532 if (%_IsConstructCall()) { | 1527 if (%_IsConstructCall()) { |
| 1533 %_SetValueOf(this, value); | 1528 %_SetValueOf(this, value); |
| 1534 } else { | 1529 } else { |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1670 // Harmony isNaN. | 1665 // Harmony isNaN. |
| 1671 function NumberIsNaN(number) { | 1666 function NumberIsNaN(number) { |
| 1672 return IS_NUMBER(number) && NUMBER_IS_NAN(number); | 1667 return IS_NUMBER(number) && NUMBER_IS_NAN(number); |
| 1673 } | 1668 } |
| 1674 | 1669 |
| 1675 | 1670 |
| 1676 // Harmony isSafeInteger | 1671 // Harmony isSafeInteger |
| 1677 function NumberIsSafeInteger(number) { | 1672 function NumberIsSafeInteger(number) { |
| 1678 if (NumberIsFinite(number)) { | 1673 if (NumberIsFinite(number)) { |
| 1679 var integral = TO_INTEGER(number); | 1674 var integral = TO_INTEGER(number); |
| 1680 if (integral == number) { | 1675 if (integral == number) return $abs(integral) <= $Number.MAX_SAFE_INTEGER; |
| 1681 return $abs(integral) <= GlobalNumber.MAX_SAFE_INTEGER; | |
| 1682 } | |
| 1683 } | 1676 } |
| 1684 return false; | 1677 return false; |
| 1685 } | 1678 } |
| 1686 | 1679 |
| 1687 | 1680 |
| 1688 // ---------------------------------------------------------------------------- | 1681 // ---------------------------------------------------------------------------- |
| 1689 | 1682 |
| 1690 %SetCode(GlobalNumber, NumberConstructor); | 1683 function SetUpNumber() { |
| 1691 %FunctionSetPrototype(GlobalNumber, new GlobalNumber(0)); | 1684 %CheckIsBootstrapping(); |
| 1692 | 1685 |
| 1693 %OptimizeObjectForAddingMultipleProperties(GlobalNumber.prototype, 8); | 1686 %SetCode($Number, NumberConstructor); |
| 1694 // Set up the constructor property on the Number prototype object. | 1687 %FunctionSetPrototype($Number, new $Number(0)); |
| 1695 %AddNamedProperty(GlobalNumber.prototype, "constructor", GlobalNumber, | |
| 1696 DONT_ENUM); | |
| 1697 | 1688 |
| 1698 InstallConstants(GlobalNumber, [ | 1689 %OptimizeObjectForAddingMultipleProperties($Number.prototype, 8); |
| 1699 // ECMA-262 section 15.7.3.1. | 1690 // Set up the constructor property on the Number prototype object. |
| 1700 "MAX_VALUE", 1.7976931348623157e+308, | 1691 %AddNamedProperty($Number.prototype, "constructor", $Number, DONT_ENUM); |
| 1701 // ECMA-262 section 15.7.3.2. | |
| 1702 "MIN_VALUE", 5e-324, | |
| 1703 // ECMA-262 section 15.7.3.3. | |
| 1704 "NaN", NAN, | |
| 1705 // ECMA-262 section 15.7.3.4. | |
| 1706 "NEGATIVE_INFINITY", -INFINITY, | |
| 1707 // ECMA-262 section 15.7.3.5. | |
| 1708 "POSITIVE_INFINITY", INFINITY, | |
| 1709 | 1692 |
| 1710 // --- Harmony constants (no spec refs until settled.) | 1693 InstallConstants($Number, [ |
| 1694 // ECMA-262 section 15.7.3.1. |
| 1695 "MAX_VALUE", 1.7976931348623157e+308, |
| 1696 // ECMA-262 section 15.7.3.2. |
| 1697 "MIN_VALUE", 5e-324, |
| 1698 // ECMA-262 section 15.7.3.3. |
| 1699 "NaN", NAN, |
| 1700 // ECMA-262 section 15.7.3.4. |
| 1701 "NEGATIVE_INFINITY", -INFINITY, |
| 1702 // ECMA-262 section 15.7.3.5. |
| 1703 "POSITIVE_INFINITY", INFINITY, |
| 1711 | 1704 |
| 1712 "MAX_SAFE_INTEGER", %_MathPow(2, 53) - 1, | 1705 // --- Harmony constants (no spec refs until settled.) |
| 1713 "MIN_SAFE_INTEGER", -%_MathPow(2, 53) + 1, | |
| 1714 "EPSILON", %_MathPow(2, -52) | |
| 1715 ]); | |
| 1716 | 1706 |
| 1717 // Set up non-enumerable functions on the Number prototype object. | 1707 "MAX_SAFE_INTEGER", %_MathPow(2, 53) - 1, |
| 1718 InstallFunctions(GlobalNumber.prototype, DONT_ENUM, [ | 1708 "MIN_SAFE_INTEGER", -%_MathPow(2, 53) + 1, |
| 1719 "toString", NumberToStringJS, | 1709 "EPSILON", %_MathPow(2, -52) |
| 1720 "toLocaleString", NumberToLocaleString, | 1710 ]); |
| 1721 "valueOf", NumberValueOf, | |
| 1722 "toFixed", NumberToFixedJS, | |
| 1723 "toExponential", NumberToExponentialJS, | |
| 1724 "toPrecision", NumberToPrecisionJS | |
| 1725 ]); | |
| 1726 | 1711 |
| 1727 // Harmony Number constructor additions | 1712 // Set up non-enumerable functions on the Number prototype object. |
| 1728 InstallFunctions(GlobalNumber, DONT_ENUM, [ | 1713 InstallFunctions($Number.prototype, DONT_ENUM, [ |
| 1729 "isFinite", NumberIsFinite, | 1714 "toString", NumberToStringJS, |
| 1730 "isInteger", NumberIsInteger, | 1715 "toLocaleString", NumberToLocaleString, |
| 1731 "isNaN", NumberIsNaN, | 1716 "valueOf", NumberValueOf, |
| 1732 "isSafeInteger", NumberIsSafeInteger, | 1717 "toFixed", NumberToFixedJS, |
| 1733 "parseInt", GlobalParseInt, | 1718 "toExponential", NumberToExponentialJS, |
| 1734 "parseFloat", GlobalParseFloat | 1719 "toPrecision", NumberToPrecisionJS |
| 1735 ]); | 1720 ]); |
| 1736 | 1721 |
| 1737 %SetInlineBuiltinFlag(NumberIsNaN); | 1722 // Harmony Number constructor additions |
| 1723 InstallFunctions($Number, DONT_ENUM, [ |
| 1724 "isFinite", NumberIsFinite, |
| 1725 "isInteger", NumberIsInteger, |
| 1726 "isNaN", NumberIsNaN, |
| 1727 "isSafeInteger", NumberIsSafeInteger, |
| 1728 "parseInt", GlobalParseInt, |
| 1729 "parseFloat", GlobalParseFloat |
| 1730 ]); |
| 1731 |
| 1732 %SetInlineBuiltinFlag(NumberIsNaN); |
| 1733 } |
| 1734 |
| 1735 SetUpNumber(); |
| 1738 | 1736 |
| 1739 | 1737 |
| 1740 // ---------------------------------------------------------------------------- | 1738 // ---------------------------------------------------------------------------- |
| 1741 // Function | 1739 // Function |
| 1742 | 1740 |
| 1743 function FunctionSourceString(func) { | 1741 function FunctionSourceString(func) { |
| 1744 while (%IsJSFunctionProxy(func)) { | 1742 while (%IsJSFunctionProxy(func)) { |
| 1745 func = %GetCallTrap(func); | 1743 func = %GetCallTrap(func); |
| 1746 } | 1744 } |
| 1747 | 1745 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1837 // which are non-configurable. It therefore makes no sence to | 1835 // which are non-configurable. It therefore makes no sence to |
| 1838 // try to redefine these as defined by the spec. The spec says | 1836 // try to redefine these as defined by the spec. The spec says |
| 1839 // that bind should make these throw a TypeError if get or set | 1837 // that bind should make these throw a TypeError if get or set |
| 1840 // is called and make them non-enumerable and non-configurable. | 1838 // is called and make them non-enumerable and non-configurable. |
| 1841 // To be consistent with our normal functions we leave this as it is. | 1839 // To be consistent with our normal functions we leave this as it is. |
| 1842 // TODO(lrn): Do set these to be thrower. | 1840 // TODO(lrn): Do set these to be thrower. |
| 1843 return result; | 1841 return result; |
| 1844 } | 1842 } |
| 1845 | 1843 |
| 1846 | 1844 |
| 1847 function NewFunctionString(args, function_token) { | 1845 function NewFunctionString(arguments, function_token) { |
| 1848 var n = args.length; | 1846 var n = arguments.length; |
| 1849 var p = ''; | 1847 var p = ''; |
| 1850 if (n > 1) { | 1848 if (n > 1) { |
| 1851 p = ToString(args[0]); | 1849 p = ToString(arguments[0]); |
| 1852 for (var i = 1; i < n - 1; i++) { | 1850 for (var i = 1; i < n - 1; i++) { |
| 1853 p += ',' + ToString(args[i]); | 1851 p += ',' + ToString(arguments[i]); |
| 1854 } | 1852 } |
| 1855 // If the formal parameters string include ) - an illegal | 1853 // If the formal parameters string include ) - an illegal |
| 1856 // character - it may make the combined function expression | 1854 // character - it may make the combined function expression |
| 1857 // compile. We avoid this problem by checking for this early on. | 1855 // compile. We avoid this problem by checking for this early on. |
| 1858 if (%_CallFunction(p, ')', $stringIndexOf) != -1) { | 1856 if (%_CallFunction(p, ')', $stringIndexOf) != -1) { |
| 1859 throw MakeSyntaxError(kParenthesisInArgString); | 1857 throw MakeSyntaxError(kParenthesisInArgString); |
| 1860 } | 1858 } |
| 1861 // If the formal parameters include an unbalanced block comment, the | 1859 // If the formal parameters include an unbalanced block comment, the |
| 1862 // function must be rejected. Since JavaScript does not allow nested | 1860 // function must be rejected. Since JavaScript does not allow nested |
| 1863 // comments we can include a trailing block comment to catch this. | 1861 // comments we can include a trailing block comment to catch this. |
| 1864 p += '\n/' + '**/'; | 1862 p += '\n/' + '**/'; |
| 1865 } | 1863 } |
| 1866 var body = (n > 0) ? ToString(args[n - 1]) : ''; | 1864 var body = (n > 0) ? ToString(arguments[n - 1]) : ''; |
| 1867 return '(' + function_token + '(' + p + ') {\n' + body + '\n})'; | 1865 return '(' + function_token + '(' + p + ') {\n' + body + '\n})'; |
| 1868 } | 1866 } |
| 1869 | 1867 |
| 1870 | 1868 |
| 1871 function FunctionConstructor(arg1) { // length == 1 | 1869 function FunctionConstructor(arg1) { // length == 1 |
| 1872 var source = NewFunctionString(arguments, 'function'); | 1870 var source = NewFunctionString(arguments, 'function'); |
| 1873 var global_proxy = %GlobalProxy(global); | 1871 var global_proxy = %GlobalProxy(global); |
| 1874 // Compile the string in the constructor and not a helper so that errors | 1872 // Compile the string in the constructor and not a helper so that errors |
| 1875 // appear to come from here. | 1873 // appear to come from here. |
| 1876 var f = %_CallFunction(global_proxy, %CompileString(source, true)); | 1874 var f = %_CallFunction(global_proxy, %CompileString(source, true)); |
| 1877 %FunctionMarkNameShouldPrintAsAnonymous(f); | 1875 %FunctionMarkNameShouldPrintAsAnonymous(f); |
| 1878 return f; | 1876 return f; |
| 1879 } | 1877 } |
| 1880 | 1878 |
| 1881 | 1879 |
| 1882 // ---------------------------------------------------------------------------- | 1880 // ---------------------------------------------------------------------------- |
| 1883 | 1881 |
| 1884 %SetCode(GlobalFunction, FunctionConstructor); | 1882 function SetUpFunction() { |
| 1885 %AddNamedProperty(GlobalFunction.prototype, "constructor", GlobalFunction, | 1883 %CheckIsBootstrapping(); |
| 1886 DONT_ENUM); | |
| 1887 | 1884 |
| 1888 InstallFunctions(GlobalFunction.prototype, DONT_ENUM, [ | 1885 %SetCode($Function, FunctionConstructor); |
| 1889 "bind", FunctionBind, | 1886 %AddNamedProperty($Function.prototype, "constructor", $Function, DONT_ENUM); |
| 1890 "toString", FunctionToString | 1887 |
| 1891 ]); | 1888 InstallFunctions($Function.prototype, DONT_ENUM, [ |
| 1889 "bind", FunctionBind, |
| 1890 "toString", FunctionToString |
| 1891 ]); |
| 1892 } |
| 1893 |
| 1894 SetUpFunction(); |
| 1895 |
| 1892 | 1896 |
| 1893 // ---------------------------------------------------------------------------- | 1897 // ---------------------------------------------------------------------------- |
| 1894 // Iterator related spec functions. | 1898 // Iterator related spec functions. |
| 1895 | 1899 |
| 1896 // ES6 rev 33, 2015-02-12 | 1900 // ES6 rev 33, 2015-02-12 |
| 1897 // 7.4.1 GetIterator ( obj, method ) | 1901 // 7.4.1 GetIterator ( obj, method ) |
| 1898 function GetIterator(obj, method) { | 1902 function GetIterator(obj, method) { |
| 1899 if (IS_UNDEFINED(method)) { | 1903 if (IS_UNDEFINED(method)) { |
| 1900 method = obj[symbolIterator]; | 1904 method = obj[symbolIterator]; |
| 1901 } | 1905 } |
| 1902 if (!IS_SPEC_FUNCTION(method)) { | 1906 if (!IS_SPEC_FUNCTION(method)) { |
| 1903 throw MakeTypeError(kNotIterable, obj); | 1907 throw MakeTypeError(kNotIterable, obj); |
| 1904 } | 1908 } |
| 1905 var iterator = %_CallFunction(obj, method); | 1909 var iterator = %_CallFunction(obj, method); |
| 1906 if (!IS_SPEC_OBJECT(iterator)) { | 1910 if (!IS_SPEC_OBJECT(iterator)) { |
| 1907 throw MakeTypeError(kNotAnIterator, iterator); | 1911 throw MakeTypeError(kNotAnIterator, iterator); |
| 1908 } | 1912 } |
| 1909 return iterator; | 1913 return iterator; |
| 1910 } | 1914 } |
| 1911 | |
| 1912 //---------------------------------------------------------------------------- | |
| 1913 | |
| 1914 $delete = Delete; | |
| 1915 $functionSourceString = FunctionSourceString; | |
| 1916 $getIterator = GetIterator; | |
| 1917 $getMethod = GetMethod; | |
| 1918 $globalEval = GlobalEval; | |
| 1919 $installConstants = InstallConstants; | |
| 1920 $installFunctions = InstallFunctions; | |
| 1921 $installGetter = InstallGetter; | |
| 1922 $isFinite = GlobalIsFinite; | |
| 1923 $isNaN = GlobalIsNaN; | |
| 1924 $newFunctionString = NewFunctionString; | |
| 1925 $numberIsNaN = NumberIsNaN; | |
| 1926 $objectDefineProperties = ObjectDefineProperties; | |
| 1927 $objectDefineProperty = ObjectDefineProperty; | |
| 1928 $objectFreeze = ObjectFreezeJS; | |
| 1929 $objectGetOwnPropertyDescriptor = ObjectGetOwnPropertyDescriptor; | |
| 1930 $objectGetOwnPropertyKeys = ObjectGetOwnPropertyKeys; | |
| 1931 $objectHasOwnProperty = ObjectHasOwnProperty; | |
| 1932 $objectIsFrozen = ObjectIsFrozen; | |
| 1933 $objectIsSealed = ObjectIsSealed; | |
| 1934 $objectLookupGetter = ObjectLookupGetter; | |
| 1935 $objectLookupSetter = ObjectLookupSetter; | |
| 1936 $objectToString = ObjectToString; | |
| 1937 $overrideFunction = OverrideFunction; | |
| 1938 $setFunctionName = SetFunctionName; | |
| 1939 $setUpLockedPrototype = SetUpLockedPrototype; | |
| 1940 $toCompletePropertyDescriptor = ToCompletePropertyDescriptor; | |
| 1941 $toNameArray = ToNameArray; | |
| 1942 | |
| 1943 })(); | |
| OLD | NEW |