Skip to content

Commit f7796f2

Browse files
addaleaxMylesBorins
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 b630be2 commit f7796f2

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
@@ -314,6 +314,10 @@ function formatValue(ctx, value, recurseTimes) {
314314
formatted = formatPrimitiveNoColor(ctx, raw);
315315
return ctx.stylize('[String: ' + formatted + ']', 'string');
316316
}
317+
if (typeof raw === 'symbol') {
318+
formatted = formatPrimitiveNoColor(ctx, raw);
319+
return ctx.stylize('[Symbol: ' + formatted + ']', 'symbol');
320+
}
317321
if (typeof raw === 'number') {
318322
formatted = formatPrimitiveNoColor(ctx, raw);
319323
return ctx.stylize('[Number: ' + formatted + ']', 'number');

test/parallel/test-util-inspect.js

+1
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ test_lines({
333333

334334
// test boxed primitives output the correct values
335335
assert.equal(util.inspect(new String('test')), '[String: \'test\']');
336+
assert.equal(util.inspect(Object(Symbol('test'))), '[Symbol: Symbol(test)]');
336337
assert.equal(util.inspect(new Boolean(false)), '[Boolean: false]');
337338
assert.equal(util.inspect(new Boolean(true)), '[Boolean: true]');
338339
assert.equal(util.inspect(new Number(0)), '[Number: 0]');

0 commit comments

Comments
 (0)