diff --git a/src/env.cc b/src/env.cc index 6d69339b585e30..023e69665d94ed 100644 --- a/src/env.cc +++ b/src/env.cc @@ -341,6 +341,13 @@ void Environment::Start(const std::vector& 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 obj = Object::New(isolate()); + CHECK(obj->SetPrototype(context(), Null(isolate())).FromJust()); + set_inspector_console_api_object(obj); +#endif // HAVE_INSPECTOR } void Environment::RegisterHandleCleanups() { diff --git a/src/inspector_agent.cc b/src/inspector_agent.cc index 2ef964276177be..8710b8569072a1 100644 --- a/src/inspector_agent.cc +++ b/src/inspector_agent.cc @@ -506,6 +506,7 @@ class NodeInspectorClient : public V8InspectorClient { void installAdditionalCommandLineAPI(Local context, Local target) override { Local console_api = env_->inspector_console_api_object(); + CHECK(!console_api.IsEmpty()); Local properties = console_api->GetOwnPropertyNames(context).ToLocalChecked(); diff --git a/src/inspector_js_api.cc b/src/inspector_js_api.cc index 1cb51b51ec09d3..8f0332cc616341 100644 --- a/src/inspector_js_api.cc +++ b/src/inspector_js_api.cc @@ -277,12 +277,6 @@ void Url(const FunctionCallbackInfo& args) { void Initialize(Local target, Local unused, Local context, void* priv) { Environment* env = Environment::GetCurrent(context); - { - auto obj = Object::New(env->isolate()); - auto null = Null(env->isolate()); - CHECK(obj->SetPrototype(context, null).FromJust()); - env->set_inspector_console_api_object(obj); - } Agent* agent = env->inspector_agent(); env->SetMethod(target, "consoleCall", InspectorConsoleCall);