Debian Codegraph @

js/src/tests/test262/built-ins/Atomics/wait/was-woken-before-timeout.js

raw
1 // |reftest| skip-if(!this.hasOwnProperty('Atomics')||!this.hasOwnProperty('SharedArrayBuffer')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration('arm64-simulator'))) -- Atomics,SharedArrayBuffer is not enabled unconditionally, ARM64 Simulator cannot emulate atomics
2 // Copyright (C) 2018 Amal Hussein. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4 /*---
5 esid: sec-atomics.wait
6 description: >
7 Test that Atomics.wait returns the right result when it was awoken before
8 a timeout
9 info: |
10 Atomics.wait( typedArray, index, value, timeout )
11
12 2.Let i be ? ValidateAtomicAccess(typedArray, index).
13 ...
14 2.Let accessIndex be ? ToIndex(requestIndex).
15
16 9.If IsSharedArrayBuffer(buffer) is false, throw a TypeError exception.
17 ...
18 3.If bufferData is a Data Block, return false
19
20 If value is undefined, then
21 Let index be 0.
22 includes: [atomicsHelper.js]
23 features: [Atomics, SharedArrayBuffer, TypedArray]
24 ---*/
25
26 const RUNNING = 1;
27 const TIMEOUT = $262.agent.timeouts.huge;
28
29 $262.agent.start(`
30 $262.agent.receiveBroadcast(function(sab) {
31 const i32a = new Int32Array(sab);
32 Atomics.add(i32a, ${RUNNING}, 1);
33
34 const before = $262.agent.monotonicNow();
35 const unpark = Atomics.wait(i32a, 0, 0, ${TIMEOUT});
36 const duration = $262.agent.monotonicNow() - before;
37
38 $262.agent.report(duration);
39 $262.agent.report(unpark);
40 $262.agent.leaving();
41 });
42 `);
43
44 const i32a = new Int32Array(
45 new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
46 );
47
48 $262.agent.safeBroadcast(i32a);
49 $262.agent.waitUntil(i32a, RUNNING, 1);
50
51 // Try to yield control to ensure the agent actually started to wait.
52 $262.agent.tryYield();
53
54 assert.sameValue(Atomics.notify(i32a, 0), 1, 'Atomics.notify(i32a, 0) returns 1');
55
56 const lapse = $262.agent.getReport();
57
58 assert(
59 lapse < TIMEOUT,
60 'The result of `(lapse < TIMEOUT)` is true'
61 );
62 assert.sameValue($262.agent.getReport(), 'ok', '$262.agent.getReport() returns "ok"');
63
64 reportCompare(0, 0);