Index: test/mjsunit/d8-worker-sharedarraybuffer.js |
diff --git a/test/mjsunit/d8-worker-spawn-worker.js b/test/mjsunit/d8-worker-sharedarraybuffer.js |
similarity index 63% |
copy from test/mjsunit/d8-worker-spawn-worker.js |
copy to test/mjsunit/d8-worker-sharedarraybuffer.js |
index b9d7f9ade4fd116837c275a73867eeda26076e5a..e10e738bf2bb05cec920721d640baabe2675c7ca 100644 |
--- a/test/mjsunit/d8-worker-spawn-worker.js |
+++ b/test/mjsunit/d8-worker-sharedarraybuffer.js |
@@ -25,22 +25,47 @@ |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+// Flags: --harmony-sharedarraybuffer --harmony-atomics |
+ |
+function f() { |
+ onmessage = function(m) { |
+ var sab = m; |
+ var ta = new Uint32Array(sab); |
+ if (sab.byteLength !== 16) { |
+ throw new Error("SharedArrayBuffer transfer byteLength"); |
+ } |
+ |
+ for (var i = 0; i < 4; ++i) { |
+ if (ta[i] !== i) { |
+ throw new Error("SharedArrayBuffer transfer value " + i); |
+ } |
+ } |
+ |
+ // Atomically update ta[0] |
+ Atomics.store(ta, 0, 100); |
+ }; |
+} |
+ |
if (this.Worker) { |
- function f() { |
- var g = function () { |
- postMessage(42); |
- }; |
- |
- var w = new Worker(g); |
- |
- onmessage = function(parentMsg) { |
- w.postMessage(parentMsg); |
- var childMsg = w.getMessage(); |
- postMessage(childMsg); |
- }; |
+ var w = new Worker(f); |
+ |
+ var sab = new SharedArrayBuffer(16); |
+ var ta = new Uint32Array(sab); |
+ for (var i = 0; i < 4; ++i) { |
+ ta[i] = i; |
} |
- var w = new Worker(f); |
- w.postMessage(9); |
- assertEquals(42, w.getMessage()); |
+ // Transfer SharedArrayBuffer |
+ w.postMessage(sab, [sab]); |
+ assertEquals(16, sab.byteLength); // ArrayBuffer should not be neutered. |
+ |
+ // Spinwait for the worker to update ta[0] |
+ var ta0; |
+ while ((ta0 = Atomics.load(ta, 0)) == 0) {} |
+ |
+ assertEquals(100, ta0); |
+ |
+ w.terminate(); |
+ |
+ assertEquals(16, sab.byteLength); // Still not neutered. |
} |