Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/Atomics/wait/no-spurious-wakeup.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 that Atomics.wait actually waits and does not spuriously wake
8 up when the memory value is changed.
9 includes: [atomicsHelper.js]
10 ---*/
11
12 $262.agent.start(
13 `
14 $262.agent.receiveBroadcast(function (sab, id) {
15 var ia = new Int32Array(sab);
16 var then = Date.now();
17 Atomics.wait(ia, 0, 0);
18 var diff = Date.now() - then; // Should be about 1000 ms but can be more
19 $262.agent.report(diff);
20 $262.agent.leaving();
21 })
22 `);
23
24 var ia = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT));
25
26 $262.agent.broadcast(ia.buffer);
27 $262.agent.sleep(500); // Give the agent a chance to wait
28 Atomics.store(ia, 0, 1); // Change the value, should not wake the agent
29 $262.agent.sleep(500); // Wait some more so that we can tell
30 Atomics.wake(ia, 0); // Really wake it up
31 assert.sameValue((getReport() | 0) >= 1000 - $ATOMICS_MAX_TIME_EPSILON, true);
32
33 function getReport() {
34 var r;
35 while ((r = $262.agent.getReport()) == null)
36 $262.agent.sleep(100);
37 return r;
38 }