summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorEugene Ostroukhov <eostroukhov@gmail.com>2019-07-26 10:40:54 -0700
committerEugene Ostroukhov <eostroukhov@gmail.com>2019-09-16 09:01:55 -0700
commit3d841fe20d732111094c3f62febd5a6b8b483b91 (patch)
tree197e5397ecd069b315f9e76b1d2ce942f35cfa9b /lib
parent70abb4ffe40c8526c5415c02c20b7b3a3cdbacd2 (diff)
downloadandroid-node-v8-3d841fe20d732111094c3f62febd5a6b8b483b91.tar.gz
android-node-v8-3d841fe20d732111094c3f62febd5a6b8b483b91.tar.bz2
android-node-v8-3d841fe20d732111094c3f62febd5a6b8b483b91.zip
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 <ak239spb@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/inspector.js14
-rw-r--r--lib/internal/errors.js1
2 files changed, 15 insertions, 0 deletions
diff --git a/lib/inspector.js b/lib/inspector.js
index 198d87ae44..08cf938999 100644
--- a/lib/inspector.js
+++ b/lib/inspector.js
@@ -9,6 +9,7 @@ const {
ERR_INSPECTOR_NOT_AVAILABLE,
ERR_INSPECTOR_NOT_CONNECTED,
ERR_INSPECTOR_NOT_ACTIVE,
+ ERR_INSPECTOR_NOT_WORKER,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_CALLBACK
} = require('internal/errors').codes;
@@ -20,8 +21,11 @@ if (!hasInspector)
const EventEmitter = require('events');
const { validateString } = require('internal/validators');
const util = require('util');
+const { isMainThread } = require('worker_threads');
+
const {
Connection,
+ MainThreadConnection,
open,
url,
waitForDebugger
@@ -47,6 +51,16 @@ class Session extends EventEmitter {
new Connection((message) => this[onMessageSymbol](message));
}
+ connectToMainThread() {
+ if (isMainThread)
+ throw new ERR_INSPECTOR_NOT_WORKER();
+ if (this[connectionSymbol])
+ throw new ERR_INSPECTOR_ALREADY_CONNECTED('The inspector session');
+ this[connectionSymbol] =
+ new MainThreadConnection(
+ (message) => queueMicrotask(() => this[onMessageSymbol](message)));
+ }
+
[onMessageSymbol](message) {
const parsed = JSON.parse(message);
try {
diff --git a/lib/internal/errors.js b/lib/internal/errors.js
index c478e83f60..eba6989916 100644
--- a/lib/internal/errors.js
+++ b/lib/internal/errors.js
@@ -893,6 +893,7 @@ E('ERR_INSPECTOR_COMMAND', 'Inspector error %d: %s', Error);
E('ERR_INSPECTOR_NOT_ACTIVE', 'Inspector is not active', Error);
E('ERR_INSPECTOR_NOT_AVAILABLE', 'Inspector is not available', Error);
E('ERR_INSPECTOR_NOT_CONNECTED', 'Session is not connected', Error);
+E('ERR_INSPECTOR_NOT_WORKER', 'Current thread is not a worker', Error);
E('ERR_INTERNAL_ASSERTION', (message) => {
const suffix = 'This is caused by either a bug in Node.js ' +
'or incorrect usage of Node.js internals.\n' +