| 1 |
// |reftest| skip-if(!xulRuntime.shell) |
| 2 |
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 3 |
/* |
| 4 |
* Any copyright is dedicated to the Public Domain. |
| 5 |
* http://creativecommons.org/licenses/publicdomain/ |
| 6 |
*/ |
| 7 |
|
| 8 |
if (this.SharedArrayBuffer && this.Atomics) { |
| 9 |
|
| 10 |
// Checks for parameter validation of wait/wake API. All of these test |
| 11 |
// cases should throw exceptions during parameter validation, before |
| 12 |
// we check whether any waiting should be done. |
| 13 |
|
| 14 |
let ab = new ArrayBuffer(16); |
| 15 |
let sab = new SharedArrayBuffer(16); |
| 16 |
|
| 17 |
////////////////////////////////////////////////////////////////////// |
| 18 |
// |
| 19 |
// The view must be an Int32Array on a SharedArrayBuffer. |
| 20 |
|
| 21 |
// Check against non-TypedArray cases. |
| 22 |
|
| 23 |
{ |
| 24 |
let values = [null, |
| 25 |
undefined, |
| 26 |
true, |
| 27 |
false, |
| 28 |
new Boolean(true), |
| 29 |
10, |
| 30 |
3.14, |
| 31 |
new Number(4), |
| 32 |
"Hi there", |
| 33 |
new Date, |
| 34 |
/a*utomaton/g, |
| 35 |
{ password: "qumquat" }, |
| 36 |
new DataView(new ArrayBuffer(10)), |
| 37 |
new ArrayBuffer(128), |
| 38 |
new SharedArrayBuffer(128), |
| 39 |
new Error("Ouch"), |
| 40 |
[1,1,2,3,5,8], |
| 41 |
((x) => -x), |
| 42 |
new Map(), |
| 43 |
new Set(), |
| 44 |
new WeakMap(), |
| 45 |
new WeakSet(), |
| 46 |
new Promise(() => "done"), |
| 47 |
Symbol("halleluja"), |
| 48 |
// TODO: Proxy? |
| 49 |
Object, |
| 50 |
Int32Array, |
| 51 |
Date, |
| 52 |
Math, |
| 53 |
Atomics ]; |
| 54 |
|
| 55 |
for ( let i=0 ; i < values.length ; i++ ) { |
| 56 |
let view = values[i]; |
| 57 |
assertThrowsInstanceOf(() => Atomics.wait(view, 0, 0), TypeError); |
| 58 |
assertThrowsInstanceOf(() => Atomics.wake(view, 0), TypeError); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
// Check against TypedArray on non-shared memory and wrong view types cases. |
| 63 |
|
| 64 |
{ |
| 65 |
let views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Uint32Array, |
| 66 |
Uint8ClampedArray, Float32Array, Float64Array]; |
| 67 |
|
| 68 |
for ( let View of views ) { |
| 69 |
let view = new View(ab); |
| 70 |
|
| 71 |
assertThrowsInstanceOf(() => Atomics.wait(view, 0, 0), TypeError); |
| 72 |
assertThrowsInstanceOf(() => Atomics.wake(view, 0), TypeError); |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
// Check against TypedArray on non-shared memory and correct view types cases. |
| 77 |
|
| 78 |
{ |
| 79 |
let views = [Int32Array]; |
| 80 |
|
| 81 |
for ( let View of views ) { |
| 82 |
let view = new View(ab); |
| 83 |
|
| 84 |
assertThrowsInstanceOf(() => Atomics.wait(view, 0, 0), TypeError); |
| 85 |
assertEq(Atomics.wake(view, 0, 0), 0); |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
// Check against TypedArray on shared memory, but wrong view type |
| 90 |
|
| 91 |
{ |
| 92 |
let views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Uint32Array, |
| 93 |
Uint8ClampedArray, Float32Array, Float64Array]; |
| 94 |
|
| 95 |
for ( let View of views ) { |
| 96 |
let view = new View(sab); |
| 97 |
|
| 98 |
assertThrowsInstanceOf(() => Atomics.wait(view, 0, 0), TypeError); |
| 99 |
assertThrowsInstanceOf(() => Atomics.wake(view, 0), TypeError); |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
////////////////////////////////////////////////////////////////////// |
| 104 |
// |
| 105 |
// The indices must be in the range of the array |
| 106 |
|
| 107 |
{ |
| 108 |
let view = new Int32Array(sab); |
| 109 |
|
| 110 |
let indices = [ (view) => -1, |
| 111 |
(view) => view.length, |
| 112 |
(view) => view.length*2, |
| 113 |
(view) => '-3.5', |
| 114 |
(view) => ({ valueOf: () => -8 }) ]; |
| 115 |
|
| 116 |
for ( let iidx=0 ; iidx < indices.length ; iidx++ ) { |
| 117 |
let Idx = indices[iidx](view); |
| 118 |
assertThrowsInstanceOf(() => Atomics.wait(view, Idx, 10), RangeError); |
| 119 |
assertThrowsInstanceOf(() => Atomics.wake(view, Idx), RangeError); |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
} // if (this.SharedArrayBuffer && this.Atomics) { ... } |
| 124 |
|
| 125 |
reportCompare(true,true); |