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