Skip to content

Commit

Permalink
inspector: report when main context is destroyed
Browse files Browse the repository at this point in the history
PR-URL: nodejs#12814
Reimplements: nodejs#7756
Fixes: nodejs#7742
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
  • Loading branch information
Eugene Ostroukhov authored and Olivier Martin committed May 6, 2017
1 parent 5f2b8a3 commit 8fc7d0b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/inspector_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,6 @@ class NodeInspectorClient : public v8_inspector::V8InspectorClient {
terminated_(false),
running_nested_loop_(false) {
inspector_ = V8Inspector::create(env->isolate(), this);
const uint8_t CONTEXT_NAME[] = "Node.js Main Context";
StringView context_name(CONTEXT_NAME, sizeof(CONTEXT_NAME) - 1);
v8_inspector::V8ContextInfo info(env->context(), CONTEXT_GROUP_ID,
context_name);
inspector_->contextCreated(info);
}

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

void contextCreated(Local<Context> context, const std::string& name) {
std::unique_ptr<StringBuffer> name_buffer = Utf8ToStringView(name);
v8_inspector::V8ContextInfo info(context, CONTEXT_GROUP_ID,
name_buffer->string());
inspector_->contextCreated(info);
}

void contextDestroyed(Local<Context> context) {
inspector_->contextDestroyed(context);
}

void quitMessageLoopOnPause() override {
terminated_ = true;
}
Expand Down Expand Up @@ -379,6 +385,7 @@ bool Agent::Start(v8::Platform* platform, const char* path,
inspector_ =
std::unique_ptr<NodeInspectorClient>(
new NodeInspectorClient(parent_env_, platform));
inspector_->contextCreated(parent_env_->context(), "Node.js Main Context");
platform_ = platform;
if (options.inspector_enabled()) {
return StartIoThread();
Expand Down Expand Up @@ -451,6 +458,8 @@ bool Agent::IsStarted() {
}

void Agent::WaitForDisconnect() {
CHECK_NE(inspector_, nullptr);
inspector_->contextDestroyed(parent_env_->context());
if (io_ != nullptr) {
io_->WaitForDisconnect();
}
Expand Down
8 changes: 8 additions & 0 deletions test/inspector/test-inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ function setupExpectValue(value) {
};
}

function setupExpectContextDestroyed(id) {
return function(message) {
if ('Runtime.executionContextDestroyed' === message['method'])
return message['params']['executionContextId'] === id;
};
}

function testBreakpointOnStart(session) {
console.log('[test]',
'Verifying debugger stops on start (--inspect-brk option)');
Expand Down Expand Up @@ -203,6 +210,7 @@ function testI18NCharacters(session) {
function testWaitsForFrontendDisconnect(session, harness) {
console.log('[test]', 'Verify node waits for the frontend to disconnect');
session.sendInspectorCommands({ 'method': 'Debugger.resume'})
.expectMessages(setupExpectContextDestroyed(1))
.expectStderrOutput('Waiting for the debugger to disconnect...')
.disconnect(true);
}
Expand Down

0 comments on commit 8fc7d0b

Please sign in to comment.