diff --git a/test/built-ins/Atomics/waitAsync/bad-range.js b/test/built-ins/Atomics/waitAsync/bad-range.js index 4205df864f..332cfe4ec3 100644 --- a/test/built-ins/Atomics/waitAsync/bad-range.js +++ b/test/built-ins/Atomics/waitAsync/bad-range.js @@ -19,6 +19,7 @@ info: | includes: [testAtomics.js] features: [Atomics.waitAsync, Atomics, SharedArrayBuffer, ArrayBuffer, DataView, Symbol, TypedArray] ---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function'); const i32a = new Int32Array( new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 8) ); diff --git a/test/built-ins/Atomics/waitAsync/bigint/bad-range.js b/test/built-ins/Atomics/waitAsync/bigint/bad-range.js new file mode 100644 index 0000000000..398dfae844 --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/bad-range.js @@ -0,0 +1,28 @@ +// 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'); +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 RangeError'); +}); diff --git a/test/built-ins/Atomics/waitAsync/bigint/false-for-timeout-agent.js b/test/built-ins/Atomics/waitAsync/bigint/false-for-timeout-agent.js new file mode 100644 index 0000000000..7ddf025eed --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/false-for-timeout-agent.js @@ -0,0 +1,91 @@ +// 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'); +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); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + 'await Atomics.waitAsync(i64a, 0, 0n, false).value resolves to "timed-out"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + 'await Atomics.waitAsync(i64a, 0, 0n, valueOf).value resolves to "timed-out"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + 'await Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value resolves to "timed-out"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + 'Atomics.waitAsync(i64a, 0, 0n, false).value resolves to "timed-out"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + 'Atomics.waitAsync(i64a, 0, 0n, valueOf).value resolves to "timed-out"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + 'Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value resolves to "timed-out"' + ); + + assert.sameValue(Atomics.notify(i64a, 0), 0, 'Atomics.notify(i64a, 0) returns 0'); +}).then($DONE, $DONE); diff --git a/test/built-ins/Atomics/waitAsync/bigint/false-for-timeout.js b/test/built-ins/Atomics/waitAsync/bigint/false-for-timeout.js new file mode 100644 index 0000000000..fbb7d5a885 --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/false-for-timeout.js @@ -0,0 +1,60 @@ +// 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'); +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', + 'Atomics.waitAsync(i64a, 0, 0n, false).value resolves to "timed-out"' +); + +assert.sameValue( + Atomics.waitAsync(i64a, 0, 0n, valueOf).value, + 'timed-out', + 'Atomics.waitAsync(i64a, 0, 0n, false).value resolves to "timed-out"' +); + +assert.sameValue( + Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value, + 'timed-out', + 'Atomics.waitAsync(i64a, 0, 0n, false).value resolves to "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'); + assert.sameValue(outcomes[1], 'timed-out'); + assert.sameValue(outcomes[2], 'timed-out'); +}, $DONE).then($DONE, $DONE); diff --git a/test/built-ins/Atomics/waitAsync/bigint/good-views.js b/test/built-ins/Atomics/waitAsync/bigint/good-views.js new file mode 100644 index 0000000000..be5d7e5ee8 --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/good-views.js @@ -0,0 +1,72 @@ +// 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] +features: [Atomics.waitAsync, Atomics, BigInt] +---*/ +assert.sameValue(typeof Atomics.waitAsync, '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(); + })(); +`); + + +Promise.all([ + $262.agent.getReportAsync(), + $262.agent.getReportAsync(), + $262.agent.getReportAsync(), +]).then(outcomes => { + + assert.sameValue( + outcomes[0], + 'A timed-out', + '"A " + (await Atomics.waitAsync(view, 0, 0n, 0).value resolves to "A timed-out"' + ); + + assert.sameValue( + outcomes[1], + 'B not-equal', + '"B " + (await Atomics.waitAsync(view, 0, 37n, 0).value resolves to "B not-equal"' + ); + assert.sameValue( + outcomes[2], + 'C not-equal,not-equal,not-equal,not-equal,not-equal', + 'All C values are not equal' + ); +}, $DONE).then($DONE, $DONE); + + diff --git a/test/built-ins/Atomics/waitAsync/bigint/nan-for-timeout-agent.js b/test/built-ins/Atomics/waitAsync/bigint/nan-for-timeout-agent.js new file mode 100644 index 0000000000..9524ae874e --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/nan-for-timeout-agent.js @@ -0,0 +1,44 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-atomics.waitasync +description: > + 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'); +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); + assert.sameValue(Atomics.notify(i64a, 0), 1, 'Atomics.notify(i64a, 0) returns 1'); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'ok', + 'await Atomics.waitAsync(i64a, 0, 0n, NaN).value resolves to "ok"' + ); +}).then($DONE, $DONE); diff --git a/test/built-ins/Atomics/waitAsync/bigint/negative-index-throws.js b/test/built-ins/Atomics/waitAsync/bigint/negative-index-throws.js new file mode 100644 index 0000000000..cb0d4333f1 --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/negative-index-throws.js @@ -0,0 +1,43 @@ +// 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'); +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 RangeError'); +assert.throws(RangeError, function() { + Atomics.waitAsync(i64a, -7.999, poisoned, poisoned); +}, '`Atomics.waitAsync(i64a, -7.999, poisoned, poisoned)` throws RangeError'); +assert.throws(RangeError, function() { + Atomics.waitAsync(i64a, -1, poisoned, poisoned); +}, '`Atomics.waitAsync(i64a, -1, poisoned, poisoned)` throws RangeError'); +assert.throws(RangeError, function() { + Atomics.waitAsync(i64a, -300, poisoned, poisoned); +}, '`Atomics.wait(i64a, -300, poisoned, poisoned)` throws RangeError'); + diff --git a/test/built-ins/Atomics/waitAsync/bigint/negative-timeout-agent.js b/test/built-ins/Atomics/waitAsync/bigint/negative-timeout-agent.js new file mode 100644 index 0000000000..6f691a12da --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/negative-timeout-agent.js @@ -0,0 +1,44 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-atomics.waitasync +description: > + 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'); +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); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + 'await Atomics.waitAsync(i64a, 0, 0n, -5).value resolves to "timed-out"' + ); + + assert.sameValue(Atomics.notify(i64a, 0), 0, 'Atomics.notify(i64a, 0) returns 0'); +}).then($DONE, $DONE); diff --git a/test/built-ins/Atomics/waitAsync/bigint/negative-timeout.js b/test/built-ins/Atomics/waitAsync/bigint/negative-timeout.js new file mode 100644 index 0000000000..7b88839bb8 --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/negative-timeout.js @@ -0,0 +1,28 @@ +// 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'); +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', + 'Atomics.waitAsync(i64a, 0, 0n, -1).value resolves to "timed-out"' + ); +}, $DONE).then($DONE, $DONE); diff --git a/test/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-no-operation.js b/test/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-no-operation.js new file mode 100644 index 0000000000..80505e42e7 --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-no-operation.js @@ -0,0 +1,61 @@ +// 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'); +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); + const lapse = await $262.agent.getReportAsync(); + assert(lapse >= TIMEOUT, 'The result of `(lapse >= TIMEOUT)` is true'); + const result = await $262.agent.getReportAsync(); + + assert.sameValue( + result, + 'timed-out', + 'await Atomics.waitAsync(i64a, 0, 0n, ${TIMEOUT}).value resolves to "timed-out"' + ); + + assert.sameValue(Atomics.notify(i64a, 0), 0, 'Atomics.notify(i64a, 0) returns 0'); +}).then($DONE, $DONE); diff --git a/test/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-add.js b/test/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-add.js new file mode 100644 index 0000000000..1f7fa4ad07 --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-add.js @@ -0,0 +1,61 @@ +// 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'); +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); + Atomics.add(i64a, 0, 1n); + const lapse = await $262.agent.getReportAsync(); + assert(lapse >= TIMEOUT, 'The result of `(lapse >= TIMEOUT)` is true'); + const result = await $262.agent.getReportAsync(); + + assert.sameValue( + result, + 'timed-out', + 'await Atomics.waitAsync(i64a, 0, 0n, ${TIMEOUT}).value resolves to "timed-out"' + ); + + assert.sameValue(Atomics.notify(i64a, 0), 0, 'Atomics.notify(i64a, 0) returns 0'); +}).then($DONE, $DONE); diff --git a/test/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-and.js b/test/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-and.js new file mode 100644 index 0000000000..6c5146f1bf --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-and.js @@ -0,0 +1,61 @@ +// 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'); +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); + Atomics.and(i64a, 0, 1n); + const lapse = await $262.agent.getReportAsync(); + assert(lapse >= TIMEOUT, 'The result of `(lapse >= TIMEOUT)` is true'); + const result = await $262.agent.getReportAsync(); + + assert.sameValue( + result, + 'timed-out', + 'await Atomics.waitAsync(i64a, 0, 0n, ${TIMEOUT}).value resolves to "timed-out"' + ); + + assert.sameValue(Atomics.notify(i64a, 0), 0, 'Atomics.notify(i64a, 0) returns 0'); +}).then($DONE, $DONE); diff --git a/test/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-compareExchange.js b/test/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-compareExchange.js new file mode 100644 index 0000000000..efcacccd76 --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-compareExchange.js @@ -0,0 +1,61 @@ +// 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'); +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); + Atomics.compareExchange(i64a, 0, 0n, 1n); + const lapse = await $262.agent.getReportAsync(); + assert(lapse >= TIMEOUT, 'The result of `(lapse >= TIMEOUT)` is true'); + const result = await $262.agent.getReportAsync(); + + assert.sameValue( + result, + 'timed-out', + 'await Atomics.waitAsync(i64a, 0, 0n, ${TIMEOUT}).value resolves to "timed-out"' + ); + + assert.sameValue(Atomics.notify(i64a, 0), 0, 'Atomics.notify(i64a, 0) returns 0'); +}).then($DONE, $DONE); diff --git a/test/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-exchange.js b/test/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-exchange.js new file mode 100644 index 0000000000..6fbb585bc9 --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-exchange.js @@ -0,0 +1,61 @@ +// 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'); +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); + Atomics.exchange(i64a, 0, 1n); + const lapse = await $262.agent.getReportAsync(); + assert(lapse >= TIMEOUT, 'The result of `(lapse >= TIMEOUT)` is true'); + const result = await $262.agent.getReportAsync(); + + assert.sameValue( + result, + 'timed-out', + 'await Atomics.waitAsync(i64a, 0, 0n, ${TIMEOUT}).value resolves to "timed-out"' + ); + + assert.sameValue(Atomics.notify(i64a, 0), 0, 'Atomics.notify(i64a, 0) returns 0'); +}).then($DONE, $DONE); diff --git a/test/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-or.js b/test/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-or.js new file mode 100644 index 0000000000..dece081cfd --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-or.js @@ -0,0 +1,61 @@ +// 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'); +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); + Atomics.or(i64a, 0, 1n); + const lapse = await $262.agent.getReportAsync(); + assert(lapse >= TIMEOUT, 'The result of `(lapse >= TIMEOUT)` is true'); + const result = await $262.agent.getReportAsync(); + + assert.sameValue( + result, + 'timed-out', + 'await Atomics.waitAsync(i64a, 0, 0n, ${TIMEOUT}).value resolves to "timed-out"' + ); + + assert.sameValue(Atomics.notify(i64a, 0), 0, 'Atomics.notify(i64a, 0) returns 0'); +}).then($DONE, $DONE); diff --git a/test/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-store.js b/test/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-store.js new file mode 100644 index 0000000000..bae57bdea1 --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-store.js @@ -0,0 +1,61 @@ +// 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'); +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); + Atomics.store(i64a, 0, 0b1010n); + const lapse = await $262.agent.getReportAsync(); + assert(lapse >= TIMEOUT, 'The result of `(lapse >= TIMEOUT)` is true'); + const result = await $262.agent.getReportAsync(); + + assert.sameValue( + result, + 'timed-out', + 'await Atomics.waitAsync(i64a, 0, 0n, ${TIMEOUT}).value resolves to "timed-out"' + ); + + assert.sameValue(Atomics.notify(i64a, 0), 0, 'Atomics.notify(i64a, 0) returns 0'); +}).then($DONE, $DONE); diff --git a/test/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-sub.js b/test/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-sub.js new file mode 100644 index 0000000000..9d47f76409 --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-sub.js @@ -0,0 +1,61 @@ +// 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'); +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); + Atomics.sub(i64a, 0, 1n); + const lapse = await $262.agent.getReportAsync(); + assert(lapse >= TIMEOUT, 'The result of `(lapse >= TIMEOUT)` is true'); + const result = await $262.agent.getReportAsync(); + + assert.sameValue( + result, + 'timed-out', + 'await Atomics.waitAsync(i64a, 0, 0n, ${TIMEOUT}).value resolves to "timed-out"' + ); + + assert.sameValue(Atomics.notify(i64a, 0), 0, 'Atomics.notify(i64a, 0) returns 0'); +}).then($DONE, $DONE); diff --git a/test/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-xor.js b/test/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-xor.js new file mode 100644 index 0000000000..b95c4bfe88 --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-xor.js @@ -0,0 +1,61 @@ +// 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'); +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); + Atomics.xor(i64a, 0, 1n); + const lapse = await $262.agent.getReportAsync(); + assert(lapse >= TIMEOUT, 'The result of `(lapse >= TIMEOUT)` is true'); + const result = await $262.agent.getReportAsync(); + + assert.sameValue( + result, + 'timed-out', + 'await Atomics.waitAsync(i64a, 0, 0n, ${TIMEOUT}).value resolves to "timed-out"' + ); + + assert.sameValue(Atomics.notify(i64a, 0), 0, 'Atomics.notify(i64a, 0) returns 0'); +}).then($DONE, $DONE); diff --git a/test/built-ins/Atomics/waitAsync/bigint/non-bigint64-typedarray-throws.js b/test/built-ins/Atomics/waitAsync/bigint/non-bigint64-typedarray-throws.js new file mode 100644 index 0000000000..4352785058 --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/non-bigint64-typedarray-throws.js @@ -0,0 +1,35 @@ +// 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'); +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 TypeError'); + diff --git a/test/built-ins/Atomics/waitAsync/bigint/non-shared-bufferdata-throws.js b/test/built-ins/Atomics/waitAsync/bigint/non-shared-bufferdata-throws.js new file mode 100644 index 0000000000..e6dcbfee43 --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/non-shared-bufferdata-throws.js @@ -0,0 +1,38 @@ +// 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'); +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 TypeError'); + +assert.throws(TypeError, () => { + Atomics.waitAsync(i64a, poisoned, poisoned, poisoned); +}, '`Atomics.waitAsync(i64a, poisoned, poisoned, poisoned)` throws TypeError'); diff --git a/test/built-ins/Atomics/waitAsync/bigint/not-a-typedarray-throws.js b/test/built-ins/Atomics/waitAsync/bigint/not-a-typedarray-throws.js new file mode 100644 index 0000000000..4bdeadbd0c --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/not-a-typedarray-throws.js @@ -0,0 +1,40 @@ +// 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'); +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 TypeError'); + +assert.throws(TypeError, () => { + Atomics.waitAsync({}, poisoned, poisoned, poisoned); +}, '`Atomics.waitAsync({}, poisoned, poisoned, poisoned)` throws TypeError'); diff --git a/test/built-ins/Atomics/waitAsync/bigint/not-an-object-throws.js b/test/built-ins/Atomics/waitAsync/bigint/not-an-object-throws.js new file mode 100644 index 0000000000..9e68a4336f --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/not-an-object-throws.js @@ -0,0 +1,61 @@ +// 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'); +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 TypeError'); + +assert.throws(TypeError, () => { + Atomics.waitAsync(undefined, poisoned, poisoned, poisoned); +}, '`Atomics.waitAsync(undefined, poisoned, poisoned, poisoned)` throws TypeError'); + +assert.throws(TypeError, () => { + Atomics.waitAsync(true, poisoned, poisoned, poisoned); +}, '`Atomics.waitAsync(true, poisoned, poisoned, poisoned)` throws TypeError'); + +assert.throws(TypeError, () => { + Atomics.waitAsync(false, poisoned, poisoned, poisoned); +}, '`Atomics.waitAsync(false, poisoned, poisoned, poisoned)` throws TypeError'); + +assert.throws(TypeError, () => { + Atomics.waitAsync('***string***', poisoned, poisoned, poisoned); +}, '`Atomics.waitAsync(\'***string***\', poisoned, poisoned, poisoned)` throws TypeError'); + +assert.throws(TypeError, () => { + Atomics.waitAsync(Number.NEGATIVE_INFINITY, poisoned, poisoned, poisoned); +}, '`Atomics.waitAsync(Number.NEGATIVE_INFINITY, poisoned, poisoned, poisoned)` throws TypeError'); + +assert.throws(TypeError, () => { + Atomics.waitAsync(Symbol('***symbol***'), poisoned, poisoned, poisoned); +}, '`Atomics.waitAsync(Symbol(\'***symbol***\'), poisoned, poisoned, poisoned)` throws TypeError'); + diff --git a/test/built-ins/Atomics/waitAsync/bigint/null-bufferdata-throws.js b/test/built-ins/Atomics/waitAsync/bigint/null-bufferdata-throws.js new file mode 100644 index 0000000000..c44f51a33e --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/null-bufferdata-throws.js @@ -0,0 +1,48 @@ +// 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'); +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) { + $ERROR(`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 TypeError'); + diff --git a/test/built-ins/Atomics/waitAsync/bigint/null-for-timeout-agent.js b/test/built-ins/Atomics/waitAsync/bigint/null-for-timeout-agent.js new file mode 100644 index 0000000000..a3f9a82537 --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/null-for-timeout-agent.js @@ -0,0 +1,93 @@ +// 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'); +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); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + 'await Atomics.waitAsync(i64a, 0, 0n, null).value resolves to "timed-out"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + 'await Atomics.waitAsync(i64a, 0, 0n, valueOf).value resolves to "timed-out"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + 'await Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value resolves to "timed-out"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + 'Atomics.waitAsync(i64a, 0, 0n, null).value resolves to "timed-out"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + 'Atomics.waitAsync(i64a, 0, 0n, valueOf).value resolves to "timed-out"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + 'Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value resolves to "timed-out"' + ); + + assert.sameValue(Atomics.notify(i64a, 0), 0, 'Atomics.notify(i64a, 0) returns 0'); +}).then($DONE, $DONE); diff --git a/test/built-ins/Atomics/waitAsync/bigint/null-for-timeout.js b/test/built-ins/Atomics/waitAsync/bigint/null-for-timeout.js new file mode 100644 index 0000000000..eb4d1039fb --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/null-for-timeout.js @@ -0,0 +1,62 @@ +// 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] +flags: [async] +---*/ +assert.sameValue(typeof Atomics.waitAsync, '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', + 'Atomics.waitAsync(i64a, 0, 0n, null).value resolves to "timed-out"' +); + +assert.sameValue( + Atomics.waitAsync(i64a, 0, 0n, valueOf).value, + 'timed-out', + 'Atomics.waitAsync(i64a, 0, 0n, valueOf).value resolves to "timed-out"' +); + +assert.sameValue( + Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value, + 'timed-out', + 'Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value resolves to "timed-out"' +); + +Promise.all([ + Atomics.waitAsync(i64a, 0, 0n, null).value, + Atomics.waitAsync(i64a, 0, 0n, valueOf).value, + Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value +]).then(outcomes => { + assert.sameValue(outcomes[0], 'timed-out'); + assert.sameValue(outcomes[1], 'timed-out'); + assert.sameValue(outcomes[2], 'timed-out'); +}, $DONE).then($DONE, $DONE); diff --git a/test/built-ins/Atomics/waitAsync/bigint/object-for-timeout-agent.js b/test/built-ins/Atomics/waitAsync/bigint/object-for-timeout-agent.js new file mode 100644 index 0000000000..03d65c8661 --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/object-for-timeout-agent.js @@ -0,0 +1,102 @@ +// 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'); +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); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + 'await Atomics.waitAsync(i64a, 0, 0n, valueOf).value resolves to "timed-out"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + 'await Atomics.waitAsync(i64a, 0, 0n, toString).value resolves to "timed-out"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + 'await Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value resolves to "timed-out"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + 'Atomics.waitAsync(i64a, 0, 0n, valueOf).value resolves to "timed-out"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + 'Atomics.waitAsync(i64a, 0, 0n, toString).value resolves to "timed-out"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + 'Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value resolves to "timed-out"' + ); + + assert.sameValue(Atomics.notify(i64a, 0), 0, 'Atomics.notify(i64a, 0) returns 0'); +}).then($DONE, $DONE); diff --git a/test/built-ins/Atomics/waitAsync/bigint/object-for-timeout.js b/test/built-ins/Atomics/waitAsync/bigint/object-for-timeout.js new file mode 100644 index 0000000000..6f377a3b35 --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/object-for-timeout.js @@ -0,0 +1,71 @@ +// 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'); +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', + 'Atomics.waitAsync(i64a, 0, 0n, valueOf).value resolves to "timed-out"' +); + +assert.sameValue( + Atomics.waitAsync(i64a, 0, 0n, toString).value, + 'timed-out', + 'Atomics.waitAsync(i64a, 0, 0n, toString).value resolves to "timed-out"' +); + +assert.sameValue( + Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value, + 'timed-out', + 'Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value resolves to "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'); + assert.sameValue(outcomes[1], 'timed-out'); + assert.sameValue(outcomes[2], 'timed-out'); +}, $DONE).then($DONE, $DONE); diff --git a/test/built-ins/Atomics/waitAsync/bigint/out-of-range-index-throws.js b/test/built-ins/Atomics/waitAsync/bigint/out-of-range-index-throws.js new file mode 100644 index 0000000000..550c5d5a1f --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/out-of-range-index-throws.js @@ -0,0 +1,46 @@ +// 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'); +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.wait(i64a, Infinity, poisoned, poisoned); +}, '`Atomics.wait(i64a, Infinity, poisoned, poisoned)` throws RangeError'); +assert.throws(RangeError, function() { + Atomics.wait(i64a, -1, poisoned, poisoned); +}, '`Atomics.wait(i64a, -1, poisoned, poisoned)` throws RangeError'); +assert.throws(RangeError, function() { + Atomics.wait(i64a, 4, poisoned, poisoned); +}, '`Atomics.wait(i64a, 4, poisoned, poisoned)` throws RangeError'); +assert.throws(RangeError, function() { + Atomics.wait(i64a, 200, poisoned, poisoned); +}, '`Atomics.wait(i64a, 200, poisoned, poisoned)` throws RangeError'); + diff --git a/test/built-ins/Atomics/waitAsync/bigint/poisoned-object-for-timeout-throws-agent.js b/test/built-ins/Atomics/waitAsync/bigint/poisoned-object-for-timeout-throws-agent.js new file mode 100644 index 0000000000..498a534d4c --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/poisoned-object-for-timeout-throws-agent.js @@ -0,0 +1,81 @@ +// 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'); +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.wait(i64a, 0, 0n, poisonedValueOf); + } catch (error) { + status1 = 'poisonedValueOf'; + } + try { + Atomics.wait(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); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'poisonedValueOf', + 'Atomics.wait(i64a, 0, 0n, poisonedValueOf) throws' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'poisonedToPrimitive', + 'Atomics.wait(i64a, 0, 0n, poisonedToPrimitive) throws' + ); + + assert.sameValue(Atomics.notify(i64a, 0), 0, 'Atomics.notify(i64a, 0) returns 0'); +}).then($DONE, $DONE); diff --git a/test/built-ins/Atomics/waitAsync/bigint/poisoned-object-for-timeout-throws.js b/test/built-ins/Atomics/waitAsync/bigint/poisoned-object-for-timeout-throws.js new file mode 100644 index 0000000000..5c805d21f1 --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/poisoned-object-for-timeout-throws.js @@ -0,0 +1,42 @@ +// 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'); +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.wait(i64a, 0, 0n, poisonedValueOf); +}, '`Atomics.wait(i64a, 0, 0n, poisonedValueOf)` throws Test262Error'); + +assert.throws(Test262Error, function() { + Atomics.wait(i64a, 0, 0n, poisonedToPrimitive); +}, '`Atomics.wait(i64a, 0, 0n, poisonedToPrimitive)` throws Test262Error'); diff --git a/test/built-ins/Atomics/waitAsync/bigint/symbol-for-index-throws-agent.js b/test/built-ins/Atomics/waitAsync/bigint/symbol-for-index-throws-agent.js new file mode 100644 index 0000000000..7c64fc050c --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/symbol-for-index-throws-agent.js @@ -0,0 +1,93 @@ +// 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'); +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); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'A TypeError', + 'Atomics.waitAsync(i64a, Symbol("1"), ..., ...) throws TypeError' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'B TypeError', + 'Atomics.waitAsync(i64a, Symbol("2"), ..., ...) throws TypeError' + ); + + assert.sameValue(Atomics.notify(i64a, 0), 0, 'Atomics.notify(i64a, 0) returns 0'); +}).then($DONE, $DONE); diff --git a/test/built-ins/Atomics/waitAsync/bigint/symbol-for-index-throws.js b/test/built-ins/Atomics/waitAsync/bigint/symbol-for-index-throws.js new file mode 100644 index 0000000000..79455fc758 --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/symbol-for-index-throws.js @@ -0,0 +1,68 @@ +// 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'); +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 Test262Error'); + +assert.throws(Test262Error, function() { + Atomics.waitAsync(i64a, poisonedToPrimitive, poisonedToPrimitive, poisonedToPrimitive); +}, '`Atomics.waitAsync(i64a, poisonedToPrimitive, poisonedToPrimitive, poisonedToPrimitive)` throws Test262Error'); + +assert.throws(TypeError, function() { + Atomics.waitAsync(i64a, Symbol('1'), poisonedValueOf, poisonedValueOf); +}, '`Atomics.waitAsync(i64a, Symbol("1"), poisonedValueOf, poisonedValueOf)` throws TypeError'); + +assert.throws(TypeError, function() { + Atomics.waitAsync(i64a, Symbol('2'), poisonedToPrimitive, poisonedToPrimitive); +}, '`Atomics.waitAsync(i64a, Symbol("2"), poisonedToPrimitive, poisonedToPrimitive)` throws TypeError'); + + + diff --git a/test/built-ins/Atomics/waitAsync/bigint/symbol-for-timeout-throws-agent.js b/test/built-ins/Atomics/waitAsync/bigint/symbol-for-timeout-throws-agent.js new file mode 100644 index 0000000000..87958a1ea4 --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/symbol-for-timeout-throws-agent.js @@ -0,0 +1,68 @@ +// 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'); +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); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'A TypeError', + 'Atomics.wait(i64a, 0, 0n, Symbol("1")) throws TypeError' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'B TypeError', + 'Atomics.wait(i64a, 0, 0n, Symbol("2")) throws TypeError' + ); + + assert.sameValue(Atomics.notify(i64a, 0), 0, 'Atomics.notify(i64a, 0) returns 0'); +}).then($DONE, $DONE); diff --git a/test/built-ins/Atomics/waitAsync/bigint/symbol-for-timeout-throws.js b/test/built-ins/Atomics/waitAsync/bigint/symbol-for-timeout-throws.js new file mode 100644 index 0000000000..556b63d0f2 --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/symbol-for-timeout-throws.js @@ -0,0 +1,49 @@ +// 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'); +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 Test262Error'); + +assert.throws(Test262Error, function() { + Atomics.waitAsync(i64a, 0, 0n, poisonedToPrimitive); +}, '`Atomics.waitAsync(i64a, 0, 0n, poisonedToPrimitive)` throws Test262Error'); + +assert.throws(TypeError, function() { + Atomics.waitAsync(i64a, 0, 0n, Symbol('foo')); +}, '`Atomics.waitAsync(i64a, 0, 0n, Symbol("foo"))` throws TypeError'); + +assert.throws(TypeError, function() { + Atomics.waitAsync(i64a, 0, 0n, Symbol('foo')); +}, '`Atomics.waitAsync(i64a, 0, 0n, Symbol("foo"))` throws TypeError'); diff --git a/test/built-ins/Atomics/waitAsync/bigint/symbol-for-value-throws-agent.js b/test/built-ins/Atomics/waitAsync/bigint/symbol-for-value-throws-agent.js new file mode 100644 index 0000000000..40be1da354 --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/symbol-for-value-throws-agent.js @@ -0,0 +1,84 @@ +// 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'); +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); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'A TypeError', + 'Atomics.waitAsync(i64a, 0, Symbol("1"), ...) throws TypeError' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'B TypeError', + 'Atomics.waitAsync(i64a, 0, Symbol("2"), ...) throws TypeError' + ); + + assert.sameValue(Atomics.notify(i64a, 0), 0, 'Atomics.notify(i64a, 0) returns 0'); +}).then($DONE, $DONE); diff --git a/test/built-ins/Atomics/waitAsync/bigint/symbol-for-value-throws.js b/test/built-ins/Atomics/waitAsync/bigint/symbol-for-value-throws.js new file mode 100644 index 0000000000..5d08ad2f21 --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/symbol-for-value-throws.js @@ -0,0 +1,57 @@ +// 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'); +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 Test262Error'); + +assert.throws(Test262Error, function() { + Atomics.waitAsync(i64a, 0, poisonedToPrimitive, poisonedToPrimitive); +}, '`Atomics.waitAsync(i64a, 0, poisonedToPrimitive, poisonedToPrimitive)` throws Test262Error'); + +assert.throws(TypeError, function() { + Atomics.waitAsync(i64a, 0, Symbol("foo"), poisonedValueOf); +}, '`Atomics.waitAsync(i64a, 0, Symbol("foo"), poisonedValueOf)` throws TypeError'); + +assert.throws(TypeError, function() { + Atomics.waitAsync(i64a, 0, Symbol("foo"), poisonedToPrimitive); +}, '`Atomics.waitAsync(i64a, 0, Symbol("foo"), poisonedToPrimitive)` throws TypeError'); + diff --git a/test/built-ins/Atomics/waitAsync/bigint/true-for-timeout-agent.js b/test/built-ins/Atomics/waitAsync/bigint/true-for-timeout-agent.js new file mode 100644 index 0000000000..d38239e4ab --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/true-for-timeout-agent.js @@ -0,0 +1,70 @@ +// 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'); +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); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + 'await Atomics.waitAsync(i64a, 0, 0n, false).value resolves to "timed-out"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + 'await Atomics.waitAsync(i64a, 0, 0n, valueOf).value resolves to "timed-out"' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'timed-out', + 'await Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value resolves to "timed-out"' + ); + + assert.sameValue(Atomics.notify(i64a, 0), 0, 'Atomics.notify(i64a, 0) returns 0'); +}).then($DONE, $DONE); diff --git a/test/built-ins/Atomics/waitAsync/bigint/true-for-timeout.js b/test/built-ins/Atomics/waitAsync/bigint/true-for-timeout.js new file mode 100644 index 0000000000..63ddeb5ecb --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/true-for-timeout.js @@ -0,0 +1,44 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-atomics.waitasync +description: > + 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] +features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, BigInt, computed-property-names, Symbol, Symbol.toPrimitive, arrow-function] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function'); +const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + +const valueOf = { + valueOf() { + return true; + } +}; + +const toPrimitive = { + [Symbol.toPrimitive]() { + return true; + } +}; + +Promise.all([ + Atomics.waitAsync(i64a, 0, 0n, true).value, + Atomics.waitAsync(i64a, 0, 0n, valueOf).value, + Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value +]).then(outcomes => { + assert.sameValue(outcomes[0], 'timed-out'); + assert.sameValue(outcomes[1], 'timed-out'); + assert.sameValue(outcomes[2], 'timed-out'); +}, $DONE).then($DONE, $DONE); diff --git a/test/built-ins/Atomics/waitAsync/bigint/undefined-for-timeout-agent.js b/test/built-ins/Atomics/waitAsync/bigint/undefined-for-timeout-agent.js new file mode 100644 index 0000000000..e8bf873474 --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/undefined-for-timeout-agent.js @@ -0,0 +1,77 @@ +// 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'); + +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)); + + assert.sameValue( + Atomics.notify(i64a, WAIT_INDEX, NOTIFYCOUNT), + NOTIFYCOUNT, + 'Atomics.notify(i64a, WAIT_INDEX, NOTIFYCOUNT) returns the value of `NOTIFYCOUNT` (2)' + ); + + 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/test/built-ins/Atomics/waitAsync/bigint/undefined-for-timeout.js b/test/built-ins/Atomics/waitAsync/bigint/undefined-for-timeout.js new file mode 100644 index 0000000000..e3b6ae9ecd --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/undefined-for-timeout.js @@ -0,0 +1,60 @@ +// 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, computed-property-names, Symbol, Symbol.toPrimitive, arrow-function] +---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function'); +const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + +$262.agent.start(` + $262.agent.receiveBroadcast(async (sab) => { + var i64a = new BigInt64Array(sab); + $262.agent.sleep(1000); + Atomics.notify(i64a, 0, 4); + $262.agent.leaving(); + }); +`); + +$262.agent.safeBroadcast(i64a); + +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'); + assert.sameValue(outcomes[1], 'ok'); + assert.sameValue(outcomes[2], 'ok'); + assert.sameValue(outcomes[3], 'ok'); +}, $DONE).then($DONE, $DONE); diff --git a/test/built-ins/Atomics/waitAsync/bigint/undefined-index-defaults-to-zero-agent.js b/test/built-ins/Atomics/waitAsync/bigint/undefined-index-defaults-to-zero-agent.js new file mode 100644 index 0000000000..662c8741c6 --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/undefined-index-defaults-to-zero-agent.js @@ -0,0 +1,79 @@ +// 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'); + +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)); + + assert.sameValue( + Atomics.notify(i64a, WAIT_INDEX, NOTIFYCOUNT), + NOTIFYCOUNT, + 'Atomics.notify(i64a, WAIT_INDEX, NOTIFYCOUNT) returns the value of `NOTIFYCOUNT` (2)' + ); + + 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/test/built-ins/Atomics/waitAsync/bigint/value-not-equal-agent.js b/test/built-ins/Atomics/waitAsync/bigint/value-not-equal-agent.js new file mode 100644 index 0000000000..1e8d5b1c37 --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/value-not-equal-agent.js @@ -0,0 +1,62 @@ +// 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'); +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); + + assert.sameValue( + await $262.agent.getReportAsync(), + value.toString(), + 'Atomics.store(i64a, 0, 42n) returns 42' + ); + + assert.sameValue( + await $262.agent.getReportAsync(), + 'not-equal', + 'Atomics.waitAsync(i64a, 0, 0n).value resolves to "not-equal"' + ); + + assert.sameValue( + Atomics.notify(i64a, 0, 1), + 0, + 'Atomics.notify(i64a, 0, 1) returns 0 (nothing to notify)' + ); +}).then($DONE, $DONE); diff --git a/test/built-ins/Atomics/waitAsync/bigint/value-not-equal.js b/test/built-ins/Atomics/waitAsync/bigint/value-not-equal.js new file mode 100644 index 0000000000..94dfd6fc6c --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/value-not-equal.js @@ -0,0 +1,43 @@ +// 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'); +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); + assert.sameValue(outcomes[1], 'not-equal'); +}, $DONE).then($DONE, $DONE); diff --git a/test/built-ins/Atomics/waitAsync/bigint/waiterlist-block-indexedposition-wake.js b/test/built-ins/Atomics/waitAsync/bigint/waiterlist-block-indexedposition-wake.js new file mode 100644 index 0000000000..f4617aaa2b --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/waiterlist-block-indexedposition-wake.js @@ -0,0 +1,85 @@ +// 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'); + +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)); + + // Notify index 1, notifies nothing + assert.sameValue(Atomics.notify(i64a, 1), 0, 'Atomics.notify(i64a, 1) returns 0'); + + // Notify index 3, notifies nothing + assert.sameValue(Atomics.notify(i64a, 3), 0, 'Atomics.notify(i64a, 3) returns 0'); + + // Notify index 2, notifies 1 + assert.sameValue(Atomics.notify(i64a, 2), 1, 'Atomics.notify(i64a, 2) returns 1'); + assert.sameValue( + await $262.agent.getReportAsync(), + 'ok', + 'await Atomics.waitAsync(i64a, 0, 0n, Infinity).value resolves to "ok"' + ); + + // Notify index 0, notifies 1 + assert.sameValue(Atomics.notify(i64a, 0), 1, 'Atomics.notify(i64a, 0) returns 1'); + assert.sameValue( + await $262.agent.getReportAsync(), + 'ok', + 'await Atomics.waitAsync(i64a, 2, 0n, Infinity).value resolves to "ok"' + ); + +}).then($DONE, $DONE); + diff --git a/test/built-ins/Atomics/waitAsync/bigint/was-woken-before-timeout.js b/test/built-ins/Atomics/waitAsync/bigint/was-woken-before-timeout.js new file mode 100644 index 0000000000..3f4a7f1ff3 --- /dev/null +++ b/test/built-ins/Atomics/waitAsync/bigint/was-woken-before-timeout.js @@ -0,0 +1,46 @@ +// 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'); +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); + assert.sameValue(Atomics.notify(i64a, 0), 1, 'Atomics.notify(i64a, 0) returns 1'); + const lapse = await $262.agent.getReportAsync(); + assert(lapse < TIMEOUT, 'The result of `(lapse >= TIMEOUT)` is true'); + const result = await $262.agent.getReportAsync(); + + assert.sameValue( + result, + 'ok', + 'await Atomics.waitAsync(i64a, 0, 0n, ${TIMEOUT}).value resolves to "ok"' + ); + + assert.sameValue(Atomics.notify(i64a, 0), 0, 'Atomics.notify(i64a, 0) returns 0'); +}).then($DONE, $DONE); diff --git a/test/built-ins/Atomics/waitAsync/false-for-timeout.js b/test/built-ins/Atomics/waitAsync/false-for-timeout.js index 53fb98b24e..8a42d54748 100644 --- a/test/built-ins/Atomics/waitAsync/false-for-timeout.js +++ b/test/built-ins/Atomics/waitAsync/false-for-timeout.js @@ -17,6 +17,7 @@ info: | flags: [async] features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, computed-property-names, Symbol, Symbol.toPrimitive, arrow-function] ---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function'); const i32a = new Int32Array( new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4) ); diff --git a/test/built-ins/Atomics/waitAsync/good-views.js b/test/built-ins/Atomics/waitAsync/good-views.js index a376d042dd..8efa7a2aa2 100644 --- a/test/built-ins/Atomics/waitAsync/good-views.js +++ b/test/built-ins/Atomics/waitAsync/good-views.js @@ -5,16 +5,16 @@ esid: sec-atomics.waitasync description: > Test Atomics.waitAsync on arrays that allow atomic operations +flags: [async] includes: [atomicsHelper.js] features: [Atomics.waitAsync, Atomics] ---*/ assert.sameValue(typeof Atomics.waitAsync, 'function'); + $262.agent.start(` (async () => { var sab = new SharedArrayBuffer(1024); - var ab = new ArrayBuffer(16); - var good_indices = [ (view) => 0/-1, // -0 (view) => '-0', (view) => view.length - 1, @@ -28,6 +28,7 @@ $262.agent.start(` $262.agent.report("A " + (await Atomics.waitAsync(view, 0, 0, 0).value)) $262.agent.report("B " + (await Atomics.waitAsync(view, 0, 37, 0).value)); + const results = []; // In-bounds boundary cases for indexing for ( let IdxGen of good_indices ) { let Idx = IdxGen(view); @@ -35,30 +36,35 @@ $262.agent.start(` // Atomics.store() computes an index from Idx in the same way as other // Atomics operations, not quite like view[Idx]. Atomics.store(view, Idx, 37); - $262.agent.report("C " + (await Atomics.waitAsync(view, Idx, 0).value)); + results.push(await Atomics.waitAsync(view, Idx, 0).value); } - $262.agent.report("done"); + $262.agent.report("C " + results.join(",")); $262.agent.leaving(); })(); `); -assert.sameValue( - $262.agent.getReport(), - 'A timed-out', - '"A " + (await Atomics.waitAsync(view, 0, 0, 0).value resolves to "A timed-out"' -); -assert.sameValue( - $262.agent.getReport(), - 'B not-equal', - '"B " + (await Atomics.waitAsync(view, 0, 37, 0).value resolves to "B not-equal"' -); +Promise.all([ + $262.agent.getReportAsync(), + $262.agent.getReportAsync(), + $262.agent.getReportAsync(), +]).then(outcomes => { -var r; -while ((r = $262.agent.getReport()) !== "done") { assert.sameValue( - r, - 'C not-equal', - '"C " + (await Atomics.waitAsync(view, Idx, 0).value resolves to "C not-equal"' + outcomes[0], + 'A timed-out', + '"A " + (await Atomics.waitAsync(view, 0, 0, 0).value resolves to "A timed-out"' ); -} + + assert.sameValue( + outcomes[1], + 'B not-equal', + '"B " + (await Atomics.waitAsync(view, 0, 37, 0).value resolves to "B not-equal"' + ); + assert.sameValue( + outcomes[2], + 'C not-equal,not-equal,not-equal,not-equal,not-equal', + 'All C values are not equal' + ); +}, $DONE).then($DONE, $DONE); + diff --git a/test/built-ins/Atomics/waitAsync/negative-index-throws.js b/test/built-ins/Atomics/waitAsync/negative-index-throws.js index fee4f19fa7..541e793a1d 100644 --- a/test/built-ins/Atomics/waitAsync/negative-index-throws.js +++ b/test/built-ins/Atomics/waitAsync/negative-index-throws.js @@ -17,6 +17,7 @@ info: | features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics] ---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function'); const i32a = new Int32Array( new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4) ); diff --git a/test/built-ins/Atomics/waitAsync/negative-timeout.js b/test/built-ins/Atomics/waitAsync/negative-timeout.js index 9b2a74a8b5..a50d056e18 100644 --- a/test/built-ins/Atomics/waitAsync/negative-timeout.js +++ b/test/built-ins/Atomics/waitAsync/negative-timeout.js @@ -17,6 +17,7 @@ info: | flags: [async] features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, destructuring-binding, arrow-function] ---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function'); const i32a = new Int32Array( new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4) ); diff --git a/test/built-ins/Atomics/waitAsync/non-int32-typedarray-throws.js b/test/built-ins/Atomics/waitAsync/non-int32-typedarray-throws.js index 2f7c2d2be8..e3b781d022 100644 --- a/test/built-ins/Atomics/waitAsync/non-int32-typedarray-throws.js +++ b/test/built-ins/Atomics/waitAsync/non-int32-typedarray-throws.js @@ -21,6 +21,7 @@ info: | features: [Atomics.waitAsync, Float32Array, Float64Array, Int8Array, TypedArray, Uint16Array, Uint8Array, Uint8ClampedArray, arrow-function, SharedArrayBuffer, Atomics] ---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function'); const poisoned = { valueOf() { throw new Test262Error('should not evaluate this code'); diff --git a/test/built-ins/Atomics/waitAsync/non-shared-bufferdata-throws.js b/test/built-ins/Atomics/waitAsync/non-shared-bufferdata-throws.js index e2e75a670c..530767d19f 100644 --- a/test/built-ins/Atomics/waitAsync/non-shared-bufferdata-throws.js +++ b/test/built-ins/Atomics/waitAsync/non-shared-bufferdata-throws.js @@ -20,6 +20,7 @@ info: | features: [Atomics.waitAsync, ArrayBuffer, Atomics, TypedArray, arrow-function] ---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function'); const i32a = new Int32Array( new ArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4) ); @@ -31,9 +32,9 @@ const poisoned = { }; assert.throws(TypeError, () => { - Atomics.wait(i32a, 0, 0, 0); -}, '`Atomics.wait(i32a, 0, 0, 0)` throws TypeError'); + Atomics.waitAsync(i32a, 0, 0, 0); +}, '`Atomics.waitAsync(i32a, 0, 0, 0)` throws TypeError'); assert.throws(TypeError, () => { - Atomics.wait(i32a, poisoned, poisoned, poisoned); -}, '`Atomics.wait(i32a, poisoned, poisoned, poisoned)` throws TypeError'); + Atomics.waitAsync(i32a, poisoned, poisoned, poisoned); +}, '`Atomics.waitAsync(i32a, poisoned, poisoned, poisoned)` throws TypeError'); diff --git a/test/built-ins/Atomics/waitAsync/not-a-typedarray-throws.js b/test/built-ins/Atomics/waitAsync/not-a-typedarray-throws.js index 28027b3dfe..b908d36dca 100644 --- a/test/built-ins/Atomics/waitAsync/not-a-typedarray-throws.js +++ b/test/built-ins/Atomics/waitAsync/not-a-typedarray-throws.js @@ -24,6 +24,7 @@ info: | features: [Atomics.waitAsync, arrow-function, Atomics] ---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function'); const poisoned = { valueOf() { throw new Test262Error('should not evaluate this code'); diff --git a/test/built-ins/Atomics/waitAsync/not-an-object-throws.js b/test/built-ins/Atomics/waitAsync/not-an-object-throws.js index ec0097a711..eaf38b3f45 100644 --- a/test/built-ins/Atomics/waitAsync/not-an-object-throws.js +++ b/test/built-ins/Atomics/waitAsync/not-an-object-throws.js @@ -24,6 +24,7 @@ info: | features: [Atomics.waitAsync, Symbol, arrow-function, Atomics] ---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function'); const poisoned = { valueOf() { throw new Test262Error('should not evaluate this code'); diff --git a/test/built-ins/Atomics/waitAsync/null-bufferdata-throws.js b/test/built-ins/Atomics/waitAsync/null-bufferdata-throws.js index 9fb7d23d5d..4c7f440067 100644 --- a/test/built-ins/Atomics/waitAsync/null-bufferdata-throws.js +++ b/test/built-ins/Atomics/waitAsync/null-bufferdata-throws.js @@ -25,6 +25,7 @@ info: | includes: [detachArrayBuffer.js] features: [Atomics.waitAsync, ArrayBuffer, Atomics, TypedArray] ---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function'); const i32a = new Int32Array( new ArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4) ); diff --git a/test/built-ins/Atomics/waitAsync/object-for-timeout.js b/test/built-ins/Atomics/waitAsync/object-for-timeout.js index f45d304b8f..cdadc6b321 100644 --- a/test/built-ins/Atomics/waitAsync/object-for-timeout.js +++ b/test/built-ins/Atomics/waitAsync/object-for-timeout.js @@ -22,6 +22,7 @@ info: | features: [Atomics.waitAsync, SharedArrayBuffer, Symbol, Symbol.toPrimitive, TypedArray, computed-property-names, Atomics, arrow-function] flags: [async] ---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function'); const i32a = new Int32Array( new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4) ); diff --git a/test/built-ins/Atomics/waitAsync/out-of-range-index-throws.js b/test/built-ins/Atomics/waitAsync/out-of-range-index-throws.js index bbb3ec2175..4d40359f1b 100644 --- a/test/built-ins/Atomics/waitAsync/out-of-range-index-throws.js +++ b/test/built-ins/Atomics/waitAsync/out-of-range-index-throws.js @@ -20,6 +20,7 @@ info: | 5. If accessIndex ≥ length, throw a RangeError exception. features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics] ---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function'); const i32a = new Int32Array( new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4) ); diff --git a/test/built-ins/Atomics/waitAsync/symbol-for-timeout-throws.js b/test/built-ins/Atomics/waitAsync/symbol-for-timeout-throws.js index 5d5239008a..0d8bc29d37 100644 --- a/test/built-ins/Atomics/waitAsync/symbol-for-timeout-throws.js +++ b/test/built-ins/Atomics/waitAsync/symbol-for-timeout-throws.js @@ -18,6 +18,7 @@ info: | features: [Atomics.waitAsync, SharedArrayBuffer, Symbol, Symbol.toPrimitive, TypedArray, computed-property-names, Atomics] ---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function'); const i32a = new Int32Array( new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4) ); diff --git a/test/built-ins/Atomics/waitAsync/symbol-for-value-throws.js b/test/built-ins/Atomics/waitAsync/symbol-for-value-throws.js index 051ffd8810..530850ee8c 100644 --- a/test/built-ins/Atomics/waitAsync/symbol-for-value-throws.js +++ b/test/built-ins/Atomics/waitAsync/symbol-for-value-throws.js @@ -22,6 +22,7 @@ info: | features: [Atomics.waitAsync, SharedArrayBuffer, Symbol, Symbol.toPrimitive, TypedArray, computed-property-names, Atomics] ---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function'); const i32a = new Int32Array( new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4) ); diff --git a/test/built-ins/Atomics/waitAsync/true-for-timeout.js b/test/built-ins/Atomics/waitAsync/true-for-timeout.js index 631fc59170..b09280f5e1 100644 --- a/test/built-ins/Atomics/waitAsync/true-for-timeout.js +++ b/test/built-ins/Atomics/waitAsync/true-for-timeout.js @@ -19,6 +19,7 @@ info: | flags: [async] features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, computed-property-names, Symbol, Symbol.toPrimitive, arrow-function] ---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function'); const i32a = new Int32Array( new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4) ); diff --git a/test/built-ins/Atomics/waitAsync/undefined-for-timeout.js b/test/built-ins/Atomics/waitAsync/undefined-for-timeout.js index 7b9b5ac64e..894dff1a4e 100644 --- a/test/built-ins/Atomics/waitAsync/undefined-for-timeout.js +++ b/test/built-ins/Atomics/waitAsync/undefined-for-timeout.js @@ -22,6 +22,7 @@ flags: [async] includes: [atomicsHelper.js] features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, computed-property-names, Symbol, Symbol.toPrimitive, arrow-function] ---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function'); const i32a = new Int32Array( new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4) ); diff --git a/test/built-ins/Atomics/waitAsync/value-not-equal.js b/test/built-ins/Atomics/waitAsync/value-not-equal.js index 0e606f91ce..e1b7a8a374 100644 --- a/test/built-ins/Atomics/waitAsync/value-not-equal.js +++ b/test/built-ins/Atomics/waitAsync/value-not-equal.js @@ -23,6 +23,7 @@ info: | flags: [async] features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, computed-property-names, Symbol, Symbol.toPrimitive, Atomics, arrow-function] ---*/ +assert.sameValue(typeof Atomics.waitAsync, 'function'); const i32a = new Int32Array( new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4) );