Debian Codegraph @

js/src/jit-test/tests/debug/wasm-onExceptionUnwind-gc.js

raw
1 // |jit-test| skip-if: !wasmDebuggingEnabled()
2
3 var sandbox = newGlobal({newCompartment: true});
4 var dbg = new Debugger(sandbox);
5 var counter = 0;
6 dbg.onExceptionUnwind = (frame, value) => {
7 if (frame.type !== "wasmcall")
8 return;
9 if (++counter != 2)
10 return;
11 gc();
12 };
13
14 sandbox.innerCode = wasmTextToBinary(`(module
15 (import "imports" "tbl" (table 1 funcref))
16 (import "imports" "setNull" (func $setNull))
17 (func $trap
18 call $setNull
19 unreachable
20 )
21 (elem (i32.const 0) $trap)
22 )`);
23 sandbox.outerCode = wasmTextToBinary(`(module
24 (import "imports" "tbl" (table 1 funcref))
25 (type $v2v (func))
26 (func (export "run")
27 i32.const 0
28 call_indirect (type $v2v)
29 )
30 )`);
31
32 sandbox.eval(`
33 (function() {
34
35 var tbl = new WebAssembly.Table({initial:1, element:"funcref"});
36 function setNull() { tbl.set(0, null) }
37 new WebAssembly.Instance(new WebAssembly.Module(innerCode), {imports:{tbl,setNull}});
38 var outer = new WebAssembly.Instance(new WebAssembly.Module(outerCode), {imports:{tbl}});
39 var caught;
40 try {
41 outer.exports.run();
42 } catch (e) {
43 caught = e;
44 }
45 assertEq(caught instanceof WebAssembly.RuntimeError, true);
46
47 })();
48 `);