Skip to content

Commit 3cc3e09

Browse files
committed
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>
1 parent 91383e4 commit 3cc3e09

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

lib/util.js

+3
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,9 @@ function formatValue(ctx, value, recurseTimes) {
466466
return `${constructor.name}` +
467467
` { byteLength: ${formatNumber(ctx, value.byteLength)} }`;
468468
}
469+
if (binding.isExternal(value)) {
470+
return ctx.stylize('[External]', 'special');
471+
}
469472
}
470473

471474
var base = '';

src/node_util.cc

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ using v8::Value;
2222
V(isArrayBuffer, IsArrayBuffer) \
2323
V(isDataView, IsDataView) \
2424
V(isDate, IsDate) \
25+
V(isExternal, IsExternal) \
2526
V(isMap, IsMap) \
2627
V(isMapIterator, IsMapIterator) \
2728
V(isPromise, IsPromise) \

test/parallel/test-util-inspect.js

+3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ assert.strictEqual(util.inspect(Object.assign(new String('hello'),
8282
{ [Symbol('foo')]: 123 }), { showHidden: true }),
8383
'{ [String: \'hello\'] [length]: 5, [Symbol(foo)]: 123 }');
8484

85+
assert.strictEqual(util.inspect(process.stdin._handle._externalStream),
86+
'[External]');
87+
8588
{
8689
const regexp = /regexp/;
8790
regexp.aprop = 42;

0 commit comments

Comments
 (0)