Atomics.waitAsync: Return Value

This commit is contained in:
Rick Waldron 2020-04-03 11:53:00 -04:00
parent dabcc05199
commit 9519cd8448
4 changed files with 135 additions and 5 deletions

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: >
Atomics.waitAsync returns a result object containing a promise that resolves to "ok" and async is true.
info: |
Atomics.waitAsync( typedArray, index, value, timeout )
1. Return DoWait(async, typedArray, index, value, timeout).
DoWait ( mode, typedArray, index, value, timeout )
...
13. Let promiseCapability be undefined.
14. If mode is async, then
a. Set promiseCapability to ! NewPromiseCapability(%Promise%).
...
Perform ! CreateDataPropertyOrThrow(_resultObject_, *"async"*, *true*).
Perform ! CreateDataPropertyOrThrow(_resultObject_, *"value"*, _promiseCapability_.[[Promise]]).
Return _resultObject_.
flags: [async]
features: [Atomics.waitAsync]
---*/
const i32a = new Int32Array(
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 8)
);
let {async, value} = Atomics.waitAsync(i32a, 0, 0, 1000);
assert.sameValue(async, true);
assert(value instanceof Promise);
assert.sameValue(Object.getPrototypeOf(value), Promise.prototype);
value.then(outcome => {
assert.sameValue(outcome, "ok");
}).then(() => $DONE(), $DONE);
Atomics.add(i32a, 0, 1);
Atomics.notify(i32a, 0, 1);

View File

@ -0,0 +1,44 @@
// 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: >
Atomics.waitAsync returns a result object containing a promise that resolves to "timed-out" and async is true.
info: |
Atomics.waitAsync( typedArray, index, value, timeout )
1. Return DoWait(async, typedArray, index, value, timeout).
DoWait ( mode, typedArray, index, value, timeout )
...
13. Let promiseCapability be undefined.
14. If mode is async, then
a. Set promiseCapability to ! NewPromiseCapability(%Promise%).
...
Perform ! CreateDataPropertyOrThrow(_resultObject_, *"async"*, *true*).
Perform ! CreateDataPropertyOrThrow(_resultObject_, *"value"*, _promiseCapability_.[[Promise]]).
Return _resultObject_.
flags: [async]
features: [Atomics.waitAsync]
---*/
const i32a = new Int32Array(
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 8)
);
let {async, value} = Atomics.waitAsync(i32a, 0, 0, 1);
assert.sameValue(async, true);
assert(value instanceof Promise);
assert.sameValue(Object.getPrototypeOf(value), Promise.prototype);
value.then(outcome => {
assert.sameValue(outcome, "timed-out");
}).then(() => $DONE(), $DONE);

View File

@ -4,8 +4,9 @@
/*---
esid: sec-atomics.waitasync
description: >
Atomics.waitAsync returns a promise.
Atomics.waitAsync returns a result object containing a string "not-equal" and async is false.
info: |
Atomics.waitAsync( typedArray, index, value, timeout )
1. Return DoWait(async, typedArray, index, value, timeout).
@ -18,7 +19,9 @@ info: |
a. Set promiseCapability to ! NewPromiseCapability(%Promise%).
...
24. Return promiseCapability.[[Promise]].
Perform ! CreateDataPropertyOrThrow(_resultObject_, *"async"*, *true*).
Perform ! CreateDataPropertyOrThrow(_resultObject_, *"value"*, _promiseCapability_.[[Promise]]).
Return _resultObject_.
features: [Atomics.waitAsync]
---*/
@ -27,7 +30,7 @@ const i32a = new Int32Array(
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 8)
);
let p = Atomics.waitAsync(i32a, 0, 0, 0);
let {async, value} = Atomics.waitAsync(i32a, 0, 1);
assert(p instanceof Promise);
assert.sameValue(Object.getPrototypeOf(p), Promise.prototype);
assert.sameValue(async, false);
assert.sameValue(value, "not-equal");

View File

@ -0,0 +1,36 @@
// 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: >
Atomics.waitAsync returns a result object containing a string "not-equal" and async is false.
info: |
Atomics.waitAsync( typedArray, index, value, timeout )
1. Return DoWait(async, typedArray, index, value, timeout).
DoWait ( mode, typedArray, index, value, timeout )
...
13. Let promiseCapability be undefined.
14. If mode is async, then
a. Set promiseCapability to ! NewPromiseCapability(%Promise%).
...
Perform ! CreateDataPropertyOrThrow(_resultObject_, *"async"*, *true*).
Perform ! CreateDataPropertyOrThrow(_resultObject_, *"value"*, _promiseCapability_.[[Promise]]).
Return _resultObject_.
features: [Atomics.waitAsync]
---*/
const i32a = new Int32Array(
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 8)
);
let {async, value} = Atomics.waitAsync(i32a, 0, 0, 0);
assert.sameValue(async, false);
assert.sameValue(value, "timed-out");