Skip to content

Commit

Permalink
inspector: fix session.disconnect crash
Browse files Browse the repository at this point in the history
  • Loading branch information
theanarkh committed Mar 4, 2023
1 parent 733ef4e commit ee09149
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/inspector_js_api.cc
Expand Up @@ -69,6 +69,7 @@ class JSBindingsConnection : public AsyncWrap {
JSBindingsConnection* connection)
: env_(env),
connection_(connection) {
connection_->Detach();
}

void SendMessageToFrontend(const v8_inspector::StringView& message)
Expand Down Expand Up @@ -123,10 +124,7 @@ class JSBindingsConnection : public AsyncWrap {
new JSBindingsConnection(env, info.This(), callback);
}

void Disconnect() {
session_.reset();
delete this;
}
void Disconnect() { session_.reset(); }

static void Disconnect(const FunctionCallbackInfo<Value>& info) {
JSBindingsConnection* session;
Expand Down
20 changes: 20 additions & 0 deletions test/parallel/test-inspector-connect-to-main-thread.js
@@ -0,0 +1,20 @@
'use strict';
const common = require('../common');

common.skipIfInspectorDisabled();

const { Session } = require('inspector');
const { Worker, isMainThread, workerData } = require('worker_threads');

if (!workerData) {
common.skipIfWorker();
}

if (isMainThread) {
new Worker(__filename, { workerData: {} });
} else {
const session = new Session();
session.connectToMainThread();
// Do not crash
session.disconnect();
}

0 comments on commit ee09149

Please sign in to comment.