Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlegendecas <legendecas@gmail.com>2022-05-18 18:30:49 +0300
committerBryan English <bryan@bryanenglish.com>2022-05-30 19:33:54 +0300
commit41b69e3cf469ea683592e20278f0b04c413ff34f (patch)
treee59bf7e91c06e2755128b7bca6a6e3d359978c55
parent9539cfa35817ea3ad61eccd2ed0572cc5c449d03 (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>
-rw-r--r--lib/inspector.js7
-rw-r--r--lib/internal/bootstrap/browser.js10
-rw-r--r--lib/internal/util/inspector.js12
-rw-r--r--src/inspector_js_api.cc12
4 files changed, 20 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;
- }
};
diff --git a/src/inspector_js_api.cc b/src/inspector_js_api.cc
index 4ebb8acd689..298066dfc75 100644
--- a/src/inspector_js_api.cc
+++ b/src/inspector_js_api.cc
@@ -343,6 +343,18 @@ void Initialize(Local<Object> target, Local<Value> unused,
env->SetMethod(target, "registerAsyncHook", RegisterAsyncHookWrapper);
env->SetMethodNoSideEffect(target, "isEnabled", IsEnabled);
+ Local<String> console_string =
+ FIXED_ONE_BYTE_STRING(env->isolate(), "console");
+
+ // Grab the console from the binding object and expose those to our binding
+ // layer.
+ Local<Object> binding = context->GetExtrasBindingObject();
+ target
+ ->Set(context,
+ console_string,
+ binding->Get(context, console_string).ToLocalChecked())
+ .Check();
+
JSBindingsConnection<LocalConnection>::Bind(env, target);
JSBindingsConnection<MainThreadConnection>::Bind(env, target);
}