diff --git a/doc/api/worker_threads.md b/doc/api/worker_threads.md index 106efca846f15b..37f50cef79ad33 100644 --- a/doc/api/worker_threads.md +++ b/doc/api/worker_threads.md @@ -347,10 +347,12 @@ if (isMainThread) { -> Stability: 1 - Experimental - Instances of `BroadcastChannel` allow asynchronous one-to-many communication with all other `BroadcastChannel` instances bound to the same channel name. diff --git a/lib/internal/worker/io.js b/lib/internal/worker/io.js index 5d03f43ef6df62..0379e5f26c8b54 100644 --- a/lib/internal/worker/io.js +++ b/lib/internal/worker/io.js @@ -395,6 +395,9 @@ function isBroadcastChannel(value) { } class BroadcastChannel extends EventTarget { + /** + * @param {string} name + */ constructor(name) { if (arguments.length === 0) throw new ERR_MISSING_ARGS('name'); @@ -426,12 +429,18 @@ class BroadcastChannel extends EventTarget { }, opts)}`; } + /** + * @type {string} + */ get name() { if (!isBroadcastChannel(this)) throw new ERR_INVALID_THIS('BroadcastChannel'); return this[kName]; } + /** + * @returns {void} + */ close() { if (!isBroadcastChannel(this)) throw new ERR_INVALID_THIS('BroadcastChannel'); @@ -445,6 +454,11 @@ class BroadcastChannel extends EventTarget { this[kHandle] = undefined; } + /** + * + * @param {*} message + * @returns {void} + */ postMessage(message) { if (!isBroadcastChannel(this)) throw new ERR_INVALID_THIS('BroadcastChannel'); @@ -460,6 +474,9 @@ class BroadcastChannel extends EventTarget { // BroadcastChannel API definition. Typically we shouldn't extend Web // Platform APIs with Node.js specific methods but ref and unref // are a bit special. + /** + * @returns {BroadcastChannel} + */ ref() { if (!isBroadcastChannel(this)) throw new ERR_INVALID_THIS('BroadcastChannel'); @@ -472,6 +489,9 @@ class BroadcastChannel extends EventTarget { // BroadcastChannel API definition. Typically we shouldn't extend Web // Platform APIs with Node.js specific methods but ref and unref // are a bit special. + /** + * @returns {BroadcastChannel} + */ unref() { if (!isBroadcastChannel(this)) throw new ERR_INVALID_THIS('BroadcastChannel');