Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/Atomics/wait/good-views.js

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