From 7851af051ab72401ca5b2dcf24f8a0f72d24a9f2 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Tue, 20 Feb 2024 19:25:31 +0100 Subject: [PATCH] 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 Reviewed-By: Chengzhong Wu Reviewed-By: Moshe Atlow --- lib/internal/console/constructor.js | 2 -- lib/internal/console/global.js | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/internal/console/constructor.js b/lib/internal/console/constructor.js index 0a5849d524f782..454652e3632472 100644 --- a/lib/internal/console/constructor.js +++ b/lib/internal/console/constructor.js @@ -694,8 +694,6 @@ Console.prototype.groupCollapsed = Console.prototype.group; function initializeGlobalConsole(globalConsole) { globalConsole[kBindStreamsLazy](process); - globalConsole[kBindProperties](true, 'auto'); - const { namespace: { addSerializeCallback, diff --git a/lib/internal/console/global.js b/lib/internal/console/global.js index 33654d8dbc6740..908471ff44d74e 100644 --- a/lib/internal/console/global.js +++ b/lib/internal/console/global.js @@ -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;