tor-browser

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

test_wasm_source-01.js (2656B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 /* eslint-disable no-shadow, max-nested-callbacks */
      4 
      5 "use strict";
      6 
      7 /**
      8 * Verify if client can receive binary wasm
      9 */
     10 
     11 var gDebuggee;
     12 var gThreadFront;
     13 
     14 add_task(
     15  threadFrontTest(
     16    async ({ threadFront, debuggee }) => {
     17      gThreadFront = threadFront;
     18      gDebuggee = debuggee;
     19 
     20      await gThreadFront.reconfigure({
     21        observeAsmJS: true,
     22        observeWasm: true,
     23      });
     24 
     25      test_source();
     26    },
     27    { waitForFinish: true, doNotRunWorker: true }
     28  )
     29 );
     30 
     31 const EXPECTED_CONTENT = String.fromCharCode(
     32  0,
     33  97,
     34  115,
     35  109,
     36  1,
     37  0,
     38  0,
     39  0,
     40  1,
     41  132,
     42  128,
     43  128,
     44  128,
     45  0,
     46  1,
     47  96,
     48  0,
     49  0,
     50  3,
     51  130,
     52  128,
     53  128,
     54  128,
     55  0,
     56  1,
     57  0,
     58  6,
     59  129,
     60  128,
     61  128,
     62  128,
     63  0,
     64  0,
     65  7,
     66  133,
     67  128,
     68  128,
     69  128,
     70  0,
     71  1,
     72  1,
     73  102,
     74  0,
     75  0,
     76  10,
     77  136,
     78  128,
     79  128,
     80  128,
     81  0,
     82  1,
     83  130,
     84  128,
     85  128,
     86  128,
     87  0,
     88  0,
     89  11
     90 );
     91 
     92 function test_source() {
     93  gThreadFront.once("paused", function () {
     94    gThreadFront.getSources().then(function (response) {
     95      Assert.ok(!!response);
     96      Assert.ok(!!response.sources);
     97 
     98      const source = response.sources.filter(function (s) {
     99        return s.introductionType === "wasm";
    100      })[0];
    101 
    102      Assert.ok(!!source);
    103 
    104      const sourceFront = gThreadFront.source(source);
    105      sourceFront.source().then(function (response) {
    106        Assert.ok(!!response);
    107        Assert.ok(!!response.contentType);
    108        Assert.ok(response.contentType.includes("wasm"));
    109 
    110        const sourceContent = response.source;
    111        Assert.ok(!!sourceContent);
    112        Assert.equal(typeof sourceContent, "object");
    113        Assert.ok("binary" in sourceContent);
    114        Assert.equal(EXPECTED_CONTENT, sourceContent.binary);
    115 
    116        gThreadFront.resume().then(function () {
    117          threadFrontTestFinished();
    118        });
    119      });
    120    });
    121  });
    122 
    123  /* eslint-disable comma-spacing, max-len */
    124  gDebuggee.eval(
    125    "(" +
    126      function () {
    127        // WebAssembly bytecode was generated by running:
    128        // js -e 'print(wasmTextToBinary("(module(func(export \"f\")))"))'
    129        const m = new WebAssembly.Module(
    130          new Uint8Array([
    131            0, 97, 115, 109, 1, 0, 0, 0, 1, 132, 128, 128, 128, 0, 1, 96, 0, 0,
    132            3, 130, 128, 128, 128, 0, 1, 0, 6, 129, 128, 128, 128, 0, 0, 7, 133,
    133            128, 128, 128, 0, 1, 1, 102, 0, 0, 10, 136, 128, 128, 128, 0, 1,
    134            130, 128, 128, 128, 0, 0, 11,
    135          ])
    136        );
    137        const i = new WebAssembly.Instance(m);
    138        debugger;
    139        i.exports.f();
    140      } +
    141      ")()"
    142  );
    143 }