mirror of https://github.com/nodejs/node.git
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>pull/12814/head
parent
2614d247fb
commit
15e160e626
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue