Atomics.waitAsync: make all agent timeouts async

This commit is contained in:
Rick Waldron 2020-04-08 16:38:57 -04:00
parent f03c0c2de3
commit c3efb56025
11 changed files with 381 additions and 129 deletions

View File

@ -14,6 +14,7 @@ info: |
6. Let q be ? ToNumber(timeout).
flags: [async]
includes: [atomicsHelper.js]
features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics]
---*/
@ -48,40 +49,43 @@ $262.agent.start(`
const i32a = new Int32Array(
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
);
$262.agent.safeBroadcastAsync(i32a, RUNNING, 1).then(async (agentCount) => {
$262.agent.safeBroadcast(i32a);
$262.agent.waitUntil(i32a, RUNNING, 1);
$262.agent.tryYield();
assert.sameValue(agentCount, 1);
assert.sameValue(
await $262.agent.getReportAsync(),
'timed-out',
'await Atomics.waitAsync(i32a, 0, 0, false).value resolves to "timed-out"'
);
assert.sameValue(
await $262.agent.getReportAsync(),
'timed-out',
'await Atomics.waitAsync(i32a, 0, 0, valueOf).value resolves to "timed-out"'
);
assert.sameValue(
await $262.agent.getReportAsync(),
'timed-out',
'await Atomics.waitAsync(i32a, 0, 0, toPrimitive).value resolves to "timed-out"'
);
assert.sameValue(
await $262.agent.getReportAsync(),
'timed-out',
'Atomics.waitAsync(i32a, 0, 0, false).value resolves to "timed-out"'
);
assert.sameValue(
await $262.agent.getReportAsync(),
'timed-out',
'Atomics.waitAsync(i32a, 0, 0, valueOf).value resolves to "timed-out"'
);
assert.sameValue(
await $262.agent.getReportAsync(),
'timed-out',
'Atomics.waitAsync(i32a, 0, 0, toPrimitive).value resolves to "timed-out"'
);
assert.sameValue(Atomics.notify(i32a, 0), 0, 'Atomics.notify(i32a, 0) returns 0');
}).then($DONE, $DONE);
assert.sameValue(
$262.agent.getReport(),
'timed-out',
'await Atomics.waitAsync(i32a, 0, 0, false).value resolves to "timed-out"'
);
assert.sameValue(
$262.agent.getReport(),
'timed-out',
'await Atomics.waitAsync(i32a, 0, 0, valueOf).value resolves to "timed-out"'
);
assert.sameValue(
$262.agent.getReport(),
'timed-out',
'await Atomics.waitAsync(i32a, 0, 0, toPrimitive).value resolves to "timed-out"'
);
assert.sameValue(
$262.agent.getReport(),
'timed-out',
'Atomics.waitAsync(i32a, 0, 0, false).value resolves to "timed-out"'
);
assert.sameValue(
$262.agent.getReport(),
'timed-out',
'Atomics.waitAsync(i32a, 0, 0, valueOf).value resolves to "timed-out"'
);
assert.sameValue(
$262.agent.getReport(),
'timed-out',
'Atomics.waitAsync(i32a, 0, 0, toPrimitive).value resolves to "timed-out"'
);
assert.sameValue(Atomics.notify(i32a, 0), 0, 'Atomics.notify(i32a, 0) returns 0');

View File

@ -14,6 +14,7 @@ info: |
6. Let q be ? ToNumber(timeout).
flags: [async]
includes: [atomicsHelper.js]
features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics]
---*/
@ -34,9 +35,18 @@ const i32a = new Int32Array(
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
);
$262.agent.safeBroadcast(i32a);
$262.agent.waitUntil(i32a, RUNNING, 1);
$262.agent.tryYield();
$262.agent.safeBroadcastAsync(i32a, RUNNING, 1).then(async (agentCount) => {
assert.sameValue(agentCount, 1);
assert.sameValue(Atomics.notify(i32a, 0), 1, 'Atomics.notify(i32a, 0) returns 1');
assert.sameValue(
await $262.agent.getReportAsync(),
'ok',
'await Atomics.waitAsync(i32a, 0, 0, NaN).value resolves to "ok"'
);
}).then($DONE, $DONE);
assert.sameValue(Atomics.notify(i32a, 0), 1, 'Atomics.notify(i32a, 0) returns 1');
assert.sameValue($262.agent.getReport(), "ok", 'await Atomics.waitAsync(i32a, 0, 0, NaN).value resolves to "ok"');

View File

@ -5,6 +5,16 @@
esid: sec-atomics.waitasync
description: >
Test that Atomics.waitAsync times out with a negative 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).
flags: [async]
includes: [atomicsHelper.js]
features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics]
---*/
@ -15,7 +25,7 @@ $262.agent.start(`
$262.agent.receiveBroadcast(async (sab) => {
var i32a = new Int32Array(sab);
Atomics.add(i32a, ${RUNNING}, 1);
$262.agent.report(await Atomics.waitSync(i32a, 0, 0, -5).value); // -5 => 0
$262.agent.report(await Atomics.waitAsync(i32a, 0, 0, -5).value); // -5 => 0
$262.agent.leaving();
});
`);
@ -24,15 +34,17 @@ const i32a = new Int32Array(
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
);
$262.agent.safeBroadcast(i32a);
$262.agent.waitUntil(i32a, RUNNING, 1);
$262.agent.safeBroadcastAsync(i32a, RUNNING, 1).then(async (agentCount) => {
// Try to yield control to ensure the agent actually started to wait.
$262.agent.tryYield();
assert.sameValue(agentCount, 1);
assert.sameValue(
await $262.agent.getReportAsync(),
'timed-out',
'await Atomics.waitAsync(i32a, 0, 0, -5).value resolves to "timed-out"'
);
assert.sameValue(Atomics.notify(i32a, 0), 0, 'Atomics.notify(i32a, 0) returns 0');
}).then($DONE, $DONE);
assert.sameValue(
$262.agent.getReport(),
'timed-out',
'await Atomics.waitSync(i32a, 0, 0, -5).value resolves to "timed-out"'
);
assert.sameValue(Atomics.notify(i32a, 0), 0, 'Atomics.notify(i32a, 0) returns 0');

View File

@ -5,6 +5,15 @@
esid: sec-atomics.waitasync
description: >
Test that Atomics.waitAsync times out with a negative 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).
flags: [async]
features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics]
---*/

View File

@ -8,10 +8,15 @@ description: >
info: |
Atomics.waitAsync( typedArray, index, value, timeout )
4. Let q be ? ToNumber(timeout).
1. Return DoWait(async, typedArray, index, value, timeout).
DoWait ( mode, typedArray, index, value, timeout )
6. Let q be ? ToNumber(timeout).
Null -> Return +0.
flags: [async]
includes: [atomicsHelper.js]
features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics]
---*/
@ -48,41 +53,41 @@ const i32a = new Int32Array(
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
);
$262.agent.safeBroadcast(i32a);
$262.agent.waitUntil(i32a, RUNNING, 1);
$262.agent.safeBroadcastAsync(i32a, RUNNING, 1).then(async (agentCount) => {
assert.sameValue(agentCount, 1);
// Try to yield control to ensure the agent actually started to wait.
$262.agent.tryYield();
assert.sameValue(
await $262.agent.getReportAsync(),
'timed-out',
'await Atomics.waitAsync(i32a, 0, 0, null).value resolves to "timed-out"'
);
assert.sameValue(
await $262.agent.getReportAsync(),
'timed-out',
'await Atomics.waitAsync(i32a, 0, 0, valueOf).value resolves to "timed-out"'
);
assert.sameValue(
await $262.agent.getReportAsync(),
'timed-out',
'await Atomics.waitAsync(i32a, 0, 0, toPrimitive).value resolves to "timed-out"'
);
assert.sameValue(
await $262.agent.getReportAsync(),
'timed-out',
'Atomics.waitAsync(i32a, 0, 0, null).value resolves to "timed-out"'
);
assert.sameValue(
await $262.agent.getReportAsync(),
'timed-out',
'Atomics.waitAsync(i32a, 0, 0, valueOf).value resolves to "timed-out"'
);
assert.sameValue(
await $262.agent.getReportAsync(),
'timed-out',
'Atomics.waitAsync(i32a, 0, 0, toPrimitive).value resolves to "timed-out"'
);
assert.sameValue(
$262.agent.getReport(),
'timed-out',
'await Atomics.waitAsync(i32a, 0, 0, null).value resolves to "timed-out"'
);
assert.sameValue(
$262.agent.getReport(),
'timed-out',
'await Atomics.waitAsync(i32a, 0, 0, valueOf).value resolves to "timed-out"'
);
assert.sameValue(
$262.agent.getReport(),
'timed-out',
'await Atomics.waitAsync(i32a, 0, 0, toPrimitive).value resolves to "timed-out"'
);
assert.sameValue(
$262.agent.getReport(),
'timed-out',
'Atomics.waitAsync(i32a, 0, 0, null).value resolves to "timed-out"'
);
assert.sameValue(
$262.agent.getReport(),
'timed-out',
'Atomics.waitAsync(i32a, 0, 0, valueOf).value resolves to "timed-out"'
);
assert.sameValue(
$262.agent.getReport(),
'timed-out',
'Atomics.waitAsync(i32a, 0, 0, toPrimitive).value resolves to "timed-out"'
);
assert.sameValue(Atomics.notify(i32a, 0), 0, 'Atomics.notify(i32a, 0) returns 0');
}).then($DONE, $DONE);
assert.sameValue(Atomics.notify(i32a, 0), 0, 'Atomics.notify(i32a, 0) returns 0');

View File

@ -8,7 +8,11 @@ description: >
info: |
Atomics.waitAsync( typedArray, index, value, timeout )
4. Let q be ? ToNumber(timeout).
1. Return DoWait(async, typedArray, index, value, timeout).
DoWait ( mode, typedArray, index, value, timeout )
6. Let q be ? ToNumber(timeout).
Null -> Return +0.

View File

@ -4,14 +4,22 @@
/*---
esid: sec-atomics.waitasync
description: >
False timeout arg should result in an +0 timeout
Object valueOf, toString, toPrimitive Zero timeout arg should result in an +0 timeout
info: |
Atomics.wait( typedArray, index, value, timeout )
Atomics.waitAsync( typedArray, index, value, timeout )
4. Let q be ? ToNumber(timeout).
1. Return DoWait(async, typedArray, index, value, timeout).
Null -> Return +0.
DoWait ( mode, typedArray, index, value, timeout )
6. Let q be ? ToNumber(timeout).
Object -> Apply the following steps:
Let primValue be ? ToPrimitive(argument, hint Number).
Return ? ToNumber(primValue).
flags: [async]
includes: [atomicsHelper.js]
features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics]
---*/
@ -53,41 +61,42 @@ const i32a = new Int32Array(
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
);
$262.agent.safeBroadcast(i32a);
$262.agent.waitUntil(i32a, RUNNING, 1);
$262.agent.safeBroadcastAsync(i32a, RUNNING, 1).then(async (agentCount) => {
// Try to yield control to ensure the agent actually started to wait.
$262.agent.tryYield();
assert.sameValue(agentCount, 1);
assert.sameValue(
$262.agent.getReport(),
'timed-out',
'await Atomics.waitAsync(i32a, 0, 0, valueOf).value resolves to "timed-out"'
);
assert.sameValue(
$262.agent.getReport(),
'timed-out',
'await Atomics.waitAsync(i32a, 0, 0, toString).value resolves to "timed-out"'
);
assert.sameValue(
$262.agent.getReport(),
'timed-out',
'await Atomics.waitAsync(i32a, 0, 0, toPrimitive).value resolves to "timed-out"'
);
assert.sameValue(
$262.agent.getReport(),
'timed-out',
'Atomics.waitAsync(i32a, 0, 0, valueOf).value resolves to "timed-out"'
);
assert.sameValue(
$262.agent.getReport(),
'timed-out',
'Atomics.waitAsync(i32a, 0, 0, toString).value resolves to "timed-out"'
);
assert.sameValue(
$262.agent.getReport(),
'timed-out',
'Atomics.waitAsync(i32a, 0, 0, toPrimitive).value resolves to "timed-out"'
);
assert.sameValue(
await $262.agent.getReportAsync(),
'timed-out',
'await Atomics.waitAsync(i32a, 0, 0, valueOf).value resolves to "timed-out"'
);
assert.sameValue(
await $262.agent.getReportAsync(),
'timed-out',
'await Atomics.waitAsync(i32a, 0, 0, toString).value resolves to "timed-out"'
);
assert.sameValue(
await $262.agent.getReportAsync(),
'timed-out',
'await Atomics.waitAsync(i32a, 0, 0, toPrimitive).value resolves to "timed-out"'
);
assert.sameValue(
await $262.agent.getReportAsync(),
'timed-out',
'Atomics.waitAsync(i32a, 0, 0, valueOf).value resolves to "timed-out"'
);
assert.sameValue(
await $262.agent.getReportAsync(),
'timed-out',
'Atomics.waitAsync(i32a, 0, 0, toString).value resolves to "timed-out"'
);
assert.sameValue(
await $262.agent.getReportAsync(),
'timed-out',
'Atomics.waitAsync(i32a, 0, 0, toPrimitive).value resolves to "timed-out"'
);
assert.sameValue(Atomics.notify(i32a, 0), 0, 'Atomics.notify(i32a, 0) returns 0');
}).then($DONE, $DONE);
assert.sameValue(Atomics.notify(i32a, 0), 0, 'Atomics.notify(i32a, 0) returns 0');

View File

@ -4,11 +4,15 @@
/*---
esid: sec-atomics.waitasync
description: >
Throws a TypeError if index arg can not be converted to an Integer
Object valueOf, toString, toPrimitive Zero timeout arg should result in an +0 timeout
info: |
Atomics.wait( typedArray, index, value, timeout )
Atomics.waitAsync( typedArray, index, value, timeout )
4. Let q be ? ToNumber(timeout).
1. Return DoWait(async, typedArray, index, value, timeout).
DoWait ( mode, typedArray, index, value, timeout )
6. Let q be ? ToNumber(timeout).
Object -> Apply the following steps:

View File

@ -0,0 +1,73 @@
// 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: >
True 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).
flags: [async]
includes: [atomicsHelper.js]
features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics]
---*/
const RUNNING = 1;
$262.agent.start(`
const valueOf = {
valueOf() {
return true;
}
};
const toPrimitive = {
[Symbol.toPrimitive]() {
return true;
}
};
$262.agent.receiveBroadcast(async (sab) => {
const i32a = new Int32Array(sab);
Atomics.add(i32a, ${RUNNING}, 1);
$262.agent.report(await Atomics.waitAsync(i32a, 0, 0, true).value);
$262.agent.report(await Atomics.waitAsync(i32a, 0, 0, valueOf).value);
$262.agent.report(await Atomics.waitAsync(i32a, 0, 0, toPrimitive).value);
$262.agent.leaving();
});
`);
const i32a = new Int32Array(
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
);
$262.agent.safeBroadcastAsync(i32a, RUNNING, 1).then(async (agentCount) => {
assert.sameValue(agentCount, 1);
assert.sameValue(
await $262.agent.getReportAsync(),
'timed-out',
'await Atomics.waitAsync(i32a, 0, 0, false).value resolves to "timed-out"'
);
assert.sameValue(
await $262.agent.getReportAsync(),
'timed-out',
'await Atomics.waitAsync(i32a, 0, 0, valueOf).value resolves to "timed-out"'
);
assert.sameValue(
await $262.agent.getReportAsync(),
'timed-out',
'await Atomics.waitAsync(i32a, 0, 0, toPrimitive).value resolves to "timed-out"'
);
assert.sameValue(Atomics.notify(i32a, 0), 0, 'Atomics.notify(i32a, 0) returns 0');
}).then($DONE, $DONE);

View File

@ -0,0 +1,47 @@
// 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: >
Throws a TypeError if index arg can not be converted to an Integer
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).
Boolean -> If argument is true, return 1. If argument is false, return +0.
flags: [async]
includes: [atomicsHelper.js]
features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics]
---*/
const i32a = new Int32Array(
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
);
const valueOf = {
valueOf() {
return true;
}
};
const toPrimitive = {
[Symbol.toPrimitive]() {
return true;
}
};
Promise.all([
Atomics.waitAsync(i32a, 0, 0, true).value,
Atomics.waitAsync(i32a, 0, 0, valueOf).value,
Atomics.waitAsync(i32a, 0, 0, toPrimitive).value,
]).then(outcomes => {
assert.sameValue(outcomes[0], 'timed-out');
assert.sameValue(outcomes[0], 'timed-out');
assert.sameValue(outcomes[0], 'timed-out');
}, $DONE).then($DONE, $DONE);

View File

@ -0,0 +1,75 @@
// 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: >
Undefined timeout arg should result in an infinite 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).
...
Undefined Return NaN.
5.If q is NaN, let t be +, else let t be max(q, 0)
flags: [async]
includes: [atomicsHelper.js]
features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics]
---*/
const WAIT_INDEX = 0;
const RUNNING = 1;
const NUMAGENT = 2;
const NOTIFYCOUNT = 2;
$262.agent.start(`
$262.agent.receiveBroadcast(async (sab) => {
var i32a = new Int32Array(sab);
Atomics.add(i32a, ${RUNNING}, 1);
// undefined => NaN => +Infinity
$262.agent.report("A " + (await Atomics.waitAsync(i32a, 0, 0, undefined).value));
$262.agent.leaving();
});
`);
$262.agent.start(`
$262.agent.receiveBroadcast(async (sab) => {
var i32a = new Int32Array(sab);
Atomics.add(i32a, ${RUNNING}, 1);
// undefined timeout arg => NaN => +Infinity
$262.agent.report("B " + (await Atomics.waitAsync(i32a, 0, 0).value));
$262.agent.leaving();
});
`);
const i32a = new Int32Array(
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
);
$262.agent.safeBroadcastAsync(i32a, RUNNING, NUMAGENT).then(async (agentCount) => {
assert.sameValue(agentCount, NUMAGENT);
assert.sameValue(
Atomics.notify(i32a, WAIT_INDEX, NOTIFYCOUNT),
NOTIFYCOUNT,
'Atomics.notify(i32a, WAIT_INDEX, NOTIFYCOUNT) returns the value of `NOTIFYCOUNT` (2)'
);
Promise.all([
$262.agent.getReportAsync(),
$262.agent.getReportAsync(),
]).then(reports => {
reports.sort();
assert.sameValue(reports[0], 'A ok', 'The value of reports[0] is "A ok"');
assert.sameValue(reports[1], 'B ok', 'The value of reports[1] is "B ok"');
}).then($DONE, $DONE);
}).then($DONE, $DONE);