Commit 7a7b692b authored by bmeurer's avatar bmeurer Committed by Commit bot

[runtime] Replace %to_string_fun with %_ToString.

Introduce a new macro TO_STRING that maps to %_ToString and use that
instead of calling into any of the ToString/NonStringToString JavaScript
builtins. Also remove the TO_STRING_INLINE macro, which is basically
obsolete with %_ToString. We still have a few uses of ToString left (via
the utils export mechanism), where we need to investigate whether we
will tank badly if we replace them with TO_STRING as well.

CQ_INCLUDE_TRYBOTS=tryserver.v8:v8_linux_layout_dbg,v8_linux_nosnap_dbg
R=yangguo@chromium.org
BUG=v8:4307
LOG=n

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

Cr-Commit-Position: refs/heads/master@{#30895}
parent e392bb2e
......@@ -411,8 +411,8 @@ function ArrayToLocaleString() {
function InnerArrayJoin(separator, array, length) {
if (IS_UNDEFINED(separator)) {
separator = ',';
} else if (!IS_STRING(separator)) {
separator = $nonStringToString(separator);
} else {
separator = TO_STRING(separator);
}
var result = %_FastOneByteArrayJoin(array, separator);
......@@ -421,9 +421,8 @@ function InnerArrayJoin(separator, array, length) {
// Fast case for one-element arrays.
if (length === 1) {
var e = array[0];
if (IS_STRING(e)) return e;
if (IS_NULL_OR_UNDEFINED(e)) return '';
return $nonStringToString(e);
return TO_STRING(e);
}
return Join(array, length, separator, ConvertToString);
......
......@@ -79,14 +79,12 @@ enum BindingFlags {
V(MAKE_RANGE_ERROR_INDEX, JSFunction, make_range_error) \
V(MAKE_TYPE_ERROR_INDEX, JSFunction, make_type_error) \
V(NON_NUMBER_TO_NUMBER_INDEX, JSFunction, non_number_to_number) \
V(NON_STRING_TO_STRING_INDEX, JSFunction, non_string_to_string) \
V(REFLECT_APPLY_INDEX, JSFunction, reflect_apply) \
V(REFLECT_CONSTRUCT_INDEX, JSFunction, reflect_construct) \
V(SPREAD_ARGUMENTS_INDEX, JSFunction, spread_arguments) \
V(SPREAD_ITERABLE_INDEX, JSFunction, spread_iterable) \
V(TO_LENGTH_FUN_INDEX, JSFunction, to_length_fun) \
V(TO_NUMBER_FUN_INDEX, JSFunction, to_number_fun) \
V(TO_STRING_FUN_INDEX, JSFunction, to_string_fun)
V(TO_NUMBER_FUN_INDEX, JSFunction, to_number_fun)
#define NATIVE_CONTEXT_JS_BUILTINS(V) \
......
......@@ -22,14 +22,12 @@ var IsFinite;
var MathAbs;
var MathFloor;
var ToNumber;
var ToString;
utils.Import(function(from) {
IsFinite = from.IsFinite;
MathAbs = from.MathAbs;
MathFloor = from.MathFloor;
ToNumber = from.ToNumber;
ToString = from.ToString;
});
// -------------------------------------------------------------------
......@@ -268,7 +266,7 @@ var parse_buffer = new InternalArray(8);
// ECMA 262 - 15.9.4.2
function DateParse(string) {
var arr = %DateParseString(ToString(string), parse_buffer);
var arr = %DateParseString(string, parse_buffer);
if (IS_NULL(arr)) return NAN;
var day = MakeDay(arr[0], arr[1], arr[2]);
......
......@@ -12,11 +12,6 @@
// Imports
var GlobalRegExp = global.RegExp;
var ToString;
utils.Import(function(from) {
ToString = from.ToString;
});
// -------------------------------------------------------------------
......@@ -24,7 +19,7 @@ utils.Import(function(from) {
// + https://bugs.ecmascript.org/show_bug.cgi?id=3423
function RegExpGetFlags() {
if (!IS_SPEC_OBJECT(this)) {
throw MakeTypeError(kFlagsGetterNonObject, ToString(this));
throw MakeTypeError(kFlagsGetterNonObject, TO_STRING(this));
}
var result = '';
if (this.global) result += 'g';
......
......@@ -2004,10 +2004,10 @@ OverrideFunction(GlobalString.prototype, 'normalize', function() {
}
CHECK_OBJECT_COERCIBLE(this, "String.prototype.normalize");
var s = TO_STRING_INLINE(this);
var s = TO_STRING(this);
var formArg = %_Arguments(0);
var form = IS_UNDEFINED(formArg) ? 'NFC' : TO_STRING_INLINE(formArg);
var form = IS_UNDEFINED(formArg) ? 'NFC' : TO_STRING(formArg);
var NORMALIZATION_FORMS = ['NFC', 'NFD', 'NFKC', 'NFKD'];
......
......@@ -17,7 +17,6 @@ var MathMax;
var MathMin;
var ObjectHasOwnProperty;
var ToNumber;
var ToString;
var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol");
utils.Import(function(from) {
......@@ -25,7 +24,6 @@ utils.Import(function(from) {
MathMin = from.MathMin;
ObjectHasOwnProperty = from.ObjectHasOwnProperty;
ToNumber = from.ToNumber;
ToString = from.ToString;
});
// -------------------------------------------------------------------
......@@ -57,7 +55,7 @@ function Revive(holder, name, reviver) {
function JSONParse(text, reviver) {
var unfiltered = %ParseJson(TO_STRING_INLINE(text));
var unfiltered = %ParseJson(text);
if (IS_CALLABLE(reviver)) {
return Revive({'': unfiltered}, '', reviver);
} else {
......@@ -161,7 +159,7 @@ function JSONSerialize(key, holder, replacer, stack, indent, gap) {
return value ? "true" : "false";
} else if (IS_NULL(value)) {
return "null";
} else if (IS_SPEC_OBJECT(value) && !(typeof value == "function")) {
} else if (IS_SPEC_OBJECT(value) && !IS_CALLABLE(value)) {
// Non-callable object. If it's a primitive wrapper, it must be unwrapped.
if (IS_ARRAY(value)) {
return SerializeArray(value, replacer, stack, indent, gap);
......@@ -169,7 +167,7 @@ function JSONSerialize(key, holder, replacer, stack, indent, gap) {
value = ToNumber(value);
return JSON_NUMBER_TO_STRING(value);
} else if (IS_STRING_WRAPPER(value)) {
return %QuoteJSONString(ToString(value));
return %QuoteJSONString(TO_STRING(value));
} else if (IS_BOOLEAN_WRAPPER(value)) {
return %_ValueOf(value) ? "true" : "false";
} else {
......@@ -198,7 +196,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 = TO_STRING(v);
} else {
continue;
}
......@@ -214,7 +212,7 @@ function JSONStringify(value, replacer, space) {
if (IS_NUMBER_WRAPPER(space)) {
space = ToNumber(space);
} else if (IS_STRING_WRAPPER(space)) {
space = ToString(space);
space = TO_STRING(space);
}
}
var gap;
......
......@@ -147,7 +147,7 @@ macro TO_INTEGER_MAP_MINUS_ZERO(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToI
macro TO_INT32(arg) = (arg | 0);
macro TO_UINT32(arg) = (arg >>> 0);
macro TO_LENGTH_OR_UINT32(arg) = (harmony_tolength ? $toLength(arg) : TO_UINT32(arg));
macro TO_STRING_INLINE(arg) = (IS_STRING(%IS_VAR(arg)) ? arg : $nonStringToString(arg));
macro TO_STRING(arg) = (%_ToString(arg));
macro TO_NUMBER_INLINE(arg) = (IS_NUMBER(%IS_VAR(arg)) ? arg : $nonNumberToNumber(arg));
macro TO_OBJECT(arg) = (%_ToObject(arg));
macro TO_PRIMITIVE(arg) = (%_ToPrimitive(arg));
......
......@@ -49,7 +49,6 @@ var StringCharAt;
var StringIndexOf;
var StringSubstring;
var SymbolToString;
var ToString = utils.ImportNow("ToString");
var Uint16x8ToString;
var Uint32x4ToString;
var Uint8x16ToString;
......@@ -169,7 +168,7 @@ function ToStringCheckErrorObject(obj) {
if (CanBeSafelyTreatedAsAnErrorObject(obj)) {
return %_CallFunction(obj, ErrorToString);
} else {
return ToString(obj);
return TO_STRING(obj);
}
}
......@@ -953,7 +952,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', TO_STRING(m), DONT_ENUM);
}
} else {
return new f(m);
......
......@@ -6102,8 +6102,8 @@ Expression* Parser::CloseTemplateLiteral(TemplateLiteralState* state, int start,
ZoneList<Expression*>* args =
new (zone()) ZoneList<Expression*>(1, zone());
args->Add(sub, zone());
Expression* middle = factory()->NewCallRuntime(
Context::TO_STRING_FUN_INDEX, args, sub->position());
Expression* middle = factory()->NewCallRuntime(Runtime::kInlineToString,
args, sub->position());
expr = factory()->NewBinaryOperation(
Token::ADD, factory()->NewBinaryOperation(
......
......@@ -145,7 +145,7 @@ function DerivedKeysTrap() {
for (var i = 0, count = 0; i < names.length; ++i) {
var name = names[i]
if (IS_SYMBOL(name)) continue
var desc = this.getOwnPropertyDescriptor(TO_STRING_INLINE(name))
var desc = this.getOwnPropertyDescriptor(TO_STRING(name))
if (!IS_UNDEFINED(desc) && desc.enumerable) {
enumerableNames[count++] = names[i]
}
......@@ -159,7 +159,7 @@ function DerivedEnumerateTrap() {
for (var i = 0, count = 0; i < names.length; ++i) {
var name = names[i]
if (IS_SYMBOL(name)) continue
var desc = this.getPropertyDescriptor(TO_STRING_INLINE(name))
var desc = this.getPropertyDescriptor(TO_STRING(name))
if (!IS_UNDEFINED(desc)) {
if (!desc.configurable) {
throw MakeTypeError(kProxyPropNotConfigurable,
......
......@@ -66,8 +66,8 @@ function DoConstructRegExp(object, pattern, flags) {
pattern = pattern.source;
}
pattern = IS_UNDEFINED(pattern) ? '' : $toString(pattern);
flags = IS_UNDEFINED(flags) ? '' : $toString(flags);
pattern = IS_UNDEFINED(pattern) ? '' : TO_STRING(pattern);
flags = IS_UNDEFINED(flags) ? '' : TO_STRING(flags);
%RegExpInitializeAndCompile(object, pattern, flags);
}
......@@ -161,7 +161,7 @@ function RegExpExecJS(string) {
'RegExp.prototype.exec', this);
}
string = TO_STRING_INLINE(string);
string = TO_STRING(string);
var lastIndex = this.lastIndex;
// Conversion is required by the ES5 specification (RegExp.prototype.exec
......@@ -208,7 +208,7 @@ function RegExpTest(string) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'RegExp.prototype.test', this);
}
string = TO_STRING_INLINE(string);
string = TO_STRING(string);
var lastIndex = this.lastIndex;
......@@ -392,7 +392,7 @@ var RegExpGetInput = function() {
return IS_UNDEFINED(regExpInput) ? "" : regExpInput;
};
var RegExpSetInput = function(string) {
LAST_INPUT(RegExpLastMatchInfo) = $toString(string);
LAST_INPUT(RegExpLastMatchInfo) = TO_STRING(string);
};
%OptimizeObjectForAddingMultipleProperties(GlobalRegExp, 22);
......
......@@ -14,14 +14,12 @@
var $defaultString;
var $NaN;
var $nonNumberToNumber;
var $nonStringToString;
var $sameValue;
var $sameValueZero;
var $toInteger;
var $toLength;
var $toNumber;
var $toPositiveInteger;
var $toString;
var harmony_tolength = false;
......@@ -47,8 +45,7 @@ function APPLY_PREPARE(args) {
// First check that the receiver is callable.
if (!IS_CALLABLE(this)) {
throw %make_type_error(kApplyNonFunction, %to_string_fun(this),
typeof this);
throw %make_type_error(kApplyNonFunction, TO_STRING(this), typeof this);
}
// First check whether length is a positive Smi and args is an
......@@ -84,8 +81,7 @@ function REFLECT_APPLY_PREPARE(args) {
// First check that the receiver is callable.
if (!IS_CALLABLE(this)) {
throw %make_type_error(kApplyNonFunction, %to_string_fun(this),
typeof this);
throw %make_type_error(kApplyNonFunction, TO_STRING(this), typeof this);
}
// First check whether length is a positive Smi and args is an
......@@ -134,17 +130,17 @@ function REFLECT_CONSTRUCT_PREPARE(
if (!ctorOk) {
if (!IS_CALLABLE(this)) {
throw %make_type_error(kCalledNonCallable, %to_string_fun(this));
throw %make_type_error(kCalledNonCallable, TO_STRING(this));
} else {
throw %make_type_error(kNotConstructor, %to_string_fun(this));
throw %make_type_error(kNotConstructor, TO_STRING(this));
}
}
if (!newTargetOk) {
if (!IS_CALLABLE(newTarget)) {
throw %make_type_error(kCalledNonCallable, %to_string_fun(newTarget));
throw %make_type_error(kCalledNonCallable, TO_STRING(newTarget));
} else {
throw %make_type_error(kNotConstructor, %to_string_fun(newTarget));
throw %make_type_error(kNotConstructor, TO_STRING(newTarget));
}
}
......@@ -220,14 +216,6 @@ function ToString(x) {
return (IS_NULL(x)) ? 'null' : ToString(DefaultString(x));
}
function NonStringToString(x) {
if (IS_NUMBER(x)) return %_NumberToString(x);
if (IS_BOOLEAN(x)) return x ? 'true' : 'false';
if (IS_UNDEFINED(x)) return 'undefined';
// Types that can't be converted to string are caught in DefaultString.
return (IS_NULL(x)) ? 'null' : ToString(DefaultString(x));
}
// ECMA-262, section 9.4, page 34.
function ToInteger(x) {
......@@ -360,14 +348,12 @@ function ToPositiveInteger(x, rangeErrorIndex) {
$defaultString = DefaultString;
$NaN = %GetRootNaN();
$nonNumberToNumber = NonNumberToNumber;
$nonStringToString = NonStringToString;
$sameValue = SameValue;
$sameValueZero = SameValueZero;
$toInteger = ToInteger;
$toLength = ToLength;
$toNumber = ToNumber;
$toPositiveInteger = ToPositiveInteger;
$toString = ToString;
%InstallToContext([
"apply_prepare_builtin", APPLY_PREPARE,
......@@ -379,11 +365,9 @@ $toString = ToString;
%InstallToContext([
"concat_iterable_to_array", ConcatIterableToArray,
"non_number_to_number", NonNumberToNumber,
"non_string_to_string", NonStringToString,
"to_integer_fun", ToInteger,
"to_length_fun", ToLength,
"to_number_fun", ToNumber,
"to_string_fun", ToString,
]);
utils.Export(function(to) {
......
......@@ -100,8 +100,8 @@ RUNTIME_FUNCTION(Runtime_DateCurrentTime) {
RUNTIME_FUNCTION(Runtime_DateParseString) {
HandleScope scope(isolate);
DCHECK(args.length() == 2);
CONVERT_ARG_HANDLE_CHECKED(String, str, 0);
DCHECK_EQ(2, args.length());
CONVERT_ARG_HANDLE_CHECKED(Object, input, 0);
CONVERT_ARG_HANDLE_CHECKED(JSArray, output, 1);
RUNTIME_ASSERT(output->HasFastElements());
......@@ -110,6 +110,10 @@ RUNTIME_FUNCTION(Runtime_DateParseString) {
Handle<FixedArray> output_array(FixedArray::cast(output->elements()));
RUNTIME_ASSERT(output_array->length() >= DateParser::OUTPUT_SIZE);
Handle<String> str;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, str,
Object::ToString(isolate, input));
str = String::Flatten(str);
DisallowHeapAllocation no_gc;
......
......@@ -39,9 +39,11 @@ RUNTIME_FUNCTION(Runtime_BasicJSONStringify) {
RUNTIME_FUNCTION(Runtime_ParseJson) {
HandleScope scope(isolate);
DCHECK(args.length() == 1);
CONVERT_ARG_HANDLE_CHECKED(String, source, 0);
DCHECK_EQ(1, args.length());
CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
Handle<String> source;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, source,
Object::ToString(isolate, object));
source = String::Flatten(source);
// Optimized fast case where we only have Latin1 characters.
Handle<Object> result;
......@@ -51,5 +53,6 @@ RUNTIME_FUNCTION(Runtime_ParseJson) {
: JsonParser<false>::Parse(source));
return *result;
}
} // namespace internal
} // namespace v8
......@@ -258,13 +258,15 @@ MaybeHandle<String> URIEscape::Escape(Isolate* isolate, Handle<String> string) {
RUNTIME_FUNCTION(Runtime_URIEscape) {
HandleScope scope(isolate);
DCHECK(args.length() == 1);
CONVERT_ARG_HANDLE_CHECKED(String, source, 0);
Handle<String> string = String::Flatten(source);
DCHECK(string->IsFlat());
DCHECK_EQ(1, args.length());
CONVERT_ARG_HANDLE_CHECKED(Object, input, 0);
Handle<String> source;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, source,
Object::ToString(isolate, input));
source = String::Flatten(source);
Handle<String> result;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, result, string->IsOneByteRepresentationUnderneath()
isolate, result, source->IsOneByteRepresentationUnderneath()
? URIEscape::Escape<uint8_t>(isolate, source)
: URIEscape::Escape<uc16>(isolate, source));
return *result;
......@@ -274,15 +276,18 @@ RUNTIME_FUNCTION(Runtime_URIEscape) {
RUNTIME_FUNCTION(Runtime_URIUnescape) {
HandleScope scope(isolate);
DCHECK(args.length() == 1);
CONVERT_ARG_HANDLE_CHECKED(String, source, 0);
Handle<String> string = String::Flatten(source);
DCHECK(string->IsFlat());
CONVERT_ARG_HANDLE_CHECKED(Object, input, 0);
Handle<String> source;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, source,
Object::ToString(isolate, input));
source = String::Flatten(source);
Handle<String> result;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, result, string->IsOneByteRepresentationUnderneath()
isolate, result, source->IsOneByteRepresentationUnderneath()
? URIUnescape::Unescape<uint8_t>(isolate, source)
: URIUnescape::Unescape<uc16>(isolate, source));
return *result;
}
} // namespace internal
} // namespace v8
......@@ -26,7 +26,7 @@ function StringIterator() {}
// 21.1.5.1 CreateStringIterator Abstract Operation
function CreateStringIterator(string) {
var s = TO_STRING_INLINE(string);
var s = TO_STRING(string);
var iterator = new StringIterator;
SET_PRIVATE(iterator, stringIteratorIteratedStringSymbol, s);
SET_PRIVATE(iterator, stringIteratorNextIndexSymbol, 0);
......
This diff is collapsed.
......@@ -58,7 +58,7 @@ function SymbolValueOf() {
function SymbolFor(key) {
key = TO_STRING_INLINE(key);
key = TO_STRING(key);
var registry = %SymbolRegistry();
if (IS_UNDEFINED(registry.for[key])) {
var symbol = %CreateSymbol(key);
......
......@@ -17,11 +17,6 @@
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.
......@@ -169,7 +164,7 @@ function URIDecodeOctets(octets, result, index) {
// ECMA-262, section 15.1.3
function Encode(uri, unescape) {
uri = TO_STRING_INLINE(uri);
uri = TO_STRING(uri);
var uriLength = uri.length;
var array = new InternalArray(uriLength);
var index = 0;
......@@ -200,7 +195,7 @@ function Encode(uri, unescape) {
// ECMA-262, section 15.1.3
function Decode(uri, reserved) {
uri = TO_STRING_INLINE(uri);
uri = TO_STRING(uri);
var uriLength = uri.length;
var one_byte = %NewString(uriLength, NEW_ONE_BYTE_STRING);
var index = 0;
......@@ -278,14 +273,12 @@ function Decode(uri, reserved) {
// Define exported functions.
// ECMA-262 - B.2.1.
function URIEscapeJS(str) {
var s = ToString(str);
function URIEscapeJS(s) {
return %URIEscape(s);
}
// ECMA-262 - B.2.2.
function URIUnescapeJS(str) {
var s = ToString(str);
function URIUnescapeJS(s) {
return %URIUnescape(s);
}
......@@ -309,15 +302,13 @@ function URIDecode(uri) {
return false;
};
var string = ToString(uri);
return Decode(string, reservedPredicate);
return Decode(uri, reservedPredicate);
}
// ECMA-262 - 15.1.3.2.
function URIDecodeComponent(component) {
var reservedPredicate = function(cc) { return false; };
var string = ToString(component);
return Decode(string, reservedPredicate);
return Decode(component, reservedPredicate);
}
// ECMA-262 - 15.1.3.3.
......@@ -343,8 +334,7 @@ function URIEncode(uri) {
return false;
};
var string = ToString(uri);
return Encode(string, unescapePredicate);
return Encode(uri, unescapePredicate);
}
// ECMA-262 - 15.1.3.4
......@@ -364,8 +354,7 @@ function URIEncodeComponent(component) {
return false;
};
var string = ToString(component);
return Encode(string, unescapePredicate);
return Encode(component, unescapePredicate);
}
// -------------------------------------------------------------------
......
......@@ -24,13 +24,11 @@ var ProxyDerivedKeysTrap;
var StringIndexOf;
var ToBoolean = utils.ImportNow("ToBoolean");
var ToNumber = utils.ImportNow("ToNumber");
var ToString;
var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol");
utils.Import(function(from) {
MathAbs = from.MathAbs;
StringIndexOf = from.StringIndexOf;
ToString = from.ToString;
});
utils.ImportFromExperimental(function(from) {
......@@ -72,11 +70,11 @@ function GlobalParseInt(string, radix) {
// Truncate number.
return string | 0;
}
string = TO_STRING_INLINE(string);
string = TO_STRING(string);
radix = radix | 0;
} else {
// The spec says ToString should be evaluated before ToInt32.
string = TO_STRING_INLINE(string);
string = TO_STRING(string);
radix = TO_INT32(radix);
if (!(radix == 0 || (2 <= radix && radix <= 36))) {
return NAN;
......@@ -93,7 +91,7 @@ function GlobalParseInt(string, radix) {
// ECMA-262 - 15.1.2.3
function GlobalParseFloat(string) {
string = TO_STRING_INLINE(string);
string = TO_STRING(string);
if (%_HasCachedArrayIndex(string)) return %_GetCachedArrayIndex(string);
return %StringParseFloat(string);
}
......@@ -806,7 +804,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 (TO_STRING(index) == p && index != 4294967295) {
var length = obj.length;
if (index >= length && %IsObserved(obj)) {
emit_splice = true;
......@@ -974,7 +972,7 @@ function ObjectGetOwnPropertyKeys(obj, filter) {
}
} else {
if (filter & PROPERTY_ATTRIBUTES_STRING) continue;
name = ToString(name);
name = TO_STRING(name);
}
if (seenKeys[name]) continue;
seenKeys[name] = true;
......@@ -1538,7 +1536,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 TO_STRING(x);
var p = TO_INTEGER(precision);
if (NUMBER_IS_NAN(x)) return "NaN";
......@@ -1758,9 +1756,9 @@ function NewFunctionString(args, function_token) {
var n = args.length;
var p = '';
if (n > 1) {
p = ToString(args[0]);
p = TO_STRING(args[0]);
for (var i = 1; i < n - 1; i++) {
p += ',' + ToString(args[i]);
p += ',' + TO_STRING(args[i]);
}
// If the formal parameters string include ) - an illegal
// character - it may make the combined function expression
......@@ -1773,7 +1771,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) ? TO_STRING(args[n - 1]) : '';
return '(' + function_token + '(' + p + ') {\n' + body + '\n})';
}
......
......@@ -143,14 +143,11 @@ TEST(RuntimeCallCPP2) {
TEST(RuntimeCallJS) {
FLAG_allow_natives_syntax = true;
FunctionTester T("(function(a) { return %to_string_fun(a); })");
T.CheckCall(T.Val("23"), T.Val(23), T.undefined());
T.CheckCall(T.Val("4.2"), T.Val(4.2), T.undefined());
T.CheckCall(T.Val("str"), T.Val("str"), T.undefined());
T.CheckCall(T.Val("true"), T.true_value(), T.undefined());
T.CheckCall(T.Val("false"), T.false_value(), T.undefined());
T.CheckCall(T.Val("undefined"), T.undefined(), T.undefined());
FunctionTester T("(function(a) { return %to_number_fun(a); })");
T.CheckCall(T.Val(23), T.Val(23), T.undefined());
T.CheckCall(T.Val(4.2), T.Val(4.2), T.undefined());
T.CheckCall(T.Val(1), T.true_value(), T.undefined());
}
......
......@@ -29,4 +29,4 @@
// Test call of JS runtime functions.
assertEquals("1", %to_string_fun(1));
assertEquals(1, %to_number_fun("1"));
......@@ -76,7 +76,8 @@ test(function() {
// kCannotConvertToPrimitive
test(function() {
[].join(Object(Symbol(1)));
var o = { toString: function() { return this } };
[].join(o);
}, "Cannot convert object to primitive value", TypeError);
// kCircularStructure
......
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