Skip to content

Commit 6486a30

Browse files
committed
worker: graduate BroadcastChannel to supported
Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: #41271 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 1e34969 commit 6486a30

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

doc/api/worker_threads.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,12 @@ if (isMainThread) {
347347

348348
<!-- YAML
349349
added: v15.4.0
350+
changes:
351+
- version: REPLACEME
352+
pr-url: https://github.com/nodejs/node/pull/00000
353+
description: No longer experimental.
350354
-->
351355

352-
> Stability: 1 - Experimental
353-
354356
Instances of `BroadcastChannel` allow asynchronous one-to-many communication
355357
with all other `BroadcastChannel` instances bound to the same channel name.
356358

lib/internal/worker/io.js

+20
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,9 @@ function isBroadcastChannel(value) {
395395
}
396396

397397
class BroadcastChannel extends EventTarget {
398+
/**
399+
* @param {string} name
400+
*/
398401
constructor(name) {
399402
if (arguments.length === 0)
400403
throw new ERR_MISSING_ARGS('name');
@@ -426,12 +429,18 @@ class BroadcastChannel extends EventTarget {
426429
}, opts)}`;
427430
}
428431

432+
/**
433+
* @type {string}
434+
*/
429435
get name() {
430436
if (!isBroadcastChannel(this))
431437
throw new ERR_INVALID_THIS('BroadcastChannel');
432438
return this[kName];
433439
}
434440

441+
/**
442+
* @returns {void}
443+
*/
435444
close() {
436445
if (!isBroadcastChannel(this))
437446
throw new ERR_INVALID_THIS('BroadcastChannel');
@@ -445,6 +454,11 @@ class BroadcastChannel extends EventTarget {
445454
this[kHandle] = undefined;
446455
}
447456

457+
/**
458+
*
459+
* @param {*} message
460+
* @returns {void}
461+
*/
448462
postMessage(message) {
449463
if (!isBroadcastChannel(this))
450464
throw new ERR_INVALID_THIS('BroadcastChannel');
@@ -460,6 +474,9 @@ class BroadcastChannel extends EventTarget {
460474
// BroadcastChannel API definition. Typically we shouldn't extend Web
461475
// Platform APIs with Node.js specific methods but ref and unref
462476
// are a bit special.
477+
/**
478+
* @returns {BroadcastChannel}
479+
*/
463480
ref() {
464481
if (!isBroadcastChannel(this))
465482
throw new ERR_INVALID_THIS('BroadcastChannel');
@@ -472,6 +489,9 @@ class BroadcastChannel extends EventTarget {
472489
// BroadcastChannel API definition. Typically we shouldn't extend Web
473490
// Platform APIs with Node.js specific methods but ref and unref
474491
// are a bit special.
492+
/**
493+
* @returns {BroadcastChannel}
494+
*/
475495
unref() {
476496
if (!isBroadcastChannel(this))
477497
throw new ERR_INVALID_THIS('BroadcastChannel');

0 commit comments

Comments
 (0)