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

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: feedback 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 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.
}
« 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