Sha256: 4badd58ccc6f964e3a3b0876f37126b0828baf2e23198d6f2d8a21150441f681

Contents?: true

Size: 1.57 KB

Versions: 50

Compression:

Stored size: 1.57 KB

Contents

/* os.Worker API test */
import * as std from "std";
import * as os from "os";

function assert(actual, expected, message) {
    if (arguments.length == 1)
        expected = true;

    if (actual === expected)
        return;

    if (actual !== null && expected !== null
    &&  typeof actual == 'object' && typeof expected == 'object'
    &&  actual.toString() === expected.toString())
        return;

    throw Error("assertion failed: got |" + actual + "|" +
                ", expected |" + expected + "|" +
                (message ? " (" + message + ")" : ""));
}

var worker;

function test_worker()
{
    var counter;

    worker = new os.Worker("./test_worker_module.js");

    counter = 0;
    worker.onmessage = function (e) {
        var ev = e.data;
//        print("recv", JSON.stringify(ev));
        switch(ev.type) {
        case "num":
            assert(ev.num, counter);
            counter++;
            if (counter == 10) {
                /* test SharedArrayBuffer modification */
                let sab = new SharedArrayBuffer(10);
                let buf = new Uint8Array(sab);
                worker.postMessage({ type: "sab", buf: buf });
            }
            break;
        case "sab_done":
            {
                let buf = ev.buf;
                /* check that the SharedArrayBuffer was modified */
                assert(buf[2], 10);
                worker.postMessage({ type: "abort" });
            }
            break;
        case "done":
            /* terminate */
            worker.onmessage = null;
            break;
        }
    };
}


test_worker();

Version data entries

50 entries across 49 versions & 6 rubygems

Version Path
freespeech-1.0.88 ./other/experimental_code/quickjs/tests/test_worker.js
elonmusk-1.0.88 ./other/experimental_code/quickjs/tests/test_worker.js
politics-1.0.88 ./other/experimental_code/quickjs/tests/test_worker.js
democracy-1.0.86 ./other/experimental_code/quickjs/tests/test_worker.js
politics-1.0.82 ./other/experimental_code/quickjs/tests/test_worker.js
freespeech-1.0.82 ./other/experimental_code/quickjs/tests/test_worker.js
elonmusk-1.0.82 ./other/experimental_code/quickjs/tests/test_worker.js
ufos-1.0.82 ./other/experimental_code/quickjs/tests/test_worker.js
aliens-1.0.82 ./other/experimental_code/quickjs/tests/test_worker.js
politics-1.0.81 ./other/experimental_code/quickjs/tests/test_worker.js
ufos-1.0.79 ./other/experimental_code/quickjs/tests/test_worker.js
aliens-1.0.79 ./other/experimental_code/quickjs/tests/test_worker.js
freespeech-1.0.79 ./other/experimental_code/quickjs/tests/test_worker.js
elonmusk-1.0.79 ./other/experimental_code/quickjs/tests/test_worker.js
elonmusk-1.0.77 ./other/experimental_code/quickjs/tests/test_worker.js
ufos-1.0.77 ./other/experimental_code/quickjs/tests/test_worker.js
aliens-1.0.77 ./other/experimental_code/quickjs/tests/test_worker.js
freespeech-1.0.77 ./other/experimental_code/quickjs/tests/test_worker.js
elonmusk-1.0.72 ./other/experimental_code/quickjs/tests/test_worker.js
ufos-1.0.72 ./other/experimental_code/quickjs/tests/test_worker.js