Debian Codegraph @

js/src/jit-test/tests/wasm/tail-calls/litmus12.js

raw
1 // Basically try to assert that the instance is restored properly when
2 // performing an import call. We do this by accessing the instance once we get
3 // out of the tail call chain.
4
5 // In this pure form, this test can't test for stack overflow as we can't do a loop of
6 // imported functions without return_call_indirect and a table.
7
8 // TODO: Probably add a loop here with an indirect call
9 // TODO: More ballast will make it more likely that stack smashing is detected
10
11 var insh = wasmEvalText(`
12 (module
13 (global $glob (export "glob") (mut i32) (i32.const 12345678))
14 (func $h (export "h") (param i32) (result i32)
15 (local.get 0)))`);
16
17 var insg = wasmEvalText(`
18 (module
19 (import "insh" "h" (func $h (param i32) (result i32)))
20 (global $glob (export "glob") (mut i32) (i32.const 24680246))
21 (func $g (export "g") (param i32) (result i32)
22 (return_call $h (local.get 0))))`, {insh:insh.exports});
23
24 var insf = wasmEvalText(`
25 (module
26 (import "insg" "g" (func $g (param i32) (result i32)))
27 (global $glob (export "glob") (mut i32) (i32.const 36903690))
28 (func $f (export "f") (param i32) (result i32)
29 (return_call $g (local.get 0))))`, {insg:insg.exports});
30
31 var start = wasmEvalText(`
32 (module
33 (import "insf" "f" (func $f (param i32) (result i32)))
34 (global $glob (export "glob") (mut i32) (i32.const 480480480))
35 (func (export "run") (param i32) (result i32)
36 (i32.add (call $f (local.get 0)) (global.get $glob))))`, {insf:insf.exports});
37
38 assertEq(start.exports.run(37), 480480480 + 37);
39