Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typings: add JSDoc typings for inspector #38390

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 36 additions & 1 deletion lib/inspector.js
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