Browse Source

inspector: report when main context is destroyed

PR-URL: https://github.com/nodejs/node/pull/12814
Reimplements: https://github.com/nodejs/node/pull/7756
Fixes: https://github.com/nodejs/node/issues/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>
v6
Eugene Ostroukhov 8 years ago
parent
commit
15e160e626
  1. 19
      src/inspector_agent.cc
  2. 8
      test/inspector/test-inspector.js

19
src/inspector_agent.cc

@ -271,11 +271,6 @@ class NodeInspectorClient : public v8_inspector::V8InspectorClient {
terminated_(false), terminated_(false),
running_nested_loop_(false) { running_nested_loop_(false) {
inspector_ = V8Inspector::create(env->isolate(), this); 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 { 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; 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 { void quitMessageLoopOnPause() override {
terminated_ = true; terminated_ = true;
} }
@ -379,6 +385,7 @@ bool Agent::Start(v8::Platform* platform, const char* path,
inspector_ = inspector_ =
std::unique_ptr<NodeInspectorClient>( std::unique_ptr<NodeInspectorClient>(
new NodeInspectorClient(parent_env_, platform)); new NodeInspectorClient(parent_env_, platform));
inspector_->contextCreated(parent_env_->context(), "Node.js Main Context");
platform_ = platform; platform_ = platform;
if (options.inspector_enabled()) { if (options.inspector_enabled()) {
return StartIoThread(); return StartIoThread();
@ -451,6 +458,8 @@ bool Agent::IsStarted() {
} }
void Agent::WaitForDisconnect() { void Agent::WaitForDisconnect() {
CHECK_NE(inspector_, nullptr);
inspector_->contextDestroyed(parent_env_->context());
if (io_ != nullptr) { if (io_ != nullptr) {
io_->WaitForDisconnect(); io_->WaitForDisconnect();
} }

8
test/inspector/test-inspector.js

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

Loading…
Cancel
Save