Skip to content

Commit 0858e62

Browse files
addaleaxevanlucas
authored andcommitted
util: inspect boxed symbols like other primitives
Inspect boxed symbol objects in the same way other boxed primitives are inspected. Fixes: #7639 PR-URL: #7641 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
1 parent 939cf6d commit 0858e62

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

lib/util.js

+4
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,10 @@ function formatValue(ctx, value, recurseTimes) {
413413
formatted = formatPrimitiveNoColor(ctx, raw);
414414
return ctx.stylize('[String: ' + formatted + ']', 'string');
415415
}
416+
if (typeof raw === 'symbol') {
417+
formatted = formatPrimitiveNoColor(ctx, raw);
418+
return ctx.stylize('[Symbol: ' + formatted + ']', 'symbol');
419+
}
416420
if (typeof raw === 'number') {
417421
formatted = formatPrimitiveNoColor(ctx, raw);
418422
return ctx.stylize('[Number: ' + formatted + ']', 'number');

test/parallel/test-util-inspect.js

+1
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ test_lines({
474474

475475
// test boxed primitives output the correct values
476476
assert.equal(util.inspect(new String('test')), '[String: \'test\']');
477+
assert.equal(util.inspect(Object(Symbol('test'))), '[Symbol: Symbol(test)]');
477478
assert.equal(util.inspect(new Boolean(false)), '[Boolean: false]');
478479
assert.equal(util.inspect(new Boolean(true)), '[Boolean: true]');
479480
assert.equal(util.inspect(new Number(0)), '[Number: 0]');

0 commit comments

Comments
 (0)