tor-browser

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

wasm-09.js (1468B)


      1 // |jit-test| test-also=--wasm-compiler=optimizing; skip-if: !wasmDebuggingEnabled()
      2 // Tests debugEnabled state of wasm when allowUnobservedWasm == true.
      3 
      4 load(libdir + "asserts.js");
      5 
      6 // Checking that there are no offsets are present in a wasm instance script for
      7 // which debug mode was not enabled.
      8 function getWasmScriptWithoutAllowUnobservedWasm(wast) {
      9    var sandbox = newGlobal({newCompartment: true});
     10    var dbg = new Debugger();
     11    dbg.allowUnobservedWasm = true;
     12    dbg.addDebuggee(sandbox);
     13    sandbox.eval(`
     14        var wasm = wasmTextToBinary('${wast}');
     15        var m = new WebAssembly.Instance(new WebAssembly.Module(wasm));
     16    `);
     17    // Attaching after wasm instance is created.
     18    var wasmScript = dbg.findScripts().filter(s => s.format == 'wasm')[0];
     19    return wasmScript;
     20 }
     21 
     22 var wasmScript1 = getWasmScriptWithoutAllowUnobservedWasm('(module (func (nop)))');
     23 var wasmLines1 = wasmScript1.source.text.split('\n');
     24 assertEq(wasmScript1.startLine, 1);
     25 assertEq(wasmScript1.lineCount, 0);
     26 assertEq(wasmLines1.every((l, n) => wasmScript1.getLineOffsets(n + 1).length == 0), true);
     27 
     28 // Checking that we must not resolve any location for any offset in a wasm
     29 // instance which debug mode was not enabled.
     30 var wasmScript2 = getWasmScriptWithoutAllowUnobservedWasm('(module (func (nop)))');
     31 for (var i = wasmTextToBinary('(module (func (nop)))').length - 1; i >= 0; i--)
     32    assertThrowsInstanceOf(() => wasmScript2.getOffsetLocation(i), Error);