| 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 times out with a negative timeout |
| 8 |
info: | |
| 9 |
Atomics.waitAsync( typedArray, index, value, timeout ) |
| 10 |
|
| 11 |
1. Return DoWait(async, typedArray, index, value, timeout). |
| 12 |
|
| 13 |
DoWait ( mode, typedArray, index, value, timeout ) |
| 14 |
|
| 15 |
6. Let q be ? ToNumber(timeout). |
| 16 |
|
| 17 |
flags: [async] |
| 18 |
includes: [atomicsHelper.js] |
| 19 |
features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, BigInt, arrow-function, async-functions] |
| 20 |
---*/ |
| 21 |
assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); |
| 22 |
const RUNNING = 1; |
| 23 |
|
| 24 |
$262.agent.start(` |
| 25 |
$262.agent.receiveBroadcast(async (sab) => { |
| 26 |
var i64a = new BigInt64Array(sab); |
| 27 |
Atomics.add(i64a, ${RUNNING}, 1n); |
| 28 |
$262.agent.report(await Atomics.waitAsync(i64a, 0, 0n, -5).value); // -5 => 0 |
| 29 |
$262.agent.leaving(); |
| 30 |
}); |
| 31 |
`); |
| 32 |
|
| 33 |
const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); |
| 34 |
|
| 35 |
$262.agent.safeBroadcastAsync(i64a, RUNNING, 1n).then(async agentCount => { |
| 36 |
assert.sameValue(agentCount, 1n, 'The value of `agentCount` is 1n'); |
| 37 |
|
| 38 |
assert.sameValue( |
| 39 |
await $262.agent.getReportAsync(), |
| 40 |
'timed-out', |
| 41 |
'(await $262.agent.getReportAsync()) resolves to the value "timed-out"' |
| 42 |
); |
| 43 |
|
| 44 |
assert.sameValue( |
| 45 |
Atomics.notify(i64a, 0), |
| 46 |
0, |
| 47 |
'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0) must return 0' |
| 48 |
); |
| 49 |
}).then($DONE, $DONE); |