From 15609e9a0073221a98340ae815668101c690e16c Mon Sep 17 00:00:00 2001 From: Nahee-Park Date: Mon, 30 Sep 2024 18:44:48 +0900 Subject: [PATCH] worker: throw InvalidStateError in postMessage after close Align BroadcastChannel behavior with the spec by throwing an InvalidStateError when postMessage is called after the channel is closed. This ensures that BroadcastChannel properly handles closed states and throws the correct error for postMessage attempts. This update addresses expected failures for invalid postMessage after close in WPT. --- lib/internal/worker/io.js | 2 +- test/wpt/status/webmessaging/broadcastchannel.json | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/lib/internal/worker/io.js b/lib/internal/worker/io.js index 3263ddb88194fc..80b39c24033147 100644 --- a/lib/internal/worker/io.js +++ b/lib/internal/worker/io.js @@ -402,7 +402,7 @@ class BroadcastChannel extends EventTarget { if (arguments.length === 0) throw new ERR_MISSING_ARGS('message'); if (this[kHandle] === undefined) - throw new DOMException('BroadcastChannel is closed.'); + throw new DOMException('BroadcastChannel is closed.', 'InvalidStateError'); if (this[kHandle].postMessage(message) === undefined) throw new DOMException('Message could not be posted.'); } diff --git a/test/wpt/status/webmessaging/broadcastchannel.json b/test/wpt/status/webmessaging/broadcastchannel.json index b6ee1b6e0db194..340b9955f33fe3 100644 --- a/test/wpt/status/webmessaging/broadcastchannel.json +++ b/test/wpt/status/webmessaging/broadcastchannel.json @@ -10,14 +10,6 @@ ] } }, - "interface.any.js": { - "fail": { - "expected": [ - "postMessage after close should throw", - "postMessage should throw InvalidStateError after close, even with uncloneable data" - ] - } - }, "origin.window.js": { "fail": { "expected": [