util: show External values explicitly in inspect

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

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Anna Henningsen 2017-03-31 22:35:54 +02:00
parent 91383e47fd
commit 3cc3e099be
No known key found for this signature in database
GPG Key ID: D8B9F5AEAE84E4CF
3 changed files with 7 additions and 0 deletions

View File

@ -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 File

@ -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) \

View File

@ -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;