| 1 |
|
| 2 |
import * as std from "std"; |
| 3 |
import * as os from "os"; |
| 4 |
|
| 5 |
function assert(actual, expected, message) { |
| 6 |
if (arguments.length == 1) |
| 7 |
expected = true; |
| 8 |
|
| 9 |
if (actual === expected) |
| 10 |
return; |
| 11 |
|
| 12 |
if (actual !== null && expected !== null |
| 13 |
&& typeof actual == 'object' && typeof expected == 'object' |
| 14 |
&& actual.toString() === expected.toString()) |
| 15 |
return; |
| 16 |
|
| 17 |
throw Error("assertion failed: got |" + actual + "|" + |
| 18 |
", expected |" + expected + "|" + |
| 19 |
(message ? " (" + message + ")" : "")); |
| 20 |
} |
| 21 |
|
| 22 |
var worker; |
| 23 |
|
| 24 |
function test_worker() |
| 25 |
{ |
| 26 |
var counter; |
| 27 |
|
| 28 |
worker = new os.Worker("./test_worker_module.js"); |
| 29 |
|
| 30 |
counter = 0; |
| 31 |
worker.onmessage = function (e) { |
| 32 |
var ev = e.data; |
| 33 |
|
| 34 |
switch(ev.type) { |
| 35 |
case "num": |
| 36 |
assert(ev.num, counter); |
| 37 |
counter++; |
| 38 |
if (counter == 10) { |
| 39 |
|
| 40 |
let sab = new SharedArrayBuffer(10); |
| 41 |
let buf = new Uint8Array(sab); |
| 42 |
worker.postMessage({ type: "sab", buf: buf }); |
| 43 |
} |
| 44 |
break; |
| 45 |
case "sab_done": |
| 46 |
{ |
| 47 |
let buf = ev.buf; |
| 48 |
|
| 49 |
assert(buf[2], 10); |
| 50 |
worker.postMessage({ type: "abort" }); |
| 51 |
} |
| 52 |
break; |
| 53 |
case "done": |
| 54 |
|
| 55 |
worker.onmessage = null; |
| 56 |
break; |
| 57 |
} |
| 58 |
}; |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
test_worker(); |