-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Should BroadcastChannel check for closed flag before dispatching events? #1371
Comments
The behavior as specified seems particularly weird when |
@bakulf, would you be able to weigh in with Gecko's perspective? My weak opinion is that being consistent with MessageChannel and MessagePort is more important, and Firefox should probably fix their implementation. |
Gecko collects all destination channels asynchronously. I can change it. Bug 1278340. |
My suggestion was to process close() asynchronously for receiving but synchronously for posting message. |
Right, This is actually what we do. In this way, if there are messages in the process to be received, they will be processed before 'close()'. Of course, close() synchronously, sets a flag so that any postMessage() will be ignored. |
I think we can add to this:
Basically, all the checks of step 7, except for the channel name, which isn't going to change. So I'll open a PR and move them to Step 10, inside the task. |
Ah no that's incorrect, since the worker closing, or the document not being fully-active, aren't things you can check from inside a task if they are positive and negative respectively(the task will by definition not run?). I'll focus on the close flag then. There is already a test in the suite that links to this issue BTW. |
This way nothing happens if something got closed during delivery. (Implementations already did this.) Tests: web-platform-tests/wpt#21895. Fixes #1371. Possible follow-up: #5327.
Currently the way
BroadcastChannel.postMessage
is specified, thepostMessage
method synchronously collects all destination channels (that match and aren't closed), and then queues tasks for all of these channels to dispatch amessage
event. This seems counterintuitive in code like this:According to the spec the expected result of this is for both 'first' and 'second' to be logged to the console. Because despite
c2
closing itself after receiving the first event, the second event has already been queued and should still be delivered. This behavior doesn't seem to match the firefox implementation, which won't deliver the second event toc2
if it closed itself already in an earlier message event. So should the spec be modified to have a check inside the queued task to make sure the BroadcastChannel object still is not closed?But on the other hand the behavior as specced is consistent with the equivalent code using
MessageChannel
/MessagePort
(https://jsfiddle.net/c9mbo2c3/2/), where at least firefox and chrome seem to actually match the spec.So should the spec change for
BroadcastChannel
, or should firefox fix their implementation? (And if the spec is changed, should a similar change be made forMessagePort
? Even though the implementations I tried there curently match the spec)The text was updated successfully, but these errors were encountered: