diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/test262/built-ins/Atomics/waitAsync/bigint | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/Atomics/waitAsync/bigint')
46 files changed, 2777 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/bad-range.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/bad-range.js new file mode 100644 index 0000000000..a2214e5b2b --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/bad-range.js @@ -0,0 +1,31 @@ +// |reftest| skip -- Atomics.waitAsync is not supported +// 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: > + Test range checking of Atomics.waitAsync on arrays that allow atomic operations +info: | + Atomics.waitAsync( typedArray, index, value, timeout ) + + 1. Return DoWait(async, typedArray, index, value, timeout). + + DoWait ( mode, typedArray, index, value, timeout ) + + ... + 2. Let i be ? ValidateAtomicAccess(typedArray, index). + ... + +includes: [testAtomics.js] +features: [Atomics.waitAsync, Atomics, SharedArrayBuffer, ArrayBuffer, DataView, Symbol, TypedArray, BigInt] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 8)); + +testWithAtomicsOutOfBoundsIndices(function(IdxGen) { + assert.throws(RangeError, function() { + Atomics.waitAsync(i64a, IdxGen(i64a), 0n, 0); + }, '`Atomics.waitAsync(i64a, IdxGen(i64a), 0n, 0)` throws a RangeError exception'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/browser.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/browser.js diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/false-for-timeout-agent.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/false-for-timeout-agent.js new file mode 100644 index 0000000000..37bb338b35 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/false-for-timeout-agent.js @@ -0,0 +1,96 @@ +// |reftest| skip async -- Atomics.waitAsync is not supported +// 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). + +flags: [async] +includes: [atomicsHelper.js] +features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, BigInt, arrow-function, async-functions] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const RUNNING = 1; + +$262.agent.start(` + const valueOf = { + valueOf() { + return false; + } + }; + + const toPrimitive = { + [Symbol.toPrimitive]() { + return false; + } + }; + + $262.agent.receiveBroadcast(async (sab) => { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + $262.agent.report(await Atomics.waitAsync(i64a, 0, 0n, false).value); + $262.agent.report(await Atomics.waitAsync(i64a, 0, 0n, valueOf).value); + $262.agent.report(await Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value); + $262.agent.report(Atomics.waitAsync(i64a, 0, 0n, false).value); + $262.agent.report(Atomics.waitAsync(i64a, 0, 0n, valueOf).value); + $262.agent.report(Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value); + $262.agent.leaving(); + }); +`); + +const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + +$262.agent.safeBroadcastAsync(i64a, RUNNING, 1n).then(async agentCount => { + assert.sameValue(agentCount, 1n, 'The value of `agentCount` is 1n'); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + '(await $262.agent.getReportAsync()) resolves to the value "timed-out"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + '(await $262.agent.getReportAsync()) resolves to the value "timed-out"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + '(await $262.agent.getReportAsync()) resolves to the value "timed-out"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + '(await $262.agent.getReportAsync()) resolves to the value "timed-out"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + '(await $262.agent.getReportAsync()) resolves to the value "timed-out"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + '(await $262.agent.getReportAsync()) resolves to the value "timed-out"' + ); + + assert.sameValue( + Atomics.notify(i64a, 0), + 0, + 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0) must return 0' + ); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/false-for-timeout.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/false-for-timeout.js new file mode 100644 index 0000000000..78e5cb927c --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/false-for-timeout.js @@ -0,0 +1,61 @@ +// |reftest| skip async -- Atomics.waitAsync is not supported +// 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). + +flags: [async] +features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, BigInt, computed-property-names, Symbol, Symbol.toPrimitive, arrow-function] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + +const valueOf = { + valueOf() { + return false; + } +}; + +const toPrimitive = { + [Symbol.toPrimitive]() { + return false; + } +}; + +assert.sameValue( + Atomics.waitAsync(i64a, 0, 0n, false).value, + 'timed-out', + 'The value of Atomics.waitAsync(i64a, 0, 0n, false).value is "timed-out"' +); + +assert.sameValue( + Atomics.waitAsync(i64a, 0, 0n, valueOf).value, + 'timed-out', + 'The value of Atomics.waitAsync(i64a, 0, 0n, valueOf).value is "timed-out"' +); + +assert.sameValue( + Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value, + 'timed-out', + 'The value of Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value is "timed-out"' +); + +Promise.all([ + Atomics.waitAsync(i64a, 0, 0n, false).value, + Atomics.waitAsync(i64a, 0, 0n, valueOf).value, + Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value +]).then(outcomes => { + assert.sameValue(outcomes[0], 'timed-out', 'The value of outcomes[0] is "timed-out"'); + assert.sameValue(outcomes[1], 'timed-out', 'The value of outcomes[1] is "timed-out"'); + assert.sameValue(outcomes[2], 'timed-out', 'The value of outcomes[2] is "timed-out"'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/good-views.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/good-views.js new file mode 100644 index 0000000000..8a084276ad --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/good-views.js @@ -0,0 +1,71 @@ +// |reftest| skip async -- Atomics.waitAsync is not supported +// 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: > + Test Atomics.waitAsync on arrays that allow atomic operations +flags: [async] +includes: [atomicsHelper.js, asyncHelpers.js] +features: [Atomics.waitAsync, Atomics, BigInt] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); + +$262.agent.start(` + (async () => { + var sab = new SharedArrayBuffer(2048); + var good_indices = [ (view) => 0/-1, // -0 + (view) => '-0', + (view) => view.length - 1, + (view) => ({ valueOf: () => 0 }), + (view) => ({ toString: () => '0', valueOf: false }) // non-callable valueOf triggers invocation of toString + ]; + + var view = new BigInt64Array(sab, 32, 20); + + view[0] = 0n; + $262.agent.report("A " + (await Atomics.waitAsync(view, 0, 0n, 0).value)) + $262.agent.report("B " + (await Atomics.waitAsync(view, 0, 37n, 0).value)); + + const results = []; + // In-bounds boundary cases for indexing + for ( let IdxGen of good_indices ) { + let Idx = IdxGen(view); + view.fill(0n); + // Atomics.store() computes an index from Idx in the same way as other + // Atomics operations, not quite like view[Idx]. + Atomics.store(view, Idx, 37n); + results.push(await Atomics.waitAsync(view, Idx, 0n).value); + } + $262.agent.report("C " + results.join(",")); + + $262.agent.leaving(); + })(); +`); + + +asyncTest(async () => { + const outcomes = []; + + for (let i = 0; i < 3; i++) { + outcomes.push(await $262.agent.getReportAsync()); + } + + assert.sameValue( + outcomes[0], + 'A timed-out', + 'The value of outcomes[0] is "A timed-out"' + ); + + assert.sameValue( + outcomes[1], + 'B not-equal', + 'The value of outcomes[1] is "B not-equal"' + ); + assert.sameValue( + outcomes[2], + 'C not-equal,not-equal,not-equal,not-equal,not-equal', + 'The value of outcomes[2] is "C not-equal,not-equal,not-equal,not-equal,not-equal"' + ); +}); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/nan-for-timeout-agent.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/nan-for-timeout-agent.js new file mode 100644 index 0000000000..70f79c11e0 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/nan-for-timeout-agent.js @@ -0,0 +1,50 @@ +// |reftest| skip async -- Atomics.waitAsync is not supported +// 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: > + NaN 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). + +flags: [async] +includes: [atomicsHelper.js] +features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, BigInt, arrow-function, async-functions] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const RUNNING = 1; + +$262.agent.start(` + $262.agent.receiveBroadcast(async (sab) => { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + $262.agent.report(await Atomics.waitAsync(i64a, 0, 0n, NaN).value); // NaN => +Infinity + $262.agent.leaving(); + }); +`); + +const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + +$262.agent.safeBroadcastAsync(i64a, RUNNING, 1n).then(async agentCount => { + assert.sameValue(agentCount, 1n, 'The value of `agentCount` is 1n'); + + assert.sameValue( + Atomics.notify(i64a, 0), + 1, + 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0) must return 1' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'ok', + '(await $262.agent.getReportAsync()) resolves to the value "ok"' + ); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/negative-index-throws.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/negative-index-throws.js new file mode 100644 index 0000000000..0618a9aa71 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/negative-index-throws.js @@ -0,0 +1,46 @@ +// |reftest| skip -- Atomics.waitAsync is not supported +// 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 RangeError is index < 0 +info: | + Atomics.waitAsync( typedArray, index, value, timeout ) + + 1. Return DoWait(async, typedArray, index, value, timeout). + + DoWait ( mode, typedArray, index, value, timeout ) + + 1. Let buffer be ? ValidateSharedIntegerTypedArray(typedArray, true). + 2. Let i be ? ValidateAtomicAccess(typedArray, index). + +features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, BigInt] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4) +); + +const poisoned = { + valueOf() { + throw new Test262Error('should not evaluate this code'); + } +}; + +assert.throws(RangeError, function() { + Atomics.waitAsync(i64a, -Infinity, poisoned, poisoned); +}, '`Atomics.waitAsync(i64a, -Infinity, poisoned, poisoned)` throws a RangeError exception'); +assert.throws(RangeError, function() { + Atomics.waitAsync(i64a, -7.999, poisoned, poisoned); +}, '`Atomics.waitAsync(i64a, -7.999, poisoned, poisoned)` throws a RangeError exception'); +assert.throws(RangeError, function() { + Atomics.waitAsync(i64a, -1, poisoned, poisoned); +}, '`Atomics.waitAsync(i64a, -1, poisoned, poisoned)` throws a RangeError exception'); +assert.throws(RangeError, function() { + Atomics.waitAsync(i64a, -300, poisoned, poisoned); +}, '`Atomics.waitAsync(i64a, -300, poisoned, poisoned)` throws a RangeError exception'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/negative-timeout-agent.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/negative-timeout-agent.js new file mode 100644 index 0000000000..9ef681c34b --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/negative-timeout-agent.js @@ -0,0 +1,49 @@ +// |reftest| skip async -- Atomics.waitAsync is not supported +// 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: > + 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, BigInt, arrow-function, async-functions] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const RUNNING = 1; + +$262.agent.start(` + $262.agent.receiveBroadcast(async (sab) => { + var i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + $262.agent.report(await Atomics.waitAsync(i64a, 0, 0n, -5).value); // -5 => 0 + $262.agent.leaving(); + }); +`); + +const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + +$262.agent.safeBroadcastAsync(i64a, RUNNING, 1n).then(async agentCount => { + assert.sameValue(agentCount, 1n, 'The value of `agentCount` is 1n'); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + '(await $262.agent.getReportAsync()) resolves to the value "timed-out"' + ); + + assert.sameValue( + Atomics.notify(i64a, 0), + 0, + 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0) must return 0' + ); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/negative-timeout.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/negative-timeout.js new file mode 100644 index 0000000000..2f0f64af62 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/negative-timeout.js @@ -0,0 +1,25 @@ +// |reftest| skip async -- Atomics.waitAsync is not supported +// 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: > + 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, BigInt, destructuring-binding, arrow-function] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + +Promise.all([Atomics.waitAsync(i64a, 0, 0n, -1).value]).then(([outcome]) => { + assert.sameValue(outcome, 'timed-out', 'The value of `outcome` is "timed-out"'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-no-operation.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-no-operation.js new file mode 100644 index 0000000000..a87317a889 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-no-operation.js @@ -0,0 +1,61 @@ +// |reftest| skip async -- Atomics.waitAsync is not supported +// 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: > + Test that Atomics.waitAsync returns the right result when it timed out and that + the time to time out is reasonable. +info: | + AddWaiter ( WL, waiterRecord ) + + 5. Append waiterRecord as the last element of WL.[[Waiters]] + 6. If waiterRecord.[[Timeout]] is finite, then in parallel, + a. Wait waiterRecord.[[Timeout]] milliseconds. + b. Perform TriggerTimeout(WL, waiterRecord). + + TriggerTimeout( WL, waiterRecord ) + + 3. If waiterRecord is in WL.[[Waiters]], then + a. Set waiterRecord.[[Result]] to "timed-out". + b. Perform RemoveWaiter(WL, waiterRecord). + c. Perform NotifyWaiter(WL, waiterRecord). + 4. Perform LeaveCriticalSection(WL). + +flags: [async] +includes: [atomicsHelper.js] +features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, BigInt, arrow-function, async-functions] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const RUNNING = 1; +const TIMEOUT = $262.agent.timeouts.small; +const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + +$262.agent.start(` + $262.agent.receiveBroadcast(async (sab) => { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + const before = $262.agent.monotonicNow(); + const unpark = await Atomics.waitAsync(i64a, 0, 0n, ${TIMEOUT}).value; + const duration = $262.agent.monotonicNow() - before; + + $262.agent.report(duration); + $262.agent.report(unpark); + $262.agent.leaving(); + }); +`); + +$262.agent.safeBroadcastAsync(i64a, RUNNING, 1n).then(async agentCount => { + assert.sameValue(agentCount, 1n, 'The value of `agentCount` is 1n'); + const lapse = await $262.agent.getReportAsync(); + assert(lapse >= TIMEOUT, 'The result of evaluating `(lapse >= TIMEOUT)` is true'); + const result = await $262.agent.getReportAsync(); + assert.sameValue(result, 'timed-out', 'The value of `result` is "timed-out"'); + + assert.sameValue( + Atomics.notify(i64a, 0), + 0, + 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0) must return 0' + ); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-add.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-add.js new file mode 100644 index 0000000000..e15da5a1e2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-add.js @@ -0,0 +1,61 @@ +// |reftest| skip async -- Atomics.waitAsync is not supported +// 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: > + Waiter does not spuriously notify on index which is subject to Add operation +info: | + AddWaiter ( WL, waiterRecord ) + + 5. Append waiterRecord as the last element of WL.[[Waiters]] + 6. If waiterRecord.[[Timeout]] is finite, then in parallel, + a. Wait waiterRecord.[[Timeout]] milliseconds. + b. Perform TriggerTimeout(WL, waiterRecord). + + TriggerTimeout( WL, waiterRecord ) + + 3. If waiterRecord is in WL.[[Waiters]], then + a. Set waiterRecord.[[Result]] to "timed-out". + b. Perform RemoveWaiter(WL, waiterRecord). + c. Perform NotifyWaiter(WL, waiterRecord). + 4. Perform LeaveCriticalSection(WL). + +flags: [async] +includes: [atomicsHelper.js] +features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, BigInt, arrow-function, async-functions] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const RUNNING = 1; +const TIMEOUT = $262.agent.timeouts.small; +const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + +$262.agent.start(` + $262.agent.receiveBroadcast(async (sab) => { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + const before = $262.agent.monotonicNow(); + const unpark = await Atomics.waitAsync(i64a, 0, 0n, ${TIMEOUT}).value; + const duration = $262.agent.monotonicNow() - before; + + $262.agent.report(duration); + $262.agent.report(unpark); + $262.agent.leaving(); + }); +`); + +$262.agent.safeBroadcastAsync(i64a, RUNNING, 1n).then(async agentCount => { + assert.sameValue(agentCount, 1n, 'The value of `agentCount` is 1n'); + Atomics.add(i64a, 0, 1n); + const lapse = await $262.agent.getReportAsync(); + assert(lapse >= TIMEOUT, 'The result of evaluating `(lapse >= TIMEOUT)` is true'); + const result = await $262.agent.getReportAsync(); + assert.sameValue(result, 'timed-out', 'The value of `result` is "timed-out"'); + + assert.sameValue( + Atomics.notify(i64a, 0), + 0, + 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0) must return 0' + ); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-and.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-and.js new file mode 100644 index 0000000000..02ed9ef726 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-and.js @@ -0,0 +1,61 @@ +// |reftest| skip async -- Atomics.waitAsync is not supported +// 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: > + Waiter does not spuriously notify on index which is subject to And operation +info: | + AddWaiter ( WL, waiterRecord ) + + 5. Append waiterRecord as the last element of WL.[[Waiters]] + 6. If waiterRecord.[[Timeout]] is finite, then in parallel, + a. Wait waiterRecord.[[Timeout]] milliseconds. + b. Perform TriggerTimeout(WL, waiterRecord). + + TriggerTimeout( WL, waiterRecord ) + + 3. If waiterRecord is in WL.[[Waiters]], then + a. Set waiterRecord.[[Result]] to "timed-out". + b. Perform RemoveWaiter(WL, waiterRecord). + c. Perform NotifyWaiter(WL, waiterRecord). + 4. Perform LeaveCriticalSection(WL). + +flags: [async] +includes: [atomicsHelper.js] +features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, BigInt, arrow-function, async-functions] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const RUNNING = 1; +const TIMEOUT = $262.agent.timeouts.small; +const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + +$262.agent.start(` + $262.agent.receiveBroadcast(async (sab) => { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + const before = $262.agent.monotonicNow(); + const unpark = await Atomics.waitAsync(i64a, 0, 0n, ${TIMEOUT}).value; + const duration = $262.agent.monotonicNow() - before; + + $262.agent.report(duration); + $262.agent.report(unpark); + $262.agent.leaving(); + }); +`); + +$262.agent.safeBroadcastAsync(i64a, RUNNING, 1n).then(async agentCount => { + assert.sameValue(agentCount, 1n, 'The value of `agentCount` is 1n'); + Atomics.and(i64a, 0, 1n); + const lapse = await $262.agent.getReportAsync(); + assert(lapse >= TIMEOUT, 'The result of evaluating `(lapse >= TIMEOUT)` is true'); + const result = await $262.agent.getReportAsync(); + assert.sameValue(result, 'timed-out', 'The value of `result` is "timed-out"'); + + assert.sameValue( + Atomics.notify(i64a, 0), + 0, + 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0) must return 0' + ); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-compareExchange.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-compareExchange.js new file mode 100644 index 0000000000..36308c49b6 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-compareExchange.js @@ -0,0 +1,61 @@ +// |reftest| skip async -- Atomics.waitAsync is not supported +// 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: > + Waiter does not spuriously notify on index which is subject to compareExchange operation +info: | + AddWaiter ( WL, waiterRecord ) + + 5. Append waiterRecord as the last element of WL.[[Waiters]] + 6. If waiterRecord.[[Timeout]] is finite, then in parallel, + a. Wait waiterRecord.[[Timeout]] milliseconds. + b. Perform TriggerTimeout(WL, waiterRecord). + + TriggerTimeout( WL, waiterRecord ) + + 3. If waiterRecord is in WL.[[Waiters]], then + a. Set waiterRecord.[[Result]] to "timed-out". + b. Perform RemoveWaiter(WL, waiterRecord). + c. Perform NotifyWaiter(WL, waiterRecord). + 4. Perform LeaveCriticalSection(WL). + +flags: [async] +includes: [atomicsHelper.js] +features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, BigInt, arrow-function, async-functions] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const RUNNING = 1; +const TIMEOUT = $262.agent.timeouts.small; +const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + +$262.agent.start(` + $262.agent.receiveBroadcast(async (sab) => { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + const before = $262.agent.monotonicNow(); + const unpark = await Atomics.waitAsync(i64a, 0, 0n, ${TIMEOUT}).value; + const duration = $262.agent.monotonicNow() - before; + + $262.agent.report(duration); + $262.agent.report(unpark); + $262.agent.leaving(); + }); +`); + +$262.agent.safeBroadcastAsync(i64a, RUNNING, 1n).then(async agentCount => { + assert.sameValue(agentCount, 1n, 'The value of `agentCount` is 1n'); + Atomics.compareExchange(i64a, 0, 0n, 1n); + const lapse = await $262.agent.getReportAsync(); + assert(lapse >= TIMEOUT, 'The result of evaluating `(lapse >= TIMEOUT)` is true'); + const result = await $262.agent.getReportAsync(); + assert.sameValue(result, 'timed-out', 'The value of `result` is "timed-out"'); + + assert.sameValue( + Atomics.notify(i64a, 0), + 0, + 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0) must return 0' + ); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-exchange.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-exchange.js new file mode 100644 index 0000000000..93e73140bb --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-exchange.js @@ -0,0 +1,61 @@ +// |reftest| skip async -- Atomics.waitAsync is not supported +// 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: > + Waiter does not spuriously notify on index which is subject to exchange operation +info: | + AddWaiter ( WL, waiterRecord ) + + 5. Append waiterRecord as the last element of WL.[[Waiters]] + 6. If waiterRecord.[[Timeout]] is finite, then in parallel, + a. Wait waiterRecord.[[Timeout]] milliseconds. + b. Perform TriggerTimeout(WL, waiterRecord). + + TriggerTimeout( WL, waiterRecord ) + + 3. If waiterRecord is in WL.[[Waiters]], then + a. Set waiterRecord.[[Result]] to "timed-out". + b. Perform RemoveWaiter(WL, waiterRecord). + c. Perform NotifyWaiter(WL, waiterRecord). + 4. Perform LeaveCriticalSection(WL). + +flags: [async] +includes: [atomicsHelper.js] +features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, BigInt, arrow-function, async-functions] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const RUNNING = 1; +const TIMEOUT = $262.agent.timeouts.small; +const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + +$262.agent.start(` + $262.agent.receiveBroadcast(async (sab) => { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + const before = $262.agent.monotonicNow(); + const unpark = await Atomics.waitAsync(i64a, 0, 0n, ${TIMEOUT}).value; + const duration = $262.agent.monotonicNow() - before; + + $262.agent.report(duration); + $262.agent.report(unpark); + $262.agent.leaving(); + }); +`); + +$262.agent.safeBroadcastAsync(i64a, RUNNING, 1n).then(async agentCount => { + assert.sameValue(agentCount, 1n, 'The value of `agentCount` is 1n'); + Atomics.exchange(i64a, 0, 1n); + const lapse = await $262.agent.getReportAsync(); + assert(lapse >= TIMEOUT, 'The result of evaluating `(lapse >= TIMEOUT)` is true'); + const result = await $262.agent.getReportAsync(); + assert.sameValue(result, 'timed-out', 'The value of `result` is "timed-out"'); + + assert.sameValue( + Atomics.notify(i64a, 0), + 0, + 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0) must return 0' + ); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-or.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-or.js new file mode 100644 index 0000000000..321f100417 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-or.js @@ -0,0 +1,61 @@ +// |reftest| skip async -- Atomics.waitAsync is not supported +// 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: > + Waiter does not spuriously notify on index which is subject to Or operation +info: | + AddWaiter ( WL, waiterRecord ) + + 5. Append waiterRecord as the last element of WL.[[Waiters]] + 6. If waiterRecord.[[Timeout]] is finite, then in parallel, + a. Wait waiterRecord.[[Timeout]] milliseconds. + b. Perform TriggerTimeout(WL, waiterRecord). + + TriggerTimeout( WL, waiterRecord ) + + 3. If waiterRecord is in WL.[[Waiters]], then + a. Set waiterRecord.[[Result]] to "timed-out". + b. Perform RemoveWaiter(WL, waiterRecord). + c. Perform NotifyWaiter(WL, waiterRecord). + 4. Perform LeaveCriticalSection(WL). + +flags: [async] +includes: [atomicsHelper.js] +features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, BigInt, arrow-function, async-functions] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const RUNNING = 1; +const TIMEOUT = $262.agent.timeouts.small; +const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + +$262.agent.start(` + $262.agent.receiveBroadcast(async (sab) => { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + const before = $262.agent.monotonicNow(); + const unpark = await Atomics.waitAsync(i64a, 0, 0n, ${TIMEOUT}).value; + const duration = $262.agent.monotonicNow() - before; + + $262.agent.report(duration); + $262.agent.report(unpark); + $262.agent.leaving(); + }); +`); + +$262.agent.safeBroadcastAsync(i64a, RUNNING, 1n).then(async agentCount => { + assert.sameValue(agentCount, 1n, 'The value of `agentCount` is 1n'); + Atomics.or(i64a, 0, 1n); + const lapse = await $262.agent.getReportAsync(); + assert(lapse >= TIMEOUT, 'The result of evaluating `(lapse >= TIMEOUT)` is true'); + const result = await $262.agent.getReportAsync(); + assert.sameValue(result, 'timed-out', 'The value of `result` is "timed-out"'); + + assert.sameValue( + Atomics.notify(i64a, 0), + 0, + 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0) must return 0' + ); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-store.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-store.js new file mode 100644 index 0000000000..74b2a930b2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-store.js @@ -0,0 +1,61 @@ +// |reftest| skip async -- Atomics.waitAsync is not supported +// 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: > + Waiter does not spuriously notify on index which is subject to Store operation +info: | + AddWaiter ( WL, waiterRecord ) + + 5. Append waiterRecord as the last element of WL.[[Waiters]] + 6. If waiterRecord.[[Timeout]] is finite, then in parallel, + a. Wait waiterRecord.[[Timeout]] milliseconds. + b. Perform TriggerTimeout(WL, waiterRecord). + + TriggerTimeout( WL, waiterRecord ) + + 3. If waiterRecord is in WL.[[Waiters]], then + a. Set waiterRecord.[[Result]] to "timed-out". + b. Perform RemoveWaiter(WL, waiterRecord). + c. Perform NotifyWaiter(WL, waiterRecord). + 4. Perform LeaveCriticalSection(WL). + +flags: [async] +includes: [atomicsHelper.js] +features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, BigInt, arrow-function, async-functions] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const RUNNING = 1; +const TIMEOUT = $262.agent.timeouts.small; +const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + +$262.agent.start(` + $262.agent.receiveBroadcast(async (sab) => { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + const before = $262.agent.monotonicNow(); + const unpark = await Atomics.waitAsync(i64a, 0, 0n, ${TIMEOUT}).value; + const duration = $262.agent.monotonicNow() - before; + + $262.agent.report(duration); + $262.agent.report(unpark); + $262.agent.leaving(); + }); +`); + +$262.agent.safeBroadcastAsync(i64a, RUNNING, 1n).then(async agentCount => { + assert.sameValue(agentCount, 1n, 'The value of `agentCount` is 1n'); + Atomics.store(i64a, 0, 0b1010n); + const lapse = await $262.agent.getReportAsync(); + assert(lapse >= TIMEOUT, 'The result of evaluating `(lapse >= TIMEOUT)` is true'); + const result = await $262.agent.getReportAsync(); + assert.sameValue(result, 'timed-out', 'The value of `result` is "timed-out"'); + + assert.sameValue( + Atomics.notify(i64a, 0), + 0, + 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0) must return 0' + ); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-sub.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-sub.js new file mode 100644 index 0000000000..9359795e8b --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-sub.js @@ -0,0 +1,61 @@ +// |reftest| skip async -- Atomics.waitAsync is not supported +// 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: > + Waiter does not spuriously notify on index which is subject to Sub operation +info: | + AddWaiter ( WL, waiterRecord ) + + 5. Append waiterRecord as the last element of WL.[[Waiters]] + 6. If waiterRecord.[[Timeout]] is finite, then in parallel, + a. Wait waiterRecord.[[Timeout]] milliseconds. + b. Perform TriggerTimeout(WL, waiterRecord). + + TriggerTimeout( WL, waiterRecord ) + + 3. If waiterRecord is in WL.[[Waiters]], then + a. Set waiterRecord.[[Result]] to "timed-out". + b. Perform RemoveWaiter(WL, waiterRecord). + c. Perform NotifyWaiter(WL, waiterRecord). + 4. Perform LeaveCriticalSection(WL). + +flags: [async] +includes: [atomicsHelper.js] +features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, BigInt, arrow-function, async-functions] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const RUNNING = 1; +const TIMEOUT = $262.agent.timeouts.small; +const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + +$262.agent.start(` + $262.agent.receiveBroadcast(async (sab) => { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + const before = $262.agent.monotonicNow(); + const unpark = await Atomics.waitAsync(i64a, 0, 0n, ${TIMEOUT}).value; + const duration = $262.agent.monotonicNow() - before; + + $262.agent.report(duration); + $262.agent.report(unpark); + $262.agent.leaving(); + }); +`); + +$262.agent.safeBroadcastAsync(i64a, RUNNING, 1n).then(async agentCount => { + assert.sameValue(agentCount, 1n, 'The value of `agentCount` is 1n'); + Atomics.sub(i64a, 0, 1n); + const lapse = await $262.agent.getReportAsync(); + assert(lapse >= TIMEOUT, 'The result of evaluating `(lapse >= TIMEOUT)` is true'); + const result = await $262.agent.getReportAsync(); + assert.sameValue(result, 'timed-out', 'The value of `result` is "timed-out"'); + + assert.sameValue( + Atomics.notify(i64a, 0), + 0, + 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0) must return 0' + ); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-xor.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-xor.js new file mode 100644 index 0000000000..dfc8d00b07 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-xor.js @@ -0,0 +1,61 @@ +// |reftest| skip async -- Atomics.waitAsync is not supported +// 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: > + Waiter does not spuriously notify on index which is subject to xor operation +info: | + AddWaiter ( WL, waiterRecord ) + + 5. Append waiterRecord as the last element of WL.[[Waiters]] + 6. If waiterRecord.[[Timeout]] is finite, then in parallel, + a. Wait waiterRecord.[[Timeout]] milliseconds. + b. Perform TriggerTimeout(WL, waiterRecord). + + TriggerTimeout( WL, waiterRecord ) + + 3. If waiterRecord is in WL.[[Waiters]], then + a. Set waiterRecord.[[Result]] to "timed-out". + b. Perform RemoveWaiter(WL, waiterRecord). + c. Perform NotifyWaiter(WL, waiterRecord). + 4. Perform LeaveCriticalSection(WL). + +flags: [async] +includes: [atomicsHelper.js] +features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, BigInt, arrow-function, async-functions] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const RUNNING = 1; +const TIMEOUT = $262.agent.timeouts.small; +const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + +$262.agent.start(` + $262.agent.receiveBroadcast(async (sab) => { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + const before = $262.agent.monotonicNow(); + const unpark = await Atomics.waitAsync(i64a, 0, 0n, ${TIMEOUT}).value; + const duration = $262.agent.monotonicNow() - before; + + $262.agent.report(duration); + $262.agent.report(unpark); + $262.agent.leaving(); + }); +`); + +$262.agent.safeBroadcastAsync(i64a, RUNNING, 1n).then(async agentCount => { + assert.sameValue(agentCount, 1n, 'The value of `agentCount` is 1n'); + Atomics.xor(i64a, 0, 1n); + const lapse = await $262.agent.getReportAsync(); + assert(lapse >= TIMEOUT, 'The result of evaluating `(lapse >= TIMEOUT)` is true'); + const result = await $262.agent.getReportAsync(); + assert.sameValue(result, 'timed-out', 'The value of `result` is "timed-out"'); + + assert.sameValue( + Atomics.notify(i64a, 0), + 0, + 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0) must return 0' + ); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/non-bigint64-typedarray-throws.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/non-bigint64-typedarray-throws.js new file mode 100644 index 0000000000..a4e3dd79f7 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/non-bigint64-typedarray-throws.js @@ -0,0 +1,38 @@ +// |reftest| skip -- Atomics.waitAsync is not supported +// 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 typedArray arg is not an BigInt64Array +info: | + Atomics.waitAsync( typedArray, index, value, timeout ) + + 1. Return DoWait(async, typedArray, index, value, timeout). + + DoWait ( mode, typedArray, index, value, timeout ) + + 1. Let buffer be ? ValidateSharedIntegerTypedArray(typedArray, true). + + ValidateSharedIntegerTypedArray ( typedArray [ , waitable ] ) + + 5. If waitable is true, then + a. If typeName is not "Int32Array" or "BigInt64Array", throw a TypeError exception. + +features: [Atomics.waitAsync, Float32Array, Float64Array, Int8Array, TypedArray, Uint16Array, Uint8Array, Uint8ClampedArray, arrow-function, SharedArrayBuffer, Atomics] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const poisoned = { + valueOf() { + throw new Test262Error('should not evaluate this code'); + } +}; + +assert.throws(TypeError, () => { + const view = new BigUint64Array(new SharedArrayBuffer(BigUint64Array.BYTES_PER_ELEMENT * 8)); + Atomics.waitAsync(view, poisoned, poisoned, poisoned); +}, '`const view = new BigUint64Array(new SharedArrayBuffer(BigUint64Array.BYTES_PER_ELEMENT * 8)); Atomics.waitAsync(view, poisoned, poisoned, poisoned)` throws a TypeError exception'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/non-shared-bufferdata-throws.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/non-shared-bufferdata-throws.js new file mode 100644 index 0000000000..def8fe86ea --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/non-shared-bufferdata-throws.js @@ -0,0 +1,41 @@ +// |reftest| skip -- Atomics.waitAsync is not supported +// 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 typedArray.buffer is not a SharedArrayBuffer +info: | + Atomics.waitAsync( typedArray, index, value, timeout ) + + 1. Return DoWait(async, typedArray, index, value, timeout). + + DoWait ( mode, typedArray, index, value, timeout ) + + 1. Let buffer be ? ValidateSharedIntegerTypedArray(typedArray, true). + + ValidateSharedIntegerTypedArray ( typedArray [ , waitable ] ) + + 5. If waitable is true, then + a. If typeName is not "BigInt64Array" or "BigInt64Array", throw a TypeError exception. + +features: [Atomics.waitAsync, ArrayBuffer, Atomics, TypedArray, BigInt, arrow-function] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const i64a = new BigInt64Array(new ArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + +const poisoned = { + valueOf() { + throw new Test262Error('should not evaluate this code'); + } +}; + +assert.throws(TypeError, () => { + Atomics.waitAsync(i64a, 0, 0n, 0); +}, '`Atomics.waitAsync(i64a, 0, 0n, 0)` throws a TypeError exception'); + +assert.throws(TypeError, () => { + Atomics.waitAsync(i64a, poisoned, poisoned, poisoned); +}, '`Atomics.waitAsync(i64a, poisoned, poisoned, poisoned)` throws a TypeError exception'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/not-a-typedarray-throws.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/not-a-typedarray-throws.js new file mode 100644 index 0000000000..8fc491f329 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/not-a-typedarray-throws.js @@ -0,0 +1,44 @@ +// |reftest| skip -- Atomics.waitAsync is not supported +// 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 the typedArray arg is not a TypedArray object +info: | + Atomics.waitAsync( typedArray, index, value, timeout ) + + 1. Return DoWait(async, typedArray, index, value, timeout). + + DoWait ( mode, typedArray, index, value, timeout ) + + 1. Let buffer be ? ValidateSharedIntegerTypedArray(typedArray, true). + + ValidateSharedIntegerTypedArray ( typedArray [ , waitable ] ) + + 2. Perform ? RequireInternalSlot(typedArray, [[TypedArrayName]]). + + RequireInternalSlot ( O, internalSlot ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have an internalSlot internal slot, throw a TypeError exception. + +features: [Atomics.waitAsync, arrow-function, Atomics] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); + +const poisoned = { + valueOf() { + throw new Test262Error('should not evaluate this code'); + } +}; + +assert.throws(TypeError, () => { + Atomics.waitAsync({}, 0, 0n, 0); +}, '`Atomics.waitAsync({}, 0, 0n, 0)` throws a TypeError exception'); + +assert.throws(TypeError, () => { + Atomics.waitAsync({}, poisoned, poisoned, poisoned); +}, '`Atomics.waitAsync({}, poisoned, poisoned, poisoned)` throws a TypeError exception'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/not-an-object-throws.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/not-an-object-throws.js new file mode 100644 index 0000000000..3f4caa0d05 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/not-an-object-throws.js @@ -0,0 +1,64 @@ +// |reftest| skip -- Atomics.waitAsync is not supported +// 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 typedArray arg is not an Object +info: | + Atomics.waitAsync( typedArray, index, value, timeout ) + + 1. Return DoWait(async, typedArray, index, value, timeout). + + DoWait ( mode, typedArray, index, value, timeout ) + + 1. Let buffer be ? ValidateSharedIntegerTypedArray(typedArray, true). + + ValidateSharedIntegerTypedArray ( typedArray [ , waitable ] ) + + 2. Perform ? RequireInternalSlot(typedArray, [[TypedArrayName]]). + + RequireInternalSlot ( O, internalSlot ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have an internalSlot internal slot, throw a TypeError exception. + +features: [Atomics.waitAsync, Symbol, arrow-function, Atomics] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const poisoned = { + valueOf() { + throw new Test262Error('should not evaluate this code'); + } +}; + +assert.throws(TypeError, () => { + Atomics.waitAsync(null, poisoned, poisoned, poisoned); +}, '`Atomics.waitAsync(null, poisoned, poisoned, poisoned)` throws a TypeError exception'); + +assert.throws(TypeError, () => { + Atomics.waitAsync(undefined, poisoned, poisoned, poisoned); +}, '`Atomics.waitAsync(undefined, poisoned, poisoned, poisoned)` throws a TypeError exception'); + +assert.throws(TypeError, () => { + Atomics.waitAsync(true, poisoned, poisoned, poisoned); +}, '`Atomics.waitAsync(true, poisoned, poisoned, poisoned)` throws a TypeError exception'); + +assert.throws(TypeError, () => { + Atomics.waitAsync(false, poisoned, poisoned, poisoned); +}, '`Atomics.waitAsync(false, poisoned, poisoned, poisoned)` throws a TypeError exception'); + +assert.throws(TypeError, () => { + Atomics.waitAsync('***string***', poisoned, poisoned, poisoned); +}, '`Atomics.waitAsync("***string***", poisoned, poisoned, poisoned)` throws a TypeError exception'); + +assert.throws(TypeError, () => { + Atomics.waitAsync(Number.NEGATIVE_INFINITY, poisoned, poisoned, poisoned); +}, '`Atomics.waitAsync(Number.NEGATIVE_INFINITY, poisoned, poisoned, poisoned)` throws a TypeError exception'); + +assert.throws(TypeError, () => { + Atomics.waitAsync(Symbol('***symbol***'), poisoned, poisoned, poisoned); +}, '`Atomics.waitAsync(Symbol("***symbol***"), poisoned, poisoned, poisoned)` throws a TypeError exception'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/null-bufferdata-throws.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/null-bufferdata-throws.js new file mode 100644 index 0000000000..96e8e987b4 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/null-bufferdata-throws.js @@ -0,0 +1,51 @@ +// |reftest| skip -- Atomics.waitAsync is not supported +// 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: > + A null value for bufferData throws a TypeError +info: | + Atomics.waitAsync( typedArray, index, value, timeout ) + + 1. Return DoWait(async, typedArray, index, value, timeout). + + DoWait ( mode, typedArray, index, value, timeout ) + + 1. Let buffer be ? ValidateSharedIntegerTypedArray(typedArray, true). + + ValidateSharedIntegerTypedArray ( typedArray [ , waitable ] ) + + 2. Perform ? RequireInternalSlot(typedArray, [[TypedArrayName]]). + + RequireInternalSlot ( O, internalSlot ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have an internalSlot internal slot, throw a TypeError exception. + +includes: [detachArrayBuffer.js] +features: [Atomics.waitAsync, ArrayBuffer, Atomics, TypedArray, BigInt] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const i64a = new BigInt64Array( + new ArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4) +); + +const poisoned = { + valueOf() { + throw new Test262Error('should not evaluate this code'); + } +}; + +try { + $DETACHBUFFER(i64a.buffer); // Detaching a non-shared ArrayBuffer sets the [[ArrayBufferData]] value to null +} catch (error) { + throw new Test262Error(`An unexpected error occurred when detaching ArrayBuffer: ${error.message}`); +} + +assert.throws(TypeError, function() { + Atomics.waitAsync(i64a, poisoned, poisoned, poisoned); +}, '`Atomics.waitAsync(i64a, poisoned, poisoned, poisoned)` throws a TypeError exception'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/null-for-timeout-agent.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/null-for-timeout-agent.js new file mode 100644 index 0000000000..298f98d34f --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/null-for-timeout-agent.js @@ -0,0 +1,98 @@ +// |reftest| skip async -- Atomics.waitAsync is not supported +// 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: > + null 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). + + Null -> Return +0. + +flags: [async] +includes: [atomicsHelper.js] +features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, BigInt, arrow-function, async-functions] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const RUNNING = 1; + +$262.agent.start(` + const valueOf = { + valueOf() { + return null; + } + }; + + const toPrimitive = { + [Symbol.toPrimitive]() { + return null; + } + }; + + $262.agent.receiveBroadcast(async (sab) => { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + $262.agent.report(await Atomics.waitAsync(i64a, 0, 0n, null).value); + $262.agent.report(await Atomics.waitAsync(i64a, 0, 0n, valueOf).value); + $262.agent.report(await Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value); + $262.agent.report(Atomics.waitAsync(i64a, 0, 0n, null).value); + $262.agent.report(Atomics.waitAsync(i64a, 0, 0n, valueOf).value); + $262.agent.report(Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value); + $262.agent.leaving(); + }); +`); + +const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + +$262.agent.safeBroadcastAsync(i64a, RUNNING, 1n).then(async agentCount => { + assert.sameValue(agentCount, 1n, 'The value of `agentCount` is 1n'); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + '(await $262.agent.getReportAsync()) resolves to the value "timed-out"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + '(await $262.agent.getReportAsync()) resolves to the value "timed-out"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + '(await $262.agent.getReportAsync()) resolves to the value "timed-out"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + '(await $262.agent.getReportAsync()) resolves to the value "timed-out"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + '(await $262.agent.getReportAsync()) resolves to the value "timed-out"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + '(await $262.agent.getReportAsync()) resolves to the value "timed-out"' + ); + + assert.sameValue( + Atomics.notify(i64a, 0), + 0, + 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0) must return 0' + ); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/null-for-timeout.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/null-for-timeout.js new file mode 100644 index 0000000000..9f50139d06 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/null-for-timeout.js @@ -0,0 +1,54 @@ +// |reftest| skip -- Atomics.waitAsync is not supported +// 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: > + null 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). + + Null -> Return +0. + +features: [Atomics.waitAsync, SharedArrayBuffer, Symbol, Symbol.toPrimitive, TypedArray, computed-property-names, Atomics, BigInt, arrow-function] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + +const valueOf = { + valueOf() { + return null; + } +}; + +const toPrimitive = { + [Symbol.toPrimitive]() { + return null; + } +}; + +assert.sameValue( + Atomics.waitAsync(i64a, 0, 0n, null).value, + 'timed-out', + 'The value of Atomics.waitAsync(i64a, 0, 0n, null).value is "timed-out"' +); + +assert.sameValue( + Atomics.waitAsync(i64a, 0, 0n, valueOf).value, + 'timed-out', + 'The value of Atomics.waitAsync(i64a, 0, 0n, valueOf).value is "timed-out"' +); + +assert.sameValue( + Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value, + 'timed-out', + 'The value of Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value is "timed-out"' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/object-for-timeout-agent.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/object-for-timeout-agent.js new file mode 100644 index 0000000000..be0fece5ee --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/object-for-timeout-agent.js @@ -0,0 +1,107 @@ +// |reftest| skip async -- Atomics.waitAsync is not supported +// 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: > + Object valueOf, toString, toPrimitive Zero 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). + + 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, BigInt, arrow-function, async-functions] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const RUNNING = 1; + +$262.agent.start(` + const valueOf = { + valueOf() { + return 0; + } + }; + + const toString = { + toString() { + return "0"; + } + }; + + const toPrimitive = { + [Symbol.toPrimitive]() { + return 0; + } + }; + + $262.agent.receiveBroadcast(async (sab) => { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + $262.agent.report(await Atomics.waitAsync(i64a, 0, 0n, valueOf).value); + $262.agent.report(await Atomics.waitAsync(i64a, 0, 0n, toString).value); + $262.agent.report(await Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value); + $262.agent.report(Atomics.waitAsync(i64a, 0, 0n, valueOf).value); + $262.agent.report(Atomics.waitAsync(i64a, 0, 0n, toString).value); + $262.agent.report(Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value); + $262.agent.leaving(); + }); +`); + +const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + +$262.agent.safeBroadcastAsync(i64a, RUNNING, 1n).then(async agentCount => { + assert.sameValue(agentCount, 1n, 'The value of `agentCount` is 1n'); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + '(await $262.agent.getReportAsync()) resolves to the value "timed-out"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + '(await $262.agent.getReportAsync()) resolves to the value "timed-out"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + '(await $262.agent.getReportAsync()) resolves to the value "timed-out"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + '(await $262.agent.getReportAsync()) resolves to the value "timed-out"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + '(await $262.agent.getReportAsync()) resolves to the value "timed-out"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + '(await $262.agent.getReportAsync()) resolves to the value "timed-out"' + ); + + assert.sameValue( + Atomics.notify(i64a, 0), + 0, + 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0) must return 0' + ); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/object-for-timeout.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/object-for-timeout.js new file mode 100644 index 0000000000..d46f27436b --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/object-for-timeout.js @@ -0,0 +1,72 @@ +// |reftest| skip async -- Atomics.waitAsync is not supported +// 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: > + Object valueOf, toString, toPrimitive Zero 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). + + Object -> Apply the following steps: + + Let primValue be ? ToPrimitive(argument, hint Number). + Return ? ToNumber(primValue). + +features: [Atomics.waitAsync, SharedArrayBuffer, Symbol, Symbol.toPrimitive, TypedArray, computed-property-names, Atomics, BigInt, arrow-function] +flags: [async] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + +const valueOf = { + valueOf() { + return 0; + } +}; + +const toString = { + toString() { + return '0'; + } +}; + +const toPrimitive = { + [Symbol.toPrimitive]() { + return 0; + } +}; + +assert.sameValue( + Atomics.waitAsync(i64a, 0, 0n, valueOf).value, + 'timed-out', + 'The value of Atomics.waitAsync(i64a, 0, 0n, valueOf).value is "timed-out"' +); + +assert.sameValue( + Atomics.waitAsync(i64a, 0, 0n, toString).value, + 'timed-out', + 'The value of Atomics.waitAsync(i64a, 0, 0n, toString).value is "timed-out"' +); + +assert.sameValue( + Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value, + 'timed-out', + 'The value of Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value is "timed-out"' +); + +Promise.all([ + Atomics.waitAsync(i64a, 0, 0n, valueOf).value, + Atomics.waitAsync(i64a, 0, 0n, toString).value, + Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value +]).then(outcomes => { + assert.sameValue(outcomes[0], 'timed-out', 'The value of outcomes[0] is "timed-out"'); + assert.sameValue(outcomes[1], 'timed-out', 'The value of outcomes[1] is "timed-out"'); + assert.sameValue(outcomes[2], 'timed-out', 'The value of outcomes[2] is "timed-out"'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/out-of-range-index-throws.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/out-of-range-index-throws.js new file mode 100644 index 0000000000..e129569ae1 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/out-of-range-index-throws.js @@ -0,0 +1,49 @@ +// |reftest| skip -- Atomics.waitAsync is not supported +// 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 RangeError if value of index arg is out of range +info: | + Atomics.waitAsync( typedArray, index, value, timeout ) + + 1. Return DoWait(async, typedArray, index, value, timeout). + + DoWait ( mode, typedArray, index, value, timeout ) + + 2. Let i be ? ValidateAtomicAccess(typedArray, index). + + ... + 2.Let accessIndex be ? ToIndex(requestIndex). + ... + 5. If accessIndex ≥ length, throw a RangeError exception. +features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, BigInt] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4) +); + +const poisoned = { + valueOf() { + throw new Test262Error('should not evaluate this code'); + } +}; + +assert.throws(RangeError, function() { + Atomics.waitAsync(i64a, Infinity, poisoned, poisoned); +}, '`Atomics.waitAsync(i64a, Infinity, poisoned, poisoned)` throws a RangeError exception'); +assert.throws(RangeError, function() { + Atomics.waitAsync(i64a, -1, poisoned, poisoned); +}, '`Atomics.waitAsync(i64a, -1, poisoned, poisoned)` throws a RangeError exception'); +assert.throws(RangeError, function() { + Atomics.waitAsync(i64a, 4, poisoned, poisoned); +}, '`Atomics.waitAsync(i64a, 4, poisoned, poisoned)` throws a RangeError exception'); +assert.throws(RangeError, function() { + Atomics.waitAsync(i64a, 200, poisoned, poisoned); +}, '`Atomics.waitAsync(i64a, 200, poisoned, poisoned)` throws a RangeError exception'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/poisoned-object-for-timeout-throws-agent.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/poisoned-object-for-timeout-throws-agent.js new file mode 100644 index 0000000000..abb3e8d0d1 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/poisoned-object-for-timeout-throws-agent.js @@ -0,0 +1,86 @@ +// |reftest| skip async -- Atomics.waitAsync is not supported +// 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). + + Let primValue be ? ToPrimitive(argument, hint Number). + Return ? ToNumber(primValue). + +flags: [async] +includes: [atomicsHelper.js] +features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, BigInt, arrow-function, async-functions] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const RUNNING = 1; + +$262.agent.start(` + const poisonedValueOf = { + valueOf() { + throw new Error('should not evaluate this code'); + } + }; + + const poisonedToPrimitive = { + [Symbol.toPrimitive]() { + throw new Error('passing a poisoned object using @@ToPrimitive'); + } + }; + + $262.agent.receiveBroadcast(function(sab) { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + let status1 = ''; + let status2 = ''; + + try { + Atomics.waitAsync(i64a, 0, 0n, poisonedValueOf); + } catch (error) { + status1 = 'poisonedValueOf'; + } + try { + Atomics.waitAsync(i64a, 0, 0n, poisonedToPrimitive); + } catch (error) { + status2 = 'poisonedToPrimitive'; + } + + $262.agent.report(status1); + $262.agent.report(status2); + $262.agent.leaving(); + }); +`); + +const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + +$262.agent.safeBroadcastAsync(i64a, RUNNING, 1n).then(async agentCount => { + assert.sameValue(agentCount, 1n, 'The value of `agentCount` is 1n'); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'poisonedValueOf', + '(await $262.agent.getReportAsync()) resolves to the value "poisonedValueOf"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'poisonedToPrimitive', + '(await $262.agent.getReportAsync()) resolves to the value "poisonedToPrimitive"' + ); + + assert.sameValue( + Atomics.notify(i64a, 0), + 0, + 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0) must return 0' + ); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/poisoned-object-for-timeout-throws.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/poisoned-object-for-timeout-throws.js new file mode 100644 index 0000000000..a7878a5ba7 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/poisoned-object-for-timeout-throws.js @@ -0,0 +1,45 @@ +// |reftest| skip -- Atomics.waitAsync is not supported +// 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). + + Let primValue be ? ToPrimitive(argument, hint Number). + Return ? ToNumber(primValue). + +features: [Atomics.waitAsync, SharedArrayBuffer, Symbol, Symbol.toPrimitive, TypedArray, computed-property-names, Atomics, BigInt] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + +const poisonedValueOf = { + valueOf() { + throw new Test262Error('should not evaluate this code'); + } +}; + +const poisonedToPrimitive = { + [Symbol.toPrimitive]() { + throw new Test262Error('passing a poisoned object using @@ToPrimitive'); + } +}; + +assert.throws(Test262Error, function() { + Atomics.waitAsync(i64a, 0, 0n, poisonedValueOf); +}, '`Atomics.waitAsync(i64a, 0, 0n, poisonedValueOf)` throws a Test262Error exception'); + +assert.throws(Test262Error, function() { + Atomics.waitAsync(i64a, 0, 0n, poisonedToPrimitive); +}, '`Atomics.waitAsync(i64a, 0, 0n, poisonedToPrimitive)` throws a Test262Error exception'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/shell.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/shell.js diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/symbol-for-index-throws-agent.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/symbol-for-index-throws-agent.js new file mode 100644 index 0000000000..41cbde0555 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/symbol-for-index-throws-agent.js @@ -0,0 +1,98 @@ +// |reftest| skip async -- Atomics.waitAsync is not supported +// 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 ) + + 2. Let i be ? ValidateAtomicAccess(typedArray, index). + + ValidateAtomicAccess( typedArray, requestIndex ) + + 2. Let accessIndex be ? ToIndex(requestIndex). + + ToIndex ( value ) + + 2. Else, + a. Let integerIndex be ? ToInteger(value). + + ToInteger(value) + + 1. Let number be ? ToNumber(argument). + + Symbol --> Throw a TypeError exception. + +flags: [async] +includes: [atomicsHelper.js] +features: [Atomics.waitAsync, SharedArrayBuffer, Symbol, Symbol.toPrimitive, TypedArray, Atomics, BigInt, arrow-function, async-functions] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const RUNNING = 1; + +$262.agent.start(` + const poisonedValueOf = { + valueOf() { + throw new Test262Error('should not evaluate this code'); + } + }; + + const poisonedToPrimitive = { + [Symbol.toPrimitive]() { + throw new Test262Error('should not evaluate this code'); + } + }; + + $262.agent.receiveBroadcast(function(sab) { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + let status1 = ''; + let status2 = ''; + + try { + Atomics.waitAsync(i64a, Symbol('1'), poisonedValueOf, poisonedValueOf); + } catch (error) { + status1 = 'A ' + error.name; + } + try { + Atomics.waitAsync(i64a, Symbol('2'), poisonedToPrimitive, poisonedToPrimitive); + } catch (error) { + status2 = 'B ' + error.name; + } + + $262.agent.report(status1); + $262.agent.report(status2); + $262.agent.leaving(); + }); +`); + +const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + +$262.agent.safeBroadcastAsync(i64a, RUNNING, 1n).then(async agentCount => { + assert.sameValue(agentCount, 1n, 'The value of `agentCount` is 1n'); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'A TypeError', + '(await $262.agent.getReportAsync()) resolves to the value "A TypeError"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'B TypeError', + '(await $262.agent.getReportAsync()) resolves to the value "B TypeError"' + ); + + assert.sameValue( + Atomics.notify(i64a, 0), + 0, + 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0) must return 0' + ); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/symbol-for-index-throws.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/symbol-for-index-throws.js new file mode 100644 index 0000000000..aaa9ae80e9 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/symbol-for-index-throws.js @@ -0,0 +1,71 @@ +// |reftest| skip -- Atomics.waitAsync is not supported +// 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 ) + + 2. Let i be ? ValidateAtomicAccess(typedArray, index). + + ValidateAtomicAccess( typedArray, requestIndex ) + + 2. Let accessIndex be ? ToIndex(requestIndex). + + ToIndex ( value ) + + 2. Else, + a. Let integerIndex be ? ToInteger(value). + + ToInteger(value) + + 1. Let number be ? ToNumber(argument). + + Symbol --> Throw a TypeError exception. + +features: [Atomics.waitAsync, SharedArrayBuffer, Symbol, Symbol.toPrimitive, TypedArray, computed-property-names, Atomics, BigInt] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4) +); + +const poisonedValueOf = { + valueOf() { + throw new Test262Error('should not evaluate this code'); + } +}; + +const poisonedToPrimitive = { + [Symbol.toPrimitive]() { + throw new Test262Error('should not evaluate this code'); + } +}; + +assert.throws(Test262Error, function() { + Atomics.waitAsync(i64a, poisonedValueOf, poisonedValueOf, poisonedValueOf); +}, '`Atomics.waitAsync(i64a, poisonedValueOf, poisonedValueOf, poisonedValueOf)` throws a Test262Error exception'); + +assert.throws(Test262Error, function() { + Atomics.waitAsync(i64a, poisonedToPrimitive, poisonedToPrimitive, poisonedToPrimitive); +}, '`Atomics.waitAsync(i64a, poisonedToPrimitive, poisonedToPrimitive, poisonedToPrimitive)` throws a Test262Error exception'); + +assert.throws(TypeError, function() { + Atomics.waitAsync(i64a, Symbol('1'), poisonedValueOf, poisonedValueOf); +}, '`Atomics.waitAsync(i64a, Symbol("1"), poisonedValueOf, poisonedValueOf)` throws a TypeError exception'); + +assert.throws(TypeError, function() { + Atomics.waitAsync(i64a, Symbol('2'), poisonedToPrimitive, poisonedToPrimitive); +}, '`Atomics.waitAsync(i64a, Symbol("2"), poisonedToPrimitive, poisonedToPrimitive)` throws a TypeError exception'); + + + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/symbol-for-timeout-throws-agent.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/symbol-for-timeout-throws-agent.js new file mode 100644 index 0000000000..2ef1e36e59 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/symbol-for-timeout-throws-agent.js @@ -0,0 +1,73 @@ +// |reftest| skip async -- Atomics.waitAsync is not supported +// 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). + + Symbol --> Throw a TypeError exception. + +flags: [async] +includes: [atomicsHelper.js] +features: [Atomics.waitAsync, SharedArrayBuffer, Symbol, Symbol.toPrimitive, TypedArray, Atomics, BigInt, arrow-function, async-functions] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const RUNNING = 1; + +$262.agent.start(` + $262.agent.receiveBroadcast(function(sab) { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + let status1 = ''; + let status2 = ''; + + try { + Atomics.waitAsync(i64a, 0, 0n, Symbol('1')); + } catch (error) { + status1 = 'A ' + error.name; + } + try { + Atomics.waitAsync(i64a, 0, 0n, Symbol('2')); + } catch (error) { + status2 = 'B ' + error.name; + } + + $262.agent.report(status1); + $262.agent.report(status2); + $262.agent.leaving(); + }); +`); + +const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + +$262.agent.safeBroadcastAsync(i64a, RUNNING, 1n).then(async agentCount => { + assert.sameValue(agentCount, 1n, 'The value of `agentCount` is 1n'); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'A TypeError', + '(await $262.agent.getReportAsync()) resolves to the value "A TypeError"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'B TypeError', + '(await $262.agent.getReportAsync()) resolves to the value "B TypeError"' + ); + + assert.sameValue( + Atomics.notify(i64a, 0), + 0, + 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0) must return 0' + ); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/symbol-for-timeout-throws.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/symbol-for-timeout-throws.js new file mode 100644 index 0000000000..55dbafc489 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/symbol-for-timeout-throws.js @@ -0,0 +1,52 @@ +// |reftest| skip -- Atomics.waitAsync is not supported +// 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). + + Symbol --> Throw a TypeError exception. + +features: [Atomics.waitAsync, SharedArrayBuffer, Symbol, Symbol.toPrimitive, TypedArray, computed-property-names, Atomics, BigInt] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + +const poisonedValueOf = { + valueOf() { + throw new Test262Error('should not evaluate this code'); + } +}; + +const poisonedToPrimitive = { + [Symbol.toPrimitive]() { + throw new Test262Error('passing a poisoned object using @@ToPrimitive'); + } +}; + +assert.throws(Test262Error, function() { + Atomics.waitAsync(i64a, 0, 0n, poisonedValueOf); +}, '`Atomics.waitAsync(i64a, 0, 0n, poisonedValueOf)` throws a Test262Error exception'); + +assert.throws(Test262Error, function() { + Atomics.waitAsync(i64a, 0, 0n, poisonedToPrimitive); +}, '`Atomics.waitAsync(i64a, 0, 0n, poisonedToPrimitive)` throws a Test262Error exception'); + +assert.throws(TypeError, function() { + Atomics.waitAsync(i64a, 0, 0n, Symbol('foo')); +}, '`Atomics.waitAsync(i64a, 0, 0n, Symbol("foo"))` throws a TypeError exception'); + +assert.throws(TypeError, function() { + Atomics.waitAsync(i64a, 0, 0n, Symbol('foo')); +}, '`Atomics.waitAsync(i64a, 0, 0n, Symbol("foo"))` throws a TypeError exception'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/symbol-for-value-throws-agent.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/symbol-for-value-throws-agent.js new file mode 100644 index 0000000000..70bcc8d273 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/symbol-for-value-throws-agent.js @@ -0,0 +1,89 @@ +// |reftest| skip async -- Atomics.waitAsync is not supported +// 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 value arg is a Symbol +info: | + Atomics.waitAsync( typedArray, index, value, timeout ) + + 1. Return DoWait(async, typedArray, index, value, timeout). + + DoWait ( mode, typedArray, index, value, timeout ) + + 5. Otherwise, let v be ? ToInt32(value). + + ToInt32(value) + + 1.Let number be ? ToNumber(argument). + + Symbol --> Throw a TypeError exception. + +flags: [async] +includes: [atomicsHelper.js] +features: [Atomics.waitAsync, SharedArrayBuffer, Symbol, Symbol.toPrimitive, TypedArray, Atomics, BigInt, arrow-function, async-functions] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const RUNNING = 1; + +$262.agent.start(` + const poisonedValueOf = { + valueOf: function() { + throw new Test262Error('should not evaluate this code'); + } + }; + + const poisonedToPrimitive = { + [Symbol.toPrimitive]: function() { + throw new Test262Error("passing a poisoned object using @@ToPrimitive"); + } + }; + + $262.agent.receiveBroadcast(function(sab) { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + let status1 = ""; + let status2 = ""; + + try { + Atomics.waitAsync(i64a, 0, Symbol("1"), poisonedValueOf); + } catch (error) { + status1 = 'A ' + error.name; + } + try { + Atomics.waitAsync(i64a, 0, Symbol("2"), poisonedToPrimitive); + } catch (error) { + status2 = 'B ' + error.name; + } + + $262.agent.report(status1); + $262.agent.report(status2); + $262.agent.leaving(); + }); +`); + +const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + +$262.agent.safeBroadcastAsync(i64a, RUNNING, 1n).then(async agentCount => { + assert.sameValue(agentCount, 1n, 'The value of `agentCount` is 1n'); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'A TypeError', + '(await $262.agent.getReportAsync()) resolves to the value "A TypeError"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'B TypeError', + '(await $262.agent.getReportAsync()) resolves to the value "B TypeError"' + ); + + assert.sameValue( + Atomics.notify(i64a, 0), + 0, + 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0) must return 0' + ); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/symbol-for-value-throws.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/symbol-for-value-throws.js new file mode 100644 index 0000000000..552928e077 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/symbol-for-value-throws.js @@ -0,0 +1,60 @@ +// |reftest| skip -- Atomics.waitAsync is not supported +// 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 value arg is a Symbol +info: | + Atomics.waitAsync( typedArray, index, value, timeout ) + + 1. Return DoWait(async, typedArray, index, value, timeout). + + DoWait ( mode, typedArray, index, value, timeout ) + + 5. Otherwise, let v be ? ToInt32(value). + + ToInt32(value) + + 1.Let number be ? ToNumber(argument). + + Symbol --> Throw a TypeError exception. + +features: [Atomics.waitAsync, SharedArrayBuffer, Symbol, Symbol.toPrimitive, TypedArray, computed-property-names, Atomics, BigInt] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4) +); + +const poisonedValueOf = { + valueOf() { + throw new Test262Error('should not evaluate this code'); + } +}; + +const poisonedToPrimitive = { + [Symbol.toPrimitive]() { + throw new Test262Error("passing a poisoned object using @@ToPrimitive"); + } +}; + +assert.throws(Test262Error, function() { + Atomics.waitAsync(i64a, 0, poisonedValueOf, poisonedValueOf); +}, '`Atomics.waitAsync(i64a, 0, poisonedValueOf, poisonedValueOf)` throws a Test262Error exception'); + +assert.throws(Test262Error, function() { + Atomics.waitAsync(i64a, 0, poisonedToPrimitive, poisonedToPrimitive); +}, '`Atomics.waitAsync(i64a, 0, poisonedToPrimitive, poisonedToPrimitive)` throws a Test262Error exception'); + +assert.throws(TypeError, function() { + Atomics.waitAsync(i64a, 0, Symbol("foo"), poisonedValueOf); +}, '`Atomics.waitAsync(i64a, 0, Symbol("foo"), poisonedValueOf)` throws a TypeError exception'); + +assert.throws(TypeError, function() { + Atomics.waitAsync(i64a, 0, Symbol("foo"), poisonedToPrimitive); +}, '`Atomics.waitAsync(i64a, 0, Symbol("foo"), poisonedToPrimitive)` throws a TypeError exception'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/true-for-timeout-agent.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/true-for-timeout-agent.js new file mode 100644 index 0000000000..af48ef70d9 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/true-for-timeout-agent.js @@ -0,0 +1,75 @@ +// |reftest| skip async -- Atomics.waitAsync is not supported +// 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, BigInt, arrow-function, async-functions] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const RUNNING = 1; + +$262.agent.start(` + const valueOf = { + valueOf() { + return true; + } + }; + + const toPrimitive = { + [Symbol.toPrimitive]() { + return true; + } + }; + + $262.agent.receiveBroadcast(async (sab) => { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + $262.agent.report(await Atomics.waitAsync(i64a, 0, 0n, true).value); + $262.agent.report(await Atomics.waitAsync(i64a, 0, 0n, valueOf).value); + $262.agent.report(await Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value); + $262.agent.leaving(); + }); +`); + +const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + +$262.agent.safeBroadcastAsync(i64a, RUNNING, 1n).then(async agentCount => { + assert.sameValue(agentCount, 1n, 'The value of `agentCount` is 1n'); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + '(await $262.agent.getReportAsync()) resolves to the value "timed-out"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + '(await $262.agent.getReportAsync()) resolves to the value "timed-out"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + '(await $262.agent.getReportAsync()) resolves to the value "timed-out"' + ); + + assert.sameValue( + Atomics.notify(i64a, 0), + 0, + 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0) must return 0' + ); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/true-for-timeout.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/true-for-timeout.js new file mode 100644 index 0000000000..884acd3219 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/true-for-timeout.js @@ -0,0 +1,65 @@ +// |reftest| skip async -- Atomics.waitAsync is not supported +// 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, BigInt, computed-property-names, Symbol, Symbol.toPrimitive, arrow-function] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + +const valueOf = { + valueOf() { + return true; + } +}; + +const toPrimitive = { + [Symbol.toPrimitive]() { + return true; + } +}; + +let outcomes = []; +let lifespan = 1000; +let start = $262.agent.monotonicNow(); + +(function wait() { + let elapsed = $262.agent.monotonicNow() - start; + + if (elapsed > lifespan) { + $DONE('Test timed out'); + return; + } + + if (outcomes.length) { + assert.sameValue(outcomes[0], 'timed-out', 'The value of outcomes[0] is "timed-out"'); + assert.sameValue(outcomes[1], 'timed-out', 'The value of outcomes[1] is "timed-out"'); + assert.sameValue(outcomes[2], 'timed-out', 'The value of outcomes[2] is "timed-out"'); + $DONE(); + return; + } + + $262.agent.setTimeout(wait, 0); +})(); + +Promise.all([ + Atomics.waitAsync(i64a, 0, 0n, true).value, + Atomics.waitAsync(i64a, 0, 0n, valueOf).value, + Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value +]).then(results => outcomes = results, $DONE); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/undefined-for-timeout-agent.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/undefined-for-timeout-agent.js new file mode 100644 index 0000000000..9ccc4e03c8 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/undefined-for-timeout-agent.js @@ -0,0 +1,82 @@ +// |reftest| skip async -- Atomics.waitAsync is not supported +// 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 is coerced to zero +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, BigInt, arrow-function, async-functions] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); + +const WAIT_INDEX = 0; +const RUNNING = 1; +const NUMAGENT = 2; +const NOTIFYCOUNT = 2; + +$262.agent.start(` + $262.agent.receiveBroadcast(async (sab) => { + var i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + // undefined => NaN => +Infinity + $262.agent.report("A " + (await Atomics.waitAsync(i64a, 0, 0n, undefined).value)); + $262.agent.leaving(); + }); +`); + +$262.agent.start(` + $262.agent.receiveBroadcast(async (sab) => { + var i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + // undefined timeout arg => NaN => +Infinity + $262.agent.report("B " + (await Atomics.waitAsync(i64a, 0, 0n).value)); + $262.agent.leaving(); + }); +`); + +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4) +); + +$262.agent.safeBroadcastAsync(i64a, RUNNING, BigInt(NUMAGENT)).then(async (agentCount) => { + + assert.sameValue( + agentCount, + BigInt(NUMAGENT), + 'The value of `agentCount` must return the same value returned by BigInt(NUMAGENT)' + ); + + assert.sameValue( + Atomics.notify(i64a, WAIT_INDEX, NOTIFYCOUNT), + NOTIFYCOUNT, + 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0, 2) must return the value of NOTIFYCOUNT' + ); + + const reports = [ + await $262.agent.getReportAsync(), + await $262.agent.getReportAsync(), + ]; + + 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); + diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/undefined-for-timeout.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/undefined-for-timeout.js new file mode 100644 index 0000000000..0b9deb11d2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/undefined-for-timeout.js @@ -0,0 +1,51 @@ +// |reftest| skip async -- Atomics.waitAsync is not supported +// 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 is coerced to zero +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] +features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, BigInt, computed-property-names, Symbol, Symbol.toPrimitive, arrow-function] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + +const valueOf = { + valueOf() { + return undefined; + } +}; + +const toPrimitive = { + [Symbol.toPrimitive]() { + return undefined; + } +}; + +Promise.all([ + Atomics.waitAsync(i64a, 0, 0n).value, + Atomics.waitAsync(i64a, 0, 0n, undefined).value, + Atomics.waitAsync(i64a, 0, 0n, valueOf).value, + Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value +]).then(outcomes => { + assert.sameValue(outcomes[0], 'ok', 'The value of outcomes[0] is "ok"'); + assert.sameValue(outcomes[1], 'ok', 'The value of outcomes[1] is "ok"'); + assert.sameValue(outcomes[2], 'ok', 'The value of outcomes[2] is "ok"'); + assert.sameValue(outcomes[3], 'ok', 'The value of outcomes[3] is "ok"'); +}).then($DONE, $DONE); + +Atomics.notify(i64a, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/undefined-index-defaults-to-zero-agent.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/undefined-index-defaults-to-zero-agent.js new file mode 100644 index 0000000000..0eb729af68 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/undefined-index-defaults-to-zero-agent.js @@ -0,0 +1,84 @@ +// |reftest| skip async -- Atomics.waitAsync is not supported +// 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 index arg is coerced to zero +info: | + Atomics.waitAsync( typedArray, index, value, timeout ) + + 1. Return DoWait(async, typedArray, index, value, timeout). + + DoWait ( mode, 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. + +flags: [async] +includes: [atomicsHelper.js] +features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, BigInt, arrow-function, async-functions] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); + +const WAIT_INDEX = 0; +const RUNNING = 1; +const NUMAGENT = 2; +const NOTIFYCOUNT = 2; + +$262.agent.start(` + $262.agent.receiveBroadcast(async (sab) => { + var i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + $262.agent.report("A " + (await Atomics.waitAsync(i64a, undefined, 0n).value)); + $262.agent.leaving(); + }); +`); + +$262.agent.start(` + $262.agent.receiveBroadcast(async (sab) => { + var i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + $262.agent.report("B " + (await Atomics.waitAsync(i64a, undefined, 0n).value)); + $262.agent.leaving(); + }); +`); + +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4) +); + +$262.agent.safeBroadcastAsync(i64a, RUNNING, BigInt(NUMAGENT)).then(async (agentCount) => { + + assert.sameValue( + agentCount, + BigInt(NUMAGENT), + 'The value of `agentCount` must return the same value returned by BigInt(NUMAGENT)' + ); + + assert.sameValue( + Atomics.notify(i64a, WAIT_INDEX, NOTIFYCOUNT), + NOTIFYCOUNT, + 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0, 2) must return the value of NOTIFYCOUNT' + ); + + const reports = [ + await $262.agent.getReportAsync(), + await $262.agent.getReportAsync(), + ]; + + 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); + diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/value-not-equal-agent.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/value-not-equal-agent.js new file mode 100644 index 0000000000..6c0922fcf8 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/value-not-equal-agent.js @@ -0,0 +1,63 @@ +// |reftest| skip async -- Atomics.waitAsync is not supported +// 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: > + Returns "not-equal" when value arg does not match an index in the typedArray +info: | + Atomics.waitAsync( typedArray, index, value, timeout ) + + 1. Return DoWait(async, typedArray, index, value, timeout). + + DoWait ( mode, typedArray, index, value, timeout ) + + 16. Let w be ! AtomicLoad(typedArray, i). + 17. If v is not equal to w, then + a. Perform LeaveCriticalSection(WL). + b. If mode is sync, then + i. Return the String "not-equal". + c. Perform ! Call(capability.[[Resolve]], undefined, « "not-equal" »). + d. Return promiseCapability.[[Promise]]. + +flags: [async] +includes: [atomicsHelper.js] +features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, BigInt, arrow-function, async-functions] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const RUNNING = 1; +const value = 42n; + +$262.agent.start(` + $262.agent.receiveBroadcast(function(sab) { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + $262.agent.report(Atomics.store(i64a, 0, 42n)); + $262.agent.report(Atomics.waitAsync(i64a, 0, 0n).value); + $262.agent.leaving(); + }); +`); + +const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + +$262.agent.safeBroadcastAsync(i64a, RUNNING, 1n).then(async agentCount => { + assert.sameValue(agentCount, 1n, 'The value of `agentCount` is 1n'); + + assert.sameValue( + await $262.agent.getReportAsync(), + value.toString(), + '(await $262.agent.getReportAsync()) must return the same value returned by value.toString()' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'not-equal', + '(await $262.agent.getReportAsync()) resolves to the value "not-equal"' + ); + + assert.sameValue( + Atomics.notify(i64a, 0, 1), + 0, + 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0, 1) must return 0' + ); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/value-not-equal.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/value-not-equal.js new file mode 100644 index 0000000000..adc2bc69a2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/value-not-equal.js @@ -0,0 +1,44 @@ +// |reftest| skip async -- Atomics.waitAsync is not supported +// 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: > + Returns "not-equal" when value arg does not match an index in the typedArray +info: | + Atomics.waitAsync( typedArray, index, value, timeout ) + + 1. Return DoWait(async, typedArray, index, value, timeout). + + DoWait ( mode, typedArray, index, value, timeout ) + + 16. Let w be ! AtomicLoad(typedArray, i). + 17. If v is not equal to w, then + a. Perform LeaveCriticalSection(WL). + b. If mode is sync, then + i. Return the String "not-equal". + c. Perform ! Call(capability.[[Resolve]], undefined, « "not-equal" »). + d. Return promiseCapability.[[Promise]]. + +flags: [async] +features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, BigInt, computed-property-names, Symbol, Symbol.toPrimitive, Atomics, arrow-function] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + +const valueOf = { + valueOf() { + return undefined; + } +}; + +const toPrimitive = { + [Symbol.toPrimitive]() { + return undefined; + } +}; + +Promise.all([Atomics.store(i64a, 0, 42n), Atomics.waitAsync(i64a, 0, 0n).value]).then(outcomes => { + assert.sameValue(outcomes[0], 42n, 'The value of outcomes[0] is 42n'); + assert.sameValue(outcomes[1], 'not-equal', 'The value of outcomes[1] is "not-equal"'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/waiterlist-block-indexedposition-wake.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/waiterlist-block-indexedposition-wake.js new file mode 100644 index 0000000000..bde4046ecd --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/waiterlist-block-indexedposition-wake.js @@ -0,0 +1,90 @@ +// |reftest| skip async -- Atomics.waitAsync is not supported +// 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: > + Get the correct WaiterList +info: | + Atomics.waitAsync( typedArray, index, value, timeout ) + + 1. Return DoWait(async, typedArray, index, value, timeout). + + DoWait ( mode, typedArray, index, value, timeout ) + + 11. Let indexedPosition be (i × 4) + offset. + 12. Let WL be GetWaiterList(block, indexedPosition). + + GetWaiterList( block, i ) + + ... + 4. Return the WaiterList that is referenced by the pair (block, i). + +flags: [async] +includes: [atomicsHelper.js] +features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, BigInt, arrow-function, async-functions] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); + +const NUMAGENT = 2; +const RUNNING = 4; + +$262.agent.start(` + $262.agent.receiveBroadcast(async (sab) => { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + // Wait on index 0 + $262.agent.report(await Atomics.waitAsync(i64a, 0, 0n, Infinity).value); + $262.agent.leaving(); + }); +`); + +$262.agent.start(` + $262.agent.receiveBroadcast(async (sab) => { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + // Wait on index 2 + $262.agent.report(await Atomics.waitAsync(i64a, 2, 0n, Infinity).value); + $262.agent.leaving(); + }); +`); + +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 5) +); + +$262.agent.safeBroadcastAsync(i64a, RUNNING, BigInt(NUMAGENT)).then(async (agentCount) => { + + assert.sameValue( + agentCount, + BigInt(NUMAGENT), + 'The value of `agentCount` must return the same value returned by BigInt(NUMAGENT)' + ); + + // Notify index 1, notifies nothing + assert.sameValue(Atomics.notify(i64a, 1), 0, 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 5)), 1) must return 0'); + + // Notify index 3, notifies nothing + assert.sameValue(Atomics.notify(i64a, 3), 0, 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 5)), 3) must return 0'); + + // Notify index 2, notifies 1 + assert.sameValue(Atomics.notify(i64a, 2), 1, 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 5)), 2) must return 1'); + assert.sameValue( + await $262.agent.getReportAsync(), + 'ok', + '(await $262.agent.getReportAsync()) resolves to the value "ok"' + ); + + // Notify index 0, notifies 1 + assert.sameValue(Atomics.notify(i64a, 0), 1, 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 5)), 0) must return 1'); + assert.sameValue( + await $262.agent.getReportAsync(), + 'ok', + '(await $262.agent.getReportAsync()) resolves to the value "ok"' + ); + +}).then($DONE, $DONE); + diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/was-woken-before-timeout.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/was-woken-before-timeout.js new file mode 100644 index 0000000000..ba8807b68d --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/was-woken-before-timeout.js @@ -0,0 +1,53 @@ +// |reftest| skip async -- Atomics.waitAsync is not supported +// 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: > + Test that Atomics.waitAsync returns the right result when it was awoken before + a timeout +flags: [async] +includes: [atomicsHelper.js] +features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, BigInt, arrow-function, async-functions] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); +const RUNNING = 1; +const TIMEOUT = $262.agent.timeouts.huge; +const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + +$262.agent.start(` + $262.agent.receiveBroadcast(async (sab) => { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + const before = $262.agent.monotonicNow(); + const unpark = await Atomics.waitAsync(i64a, 0, 0n, ${TIMEOUT}).value; + const duration = $262.agent.monotonicNow() - before; + + $262.agent.report(duration); + $262.agent.report(unpark); + $262.agent.leaving(); + }); +`); + +$262.agent.safeBroadcastAsync(i64a, RUNNING, 1n).then(async agentCount => { + assert.sameValue(agentCount, 1n, 'The value of `agentCount` is 1n'); + + assert.sameValue( + Atomics.notify(i64a, 0), + 1, + 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0) must return 1' + ); + + const lapse = await $262.agent.getReportAsync(); + assert(lapse < TIMEOUT, 'The result of evaluating `(lapse < TIMEOUT)` is true'); + const result = await $262.agent.getReportAsync(); + assert.sameValue(result, 'ok', 'The value of `result` is "ok"'); + assert.sameValue(result, 'ok', 'The value of `result` is "ok"'); + + assert.sameValue( + Atomics.notify(i64a, 0), + 0, + 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0) must return 0' + ); +}).then($DONE, $DONE); |