| Index: src/v8natives.js
|
| diff --git a/src/v8natives.js b/src/v8natives.js
|
| index d163f5e23218b1f8946d602b7a0e19ce0e72d12f..9c822b266b7c2e4607c41e718e3edcc62d45addc 100644
|
| --- a/src/v8natives.js
|
| +++ b/src/v8natives.js
|
| @@ -2,16 +2,44 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -// This file relies on the fact that the following declarations have been made
|
| -// in runtime.js:
|
| -// var $Object = global.Object;
|
| -// var $Boolean = global.Boolean;
|
| -// var $Number = global.Number;
|
| -// var $Function = global.Function;
|
| -// var $Array = global.Array;
|
| -
|
| -var $isNaN = GlobalIsNaN;
|
| -var $isFinite = GlobalIsFinite;
|
| +var $delete;
|
| +var $functionSourceString;
|
| +var $getIterator;
|
| +var $getMethod;
|
| +var $globalEval;
|
| +var $installConstants;
|
| +var $installFunctions;
|
| +var $installGetter;
|
| +var $isFinite;
|
| +var $isNaN;
|
| +var $newFunctionString;
|
| +var $numberIsNaN;
|
| +var $objectDefineProperties;
|
| +var $objectDefineProperty;
|
| +var $objectFreeze;
|
| +var $objectGetOwnPropertyDescriptor;
|
| +var $objectGetOwnPropertyKeys;
|
| +var $objectHasOwnProperty;
|
| +var $objectIsFrozen;
|
| +var $objectIsSealed;
|
| +var $objectLookupGetter;
|
| +var $objectLookupSetter;
|
| +var $objectToString;
|
| +var $overrideFunction;
|
| +var $setFunctionName;
|
| +var $setUpLockedPrototype;
|
| +var $toCompletePropertyDescriptor;
|
| +var $toNameArray;
|
| +
|
| +(function() {
|
| +
|
| +%CheckIsBootstrapping();
|
| +
|
| +var GlobalArray = global.Array;
|
| +var GlobalBoolean = global.Boolean;
|
| +var GlobalFunction = global.Function;
|
| +var GlobalNumber = global.Number;
|
| +var GlobalObject = global.Object;
|
|
|
| // ----------------------------------------------------------------------------
|
|
|
| @@ -195,44 +223,31 @@ function GlobalEval(x) {
|
| // ----------------------------------------------------------------------------
|
|
|
| // Set up global object.
|
| -function SetUpGlobal() {
|
| - %CheckIsBootstrapping();
|
| -
|
| - var attributes = DONT_ENUM | DONT_DELETE | READ_ONLY;
|
| +var attributes = DONT_ENUM | DONT_DELETE | READ_ONLY;
|
|
|
| +InstallConstants(global, [
|
| // ECMA 262 - 15.1.1.1.
|
| - %AddNamedProperty(global, "NaN", NAN, attributes);
|
| -
|
| + "NaN", NAN,
|
| // ECMA-262 - 15.1.1.2.
|
| - %AddNamedProperty(global, "Infinity", INFINITY, attributes);
|
| -
|
| - // ECMA-262 - 15.1.1.3.
|
| - %AddNamedProperty(global, "undefined", UNDEFINED, attributes);
|
| -
|
| - // Set up non-enumerable function on the global object.
|
| - InstallFunctions(global, DONT_ENUM, [
|
| - "isNaN", GlobalIsNaN,
|
| - "isFinite", GlobalIsFinite,
|
| - "parseInt", GlobalParseInt,
|
| - "parseFloat", GlobalParseFloat,
|
| - "eval", GlobalEval
|
| - ]);
|
| -}
|
| + "Infinity", INFINITY,
|
| + // ECMA-262 - 15.1.1.2.
|
| + "undefined", UNDEFINED,
|
| +]);
|
|
|
| -SetUpGlobal();
|
| +// Set up non-enumerable function on the global object.
|
| +InstallFunctions(global, DONT_ENUM, [
|
| + "isNaN", GlobalIsNaN,
|
| + "isFinite", GlobalIsFinite,
|
| + "parseInt", GlobalParseInt,
|
| + "parseFloat", GlobalParseFloat,
|
| + "eval", GlobalEval
|
| +]);
|
|
|
|
|
| // ----------------------------------------------------------------------------
|
| // Object
|
|
|
| // ECMA-262 - 15.2.4.2
|
| -function NoSideEffectsObjectToString() {
|
| - if (IS_UNDEFINED(this) && !IS_UNDETECTABLE(this)) return "[object Undefined]";
|
| - if (IS_NULL(this)) return "[object Null]";
|
| - return "[object " + %_ClassOf(TO_OBJECT_INLINE(this)) + "]";
|
| -}
|
| -
|
| -
|
| function ObjectToString() {
|
| if (IS_UNDEFINED(this) && !IS_UNDETECTABLE(this)) return "[object Undefined]";
|
| if (IS_NULL(this)) return "[object Null]";
|
| @@ -242,7 +257,7 @@ function ObjectToString() {
|
|
|
| // TODO(caitp): cannot wait to get rid of this flag :>
|
| if (harmony_tostring) {
|
| - var tag = O[symbolToStringTag];
|
| + tag = O[symbolToStringTag];
|
| if (!IS_STRING(tag)) {
|
| tag = builtinTag;
|
| }
|
| @@ -411,7 +426,7 @@ function FromPropertyDescriptor(desc) {
|
| // Harmony Proxies
|
| function FromGenericPropertyDescriptor(desc) {
|
| if (IS_UNDEFINED(desc)) return desc;
|
| - var obj = new $Object();
|
| + var obj = new GlobalObject();
|
|
|
| if (desc.hasValue()) {
|
| %AddNamedProperty(obj, "value", desc.getValue(), NONE);
|
| @@ -1040,7 +1055,7 @@ function ToNameArray(obj, trap, includeSymbols) {
|
| throw MakeTypeError(kProxyNonObjectPropNames, trap, obj);
|
| }
|
| var n = ToUint32(obj.length);
|
| - var array = new $Array(n);
|
| + var array = new GlobalArray(n);
|
| var realLength = 0;
|
| var names = { __proto__: null }; // TODO(rossberg): use sets once ready.
|
| for (var index = 0; index < n; index++) {
|
| @@ -1249,8 +1264,8 @@ function ProxyFix(obj) {
|
| %SetCode(obj, code);
|
| // TODO(rossberg): What about length and other properties? Not specified.
|
| // We just put in some half-reasonable defaults for now.
|
| - var prototype = new $Object();
|
| - $Object.defineProperty(prototype, "constructor",
|
| + var prototype = new GlobalObject();
|
| + ObjectDefineProperty(prototype, "constructor",
|
| {value: obj, writable: true, enumerable: false, configurable: true});
|
| // TODO(v8:1530): defineProperty does not handle prototype and length.
|
| %FunctionSetPrototype(obj, prototype);
|
| @@ -1415,54 +1430,49 @@ function ObjectConstructor(x) {
|
| // ----------------------------------------------------------------------------
|
| // Object
|
|
|
| -function SetUpObject() {
|
| - %CheckIsBootstrapping();
|
| -
|
| - %SetNativeFlag($Object);
|
| - %SetCode($Object, ObjectConstructor);
|
| -
|
| - %AddNamedProperty($Object.prototype, "constructor", $Object, DONT_ENUM);
|
| -
|
| - // Set up non-enumerable functions on the Object.prototype object.
|
| - InstallFunctions($Object.prototype, DONT_ENUM, [
|
| - "toString", ObjectToString,
|
| - "toLocaleString", ObjectToLocaleString,
|
| - "valueOf", ObjectValueOf,
|
| - "hasOwnProperty", ObjectHasOwnProperty,
|
| - "isPrototypeOf", ObjectIsPrototypeOf,
|
| - "propertyIsEnumerable", ObjectPropertyIsEnumerable,
|
| - "__defineGetter__", ObjectDefineGetter,
|
| - "__lookupGetter__", ObjectLookupGetter,
|
| - "__defineSetter__", ObjectDefineSetter,
|
| - "__lookupSetter__", ObjectLookupSetter
|
| - ]);
|
| - InstallGetterSetter($Object.prototype, "__proto__",
|
| - ObjectGetProto, ObjectSetProto);
|
| -
|
| - // Set up non-enumerable functions in the Object object.
|
| - InstallFunctions($Object, DONT_ENUM, [
|
| - "keys", ObjectKeys,
|
| - "create", ObjectCreate,
|
| - "defineProperty", ObjectDefineProperty,
|
| - "defineProperties", ObjectDefineProperties,
|
| - "freeze", ObjectFreezeJS,
|
| - "getPrototypeOf", ObjectGetPrototypeOf,
|
| - "setPrototypeOf", ObjectSetPrototypeOf,
|
| - "getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor,
|
| - "getOwnPropertyNames", ObjectGetOwnPropertyNames,
|
| - // getOwnPropertySymbols is added in symbol.js.
|
| - "is", ObjectIs,
|
| - "isExtensible", ObjectIsExtensible,
|
| - "isFrozen", ObjectIsFrozen,
|
| - "isSealed", ObjectIsSealed,
|
| - "preventExtensions", ObjectPreventExtension,
|
| - "seal", ObjectSealJS
|
| - // deliverChangeRecords, getNotifier, observe and unobserve are added
|
| - // in object-observe.js.
|
| - ]);
|
| -}
|
| -
|
| -SetUpObject();
|
| +%SetNativeFlag(GlobalObject);
|
| +%SetCode(GlobalObject, ObjectConstructor);
|
| +
|
| +%AddNamedProperty(GlobalObject.prototype, "constructor", GlobalObject,
|
| + DONT_ENUM);
|
| +
|
| +// Set up non-enumerable functions on the Object.prototype object.
|
| +InstallFunctions(GlobalObject.prototype, DONT_ENUM, [
|
| + "toString", ObjectToString,
|
| + "toLocaleString", ObjectToLocaleString,
|
| + "valueOf", ObjectValueOf,
|
| + "hasOwnProperty", ObjectHasOwnProperty,
|
| + "isPrototypeOf", ObjectIsPrototypeOf,
|
| + "propertyIsEnumerable", ObjectPropertyIsEnumerable,
|
| + "__defineGetter__", ObjectDefineGetter,
|
| + "__lookupGetter__", ObjectLookupGetter,
|
| + "__defineSetter__", ObjectDefineSetter,
|
| + "__lookupSetter__", ObjectLookupSetter
|
| +]);
|
| +InstallGetterSetter(GlobalObject.prototype, "__proto__", ObjectGetProto,
|
| + ObjectSetProto);
|
| +
|
| +// Set up non-enumerable functions in the Object object.
|
| +InstallFunctions(GlobalObject, DONT_ENUM, [
|
| + "keys", ObjectKeys,
|
| + "create", ObjectCreate,
|
| + "defineProperty", ObjectDefineProperty,
|
| + "defineProperties", ObjectDefineProperties,
|
| + "freeze", ObjectFreezeJS,
|
| + "getPrototypeOf", ObjectGetPrototypeOf,
|
| + "setPrototypeOf", ObjectSetPrototypeOf,
|
| + "getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor,
|
| + "getOwnPropertyNames", ObjectGetOwnPropertyNames,
|
| + // getOwnPropertySymbols is added in symbol.js.
|
| + "is", ObjectIs,
|
| + "isExtensible", ObjectIsExtensible,
|
| + "isFrozen", ObjectIsFrozen,
|
| + "isSealed", ObjectIsSealed,
|
| + "preventExtensions", ObjectPreventExtension,
|
| + "seal", ObjectSealJS
|
| + // deliverChangeRecords, getNotifier, observe and unobserve are added
|
| + // in object-observe.js.
|
| +]);
|
|
|
|
|
| // ----------------------------------------------------------------------------
|
| @@ -1503,20 +1513,15 @@ function BooleanValueOf() {
|
|
|
| // ----------------------------------------------------------------------------
|
|
|
| -function SetUpBoolean () {
|
| - %CheckIsBootstrapping();
|
| -
|
| - %SetCode($Boolean, BooleanConstructor);
|
| - %FunctionSetPrototype($Boolean, new $Boolean(false));
|
| - %AddNamedProperty($Boolean.prototype, "constructor", $Boolean, DONT_ENUM);
|
| +%SetCode(GlobalBoolean, BooleanConstructor);
|
| +%FunctionSetPrototype(GlobalBoolean, new GlobalBoolean(false));
|
| +%AddNamedProperty(GlobalBoolean.prototype, "constructor", GlobalBoolean,
|
| + DONT_ENUM);
|
|
|
| - InstallFunctions($Boolean.prototype, DONT_ENUM, [
|
| - "toString", BooleanToString,
|
| - "valueOf", BooleanValueOf
|
| - ]);
|
| -}
|
| -
|
| -SetUpBoolean();
|
| +InstallFunctions(GlobalBoolean.prototype, DONT_ENUM, [
|
| + "toString", BooleanToString,
|
| + "valueOf", BooleanValueOf
|
| +]);
|
|
|
|
|
| // ----------------------------------------------------------------------------
|
| @@ -1672,7 +1677,9 @@ function NumberIsNaN(number) {
|
| function NumberIsSafeInteger(number) {
|
| if (NumberIsFinite(number)) {
|
| var integral = TO_INTEGER(number);
|
| - if (integral == number) return $abs(integral) <= $Number.MAX_SAFE_INTEGER;
|
| + if (integral == number) {
|
| + return $abs(integral) <= GlobalNumber.MAX_SAFE_INTEGER;
|
| + }
|
| }
|
| return false;
|
| }
|
| @@ -1680,59 +1687,54 @@ function NumberIsSafeInteger(number) {
|
|
|
| // ----------------------------------------------------------------------------
|
|
|
| -function SetUpNumber() {
|
| - %CheckIsBootstrapping();
|
| +%SetCode(GlobalNumber, NumberConstructor);
|
| +%FunctionSetPrototype(GlobalNumber, new GlobalNumber(0));
|
| +
|
| +%OptimizeObjectForAddingMultipleProperties(GlobalNumber.prototype, 8);
|
| +// Set up the constructor property on the Number prototype object.
|
| +%AddNamedProperty(GlobalNumber.prototype, "constructor", GlobalNumber,
|
| + DONT_ENUM);
|
| +
|
| +InstallConstants(GlobalNumber, [
|
| + // ECMA-262 section 15.7.3.1.
|
| + "MAX_VALUE", 1.7976931348623157e+308,
|
| + // ECMA-262 section 15.7.3.2.
|
| + "MIN_VALUE", 5e-324,
|
| + // ECMA-262 section 15.7.3.3.
|
| + "NaN", NAN,
|
| + // ECMA-262 section 15.7.3.4.
|
| + "NEGATIVE_INFINITY", -INFINITY,
|
| + // ECMA-262 section 15.7.3.5.
|
| + "POSITIVE_INFINITY", INFINITY,
|
| +
|
| + // --- Harmony constants (no spec refs until settled.)
|
| +
|
| + "MAX_SAFE_INTEGER", %_MathPow(2, 53) - 1,
|
| + "MIN_SAFE_INTEGER", -%_MathPow(2, 53) + 1,
|
| + "EPSILON", %_MathPow(2, -52)
|
| +]);
|
|
|
| - %SetCode($Number, NumberConstructor);
|
| - %FunctionSetPrototype($Number, new $Number(0));
|
| -
|
| - %OptimizeObjectForAddingMultipleProperties($Number.prototype, 8);
|
| - // Set up the constructor property on the Number prototype object.
|
| - %AddNamedProperty($Number.prototype, "constructor", $Number, DONT_ENUM);
|
| -
|
| - InstallConstants($Number, [
|
| - // ECMA-262 section 15.7.3.1.
|
| - "MAX_VALUE", 1.7976931348623157e+308,
|
| - // ECMA-262 section 15.7.3.2.
|
| - "MIN_VALUE", 5e-324,
|
| - // ECMA-262 section 15.7.3.3.
|
| - "NaN", NAN,
|
| - // ECMA-262 section 15.7.3.4.
|
| - "NEGATIVE_INFINITY", -INFINITY,
|
| - // ECMA-262 section 15.7.3.5.
|
| - "POSITIVE_INFINITY", INFINITY,
|
| -
|
| - // --- Harmony constants (no spec refs until settled.)
|
| -
|
| - "MAX_SAFE_INTEGER", %_MathPow(2, 53) - 1,
|
| - "MIN_SAFE_INTEGER", -%_MathPow(2, 53) + 1,
|
| - "EPSILON", %_MathPow(2, -52)
|
| - ]);
|
| -
|
| - // Set up non-enumerable functions on the Number prototype object.
|
| - InstallFunctions($Number.prototype, DONT_ENUM, [
|
| - "toString", NumberToStringJS,
|
| - "toLocaleString", NumberToLocaleString,
|
| - "valueOf", NumberValueOf,
|
| - "toFixed", NumberToFixedJS,
|
| - "toExponential", NumberToExponentialJS,
|
| - "toPrecision", NumberToPrecisionJS
|
| - ]);
|
| -
|
| - // Harmony Number constructor additions
|
| - InstallFunctions($Number, DONT_ENUM, [
|
| - "isFinite", NumberIsFinite,
|
| - "isInteger", NumberIsInteger,
|
| - "isNaN", NumberIsNaN,
|
| - "isSafeInteger", NumberIsSafeInteger,
|
| - "parseInt", GlobalParseInt,
|
| - "parseFloat", GlobalParseFloat
|
| - ]);
|
| -
|
| - %SetInlineBuiltinFlag(NumberIsNaN);
|
| -}
|
| -
|
| -SetUpNumber();
|
| +// Set up non-enumerable functions on the Number prototype object.
|
| +InstallFunctions(GlobalNumber.prototype, DONT_ENUM, [
|
| + "toString", NumberToStringJS,
|
| + "toLocaleString", NumberToLocaleString,
|
| + "valueOf", NumberValueOf,
|
| + "toFixed", NumberToFixedJS,
|
| + "toExponential", NumberToExponentialJS,
|
| + "toPrecision", NumberToPrecisionJS
|
| +]);
|
| +
|
| +// Harmony Number constructor additions
|
| +InstallFunctions(GlobalNumber, DONT_ENUM, [
|
| + "isFinite", NumberIsFinite,
|
| + "isInteger", NumberIsInteger,
|
| + "isNaN", NumberIsNaN,
|
| + "isSafeInteger", NumberIsSafeInteger,
|
| + "parseInt", GlobalParseInt,
|
| + "parseFloat", GlobalParseFloat
|
| +]);
|
| +
|
| +%SetInlineBuiltinFlag(NumberIsNaN);
|
|
|
|
|
| // ----------------------------------------------------------------------------
|
| @@ -1850,13 +1852,13 @@ function FunctionBind(this_arg) { // Length is 1.
|
| }
|
|
|
|
|
| -function NewFunctionString(arguments, function_token) {
|
| - var n = arguments.length;
|
| +function NewFunctionString(args, function_token) {
|
| + var n = args.length;
|
| var p = '';
|
| if (n > 1) {
|
| - p = ToString(arguments[0]);
|
| + p = ToString(args[0]);
|
| for (var i = 1; i < n - 1; i++) {
|
| - p += ',' + ToString(arguments[i]);
|
| + p += ',' + ToString(args[i]);
|
| }
|
| // If the formal parameters string include ) - an illegal
|
| // character - it may make the combined function expression
|
| @@ -1869,7 +1871,7 @@ function NewFunctionString(arguments, function_token) {
|
| // comments we can include a trailing block comment to catch this.
|
| p += '\n/' + '**/';
|
| }
|
| - var body = (n > 0) ? ToString(arguments[n - 1]) : '';
|
| + var body = (n > 0) ? ToString(args[n - 1]) : '';
|
| return '(' + function_token + '(' + p + ') {\n' + body + '\n})';
|
| }
|
|
|
| @@ -1887,20 +1889,14 @@ function FunctionConstructor(arg1) { // length == 1
|
|
|
| // ----------------------------------------------------------------------------
|
|
|
| -function SetUpFunction() {
|
| - %CheckIsBootstrapping();
|
| -
|
| - %SetCode($Function, FunctionConstructor);
|
| - %AddNamedProperty($Function.prototype, "constructor", $Function, DONT_ENUM);
|
| -
|
| - InstallFunctions($Function.prototype, DONT_ENUM, [
|
| - "bind", FunctionBind,
|
| - "toString", FunctionToString
|
| - ]);
|
| -}
|
| -
|
| -SetUpFunction();
|
| +%SetCode(GlobalFunction, FunctionConstructor);
|
| +%AddNamedProperty(GlobalFunction.prototype, "constructor", GlobalFunction,
|
| + DONT_ENUM);
|
|
|
| +InstallFunctions(GlobalFunction.prototype, DONT_ENUM, [
|
| + "bind", FunctionBind,
|
| + "toString", FunctionToString
|
| +]);
|
|
|
| // ----------------------------------------------------------------------------
|
| // Iterator related spec functions.
|
| @@ -1920,3 +1916,36 @@ function GetIterator(obj, method) {
|
| }
|
| return iterator;
|
| }
|
| +
|
| +//----------------------------------------------------------------------------
|
| +
|
| +$delete = Delete;
|
| +$functionSourceString = FunctionSourceString;
|
| +$getIterator = GetIterator;
|
| +$getMethod = GetMethod;
|
| +$globalEval = GlobalEval;
|
| +$installConstants = InstallConstants;
|
| +$installFunctions = InstallFunctions;
|
| +$installGetter = InstallGetter;
|
| +$isFinite = GlobalIsFinite;
|
| +$isNaN = GlobalIsNaN;
|
| +$newFunctionString = NewFunctionString;
|
| +$numberIsNaN = NumberIsNaN;
|
| +$objectDefineProperties = ObjectDefineProperties;
|
| +$objectDefineProperty = ObjectDefineProperty;
|
| +$objectFreeze = ObjectFreezeJS;
|
| +$objectGetOwnPropertyDescriptor = ObjectGetOwnPropertyDescriptor;
|
| +$objectGetOwnPropertyKeys = ObjectGetOwnPropertyKeys;
|
| +$objectHasOwnProperty = ObjectHasOwnProperty;
|
| +$objectIsFrozen = ObjectIsFrozen;
|
| +$objectIsSealed = ObjectIsSealed;
|
| +$objectLookupGetter = ObjectLookupGetter;
|
| +$objectLookupSetter = ObjectLookupSetter;
|
| +$objectToString = ObjectToString;
|
| +$overrideFunction = OverrideFunction;
|
| +$setFunctionName = SetFunctionName;
|
| +$setUpLockedPrototype = SetUpLockedPrototype;
|
| +$toCompletePropertyDescriptor = ToCompletePropertyDescriptor;
|
| +$toNameArray = ToNameArray;
|
| +
|
| +})();
|
|
|