Debian Codegraph @

js/src/tests/test262/built-ins/Atomics/wait/good-views.js

raw
1 // |reftest| skip-if(!this.hasOwnProperty('Atomics')) -- Atomics is not enabled unconditionally
2 // Copyright (C) 2017 Mozilla Corporation. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4
5 /*---
6 esid: sec-atomics.wait
7 description: >
8 Test Atomics.wait on arrays that allow atomic operations,
9 in an Agent that is allowed to wait.
10 includes: [atomicsHelper.js]
11 features: [Atomics]
12 ---*/
13
14 // Let's assume 'wait' is not allowed on the main thread,
15 // even in the shell.
16
17 $262.agent.start(`
18 var sab = new SharedArrayBuffer(1024);
19 var ab = new ArrayBuffer(16);
20
21 var good_indices = [ (view) => 0/-1, // -0
22 (view) => '-0',
23 (view) => view.length - 1,
24 (view) => ({ valueOf: () => 0 }),
25 (view) => ({ toString: () => '0', valueOf: false }) // non-callable valueOf triggers invocation of toString
26 ];
27
28 var view = new Int32Array(sab, 32, 20);
29
30 view[0] = 0;
31 $262.agent.report("A " + Atomics.wait(view, 0, 0, 0))
32 $262.agent.report("B " + Atomics.wait(view, 0, 37, 0));
33
34 // In-bounds boundary cases for indexing
35 for ( let IdxGen of good_indices ) {
36 let Idx = IdxGen(view);
37 view.fill(0);
38 // Atomics.store() computes an index from Idx in the same way as other
39 // Atomics operations, not quite like view[Idx].
40 Atomics.store(view, Idx, 37);
41 $262.agent.report("C " + Atomics.wait(view, Idx, 0));
42 }
43
44 $262.agent.report("done");
45 $262.agent.leaving();
46 `);
47
48 assert.sameValue(
49 $262.agent.getReport(),
50 'A timed-out',
51 '$262.agent.getReport() returns "A timed-out"'
52 );
53
54 assert.sameValue(
55 $262.agent.getReport(),
56 'B not-equal',
57 '$262.agent.getReport() returns "B not-equal"'
58 );
59
60 var r;
61 while ((r = $262.agent.getReport()) !== "done") {
62 assert.sameValue(
63 r,
64 'C not-equal',
65 '$262.agent.getReport() returns "C not-equal"'
66 );
67 }
68
69 reportCompare(0, 0);