Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5a1289d

Browse filesBrowse files
joyeecheungBethGriggs
authored andcommitted
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 <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
1 parent e61bbda commit 5a1289d
Copy full SHA for 5a1289d

File tree

Expand file treeCollapse file tree

3 files changed

+8
-6
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+8
-6
lines changed
Open diff view settings
Collapse file

‎src/env.cc‎

Copy file name to clipboardExpand all lines: src/env.cc
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,13 @@ void Environment::Start(const std::vector<std::string>& args,
341341
static uv_once_t init_once = UV_ONCE_INIT;
342342
uv_once(&init_once, InitThreadLocalOnce);
343343
uv_key_set(&thread_local_env, this);
344+
345+
#if HAVE_INSPECTOR
346+
// This needs to be set before we start the inspector
347+
Local<Object> obj = Object::New(isolate());
348+
CHECK(obj->SetPrototype(context(), Null(isolate())).FromJust());
349+
set_inspector_console_api_object(obj);
350+
#endif // HAVE_INSPECTOR
344351
}
345352

346353
void Environment::RegisterHandleCleanups() {
Collapse file

‎src/inspector_agent.cc‎

Copy file name to clipboardExpand all lines: src/inspector_agent.cc
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ class NodeInspectorClient : public V8InspectorClient {
506506
void installAdditionalCommandLineAPI(Local<Context> context,
507507
Local<Object> target) override {
508508
Local<Object> console_api = env_->inspector_console_api_object();
509+
CHECK(!console_api.IsEmpty());
509510

510511
Local<Array> properties =
511512
console_api->GetOwnPropertyNames(context).ToLocalChecked();
Collapse file

‎src/inspector_js_api.cc‎

Copy file name to clipboardExpand all lines: src/inspector_js_api.cc
-6Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,6 @@ void Url(const FunctionCallbackInfo<Value>& args) {
277277
void Initialize(Local<Object> target, Local<Value> unused,
278278
Local<Context> context, void* priv) {
279279
Environment* env = Environment::GetCurrent(context);
280-
{
281-
auto obj = Object::New(env->isolate());
282-
auto null = Null(env->isolate());
283-
CHECK(obj->SetPrototype(context, null).FromJust());
284-
env->set_inspector_console_api_object(obj);
285-
}
286280

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.