diff options
Diffstat (limited to 'js/src/jit-test/tests/wasm/memory-maximum-clamping.js')
-rw-r--r-- | js/src/jit-test/tests/wasm/memory-maximum-clamping.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/wasm/memory-maximum-clamping.js b/js/src/jit-test/tests/wasm/memory-maximum-clamping.js new file mode 100644 index 0000000000..dfd1d175d7 --- /dev/null +++ b/js/src/jit-test/tests/wasm/memory-maximum-clamping.js @@ -0,0 +1,32 @@ +const MemoryMaxValid = 65536; + +// Linking should fail if the imported memory has a higher maximum than required, +// however if we internally clamp maximum values to an implementation limit +// and use that for linking we may erroneously accept some modules. + +function testLinkFail(importMax, importedMax) { + assertErrorMessage(() => { + let importedMemory = new WebAssembly.Memory({ + initial: 0, + maximum: importedMax, + }); + wasmEvalText(`(module + (memory (import "" "") 0 ${importMax}) + )`, {"": {"": importedMemory}}); + }, WebAssembly.LinkError, /incompatible maximum/); +} + +testLinkFail(0, 1); +testLinkFail(MemoryMaxValid - 1, MemoryMaxValid); + +// The type reflection interface for WebAssembly.Memory should not report +// an internally clamped maximum. + +if ('type' in WebAssembly.Memory.prototype) { + let memory = new WebAssembly.Memory({ + initial: 0, + maximum: MemoryMaxValid, + }); + let type = memory.type(); + assertEq(type.maximum, MemoryMaxValid, 'reported memory maximum is not clamped'); +} |