File: exec.tjs

package info (click to toggle)
node-webassemblyjs 1.11.0%2Bdfsg%2B~cs10.10.16-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 8,040 kB
  • sloc: javascript: 28,630; makefile: 84; sh: 42; ansic: 16
file content (38 lines) | stat: -rw-r--r-- 1,137 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const PAGE_SIZE = Math.pow(2, 16);
const I32_SIZE = 4;

it("should load from the given location", () => {
  return WebAssembly.instantiate(wasmmodule).then(m => {
    const i32 = new Uint32Array(m.instance.exports.memory.buffer);

    // store a number
    i32[12 / I32_SIZE] = 45;
    assert.equal(m.instance.exports.load(12), 45);
  });
});

it("should throw for memory out of bounds", () => {
  return WebAssembly.instantiate(wasmmodule).then(m => {
    const i32 = new Uint32Array(m.instance.exports.memory.buffer);

    // upper bound
    i32[PAGE_SIZE / I32_SIZE - 1] = 45;
    assert.equal(m.instance.exports.load(PAGE_SIZE - I32_SIZE), 45);

    assert.throws(() => {
      // upper bound exceeded
      m.instance.exports.load(PAGE_SIZE + 4);
    }, "memory access out of bounds");
  });
});

it("should support offsets", () => {
  return WebAssembly.instantiate(wasmmodule).then(m => {
    const i32 = new Uint32Array(m.instance.exports.memory.buffer);

    // load a number with an offset
    const offset = 4;
    i32[(4 + offset) / I32_SIZE - 1] = 45;
    assert.equal(m.instance.exports.load_with_offset(4), 45);
  });
});