Skip to content

Commit

Permalink
worker: expose BroadcastChannel as a global
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
jasnell committed Dec 24, 2021
1 parent 6486a30 commit ce4d3ad
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ module.exports = {
Event: 'readable',
EventTarget: 'readable',
MessageChannel: 'readable',
BroadcastChannel: 'readable',
MessageEvent: 'readable',
MessagePort: 'readable',
TextEncoder: 'readable',
Expand Down
8 changes: 8 additions & 0 deletions doc/api/globals.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,14 @@ added: v16.0.0
Global alias for [`buffer.atob()`][].

## `BroadcastChannel`

<!-- YAML
added: REPLACEME
-->

See {BroadcastChannel}.

## `btoa(data)`

<!-- YAML
Expand Down
2 changes: 1 addition & 1 deletion doc/api/worker_threads.md
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ if (isMainThread) {
added: v15.4.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/00000
pr-url: https://github.com/nodejs/node/pull/41271
description: No longer experimental.
-->

Expand Down
2 changes: 2 additions & 0 deletions lib/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ rules:
# disabled with --without-intl build flag.
- name: Intl
message: "Use `const { Intl } = globalThis;` instead of the global."
- name: BroadcastChannel
message: "Use `const { BroadcastChannel } = require('internal/worker/io');` instead of the global."
- name: MessageChannel
message: "Use `const { MessageChannel } = require('internal/worker/io');` instead of the global."
- name: MessageEvent
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,12 @@ if (!config.noBrowserGlobals) {
MessageChannel,
MessagePort,
MessageEvent,
BroadcastChannel,
} = require('internal/worker/io');
exposeInterface(globalThis, 'MessageChannel', MessageChannel);
exposeInterface(globalThis, 'MessagePort', MessagePort);
exposeInterface(globalThis, 'MessageEvent', MessageEvent);
exposeInterface(globalThis, 'BroadcastChannel', BroadcastChannel);

// https://html.spec.whatwg.org/multipage/webappapis.html#windoworworkerglobalscope
const timers = require('timers');
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/worker/io.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ class BroadcastChannel extends EventTarget {

/**
*
* @param {*} message
* @param {any} message
* @returns {void}
*/
postMessage(message) {
Expand Down

0 comments on commit ce4d3ad

Please sign in to comment.