From 64037b1f027ac977a0f227669d367cf2e1c71791 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Wed, 28 Aug 2024 21:13:34 +0200 Subject: refactor: don't virtualize the `console` global for node mode (#25263) Turns out we only virtualized it so one could have a `Console` property, and the other one not. We can just make this `console.Console` available everywhere. --- ext/node/global.rs | 4 +--- ext/node/polyfills/01_require.js | 4 +--- ext/node/polyfills/02_init.js | 1 - ext/node/polyfills/console.ts | 4 +++- 4 files changed, 5 insertions(+), 8 deletions(-) (limited to 'ext/node') diff --git a/ext/node/global.rs b/ext/node/global.rs index 0b4adfc7d..61bcc3343 100644 --- a/ext/node/global.rs +++ b/ext/node/global.rs @@ -52,7 +52,6 @@ const fn str_to_utf16(s: &str) -> [u16; N] { // - clearImmediate (node only) // - clearInterval (both, but different implementation) // - clearTimeout (both, but different implementation) -// - console (both, but different implementation) // - global (node only) // - performance (both, but different implementation) // - process (node only) @@ -63,13 +62,12 @@ const fn str_to_utf16(s: &str) -> [u16; N] { // UTF-16 encodings of the managed globals. THIS LIST MUST BE SORTED. #[rustfmt::skip] -const MANAGED_GLOBALS: [&[u16]; 14] = [ +const MANAGED_GLOBALS: [&[u16]; 13] = [ &str_to_utf16::<6>("Buffer"), &str_to_utf16::<17>("WorkerGlobalScope"), &str_to_utf16::<14>("clearImmediate"), &str_to_utf16::<13>("clearInterval"), &str_to_utf16::<12>("clearTimeout"), - &str_to_utf16::<7>("console"), &str_to_utf16::<6>("global"), &str_to_utf16::<11>("performance"), &str_to_utf16::<7>("process"), diff --git a/ext/node/polyfills/01_require.js b/ext/node/polyfills/01_require.js index c29073901..aec8c55b8 100644 --- a/ext/node/polyfills/01_require.js +++ b/ext/node/polyfills/01_require.js @@ -945,7 +945,7 @@ Module.prototype.require = function (id) { // The only observable difference is that in Deno `arguments.callee` is not // null. Module.wrapper = [ - "(function (exports, require, module, __filename, __dirname, Buffer, clearImmediate, clearInterval, clearTimeout, console, global, process, setImmediate, setInterval, setTimeout, performance) { (function (exports, require, module, __filename, __dirname) {", + "(function (exports, require, module, __filename, __dirname, Buffer, clearImmediate, clearInterval, clearTimeout, global, process, setImmediate, setInterval, setTimeout, performance) { (function (exports, require, module, __filename, __dirname) {", "\n}).call(this, exports, require, module, __filename, __dirname); })", ]; Module.wrap = function (script) { @@ -1029,7 +1029,6 @@ Module.prototype._compile = function (content, filename, format) { clearImmediate, clearInterval, clearTimeout, - console, global, process, setImmediate, @@ -1049,7 +1048,6 @@ Module.prototype._compile = function (content, filename, format) { clearImmediate, clearInterval, clearTimeout, - console, global, process, setImmediate, diff --git a/ext/node/polyfills/02_init.js b/ext/node/polyfills/02_init.js index 7a697abe4..870ff12f3 100644 --- a/ext/node/polyfills/02_init.js +++ b/ext/node/polyfills/02_init.js @@ -76,7 +76,6 @@ nodeGlobals.Buffer = nativeModuleExports["buffer"].Buffer; nodeGlobals.clearImmediate = nativeModuleExports["timers"].clearImmediate; nodeGlobals.clearInterval = nativeModuleExports["timers"].clearInterval; nodeGlobals.clearTimeout = nativeModuleExports["timers"].clearTimeout; -nodeGlobals.console = nativeModuleExports["console"]; nodeGlobals.global = globalThis; nodeGlobals.process = nativeModuleExports["process"]; nodeGlobals.setImmediate = nativeModuleExports["timers"].setImmediate; diff --git a/ext/node/polyfills/console.ts b/ext/node/polyfills/console.ts index c72cfb160..b1364481f 100644 --- a/ext/node/polyfills/console.ts +++ b/ext/node/polyfills/console.ts @@ -9,7 +9,9 @@ import { windowOrWorkerGlobalScope } from "ext:runtime/98_global_scope_shared.js // to native `console` object provided by V8. const console = windowOrWorkerGlobalScope.console.value; -export default Object.assign({}, console, { Console }); +Object.assign(console, { Console }); + +export default console; export { Console }; export const { -- cgit v1.2.3