summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/wasm/memory64/memory-fill.js
blob: 500247d13c1624077ef88a2067e3cea2cc5c79c2 (plain)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// |jit-test| allow-oom; skip-if: !canRunHugeMemoryTests()

// Also see memory-fill-shared.js

try {
    var ins = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary(`
(module
  (memory (export "mem") i64 65537)
  (func (export "f") (param $p i64) (param $c i32) (param $n i64)
    (memory.fill (local.get $p) (local.get $c) (local.get $n))))`)));
} catch (e) {
    if (e instanceof WebAssembly.RuntimeError && String(e).match(/too many memory pages/)) {
        quit(0);
    }
    throw e;
}

var mem = new Uint8Array(ins.exports.mem.buffer);

// Fill above 4GB
doit(mem, 0x100000100, 37, 14);

// Fill OOB above 4GB
assertErrorMessage(() => ins.exports.f(0x10000FFFFn, 66, 14n),
                   WebAssembly.RuntimeError,
                   /out of bounds/);
assertEq(mem[0x10000FFFF], 0);
assertEq(mem[mem.length-1], 0);

// Fill across 4GB
doit(mem, 0x100000000 - 16, 42, 32);

// Fill more than 4GB...
ins.exports.f(0n, 86, 65536n*65537n);
assertEq(mem[mem.length-1], 86);
assertEq(mem[0], 86);

// Fill OOB more than 4GB
assertErrorMessage(() => ins.exports.f(1n, 75, 65536n*65537n),
                   WebAssembly.RuntimeError,
                   /out of bounds/);
assertEq(mem[1], 86);
assertEq(mem[mem.length-1], 86);

function doit(mem, addr, c, n) {
    assertEq(mem[addr-1], 0);
    assertEq(mem[addr], 0);
    assertEq(mem[addr + n - 1], 0);
    assertEq(mem[addr + n], 0);
    ins.exports.f(BigInt(addr), c, BigInt(n));
    assertEq(mem[addr-1], 0);
    assertEq(mem[addr], c);
    assertEq(mem[addr + n - 1], c);
    assertEq(mem[addr + n], 0);
}