Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(820)

Side by Side Diff: src/v8natives.js

Issue 1127693006: Reland #2 "Wrap v8natives.js into a function." (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/uri.js ('k') | src/weak-collection.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 $delete;
6 // in runtime.js: 6 var $functionSourceString;
7 // var $Object = global.Object; 7 var $getIterator;
8 // var $Boolean = global.Boolean; 8 var $getMethod;
9 // var $Number = global.Number; 9 var $globalEval;
10 // var $Function = global.Function; 10 var $installConstants;
11 // var $Array = global.Array; 11 var $installFunctions;
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;
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
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
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
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
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
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
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
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 NativeCodeFunctionSourceString(func) { 1743 function NativeCodeFunctionSourceString(func) {
1742 var name = %FunctionGetName(func); 1744 var name = %FunctionGetName(func);
1743 if (name) { 1745 if (name) {
1744 // Mimic what KJS does. 1746 // Mimic what KJS does.
1745 return 'function ' + name + '() { [native code] }'; 1747 return 'function ' + name + '() { [native code] }';
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1843 // which are non-configurable. It therefore makes no sence to 1845 // which are non-configurable. It therefore makes no sence to
1844 // try to redefine these as defined by the spec. The spec says 1846 // try to redefine these as defined by the spec. The spec says
1845 // that bind should make these throw a TypeError if get or set 1847 // that bind should make these throw a TypeError if get or set
1846 // is called and make them non-enumerable and non-configurable. 1848 // is called and make them non-enumerable and non-configurable.
1847 // To be consistent with our normal functions we leave this as it is. 1849 // To be consistent with our normal functions we leave this as it is.
1848 // TODO(lrn): Do set these to be thrower. 1850 // TODO(lrn): Do set these to be thrower.
1849 return result; 1851 return result;
1850 } 1852 }
1851 1853
1852 1854
1853 function NewFunctionString(arguments, function_token) { 1855 function NewFunctionString(args, function_token) {
1854 var n = arguments.length; 1856 var n = args.length;
1855 var p = ''; 1857 var p = '';
1856 if (n > 1) { 1858 if (n > 1) {
1857 p = ToString(arguments[0]); 1859 p = ToString(args[0]);
1858 for (var i = 1; i < n - 1; i++) { 1860 for (var i = 1; i < n - 1; i++) {
1859 p += ',' + ToString(arguments[i]); 1861 p += ',' + ToString(args[i]);
1860 } 1862 }
1861 // If the formal parameters string include ) - an illegal 1863 // If the formal parameters string include ) - an illegal
1862 // character - it may make the combined function expression 1864 // character - it may make the combined function expression
1863 // compile. We avoid this problem by checking for this early on. 1865 // compile. We avoid this problem by checking for this early on.
1864 if (%_CallFunction(p, ')', $stringIndexOf) != -1) { 1866 if (%_CallFunction(p, ')', $stringIndexOf) != -1) {
1865 throw MakeSyntaxError(kParenthesisInArgString); 1867 throw MakeSyntaxError(kParenthesisInArgString);
1866 } 1868 }
1867 // If the formal parameters include an unbalanced block comment, the 1869 // If the formal parameters include an unbalanced block comment, the
1868 // function must be rejected. Since JavaScript does not allow nested 1870 // function must be rejected. Since JavaScript does not allow nested
1869 // comments we can include a trailing block comment to catch this. 1871 // comments we can include a trailing block comment to catch this.
1870 p += '\n/' + '**/'; 1872 p += '\n/' + '**/';
1871 } 1873 }
1872 var body = (n > 0) ? ToString(arguments[n - 1]) : ''; 1874 var body = (n > 0) ? ToString(args[n - 1]) : '';
1873 return '(' + function_token + '(' + p + ') {\n' + body + '\n})'; 1875 return '(' + function_token + '(' + p + ') {\n' + body + '\n})';
1874 } 1876 }
1875 1877
1876 1878
1877 function FunctionConstructor(arg1) { // length == 1 1879 function FunctionConstructor(arg1) { // length == 1
1878 var source = NewFunctionString(arguments, 'function'); 1880 var source = NewFunctionString(arguments, 'function');
1879 var global_proxy = %GlobalProxy(global); 1881 var global_proxy = %GlobalProxy(global);
1880 // Compile the string in the constructor and not a helper so that errors 1882 // Compile the string in the constructor and not a helper so that errors
1881 // appear to come from here. 1883 // appear to come from here.
1882 var f = %_CallFunction(global_proxy, %CompileString(source, true)); 1884 var f = %_CallFunction(global_proxy, %CompileString(source, true));
1883 %FunctionMarkNameShouldPrintAsAnonymous(f); 1885 %FunctionMarkNameShouldPrintAsAnonymous(f);
1884 return f; 1886 return f;
1885 } 1887 }
1886 1888
1887 1889
1888 // ---------------------------------------------------------------------------- 1890 // ----------------------------------------------------------------------------
1889 1891
1890 function SetUpFunction() { 1892 %SetCode(GlobalFunction, FunctionConstructor);
1891 %CheckIsBootstrapping(); 1893 %AddNamedProperty(GlobalFunction.prototype, "constructor", GlobalFunction,
1894 DONT_ENUM);
1892 1895
1893 %SetCode($Function, FunctionConstructor); 1896 InstallFunctions(GlobalFunction.prototype, DONT_ENUM, [
1894 %AddNamedProperty($Function.prototype, "constructor", $Function, DONT_ENUM); 1897 "bind", FunctionBind,
1895 1898 "toString", FunctionToString
1896 InstallFunctions($Function.prototype, DONT_ENUM, [ 1899 ]);
1897 "bind", FunctionBind,
1898 "toString", FunctionToString
1899 ]);
1900 }
1901
1902 SetUpFunction();
1903
1904 1900
1905 // ---------------------------------------------------------------------------- 1901 // ----------------------------------------------------------------------------
1906 // Iterator related spec functions. 1902 // Iterator related spec functions.
1907 1903
1908 // ES6 rev 33, 2015-02-12 1904 // ES6 rev 33, 2015-02-12
1909 // 7.4.1 GetIterator ( obj, method ) 1905 // 7.4.1 GetIterator ( obj, method )
1910 function GetIterator(obj, method) { 1906 function GetIterator(obj, method) {
1911 if (IS_UNDEFINED(method)) { 1907 if (IS_UNDEFINED(method)) {
1912 method = obj[symbolIterator]; 1908 method = obj[symbolIterator];
1913 } 1909 }
1914 if (!IS_SPEC_FUNCTION(method)) { 1910 if (!IS_SPEC_FUNCTION(method)) {
1915 throw MakeTypeError(kNotIterable, obj); 1911 throw MakeTypeError(kNotIterable, obj);
1916 } 1912 }
1917 var iterator = %_CallFunction(obj, method); 1913 var iterator = %_CallFunction(obj, method);
1918 if (!IS_SPEC_OBJECT(iterator)) { 1914 if (!IS_SPEC_OBJECT(iterator)) {
1919 throw MakeTypeError(kNotAnIterator, iterator); 1915 throw MakeTypeError(kNotAnIterator, iterator);
1920 } 1916 }
1921 return iterator; 1917 return iterator;
1922 } 1918 }
1919
1920 //----------------------------------------------------------------------------
1921
1922 $delete = Delete;
1923 $functionSourceString = FunctionSourceString;
1924 $getIterator = GetIterator;
1925 $getMethod = GetMethod;
1926 $globalEval = GlobalEval;
1927 $installConstants = InstallConstants;
1928 $installFunctions = InstallFunctions;
1929 $installGetter = InstallGetter;
1930 $isFinite = GlobalIsFinite;
1931 $isNaN = GlobalIsNaN;
1932 $newFunctionString = NewFunctionString;
1933 $numberIsNaN = NumberIsNaN;
1934 $objectDefineProperties = ObjectDefineProperties;
1935 $objectDefineProperty = ObjectDefineProperty;
1936 $objectFreeze = ObjectFreezeJS;
1937 $objectGetOwnPropertyDescriptor = ObjectGetOwnPropertyDescriptor;
1938 $objectGetOwnPropertyKeys = ObjectGetOwnPropertyKeys;
1939 $objectHasOwnProperty = ObjectHasOwnProperty;
1940 $objectIsFrozen = ObjectIsFrozen;
1941 $objectIsSealed = ObjectIsSealed;
1942 $objectLookupGetter = ObjectLookupGetter;
1943 $objectLookupSetter = ObjectLookupSetter;
1944 $objectToString = ObjectToString;
1945 $overrideFunction = OverrideFunction;
1946 $setFunctionName = SetFunctionName;
1947 $setUpLockedPrototype = SetUpLockedPrototype;
1948 $toCompletePropertyDescriptor = ToCompletePropertyDescriptor;
1949 $toNameArray = ToNameArray;
1950
1951 })();
OLDNEW
« no previous file with comments | « src/uri.js ('k') | src/weak-collection.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698