Permalink
Browse files

util: show External values explicitly in inspect

Display `v8::External` values as `[External]` rather than `{}`
which makes them look like objects.

PR-URL: #12151
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
  • Loading branch information...
addaleax committed Mar 31, 2017
1 parent 91383e4 commit 3cc3e099be79274a188b2ce32f9cabddfc58ea8d
Showing with 7 additions and 0 deletions.
  1. +3 −0 lib/util.js
  2. +1 −0 src/node_util.cc
  3. +3 −0 test/parallel/test-util-inspect.js
View
@@ -466,6 +466,9 @@ function formatValue(ctx, value, recurseTimes) {
return `${constructor.name}` +
` { byteLength: ${formatNumber(ctx, value.byteLength)} }`;
}
if (binding.isExternal(value)) {
return ctx.stylize('[External]', 'special');
}
}
var base = '';
View
@@ -22,6 +22,7 @@ using v8::Value;
V(isArrayBuffer, IsArrayBuffer) \
V(isDataView, IsDataView) \
V(isDate, IsDate) \
V(isExternal, IsExternal) \
V(isMap, IsMap) \
V(isMapIterator, IsMapIterator) \
V(isPromise, IsPromise) \
@@ -82,6 +82,9 @@ assert.strictEqual(util.inspect(Object.assign(new String('hello'),
{ [Symbol('foo')]: 123 }), { showHidden: true }),
'{ [String: \'hello\'] [length]: 5, [Symbol(foo)]: 123 }');
assert.strictEqual(util.inspect(process.stdin._handle._externalStream),
'[External]');
{
const regexp = /regexp/;
regexp.aprop = 42;

0 comments on commit 3cc3e09

Please sign in to comment.