Revision: 22426
Author: [email protected]
Date: Wed Jul 16 09:26:11 2014 UTC
Log: Make ToPrimitive throw on symbol wrappers
[email protected]
BUG=v8:3442
LOG=Y
Review URL: https://codereview.chromium.org/389263003
http://code.google.com/p/v8/source/detail?r=22426
Modified:
/branches/bleeding_edge/src/runtime.js
/branches/bleeding_edge/test/mjsunit/es6/symbols.js
=======================================
--- /branches/bleeding_edge/src/runtime.js Tue Apr 29 06:42:26 2014 UTC
+++ /branches/bleeding_edge/src/runtime.js Wed Jul 16 09:26:11 2014 UTC
@@ -607,35 +607,37 @@
// ECMA-262, section 8.6.2.6, page 28.
function DefaultNumber(x) {
- var valueOf = x.valueOf;
- if (IS_SPEC_FUNCTION(valueOf)) {
- var v = %_CallFunction(x, valueOf);
- if (%IsPrimitive(v)) return v;
- }
+ if (!IS_SYMBOL_WRAPPER(x)) {
+ var valueOf = x.valueOf;
+ if (IS_SPEC_FUNCTION(valueOf)) {
+ var v = %_CallFunction(x, valueOf);
+ if (%IsPrimitive(v)) return v;
+ }
- var toString = x.toString;
- if (IS_SPEC_FUNCTION(toString)) {
- var s = %_CallFunction(x, toString);
- if (%IsPrimitive(s)) return s;
+ var toString = x.toString;
+ if (IS_SPEC_FUNCTION(toString)) {
+ var s = %_CallFunction(x, toString);
+ if (%IsPrimitive(s)) return s;
+ }
}
-
throw %MakeTypeError('cannot_convert_to_primitive', []);
}
// ECMA-262, section 8.6.2.6, page 28.
function DefaultString(x) {
- var toString = x.toString;
- if (IS_SPEC_FUNCTION(toString)) {
- var s = %_CallFunction(x, toString);
- if (%IsPrimitive(s)) return s;
- }
+ if (!IS_SYMBOL_WRAPPER(x)) {
+ var toString = x.toString;
+ if (IS_SPEC_FUNCTION(toString)) {
+ var s = %_CallFunction(x, toString);
+ if (%IsPrimitive(s)) return s;
+ }
- var valueOf = x.valueOf;
- if (IS_SPEC_FUNCTION(valueOf)) {
- var v = %_CallFunction(x, valueOf);
- if (%IsPrimitive(v)) return v;
+ var valueOf = x.valueOf;
+ if (IS_SPEC_FUNCTION(valueOf)) {
+ var v = %_CallFunction(x, valueOf);
+ if (%IsPrimitive(v)) return v;
+ }
}
-
throw %MakeTypeError('cannot_convert_to_primitive', []);
}
=======================================
--- /branches/bleeding_edge/test/mjsunit/es6/symbols.js Mon Jul 14 14:00:33
2014 UTC
+++ /branches/bleeding_edge/test/mjsunit/es6/symbols.js Wed Jul 16 09:26:11
2014 UTC
@@ -102,7 +102,9 @@
function TestValueOf() {
for (var i in symbols) {
+ assertTrue(symbols[i] === Object(symbols[i]).valueOf())
assertTrue(symbols[i] === symbols[i].valueOf())
+ assertTrue(Symbol.prototype.valueOf.call(Object(symbols[i])) ===
symbols[i])
assertTrue(Symbol.prototype.valueOf.call(symbols[i]) === symbols[i])
}
}
@@ -113,7 +115,7 @@
for (var i in symbols) {
assertThrows(function() { String(symbols[i]) }, TypeError)
assertThrows(function() { symbols[i] + "" }, TypeError)
- assertTrue(isValidSymbolString(String(Object(symbols[i]))))
+ assertThrows(function() { String(Object(symbols[i])) }, TypeError)
assertTrue(isValidSymbolString(symbols[i].toString()))
assertTrue(isValidSymbolString(Object(symbols[i]).toString()))
assertTrue(
@@ -127,6 +129,8 @@
function TestToBoolean() {
for (var i in symbols) {
+ assertTrue(Boolean(Object(symbols[i])))
+ assertFalse(!Object(symbols[i]))
assertTrue(Boolean(symbols[i]).valueOf())
assertFalse(!symbols[i])
assertTrue(!!symbols[i])
@@ -144,6 +148,8 @@
function TestToNumber() {
for (var i in symbols) {
+ assertThrows(function() { Number(Object(symbols[i])) }, TypeError)
+ assertThrows(function() { +Object(symbols[i]) }, TypeError)
assertSame(NaN, Number(symbols[i]).valueOf())
assertSame(NaN, symbols[i] + 0)
}
--
--
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.