| 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 |
/*--- |
| 6 |
esid: sec-atomics.waitasync |
| 7 |
description: > |
| 8 |
Waiter does not spuriously notify on index which is subject to Sub operation |
| 9 |
info: | |
| 10 |
AddWaiter ( WL, waiterRecord ) |
| 11 |
|
| 12 |
5. Append waiterRecord as the last element of WL.[[Waiters]] |
| 13 |
6. If waiterRecord.[[Timeout]] is finite, then in parallel, |
| 14 |
a. Wait waiterRecord.[[Timeout]] milliseconds. |
| 15 |
b. Perform TriggerTimeout(WL, waiterRecord). |
| 16 |
|
| 17 |
TriggerTimeout( WL, waiterRecord ) |
| 18 |
|
| 19 |
3. If waiterRecord is in WL.[[Waiters]], then |
| 20 |
a. Set waiterRecord.[[Result]] to "timed-out". |
| 21 |
b. Perform RemoveWaiter(WL, waiterRecord). |
| 22 |
c. Perform NotifyWaiter(WL, waiterRecord). |
| 23 |
4. Perform LeaveCriticalSection(WL). |
| 24 |
|
| 25 |
flags: [async] |
| 26 |
includes: [atomicsHelper.js] |
| 27 |
features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, arrow-function, async-functions] |
| 28 |
---*/ |
| 29 |
assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); |
| 30 |
|
| 31 |
const RUNNING = 1; |
| 32 |
const TIMEOUT = $262.agent.timeouts.small; |
| 33 |
|
| 34 |
const i32a = new Int32Array( |
| 35 |
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4) |
| 36 |
); |
| 37 |
|
| 38 |
$262.agent.start(` |
| 39 |
$262.agent.receiveBroadcast(async (sab) => { |
| 40 |
const i32a = new Int32Array(sab); |
| 41 |
Atomics.add(i32a, ${RUNNING}, 1); |
| 42 |
|
| 43 |
const before = $262.agent.monotonicNow(); |
| 44 |
const unpark = await Atomics.waitAsync(i32a, 0, 0, ${TIMEOUT}).value; |
| 45 |
const duration = $262.agent.monotonicNow() - before; |
| 46 |
|
| 47 |
$262.agent.report(duration); |
| 48 |
$262.agent.report(unpark); |
| 49 |
$262.agent.leaving(); |
| 50 |
}); |
| 51 |
`); |
| 52 |
|
| 53 |
$262.agent.safeBroadcastAsync(i32a, RUNNING, 1).then(async (agentCount) => { |
| 54 |
|
| 55 |
assert.sameValue(agentCount, 1, 'The value of `agentCount` is 1'); |
| 56 |
|
| 57 |
Atomics.sub(i32a, 0, 1); |
| 58 |
|
| 59 |
const lapse = await $262.agent.getReportAsync(); |
| 60 |
|
| 61 |
assert( |
| 62 |
lapse >= TIMEOUT, |
| 63 |
'The result of evaluating `(lapse >= TIMEOUT)` is true' |
| 64 |
); |
| 65 |
|
| 66 |
const result = await $262.agent.getReportAsync(); |
| 67 |
|
| 68 |
assert.sameValue( |
| 69 |
result, |
| 70 |
'timed-out', |
| 71 |
'The value of `result` is "timed-out"' |
| 72 |
); |
| 73 |
assert.sameValue(Atomics.notify(i32a, 0), 0, 'Atomics.notify(new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)), 0) must return 0'); |
| 74 |
}).then($DONE, $DONE); |