Bug 1636435 [wpt PR 23476] - Improve WebAssembly.Memory tests, a=testonly
authorMs2ger <Ms2ger@gmail.com>
Wed, 13 May 2020 09:47:39 +0000
changeset 531148 73514f66f8950d20c7c7e5b9e0c3fd64c11ac53f
parent 531147 803e71597e6b85e280b3725f51f030d3cbee1dbf
child 531149 07c15b19a9b95e5fcdbe79d09f57134b0753c932
push id37435
push userapavel@mozilla.com
push dateWed, 20 May 2020 15:28:23 +0000
treeherdermozilla-central@5415da14ec9a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1636435, 23476
milestone78.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1636435 [wpt PR 23476] - Improve WebAssembly.Memory tests, a=testonly Automatic update from web-platform-tests Move assert_Memory, assert_ArrayBuffer into a shared file. -- Share code between assert_Memory, assert_ArrayBuffer. -- Split tests for shared memory out of the main file. -- wpt-commits: 4ec47c29ffeccedab03bf6dc22a3b4507fac4865, a6b683ff6af2b83e7c4a2e49307c9ea3bf6c8ca1, 943b6ed25e66b68399ec0cfb2327d8437614c424 wpt-pr: 23476
testing/web-platform/tests/wasm/jsapi/memory/assertions.js
testing/web-platform/tests/wasm/jsapi/memory/constructor-shared.tentative.any.js
testing/web-platform/tests/wasm/jsapi/memory/constructor.any.js
testing/web-platform/tests/wasm/jsapi/memory/grow.any.js
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/wasm/jsapi/memory/assertions.js
@@ -0,0 +1,38 @@
+function assert_ArrayBuffer(actual, { size=0, shared=false, detached=false }, message) {
+  // https://github.com/WebAssembly/spec/issues/840
+  // See https://github.com/whatwg/html/issues/5380 for why not `self.SharedArrayBuffer`
+  const isShared = !("isView" in actual.constructor);
+  assert_equals(isShared, shared, `${message}: constructor`);
+  const sharedString = shared ? "Shared" : "";
+  assert_equals(actual.toString(), `[object ${sharedString}ArrayBuffer]`, `${message}: toString()`);
+  assert_equals(Object.getPrototypeOf(actual).toString(), `[object ${sharedString}ArrayBuffer]`, `${message}: prototype toString()`);
+  if (detached) {
+    // https://github.com/tc39/ecma262/issues/678
+    let byteLength;
+    try {
+      byteLength = actual.byteLength;
+    } catch (e) {
+      byteLength = 0;
+    }
+    assert_equals(byteLength, 0, `${message}: detached size`);
+  } else {
+    assert_equals(actual.byteLength, 0x10000 * size, `${message}: size`);
+    if (size > 0) {
+      const array = new Uint8Array(actual);
+      assert_equals(array[0], 0, `${message}: first element`);
+      assert_equals(array[array.byteLength - 1], 0, `${message}: last element`);
+    }
+  }
+  assert_equals(Object.isFrozen(actual), shared, "buffer frozen");
+  assert_equals(Object.isExtensible(actual), !shared, "buffer extensibility");
+}
+
+function assert_Memory(memory, { size=0, shared=false }) {
+  assert_equals(Object.getPrototypeOf(memory), WebAssembly.Memory.prototype,
+                "prototype");
+  assert_true(Object.isExtensible(memory), "extensible");
+
+  // https://github.com/WebAssembly/spec/issues/840
+  assert_equals(memory.buffer, memory.buffer, "buffer should be idempotent");
+  assert_ArrayBuffer(memory.buffer, { size, shared });
+}
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/wasm/jsapi/memory/constructor-shared.tentative.any.js
@@ -0,0 +1,54 @@
+// META: global=window,dedicatedworker,jsshell
+// META: script=/wasm/jsapi/assertions.js
+// META: script=/wasm/jsapi/memory/assertions.js
+
+test(() => {
+  assert_throws_js(TypeError, () => new WebAssembly.Memory({ "initial": 10, "shared": true }));
+}, "Shared memory without maximum");
+
+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": 4, "maximum": 10, shared: true };
+  const memory = new WebAssembly.Memory(argument);
+  assert_Memory(memory, { "size": 4, "shared": true });
+}, "Shared memory");
--- a/testing/web-platform/tests/wasm/jsapi/memory/constructor.any.js
+++ b/testing/web-platform/tests/wasm/jsapi/memory/constructor.any.js
@@ -1,31 +1,11 @@
 // META: global=window,dedicatedworker,jsshell
 // META: script=/wasm/jsapi/assertions.js
-
-function assert_Memory(memory, expected) {
-  assert_equals(Object.getPrototypeOf(memory), WebAssembly.Memory.prototype,
-                "prototype");
-  assert_true(Object.isExtensible(memory), "extensible");
-
-  // https://github.com/WebAssembly/spec/issues/840
-  assert_equals(memory.buffer, memory.buffer, "buffer should be idempotent");
-  const isShared = !!expected.shared;
-  const bufferType = isShared ? self.SharedArrayBuffer : ArrayBuffer;
-  assert_equals(Object.getPrototypeOf(memory.buffer), bufferType.prototype,
-                'prototype of buffer');
-  assert_equals(memory.buffer.byteLength, 0x10000 * expected.size, "size of buffer");
-  if (expected.size > 0) {
-    const array = new Uint8Array(memory.buffer);
-    assert_equals(array[0], 0, "first element of buffer");
-    assert_equals(array[array.byteLength - 1], 0, "last element of buffer");
-  }
-  assert_equals(isShared, Object.isFrozen(memory.buffer), "buffer frozen");
-  assert_not_equals(Object.isExtensible(memory.buffer), isShared, "buffer extensibility");
-}
+// META: script=/wasm/jsapi/memory/assertions.js
 
 test(() => {
   assert_function_name(WebAssembly.Memory, "Memory", "WebAssembly.Memory");
 }, "name");
 
 test(() => {
   assert_function_length(WebAssembly.Memory, 1, "WebAssembly.Memory");
 }, "length");
@@ -82,20 +62,16 @@ for (const value of outOfRangeValues) {
   }, `Out-of-range maximum value in descriptor: ${format_value(value)}`);
 }
 
 test(() => {
   assert_throws_js(RangeError, () => new WebAssembly.Memory({ "initial": 10, "maximum": 9 }));
 }, "Initial value exceeds maximum");
 
 test(() => {
-  assert_throws_js(TypeError, () => new WebAssembly.Memory({ "initial": 10, "shared": true }));
-}, "Shared memory without maximum");
-
-test(() => {
   const proxy = new Proxy({}, {
     has(o, x) {
       assert_unreached(`Should not call [[HasProperty]] with ${x}`);
     },
     get(o, x) {
       return 0;
     },
   });
@@ -130,57 +106,16 @@ test(() => {
   assert_array_equals(order, [
     "initial",
     "initial valueOf",
     "maximum",
     "maximum valueOf",
   ]);
 }, "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);
   assert_Memory(memory, { "size": 0 });
 }, "Zero initial");
 
 test(() => {
   const argument = { "initial": 4 };
@@ -188,14 +123,8 @@ test(() => {
   assert_Memory(memory, { "size": 4 });
 }, "Non-zero initial");
 
 test(() => {
   const argument = { "initial": 0 };
   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");
--- a/testing/web-platform/tests/wasm/jsapi/memory/grow.any.js
+++ b/testing/web-platform/tests/wasm/jsapi/memory/grow.any.js
@@ -1,36 +1,10 @@
 // META: global=window,dedicatedworker,jsshell
-
-function assert_ArrayBuffer(actual, { size=0, shared=false, detached=false }, message) {
-  // https://github.com/WebAssembly/spec/issues/840
-  // See https://github.com/whatwg/html/issues/5380 for why not `self.SharedArrayBuffer`
-  const isShared = !("isView" in actual.constructor);
-  assert_equals(isShared, shared, `${message}: constructor`);
-  const sharedString = shared ? "Shared" : "";
-  assert_equals(actual.toString(), `[object ${sharedString}ArrayBuffer]`, `${message}: toString()`);
-  assert_equals(Object.getPrototypeOf(actual).toString(), `[object ${sharedString}ArrayBuffer]`, `${message}: prototype toString()`);
-  if (detached) {
-    // https://github.com/tc39/ecma262/issues/678
-    let byteLength;
-    try {
-      byteLength = actual.byteLength;
-    } catch (e) {
-      byteLength = 0;
-    }
-    assert_equals(byteLength, 0, `${message}: detached size`);
-  } else {
-    assert_equals(actual.byteLength, 0x10000 * size, `${message}: size`);
-    if (size > 0) {
-      const array = new Uint8Array(actual);
-      assert_equals(array[0], 0, `${message}: first element`);
-      assert_equals(array[array.byteLength - 1], 0, `${message}: last element`);
-    }
-  }
-}
+// META: script=/wasm/jsapi/memory/assertions.js
 
 test(() => {
   const argument = { "initial": 0 };
   const memory = new WebAssembly.Memory(argument);
   assert_throws_js(TypeError, () => memory.grow());
 }, "Missing arguments");
 
 test(t => {