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

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

Issue 2657403002: Revert of [d8] Use ValueSerializer for postMessage (instead of ad-hoc serializer) (Closed)
Patch Set: 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
« no previous file with comments | « test/mjsunit/d8-worker.js ('k') | test/mjsunit/harmony/futex.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
31 (function TestTransfer() { 32 (function TestTransfer() {
32 var workerScript = 33 var workerScript =
33 `onmessage = function(m) { 34 `onmessage = function(m) {
34 var sab = m; 35 var sab = m;
35 var ta = new Uint32Array(sab); 36 var ta = new Uint32Array(sab);
36 if (sab.byteLength !== 16) { 37 if (sab.byteLength !== 16) {
37 throw new Error('SharedArrayBuffer transfer byteLength'); 38 throw new Error('SharedArrayBuffer transfer byteLength');
38 } 39 }
39 for (var i = 0; i < 4; ++i) { 40 for (var i = 0; i < 4; ++i) {
40 if (ta[i] !== i) { 41 if (ta[i] !== i) {
41 throw new Error('SharedArrayBuffer transfer value ' + i); 42 throw new Error('SharedArrayBuffer transfer value ' + i);
42 } 43 }
43 } 44 }
44 // Atomically update ta[0] 45 // Atomically update ta[0]
45 Atomics.store(ta, 0, 100); 46 Atomics.store(ta, 0, 100);
46 };`; 47 };`;
47 48
48 var w = new Worker(workerScript); 49 var w = new Worker(workerScript);
49 50
50 var sab = new SharedArrayBuffer(16); 51 var sab = new SharedArrayBuffer(16);
51 var ta = new Uint32Array(sab); 52 var ta = new Uint32Array(sab);
52 for (var i = 0; i < 4; ++i) { 53 for (var i = 0; i < 4; ++i) {
53 ta[i] = i; 54 ta[i] = i;
54 } 55 }
55 56
56 // Transfer SharedArrayBuffer 57 // Transfer SharedArrayBuffer
57 w.postMessage(sab); 58 w.postMessage(sab, [sab]);
58 assertEquals(16, sab.byteLength); // ArrayBuffer should not be neutered. 59 assertEquals(16, sab.byteLength); // ArrayBuffer should not be neutered.
59 60
60 // Spinwait for the worker to update ta[0] 61 // Spinwait for the worker to update ta[0]
61 var ta0; 62 var ta0;
62 while ((ta0 = Atomics.load(ta, 0)) == 0) {} 63 while ((ta0 = Atomics.load(ta, 0)) == 0) {}
63 64
64 assertEquals(100, ta0); 65 assertEquals(100, ta0);
65 66
66 w.terminate(); 67 w.terminate();
67 68
(...skipping 10 matching lines...) Expand all
78 postMessage(id); 79 postMessage(id);
79 };`; 80 };`;
80 81
81 var sab = new SharedArrayBuffer(16); 82 var sab = new SharedArrayBuffer(16);
82 var ta = new Uint32Array(sab); 83 var ta = new Uint32Array(sab);
83 84
84 var id; 85 var id;
85 var workers = []; 86 var workers = [];
86 for (id = 0; id < 4; ++id) { 87 for (id = 0; id < 4; ++id) {
87 workers[id] = new Worker(workerScript); 88 workers[id] = new Worker(workerScript);
88 workers[id].postMessage({sab: sab, id: id}); 89 workers[id].postMessage({sab: sab, id: id}, [sab]);
89 } 90 }
90 91
91 // Spinwait for each worker to update ta[id] 92 // Spinwait for each worker to update ta[id]
92 var count = 0; 93 var count = 0;
93 while (count < 4) { 94 while (count < 4) {
94 for (id = 0; id < 4; ++id) { 95 for (id = 0; id < 4; ++id) {
95 if (Atomics.compareExchange(ta, id, 1, -1) == 1) { 96 if (Atomics.compareExchange(ta, id, 1, -1) == 1) {
96 // Worker is finished. 97 // Worker is finished.
97 assertEquals(id, workers[id].getMessage()); 98 assertEquals(id, workers[id].getMessage());
98 workers[id].terminate(); 99 workers[id].terminate();
99 count++; 100 count++;
100 } 101 }
101 } 102 }
102 } 103 }
103 })(); 104 })();
104 105
105 } 106 }
OLDNEW
« no previous file with comments | « test/mjsunit/d8-worker.js ('k') | test/mjsunit/harmony/futex.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698