summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAleksei Koziatinskii <ak239spb@gmail.com>2019-06-25 15:28:56 -0700
committerRich Trott <rtrott@gmail.com>2019-07-20 22:19:06 -0700
commitf02dfdb2b5e266a057eda1e07eafc62b55f468d3 (patch)
treed1fc208e5dc31744f56ba566d0720ad52c6c35fd /lib
parentb30dca8d9efcff9d7650e633c20c93ace5e52f36 (diff)
downloadandroid-node-v8-f02dfdb2b5e266a057eda1e07eafc62b55f468d3.tar.gz
android-node-v8-f02dfdb2b5e266a057eda1e07eafc62b55f468d3.tar.bz2
android-node-v8-f02dfdb2b5e266a057eda1e07eafc62b55f468d3.zip
inspector: add inspector.waitForDebugger()
This method blocks current node process until a client sends Runtime.runifWaitingForDebugger. It can be useful when we need to report inspector.url() before waiting for connection: ``` inspector.open(0, undefined, false); fs.writeFileSync(someFileName, inspector.url()); inspector.waitForDebugger(); ``` PR-URL: https://github.com/nodejs/node/pull/28453 Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/inspector.js22
-rw-r--r--lib/internal/errors.js1
2 files changed, 21 insertions, 2 deletions
diff --git a/lib/inspector.js b/lib/inspector.js
index 4bec628b7d..198d87ae44 100644
--- a/lib/inspector.js
+++ b/lib/inspector.js
@@ -8,6 +8,7 @@ const {
ERR_INSPECTOR_COMMAND,
ERR_INSPECTOR_NOT_AVAILABLE,
ERR_INSPECTOR_NOT_CONNECTED,
+ ERR_INSPECTOR_NOT_ACTIVE,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_CALLBACK
} = require('internal/errors').codes;
@@ -19,7 +20,12 @@ if (!hasInspector)
const EventEmitter = require('events');
const { validateString } = require('internal/validators');
const util = require('util');
-const { Connection, open, url } = internalBinding('inspector');
+const {
+ Connection,
+ open,
+ url,
+ waitForDebugger
+} = internalBinding('inspector');
const connectionSymbol = Symbol('connectionProperty');
const messageCallbacksSymbol = Symbol('messageCallbacks');
@@ -105,10 +111,22 @@ class Session extends EventEmitter {
}
}
+function inspectorOpen(port, host, wait) {
+ open(port, host);
+ if (wait)
+ waitForDebugger();
+}
+
+function inspectorWaitForDebugger() {
+ if (!waitForDebugger())
+ throw new ERR_INSPECTOR_NOT_ACTIVE();
+}
+
module.exports = {
- open: (port, host, wait) => open(port, host, !!wait),
+ open: inspectorOpen,
close: process._debugEnd,
url: url,
+ waitForDebugger: inspectorWaitForDebugger,
// This is dynamically added during bootstrap,
// where the console from the VM is still available
console: require('internal/util/inspector').consoleFromVM,
diff --git a/lib/internal/errors.js b/lib/internal/errors.js
index 873523f64d..c36f34eff4 100644
--- a/lib/internal/errors.js
+++ b/lib/internal/errors.js
@@ -887,6 +887,7 @@ E('ERR_INPUT_TYPE_NOT_ALLOWED', '--input-type can only be used with string ' +
E('ERR_INSPECTOR_ALREADY_CONNECTED', '%s is already connected', Error);
E('ERR_INSPECTOR_CLOSED', 'Session was closed', Error);
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_INTERNAL_ASSERTION', (message) => {