tor-browser

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

test_frameactor_wasm-01.js (1953B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /**
      7 * Verify that wasm frame(s) can be requested from the client.
      8 */
      9 
     10 add_task(
     11  threadFrontTest(async ({ threadFront, debuggee }) => {
     12    await threadFront.reconfigure({
     13      observeAsmJS: true,
     14      observeWasm: true,
     15    });
     16 
     17    await executeOnNextTickAndWaitForPause(
     18      () => evalCode(debuggee),
     19      threadFront
     20    );
     21 
     22    const frameResponse = await threadFront.getFrames(0, null);
     23 
     24    Assert.equal(frameResponse.frames.length, 4);
     25 
     26    const wasmFrame = frameResponse.frames[1];
     27    Assert.equal(wasmFrame.type, "wasmcall");
     28    Assert.equal(wasmFrame.this, undefined);
     29 
     30    const location = wasmFrame.where;
     31    const source = await getSourceById(threadFront, location.actor);
     32    Assert.equal(location.line > 0, true);
     33    Assert.equal(location.column > 0, true);
     34    Assert.equal(/^wasm:(?:[^:]*:)*?[0-9a-f]{16}$/.test(source.url), true);
     35 
     36    await threadFront.resume();
     37  })
     38 );
     39 
     40 function evalCode(debuggee) {
     41  /* eslint-disable comma-spacing, max-len */
     42  debuggee.eval(
     43    "(" +
     44      function () {
     45        // WebAssembly bytecode was generated by running:
     46        // js -e 'print(wasmTextToBinary("(module(import \"a\" \"b\")(func(export \"c\")call 0))"))'
     47        const m = new WebAssembly.Module(
     48          new Uint8Array([
     49            0, 97, 115, 109, 1, 0, 0, 0, 1, 132, 128, 128, 128, 0, 1, 96, 0, 0,
     50            2, 135, 128, 128, 128, 0, 1, 1, 97, 1, 98, 0, 0, 3, 130, 128, 128,
     51            128, 0, 1, 0, 6, 129, 128, 128, 128, 0, 0, 7, 133, 128, 128, 128, 0,
     52            1, 1, 99, 0, 1, 10, 138, 128, 128, 128, 0, 1, 132, 128, 128, 128, 0,
     53            0, 16, 0, 11,
     54          ])
     55        );
     56        const i = new WebAssembly.Instance(m, {
     57          a: {
     58            b: () => {
     59              debugger;
     60            },
     61          },
     62        });
     63        i.exports.c();
     64      } +
     65      ")()"
     66  );
     67 }