Skip to content

Commit

Permalink
util: inspect boxed symbols like other primitives
Browse files Browse the repository at this point in the history
Inspect boxed symbol objects in the same way other boxed primitives
are inspected.

Fixes: #7639
PR-URL: #7641
Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
  • Loading branch information
addaleax authored and MylesBorins committed Oct 26, 2016
1 parent b630be2 commit f7796f2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ function formatValue(ctx, value, recurseTimes) {
formatted = formatPrimitiveNoColor(ctx, raw);
return ctx.stylize('[String: ' + formatted + ']', 'string');
}
if (typeof raw === 'symbol') {
formatted = formatPrimitiveNoColor(ctx, raw);
return ctx.stylize('[Symbol: ' + formatted + ']', 'symbol');
}
if (typeof raw === 'number') {
formatted = formatPrimitiveNoColor(ctx, raw);
return ctx.stylize('[Number: ' + formatted + ']', 'number');
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ test_lines({

// test boxed primitives output the correct values
assert.equal(util.inspect(new String('test')), '[String: \'test\']');
assert.equal(util.inspect(Object(Symbol('test'))), '[Symbol: Symbol(test)]');
assert.equal(util.inspect(new Boolean(false)), '[Boolean: false]');
assert.equal(util.inspect(new Boolean(true)), '[Boolean: true]');
assert.equal(util.inspect(new Number(0)), '[Number: 0]');
Expand Down

0 comments on commit f7796f2

Please sign in to comment.