Commit 6b660f28 authored by arv@chromium.org's avatar arv@chromium.org

ES6: String(symbol) should work like symbol.toString

Using String as a function and passing a symbol should return the
same  value as if Symbol.prototype.toString was called.

http://people.mozilla.org/~jorendorff/es6-draft.html#sec-string-constructor-string-value

BUG=v8:3554
LOG=Y
R=rossberg@chromium.org, rossberg

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23923 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent c44a69d9
...@@ -9,11 +9,12 @@ ...@@ -9,11 +9,12 @@
// ------------------------------------------------------------------- // -------------------------------------------------------------------
function StringConstructor(x) { function StringConstructor(x) {
var value = %_ArgumentsLength() == 0 ? '' : TO_STRING_INLINE(x); if (%_ArgumentsLength() == 0) x = '';
if (%_IsConstructCall()) { if (%_IsConstructCall()) {
%_SetValueOf(this, value); %_SetValueOf(this, TO_STRING_INLINE(x));
} else { } else {
return value; return IS_SYMBOL(x) ?
%_CallFunction(x, SymbolToString) : TO_STRING_INLINE(x);
} }
} }
......
...@@ -112,7 +112,8 @@ TestValueOf() ...@@ -112,7 +112,8 @@ TestValueOf()
function TestToString() { function TestToString() {
for (var i in symbols) { for (var i in symbols) {
assertThrows(function() { String(symbols[i]) }, TypeError) assertThrows(function() { new String(symbols[i]) }, TypeError)
assertEquals(symbols[i].toString(), String(symbols[i]))
assertThrows(function() { symbols[i] + "" }, TypeError) assertThrows(function() { symbols[i] + "" }, TypeError)
assertThrows(function() { String(Object(symbols[i])) }, TypeError) assertThrows(function() { String(Object(symbols[i])) }, TypeError)
assertTrue(isValidSymbolString(symbols[i].toString())) assertTrue(isValidSymbolString(symbols[i].toString()))
......
...@@ -83,7 +83,8 @@ TestConstructor() ...@@ -83,7 +83,8 @@ TestConstructor()
function TestToString() { function TestToString() {
for (var i in symbols) { for (var i in symbols) {
assertThrows(function() { String(symbols[i]) }, TypeError) assertThrows(function() {new String(symbols[i]) }, TypeError)
assertEquals(symbols[i].toString(), String(symbols[i]))
assertThrows(function() { symbols[i] + "" }, TypeError) assertThrows(function() { symbols[i] + "" }, TypeError)
assertTrue(isValidSymbolString(symbols[i].toString())) assertTrue(isValidSymbolString(symbols[i].toString()))
assertTrue(isValidSymbolString(Object(symbols[i]).toString())) assertTrue(isValidSymbolString(Object(symbols[i]).toString()))
......
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