diff options
Diffstat (limited to 'js/src/jit-test/tests/wasm/globals.js')
-rw-r--r-- | js/src/jit-test/tests/wasm/globals.js | 117 |
1 files changed, 56 insertions, 61 deletions
diff --git a/js/src/jit-test/tests/wasm/globals.js b/js/src/jit-test/tests/wasm/globals.js index 5a6d83e348..bbba095bb9 100644 --- a/js/src/jit-test/tests/wasm/globals.js +++ b/js/src/jit-test/tests/wasm/globals.js @@ -1,5 +1,3 @@ -// |jit-test| test-also=--wasm-extended-const; test-also=--no-wasm-extended-const - const { Instance, Module, LinkError } = WebAssembly; // Locally-defined globals @@ -44,68 +42,65 @@ testInner('i32', 13, 37, x => x|0); testInner('f32', 13.37, 0.1989, Math.fround); testInner('f64', 13.37, 0.1989, x => +x); -// Extended const stuff -if (wasmExtendedConstEnabled()) { - // Basic global shenanigans - { - const module = wasmEvalText(`(module - ;; -2 * (5 - (-10 + 20)) = 10 - (global i32 (i32.mul (i32.const -2) (i32.sub (i32.const 5) (i32.add (i32.const -10) (i32.const 20))))) - ;; ((1 + 2) - (3 * 4)) = -9 - (global i64 (i64.sub (i64.add (i64.const 1) (i64.const 2)) (i64.mul (i64.const 3) (i64.const 4)))) - - (func (export "get0") (result i32) global.get 0) - (func (export "get1") (result i64) global.get 1) - )`).exports; - - assertEq(module.get0(), 10); - assertEq(module.get1(), -9n); - } +// Basic global shenanigans +{ + const module = wasmEvalText(`(module + ;; -2 * (5 - (-10 + 20)) = 10 + (global i32 (i32.mul (i32.const -2) (i32.sub (i32.const 5) (i32.add (i32.const -10) (i32.const 20))))) + ;; ((1 + 2) - (3 * 4)) = -9 + (global i64 (i64.sub (i64.add (i64.const 1) (i64.const 2)) (i64.mul (i64.const 3) (i64.const 4)))) + + (func (export "get0") (result i32) global.get 0) + (func (export "get1") (result i64) global.get 1) + )`).exports; - // Example use of dynamic linking - { - // Make a memory for two dynamically-linked modules to share. Each module gets five pages. - const mem = new WebAssembly.Memory({ initial: 15, maximum: 15 }); - - const mod1 = new WebAssembly.Module(wasmTextToBinary(`(module - (memory (import "env" "memory") 15 15) - (global $memBase (import "env" "__memory_base") i32) - (data (offset (global.get $memBase)) "Hello from module 1.") - (data (offset (i32.add (global.get $memBase) (i32.const 65536))) "Goodbye from module 1.") - )`)); - const instance1 = new WebAssembly.Instance(mod1, { - env: { - memory: mem, - __memory_base: 65536 * 5, // this module's memory starts at page 5 - }, - }); - - const mod2 = new WebAssembly.Module(wasmTextToBinary(`(module - (memory (import "env" "memory") 15 15) - (global $memBase (import "env" "__memory_base") i32) - (data (offset (global.get $memBase)) "Hello from module 2.") - (data (offset (i32.add (global.get $memBase) (i32.const 65536))) "Goodbye from module 2.") - )`)); - const instance2 = new WebAssembly.Instance(mod2, { - env: { - memory: mem, - __memory_base: 65536 * 10, // this module's memory starts at page 10 - }, - }); - - // All four strings should now be present in the memory. - - function assertStringInMem(mem, str, addr) { - const bytes = new Uint8Array(mem.buffer).slice(addr, addr + str.length); - let memStr = String.fromCharCode(...bytes); - assertEq(memStr, str); - } + assertEq(module.get0(), 10); + assertEq(module.get1(), -9n); +} - assertStringInMem(mem, "Hello from module 1.", 65536 * 5); - assertStringInMem(mem, "Goodbye from module 1.", 65536 * 6); - assertStringInMem(mem, "Hello from module 2.", 65536 * 10); - assertStringInMem(mem, "Goodbye from module 2.", 65536 * 11); +// Example use of dynamic linking +{ + // Make a memory for two dynamically-linked modules to share. Each module gets five pages. + const mem = new WebAssembly.Memory({ initial: 15, maximum: 15 }); + + const mod1 = new WebAssembly.Module(wasmTextToBinary(`(module + (memory (import "env" "memory") 15 15) + (global $memBase (import "env" "__memory_base") i32) + (data (offset (global.get $memBase)) "Hello from module 1.") + (data (offset (i32.add (global.get $memBase) (i32.const 65536))) "Goodbye from module 1.") + )`)); + const instance1 = new WebAssembly.Instance(mod1, { + env: { + memory: mem, + __memory_base: 65536 * 5, // this module's memory starts at page 5 + }, + }); + + const mod2 = new WebAssembly.Module(wasmTextToBinary(`(module + (memory (import "env" "memory") 15 15) + (global $memBase (import "env" "__memory_base") i32) + (data (offset (global.get $memBase)) "Hello from module 2.") + (data (offset (i32.add (global.get $memBase) (i32.const 65536))) "Goodbye from module 2.") + )`)); + const instance2 = new WebAssembly.Instance(mod2, { + env: { + memory: mem, + __memory_base: 65536 * 10, // this module's memory starts at page 10 + }, + }); + + // All four strings should now be present in the memory. + + function assertStringInMem(mem, str, addr) { + const bytes = new Uint8Array(mem.buffer).slice(addr, addr + str.length); + let memStr = String.fromCharCode(...bytes); + assertEq(memStr, str); } + + assertStringInMem(mem, "Hello from module 1.", 65536 * 5); + assertStringInMem(mem, "Goodbye from module 1.", 65536 * 6); + assertStringInMem(mem, "Hello from module 2.", 65536 * 10); + assertStringInMem(mem, "Goodbye from module 2.", 65536 * 11); } // Semantic errors. |