tor-browser

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

disasm.js (1582B)


      1 // |jit-test| skip-if: !hasDisassembler()
      2 
      3 // Test that the disassembler is reasonably sane.
      4 
      5 var mod = new WebAssembly.Module(wasmTextToBinary(`
      6 (module
      7   (func $hum (import "m" "hum") (param i32) (result f64))
      8   (memory 1)
      9   (func $hi (export "f") (param i32) (param i32) (param i32) (param i32) (param i32) (param i32) (param i32) (result i32)
     10     (i32.add (i32.load (local.get 5)) (i32.load (local.get 6))))
     11   (func $ho (param i32) (result i32) (i32.const 37))
     12 )
     13 `));
     14 
     15 // The following capture the disassembly as a string.  We can't really check
     16 // that no other output is produced.
     17 
     18 var s = wasmDis(mod, {tier:'best', asString:true});
     19 assertEq(typeof s, "string")
     20 assertEq(s.match(/Kind = Function/g).length, 3)
     21 
     22 var ins = new WebAssembly.Instance(mod, {m:{hum:(x) => x+0.5}});
     23 var s = wasmDis(ins, {tier:'best', asString:true});
     24 assertEq(typeof s, "string")
     25 assertEq(s.match(/Kind = Function/g).length, 3)
     26 
     27 var s = wasmDis(ins.exports.f, {tier:'best', asString:true})
     28 assertEq(typeof s, "string")
     29 
     30 var s = wasmDis(ins, {asString:true, kinds:"InterpEntry,ImportInterpExit,Function"})
     31 assertEq(typeof s, "string")
     32 assertEq(s.match(/Kind = Function/g).length, 3)
     33 assertEq(s.match(/Kind = InterpEntry/g).length, 1)
     34 assertEq(s.match(/Kind = ImportInterpExit/g).length, 1)
     35 assertEq(s.match(/name = hi/g).length, 2)
     36 assertEq(s.match(/name = ho/g).length, 1)
     37 assertEq(s.match(/name = hum/g).length, 2)
     38 
     39 // This one prints to stderr, we can't check the output but we can check that a
     40 // string is not returned.
     41 
     42 var s = wasmDis(ins, {tier:'best'})
     43 assertEq(typeof s, "undefined")