Skip to content
Permalink
Browse files

inspector: report when main context is destroyed

PR-URL: #12814
Reimplements: #7756
Fixes: #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...
eugeneo committed May 3, 2017
1 parent 2614d24 commit 15e160e6264c0b737cc1deee3652de9b29d71d1f
Showing with 22 additions and 5 deletions.
  1. +14 −5 src/inspector_agent.cc
  2. +8 −0 test/inspector/test-inspector.js
@@ -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 {
@@ -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;
}
@@ -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();
@@ -451,6 +458,8 @@ bool Agent::IsStarted() {
}

void Agent::WaitForDisconnect() {
CHECK_NE(inspector_, nullptr);
inspector_->contextDestroyed(parent_env_->context());
if (io_ != nullptr) {
io_->WaitForDisconnect();
}
@@ -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)');
@@ -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);
}

0 comments on commit 15e160e

Please sign in to comment.
You can’t perform that action at this time.