mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-15 07:32:52 +00:00
This aligns Workers and Window and MessagePorts to all use the same mechanism for transferring serialized messages across realms. It also allows transferring more message ports into a worker. Re-enable the Worker-echo test, as none of the MessagePort tests have themselves been flaky, and those are now using the same underlying implementation.
32 lines
991 B
HTML
32 lines
991 B
HTML
<script src="../include.js"></script>
|
|
<script>
|
|
asyncTest((done) => {
|
|
let work = new Worker("worker.js");
|
|
let channel = new MessageChannel();
|
|
|
|
function finishTest() {
|
|
println("DONE");
|
|
work.onmessage = null;
|
|
work.terminate();
|
|
channel.port2.onmessage = null;
|
|
done();
|
|
}
|
|
let count = 0;
|
|
work.onmessage = (evt) => {
|
|
println("Got message from worker: " + JSON.stringify(evt.data));
|
|
count++;
|
|
if (count === 3) {
|
|
finishTest();
|
|
}
|
|
};
|
|
channel.port2.onmessage = (evt) => {
|
|
println("Got message from port: " + JSON.stringify(evt.data));
|
|
channel.port2.postMessage("Hello from port2");
|
|
count++;
|
|
if (count === 3) {
|
|
finishTest();
|
|
}
|
|
};
|
|
work.postMessage({ port: channel.port1 }, { transfer : [channel.port1]});
|
|
});
|
|
</script>
|