Skip to content

Commit 15e160e

Browse files
author
Eugene Ostroukhov
committed
inspector: report when main context is destroyed
PR-URL: #12814 Reimplements: #7756 Fixes: #7742 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Aleksey Kozyatinskiy <[email protected]>
1 parent 2614d24 commit 15e160e

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/inspector_agent.cc

+14-5
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,6 @@ class NodeInspectorClient : public v8_inspector::V8InspectorClient {
271271
terminated_(false),
272272
running_nested_loop_(false) {
273273
inspector_ = V8Inspector::create(env->isolate(), this);
274-
const uint8_t CONTEXT_NAME[] = "Node.js Main Context";
275-
StringView context_name(CONTEXT_NAME, sizeof(CONTEXT_NAME) - 1);
276-
v8_inspector::V8ContextInfo info(env->context(), CONTEXT_GROUP_ID,
277-
context_name);
278-
inspector_->contextCreated(info);
279274
}
280275

281276
void runMessageLoopOnPause(int context_group_id) override {
@@ -296,6 +291,17 @@ class NodeInspectorClient : public v8_inspector::V8InspectorClient {
296291
return uv_hrtime() * 1.0 / NANOS_PER_MSEC;
297292
}
298293

294+
void contextCreated(Local<Context> context, const std::string& name) {
295+
std::unique_ptr<StringBuffer> name_buffer = Utf8ToStringView(name);
296+
v8_inspector::V8ContextInfo info(context, CONTEXT_GROUP_ID,
297+
name_buffer->string());
298+
inspector_->contextCreated(info);
299+
}
300+
301+
void contextDestroyed(Local<Context> context) {
302+
inspector_->contextDestroyed(context);
303+
}
304+
299305
void quitMessageLoopOnPause() override {
300306
terminated_ = true;
301307
}
@@ -379,6 +385,7 @@ bool Agent::Start(v8::Platform* platform, const char* path,
379385
inspector_ =
380386
std::unique_ptr<NodeInspectorClient>(
381387
new NodeInspectorClient(parent_env_, platform));
388+
inspector_->contextCreated(parent_env_->context(), "Node.js Main Context");
382389
platform_ = platform;
383390
if (options.inspector_enabled()) {
384391
return StartIoThread();
@@ -451,6 +458,8 @@ bool Agent::IsStarted() {
451458
}
452459

453460
void Agent::WaitForDisconnect() {
461+
CHECK_NE(inspector_, nullptr);
462+
inspector_->contextDestroyed(parent_env_->context());
454463
if (io_ != nullptr) {
455464
io_->WaitForDisconnect();
456465
}

test/inspector/test-inspector.js

+8
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ function setupExpectValue(value) {
8787
};
8888
}
8989

90+
function setupExpectContextDestroyed(id) {
91+
return function(message) {
92+
if ('Runtime.executionContextDestroyed' === message['method'])
93+
return message['params']['executionContextId'] === id;
94+
};
95+
}
96+
9097
function testBreakpointOnStart(session) {
9198
console.log('[test]',
9299
'Verifying debugger stops on start (--inspect-brk option)');
@@ -203,6 +210,7 @@ function testI18NCharacters(session) {
203210
function testWaitsForFrontendDisconnect(session, harness) {
204211
console.log('[test]', 'Verify node waits for the frontend to disconnect');
205212
session.sendInspectorCommands({ 'method': 'Debugger.resume'})
213+
.expectMessages(setupExpectContextDestroyed(1))
206214
.expectStderrOutput('Waiting for the debugger to disconnect...')
207215
.disconnect(true);
208216
}

0 commit comments

Comments
 (0)