Skip to content
/ node Public
forked from nodejs/node

Commit

Permalink
util: fix inspecting document.all
Browse files Browse the repository at this point in the history
  • Loading branch information
devsnek committed Feb 26, 2020
1 parent 9a1719b commit 96caf97
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ const builtInObjects = new Set(
ObjectGetOwnPropertyNames(global).filter((e) => /^[A-Z][a-zA-Z0-9]+$/.test(e))
);

// https://tc39.es/ecma262/#sec-IsHTMLDDA-internal-slot
const isUndetectableObject = (v) => typeof v === 'undefined' && v !== undefined;

// These options must stay in sync with `getUserOptions`. So if any option will
// be added or removed, `getUserOptions` must also be updated accordingly.
const inspectDefaultOptions = ObjectSeal({
Expand Down Expand Up @@ -680,7 +683,9 @@ function findTypedConstructor(value) {
// value afterwards again.
function formatValue(ctx, value, recurseTimes, typedArray) {
// Primitive types cannot have properties.
if (typeof value !== 'object' && typeof value !== 'function') {
if (typeof value !== 'object' &&
typeof value !== 'function' &&
!isUndetectableObject(value)) {
return formatPrimitive(ctx.stylize, value, ctx);
}
if (value === null) {
Expand Down
9 changes: 9 additions & 0 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const { internalBinding } = require('internal/test/binding');
const JSStream = internalBinding('js_stream').JSStream;
const util = require('util');
const vm = require('vm');
const v8 = require('v8');
const { previewEntries } = internalBinding('util');
const { inspect } = util;
const { MessageChannel } = require('worker_threads');
Expand Down Expand Up @@ -2748,3 +2749,11 @@ assert.strictEqual(
assert.deepStrictEqual(colors.gray, originalValue);
assert.strictEqual(colors.grey, colors.gray);
}

// https://github.com/nodejs/node/issues/31889
{
v8.setFlagsFromString('--allow-natives-syntax');
const undetectable = vm.runInThisContext('%GetUndetectable()');
v8.setFlagsFromString('--no-allow-natives-syntax');
assert.strictEqual(inspect(undetectable), '{}');
}

0 comments on commit 96caf97

Please sign in to comment.