worker: expose BroadcastChannel as a global

Signed-off-by: James M Snell <jasnell@gmail.com>

PR-URL: https://github.com/nodejs/node/pull/41271
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
James M Snell committed 2021-12-24 08:32:48 -08:00
1 parent 6486a304d3
commit ce4d3adf50
6 files changed
+15 -2

No files matched your search

+1
View File
@@ -368,6 +368,7 @@ module.exports = {
Event: 'readable',
EventTarget: 'readable',
MessageChannel: 'readable',
BroadcastChannel: 'readable',
MessageEvent: 'readable',
MessagePort: 'readable',
TextEncoder: 'readable',
+8
View File
@@ -239,6 +239,14 @@ added: v16.0.0
Global alias for [`buffer.atob()`][].
## `BroadcastChannel`
<!-- YAML
added: REPLACEME
-->
See {BroadcastChannel}.
## `btoa(data)`
<!-- YAML
+1 -1
View File
@@ -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.
-->
+2
View File
@@ -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
+2
View File
@@ -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');
+1 -1
View File
@@ -456,7 +456,7 @@ class BroadcastChannel extends EventTarget {
/**
*
* @param {*} message
* @param {any} message
* @returns {void}
*/
postMessage(message) {