Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Unified Diff: test/mjsunit/d8-worker-sharedarraybuffer.js

Issue 1224843008: Revert of Fix bug when transferring SharedArrayBuffer to multiple Workers. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/d8.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/d8-worker-sharedarraybuffer.js
diff --git a/test/mjsunit/d8-worker-sharedarraybuffer.js b/test/mjsunit/d8-worker-sharedarraybuffer.js
index d432f970748486837bd745092bda7e59c7d2bb8e..791529fc89402cfe8b8afcfc3965d7c3bbcd8711 100644
--- a/test/mjsunit/d8-worker-sharedarraybuffer.js
+++ b/test/mjsunit/d8-worker-sharedarraybuffer.js
@@ -27,80 +27,42 @@
// Flags: --harmony-sharedarraybuffer --harmony-atomics
+var workerScript =
+ `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) {
+ var w = new Worker(workerScript);
- (function TestTransfer() {
- var workerScript =
- `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);
- };`;
+ var sab = new SharedArrayBuffer(16);
+ var ta = new Uint32Array(sab);
+ for (var i = 0; i < 4; ++i) {
+ ta[i] = i;
+ }
- var w = new Worker(workerScript);
+ // Transfer SharedArrayBuffer
+ w.postMessage(sab, [sab]);
+ assertEquals(16, sab.byteLength); // ArrayBuffer should not be neutered.
- var sab = new SharedArrayBuffer(16);
- var ta = new Uint32Array(sab);
- for (var i = 0; i < 4; ++i) {
- ta[i] = i;
- }
+ // Spinwait for the worker to update ta[0]
+ var ta0;
+ while ((ta0 = Atomics.load(ta, 0)) == 0) {}
- // Transfer SharedArrayBuffer
- w.postMessage(sab, [sab]);
- assertEquals(16, sab.byteLength); // ArrayBuffer should not be neutered.
+ assertEquals(100, ta0);
- // Spinwait for the worker to update ta[0]
- var ta0;
- while ((ta0 = Atomics.load(ta, 0)) == 0) {}
+ w.terminate();
- assertEquals(100, ta0);
-
- w.terminate();
-
- assertEquals(16, sab.byteLength); // Still not neutered.
- })();
-
- (function TestTransferMulti() {
- var workerScript =
- `onmessage = function(msg) {
- var sab = msg.sab;
- var id = msg.id;
- var ta = new Uint32Array(sab);
- Atomics.store(ta, id, 1);
- postMessage(id);
- };`;
-
- var sab = new SharedArrayBuffer(16);
- var ta = new Uint32Array(sab);
-
- var id;
- var workers = [];
- for (id = 0; id < 4; ++id) {
- workers[id] = new Worker(workerScript);
- workers[id].postMessage({sab: sab, id: id}, [sab]);
- }
-
- // Spinwait for each worker to update ta[id]
- var count = 0;
- while (count < 4) {
- for (id = 0; id < 4; ++id) {
- if (Atomics.compareExchange(ta, id, 1, -1) == 1) {
- // Worker is finished.
- assertEquals(id, workers[id].getMessage());
- workers[id].terminate();
- count++;
- }
- }
- }
- })();
-
+ assertEquals(16, sab.byteLength); // Still not neutered.
}
« no previous file with comments | « src/d8.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698