diff options
author | Leo Kettmeir <crowlkats@toaxl.com> | 2023-01-12 13:43:36 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-12 13:43:36 +0100 |
commit | cc806cdf2121878ae4c10b1fd0c4c03b14ba33c7 (patch) | |
tree | 337e1ea14662d58a860a32feb5a25006b9d95af4 | |
parent | a6b3910bdfe0183e458015d00a61295779e46eb1 (diff) |
fix: check if BroadcastChannel is open before sending (#17366)
Fixes #16978
-rw-r--r-- | cli/tests/unit/broadcast_channel_test.ts | 8 | ||||
-rw-r--r-- | ext/broadcast_channel/01_broadcast_channel.js | 6 |
2 files changed, 12 insertions, 2 deletions
diff --git a/cli/tests/unit/broadcast_channel_test.ts b/cli/tests/unit/broadcast_channel_test.ts index 06821c4db..b13a47574 100644 --- a/cli/tests/unit/broadcast_channel_test.ts +++ b/cli/tests/unit/broadcast_channel_test.ts @@ -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; @@ -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(); +}); diff --git a/ext/broadcast_channel/01_broadcast_channel.js b/ext/broadcast_channel/01_broadcast_channel.js index cf3b17ac5..59c6b7cef 100644 --- a/ext/broadcast_channel/01_broadcast_channel.js +++ b/ext/broadcast_channel/01_broadcast_channel.js @@ -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() { |