tor-browser

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

wasm-01.js (1272B)


      1 // |jit-test| skip-if: !wasmDebuggingEnabled()
      2 
      3 // Tests that wasm module scripts are available via findScripts.
      4 
      5 var g = newGlobal({newCompartment: true});
      6 g.eval(`o = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary('(module (func) (export "" (func 0)))')));`);
      7 
      8 function isWasm(script) { return script.format === "wasm"; }
      9 
     10 var dbg = new Debugger(g);
     11 var foundScripts1 = dbg.findScripts().filter(isWasm);
     12 assertEq(foundScripts1.length, 1);
     13 var found = foundScripts1[0];
     14 
     15 // Add another module, we should be able to find it via findScripts.
     16 g.eval(`o2 = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary('(module (func) (export "a" (func 0)))')));`);
     17 var foundScripts2 = dbg.findScripts().filter(isWasm);
     18 assertEq(foundScripts2.length, 2);
     19 
     20 // The first module should be in the list as wrapping the same wasm module
     21 // twice gets the same Debugger.Script.
     22 assertEq(foundScripts2.indexOf(found) !== -1, true);
     23 
     24 // The two modules are distinct.
     25 assertEq(foundScripts2[0] !== foundScripts2[1], true);
     26 
     27 // We should be able to find the same script via its source.
     28 for (var ws of foundScripts2) {
     29  var scriptsFromSource = dbg.findScripts({ source: ws.source });
     30  assertEq(scriptsFromSource.length, 1);
     31  assertEq(scriptsFromSource[0], ws);
     32 }