test262/test/built-ins/Atomics/waitAsync/false-for-timeout-agent.js

77 lines
1.8 KiB
JavaScript
Raw Normal View History

// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-atomics.waitasync
description: >
False timeout arg should result in an +0 timeout
info: |
Atomics.waitAsync( typedArray, index, value, timeout )
1. Return DoWait(async, typedArray, index, value, timeout).
DoWait ( mode, typedArray, index, value, timeout )
6. Let q be ? ToNumber(timeout).
includes: [atomicsHelper.js]
features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics]
---*/
const RUNNING = 1;
$262.agent.start(`
const valueOf = {
valueOf() {
return false;
}
};
const toPrimitive = {
[Symbol.toPrimitive]() {
return false;
}
};
$262.agent.receiveBroadcast(async (sab) => {
const i32a = new Int32Array(sab);
Atomics.add(i32a, ${RUNNING}, 1);
const status1 = await Atomics.waitAsync(i32a, 0, 0, false).value;
const status2 = await Atomics.waitAsync(i32a, 0, 0, valueOf).value;
const status3 = await Atomics.waitAsync(i32a, 0, 0, toPrimitive).value;
$262.agent.report(status1);
$262.agent.report(status2);
$262.agent.report(status3);
$262.agent.leaving();
});
`);
const i32a = new Int32Array(
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
);
$262.agent.safeBroadcast(i32a);
$262.agent.waitUntil(i32a, RUNNING, 1);
// Try to yield control to ensure the agent actually started to wait.
$262.agent.tryYield();
assert.sameValue(
$262.agent.getReport(),
'timed-out',
'$262.agent.getReport() returns "timed-out"'
);
assert.sameValue(
$262.agent.getReport(),
'timed-out',
'$262.agent.getReport() returns "timed-out"'
);
assert.sameValue(
$262.agent.getReport(),
'timed-out',
'$262.agent.getReport() returns "timed-out"'
);
assert.sameValue(Atomics.notify(i32a, 0), 0, 'Atomics.notify(i32a, 0) returns 0');