summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/lib/wasm-testharness.js
blob: 8f8ab6e5e94f03faf2c3b0c23817de0338e2a073 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
if (!wasmIsSupported())
    quit();

function test(func, description) {
    let maybeErr;
    try {
        func();
    } catch(e) {
        maybeErr = e;
    }

    if (typeof maybeErr !== 'undefined') {
        throw new Error(`${description}: FAIL.
${maybeErr}
${maybeErr.stack}`);
    } else {
        print(`${description}: PASS.`);
    }
}

function promise_test(func, description) {
    let maybeError = null;
    func()
    .then(_ => {
        print(`${description}: PASS.`);
    })
    .catch(err => {
        print(`${description}: FAIL.
${err}`);
        maybeError = err;
    });
    drainJobQueue();
    if (maybeError)
        throw maybeError;
}

let assert_equals = assertEq;
let assert_true = (x, errMsg) => { assertEq(x, true, errMsg || ''); }
let assert_false = (x, errMsg) => { assertEq(x, false, errMsg || ''); }

function assert_unreached(description) {
    throw new Error(`unreachable:\n${description}`);
}

function assert_not_equals(actual, not_expected, description) {
    let caught = false;
    try {
        assertEq(actual, not_expected, description);
    } catch (e) {
        caught = true;
    };
    assertEq(caught, true, "assert_not_equals failed: " + description);
}

// Make it possible to run wasm spec tests with --fuzzing-safe
if (typeof console == 'undefined') {
    console = { log() {} }
}