Skip to content
Browse files

src: create env->inspector_console_api_object earlier

Previously we create env->inspector_console_api_object() when
`process.binding('inspector')` is called, which may be too late
if the inspector console is used before the first call to
`process.binding('inspector')` - that is possible when
using `--inspect-brk-node`. Setting a breakpoint and using the
inspector console before that would crash the process.

This patch moves the initialization of the console API object to
the point when Environment is initialized so that
`installAdditionalCommandLineAPI()` can be essentially a noop
if we use the inspector console before the inspector binding
is initialized instead of crashing on an empty object.

PR-URL: #24906
Reviewed-By: Anna Henningsen <>
Reviewed-By: Colin Ihrig <>
Reviewed-By: Franziska Hinkelmann <>
  • Loading branch information
joyeecheung authored and Trott committed Dec 13, 2018
1 parent 9a26546 commit a1b283c2cacccb2e6d6f3a2382d986cd4ead11b4
Showing with 8 additions and 6 deletions.
  1. +7 −0 src/
  2. +1 −0 src/
  3. +0 −6 src/
@@ -341,6 +341,13 @@ 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);

// This needs to be set before we start the inspector
Local<Object> obj = Object::New(isolate());
CHECK(obj->SetPrototype(context(), Null(isolate())).FromJust());

void Environment::RegisterHandleCleanups() {
@@ -506,6 +506,7 @@ class NodeInspectorClient : public V8InspectorClient {
void installAdditionalCommandLineAPI(Local<Context> context,
Local<Object> target) override {
Local<Object> console_api = env_->inspector_console_api_object();

Local<Array> properties =
@@ -277,12 +277,6 @@ void Url(const FunctionCallbackInfo<Value>& args) {
void Initialize(Local<Object> target, Local<Value> unused,
Local<Context> 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());

Agent* agent = env->inspector_agent();
env->SetMethod(target, "consoleCall", InspectorConsoleCall);

0 comments on commit a1b283c

Please sign in to comment.