Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/Atomics/wait/did-timeout.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 returns the right result when it timed out and that
8 the time to time out is reasonable.
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 $262.agent.report(Atomics.wait(ia, 0, 0, 500)); // Timeout 500ms
18 $262.agent.report(Date.now() - then); // Actual time can be more than 500ms
19 $262.agent.leaving();
20 })
21 `);
22
23 var ia = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT));
24
25 $262.agent.broadcast(ia.buffer);
26 assert.sameValue(getReport(), "timed-out");
27 assert.sameValue((getReport() | 0) >= 500 - $ATOMICS_MAX_TIME_EPSILON, true);
28
29 function getReport() {
30 var r;
31 while ((r = $262.agent.getReport()) == null)
32 $262.agent.sleep(100);
33 return r;
34 }