Browse Source

util: inspect boxed symbols like other primitives

Inspect boxed symbol objects in the same way other boxed primitives
are inspected.

Fixes: https://github.com/nodejs/node/issues/7639
PR-URL: https://github.com/nodejs/node/pull/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>
v4.x
Anna Henningsen 9 years ago
committed by Myles Borins
parent
commit
f7796f23e3
  1. 4
      lib/util.js
  2. 1
      test/parallel/test-util-inspect.js

4
lib/util.js

@ -314,6 +314,10 @@ function formatValue(ctx, value, recurseTimes) {
formatted = formatPrimitiveNoColor(ctx, raw); formatted = formatPrimitiveNoColor(ctx, raw);
return ctx.stylize('[String: ' + formatted + ']', 'string'); return ctx.stylize('[String: ' + formatted + ']', 'string');
} }
if (typeof raw === 'symbol') {
formatted = formatPrimitiveNoColor(ctx, raw);
return ctx.stylize('[Symbol: ' + formatted + ']', 'symbol');
}
if (typeof raw === 'number') { if (typeof raw === 'number') {
formatted = formatPrimitiveNoColor(ctx, raw); formatted = formatPrimitiveNoColor(ctx, raw);
return ctx.stylize('[Number: ' + formatted + ']', 'number'); return ctx.stylize('[Number: ' + formatted + ']', 'number');

1
test/parallel/test-util-inspect.js

@ -333,6 +333,7 @@ test_lines({
// test boxed primitives output the correct values // test boxed primitives output the correct values
assert.equal(util.inspect(new String('test')), '[String: \'test\']'); 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(false)), '[Boolean: false]');
assert.equal(util.inspect(new Boolean(true)), '[Boolean: true]'); assert.equal(util.inspect(new Boolean(true)), '[Boolean: true]');
assert.equal(util.inspect(new Number(0)), '[Number: 0]'); assert.equal(util.inspect(new Number(0)), '[Number: 0]');

Loading…
Cancel
Save