Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check if BroadcastChannel is open before sending #17366

Merged
merged 1 commit into from Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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