You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
util: logging symbols should convert using String(symbol) #927
$ iojs test.js
Symbol(My symbol)
util.js:34
str += ' ' + x;
^
TypeError: Cannot convert a Symbol value to a string
at Console.exports.format (util.js:34:18)
at Console.log (console.js:36:34)
at Object.<anonymous> (c:\Users\Domenic\Dropbox\GitHub\whatwg\streams\reference-implementation\test.js:4:9)
at Module._compile (module.js:444:26)
at Object.Module._extensions..js (module.js:462:10)
at Module.load (module.js:339:32)
at Function.Module._load (module.js:294:12)
at Function.Module.runMain (module.js:485:10)
at startup (node.js:111:16)
at node.js:799:3
Note that the correct way to stringify a symbol is with the explicit conversion, String(symbol), instead of implicitly with the + sign.
I can get to this after work if nobody else does first.
Yeah, this is correct per spec and several TC39 meetings. It is dangerous to allow symbols to be implicitly converted to strings (and in some cases you just flat out can't do it, e.g. obj[prop] usually does an implicit string conversion). However explicit conversion is fine.
Activity
vkurchatkin commentedon Feb 23, 2015
Is it the correct behaviour though? I thought it was v8 bug
domenic commentedon Feb 23, 2015
Yeah, this is correct per spec and several TC39 meetings. It is dangerous to allow symbols to be implicitly converted to strings (and in some cases you just flat out can't do it, e.g.
obj[prop]usually does an implicit string conversion). However explicit conversion is fine.util: handle symbols properly in format()
cjihrig commentedon Feb 24, 2015
Closed by ed3b057
Symbols must be stringified explicitly
Symbols must be stringified explicitly
Symbols must be stringified explicitly
Symbols must be stringified explicitly