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` lin module.
  • Loading branch information
VoltrexKeyva committed Sep 3, 2021
1 parent f26c2ce commit e9e1812
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 a 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 a 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 {Object} [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 {
}
}

/**
* Actives 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 e9e1812

Please sign in to comment.