Skip to content

Commit

Permalink
typings: add JSDoc typings for inspector
Browse files Browse the repository at this point in the history
Added JSDoc typings for the `inspector` lib module.

PR-URL: #38390
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Adrian Estrada <edsadr@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
  • Loading branch information
VoltrexKeyva authored and BethGriggs committed Nov 25, 2021
1 parent b4a80db commit 67c7d11
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion lib/inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,22 @@ 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');
this[connectionSymbol] =
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();
Expand Down Expand Up @@ -93,6 +102,13 @@ class Session extends EventEmitter {
}
}

/**
* Posts a message to the inspector back-end.
* @param {string} method
* @param {Record<unknown, unknown>} [params]
* @param {Function} [callback]
* @returns {void}
*/
post(method, params, callback) {
validateString(method, 'method');
if (!callback && typeof params === 'function') {
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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
Expand Down

0 comments on commit 67c7d11

Please sign in to comment.