Skip to content

Commit 6d86651

Browse files
devsnekaddaleax
authored andcommitted
util: fix inspecting document.all
Fixes: #31889 PR-URL: #31938 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 928a490 commit 6d86651

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/internal/util/inspect.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ const builtInObjects = new Set(
134134
ObjectGetOwnPropertyNames(global).filter((e) => /^[A-Z][a-zA-Z0-9]+$/.test(e))
135135
);
136136

137+
// https://tc39.es/ecma262/#sec-IsHTMLDDA-internal-slot
138+
const isUndetectableObject = (v) => typeof v === 'undefined' && v !== undefined;
139+
137140
// These options must stay in sync with `getUserOptions`. So if any option will
138141
// be added or removed, `getUserOptions` must also be updated accordingly.
139142
const inspectDefaultOptions = ObjectSeal({
@@ -477,7 +480,7 @@ function getEmptyFormatArray() {
477480
function getConstructorName(obj, ctx, recurseTimes, protoProps) {
478481
let firstProto;
479482
const tmp = obj;
480-
while (obj) {
483+
while (obj || isUndetectableObject(obj)) {
481484
const descriptor = ObjectGetOwnPropertyDescriptor(obj, 'constructor');
482485
if (descriptor !== undefined &&
483486
typeof descriptor.value === 'function' &&
@@ -675,7 +678,9 @@ function findTypedConstructor(value) {
675678
// value afterwards again.
676679
function formatValue(ctx, value, recurseTimes, typedArray) {
677680
// Primitive types cannot have properties.
678-
if (typeof value !== 'object' && typeof value !== 'function') {
681+
if (typeof value !== 'object' &&
682+
typeof value !== 'function' &&
683+
!isUndetectableObject(value)) {
679684
return formatPrimitive(ctx.stylize, value, ctx);
680685
}
681686
if (value === null) {

test/parallel/test-util-inspect.js

+9
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const { internalBinding } = require('internal/test/binding');
2626
const JSStream = internalBinding('js_stream').JSStream;
2727
const util = require('util');
2828
const vm = require('vm');
29+
const v8 = require('v8');
2930
const { previewEntries } = internalBinding('util');
3031
const { inspect } = util;
3132
const { MessageChannel } = require('worker_threads');
@@ -2749,3 +2750,11 @@ assert.strictEqual(
27492750
assert.deepStrictEqual(colors.gray, originalValue);
27502751
assert.strictEqual(colors.grey, colors.gray);
27512752
}
2753+
2754+
// https://github.com/nodejs/node/issues/31889
2755+
{
2756+
v8.setFlagsFromString('--allow-natives-syntax');
2757+
const undetectable = vm.runInThisContext('%GetUndetectable()');
2758+
v8.setFlagsFromString('--no-allow-natives-syntax');
2759+
assert.strictEqual(inspect(undetectable), '{}');
2760+
}

0 commit comments

Comments
 (0)