From 152c7cd65c1b4da0c62a99746dbfe813d242db7a Mon Sep 17 00:00:00 2001 From: Voltrex <62040526+VoltrexMaster@users.noreply.github.com> Date: Sun, 25 Apr 2021 03:39:46 +0430 Subject: [PATCH] typings: add JSDoc typings for inspector Added JSDoc typings for the `inspector` lib module. --- lib/inspector.js | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/lib/inspector.js b/lib/inspector.js index d7518eff261f3a..46779a0ec21dac 100644 --- a/lib/inspector.js +++ b/lib/inspector.js @@ -53,6 +53,10 @@ class Session extends EventEmitter { this[messageCallbacksSymbol] = new SafeMap(); } + /** + * Connects the session to the inspector back-end. + * @returns {void} + */ connect() { if (this[connectionSymbol]) throw new ERR_INSPECTOR_ALREADY_CONNECTED('The inspector session'); @@ -60,6 +64,11 @@ class Session extends EventEmitter { new Connection((message) => this[onMessageSymbol](message)); } + /** + * Connects the session to the main thread + * inspector back-end. + * @returns {void} + */ connectToMainThread() { if (isMainThread) throw new ERR_INSPECTOR_NOT_WORKER(); @@ -93,6 +102,13 @@ class Session extends EventEmitter { } } + /** + * Posts a message to the inspector back-end. + * @param {string} method + * @param {Record} [params] + * @param {Function} [callback] + * @returns {void} + */ post(method, params, callback) { validateString(method, 'method'); if (!callback && typeof params === 'function') { @@ -120,6 +136,12 @@ class Session extends EventEmitter { this[connectionSymbol].dispatch(JSONStringify(message)); } + /** + * Immediately closes the session, all pending + * message callbacks will be called with an + * error. + * @returns {void} + */ disconnect() { if (!this[connectionSymbol]) return; @@ -134,6 +156,13 @@ class Session extends EventEmitter { } } +/** + * Activates inspector on host and port. + * @param {number} [port] + * @param {string} [host] + * @param {boolean} [wait] + * @returns {void} + */ function inspectorOpen(port, host, wait) { if (isEnabled()) { throw new ERR_INSPECTOR_ALREADY_ACTIVATED(); @@ -143,6 +172,12 @@ function inspectorOpen(port, host, wait) { waitForDebugger(); } +/** + * Blocks until a client (existing or connected later) + * has sent the `Runtime.runIfWaitingForDebugger` + * command. + * @returns {void} + */ function inspectorWaitForDebugger() { if (!waitForDebugger()) throw new ERR_INSPECTOR_NOT_ACTIVE(); @@ -151,7 +186,7 @@ function inspectorWaitForDebugger() { module.exports = { open: inspectorOpen, close: process._debugEnd, - url: url, + url, waitForDebugger: inspectorWaitForDebugger, // This is dynamically added during bootstrap, // where the console from the VM is still available