4 <p>Test sharing SharedArrayBuffers between dedicated workers.
</p>
5 <div id=
"result"></div>
6 <script type=
"text/javascript">
9 document
.getElementById("result").innerHTML
+= message
+ "</br>";
12 if (window
.testRunner
) {
13 testRunner
.dumpAsText();
14 testRunner
.waitUntilDone();
18 {name
: "SharedArrayBuffer"},
21 {name
: "Uint8ClampedArray"},
23 {name
: "Uint16Array"},
25 {name
: "Uint32Array"},
26 {name
: "Float32Array"},
27 {name
: "Float64Array"}
29 var currentTestCase
= 0;
31 function runTestCase(testCase
) {
33 var name
= testCase
.name
;
34 var type
= window
[name
];
38 log("Running " + name
+ " test case");
40 if (testCase
.name
== 'SharedArrayBuffer') {
41 sab
= new SharedArrayBuffer(length
);
42 ta
= new Uint8Array(sab
);
44 sab
= new SharedArrayBuffer(length
* type
.BYTES_PER_ELEMENT
);
49 for (i
= 0; i
< length
; ++i
)
52 // Without Atomics, we can't safely test modifying the contents of the
53 // SharedArrayBuffer. All we can test for now is that the SharedArrayBuffer
54 // is not neutered when transferred to a Worker.
55 if (testCase
.name
== 'SharedArrayBuffer')
56 worker
.postMessage({name
: name
, data
: sab
, length
: length
}, [sab
]);
58 worker
.postMessage({name
: name
, data
: ta
, length
: length
}, [sab
]);
61 log("FAIL: SharedArrayBuffer was neutered during transfer.");
63 log("PASS: SharedArrayBuffer not neutered during transfer.");
65 // Ensure the data wasn't changed.
66 for (i
= 0; i
< length
; ++i
) {
68 log("FAIL: Original data changed during transfer. Expected " + i
+
74 log("PASS: Original data not changed during transfer.");
77 if (window
.internals
&& internals
.runtimeFlags
.sharedArrayBufferEnabled
&& window
.SharedArrayBuffer
) {
78 var worker
= new Worker('resources/worker-sharedarraybuffer-transfer.js');
80 runTestCase(testCases
[currentTestCase
]);
82 worker
.onmessage = function(e
) {
83 if (e
.data
== 'DONE') {
84 // The current test case is finished.
85 if (++currentTestCase
== testCases
.length
) {
87 testRunner
.notifyDone();
89 runTestCase(testCases
[currentTestCase
]);
92 // The worker sent a pass/fail message.
98 log("SharedArrayBuffers are not enabled -- skipping test.");
99 testRunner
.notifyDone();