diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2019-01-15 21:57:29 +0800 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2019-01-23 20:23:23 +0800 |
commit | d3806f9f3cded6bce9831f5d8ff88372ba7e5861 (patch) | |
tree | 0ee4ee76357220d88fd44c2bf3f782e34b5cd957 /src | |
parent | a93c825d7843e72d3e534939639f49ce8e26b16b (diff) | |
download | android-node-v8-d3806f9f3cded6bce9831f5d8ff88372ba7e5861.tar.gz android-node-v8-d3806f9f3cded6bce9831f5d8ff88372ba7e5861.tar.bz2 android-node-v8-d3806f9f3cded6bce9831f5d8ff88372ba7e5861.zip |
console: refactor inspector console extension installation
- Instead of creating the console extensions eagerly during bootstrap
and storing them on an object, wrap the code into a function to be
called during `installAdditionalCommandLineAPI` only when the
extensions are actually needed, which may not even happen if the
user do not use the console in an inspector session, and does not
need to happen during bootstrap unconditionally.
- Simplify the console methods wrapping and move the `consoleFromVM`
storage to `internal/util/inspector.js`
PR-URL: https://github.com/nodejs/node/pull/25450
Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'src')
-rw-r--r-- | src/env.cc | 7 | ||||
-rw-r--r-- | src/env.h | 2 | ||||
-rw-r--r-- | src/inspector_agent.cc | 16 | ||||
-rw-r--r-- | src/inspector_js_api.cc | 14 |
4 files changed, 12 insertions, 27 deletions
diff --git a/src/env.cc b/src/env.cc index f45386dce4..97cfc72a9d 100644 --- a/src/env.cc +++ b/src/env.cc @@ -352,13 +352,6 @@ void Environment::Start(const std::vector<std::string>& args, static uv_once_t init_once = UV_ONCE_INIT; uv_once(&init_once, InitThreadLocalOnce); uv_key_set(&thread_local_env, this); - -#if HAVE_INSPECTOR - // This needs to be set before we start the inspector - Local<Object> obj = Object::New(isolate()); - CHECK(obj->SetPrototype(context(), Null(isolate())).FromJust()); - set_inspector_console_api_object(obj); -#endif // HAVE_INSPECTOR } void Environment::RegisterHandleCleanups() { @@ -356,7 +356,7 @@ constexpr size_t kFsStatsBufferLength = kFsStatsFieldsNumber * 2; V(http2settings_constructor_template, v8::ObjectTemplate) \ V(http2stream_constructor_template, v8::ObjectTemplate) \ V(immediate_callback_function, v8::Function) \ - V(inspector_console_api_object, v8::Object) \ + V(inspector_console_extension_installer, v8::Function) \ V(libuv_stream_wrap_ctor_template, v8::FunctionTemplate) \ V(message_port, v8::Object) \ V(message_port_constructor_template, v8::FunctionTemplate) \ diff --git a/src/inspector_agent.cc b/src/inspector_agent.cc index a53c58337e..dcc256b7f7 100644 --- a/src/inspector_agent.cc +++ b/src/inspector_agent.cc @@ -32,7 +32,6 @@ namespace { using node::FatalError; -using v8::Array; using v8::Context; using v8::Function; using v8::HandleScope; @@ -493,16 +492,11 @@ class NodeInspectorClient : public V8InspectorClient { void installAdditionalCommandLineAPI(Local<Context> context, Local<Object> target) override { - Local<Object> console_api = env_->inspector_console_api_object(); - CHECK(!console_api.IsEmpty()); - - Local<Array> properties = - console_api->GetOwnPropertyNames(context).ToLocalChecked(); - for (uint32_t i = 0; i < properties->Length(); ++i) { - Local<Value> key = properties->Get(context, i).ToLocalChecked(); - target->Set(context, - key, - console_api->Get(context, key).ToLocalChecked()).FromJust(); + Local<Function> installer = env_->inspector_console_extension_installer(); + if (!installer.IsEmpty()) { + Local<Value> argv[] = {target}; + // If there is an exception, proceed in JS land + USE(installer->Call(context, target, arraysize(argv), argv)); } } diff --git a/src/inspector_js_api.cc b/src/inspector_js_api.cc index d94cf4173d..8802998e9a 100644 --- a/src/inspector_js_api.cc +++ b/src/inspector_js_api.cc @@ -122,16 +122,13 @@ static bool InspectorEnabled(Environment* env) { return agent->IsActive(); } -void AddCommandLineAPI(const FunctionCallbackInfo<Value>& info) { +void SetConsoleExtensionInstaller(const FunctionCallbackInfo<Value>& info) { auto env = Environment::GetCurrent(info); - Local<Context> context = env->context(); - // inspector.addCommandLineAPI takes 2 arguments: a string and a value. - CHECK_EQ(info.Length(), 2); - CHECK(info[0]->IsString()); + CHECK_EQ(info.Length(), 1); + CHECK(info[0]->IsFunction()); - Local<Object> console_api = env->inspector_console_api_object(); - console_api->Set(context, info[0], info[1]).FromJust(); + env->set_inspector_console_extension_installer(info[0].As<Function>()); } void CallAndPauseOnStart(const FunctionCallbackInfo<v8::Value>& args) { @@ -279,7 +276,8 @@ void Initialize(Local<Object> target, Local<Value> unused, Agent* agent = env->inspector_agent(); env->SetMethod(target, "consoleCall", InspectorConsoleCall); - env->SetMethod(target, "addCommandLineAPI", AddCommandLineAPI); + env->SetMethod( + target, "setConsoleExtensionInstaller", SetConsoleExtensionInstaller); if (agent->WillWaitForConnect()) env->SetMethod(target, "callAndPauseOnStart", CallAndPauseOnStart); env->SetMethod(target, "open", Open); |