2018-03-20 00:50:28 +01:00
|
|
|
// Copyright (C) 2018 Amal Hussein. All rights reserved.
|
|
|
|
// This code is governed by the BSD license found in the LICENSE file.
|
|
|
|
/*---
|
|
|
|
esid: sec-atomics.wait
|
|
|
|
description: >
|
|
|
|
Test that Atomics.wait returns the right result when it was awoken before
|
|
|
|
a timeout
|
|
|
|
info: |
|
|
|
|
Atomics.wait( typedArray, index, value, timeout )
|
|
|
|
|
|
|
|
2.Let i be ? ValidateAtomicAccess(typedArray, index).
|
|
|
|
...
|
|
|
|
2.Let accessIndex be ? ToIndex(requestIndex).
|
|
|
|
|
|
|
|
9.If IsSharedArrayBuffer(buffer) is false, throw a TypeError exception.
|
|
|
|
...
|
|
|
|
3.If bufferData is a Data Block, return false
|
|
|
|
|
|
|
|
If value is undefined, then
|
|
|
|
Let index be 0.
|
2018-05-21 20:23:15 +02:00
|
|
|
includes: [atomicsHelper.js]
|
|
|
|
features: [Atomics, BigInt, SharedArrayBuffer, TypedArray]
|
2018-03-20 00:50:28 +01:00
|
|
|
---*/
|
|
|
|
|
2018-05-21 20:23:15 +02:00
|
|
|
var sleeping = 10;
|
2018-03-20 00:50:28 +01:00
|
|
|
var timeout = 20000;
|
2018-04-19 16:11:50 +02:00
|
|
|
|
2018-04-25 23:29:53 +02:00
|
|
|
$262.agent.start(`
|
2018-05-21 20:23:15 +02:00
|
|
|
$262.agent.receiveBroadcast(function(sab) {
|
|
|
|
const i32a = new Int32Array(sab);
|
|
|
|
const before = $262.agent.monotonicNow();
|
|
|
|
const unpark = Atomics.wait(i32a, 0, 0, ${timeout});
|
|
|
|
$262.agent.report($262.agent.monotonicNow() - before);
|
|
|
|
$262.agent.report(unpark);
|
|
|
|
$262.agent.leaving();
|
|
|
|
});
|
2018-04-19 16:11:50 +02:00
|
|
|
`);
|
|
|
|
|
2018-05-21 20:23:15 +02:00
|
|
|
const i32a = new Int32Array(
|
|
|
|
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)
|
|
|
|
);
|
2018-04-19 16:11:50 +02:00
|
|
|
|
2018-04-26 17:26:34 +02:00
|
|
|
$262.agent.broadcast(i32a.buffer);
|
2018-04-19 16:11:50 +02:00
|
|
|
$262.agent.sleep(sleeping);
|
|
|
|
|
2018-04-26 17:26:34 +02:00
|
|
|
assert.sameValue(Atomics.wake(i32a, 0), 1);
|
2018-04-19 16:11:50 +02:00
|
|
|
|
2018-05-21 20:23:15 +02:00
|
|
|
const lapse = getReport();
|
|
|
|
|
|
|
|
assert(
|
|
|
|
sleeping + lapse < timeout,
|
|
|
|
`${sleeping + lapse} should be less than ${timeout}`
|
|
|
|
);
|
|
|
|
assert.sameValue(getReport(), 'ok');
|
|
|
|
|
2018-04-19 16:11:50 +02:00
|
|
|
|