diff options
author | legendecas <legendecas@gmail.com> | 2022-05-18 18:30:49 +0300 |
---|---|---|
committer | Bryan English <bryan@bryanenglish.com> | 2022-05-30 19:33:54 +0300 |
commit | 41b69e3cf469ea683592e20278f0b04c413ff34f (patch) | |
tree | e59bf7e91c06e2755128b7bca6a6e3d359978c55 /lib | |
parent | 9539cfa35817ea3ad61eccd2ed0572cc5c449d03 (diff) |
src,lib: migrate to console on context's extra binding
Since `globalThis.console` is not an ECMAScript defined
builtin, V8's globally installed `console` implementation
is been moved to the context's extra binding object.
We need to migrate to that one before the globally
installed console object is removed in V8.
PR-URL: https://github.com/nodejs/node/pull/43142
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/inspector.js | 7 | ||||
-rw-r--r-- | lib/internal/bootstrap/browser.js | 10 | ||||
-rw-r--r-- | lib/internal/util/inspector.js | 12 |
3 files changed, 8 insertions, 21 deletions
diff --git a/lib/inspector.js b/lib/inspector.js index 58d8dbe45c7..5ffb2d9d665 100644 --- a/lib/inspector.js +++ b/lib/inspector.js @@ -37,7 +37,8 @@ const { open, url, isEnabled, - waitForDebugger + waitForDebugger, + console, } = internalBinding('inspector'); const connectionSymbol = Symbol('connectionProperty'); @@ -188,8 +189,6 @@ module.exports = { close: process._debugEnd, url, waitForDebugger: inspectorWaitForDebugger, - // This is dynamically added during bootstrap, - // where the console from the VM is still available - console: require('internal/util/inspector').consoleFromVM, + console, Session }; diff --git a/lib/internal/bootstrap/browser.js b/lib/internal/bootstrap/browser.js index 49d69b93968..5704dedecb2 100644 --- a/lib/internal/bootstrap/browser.js +++ b/lib/internal/bootstrap/browser.js @@ -12,11 +12,9 @@ const { } = require('internal/util'); const config = internalBinding('config'); -// Override global console from the one provided by the VM -// to the one implemented by Node.js // https://console.spec.whatwg.org/#console-namespace exposeNamespace(globalThis, 'console', - createGlobalConsole(globalThis.console)); + createGlobalConsole()); const { URL, URLSearchParams } = require('internal/url'); // https://url.spec.whatwg.org/#url @@ -71,16 +69,14 @@ defineOperation(globalThis, 'setTimeout', timers.setTimeout); defineReplacableAttribute(globalThis, 'performance', require('perf_hooks').performance); -function createGlobalConsole(consoleFromVM) { +function createGlobalConsole() { const consoleFromNode = require('internal/console/global'); if (config.hasInspector) { const inspector = require('internal/util/inspector'); - // This will be exposed by `require('inspector').console` later. - inspector.consoleFromVM = consoleFromVM; // TODO(joyeecheung): postpone this until the first time inspector // is activated. - inspector.wrapConsole(consoleFromNode, consoleFromVM); + inspector.wrapConsole(consoleFromNode); const { setConsoleExtensionInstaller } = internalBinding('inspector'); // Setup inspector command line API. setConsoleExtensionInstaller(inspector.installConsoleExtensions); diff --git a/lib/internal/util/inspector.js b/lib/internal/util/inspector.js index a94289b17d0..5bc4fe5351a 100644 --- a/lib/internal/util/inspector.js +++ b/lib/internal/util/inspector.js @@ -38,8 +38,8 @@ function installConsoleExtensions(commandLineApi) { } // Wrap a console implemented by Node.js with features from the VM inspector -function wrapConsole(consoleFromNode, consoleFromVM) { - const { consoleCall } = internalBinding('inspector'); +function wrapConsole(consoleFromNode) { + const { consoleCall, console: consoleFromVM } = internalBinding('inspector'); for (const key of ObjectKeys(consoleFromVM)) { // If global console has the same method as inspector console, // then wrap these two methods into one. Native wrapper will preserve @@ -61,16 +61,8 @@ function wrapConsole(consoleFromNode, consoleFromVM) { } } -// Stores the console from VM, should be set during bootstrap. -let consoleFromVM; module.exports = { installConsoleExtensions, sendInspectorCommand, wrapConsole, - get consoleFromVM() { - return consoleFromVM; - }, - set consoleFromVM(val) { - consoleFromVM = val; - } }; |