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
// -------------------------------------------------------------------
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);
}
}
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()))
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()))