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
This commit is contained in:
parent
c44a69d985
commit
6b660f2812
@ -9,11 +9,12 @@
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
function StringConstructor(x) {
|
||||
var value = %_ArgumentsLength() == 0 ? '' : TO_STRING_INLINE(x);
|
||||
if (%_ArgumentsLength() == 0) x = '';
|
||||
if (%_IsConstructCall()) {
|
||||
%_SetValueOf(this, value);
|
||||
%_SetValueOf(this, TO_STRING_INLINE(x));
|
||||
} else {
|
||||
return value;
|
||||
return IS_SYMBOL(x) ?
|
||||
%_CallFunction(x, SymbolToString) : TO_STRING_INLINE(x);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -112,7 +112,8 @@ TestValueOf()
|
||||
|
||||
function TestToString() {
|
||||
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() { String(Object(symbols[i])) }, TypeError)
|
||||
assertTrue(isValidSymbolString(symbols[i].toString()))
|
||||
|
@ -83,7 +83,8 @@ TestConstructor()
|
||||
|
||||
function TestToString() {
|
||||
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)
|
||||
assertTrue(isValidSymbolString(symbols[i].toString()))
|
||||
assertTrue(isValidSymbolString(Object(symbols[i]).toString()))
|
||||
|
Loading…
Reference in New Issue
Block a user