OLD | NEW |
(Empty) | |
| 1 function verifyArray(ta, length) { |
| 2 for (i = 0; i < length; ++i) { |
| 3 if (ta[i] != i) { |
| 4 postMessage("FAIL: Transferred data is incorrect. Expected " + |
| 5 i + " got " + ta[i]); |
| 6 return; |
| 7 } |
| 8 } |
| 9 postMessage("PASS: Transferred data is OK."); |
| 10 } |
| 11 |
| 12 function verifyArrayType(ta, name) { |
| 13 var className = Object.prototype.toString.call(ta); |
| 14 if (className.indexOf(name) != -1) |
| 15 postMessage("PASS: Transferred array type is OK."); |
| 16 else |
| 17 postMessage("FAIL: Expected array type " + name + " got " + className); |
| 18 } |
| 19 |
| 20 self.addEventListener('message', function(e) { |
| 21 var i; |
| 22 var sab; |
| 23 var ta; |
| 24 |
| 25 switch (e.data.name) { |
| 26 case 'SharedArrayBuffer': |
| 27 sab = e.data.data; |
| 28 ta = new Uint8Array(sab); |
| 29 verifyArray(ta, e.data.length); |
| 30 break; |
| 31 |
| 32 case 'Int8Array': |
| 33 case 'Uint8Array': |
| 34 case 'Uint8ClampedArray': |
| 35 case 'Int16Array': |
| 36 case 'Uint16Array': |
| 37 case 'Int32Array': |
| 38 case 'Uint32Array': |
| 39 case 'Float32Array': |
| 40 case 'Float64Array': |
| 41 ta = e.data.data; |
| 42 verifyArrayType(ta, e.data.name); |
| 43 verifyArray(ta, e.data.length); |
| 44 break; |
| 45 |
| 46 default: |
| 47 postMessage("ERROR: unknown command " + e.data.name); |
| 48 break; |
| 49 } |
| 50 postMessage("DONE"); |
| 51 }); |
OLD | NEW |