diff --git a/test/core/exports.wast b/test/core/exports.wast index 80d3ae07..e1844b11 100644 --- a/test/core/exports.wast +++ b/test/core/exports.wast @@ -201,6 +201,13 @@ (module (export "a" (memory $a)) (memory $a 0)) (module (export "a" (memory $a)) (memory $a 0 1)) +(module (memory (export "a") 0 1 shared)) +(module (memory 0 1 shared) (export "a" (memory 0))) +(module (memory $a (export "a") 0 1 shared)) +(module (memory $a 0 1 shared) (export "a" (memory $a))) +(module (export "a" (memory 0)) (memory 0 1 shared)) +(module (export "a" (memory $a)) (memory $a 0 1 shared)) + (; TODO: access memory ;) (assert_invalid diff --git a/test/core/memory.wast b/test/core/memory.wast index 497b69fc..e10c3497 100644 --- a/test/core/memory.wast +++ b/test/core/memory.wast @@ -6,6 +6,10 @@ (module (memory 0 1)) (module (memory 1 256)) (module (memory 0 65536)) +(module (memory 0 0 shared)) +(module (memory 1 2 shared)) + +(assert_invalid (module (memory 1 shared)) "shared memory must have maximum") (assert_invalid (module (memory 0) (memory 0)) "multiple memories") (assert_invalid (module (memory (import "spectest" "memory") 0) (memory 0)) "multiple memories") diff --git a/test/js-api/memory/constructor.any.js b/test/js-api/memory/constructor.any.js index 0a0be11e..abcaccc1 100644 --- a/test/js-api/memory/constructor.any.js +++ b/test/js-api/memory/constructor.any.js @@ -66,6 +66,10 @@ test(() => { assert_throws_js(RangeError, () => new WebAssembly.Memory({ "initial": 10, "maximum": 9 })); }, "Initial value exceeds maximum"); +test(() => { + assert_throws(new TypeError(), () => new WebAssembly.Memory({ "initial": 10, "shared": true })); +}, "Shared memory without maximum"); + test(() => { const proxy = new Proxy({}, { has(o, x) { @@ -120,6 +124,47 @@ test(() => { ]); }, "Order of evaluation for descriptor"); +test(t => { + const order = []; + + new WebAssembly.Memory({ + get maximum() { + order.push("maximum"); + return { + valueOf() { + order.push("maximum valueOf"); + return 1; + }, + }; + }, + + get initial() { + order.push("initial"); + return { + valueOf() { + order.push("initial valueOf"); + return 1; + }, + }; + }, + + get shared() { + order.push("shared"); + return { + valueOf: t.unreached_func("should not call shared valueOf"), + }; + }, + }); + + assert_array_equals(order, [ + "initial", + "initial valueOf", + "maximum", + "maximum valueOf", + "shared", + ]); +}, "Order of evaluation for descriptor (with shared)"); + test(() => { const argument = { "initial": 0 }; const memory = new WebAssembly.Memory(argument); @@ -137,3 +182,9 @@ test(() => { const memory = new WebAssembly.Memory(argument, {}); assert_Memory(memory, { "size": 0 }); }, "Stray argument"); + +test(() => { + const argument = { "initial": 4, "maximum": 10, shared: true }; + const memory = new WebAssembly.Memory(argument); + assert_Memory(memory, { "size": 4, "shared": true }); +}, "Shared memory");