Debian Codegraph @

js/src/jit-test/tests/wasm/memory64/data-active.js

raw
1 // |jit-test| heavy; allow-oom; skip-if: !canRunHugeMemoryTests()
2
3 function testIt(s, addr) {
4 try {
5 var ins = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary(`
6 (module
7 (memory (export "mem") i64 65537)
8 (data (i64.const ${addr}) "${s}"))`)));
9 } catch (e) {
10 if (e instanceof WebAssembly.RuntimeError && String(e).match(/too many memory pages/)) {
11 return;
12 }
13 throw e;
14 }
15 var mem = new Uint8Array(ins.exports.mem.buffer);
16 assertEq(String.fromCodePoint(...mem.slice(addr, addr + s.length)), s)
17 }
18
19 // Test that an active data segment targeting the area above 4GB works as expected
20 testIt("hello, world!", 0x100000020);
21
22 // Ditto, but crosses the 4GB boundary
23 var s = "supercalifragilisticexpialidocious";
24 testIt(s, 0x100000000 - Math.floor(s.length / 2));
25
26 // This is OOB above the 4GB boundary - throws OOB during instantiation.
27 // But can also throw for OOM when trying to create the memory.
28 assertErrorMessage(() => new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary(`
29 (module
30 (memory (export "mem") i64 65537)
31 (data (i64.const ${65536*65537-10}) "supercalifragilisticexpialidocious"))`))),
32 WebAssembly.RuntimeError,
33 /(out of bounds)|(too many memory pages)/);
34