mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-24 08:59:50 +00:00
When a message is posted to multiple ports at once, the order in which the callbacks for these messages are invoked is non-deterministic. To account for this, the test has been rewritten to accumulate logs for each port separately, and then print them grouped by port.
43 lines
1.3 KiB
HTML
43 lines
1.3 KiB
HTML
<!DOCTYPE html>
|
|
<script src="../include.js"></script>
|
|
<script>
|
|
asyncTest(done => {
|
|
let channel = new MessageChannel();
|
|
|
|
const port1Logs = [];
|
|
const port2Logs = [];
|
|
const port3Logs = [];
|
|
|
|
channel.port1.onmessage = (event) => {
|
|
port1Logs.push("Port1: " + JSON.stringify(event.data));
|
|
if (event.ports.length > 0) {
|
|
event.ports[0].postMessage("Hello from the transferred port");
|
|
return;
|
|
}
|
|
channel.port1.postMessage(event.data);
|
|
};
|
|
|
|
channel.port2.onmessage = (event) => {
|
|
port2Logs.push("Port2: " + JSON.stringify(event.data));
|
|
if (event.data === "DONE") {
|
|
for (let log of port1Logs)
|
|
println(log);
|
|
for (let log of port2Logs)
|
|
println(log);
|
|
for (let log of port3Logs)
|
|
println(log);
|
|
done();
|
|
}
|
|
};
|
|
|
|
let channel2 = new MessageChannel();
|
|
|
|
channel2.port2.onmessage = (event) => {
|
|
port3Logs.push("Port3: " + JSON.stringify(event.data));
|
|
channel.port2.postMessage("DONE");
|
|
}
|
|
|
|
channel.port2.postMessage("Hello");
|
|
channel.port2.postMessage({ foo: channel2.port1 }, { transfer: [channel2.port1] });
|
|
});
|
|
</script>
|