From da859b56cb40dd9d632180fbb4933e4f4bda4902 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 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added JSDoc typings for the `inspector` lib module. PR-URL: https://github.com/nodejs/node/pull/38390 Reviewed-By: James M Snell Reviewed-By: Adrian Estrada Reviewed-By: Rich Trott Reviewed-By: Michaƫl Zasso --- 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