Debian Codegraph @

js/src/jit-test/tests/wasm/memory64/memory-fill-shared.js

raw
1 // |jit-test| heavy; allow-oom; slow; skip-if: !canRunHugeMemoryTests()
2
3 // This is just like memory-fill.js, but it is marked slow because the
4 // C++-UB-safe operations we use for out-of-line fills on shared memory are slow
5 // and the >4GB fill takes a long time.
6
7 try {
8 var ins = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary(`
9 (module
10 (memory (export "mem") i64 65537 65537 shared)
11 (func (export "f") (param $p i64) (param $c i32) (param $n i64)
12 (memory.fill (local.get $p) (local.get $c) (local.get $n))))`)));
13 } catch (e) {
14 if (e instanceof WebAssembly.RuntimeError && String(e).match(/too many memory pages/)) {
15 quit(0);
16 }
17 throw e;
18 }
19
20 var mem = new Uint8Array(ins.exports.mem.buffer);
21
22 // Fill above 4GB
23 doit(mem, 0x100000100, 37, 14);
24
25 // Fill OOB above 4GB
26 assertErrorMessage(() => ins.exports.f(0x10000FFFFn, 66, 14n),
27 WebAssembly.RuntimeError,
28 /out of bounds/);
29 assertEq(mem[0x10000FFFF], 0);
30 assertEq(mem[mem.length-1], 0);
31
32 // Fill across 4GB
33 doit(mem, 0x100000000 - 16, 42, 32);
34
35 // Fill more than 4GB...
36 ins.exports.f(0n, 86, 65536n*65537n);
37 assertEq(mem[mem.length-1], 86);
38 assertEq(mem[0], 86);
39
40 // Fill OOB more than 4GB
41 assertErrorMessage(() => ins.exports.f(1n, 75, 65536n*65537n),
42 WebAssembly.RuntimeError,
43 /out of bounds/);
44 assertEq(mem[1], 86);
45 assertEq(mem[mem.length-1], 86);
46
47 function doit(mem, addr, c, n) {
48 assertEq(mem[addr-1], 0);
49 assertEq(mem[addr], 0);
50 assertEq(mem[addr + n - 1], 0);
51 assertEq(mem[addr + n], 0);
52 ins.exports.f(BigInt(addr), c, BigInt(n));
53 assertEq(mem[addr-1], 0);
54 assertEq(mem[addr], c);
55 assertEq(mem[addr + n - 1], c);
56 assertEq(mem[addr + n], 0);
57 }
58