summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/wasm/exceptions/events.js
blob: bc8a37531c689c24d10a2caa531e7c165b956448 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// Tests for event section support

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

function wasmEval(code, imports) {
  new WebAssembly.Instance(new WebAssembly.Module(code), imports).exports;
}

function wasmError(code, errorType, regexp) {
  assertErrorMessage(() => wasmEval(code, {}), errorType, regexp);
}

const emptyType = { args: [], ret: VoidCode };
const badExnType = { args: [], ret: I32Code };

wasmEvalText(`
  (module
    (type (func (param i32)))
    (event $exn (type 0)))
`);

wasmError(
  moduleWithSections([
    sigSection([emptyType]),
    memorySection(0),
    { name: eventId, body: [] },
  ]),
  WebAssembly.CompileError,
  /expected number of events/
);

wasmError(
  moduleWithSections([
    sigSection([emptyType]),
    memorySection(0),
    { name: eventId, body: [1, 1] },
  ]),
  WebAssembly.CompileError,
  /illegal event kind/
);

wasmError(
  moduleWithSections([
    sigSection([emptyType]),
    memorySection(0),
    { name: eventId, body: [1, 0] },
  ]),
  WebAssembly.CompileError,
  /expected function index in event/
);

wasmEval(
  moduleWithSections([
    sigSection([emptyType]),
    memorySection(0),
    eventSection([{ type: 0 }]),
  ])
);

wasmError(
  moduleWithSections([
    sigSection([badExnType]),
    memorySection(0),
    eventSection([{ type: 0 }]),
  ]),
  WebAssembly.CompileError,
  /exception function types must not return anything/
);

wasmError(
  moduleWithSections([
    sigSection([emptyType]),
    memorySection(0),
    eventSection([{ type: 1 }]),
  ]),
  WebAssembly.CompileError,
  /function type index in event out of bounds/
);

wasmError(
  moduleWithSections([
    sigSection([emptyType]),
    eventSection([{ type: 0 }]),
    memorySection(0),
  ]),
  WebAssembly.CompileError,
  /expected custom section/
);

(() => {
  const body = [1];
  body.push(...string("mod"));
  body.push(...string("exn"));
  body.push(...varU32(EventCode));

  wasmError(
    moduleWithSections([
      sigSection([emptyType]),
      { name: importId, body: body },
    ]),
    WebAssembly.CompileError,
    /expected event kind/
  );

  body.push(...varU32(0));
  wasmError(
    moduleWithSections([
      sigSection([emptyType]),
      { name: importId, body: body },
    ]),
    WebAssembly.CompileError,
    /expected function index in event/
  );

  body.push(...varU32(1));
  wasmError(
    moduleWithSections([
      sigSection([emptyType]),
      { name: importId, body: body },
    ]),
    WebAssembly.CompileError,
    /function type index in event out of bounds/
  );
})();

wasmEval(
  moduleWithSections([
    sigSection([emptyType]),
    memorySection(0),
    eventSection([{ type: 0 }]),
    exportSection([{ eventIndex: 0, name: "exn" }]),
  ])
);

wasmError(
  moduleWithSections([
    sigSection([emptyType]),
    memorySection(0),
    eventSection([{ type: 0 }]),
    exportSection([{ eventIndex: 1, name: "exn" }]),
  ]),
  WebAssembly.CompileError,
  /exported event index out of bounds/
);

(() => {
  const body = [1];
  body.push(...string("exn"));
  body.push(...varU32(EventCode));
  wasmError(
    moduleWithSections([
      sigSection([emptyType]),
      memorySection(0),
      eventSection([{ type: 0 }]),
      { name: exportId, body: body },
    ]),
    WebAssembly.CompileError,
    /expected event index/
  );
})();