Skip to content

Commit

Permalink
util: show External values explicitly in inspect
Browse files Browse the repository at this point in the history
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 Apr 3, 2017
1 parent 91383e4 commit 3cc3e09
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand Down
1 change: 1 addition & 0 deletions src/node_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down
3 changes: 3 additions & 0 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3cc3e09

Please sign in to comment.