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

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

Issue 1216023003: d8 Worker test of SharedArrayBuffer transferring (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: check value after spinwait Created 5 years, 6 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 | « no previous file | 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-spawn-worker.js b/test/mjsunit/d8-worker-sharedarraybuffer.js
similarity index 66%
copy from test/mjsunit/d8-worker-spawn-worker.js
copy to test/mjsunit/d8-worker-sharedarraybuffer.js
index b9d7f9ade4fd116837c275a73867eeda26076e5a..99d730690c6b0af09020265fed25c0649638e1fc 100644
--- a/test/mjsunit/d8-worker-spawn-worker.js
+++ b/test/mjsunit/d8-worker-sharedarraybuffer.js
@@ -25,22 +25,40 @@
// (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
+
if (this.Worker) {
function f() {
Jarin 2015/06/30 17:42:43 I do not think this is doing what you think it's d
binji 2015/06/30 18:11:04 Oh, I wasn't trying to prevent the definition of f
- var g = function () {
- postMessage(42);
- };
+ onmessage = function(m) {
+ var sab = m;
+ var ta = new Uint32Array(sab);
+ if (sab.byteLength !== 16)
+ throw new Error("SharedArrayBuffer transfer byteLength");
Jarin 2015/06/30 17:42:43 Nit: Could we get the braces here and below? (In g
binji 2015/06/30 18:11:04 Done.
+ for (var i = 0; i < 4; ++i)
+ if (ta[i] !== i)
+ throw new Error("SharedArrayBuffer transfer value " + i);
- var w = new Worker(g);
-
- onmessage = function(parentMsg) {
- w.postMessage(parentMsg);
- var childMsg = w.getMessage();
- postMessage(childMsg);
+ // Atomically update ta[0]
+ Atomics.store(ta, 0, 100);
};
}
var w = new Worker(f);
- w.postMessage(9);
- assertEquals(42, w.getMessage());
+
+ var sab = new SharedArrayBuffer(16);
+ var ta = new Uint32Array(sab);
+ for (var i = 0; i < 4; ++i)
+ ta[i] = i;
+
+ // Transfer SharedArrayBuffer
+ w.postMessage(sab, [sab]);
+ assertEquals(16, sab.byteLength); // ArrayBuffer should not neutered.
Jarin 2015/06/30 17:42:43 In the comment: ... should not *be* neutered.
binji 2015/06/30 18:11:04 Done.
+
+ // Spinwait for the worker to update ta[0]
+ var ta0;
+ while ((ta0 = Atomics.load(ta, 0)) == 0);
Jarin 2015/06/30 17:42:43 "while (<condition>);" is not recommended by the C
+
+ assertEquals(100, ta0);
+
+ w.terminate();
Jarin 2015/06/30 17:42:43 Could we also check that the array has not been ne
binji 2015/06/30 18:11:04 Done.
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698