Debian Codegraph @

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

raw
1 // |reftest| shell-option(--setpref=atomics_wait_async) skip-if(!this.hasOwnProperty('SharedArrayBuffer')||!this.hasOwnProperty('Atomics')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration('arm64-simulator'))||!xulRuntime.shell) async -- SharedArrayBuffer,Atomics is not enabled unconditionally, ARM64 Simulator cannot emulate atomics, requires shell-options
2 // Copyright (C) 2020 Rick Waldron. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4 /*---
5 esid: sec-atomics.waitasync
6 description: >
7 Test that Atomics.waitAsync returns the right result when it was awoken before
8 a timeout
9 flags: [async]
10 includes: [atomicsHelper.js]
11 features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, arrow-function, async-functions]
12 ---*/
13 assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"');
14
15 const RUNNING = 1;
16 const TIMEOUT = $262.agent.timeouts.huge;
17
18 const i32a = new Int32Array(
19 new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
20 );
21
22 $262.agent.start(`
23 $262.agent.receiveBroadcast(async (sab) => {
24 const i32a = new Int32Array(sab);
25 Atomics.add(i32a, ${RUNNING}, 1);
26
27 const before = $262.agent.monotonicNow();
28 const unpark = await Atomics.waitAsync(i32a, 0, 0, ${TIMEOUT}).value;
29 const duration = $262.agent.monotonicNow() - before;
30
31 $262.agent.report(duration);
32 $262.agent.report(unpark);
33 $262.agent.leaving();
34 });
35 `);
36
37 $262.agent.safeBroadcastAsync(i32a, RUNNING, 1).then(async (agentCount) => {
38
39 assert.sameValue(agentCount, 1, 'The value of `agentCount` is 1');
40 assert.sameValue(Atomics.notify(i32a, 0), 1, 'Atomics.notify(new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)), 0) must return 1');
41
42 let lapse = await $262.agent.getReportAsync();
43
44 assert(
45 lapse < TIMEOUT,
46 'The result of evaluating `(lapse < TIMEOUT)` is true'
47 );
48
49 assert.sameValue(
50 await $262.agent.getReportAsync(),
51 'ok',
52 '(await $262.agent.getReportAsync()) resolves to the value "ok"'
53 );
54 assert.sameValue(Atomics.notify(i32a, 0), 0, 'Atomics.notify(new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)), 0) must return 0');
55 }).then($DONE, $DONE);