| 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 |
An undefined index arg should translate to 0 |
| 8 |
info: | |
| 9 |
Atomics.wait( typedArray, index, value, timeout ) |
| 10 |
|
| 11 |
2.Let i be ? ValidateAtomicAccess(typedArray, index). |
| 12 |
... |
| 13 |
2.Let accessIndex be ? ToIndex(requestIndex). |
| 14 |
|
| 15 |
9.If IsSharedArrayBuffer(buffer) is false, throw a TypeError exception. |
| 16 |
... |
| 17 |
3.If bufferData is a Data Block, return false |
| 18 |
|
| 19 |
If value is undefined, then |
| 20 |
Let index be 0. |
| 21 |
|
| 22 |
includes: [atomicsHelper.js] |
| 23 |
features: [Atomics, SharedArrayBuffer, TypedArray] |
| 24 |
---*/ |
| 25 |
|
| 26 |
const RUNNING = 1; |
| 27 |
const TIMEOUT = $262.agent.timeouts.long; |
| 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 |
$262.agent.report(Atomics.wait(i32a, undefined, 0, ${TIMEOUT})); // undefined index => 0 |
| 35 |
$262.agent.leaving(); |
| 36 |
}); |
| 37 |
`); |
| 38 |
|
| 39 |
const i32a = new Int32Array( |
| 40 |
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4) |
| 41 |
); |
| 42 |
|
| 43 |
$262.agent.safeBroadcast(i32a); |
| 44 |
$262.agent.waitUntil(i32a, RUNNING, 1); |
| 45 |
|
| 46 |
// Try to yield control to ensure the agent actually started to wait. |
| 47 |
$262.agent.tryYield(); |
| 48 |
|
| 49 |
assert.sameValue(Atomics.notify(i32a, 0), 1, 'Atomics.notify(i32a, 0) returns 1'); // notify at index 0 |
| 50 |
assert.sameValue(Atomics.notify(i32a, 0), 0, 'Atomics.notify(i32a, 0) returns 0'); // notify again at index 0, and 0 agents should be woken |
| 51 |
assert.sameValue($262.agent.getReport(), 'ok', '$262.agent.getReport() returns "ok"'); |
| 52 |
|
| 53 |
reportCompare(0, 0); |