Skip to content

Commit

Permalink
fix: check if BroadcastChannel is open before sending (#17366)
Browse files Browse the repository at this point in the history
Fixes #16978
  • Loading branch information
crowlKats committed Jan 12, 2023
1 parent a6b3910 commit cc806cd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 7 additions & 1 deletion cli/tests/unit/broadcast_channel_test.ts
Expand Up @@ -2,7 +2,7 @@
import { assertEquals } from "../../../test_util/std/testing/asserts.ts";
import { deferred } from "../../../test_util/std/async/deferred.ts";

Deno.test("broadcastchannel worker", async () => {
Deno.test("BroadcastChannel worker", async () => {
const intercom = new BroadcastChannel("intercom");
let count = 0;

Expand All @@ -27,3 +27,9 @@ Deno.test("broadcastchannel worker", async () => {

await promise;
});

Deno.test("BroadcastChannel immediate close after post", () => {
const bc = new BroadcastChannel("internal_notification");
bc.postMessage("New listening connected!");
bc.close();
});
6 changes: 5 additions & 1 deletion ext/broadcast_channel/01_broadcast_channel.js
Expand Up @@ -122,7 +122,11 @@
dispatch(this, this[_name], new Uint8Array(data));

// Send to listeners in other VMs.
defer(() => core.opAsync("op_broadcast_send", rid, this[_name], data));
defer(() => {
if (!this[_closed]) {
core.opAsync("op_broadcast_send", rid, this[_name], data);
}
});
}

close() {
Expand Down

0 comments on commit cc806cd

Please sign in to comment.