Reviewers: rossberg,
Message:
In the spirit of the change I made to ToNumber.
This changes the message for the TypeError when converting a Symbol wrapper
to a
primitive. I'm not sure if that matters.
This isn't needed for SIMD.
https://codereview.chromium.org/1256323004/diff/20001/src/runtime.js
File src/runtime.js (left):
https://codereview.chromium.org/1256323004/diff/20001/src/runtime.js#oldcode769
src/runtime.js:769: if (IS_SYMBOL_WRAPPER(x)) throw
MakeTypeError(kSymbolToPrimitive);
Is this error part of the Spec? If so, we have to keep this line.
Description:
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
Please review this at https://codereview.chromium.org/1256323004/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+5, -12 lines):
M src/messages.h
M src/runtime.js
M test/mjsunit/messages.js
Index: src/messages.h
diff --git a/src/messages.h b/src/messages.h
index
fc98118b54f93cd85413aabf5538369b0d458baf..529c659e181d8f35cca3e05909d8e3a76fa9a3b4
100644
--- a/src/messages.h
+++ b/src/messages.h
@@ -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") \
Index: src/runtime.js
diff --git a/src/runtime.js b/src/runtime.js
index
dd776dbc8c354722c692c3580914398e5de26d30..e70666817321d2d60c7b7256ae9d20953663d8cc
100644
--- a/src/runtime.js
+++ b/src/runtime.js
@@ -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);
@@ -816,7 +815,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));
}
@@ -824,7 +823,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));
}
@@ -963,6 +962,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);
Index: test/mjsunit/messages.js
diff --git a/test/mjsunit/messages.js b/test/mjsunit/messages.js
index
2eda002d7c7f42c559d1a649a15e7c9d50b219d8..45443c75d15752fd99640dd7dc51a5cd775d3814
100644
--- a/test/mjsunit/messages.js
+++ b/test/mjsunit/messages.js
@@ -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();
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.