From 3cc3e099be79274a188b2ce32f9cabddfc58ea8d Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 31 Mar 2017 22:35:54 +0200 Subject: [PATCH] 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 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Ben Noordhuis --- lib/util.js | 3 +++ src/node_util.cc | 1 + test/parallel/test-util-inspect.js | 3 +++ 3 files changed, 7 insertions(+) diff --git a/lib/util.js b/lib/util.js index 8567f8dbaa0235..a0e8bb3c1dace4 100644 --- a/lib/util.js +++ b/lib/util.js @@ -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 = ''; diff --git a/src/node_util.cc b/src/node_util.cc index 8279a787d7d1ac..813995de796e44 100644 --- a/src/node_util.cc +++ b/src/node_util.cc @@ -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) \ diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index 32e36135efd260..ab4964f9e7b5a1 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -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;