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

Side by Side Diff: test/mjsunit/d8-worker-sharedarraybuffer.js

Issue 2643723010: [d8] Use ValueSerializer for postMessage (instead of ad-hoc serializer) (Closed)
Patch Set: forgot hash_combine Created 3 years, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 10 matching lines...) Expand all
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 // Flags: --harmony-sharedarraybuffer 28 // Flags: --harmony-sharedarraybuffer
29 29
30 if (this.Worker) { 30 if (this.Worker) {
31
32 (function TestTransfer() { 31 (function TestTransfer() {
33 var workerScript = 32 var workerScript =
34 `onmessage = function(m) { 33 `onmessage = function(m) {
35 var sab = m; 34 var sab = m;
36 var ta = new Uint32Array(sab); 35 var ta = new Uint32Array(sab);
37 if (sab.byteLength !== 16) { 36 if (sab.byteLength !== 16) {
38 throw new Error('SharedArrayBuffer transfer byteLength'); 37 throw new Error('SharedArrayBuffer transfer byteLength');
39 } 38 }
40 for (var i = 0; i < 4; ++i) { 39 for (var i = 0; i < 4; ++i) {
41 if (ta[i] !== i) { 40 if (ta[i] !== i) {
42 throw new Error('SharedArrayBuffer transfer value ' + i); 41 throw new Error('SharedArrayBuffer transfer value ' + i);
43 } 42 }
44 } 43 }
45 // Atomically update ta[0] 44 // Atomically update ta[0]
46 Atomics.store(ta, 0, 100); 45 Atomics.store(ta, 0, 100);
47 };`; 46 };`;
48 47
49 var w = new Worker(workerScript); 48 var w = new Worker(workerScript);
50 49
51 var sab = new SharedArrayBuffer(16); 50 var sab = new SharedArrayBuffer(16);
52 var ta = new Uint32Array(sab); 51 var ta = new Uint32Array(sab);
53 for (var i = 0; i < 4; ++i) { 52 for (var i = 0; i < 4; ++i) {
54 ta[i] = i; 53 ta[i] = i;
55 } 54 }
56 55
57 // Transfer SharedArrayBuffer 56 // Transfer SharedArrayBuffer
58 w.postMessage(sab, [sab]); 57 w.postMessage(sab);
59 assertEquals(16, sab.byteLength); // ArrayBuffer should not be neutered. 58 assertEquals(16, sab.byteLength); // ArrayBuffer should not be neutered.
60 59
61 // Spinwait for the worker to update ta[0] 60 // Spinwait for the worker to update ta[0]
62 var ta0; 61 var ta0;
63 while ((ta0 = Atomics.load(ta, 0)) == 0) {} 62 while ((ta0 = Atomics.load(ta, 0)) == 0) {}
64 63
65 assertEquals(100, ta0); 64 assertEquals(100, ta0);
66 65
67 w.terminate(); 66 w.terminate();
68 67
(...skipping 10 matching lines...) Expand all
79 postMessage(id); 78 postMessage(id);
80 };`; 79 };`;
81 80
82 var sab = new SharedArrayBuffer(16); 81 var sab = new SharedArrayBuffer(16);
83 var ta = new Uint32Array(sab); 82 var ta = new Uint32Array(sab);
84 83
85 var id; 84 var id;
86 var workers = []; 85 var workers = [];
87 for (id = 0; id < 4; ++id) { 86 for (id = 0; id < 4; ++id) {
88 workers[id] = new Worker(workerScript); 87 workers[id] = new Worker(workerScript);
89 workers[id].postMessage({sab: sab, id: id}, [sab]); 88 workers[id].postMessage({sab: sab, id: id});
90 } 89 }
91 90
92 // Spinwait for each worker to update ta[id] 91 // Spinwait for each worker to update ta[id]
93 var count = 0; 92 var count = 0;
94 while (count < 4) { 93 while (count < 4) {
95 for (id = 0; id < 4; ++id) { 94 for (id = 0; id < 4; ++id) {
96 if (Atomics.compareExchange(ta, id, 1, -1) == 1) { 95 if (Atomics.compareExchange(ta, id, 1, -1) == 1) {
97 // Worker is finished. 96 // Worker is finished.
98 assertEquals(id, workers[id].getMessage()); 97 assertEquals(id, workers[id].getMessage());
99 workers[id].terminate(); 98 workers[id].terminate();
100 count++; 99 count++;
101 } 100 }
102 } 101 }
103 } 102 }
104 })(); 103 })();
105 104
106 } 105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698