Skip to content

Commit eccd2a7

Browse files
devsnektargos
authored andcommittedApr 22, 2020
util: fix inspecting document.all
Fixes: #31889 PR-URL: #31938 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 6d71eb5 commit eccd2a7

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({
@@ -466,7 +469,7 @@ function getEmptyFormatArray() {
466469
function getConstructorName(obj, ctx, recurseTimes, protoProps) {
467470
let firstProto;
468471
const tmp = obj;
469-
while (obj) {
472+
while (obj || isUndetectableObject(obj)) {
470473
const descriptor = ObjectGetOwnPropertyDescriptor(obj, 'constructor');
471474
if (descriptor !== undefined &&
472475
typeof descriptor.value === 'function' &&
@@ -664,7 +667,9 @@ function findTypedConstructor(value) {
664667
// value afterwards again.
665668
function formatValue(ctx, value, recurseTimes, typedArray) {
666669
// Primitive types cannot have properties.
667-
if (typeof value !== 'object' && typeof value !== 'function') {
670+
if (typeof value !== 'object' &&
671+
typeof value !== 'function' &&
672+
!isUndetectableObject(value)) {
668673
return formatPrimitive(ctx.stylize, value, ctx);
669674
}
670675
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');
@@ -2727,3 +2728,11 @@ assert.strictEqual(
27272728
assert.deepStrictEqual(colors.gray, originalValue);
27282729
assert.strictEqual(colors.grey, colors.gray);
27292730
}
2731+
2732+
// https://github.com/nodejs/node/issues/31889
2733+
{
2734+
v8.setFlagsFromString('--allow-natives-syntax');
2735+
const undetectable = vm.runInThisContext('%GetUndetectable()');
2736+
v8.setFlagsFromString('--no-allow-natives-syntax');
2737+
assert.strictEqual(inspect(undetectable), '{}');
2738+
}

0 commit comments

Comments
 (0)
Please sign in to comment.