summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/profiler/native-trampoline-3.js
blob: 16fe5470514fa0f5763d6613c1be4b09334623aa (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
// |jit-test| skip-if: !wasmIsSupported()

// Use a Wasm module to get the following stack frames:
//
//  .. => array sort trampoline => wasmfunc comparator (Wasm) => comparator (JS)

let binary = wasmTextToBinary(`
(module
  (import "" "comparator" (func $comparator (param i32) (param i32) (result i32)))
  (func $wasmfunc
    (export "wasmfunc")
    (param $x i32)
    (param $y i32)
    (result i32)
    (return (call $comparator (local.get $x) (local.get $y)))
  )
)`);
let mod = new WebAssembly.Module(binary);
let instance = new WebAssembly.Instance(mod, {"": {comparator}});

function comparator(x, y) {
  readGeckoProfilingStack();
  return y - x;
}

enableGeckoProfilingWithSlowAssertions();

for (let i = 0; i < 20; i++) {
  let arr = [3, 1, 2, -1, 0, 4];
  arr.sort(instance.exports.wasmfunc);
  assertEq(arr.toString(), "4,3,2,1,0,-1");
}