From ed764b7d385a2bfea35b99acd8b9c7bde2af688c Mon Sep 17 00:00:00 2001
From: Marco Castelluccio <mcastelluccio@mozilla.com>
Date: Fri, 4 Oct 2019 02:56:43 +0000
Subject: [PATCH] Bug 1529796 [wpt PR 15144] - [WPT] [wasm] Add JS-API tests
 for wasm threads, a=testonly

Automatic update from web-platform-tests
[WPT] [wasm] Add JS-API tests for wasm threads

These are copied from the tests in the WebAssembly spec repo here:
https://github.com/WebAssembly/threads/commit/0b80037ebc7825db0e67c2433f556dd8d07118a2

Bug: chromium:926307
Change-Id: I54decd04abfe11bdb6ac7209240b10a3f6115fb1
Reviewed-on: https://chromium-review.googlesource.com/c/1443959
Reviewed-by: Adam Klein <adamkchromium.org>
Commit-Queue: Ben Smith <binjichromium.org>
Cr-Commit-Position: refs/heads/master{#629308}

--

wpt-commits: 4e1d6d78b38f9aa0253a43b36785f53abf51832f
wpt-pr: 15144

UltraBlame original commit: b9c6ed34a2140f3282535705c11592ed77ea8ef7
---
 .../tests/wasm/jsapi/memory/grow.any.js       | 29 ++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/testing/web-platform/tests/wasm/jsapi/memory/grow.any.js b/testing/web-platform/tests/wasm/jsapi/memory/grow.any.js
index 05c96d0c21f53..d5c9a544ee770 100644
--- a/testing/web-platform/tests/wasm/jsapi/memory/grow.any.js
+++ b/testing/web-platform/tests/wasm/jsapi/memory/grow.any.js
@@ -2,7 +2,8 @@
 
 function assert_ArrayBuffer(actual, expected, message) {
   
-  assert_equals(Object.getPrototypeOf(actual), ArrayBuffer.prototype,
+  const bufferType = expected.shared ? self.SharedArrayBuffer : ArrayBuffer;
+  assert_equals(Object.getPrototypeOf(actual), bufferType.prototype,
                 `${message}: prototype`);
   if (expected.detached) {
     
@@ -183,3 +184,29 @@ test(() => {
   assert_ArrayBuffer(oldMemory, { "detached": true }, "Old buffer after growing");
   assert_ArrayBuffer(newMemory, { "size": 2 }, "New buffer after growing");
 }, "Stray argument");
+
+test(() => {
+  const argument = { "initial": 1, "maximum": 2, "shared": true };
+  const memory = new WebAssembly.Memory(argument);
+  const oldMemory = memory.buffer;
+  assert_ArrayBuffer(oldMemory, { "size": 1, "shared": true }, "Buffer before growing");
+
+  const result = memory.grow(1);
+  assert_equals(result, 1);
+
+  const newMemory = memory.buffer;
+  assert_not_equals(oldMemory, newMemory);
+  assert_ArrayBuffer(oldMemory, { "size": 1, "shared": true }, "Old buffer after growing");
+  assert_ArrayBuffer(newMemory, { "size": 2, "shared": true }, "New buffer after growing");
+
+  
+  
+  const oldArray = new Uint8Array(oldMemory);
+  const newArray = new Uint8Array(newMemory);
+  assert_equals(oldArray[0], 0, "old first element");
+  assert_equals(newArray[0], 0, "new first element");
+  oldArray[0] = 1;
+  assert_equals(oldArray[0], 1, "old first element");
+  assert_equals(newArray[0], 1, "new first element");
+
+}, "Growing shared memory does not detach old buffer");