lib: create global console properties at snapshot build time

It is safe to create the console properties for the global
console at snapshot build time. Streams must still be created
lazily however because they need special synchronization for
the handles.

PR-URL: https://github.com/nodejs/node/pull/51700
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
This commit is contained in:
Joyee Cheung
2024-02-20 19:25:31 +01:00
committed by GitHub
parent 2eaee2820e
commit 7851af051a
2 changed files with 3 additions and 2 deletions

View File

@@ -694,8 +694,6 @@ Console.prototype.groupCollapsed = Console.prototype.group;
function initializeGlobalConsole(globalConsole) {
globalConsole[kBindStreamsLazy](process);
globalConsole[kBindProperties](true, 'auto');
const {
namespace: {
addSerializeCallback,

View File

@@ -21,6 +21,7 @@ const {
const {
Console,
kBindProperties,
} = require('internal/console/constructor');
const globalConsole = { __proto__: {} };
@@ -41,6 +42,8 @@ for (const prop of ReflectOwnKeys(Console.prototype)) {
ReflectDefineProperty(globalConsole, prop, desc);
}
globalConsole[kBindProperties](true, 'auto');
// This is a legacy feature - the Console constructor is exposed on
// the global console instance.
globalConsole.Console = Console;