summaryrefslogtreecommitdiffstats
path: root/js/src/tests/shell/futex-apis.js
blob: dd38a1c98b0ebc658a3f8f20ead3e836947cef59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// |reftest| skip-if(!xulRuntime.shell)
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/licenses/publicdomain/
 */

if (this.SharedArrayBuffer && this.Atomics) {

// Checks for parameter validation of wait/wake API.  All of these test
// cases should throw exceptions during parameter validation, before
// we check whether any waiting should be done.

let ab = new ArrayBuffer(16);
let sab = new SharedArrayBuffer(16);

//////////////////////////////////////////////////////////////////////
//
// The view must be an Int32Array on a SharedArrayBuffer.

// Check against non-TypedArray cases.

{
    let values = [null,
		  undefined,
		  true,
		  false,
		  new Boolean(true),
		  10,
		  3.14,
		  new Number(4),
		  "Hi there",
		  new Date,
		  /a*utomaton/g,
		  { password: "qumquat" },
		  new DataView(new ArrayBuffer(10)),
		  new ArrayBuffer(128),
		  new SharedArrayBuffer(128),
		  new Error("Ouch"),
		  [1,1,2,3,5,8],
		  ((x) => -x),
		  new Map(),
		  new Set(),
		  new WeakMap(),
		  new WeakSet(),
		  new Promise(() => "done"),
		  Symbol("halleluja"),
		  // TODO: Proxy?
		  Object,
		  Int32Array,
		  Date,
		  Math,
		  Atomics ];

    for ( let i=0 ; i < values.length ; i++ ) {
	let view = values[i];
	assertThrowsInstanceOf(() => Atomics.wait(view, 0, 0), TypeError);
	assertThrowsInstanceOf(() => Atomics.wake(view, 0), TypeError);
    }
}

// Check against TypedArray on non-shared memory and wrong view types cases.

{
    let views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Uint32Array,
      Uint8ClampedArray, Float32Array, Float64Array];

    for ( let View of views ) {
	let view = new View(ab);

	assertThrowsInstanceOf(() => Atomics.wait(view, 0, 0), TypeError);
	assertThrowsInstanceOf(() => Atomics.wake(view, 0), TypeError);
    }
}

// Check against TypedArray on non-shared memory and correct view types cases.

{
    let views = [Int32Array];

    for ( let View of views ) {
        let view = new View(ab);

        assertThrowsInstanceOf(() => Atomics.wait(view, 0, 0), TypeError);
        assertEq(Atomics.wake(view, 0, 0), 0);
    }
}

// Check against TypedArray on shared memory, but wrong view type

{
    let views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Uint32Array,
		 Uint8ClampedArray, Float32Array, Float64Array];

    for ( let View of views ) {
	let view = new View(sab);

	assertThrowsInstanceOf(() => Atomics.wait(view, 0, 0), TypeError);
	assertThrowsInstanceOf(() => Atomics.wake(view, 0), TypeError);
    }
}

//////////////////////////////////////////////////////////////////////
//
// The indices must be in the range of the array

{
    let view = new Int32Array(sab);

    let indices = [ (view) => -1,
		    (view) => view.length,
		    (view) => view.length*2,
		    (view) => '-3.5',
	            (view) => ({ valueOf: () => -8 }) ];

    for ( let iidx=0 ; iidx < indices.length ; iidx++ ) {
	let Idx = indices[iidx](view);
	assertThrowsInstanceOf(() => Atomics.wait(view, Idx, 10), RangeError);
	assertThrowsInstanceOf(() => Atomics.wake(view, Idx), RangeError);
    }
}

} // if (this.SharedArrayBuffer && this.Atomics) { ... }

reportCompare(true,true);