Commit bfde4582 authored by bbudge's avatar bbudge Committed by Commit bot

Optimize ToString and NonStringToString.

Moves some uncommon type checking from ToString and
NonStringToString into DefaultString. This should
speed up string operations.

LOG=N
BUG=none

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

Cr-Commit-Position: refs/heads/master@{#29913}
parent 053b8434
......@@ -240,8 +240,6 @@ class CallSite {
T(StrongSetProto, \
"On strong object %, redefining the internal prototype is deprecated") \
T(SymbolKeyFor, "% is not a symbol") \
T(SymbolToPrimitive, \
"Cannot convert a Symbol wrapper object to a primitive value") \
T(SymbolToNumber, "Cannot convert a Symbol value to a number") \
T(SymbolToString, "Cannot convert a Symbol value to a string") \
T(SimdToNumber, "Cannot convert a SIMD value to a number") \
......
......@@ -766,7 +766,6 @@ function ToPrimitive(x, hint) {
if (IS_STRING(x)) return x;
// Normal behavior.
if (!IS_SPEC_OBJECT(x)) return x;
if (IS_SYMBOL_WRAPPER(x)) throw MakeTypeError(kSymbolToPrimitive);
if (IS_FLOAT32X4(x)) return x;
if (hint == NO_HINT) hint = (IS_DATE(x)) ? STRING_HINT : NUMBER_HINT;
return (hint == NUMBER_HINT) ? DefaultNumber(x) : DefaultString(x);
......@@ -814,7 +813,7 @@ function ToString(x) {
if (IS_NUMBER(x)) return %_NumberToString(x);
if (IS_BOOLEAN(x)) return x ? 'true' : 'false';
if (IS_UNDEFINED(x)) return 'undefined';
if (IS_SYMBOL(x)) throw MakeTypeError(kSymbolToString);
// Types that can't be converted to string are caught in DefaultString.
return (IS_NULL(x)) ? 'null' : ToString(DefaultString(x));
}
......@@ -822,7 +821,7 @@ function NonStringToString(x) {
if (IS_NUMBER(x)) return %_NumberToString(x);
if (IS_BOOLEAN(x)) return x ? 'true' : 'false';
if (IS_UNDEFINED(x)) return 'undefined';
if (IS_SYMBOL(x)) throw MakeTypeError(kSymbolToString);
// Types that can't be converted to string are caught in DefaultString.
return (IS_NULL(x)) ? 'null' : ToString(DefaultString(x));
}
......@@ -960,6 +959,7 @@ function DefaultNumber(x) {
// ECMA-262, section 8.6.2.6, page 28.
function DefaultString(x) {
if (!IS_SYMBOL_WRAPPER(x)) {
if (IS_SYMBOL(x)) throw MakeTypeError(kSymbolToString);
var toString = x.toString;
if (IS_SPEC_FUNCTION(toString)) {
var s = %_CallFunction(x, toString);
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --stack-size=100 --harmony --harmony-reflect --harmony-arrays
// Flags: --harmony-regexps --harmony-simd --strong-mode
// Flags: --stack-size=100 --harmony --harmony-reflect --harmony-regexps
// Flags: --harmony-simd --strong-mode
function test(f, expected, type) {
try {
......@@ -308,11 +308,6 @@ test(function() {
"a" + 1;
}, "In strong mode, implicit conversions are deprecated", TypeError);
// kSymbolToPrimitive
test(function() {
1 + Object(Symbol());
}, "Cannot convert a Symbol wrapper object to a primitive value", TypeError);
// kSymbolToString
test(function() {
"" + Symbol();
......
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