ladybird/Tests/LibWeb/Text/input/Worker/Worker-echo.html
Andrew Kaster b10fee00eb LibWeb+WebWorker: Convert Workers to use MessagePorts for postMessage
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.
2023-12-25 12:09:11 +01:00

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>