From 9fb3f31be195430d55720f998612598efeda179c Mon Sep 17 00:00:00 2001 From: Arthur Islamov Date: Thu, 13 Jul 2023 19:53:42 +0400 Subject: [PATCH 1/5] WebAssembly.Memory "memory64: bool" constructor parameter --- document/js-api/index.bs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index 91fc50985..fc38db0a3 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -610,6 +610,7 @@ interface Instance { dictionary MemoryDescriptor { required [EnforceRange] unsigned long initial; [EnforceRange] unsigned long maximum; + boolean memory64; }; [LegacyNamespace=WebAssembly, Exposed=(Window,Worker,Worklet)] @@ -662,7 +663,8 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each 1. Let |initial| be |descriptor|["initial"]. 1. If |descriptor|["maximum"] [=map/exists=], let |maximum| be |descriptor|["maximum"]; otherwise, let |maximum| be empty. 1. If |maximum| is not empty and |maximum| < |initial|, throw a {{RangeError}} exception. - 1. Let |memtype| be { min |initial|, max |maximum| }. + 1. If |descriptior|["memory64"] [=map/exists=], let |memory64| be |descriptor|["memory64"]; otherwise, let |memory64| be false. + 1. Let |memtype| be { min |initial|, max |maximum|, memory64 |memory64| }. 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. 1. Let (|store|, |memaddr|) be [=mem_alloc=](|store|, |memtype|). If allocation fails, throw a {{RangeError}} exception. 1. Set the [=surrounding agent=]'s [=associated store=] to |store|. From b785d4031c6191213ea7a6c58f1c40ed51385894 Mon Sep 17 00:00:00 2001 From: Arthur Islamov Date: Wed, 26 Jul 2023 19:43:33 +0400 Subject: [PATCH 2/5] Added "index" parameter to WebAssembly.Memory constructor --- document/js-api/index.bs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index fc38db0a3..7c7a4323d 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -607,10 +607,15 @@ interface Instance {

Memories

+enum MemoryIndexType {
+  "u32",
+  "u64",
+};
+
 dictionary MemoryDescriptor {
   required [EnforceRange] unsigned long initial;
   [EnforceRange] unsigned long maximum;
-  boolean memory64;
+  MemoryIndexType index;
 };
 
 [LegacyNamespace=WebAssembly, Exposed=(Window,Worker,Worklet)]
@@ -663,8 +668,8 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
     1. Let |initial| be |descriptor|["initial"].
     1. If |descriptor|["maximum"] [=map/exists=], let |maximum| be |descriptor|["maximum"]; otherwise, let |maximum| be empty.
     1. If |maximum| is not empty and |maximum| < |initial|, throw a {{RangeError}} exception.
-    1. If |descriptior|["memory64"] [=map/exists=], let |memory64| be |descriptor|["memory64"]; otherwise, let |memory64| be false.
-    1. Let |memtype| be { min |initial|, max |maximum|, memory64 |memory64| }.
+    1. If |descriptior|["index"] [=map/exists=], let |index| be |descriptor|["index"]; otherwise, let |index| be "u32".
+    1. Let |memtype| be { min |initial|, max |maximum|, index |index| }.
     1. Let |store| be the [=surrounding agent=]'s [=associated store=].
     1. Let (|store|, |memaddr|) be [=mem_alloc=](|store|, |memtype|). If allocation fails, throw a {{RangeError}} exception.
     1. Set the [=surrounding agent=]'s [=associated store=] to |store|.

From 89b43ff05cb83941a12505bf26c7166ec4832202 Mon Sep 17 00:00:00 2001
From: Arthur Islamov 
Date: Thu, 3 Aug 2023 20:20:26 +0400
Subject: [PATCH 3/5] Added memory index tests

---
 test/js-api/memory/constructor.any.js | 33 +++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/test/js-api/memory/constructor.any.js b/test/js-api/memory/constructor.any.js
index 6524c8acc..043d8c676 100644
--- a/test/js-api/memory/constructor.any.js
+++ b/test/js-api/memory/constructor.any.js
@@ -72,6 +72,9 @@ test(() => {
       assert_unreached(`Should not call [[HasProperty]] with ${x}`);
     },
     get(o, x) {
+      if (x === "index") {
+        return "u32";
+      }
       return 0;
     },
   });
@@ -128,3 +131,33 @@ test(() => {
   const memory = new WebAssembly.Memory(argument, {});
   assert_Memory(memory, { "size": 0 });
 }, "Stray argument");
+
+test(() => {
+  const argument = { "initial": 1 };
+  const memory = new WebAssembly.Memory(argument);
+  assert_equals(memory.type().index, "u32");
+}, "Memory with default constructor");
+
+test(() => {
+  const argument = { "initial": 1, "index": "u32" };
+  const memory = new WebAssembly.Memory(argument);
+  assert_equals(memory.type().index, "u32");
+}, "Memory with u32 index constructor");
+
+test(() => {
+  const argument = { "initial": 1, "index": "u64" };
+  const memory = new WebAssembly.Memory(argument);
+  assert_Memory(memory, { "size": 1 });
+  assert_equals(memory.type().index, "u64");
+}, "Memory with u64 index constructor");
+
+test(() => {
+  const argument = { "initial": 1, "index": "u64", shared: true };
+  const memory = new WebAssembly.Memory(argument);
+  assert_Memory(memory, { "size": 1 });
+  assert_equals(memory.type().index, "u64");
+}, "Shared memory with u64 index constructor");
+
+test(() => {
+  assert_throws_js(TypeError, () => new WebAssembly.Memory({ "initial": 1, "index": "none" }));
+}, "Unknown memory index");

From 8952c9332f32b9841359db28c9d3674d4ba4d61b Mon Sep 17 00:00:00 2001
From: Arthur Islamov 
Date: Thu, 3 Aug 2023 21:30:40 +0400
Subject: [PATCH 4/5] Updated memory constructor tests

---
 test/js-api/memory/assertions.js      |  7 ++++++-
 test/js-api/memory/constructor.any.js | 20 ++++++++++++--------
 2 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/test/js-api/memory/assertions.js b/test/js-api/memory/assertions.js
index b539513ad..6a2884975 100644
--- a/test/js-api/memory/assertions.js
+++ b/test/js-api/memory/assertions.js
@@ -27,7 +27,7 @@ function assert_ArrayBuffer(actual, { size=0, shared=false, detached=false }, me
   assert_equals(Object.isExtensible(actual), !shared, "buffer extensibility");
 }
 
-function assert_Memory(memory, { size=0, shared=false }) {
+function assert_Memory(memory, { size=0, shared=false, index="u32" }) {
   assert_equals(Object.getPrototypeOf(memory), WebAssembly.Memory.prototype,
                 "prototype");
   assert_true(Object.isExtensible(memory), "extensible");
@@ -35,4 +35,9 @@ function assert_Memory(memory, { size=0, shared=false }) {
   // https://github.com/WebAssembly/spec/issues/840
   assert_equals(memory.buffer, memory.buffer, "buffer should be idempotent");
   assert_ArrayBuffer(memory.buffer, { size, shared });
+
+  // this depends on js-types proposal implementation
+  if (typeof memory.type == "function") {
+    assert_equals(memory.type().index, index, "memory index");
+  }
 }
diff --git a/test/js-api/memory/constructor.any.js b/test/js-api/memory/constructor.any.js
index 043d8c676..f9856bed0 100644
--- a/test/js-api/memory/constructor.any.js
+++ b/test/js-api/memory/constructor.any.js
@@ -135,27 +135,31 @@ test(() => {
 test(() => {
   const argument = { "initial": 1 };
   const memory = new WebAssembly.Memory(argument);
-  assert_equals(memory.type().index, "u32");
-}, "Memory with default constructor");
+  assert_Memory(memory, { "size": 1, "index": "u32" });
+}, "Memory with index parameter omitted");
 
 test(() => {
   const argument = { "initial": 1, "index": "u32" };
   const memory = new WebAssembly.Memory(argument);
-  assert_equals(memory.type().index, "u32");
+  assert_Memory(memory, { "size": 1, "index": "u32" });
 }, "Memory with u32 index constructor");
 
 test(() => {
   const argument = { "initial": 1, "index": "u64" };
   const memory = new WebAssembly.Memory(argument);
-  assert_Memory(memory, { "size": 1 });
-  assert_equals(memory.type().index, "u64");
+  assert_Memory(memory, { "size": 1, "index": "u64" });
 }, "Memory with u64 index constructor");
 
 test(() => {
-  const argument = { "initial": 1, "index": "u64", shared: true };
+  const argument = { "initial": 1, "maximum": 2, "index": "u32", shared: true };
   const memory = new WebAssembly.Memory(argument);
-  assert_Memory(memory, { "size": 1 });
-  assert_equals(memory.type().index, "u64");
+  assert_Memory(memory, { "size": 1, "index": "u32", shared: true });
+}, "Shared memory with u32 index constructor");
+
+test(() => {
+  const argument = { "initial": 1, "maximum": 2, "index": "u64", shared: true };
+  const memory = new WebAssembly.Memory(argument);
+  assert_Memory(memory, { "size": 1, "index": "u64", shared: true });
 }, "Shared memory with u64 index constructor");
 
 test(() => {

From 2bd28299d8a52392f21a65546eada6bfcc5c6a94 Mon Sep 17 00:00:00 2001
From: Arthur Islamov 
Date: Fri, 4 Aug 2023 21:52:49 +0400
Subject: [PATCH 5/5] Removed shared memory tests

---
 test/js-api/memory/constructor.any.js | 12 ------------
 1 file changed, 12 deletions(-)

diff --git a/test/js-api/memory/constructor.any.js b/test/js-api/memory/constructor.any.js
index f9856bed0..d1c9bf7ad 100644
--- a/test/js-api/memory/constructor.any.js
+++ b/test/js-api/memory/constructor.any.js
@@ -150,18 +150,6 @@ test(() => {
   assert_Memory(memory, { "size": 1, "index": "u64" });
 }, "Memory with u64 index constructor");
 
-test(() => {
-  const argument = { "initial": 1, "maximum": 2, "index": "u32", shared: true };
-  const memory = new WebAssembly.Memory(argument);
-  assert_Memory(memory, { "size": 1, "index": "u32", shared: true });
-}, "Shared memory with u32 index constructor");
-
-test(() => {
-  const argument = { "initial": 1, "maximum": 2, "index": "u64", shared: true };
-  const memory = new WebAssembly.Memory(argument);
-  assert_Memory(memory, { "size": 1, "index": "u64", shared: true });
-}, "Shared memory with u64 index constructor");
-
 test(() => {
   assert_throws_js(TypeError, () => new WebAssembly.Memory({ "initial": 1, "index": "none" }));
 }, "Unknown memory index");