tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

native-trampoline-3.js (852B)


      1 // |jit-test| skip-if: !wasmIsSupported()
      2 
      3 // Use a Wasm module to get the following stack frames:
      4 //
      5 //  .. => array sort trampoline => wasmfunc comparator (Wasm) => comparator (JS)
      6 
      7 let binary = wasmTextToBinary(`
      8 (module
      9  (import "" "comparator" (func $comparator (param i32) (param i32) (result i32)))
     10  (func $wasmfunc
     11    (export "wasmfunc")
     12    (param $x i32)
     13    (param $y i32)
     14    (result i32)
     15    (return (call $comparator (local.get $x) (local.get $y)))
     16  )
     17 )`);
     18 let mod = new WebAssembly.Module(binary);
     19 let instance = new WebAssembly.Instance(mod, {"": {comparator}});
     20 
     21 function comparator(x, y) {
     22  readGeckoProfilingStack();
     23  return y - x;
     24 }
     25 
     26 enableGeckoProfilingWithSlowAssertions();
     27 
     28 for (let i = 0; i < 20; i++) {
     29  let arr = [3, 1, 2, -1, 0, 4];
     30  arr.sort(instance.exports.wasmfunc);
     31  assertEq(arr.toString(), "4,3,2,1,0,-1");
     32 }