OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <body> |
| 4 <p>Test sharing SharedArrayBuffers between dedicated workers.</p> |
| 5 <div id="result"></div> |
| 6 <script type="text/javascript"> |
| 7 function log(message) |
| 8 { |
| 9 document.getElementById("result").innerHTML += message + "</br>"; |
| 10 } |
| 11 |
| 12 if (window.testRunner) { |
| 13 testRunner.dumpAsText(); |
| 14 testRunner.waitUntilDone(); |
| 15 } |
| 16 |
| 17 var testCases = [ |
| 18 {name: "SharedArrayBuffer"}, |
| 19 {name: "Int8Array"}, |
| 20 {name: "Uint8Array"}, |
| 21 {name: "Uint8ClampedArray"}, |
| 22 {name: "Int16Array"}, |
| 23 {name: "Uint16Array"}, |
| 24 {name: "Int32Array"}, |
| 25 {name: "Uint32Array"}, |
| 26 {name: "Float32Array"}, |
| 27 {name: "Float64Array"} |
| 28 ]; |
| 29 var currentTestCase = 0; |
| 30 |
| 31 function runTestCase(testCase) { |
| 32 var length = 8; |
| 33 var name = testCase.name; |
| 34 var type = window[name]; |
| 35 var sab; |
| 36 var ta; |
| 37 |
| 38 log("Running " + name + " test case"); |
| 39 |
| 40 if (testCase.name == 'SharedArrayBuffer') { |
| 41 sab = new SharedArrayBuffer(length); |
| 42 ta = new Uint8Array(sab); |
| 43 } else { |
| 44 sab = new SharedArrayBuffer(length * type.BYTES_PER_ELEMENT); |
| 45 ta = new type(sab); |
| 46 } |
| 47 |
| 48 var i; |
| 49 for (i = 0; i < length; ++i) |
| 50 ta[i] = i; |
| 51 |
| 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]); |
| 57 else |
| 58 worker.postMessage({name: name, data: ta, length: length}, [sab]); |
| 59 |
| 60 if (sab.length === 0) |
| 61 log("FAIL: SharedArrayBuffer was neutered during transfer."); |
| 62 else |
| 63 log("PASS: SharedArrayBuffer not neutered during transfer."); |
| 64 |
| 65 // Ensure the data wasn't changed. |
| 66 for (i = 0; i < length; ++i) { |
| 67 if (ta[i] != i) { |
| 68 log("FAIL: Original data changed during transfer. Expected " + i + |
| 69 " got " + ta[i]); |
| 70 break; |
| 71 } |
| 72 } |
| 73 if (i == length) |
| 74 log("PASS: Original data not changed during transfer."); |
| 75 } |
| 76 |
| 77 if (window.internals && internals.runtimeFlags.sharedArrayBufferEnabled && windo
w.SharedArrayBuffer) { |
| 78 var worker = new Worker('resources/worker-sharedarraybuffer-transfer.js'); |
| 79 |
| 80 runTestCase(testCases[currentTestCase]); |
| 81 |
| 82 worker.onmessage = function(e) { |
| 83 if (e.data == 'DONE') { |
| 84 // The current test case is finished. |
| 85 if (++currentTestCase == testCases.length) { |
| 86 log("DONE"); |
| 87 testRunner.notifyDone(); |
| 88 } else { |
| 89 runTestCase(testCases[currentTestCase]); |
| 90 } |
| 91 } else { |
| 92 // The worker sent a pass/fail message. |
| 93 log(e.data); |
| 94 } |
| 95 |
| 96 }; |
| 97 } else { |
| 98 log("SharedArrayBuffers are not enabled -- skipping test."); |
| 99 testRunner.notifyDone(); |
| 100 } |
| 101 |
| 102 </script> |
| 103 </body> |
| 104 </html> |
OLD | NEW |