1 // A try_table acts like a block label
3 let {test} = wasmEvalText(`(module
4 (func (export "test") (result i32)
15 // A try_table can have results
17 let {test} = wasmEvalText(`(module
18 (func (export "test") (result i32)
19 try_table (result i32)
28 // A try_table can have params
30 let {test} = wasmEvalText(`(module
31 (func (export "test") (result i32)
42 // Test try_table catching exceptions
44 let {test} = wasmEvalText(`(module
49 (table funcref (elem $throwA $throwB $throwC $doNothing))
65 (func (export "test") (param i32) (result i32)
66 block $handleA (result i32 exnref)
67 block $handleB (result i32 exnref)
68 block $handleUnknown (result exnref)
70 (catch_ref $A $handleA)
71 (catch_ref $B $handleB)
72 (catch_all_ref $handleUnknown)
74 (call_indirect (type $empty)
95 // Throwing A results in 1 from the payload from the catch
97 // Throwing B results in 2 from the payload from the catch
99 // Throwing C results in 3 from the constant in the catch_all
100 assertEq(test(2), 3);
101 // Not throwing anything gets -1 from the fallthrough
102 assertEq(test(3), -1);
105 // Test try_table catching exceptions without capturing the exnref
107 let {test} = wasmEvalText(`(module
112 (table funcref (elem $throwA $throwB $throwC $doNothing))
128 (func (export "test") (param i32) (result i32)
129 block $handleA (result i32)
130 block $handleB (result i32)
135 (catch_all $handleUnknown)
137 (call_indirect (type $empty)
155 // Throwing A results in 1 from the payload from the catch
156 assertEq(test(0), 1);
157 // Throwing B results in 2 from the payload from the catch
158 assertEq(test(1), 2);
159 // Throwing C results in 3 from the constant in the catch_all
160 assertEq(test(2), 3);
161 // Not throwing anything gets -1 from the fallthrough
162 assertEq(test(3), -1);
165 // Test try_table catching and rethrowing JS exceptions
167 let tag = new WebAssembly.Tag({parameters: []});
168 let exn = new WebAssembly.Exception(tag, []);
169 let values = [...WasmExternrefValues, exn];
170 function throwJS(value) {
173 let {test} = wasmEvalText(`(module
174 (import "" "tag" (tag $tag))
175 (import "" "throwJS" (func $throwJS (param externref)))
176 (func (export "test") (param externref)
177 try_table (result exnref) (catch_ref $tag 0) (catch_all_ref 0)
184 )`, {"": {tag, throwJS}}).exports;
186 for (let value of values) {
187 // TODO: A JS null value should become a non-null exnref that can be
188 // rethrown without a trap.
189 if (value === null) {
195 assertEq(true, false);
196 } catch (thrownValue) {
197 assertEq(thrownValue, value);