| 1 |
// |reftest| shell-option(--setpref=atomics_wait_async) skip-if(!this.hasOwnProperty('Atomics')||!xulRuntime.shell) async -- Atomics is not enabled unconditionally, 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 |
Test Atomics.waitAsync on arrays that allow atomic operations |
| 9 |
flags: [async] |
| 10 |
includes: [atomicsHelper.js, asyncHelpers.js] |
| 11 |
features: [Atomics.waitAsync, Atomics, BigInt] |
| 12 |
---*/ |
| 13 |
assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); |
| 14 |
|
| 15 |
$262.agent.start(` |
| 16 |
(async () => { |
| 17 |
var sab = new SharedArrayBuffer(2048); |
| 18 |
var good_indices = [ (view) => 0/-1, // -0 |
| 19 |
(view) => '-0', |
| 20 |
(view) => view.length - 1, |
| 21 |
(view) => ({ valueOf: () => 0 }), |
| 22 |
(view) => ({ toString: () => '0', valueOf: false }) // non-callable valueOf triggers invocation of toString |
| 23 |
]; |
| 24 |
|
| 25 |
var view = new BigInt64Array(sab, 32, 20); |
| 26 |
|
| 27 |
view[0] = 0n; |
| 28 |
$262.agent.report("A " + (await Atomics.waitAsync(view, 0, 0n, 0).value)) |
| 29 |
$262.agent.report("B " + (await Atomics.waitAsync(view, 0, 37n, 0).value)); |
| 30 |
|
| 31 |
const results = []; |
| 32 |
// In-bounds boundary cases for indexing |
| 33 |
for ( let IdxGen of good_indices ) { |
| 34 |
let Idx = IdxGen(view); |
| 35 |
view.fill(0n); |
| 36 |
// Atomics.store() computes an index from Idx in the same way as other |
| 37 |
// Atomics operations, not quite like view[Idx]. |
| 38 |
Atomics.store(view, Idx, 37n); |
| 39 |
results.push(await Atomics.waitAsync(view, Idx, 0n).value); |
| 40 |
} |
| 41 |
$262.agent.report("C " + results.join(",")); |
| 42 |
|
| 43 |
$262.agent.leaving(); |
| 44 |
})(); |
| 45 |
`); |
| 46 |
|
| 47 |
|
| 48 |
asyncTest(async () => { |
| 49 |
const outcomes = []; |
| 50 |
|
| 51 |
for (let i = 0; i < 3; i++) { |
| 52 |
outcomes.push(await $262.agent.getReportAsync()); |
| 53 |
} |
| 54 |
|
| 55 |
assert.sameValue( |
| 56 |
outcomes[0], |
| 57 |
'A timed-out', |
| 58 |
'The value of outcomes[0] is "A timed-out"' |
| 59 |
); |
| 60 |
|
| 61 |
assert.sameValue( |
| 62 |
outcomes[1], |
| 63 |
'B not-equal', |
| 64 |
'The value of outcomes[1] is "B not-equal"' |
| 65 |
); |
| 66 |
assert.sameValue( |
| 67 |
outcomes[2], |
| 68 |
'C not-equal,not-equal,not-equal,not-equal,not-equal', |
| 69 |
'The value of outcomes[2] is "C not-equal,not-equal,not-equal,not-equal,not-equal"' |
| 70 |
); |
| 71 |
}); |