From d6e8d03afcd3b6e64e4e46d49c3d5c5d0982e3f6 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 44fa0f32d76ff3..4d74f4d4df3668 100644 --- a/lib/internal/console/constructor.js +++ b/lib/internal/console/constructor.js @@ -689,8 +689,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;