From a26865849631b370866db04ac808373606164191 Mon Sep 17 00:00:00 2001 From: Eugene Ostroukhov Date: Fri, 26 Jul 2019 10:40:54 -0700 Subject: [PATCH] inspector: new API - Session.connectToMainThread This API is designed to enable worker threads use Inspector protocol on main thread (and other workers through NodeWorker domain). Note that worker can cause dead lock by suspending itself. I will work on a new API that will allow workers to be hidden from the inspector. Fixes: https://github.com/nodejs/node/issues/28828 PR-URL: https://github.com/nodejs/node/pull/28870 Reviewed-By: Aleksei Koziatinskii Reviewed-By: James M Snell Reviewed-By: Benjamin Gruenbaum --- doc/api/errors.md | 6 + doc/api/inspector.md | 12 +- lib/inspector.js | 14 ++ lib/internal/errors.js | 1 + src/inspector/worker_inspector.cc | 6 + src/inspector/worker_inspector.h | 5 + src/inspector_agent.cc | 11 ++ src/inspector_agent.h | 9 +- src/inspector_js_api.cc | 56 ++++-- .../test-inspector-bindings.js | 3 +- .../test-inspector-connect-main-thread.js | 179 ++++++++++++++++++ 11 files changed, 282 insertions(+), 20 deletions(-) rename test/{sequential => parallel}/test-inspector-bindings.js (98%) create mode 100644 test/parallel/test-inspector-connect-main-thread.js diff --git a/doc/api/errors.md b/doc/api/errors.md index d2946435ca3b98..87a080b081f01b 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -1213,6 +1213,12 @@ The `inspector` module is not available for use. While using the `inspector` module, an attempt was made to use the inspector before it was connected. + +### ERR_INSPECTOR_NOT_WORKER + +An API was called on the main thread that can only be used from +the worker thread. + ### ERR_INVALID_ADDRESS_FAMILY diff --git a/doc/api/inspector.md b/doc/api/inspector.md index f82c53f5bc3f51..96c3ad03c06354 100644 --- a/doc/api/inspector.md +++ b/doc/api/inspector.md @@ -121,9 +121,15 @@ session.on('Debugger.paused', ({ params }) => { added: v8.0.0 --> -Connects a session to the inspector back-end. An exception will be thrown -if there is already a connected session established either through the API or by -a front-end connected to the Inspector WebSocket port. +Connects a session to the inspector back-end. + +### session.connectToMainThread() + + +Connects a session to the main thread inspector back-end. An exception will +be thrown if this API was not called on a Worker thread. ### session.disconnect()