summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/wasm/function-references/binary.js
blob: 91cf807dc474113fc291ad3bd3789488153a11f9 (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
// |jit-test| skip-if: !wasmFunctionReferencesEnabled()

load(libdir + "wasm-binary.js");

const v2vSig = {args:[], ret:VoidCode};
const v2vSigSection = sigSection([v2vSig]);

function checkInvalid(binary, errorMessage) {
    assertErrorMessage(() => new WebAssembly.Module(binary),
        WebAssembly.CompileError,
        errorMessage);
}

// The immediate of ref.null is a heap type, not a general reference type

const invalidRefNullHeapBody = moduleWithSections([
    v2vSigSection,
    declSection([0]),
    bodySection([
        funcBody({locals:[], body:[
            RefNullCode,
            OptRefCode,
            AnyFuncCode,
            DropCode,
        ]})
    ])
]);
checkInvalid(invalidRefNullHeapBody, /invalid heap type/);

const invalidRefNullHeapElem = moduleWithSections([
    generalElemSection([
        {
            flag: PassiveElemExpr,
            typeCode: AnyFuncCode,
            elems: [
                [RefNullCode, OptRefCode, AnyFuncCode, EndCode]
            ]
        }
    ])
]);
checkInvalid(invalidRefNullHeapElem, /invalid heap type/);

const invalidRefNullHeapGlobal = moduleWithSections([
    globalSection([
        {
            valType: AnyFuncCode,
            flag: 0,
            initExpr: [RefNullCode, OptRefCode, AnyFuncCode, EndCode]
        }
    ])
]);
checkInvalid(invalidRefNullHeapGlobal, /invalid heap type/);