summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/wasm/tail-calls/litmus17.js
blob: 025c02530528f6d6f7bc9b0dc9d48b49000e3b16 (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
// |jit-test| skip-if: !wasmTailCallsEnabled()

// Test that unwinding will find the right instance in the middle of a tail call
// chain.  This test is mostly useful on the simulators, as they will walk the
// stack, looking for the innermost instance, on every memory reference.  The
// logic of this test is that the setup intra-module tail call in mod2 will need
// to be recorded as possibly-inter-module because the subsequent inter-module
// call replaces the activation with one that is actually inter-module.

let ins1 = wasmEvalText(`
(module
  (memory (export "mem") 1 1)
  (func (export "memref") (result i32)
    (i32.load (i32.const 0))))`);

let ins2 = wasmEvalText(`
(module
  (import "mod1" "memref" (func $memref (result i32)))

  (func (export "run") (result i32)
    (return_call $g))

  (func $g (result i32)
    (return_call $memref)))`, {mod1: ins1.exports});

(new Int32Array(ins1.exports.mem.buffer))[0] = 1337;
assertEq(ins2.exports.run(), 1337);