Skip to content

util: logging symbols should convert using String(symbol) #927

Description

@domenic
varsymbol=Symbol("My symbol");console.log(symbol);// fine, logs Symbol(My symbol)console.log("foo",symbol);// throws

Output:

$ 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    utilIssues and PRs related to the built-in util module.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions