bug1684861.js (1697B)
1 const oob = /index out of bounds/; 2 const unaligned = /unaligned memory access/; 3 const RuntimeError = WebAssembly.RuntimeError; 4 5 // Test memory.atomic.notify unaligned access. 6 const module = new WebAssembly.Module(wasmTextToBinary(`(module 7 (type (;0;) (func)) 8 (func $main (type 0) 9 i32.const -64 10 i32.const -63 11 memory.atomic.notify offset=1 12 unreachable) 13 (memory (;0;) 4 4) 14 (export "main" (func $main)))`)); 15 16 const instance = new WebAssembly.Instance(module); 17 assertErrorMessage(() => instance.exports.main(), RuntimeError, unaligned); 18 19 // Test memory.atomic.notify oob access. 20 const module2 = new WebAssembly.Module(wasmTextToBinary(`(module 21 (type (;0;) (func)) 22 (func $main (type 0) 23 i32.const -64 24 i32.const -63 25 memory.atomic.notify offset=65536 26 unreachable) 27 (memory (;0;) 4 4) 28 (export "main" (func $main)))`)); 29 30 const instance2 = new WebAssembly.Instance(module2); 31 assertErrorMessage(() => instance2.exports.main(), RuntimeError, oob); 32 33 // Test memory.atomic.wait32 and .wait64 unaligned access. 34 const module3 = new WebAssembly.Module(wasmTextToBinary(`(module 35 (type (;0;) (func)) 36 (func $wait32 (type 0) 37 i32.const -64 38 i32.const 42 39 i64.const 0 40 memory.atomic.wait32 offset=1 41 unreachable) 42 (func $wait64 (type 0) 43 i32.const -64 44 i64.const 43 45 i64.const 0 46 memory.atomic.wait64 offset=3 47 unreachable) 48 (memory (;0;) 4 4 shared) 49 (export "wait32" (func $wait32)) 50 (export "wait64" (func $wait64)))`)); 51 52 const instance3 = new WebAssembly.Instance(module3); 53 assertErrorMessage(() => instance3.exports.wait32(), RuntimeError, unaligned); 54 assertErrorMessage(() => instance3.exports.wait64(), RuntimeError, unaligned);