quickjs-done/tests/test_worker_module.js
Akos Kiss 6e2e68fd08 Fix termination in Worker test
Function names are case sensitive, `onMessage` is not the same as
`onmessage`.

Related to #98
2024-07-27 23:40:48 +02:00

32 lines
737 B
JavaScript

/* Worker code for test_worker.js */
import * as std from "std";
import * as os from "os";
var parent = os.Worker.parent;
function handle_msg(e) {
var ev = e.data;
// print("child_recv", JSON.stringify(ev));
switch(ev.type) {
case "abort":
parent.postMessage({ type: "done" });
parent.onmessage = null; /* terminate the worker */
break;
case "sab":
/* modify the SharedArrayBuffer */
ev.buf[2] = 10;
parent.postMessage({ type: "sab_done", buf: ev.buf });
break;
}
}
function worker_main() {
var i;
parent.onmessage = handle_msg;
for(i = 0; i < 10; i++) {
parent.postMessage({ type: "num", num: i });
}
}
worker_main();