diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js index 3d5e0061daa8d1..299e26247ca25e 100644 --- a/lib/internal/bootstrap/pre_execution.js +++ b/lib/internal/bootstrap/pre_execution.js @@ -3,6 +3,7 @@ const { Map, ObjectDefineProperty, + ObjectGetOwnPropertyNames, SafeWeakMap, } = primordials; @@ -178,6 +179,13 @@ function setupDebugEnv() { if (getOptionValue('--expose-internals')) { require('internal/bootstrap/loaders').NativeModule.exposeInternals(); } + + const { builtInObjects } = require('internal/util/inspect'); + // The content of this list depends on e.g. V8 flags, as well as + // what gets added by Node.js to the global object. + for (const key of ObjectGetOwnPropertyNames(globalThis)) { + builtInObjects.add(key); + } } // This has to be called after initializeReport() is called diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index fe21854e16aa7f..ed976dc7aea1d9 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -130,9 +130,58 @@ const typedArraySizeGetter = uncurryThis( let hexSlice; -const builtInObjects = new Set( - ObjectGetOwnPropertyNames(global).filter((e) => /^[A-Z][a-zA-Z0-9]+$/.test(e)) -); +// Make this list explicit instead of filtering over globalThis so that +// this list is deterministic during the bootstrap regardless of: +// a) Whether this file is required when the context is going to be +// serialized, or what the V8 flags are. V8 does not add +// SharedArrayBuffer, Atomics, WebAssembly, and other flaggable +// globals e.g. harmony ones to a context that will be serialized. +// b) Whether this file is required before or after bootstrap +// (Node.js adds things like Buffer, URL, etc.) +const builtInObjects = new Set([ + 'Object', + 'Function', + 'Array', + 'Number', + 'Infinity', + 'NaN', + 'Boolean', + 'String', + 'Symbol', + 'Date', + 'Promise', + 'RegExp', + 'Error', + 'EvalError', + 'RangeError', + 'ReferenceError', + 'SyntaxError', + 'TypeError', + 'URIError', + 'JSON', + 'Math', + 'Intl', + 'ArrayBuffer', + 'Uint8Array', + 'Int8Array', + 'Uint16Array', + 'Int16Array', + 'Uint32Array', + 'Int32Array', + 'Float32Array', + 'Float64Array', + 'Uint8ClampedArray', + 'BigUint64Array', + 'BigInt64Array', + 'DataView', + 'Map', + 'BigInt', + 'Set', + 'WeakMap', + 'WeakSet', + 'Proxy', + 'Reflect' +]); // https://tc39.es/ecma262/#sec-IsHTMLDDA-internal-slot const isUndetectableObject = (v) => typeof v === 'undefined' && v !== undefined; @@ -2033,5 +2082,6 @@ module.exports = { formatWithOptions, getStringWidth, inspectDefaultOptions, - stripVTControlCharacters + stripVTControlCharacters, + builtInObjects, };