tor-browser

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

js-api.js (1896B)


      1 // |jit-test| skip-if: !wasmCustomPageSizesEnabled()
      2 
      3 load(libdir + "wasm-binary.js");
      4 
      5 {
      6  let instance = wasmEvalText(`(module
      7      (memory (export "mem") 0 1 (pagesize 1))
      8    )
      9  `);
     10 
     11  assertErrorMessage(
     12    () => wasmEvalText(`(module
     13        (memory (import "m" "mem") 0 1 (pagesize 65536))
     14      )
     15    `, { m: { mem: instance.exports.mem } }),
     16    WebAssembly.LinkError,
     17    /imported memory with incompatible page size/
     18  )
     19 }
     20 
     21 // Test against explicit page size in the binary encoding.
     22 {
     23  let instance = wasmEvalBinary(
     24    moduleWithSections([ {name:memoryId, body:[0x01, 0x08, 0x00, 0x10]},
     25                         exportSection([ {name: "mem", memIndex: 0} ]) ])
     26  );
     27 
     28  assertErrorMessage(
     29    () => wasmEvalText(`(module
     30        (memory (import "m" "mem") 0 1 (pagesize 1))
     31      )
     32    `, { m: { mem: instance.exports.mem } }),
     33    WebAssembly.LinkError,
     34    /imported memory with incompatible page size/
     35  )
     36 }
     37 
     38 // Test against default page size in the binary encoding.
     39 {
     40  let instance = wasmEvalBinary(
     41    moduleWithSections([ {name:memoryId, body:[0x01, 0x01, 0x00, 0x01]},
     42                         exportSection([ {name: "mem", memIndex: 0} ]) ])
     43  );
     44 
     45  assertErrorMessage(
     46    () => wasmEvalText(`(module
     47        (memory (import "m" "mem") 0 1 (pagesize 1))
     48      )
     49    `, { m: { mem: instance.exports.mem } }),
     50    WebAssembly.LinkError,
     51    /imported memory with incompatible page size/
     52  )
     53 }
     54 
     55 // Valid cases
     56 {
     57  let instance = wasmEvalText(`(module
     58      (memory (export "mem") 0 1 (pagesize 1))
     59    )
     60  `);
     61 
     62  wasmEvalText(`(module
     63        (memory (import "m" "mem") 0 1 (pagesize 1))
     64      )
     65    `, { m: { mem: instance.exports.mem } });
     66 }
     67 
     68 {
     69  let instance = wasmEvalText(`(module
     70      (memory (export "mem") 0 1)
     71    )
     72  `);
     73 
     74  wasmEvalText(`(module
     75        (memory (import "m" "mem") 0 1 (pagesize 65536))
     76      )
     77    `, { m: { mem: instance.exports.mem } });
     78 }