From 7776e198abd6cf2196a009e355bd936f4e04c648 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Fri, 19 Jan 2024 22:55:48 +0800 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. --- 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;