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.
|
|
|
|
features: [Atomics, SharedArrayBuffer, TypedArray]
|
|
|
|
---*/
|
|
|
|
|
2018-04-19 16:11:50 +02:00
|
|
|
var sleeping = 100;
|
2018-03-20 00:50:28 +01:00
|
|
|
var timeout = 20000;
|
2018-04-19 16:11:50 +02:00
|
|
|
|
|
|
|
function getReport() {
|
|
|
|
var r;
|
|
|
|
while ((r = $262.agent.getReport()) == null) {
|
|
|
|
sleeping += 100;
|
|
|
|
$262.agent.sleep(100);
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2018-03-20 00:50:28 +01:00
|
|
|
$262.agent.start(
|
2018-04-19 16:11:50 +02:00
|
|
|
`
|
|
|
|
$262.agent.receiveBroadcast(function(sab) {
|
2018-03-20 00:50:28 +01:00
|
|
|
var int32Array = new Int32Array(sab);
|
2018-04-19 16:11:50 +02:00
|
|
|
$262.agent.report(Atomics.wait(int32Array, 0, 0, ${timeout}));
|
|
|
|
$262.agent.leaving();
|
|
|
|
});
|
|
|
|
`);
|
|
|
|
|
|
|
|
var sab = new SharedArrayBuffer(4);
|
|
|
|
var int32Array = new Int32Array(sab);
|
|
|
|
|
|
|
|
|
|
|
|
$262.agent.broadcast(int32Array.buffer);
|
|
|
|
$262.agent.sleep(sleeping);
|
|
|
|
|
|
|
|
assert.sameValue(Atomics.wake(int32Array, 0), 1);
|
|
|
|
|
|
|
|
assert.sameValue(getReport(), "ok");
|
|
|
|
assert(sleeping < timeout, "this test assumes it won't last for more than 20 seconds");
|
|
|
|
|