tor-browser

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

gc.js (1144B)


      1 // Test if we can trace roots on the alternative stack.
      2 
      3 let i = 0;
      4 function js_import() {
      5  return Promise.resolve({i: ++i});
      6 };
      7 let wasm_js_import = new WebAssembly.Suspending(js_import);
      8 
      9 let wasm_gc_import = new WebAssembly.Suspending(
     10    async () => { gc(); }
     11 );
     12 
     13 var ins = wasmEvalText(`(module
     14  (import "m" "import" (func (result externref)))
     15  (import "m" "gc" (func))
     16  (import "m" "conv" (func (param externref) (result i32)))
     17 
     18    (global (export "g") (mut i32) (i32.const 0))
     19 
     20    (func (export "test")
     21      (local i32)
     22      i32.const 5
     23      local.set 0
     24      loop
     25        call 0
     26        call 1
     27        call 2
     28        global.get 0
     29        i32.add
     30        global.set 0
     31        local.get 0
     32        i32.const 1
     33        i32.sub
     34        local.tee 0
     35        br_if 0
     36      end
     37    )
     38 
     39 )`, {
     40  m: {
     41    import: wasm_js_import,
     42    gc: wasm_gc_import,
     43    conv: ({i}) => i,
     44  },
     45 });
     46 
     47 
     48 let wrapped_export = WebAssembly.promising(ins.exports.test);
     49 
     50 let export_promise = wrapped_export();
     51 assertEq(0, ins.exports.g.value);
     52 assertEq(true, export_promise instanceof Promise);
     53 export_promise.then(() =>
     54  assertEq(15, ins.exports.g.value)
     55 );