Commit eb8c0928 authored by yangguo's avatar yangguo Committed by Commit bot

Native context: debug.js does not load from js builtins object anymore.

This mainly changes how we share ToBoolean, ToNumber and ToString between
native scripts. Instead of putting them on the js builtins object, we now
explicitly export and import those functions.

I also had to change the import/export mechanism slightly. Previously,
exports and imports are hooked up after all native scripts have been
executed. This means that imported functions cannot be called at the time
the native script is executed.

However, since ToBoolean (and also e.g. ObjectDefineProperties) is called
in v8natives.js, I changed the mechanism so that exports from previous
native scripts (runtime.js for ToBoolean) is imported immediately and can
be called.

R=cbruni@chromium.org

Review URL: https://codereview.chromium.org/1302533002

Cr-Commit-Position: refs/heads/master@{#30244}
parent 7fc7957b
......@@ -19,16 +19,17 @@ var $arrayUnshift;
// -------------------------------------------------------------------
// Imports
var Delete;
var GlobalArray = global.Array;
var InternalArray = utils.InternalArray;
var InternalPackedArray = utils.InternalPackedArray;
var Delete;
var MathMin;
var ObjectHasOwnProperty;
var ObjectIsFrozen;
var ObjectIsSealed;
var ObjectToString;
var ToNumber;
var ToString;
utils.Import(function(from) {
Delete = from.Delete;
......@@ -37,6 +38,8 @@ utils.Import(function(from) {
ObjectIsFrozen = from.ObjectIsFrozen;
ObjectIsSealed = from.ObjectIsSealed;
ObjectToString = from.ObjectToString;
ToNumber = from.ToNumber;
ToString = from.ToString;
});
// -------------------------------------------------------------------
......@@ -216,7 +219,7 @@ function ConvertToString(x) {
// Assumes x is a non-string.
if (IS_NUMBER(x)) return %_NumberToString(x);
if (IS_BOOLEAN(x)) return x ? 'true' : 'false';
return (IS_NULL_OR_UNDEFINED(x)) ? '' : $toString($defaultString(x));
return (IS_NULL_OR_UNDEFINED(x)) ? '' : ToString($defaultString(x));
}
......@@ -228,7 +231,7 @@ function ConvertToLocaleString(e) {
// must throw a TypeError if ToObject(e).toLocaleString isn't
// callable.
var e_obj = TO_OBJECT(e);
return $toString(e_obj.toLocaleString());
return ToString(e_obj.toLocaleString());
}
}
......@@ -914,8 +917,8 @@ function InnerArraySort(length, comparefn) {
if (%_IsSmi(x) && %_IsSmi(y)) {
return %SmiLexicographicCompare(x, y);
}
x = $toString(x);
y = $toString(y);
x = ToString(x);
y = ToString(y);
if (x == y) return 0;
else return x < y ? -1 : 1;
};
......
......@@ -13,13 +13,14 @@
var GlobalArrayBuffer = global.ArrayBuffer;
var GlobalObject = global.Object;
var MathMax;
var MathMin;
var ToNumber;
utils.Import(function(from) {
MathMax = from.MathMax;
MathMin = from.MathMin;
ToNumber = from.ToNumber;
});
// -------------------------------------------------------------------
......
This diff is collapsed.
This diff is collapsed.
......@@ -8,10 +8,19 @@
// ----------------------------------------------------------------------------
// Imports
var FunctionSourceString;
var GlobalArray = global.Array;
var IsNaN = global.isNaN;
var JSONStringify = global.JSON.stringify;
var MathMin = global.Math.min;
var ToBoolean;
var ToString;
utils.Import(function(from) {
FunctionSourceString = from.FunctionSourceString;
ToBoolean = from.ToBoolean;
ToString = from.ToString;
});
// ----------------------------------------------------------------------------
......@@ -990,7 +999,7 @@ FunctionMirror.prototype.source = function() {
// Return source if function is resolved. Otherwise just fall through to
// return undefined.
if (this.resolved()) {
return builtins.$functionSourceString(this.value_);
return FunctionSourceString(this.value_);
}
};
......@@ -1168,7 +1177,7 @@ ArrayMirror.prototype.indexedPropertiesFromRange = function(opt_from_index,
if (from_index > to_index) return new GlobalArray();
var values = new GlobalArray(to_index - from_index + 1);
for (var i = from_index; i <= to_index; i++) {
var details = %DebugGetPropertyDetails(this.value_, builtins.$toString(i));
var details = %DebugGetPropertyDetails(this.value_, ToString(i));
var value;
if (details) {
value = new PropertyMirror(this, i, details);
......@@ -2068,7 +2077,7 @@ FrameMirror.prototype.evaluate = function(source, disable_break,
this.details_.frameId(),
this.details_.inlinedFrameIndex(),
source,
$toBoolean(disable_break),
ToBoolean(disable_break),
opt_context_object));
};
......
......@@ -11,15 +11,15 @@
// -------------------------------------------------------------------
// Imports
var GlobalArray = global.Array;
var GlobalSymbol = global.Symbol;
var GetIterator;
var GetMethod;
var GlobalArray = global.Array;
var GlobalSymbol = global.Symbol;
var MathMax;
var MathMin;
var ObjectIsFrozen;
var ObjectDefineProperty;
var ToNumber;
utils.Import(function(from) {
GetIterator = from.GetIterator;
......@@ -28,6 +28,7 @@ utils.Import(function(from) {
MathMin = from.MathMin;
ObjectIsFrozen = from.ObjectIsFrozen;
ObjectDefineProperty = from.ObjectDefineProperty;
ToNumber = from.ToNumber;
});
// -------------------------------------------------------------------
......
......@@ -12,11 +12,12 @@
// Imports
var GlobalObject = global.Object;
var MathMax;
var ToNumber;
utils.Import(function(from) {
MathMax = from.MathMax;
ToNumber = from.ToNumber;
});
// -------------------------------------------------------------------
......@@ -49,8 +50,8 @@ function AtomicsCompareExchangeJS(sta, index, oldValue, newValue) {
if (index < 0 || index >= %_TypedArrayGetLength(sta)) {
return UNDEFINED;
}
oldValue = $toNumber(oldValue);
newValue = $toNumber(newValue);
oldValue = ToNumber(oldValue);
newValue = ToNumber(newValue);
return %_AtomicsCompareExchange(sta, index, oldValue, newValue);
}
......@@ -69,7 +70,7 @@ function AtomicsStoreJS(sta, index, value) {
if (index < 0 || index >= %_TypedArrayGetLength(sta)) {
return UNDEFINED;
}
value = $toNumber(value);
value = ToNumber(value);
return %_AtomicsStore(sta, index, value);
}
......@@ -79,7 +80,7 @@ function AtomicsAddJS(ia, index, value) {
if (index < 0 || index >= %_TypedArrayGetLength(ia)) {
return UNDEFINED;
}
value = $toNumber(value);
value = ToNumber(value);
return %_AtomicsAdd(ia, index, value);
}
......@@ -89,7 +90,7 @@ function AtomicsSubJS(ia, index, value) {
if (index < 0 || index >= %_TypedArrayGetLength(ia)) {
return UNDEFINED;
}
value = $toNumber(value);
value = ToNumber(value);
return %_AtomicsSub(ia, index, value);
}
......@@ -99,7 +100,7 @@ function AtomicsAndJS(ia, index, value) {
if (index < 0 || index >= %_TypedArrayGetLength(ia)) {
return UNDEFINED;
}
value = $toNumber(value);
value = ToNumber(value);
return %_AtomicsAnd(ia, index, value);
}
......@@ -109,7 +110,7 @@ function AtomicsOrJS(ia, index, value) {
if (index < 0 || index >= %_TypedArrayGetLength(ia)) {
return UNDEFINED;
}
value = $toNumber(value);
value = ToNumber(value);
return %_AtomicsOr(ia, index, value);
}
......@@ -119,7 +120,7 @@ function AtomicsXorJS(ia, index, value) {
if (index < 0 || index >= %_TypedArrayGetLength(ia)) {
return UNDEFINED;
}
value = $toNumber(value);
value = ToNumber(value);
return %_AtomicsXor(ia, index, value);
}
......@@ -129,7 +130,7 @@ function AtomicsExchangeJS(ia, index, value) {
if (index < 0 || index >= %_TypedArrayGetLength(ia)) {
return UNDEFINED;
}
value = $toNumber(value);
value = ToNumber(value);
return %_AtomicsExchange(ia, index, value);
}
......@@ -148,7 +149,7 @@ function AtomicsFutexWaitJS(ia, index, value, timeout) {
if (IS_UNDEFINED(timeout)) {
timeout = INFINITY;
} else {
timeout = $toNumber(timeout);
timeout = ToNumber(timeout);
if (NUMBER_IS_NAN(timeout)) {
timeout = INFINITY;
} else {
......
......@@ -13,7 +13,6 @@
// Imports
var GlobalObject = global.Object;
var OwnPropertyKeys;
utils.Import(function(from) {
......
......@@ -8,7 +8,15 @@
%CheckIsBootstrapping();
// -------------------------------------------------------------------
// Imports
var GlobalRegExp = global.RegExp;
var ToString;
utils.Import(function(from) {
ToString = from.ToString;
});
// -------------------------------------------------------------------
......@@ -16,7 +24,7 @@ var GlobalRegExp = global.RegExp;
// + https://bugs.ecmascript.org/show_bug.cgi?id=3423
function RegExpGetFlags() {
if (!IS_SPEC_OBJECT(this)) {
throw MakeTypeError(kFlagsGetterNonObject, $toString(this));
throw MakeTypeError(kFlagsGetterNonObject, ToString(this));
}
var result = '';
if (this.global) result += 'g';
......
......@@ -51,6 +51,7 @@ var IsNaN;
var MathMax;
var MathMin;
var PackedArrayReverse;
var ToNumber;
utils.Import(function(from) {
ArrayFrom = from.ArrayFrom;
......@@ -75,6 +76,7 @@ utils.Import(function(from) {
MathMax = from.MathMax;
MathMin = from.MathMin;
PackedArrayReverse = from.PackedArrayReverse;
ToNumber = from.ToNumber;
});
// -------------------------------------------------------------------
......
......@@ -17,21 +17,18 @@
// -------------------------------------------------------------------
// Imports
var ArrayIndexOf;
var ArrayJoin;
var IsFinite;
var IsNaN;
var GlobalBoolean = global.Boolean;
var GlobalDate = global.Date;
var GlobalNumber = global.Number;
var GlobalRegExp = global.RegExp;
var GlobalString = global.String;
var ObjectDefineProperties = utils.ObjectDefineProperties;
var ObjectDefineProperty = utils.ObjectDefineProperty;
var SetFunctionName = utils.SetFunctionName;
var ArrayIndexOf;
var ArrayJoin;
var IsFinite;
var IsNaN;
var MathFloor;
var RegExpTest;
var SetFunctionName = utils.SetFunctionName;
var StringIndexOf;
var StringLastIndexOf;
var StringMatch;
......@@ -54,6 +51,12 @@ utils.Import(function(from) {
StringSplit = from.StringSplit;
StringSubstr = from.StringSubstr;
StringSubstring = from.StringSubstring;
ToNumber = from.ToNumber;
});
utils.ImportNow(function(from) {
ObjectDefineProperties = from.ObjectDefineProperties;
ObjectDefineProperty = from.ObjectDefineProperty;
});
// -------------------------------------------------------------------
......@@ -1276,7 +1279,7 @@ SetFunctionName(Intl.NumberFormat.supportedLocalesOf, 'supportedLocalesOf');
*/
function formatNumber(formatter, value) {
// Spec treats -0 and +0 as 0.
var number = $toNumber(value) + 0;
var number = ToNumber(value) + 0;
return %InternalNumberFormat(%GetImplFromInitializedIntlObject(formatter),
number);
......@@ -1701,7 +1704,7 @@ function formatDate(formatter, dateValue) {
if (IS_UNDEFINED(dateValue)) {
dateMs = %DateCurrentTime();
} else {
dateMs = $toNumber(dateValue);
dateMs = ToNumber(dateValue);
}
if (!IsFinite(dateMs)) throw MakeRangeError(kDateRange);
......
......@@ -13,15 +13,18 @@
var GlobalJSON = global.JSON;
var InternalArray = utils.InternalArray;
var MathMax;
var MathMin;
var ObjectHasOwnProperty;
var ToNumber;
var ToString;
utils.Import(function(from) {
MathMax = from.MathMax;
MathMin = from.MathMin;
ObjectHasOwnProperty = from.ObjectHasOwnProperty;
ToNumber = from.ToNumber;
ToString = from.ToString;
});
// -------------------------------------------------------------------
......@@ -162,10 +165,10 @@ function JSONSerialize(key, holder, replacer, stack, indent, gap) {
if (IS_ARRAY(value)) {
return SerializeArray(value, replacer, stack, indent, gap);
} else if (IS_NUMBER_WRAPPER(value)) {
value = $toNumber(value);
value = ToNumber(value);
return JSON_NUMBER_TO_STRING(value);
} else if (IS_STRING_WRAPPER(value)) {
return %QuoteJSONString($toString(value));
return %QuoteJSONString(ToString(value));
} else if (IS_BOOLEAN_WRAPPER(value)) {
return %_ValueOf(value) ? "true" : "false";
} else {
......@@ -194,7 +197,7 @@ function JSONStringify(value, replacer, space) {
} else if (IS_NUMBER(v)) {
item = %_NumberToString(v);
} else if (IS_STRING_WRAPPER(v) || IS_NUMBER_WRAPPER(v)) {
item = $toString(v);
item = ToString(v);
} else {
continue;
}
......@@ -208,9 +211,9 @@ function JSONStringify(value, replacer, space) {
if (IS_OBJECT(space)) {
// Unwrap 'space' if it is wrapped
if (IS_NUMBER_WRAPPER(space)) {
space = $toNumber(space);
space = ToNumber(space);
} else if (IS_STRING_WRAPPER(space)) {
space = $toString(space);
space = ToString(space);
}
}
var gap;
......
......@@ -145,9 +145,9 @@ define kBoundArgumentsStartIndex = 2;
# Inline macros. Use %IS_VAR to make sure arg is evaluated only once.
macro NUMBER_IS_NAN(arg) = (!%_IsSmi(%IS_VAR(arg)) && !(arg == arg));
macro NUMBER_IS_FINITE(arg) = (%_IsSmi(%IS_VAR(arg)) || ((arg == arg) && (arg != 1/0) && (arg != -1/0)));
macro TO_INTEGER(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToInteger($toNumber(arg)));
macro TO_INTEGER_FOR_SIDE_EFFECT(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : $toNumber(arg));
macro TO_INTEGER_MAP_MINUS_ZERO(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToIntegerMapMinusZero($toNumber(arg)));
macro TO_INTEGER(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToInteger(ToNumber(arg)));
macro TO_INTEGER_FOR_SIDE_EFFECT(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : ToNumber(arg));
macro TO_INTEGER_MAP_MINUS_ZERO(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToIntegerMapMinusZero(ToNumber(arg)));
macro TO_INT32(arg) = (arg | 0);
macro TO_UINT32(arg) = (arg >>> 0);
macro TO_STRING_INLINE(arg) = (IS_STRING(%IS_VAR(arg)) ? arg : $nonStringToString(arg));
......
......@@ -22,38 +22,43 @@ var MakeURIError;
// -------------------------------------------------------------------
// Imports
var ArrayJoin;
var Bool16x8ToString;
var Bool32x4ToString;
var Bool8x16ToString;
var Float32x4ToString;
var FunctionSourceString
var GlobalObject = global.Object;
var Int16x8ToString;
var Int32x4ToString;
var Int8x16ToString;
var InternalArray = utils.InternalArray;
var ObjectDefineProperty = utils.ObjectDefineProperty;
var ArrayJoin;
var ObjectDefineProperty;
var ObjectToString;
var StringCharAt;
var StringIndexOf;
var StringSubstring;
var Float32x4ToString;
var Int32x4ToString;
var Bool32x4ToString;
var Int16x8ToString;
var Bool16x8ToString;
var Int8x16ToString;
var Bool8x16ToString;
var ToString;
utils.Import(function(from) {
ArrayJoin = from.ArrayJoin;
Bool16x8ToString = from.Bool16x8ToString;
Bool32x4ToString = from.Bool32x4ToString;
Bool8x16ToString = from.Bool8x16ToString;
Float32x4ToString = from.Float32x4ToString;
FunctionSourceString = from.FunctionSourceString;
Int16x8ToString = from.Int16x8ToString;
Int32x4ToString = from.Int32x4ToString;
Int8x16ToString = from.Int8x16ToString;
ObjectDefineProperty = from.ObjectDefineProperty;
ObjectToString = from.ObjectToString;
StringCharAt = from.StringCharAt;
StringIndexOf = from.StringIndexOf;
StringSubstring = from.StringSubstring;
Float32x4ToString = from.Float32x4ToString;
Int32x4ToString = from.Int32x4ToString;
Bool32x4ToString = from.Bool32x4ToString;
Int16x8ToString = from.Int16x8ToString;
Bool16x8ToString = from.Bool16x8ToString;
Int8x16ToString = from.Int8x16ToString;
Bool8x16ToString = from.Bool8x16ToString;
});
utils.ImportNow(function(from) {
ToString = from.ToString;
});
// -------------------------------------------------------------------
......@@ -81,7 +86,7 @@ function NoSideEffectToString(obj) {
if (IS_UNDEFINED(obj)) return 'undefined';
if (IS_NULL(obj)) return 'null';
if (IS_FUNCTION(obj)) {
var str = %_CallFunction(obj, obj, $functionSourceString);
var str = %_CallFunction(obj, obj, FunctionSourceString);
if (str.length > 128) {
str = %_SubString(str, 0, 111) + "...<omitted>..." +
%_SubString(str, str.length - 2, str.length);
......@@ -147,7 +152,7 @@ function ToStringCheckErrorObject(obj) {
if (CanBeSafelyTreatedAsAnErrorObject(obj)) {
return %_CallFunction(obj, ErrorToString);
} else {
return $toString(obj);
return ToString(obj);
}
}
......@@ -968,7 +973,7 @@ function DefineError(global, f) {
// object. This avoids going through getters and setters defined
// on prototype objects.
if (!IS_UNDEFINED(m)) {
%AddNamedProperty(this, 'message', $toString(m), DONT_ENUM);
%AddNamedProperty(this, 'message', ToString(m), DONT_ENUM);
}
} else {
return new f(m);
......
......@@ -12,17 +12,16 @@
// Utils
var imports = UNDEFINED;
var exports = UNDEFINED;
var imports_from_experimental = UNDEFINED;
var exports_to_runtime = UNDEFINED;
var exports_container = {};
// Export to other scripts.
// In normal natives, this exports functions to other normal natives.
// In experimental natives, this exports to other experimental natives and
// to normal natives that import using utils.ImportFromExperimental.
function Export(f) {
f.next = exports;
exports = f;
f(exports_container);
}
......@@ -32,7 +31,11 @@ function ExportToRuntime(f) {
exports_to_runtime = f;
}
// Import from other scripts.
// Import from other scripts. The actual importing happens in PostNatives and
// PostExperimental so that we can import from scripts executed later. However,
// that means that the import is not available until the very end. If the
// import needs to be available immediate, use ImportNow.
// In normal natives, this imports from other normal natives.
// In experimental natives, this imports from other experimental natives and
// whitelisted exports from normal natives.
......@@ -41,6 +44,13 @@ function Import(f) {
imports = f;
}
// Import immediately from exports of previous scripts. We need this for
// functions called during bootstrapping. Hooking up imports in PostNatives
// would be too late.
function ImportNow(f) {
f(exports_container);
}
// In normal natives, import from experimental natives.
// Not callable from experimental natives.
......@@ -149,14 +159,12 @@ function SetUpLockedPrototype(
// -----------------------------------------------------------------------
// To be called by bootstrapper
var experimental_exports = UNDEFINED;
function PostNatives(utils) {
%CheckIsBootstrapping();
var container = {};
for ( ; !IS_UNDEFINED(exports); exports = exports.next) exports(container);
for ( ; !IS_UNDEFINED(imports); imports = imports.next) imports(container);
for ( ; !IS_UNDEFINED(imports); imports = imports.next) {
imports(exports_container);
}
var runtime_container = {};
for ( ; !IS_UNDEFINED(exports_to_runtime);
......@@ -165,9 +173,10 @@ function PostNatives(utils) {
}
%ImportToRuntime(runtime_container);
// Whitelist of exports from normal natives to experimental natives.
var expose_to_experimental = [
// Whitelist of exports from normal natives to experimental natives and debug.
var expose_list = [
"ArrayToString",
"FunctionSourceString",
"GetIterator",
"GetMethod",
"InnerArrayEvery",
......@@ -190,15 +199,19 @@ function PostNatives(utils) {
"ObjectDefineProperty",
"OwnPropertyKeys",
"ToNameArray",
"ToBoolean",
"ToNumber",
"ToString",
];
experimental_exports = {};
var filtered_exports = {};
%OptimizeObjectForAddingMultipleProperties(
experimental_exports, expose_to_experimental.length);
for (var key of expose_to_experimental) {
experimental_exports[key] = container[key];
filtered_exports, expose_list.length);
for (var key of expose_list) {
filtered_exports[key] = exports_container[key];
}
%ToFastProperties(experimental_exports);
container = UNDEFINED;
%ToFastProperties(filtered_exports);
exports_container = filtered_exports;
utils.PostNatives = UNDEFINED;
utils.ImportFromExperimental = UNDEFINED;
......@@ -208,15 +221,12 @@ function PostNatives(utils) {
function PostExperimentals(utils) {
%CheckIsBootstrapping();
for ( ; !IS_UNDEFINED(exports); exports = exports.next) {
exports(experimental_exports);
}
for ( ; !IS_UNDEFINED(imports); imports = imports.next) {
imports(experimental_exports);
imports(exports_container);
}
for ( ; !IS_UNDEFINED(imports_from_experimental);
imports_from_experimental = imports_from_experimental.next) {
imports_from_experimental(experimental_exports);
imports_from_experimental(exports_container);
}
var runtime_container = {};
for ( ; !IS_UNDEFINED(exports_to_runtime);
......@@ -225,7 +235,7 @@ function PostExperimentals(utils) {
}
%ImportExperimentalToRuntime(runtime_container);
experimental_exports = UNDEFINED;
exports_container = UNDEFINED;
utils.PostExperimentals = UNDEFINED;
utils.PostDebug = UNDEFINED;
......@@ -235,13 +245,12 @@ function PostExperimentals(utils) {
function PostDebug(utils) {
for ( ; !IS_UNDEFINED(exports); exports = exports.next) {
exports(experimental_exports);
}
for ( ; !IS_UNDEFINED(imports); imports = imports.next) {
imports(experimental_exports);
imports(exports_container);
}
exports_container = UNDEFINED;
utils.PostDebug = UNDEFINED;
utils.PostExperimentals = UNDEFINED;
utils.Import = UNDEFINED;
......@@ -250,9 +259,10 @@ function PostDebug(utils) {
// -----------------------------------------------------------------------
%OptimizeObjectForAddingMultipleProperties(utils, 13);
%OptimizeObjectForAddingMultipleProperties(utils, 14);
utils.Import = Import;
utils.ImportNow = ImportNow;
utils.Export = Export;
utils.ExportToRuntime = ExportToRuntime;
utils.ImportFromExperimental = ImportFromExperimental;
......
......@@ -16,6 +16,10 @@ var harmony_unicode_regexps = false;
var GlobalRegExp = global.RegExp;
var InternalPackedArray = utils.InternalPackedArray;
utils.Import(function(from) {
ToNumber = from.ToNumber;
});
// -------------------------------------------------------------------
// Property of the builtins object for recording the result of the last
......
......@@ -66,7 +66,6 @@ var $nonNumberToNumber;
var $nonStringToString;
var $sameValue;
var $sameValueZero;
var $toBoolean;
var $toInteger;
var $toLength;
var $toName;
......@@ -907,7 +906,6 @@ $nonNumberToNumber = NonNumberToNumber;
$nonStringToString = NonStringToString;
$sameValue = SameValue;
$sameValueZero = SameValueZero;
$toBoolean = ToBoolean;
$toInteger = ToInteger;
$toLength = ToLength;
$toName = ToName;
......@@ -917,10 +915,16 @@ $toPrimitive = ToPrimitive;
$toString = ToString;
utils.ExportToRuntime(function(to) {
to.ToNumber = $toNumber;
to.ToString = $toString;
to.ToInteger = $toInteger;
to.ToLength = $toLength;
to.ToNumber = ToNumber;
to.ToString = ToString;
to.ToInteger = ToInteger;
to.ToLength = ToLength;
});
utils.Export(function(to) {
to.ToBoolean = ToBoolean;
to.ToNumber = ToNumber;
to.ToString = ToString;
})
})
......@@ -9,18 +9,19 @@
// -------------------------------------------------------------------
// Imports
var ArrayIndexOf;
var ArrayJoin;
var GlobalRegExp = global.RegExp;
var GlobalString = global.String;
var InternalArray = utils.InternalArray;
var InternalPackedArray = utils.InternalPackedArray;
var ArrayIndexOf;
var ArrayJoin;
var MathMax;
var MathMin;
var RegExpExec;
var RegExpExecNoTests;
var RegExpLastMatchInfo;
var ToNumber;
var ToString;
utils.Import(function(from) {
ArrayIndexOf = from.ArrayIndexOf;
......@@ -30,6 +31,8 @@ utils.Import(function(from) {
RegExpExec = from.RegExpExec;
RegExpExecNoTests = from.RegExpExecNoTests;
RegExpLastMatchInfo = from.RegExpLastMatchInfo;
ToNumber = from.ToNumber;
ToString = from.ToString;
});
//-------------------------------------------------------------------
......@@ -132,7 +135,7 @@ function StringLastIndexOfJS(pat /* position */) { // length == 1
var patLength = pat.length;
var index = subLength - patLength;
if (%_ArgumentsLength() > 1) {
var position = $toNumber(%_Arguments(1));
var position = ToNumber(%_Arguments(1));
if (!NUMBER_IS_NAN(position)) {
position = TO_INTEGER(position);
if (position < 0) {
......@@ -823,7 +826,7 @@ function StringTrimRight() {
function StringFromCharCode(code) {
var n = %_ArgumentsLength();
if (n == 1) {
if (!%_IsSmi(code)) code = $toNumber(code);
if (!%_IsSmi(code)) code = ToNumber(code);
return %_StringCharFromCode(code & 0xffff);
}
......@@ -831,7 +834,7 @@ function StringFromCharCode(code) {
var i;
for (i = 0; i < n; i++) {
var code = %_Arguments(i);
if (!%_IsSmi(code)) code = $toNumber(code) & 0xffff;
if (!%_IsSmi(code)) code = ToNumber(code) & 0xffff;
if (code < 0) code = code & 0xffff;
if (code > 0xff) break;
%_OneByteSeqStringSetChar(i, code, one_byte);
......@@ -842,7 +845,7 @@ function StringFromCharCode(code) {
var two_byte = %NewString(n - i, NEW_TWO_BYTE_STRING);
for (var j = 0; i < n; i++, j++) {
var code = %_Arguments(i);
if (!%_IsSmi(code)) code = $toNumber(code) & 0xffff;
if (!%_IsSmi(code)) code = ToNumber(code) & 0xffff;
%_TwoByteSeqStringSetChar(j, code, two_byte);
}
return one_byte + two_byte;
......@@ -1088,7 +1091,7 @@ function StringFromCodePoint(_) { // length = 1
for (index = 0; index < length; index++) {
code = %_Arguments(index);
if (!%_IsSmi(code)) {
code = $toNumber(code);
code = ToNumber(code);
}
if (code < 0 || code > 0x10FFFF || code !== TO_INTEGER(code)) {
throw MakeRangeError(kInvalidCodePoint, code);
......@@ -1117,13 +1120,13 @@ function StringRaw(callSite) {
var literalSegments = $toLength(raw.length);
if (literalSegments <= 0) return "";
var result = $toString(raw[0]);
var result = ToString(raw[0]);
for (var i = 1; i < literalSegments; ++i) {
if (i < numberOfSubstitutions) {
result += $toString(%_Arguments(i));
result += ToString(%_Arguments(i));
}
result += $toString(raw[i]);
result += ToString(raw[i]);
}
return result;
......
......@@ -23,11 +23,12 @@ var $symbolToString;
var GlobalObject = global.Object;
var GlobalSymbol = global.Symbol;
var ObjectGetOwnPropertyKeys;
var ToString;
utils.Import(function(from) {
ObjectGetOwnPropertyKeys = from.ObjectGetOwnPropertyKeys;
ToString = from.ToString;
});
// -------------------------------------------------------------------
......@@ -35,7 +36,7 @@ utils.Import(function(from) {
function SymbolConstructor(x) {
if (%_IsConstructCall()) throw MakeTypeError(kNotConstructor, "Symbol");
// NOTE: Passing in a Symbol value will throw on ToString().
return %CreateSymbol(IS_UNDEFINED(x) ? x : $toString(x));
return %CreateSymbol(IS_UNDEFINED(x) ? x : ToString(x));
}
......
......@@ -37,10 +37,12 @@ TYPED_ARRAYS(DECLARE_GLOBALS)
var MathMax;
var MathMin;
var ToNumber;
utils.Import(function(from) {
MathMax = from.MathMax;
MathMin = from.MathMin;
ToNumber = from.ToNumber;
});
var InternalArray = utils.InternalArray;
......
......@@ -17,6 +17,11 @@
var GlobalObject = global.Object;
var GlobalArray = global.Array;
var InternalArray = utils.InternalArray;
var ToString;
utils.Import(function(from) {
ToString = from.ToString;
});
// -------------------------------------------------------------------
// Define internal helper functions.
......@@ -274,13 +279,13 @@ function Decode(uri, reserved) {
// ECMA-262 - B.2.1.
function URIEscapeJS(str) {
var s = $toString(str);
var s = ToString(str);
return %URIEscape(s);
}
// ECMA-262 - B.2.2.
function URIUnescapeJS(str) {
var s = $toString(str);
var s = ToString(str);
return %URIUnescape(s);
}
......@@ -304,14 +309,14 @@ function URIDecode(uri) {
return false;
};
var string = $toString(uri);
var string = ToString(uri);
return Decode(string, reservedPredicate);
}
// ECMA-262 - 15.1.3.2.
function URIDecodeComponent(component) {
var reservedPredicate = function(cc) { return false; };
var string = $toString(component);
var string = ToString(component);
return Decode(string, reservedPredicate);
}
......@@ -338,7 +343,7 @@ function URIEncode(uri) {
return false;
};
var string = $toString(uri);
var string = ToString(uri);
return Encode(string, unescapePredicate);
}
......@@ -359,7 +364,7 @@ function URIEncodeComponent(component) {
return false;
};
var string = $toString(component);
var string = ToString(component);
return Encode(string, unescapePredicate);
}
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var $functionSourceString;
(function(global, utils) {
%CheckIsBootstrapping();
......@@ -17,16 +15,24 @@ var GlobalFunction = global.Function;
var GlobalNumber = global.Number;
var GlobalObject = global.Object;
var InternalArray = utils.InternalArray;
var MathAbs;
var ProxyDelegateCallAndConstruct;
var ProxyDerivedHasOwnTrap;
var ProxyDerivedKeysTrap;
var StringIndexOf;
var ToBoolean;
var ToNumber;
var ToString;
utils.Import(function(from) {
MathAbs = from.MathAbs;
StringIndexOf = from.StringIndexOf;
ToString = from.ToString;
});
utils.ImportNow(function(from) {
ToBoolean = from.ToBoolean;
ToNumber = from.ToNumber;
});
utils.ImportFromExperimental(function(from) {
......@@ -346,11 +352,11 @@ function ToPropertyDescriptor(obj) {
var desc = new PropertyDescriptor();
if ("enumerable" in obj) {
desc.setEnumerable($toBoolean(obj.enumerable));
desc.setEnumerable(ToBoolean(obj.enumerable));
}
if ("configurable" in obj) {
desc.setConfigurable($toBoolean(obj.configurable));
desc.setConfigurable(ToBoolean(obj.configurable));
}
if ("value" in obj) {
......@@ -358,7 +364,7 @@ function ToPropertyDescriptor(obj) {
}
if ("writable" in obj) {
desc.setWritable($toBoolean(obj.writable));
desc.setWritable(ToBoolean(obj.writable));
}
if ("get" in obj) {
......@@ -612,7 +618,7 @@ function DefineProxyProperty(obj, p, attributes, should_throw) {
var handler = %GetHandler(obj);
var result = CallTrap2(handler, "defineProperty", UNDEFINED, p, attributes);
if (!$toBoolean(result)) {
if (!ToBoolean(result)) {
if (should_throw) {
throw MakeTypeError(kProxyHandlerReturned,
handler, "false", "defineProperty");
......@@ -801,7 +807,7 @@ function DefineArrayProperty(obj, p, desc, should_throw) {
if (!IS_SYMBOL(p)) {
var index = TO_UINT32(p);
var emit_splice = false;
if ($toString(index) == p && index != 4294967295) {
if (ToString(index) == p && index != 4294967295) {
var length = obj.length;
if (index >= length && %IsObserved(obj)) {
emit_splice = true;
......@@ -969,7 +975,7 @@ function ObjectGetOwnPropertyKeys(obj, filter) {
}
} else {
if (filter & PROPERTY_ATTRIBUTES_STRING) continue;
name = $toString(name);
name = ToString(name);
}
if (seenKeys[name]) continue;
seenKeys[name] = true;
......@@ -1337,9 +1343,9 @@ utils.InstallFunctions(GlobalObject, DONT_ENUM, [
function BooleanConstructor(x) {
if (%_IsConstructCall()) {
%_SetValueOf(this, $toBoolean(x));
%_SetValueOf(this, ToBoolean(x));
} else {
return $toBoolean(x);
return ToBoolean(x);
}
}
......@@ -1385,7 +1391,7 @@ utils.InstallFunctions(GlobalBoolean.prototype, DONT_ENUM, [
// Number
function NumberConstructor(x) {
var value = %_ArgumentsLength() == 0 ? 0 : $toNumber(x);
var value = %_ArgumentsLength() == 0 ? 0 : ToNumber(x);
if (%_IsConstructCall()) {
%_SetValueOf(this, value);
} else {
......@@ -1498,7 +1504,7 @@ function NumberToPrecisionJS(precision) {
// Get the value of this number in case it's an object.
x = %_ValueOf(this);
}
if (IS_UNDEFINED(precision)) return $toString(%_ValueOf(this));
if (IS_UNDEFINED(precision)) return ToString(%_ValueOf(this));
var p = TO_INTEGER(precision);
if (NUMBER_IS_NAN(x)) return "NaN";
......@@ -1718,9 +1724,9 @@ function NewFunctionString(args, function_token) {
var n = args.length;
var p = '';
if (n > 1) {
p = $toString(args[0]);
p = ToString(args[0]);
for (var i = 1; i < n - 1; i++) {
p += ',' + $toString(args[i]);
p += ',' + ToString(args[i]);
}
// If the formal parameters string include ) - an illegal
// character - it may make the combined function expression
......@@ -1733,7 +1739,7 @@ function NewFunctionString(args, function_token) {
// comments we can include a trailing block comment to catch this.
p += '\n/' + '**/';
}
var body = (n > 0) ? $toString(args[n - 1]) : '';
var body = (n > 0) ? ToString(args[n - 1]) : '';
return '(' + function_token + '(' + p + ') {\n' + body + '\n})';
}
......@@ -1782,19 +1788,16 @@ function GetIterator(obj, method) {
// ----------------------------------------------------------------------------
// Exports
$functionSourceString = FunctionSourceString;
utils.ObjectDefineProperties = ObjectDefineProperties;
utils.ObjectDefineProperty = ObjectDefineProperty;
utils.Export(function(to) {
to.Delete = Delete;
to.FunctionSourceString = FunctionSourceString;
to.GetIterator = GetIterator;
to.GetMethod = GetMethod;
to.IsFinite = GlobalIsFinite;
to.IsNaN = GlobalIsNaN;
to.NewFunctionString = NewFunctionString;
to.NumberIsNaN = NumberIsNaN;
to.ObjectDefineProperties = ObjectDefineProperties;
to.ObjectDefineProperty = ObjectDefineProperty;
to.ObjectFreeze = ObjectFreezeJS;
to.ObjectGetOwnPropertyKeys = ObjectGetOwnPropertyKeys;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment