mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -05:00
util: fix inspecting document.all
Fixes: https://github.com/nodejs/node/issues/31889 PR-URL: https://github.com/nodejs/node/pull/31938 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
1 parent
6d71eb5b5b
commit
eccd2a7740
2 files changed
+16
-2
No files matched your search
@@ -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({
|
||||
@@ -466,7 +469,7 @@ function getEmptyFormatArray() {
|
||||
function getConstructorName(obj, ctx, recurseTimes, protoProps) {
|
||||
let firstProto;
|
||||
const tmp = obj;
|
||||
while (obj) {
|
||||
while (obj || isUndetectableObject(obj)) {
|
||||
const descriptor = ObjectGetOwnPropertyDescriptor(obj, 'constructor');
|
||||
if (descriptor !== undefined &&
|
||||
typeof descriptor.value === 'function' &&
|
||||
@@ -664,7 +667,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) {
|
||||
|
||||
@@ -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');
|
||||
@@ -2727,3 +2728,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), '{}');
|
||||
}
|
||||
Reference in new issue
Block a user