Order of ports in MessageEvent.ports is random
Categories
(Core :: DOM: postMessage, defect, P3)
Tracking
()
Tracking | Status | |
---|---|---|
firefox95 | --- | fixed |
People
(Reporter: guanzo91, Assigned: sfink)
References
Details
Attachments
(3 files)
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36
Steps to reproduce:
Reproduction links
Parent window: https://codesandbox.io/s/wonderful-dew-ktw1v?file=/index.html
Iframe window: https://codesandbox.io/s/hardcore-elbakyan-ou60y?file=/index.html
On the parent window link, click the refresh icon until you see "ERROR: ports swapped".
TL;DR
Parent window:
$iframe.contentWindow.postMessage(null, null, [port1, port2])
Iframe window:
window.addEventListener('message', async event => {
const [port1, port2] = event.ports // Sometimes it's this order
const [port2, port1] = event.ports // Sometimes it's this order
})
- Create two MessageChannels. postMessage each channels "port2" to an iframe.
- Setup message listeners on each channels "port1"
- Inside the iframe, retrieve ports from
event.ports
, and for each port, postMessage back to parent window.
Actual results:
Messages are sometimes received from the wrong channel. This is because sometimes, the order of ports passed to postMessage is not the same order when iframe retrieves ports from event.ports.
Expected results:
The order of ports in event.ports should stay the same after being postMessaged.
Comment 2•3 years ago
|
||
The Bugbug bot thinks this bug should belong to the 'Core::DOM: Core & HTML' component, and is moving the bug to that component. Please revert this change in case you think the bot is wrong.
Updated•3 years ago
|
Updated•3 years ago
|
Comment 4•3 years ago
|
||
hmm, is this coming from the JS engine, https://searchfox.org/mozilla-central/rev/489e82dcc1e5afbe691ff3b1c982382914637e38/js/src/vm/StructuredClone.cpp#593-595
Assignee | ||
Comment 5•3 years ago
|
||
(In reply to Olli Pettay [:smaug] from comment #4)
hmm, is this coming from the JS engine, https://searchfox.org/mozilla-central/rev/489e82dcc1e5afbe691ff3b1c982382914637e38/js/src/vm/StructuredClone.cpp#593-595
Yes, definitely.
Assignee | ||
Updated•3 years ago
|
Assignee | ||
Comment 6•3 years ago
|
||
Assignee | ||
Comment 7•3 years ago
|
||
Hm, I see why I didn't have a test for this. Within the JS engine, the order of Transferables is not visible. The only Transferable type is ArrayBuffer.
MessagePorts do a weird thing during transferring where they get appended to an mTransferredPorts
array and exposed to the caller.
Pushed by sfink@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/af672c9161d7 retain ordering of transferable objects r=jonco,smaug
Comment 9•3 years ago
|
||
bugherder |
Description
•