From a3b05ee839225aef7f0633ae026f572d3c58621e Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Wed, 25 Apr 2018 17:29:53 -0400 Subject: [PATCH] Atomics: updates to various Atomics tests. gh-1527 Ref gh-1531 --- .../built-ins/Atomics/add/bigint/bad-range.js | 19 ++++ .../Atomics/add/bigint/good-views.js | 53 +++++++++++ .../Atomics/add/bigint/nonshared-int-views.js | 16 ++++ .../built-ins/Atomics/and/bigint/bad-range.js | 19 ++++ .../Atomics/and/bigint/good-views.js | 60 +++++++++++++ .../Atomics/and/bigint/nonshared-int-views.js | 16 ++++ .../compareExchange/bigint/bad-range.js | 19 ++++ .../compareExchange/bigint/good-views.js | 65 ++++++++++++++ .../bigint/nonshared-int-views.js | 16 ++++ .../Atomics/exchange/bigint/bad-range.js | 19 ++++ .../Atomics/exchange/bigint/good-views.js | 54 +++++++++++ .../exchange/bigint/nonshared-int-views.js | 16 ++++ .../Atomics/isLockFree/bigint/corner-cases.js | 32 +++++++ .../Atomics/isLockFree/bigint/value.js | 46 ++++++++++ .../Atomics/load/bigint/bad-range.js | 19 ++++ .../Atomics/load/bigint/good-views.js | 45 ++++++++++ .../load/bigint/nonshared-int-views.js | 19 ++++ test/built-ins/Atomics/or/bigint/bad-range.js | 19 ++++ .../built-ins/Atomics/or/bigint/good-views.js | 60 +++++++++++++ .../Atomics/or/bigint/nonshared-int-views.js | 16 ++++ .../Atomics/store/bigint/bad-range.js | 19 ++++ .../Atomics/store/bigint/good-views.js | 59 ++++++++++++ .../store/bigint/nonshared-int-views.js | 16 ++++ .../built-ins/Atomics/sub/bigint/bad-range.js | 19 ++++ .../Atomics/sub/bigint/good-views.js | 53 +++++++++++ .../Atomics/sub/bigint/nonshared-int-views.js | 16 ++++ test/built-ins/Atomics/wait/bad-range.js | 13 ++- .../Atomics/wait/bigint/bad-range.js | 23 +++++ .../wait/bigint/cannot-suspend-throws.js | 26 ++++++ .../Atomics/wait/bigint/did-timeout.js | 41 +++++++++ .../wait/bigint/false-for-timeout-agent.js | 66 ++++++++++++++ .../Atomics/wait/bigint/false-for-timeout.js | 37 ++++++++ .../Atomics/wait/bigint/good-views.js | 59 ++++++++++++ .../Atomics/wait/bigint/nan-for-timeout.js | 42 +++++++++ .../wait/bigint/negative-index-throws.js | 38 ++++++++ .../wait/bigint/negative-timeout-agent.js | 32 +++++++ .../Atomics/wait/bigint/negative-timeout.js | 15 ++++ ...o-spurious-wakeup-on-store-padded-time.js} | 13 ++- .../bigint/no-spurious-wakeup-on-store.js | 50 +++++++++++ .../bigint/non-bigint64-typedarray-throws.js | 28 ++++++ .../bigint/non-shared-bufferdata-throws.js | 32 +++++++ .../wait/bigint/null-bufferdata-throws.js | 30 +++++++ .../wait/bigint/out-of-range-index-throws.js | 35 ++++++++ .../Atomics/wait/bigint/value-not-equal.js | 47 ++++++++++ .../waiterlist-block-indexedposition-wake.js | 62 +++++++++++++ .../waiterlist-order-of-operations-is-fifo.js | 89 +++++++++++++++++++ .../wait/bigint/was-woken-before-timeout.js | 55 ++++++++++++ .../Atomics/wait/bigint/was-woken.js | 33 +++++++ .../Atomics/wait/cannot-suspend-throws.js | 4 +- test/built-ins/Atomics/wait/did-timeout.js | 15 ++-- .../Atomics/wait/false-for-timeout-agent.js | 18 ++-- .../Atomics/wait/false-for-timeout.js | 8 +- test/built-ins/Atomics/wait/good-views.js | 5 +- .../built-ins/Atomics/wait/nan-for-timeout.js | 14 +-- .../Atomics/wait/negative-index-throws.js | 10 +-- .../Atomics/wait/negative-timeout-agent.js | 11 ++- .../Atomics/wait/negative-timeout.js | 4 +- .../Atomics/wait/no-spurious-wakeup-on-add.js | 52 +++++++++++ ...no-spurious-wakeup-on-store-padded-time.js | 39 ++++++++ .../wait/no-spurious-wakeup-on-store.js | 52 +++++++++++ .../wait/non-shared-bufferdata-throws.js | 6 +- .../Atomics/wait/null-bufferdata-throws.js | 6 +- .../Atomics/wait/null-for-timeout-agent.js | 18 ++-- .../Atomics/wait/null-for-timeout.js | 8 +- .../Atomics/wait/object-for-timeout-agent.js | 18 ++-- .../Atomics/wait/object-for-timeout.js | 8 +- .../Atomics/wait/out-of-range-index-throws.js | 8 +- ...oisoned-object-for-timeout-throws-agent.js | 16 ++-- .../poisoned-object-for-timeout-throws.js | 6 +- .../wait/symbol-for-index-throws-agent.js | 16 ++-- .../Atomics/wait/symbol-for-index-throws.js | 10 +-- .../wait/symbol-for-timeout-throws-agent.js | 19 ++-- .../Atomics/wait/symbol-for-timeout-throws.js | 10 +-- .../wait/symbol-for-value-throws-agent.js | 19 ++-- .../Atomics/wait/symbol-for-value-throws.js | 10 +-- .../Atomics/wait/true-for-timeout-agent.js | 18 ++-- .../Atomics/wait/true-for-timeout.js | 8 +- .../Atomics/wait/undefined-for-timeout.js | 23 +++-- .../wait/undefined-index-defaults-to-zero.js | 19 ++-- .../built-ins/Atomics/wait/value-not-equal.js | 21 ++--- .../wait/wait-index-value-not-equal.js | 23 +++-- .../waiterlist-block-indexedposition-wake.js | 14 +-- .../waiterlist-order-of-operations-is-fifo.js | 23 +++-- .../Atomics/wait/was-woken-before-timeout.js | 3 +- test/built-ins/Atomics/wait/was-woken.js | 7 +- .../Atomics/wake/bigint/bad-range.js | 23 +++++ .../bigint/non-bigint64-typedarray-throws.js | 26 ++++++ .../bigint/non-shared-bufferdata-throws.js | 31 +++++++ .../wake/bigint/null-bufferdata-throws.js | 31 +++++++ .../Atomics/wake/bigint/wake-all-on-loc.js | 78 ++++++++++++++++ .../count-defaults-to-infinity-missing.js | 8 +- .../count-defaults-to-infinity-undefined.js | 11 +-- test/built-ins/Atomics/wake/negative-count.js | 10 +-- .../wake/undefined-index-defaults-to-zero.js | 6 +- .../built-ins/Atomics/wake/wake-all-on-loc.js | 10 +-- test/built-ins/Atomics/wake/wake-all.js | 10 +-- test/built-ins/Atomics/wake/wake-in-order.js | 5 +- test/built-ins/Atomics/wake/wake-nan.js | 7 +- test/built-ins/Atomics/wake/wake-one.js | 5 +- .../Atomics/wake/wake-rewake-noop.js | 3 +- test/built-ins/Atomics/wake/wake-two.js | 7 +- .../wake/wake-with-no-agents-waiting.js | 5 +- .../wake-with-no-matching-agents-waiting.js | 5 +- test/built-ins/Atomics/wake/wake-zero.js | 8 +- .../built-ins/Atomics/xor/bigint/bad-range.js | 19 ++++ .../Atomics/xor/bigint/good-views.js | 61 +++++++++++++ .../Atomics/xor/bigint/nonshared-int-views.js | 16 ++++ 107 files changed, 2338 insertions(+), 292 deletions(-) create mode 100644 test/built-ins/Atomics/add/bigint/bad-range.js create mode 100644 test/built-ins/Atomics/add/bigint/good-views.js create mode 100644 test/built-ins/Atomics/add/bigint/nonshared-int-views.js create mode 100644 test/built-ins/Atomics/and/bigint/bad-range.js create mode 100644 test/built-ins/Atomics/and/bigint/good-views.js create mode 100644 test/built-ins/Atomics/and/bigint/nonshared-int-views.js create mode 100644 test/built-ins/Atomics/compareExchange/bigint/bad-range.js create mode 100644 test/built-ins/Atomics/compareExchange/bigint/good-views.js create mode 100644 test/built-ins/Atomics/compareExchange/bigint/nonshared-int-views.js create mode 100644 test/built-ins/Atomics/exchange/bigint/bad-range.js create mode 100644 test/built-ins/Atomics/exchange/bigint/good-views.js create mode 100644 test/built-ins/Atomics/exchange/bigint/nonshared-int-views.js create mode 100644 test/built-ins/Atomics/isLockFree/bigint/corner-cases.js create mode 100644 test/built-ins/Atomics/isLockFree/bigint/value.js create mode 100644 test/built-ins/Atomics/load/bigint/bad-range.js create mode 100644 test/built-ins/Atomics/load/bigint/good-views.js create mode 100644 test/built-ins/Atomics/load/bigint/nonshared-int-views.js create mode 100644 test/built-ins/Atomics/or/bigint/bad-range.js create mode 100644 test/built-ins/Atomics/or/bigint/good-views.js create mode 100644 test/built-ins/Atomics/or/bigint/nonshared-int-views.js create mode 100644 test/built-ins/Atomics/store/bigint/bad-range.js create mode 100644 test/built-ins/Atomics/store/bigint/good-views.js create mode 100644 test/built-ins/Atomics/store/bigint/nonshared-int-views.js create mode 100644 test/built-ins/Atomics/sub/bigint/bad-range.js create mode 100644 test/built-ins/Atomics/sub/bigint/good-views.js create mode 100644 test/built-ins/Atomics/sub/bigint/nonshared-int-views.js create mode 100644 test/built-ins/Atomics/wait/bigint/bad-range.js create mode 100644 test/built-ins/Atomics/wait/bigint/cannot-suspend-throws.js create mode 100644 test/built-ins/Atomics/wait/bigint/did-timeout.js create mode 100644 test/built-ins/Atomics/wait/bigint/false-for-timeout-agent.js create mode 100644 test/built-ins/Atomics/wait/bigint/false-for-timeout.js create mode 100644 test/built-ins/Atomics/wait/bigint/good-views.js create mode 100644 test/built-ins/Atomics/wait/bigint/nan-for-timeout.js create mode 100644 test/built-ins/Atomics/wait/bigint/negative-index-throws.js create mode 100644 test/built-ins/Atomics/wait/bigint/negative-timeout-agent.js create mode 100644 test/built-ins/Atomics/wait/bigint/negative-timeout.js rename test/built-ins/Atomics/wait/{no-spurious-wakeup.js => bigint/no-spurious-wakeup-on-store-padded-time.js} (77%) create mode 100644 test/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-store.js create mode 100644 test/built-ins/Atomics/wait/bigint/non-bigint64-typedarray-throws.js create mode 100644 test/built-ins/Atomics/wait/bigint/non-shared-bufferdata-throws.js create mode 100644 test/built-ins/Atomics/wait/bigint/null-bufferdata-throws.js create mode 100644 test/built-ins/Atomics/wait/bigint/out-of-range-index-throws.js create mode 100644 test/built-ins/Atomics/wait/bigint/value-not-equal.js create mode 100644 test/built-ins/Atomics/wait/bigint/waiterlist-block-indexedposition-wake.js create mode 100644 test/built-ins/Atomics/wait/bigint/waiterlist-order-of-operations-is-fifo.js create mode 100644 test/built-ins/Atomics/wait/bigint/was-woken-before-timeout.js create mode 100644 test/built-ins/Atomics/wait/bigint/was-woken.js create mode 100644 test/built-ins/Atomics/wait/no-spurious-wakeup-on-add.js create mode 100644 test/built-ins/Atomics/wait/no-spurious-wakeup-on-store-padded-time.js create mode 100644 test/built-ins/Atomics/wait/no-spurious-wakeup-on-store.js create mode 100644 test/built-ins/Atomics/wake/bigint/bad-range.js create mode 100644 test/built-ins/Atomics/wake/bigint/non-bigint64-typedarray-throws.js create mode 100644 test/built-ins/Atomics/wake/bigint/non-shared-bufferdata-throws.js create mode 100644 test/built-ins/Atomics/wake/bigint/null-bufferdata-throws.js create mode 100644 test/built-ins/Atomics/wake/bigint/wake-all-on-loc.js create mode 100644 test/built-ins/Atomics/xor/bigint/bad-range.js create mode 100644 test/built-ins/Atomics/xor/bigint/good-views.js create mode 100644 test/built-ins/Atomics/xor/bigint/nonshared-int-views.js diff --git a/test/built-ins/Atomics/add/bigint/bad-range.js b/test/built-ins/Atomics/add/bigint/bad-range.js new file mode 100644 index 0000000000..d8781ee6f6 --- /dev/null +++ b/test/built-ins/Atomics/add/bigint/bad-range.js @@ -0,0 +1,19 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.add +description: > + Test range checking of Atomics.add on arrays that allow atomic operations +includes: [testAtomics.js, testBigIntTypedArray.js] +features: [ArrayBuffer, arrow-function, Atomics, BigInt, DataView, for-of, let, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(8); + +testWithBigIntTypedArrayConstructors(function(TA) { + let view = new TA(buffer); + testWithAtomicsOutOfBoundsIndices(function(IdxGen) { + assert.throws(RangeError, () => Atomics.add(view, IdxGen(view), 10)); + }); +}); diff --git a/test/built-ins/Atomics/add/bigint/good-views.js b/test/built-ins/Atomics/add/bigint/good-views.js new file mode 100644 index 0000000000..1d81b888df --- /dev/null +++ b/test/built-ins/Atomics/add/bigint/good-views.js @@ -0,0 +1,53 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.add +description: Test Atomics.add on arrays that allow atomic operations. +includes: [testAtomics.js, testBigIntTypedArray.js] +features: [ArrayBuffer, Atomics, BigInt, computed-property-names, DataView, for-of, let, SharedArrayBuffer, TypedArray] +---*/ + +var sab = new SharedArrayBuffer(1024); +var ab = new ArrayBuffer(16); + +testWithBigIntTypedArrayConstructors(function(TA) { + // Make it interesting - use non-zero byteOffsets and non-zero indexes. + + var view = new TA(sab, 32, 20); + var control = new TA(ab, 0, 2); + + // Add positive number + view[8] = 0; + assert.sameValue(Atomics.add(view, 8, 10), 0); + assert.sameValue(view[8], 10); + + // Add negative number + assert.sameValue(Atomics.add(view, 8, -5), 10); + assert.sameValue(view[8], 5); + + view[3] = -5; + control[0] = -5; + assert.sameValue(Atomics.add(view, 3, 0), control[0], + "Result is negative and subject to coercion"); + + control[0] = 12345; + view[3] = 12345; + assert.sameValue(Atomics.add(view, 3, 0), control[0], + "Result is subject to chopping"); + + control[0] = 123456789; + view[3] = 123456789; + assert.sameValue(Atomics.add(view, 3, 0), control[0], + "Result is subject to chopping"); + + // In-bounds boundary cases for indexing + testWithAtomicsInBoundsIndices(function(IdxGen) { + let Idx = IdxGen(view); + view.fill(0); + // 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); + assert.sameValue(Atomics.add(view, Idx, 0), 37); + }); +}); diff --git a/test/built-ins/Atomics/add/bigint/nonshared-int-views.js b/test/built-ins/Atomics/add/bigint/nonshared-int-views.js new file mode 100644 index 0000000000..1d9c2b1fc9 --- /dev/null +++ b/test/built-ins/Atomics/add/bigint/nonshared-int-views.js @@ -0,0 +1,16 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.add +description: > + Test Atomics.add on non-shared integer TypedArrays +includes: [testBigIntTypedArray.js] +features: [ArrayBuffer, arrow-function, Atomics, BigInt, TypedArray] +---*/ + +var ab = new ArrayBuffer(16); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(TypeError, () => Atomics.add(new TA(ab), 0, 0)); +}); diff --git a/test/built-ins/Atomics/and/bigint/bad-range.js b/test/built-ins/Atomics/and/bigint/bad-range.js new file mode 100644 index 0000000000..0f87ca9fe9 --- /dev/null +++ b/test/built-ins/Atomics/and/bigint/bad-range.js @@ -0,0 +1,19 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.and +description: > + Test range checking of Atomics.and on arrays that allow atomic operations +includes: [testAtomics.js, testBigIntTypedArray.js] +features: [ArrayBuffer, arrow-function, Atomics, BigInt, DataView, for-of, let, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(8); + +testWithBigIntTypedArrayConstructors(function(TA) { + let view = new TA(buffer); + testWithAtomicsOutOfBoundsIndices(function(IdxGen) { + assert.throws(RangeError, () => Atomics.and(view, IdxGen(view), 10)); + }); +}); diff --git a/test/built-ins/Atomics/and/bigint/good-views.js b/test/built-ins/Atomics/and/bigint/good-views.js new file mode 100644 index 0000000000..3493c4db76 --- /dev/null +++ b/test/built-ins/Atomics/and/bigint/good-views.js @@ -0,0 +1,60 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.and +description: Test Atomics.and on arrays that allow atomic operations +includes: [testAtomics.js, testBigIntTypedArray.js] +features: [ArrayBuffer, Atomics, BigInt, computed-property-names, DataView, for-of, let, SharedArrayBuffer, TypedArray] +---*/ + +var sab = new SharedArrayBuffer(1024); +var ab = new ArrayBuffer(16); + +testWithBigIntTypedArrayConstructors(function(TA) { + // Make it interesting - use non-zero byteOffsets and non-zero indexes. + + var view = new TA(sab, 32, 20); + var control = new TA(ab, 0, 2); + + view[8] = 0x33333333; + control[0] = 0x33333333; + assert.sameValue(Atomics.and(view, 8, 0x55555555), control[0], + "Result is subject to chopping"); + + control[0] = 0x11111111; + assert.sameValue(view[8], control[0]); + assert.sameValue(Atomics.and(view, 8, 0xF0F0F0F0), control[0], + "Result is subject to chopping"); + + control[0] = 0x10101010; + assert.sameValue(view[8], control[0]); + + view[3] = -5; + control[0] = -5; + assert.sameValue(Atomics.and(view, 3, 0), control[0], + "Result is negative and subject to coercion"); + assert.sameValue(view[3], 0); + + control[0] = 12345; + view[3] = 12345; + assert.sameValue(Atomics.and(view, 3, 0), control[0], + "Result is subjective to chopping"); + assert.sameValue(view[3], 0); + + control[0] = 123456789; + view[3] = 123456789; + assert.sameValue(Atomics.and(view, 3, 0), control[0], + "Result is subjective to chopping"); + assert.sameValue(view[3], 0); + + // In-bounds boundary cases for indexing + testWithAtomicsInBoundsIndices(function(IdxGen) { + let Idx = IdxGen(view); + view.fill(0); + // 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); + assert.sameValue(Atomics.and(view, Idx, 0), 37); + }); +}); diff --git a/test/built-ins/Atomics/and/bigint/nonshared-int-views.js b/test/built-ins/Atomics/and/bigint/nonshared-int-views.js new file mode 100644 index 0000000000..8389b91852 --- /dev/null +++ b/test/built-ins/Atomics/and/bigint/nonshared-int-views.js @@ -0,0 +1,16 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.and +description: > + Test Atomics.and on non-shared integer TypedArrays +includes: [testBigIntTypedArray.js] +features: [ArrayBuffer, arrow-function, Atomics, BigInt, TypedArray] +---*/ + +var buffer = new ArrayBuffer(16); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(TypeError, () => Atomics.and(new TA(buffer), 0, 0)); +}); diff --git a/test/built-ins/Atomics/compareExchange/bigint/bad-range.js b/test/built-ins/Atomics/compareExchange/bigint/bad-range.js new file mode 100644 index 0000000000..99ff9ec70b --- /dev/null +++ b/test/built-ins/Atomics/compareExchange/bigint/bad-range.js @@ -0,0 +1,19 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.compareexchange +description: > + Test range checking of Atomics.compareExchange on arrays that allow atomic operations +includes: [testAtomics.js, testBigIntTypedArray.js] +features: [ArrayBuffer, arrow-function, Atomics, BigInt, DataView, for-of, let, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(8); + +testWithBigIntTypedArrayConstructors(function(TA) { + let view = new TA(buffer); + testWithAtomicsOutOfBoundsIndices(function(IdxGen) { + assert.throws(RangeError, () => Atomics.compareExchange(view, IdxGen(view), 10, 0)); + }); +}); diff --git a/test/built-ins/Atomics/compareExchange/bigint/good-views.js b/test/built-ins/Atomics/compareExchange/bigint/good-views.js new file mode 100644 index 0000000000..f6425e3d53 --- /dev/null +++ b/test/built-ins/Atomics/compareExchange/bigint/good-views.js @@ -0,0 +1,65 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.compareexchange +description: Test Atomics.compareExchange on arrays that allow atomic operations. +includes: [testAtomics.js, testBigIntTypedArray.js] +features: [ArrayBuffer, Atomics, BigInt, computed-property-names, DataView, for-of, let, SharedArrayBuffer, TypedArray] +---*/ + +var sab = new SharedArrayBuffer(1024); +var ab = new ArrayBuffer(16); + +testWithBigIntTypedArrayConstructors(function(TA) { + // Make it interesting - use non-zero byteOffsets and non-zero indexes. + + var view = new TA(sab, 32, 20); + var control = new TA(ab, 0, 2); + + // Performs the exchange + view[8] = 0; + assert.sameValue(Atomics.compareExchange(view, 8, 0, 10), 0); + assert.sameValue(view[8], 10); + + view[8] = 0; + assert.sameValue(Atomics.compareExchange(view, 8, 1, 10), 0, + "Does not perform the exchange"); + assert.sameValue(view[8], 0); + + view[8] = 0; + assert.sameValue(Atomics.compareExchange(view, 8, 0, -5), 0, + "Performs the exchange, coercing the value being stored"); + control[0] = -5; + assert.sameValue(view[8], control[0]); + + + view[3] = -5; + control[0] = -5; + assert.sameValue(Atomics.compareExchange(view, 3, -5, 0), control[0], + "Performs the exchange, coercing the value being tested"); + assert.sameValue(view[3], 0); + + + control[0] = 12345; + view[3] = 12345; + assert.sameValue(Atomics.compareExchange(view, 3, 12345, 0), control[0], + "Performs the exchange, chopping the value being tested"); + assert.sameValue(view[3], 0); + + control[0] = 123456789; + view[3] = 123456789; + assert.sameValue(Atomics.compareExchange(view, 3, 123456789, 0), control[0], + "Performs the exchange, chopping the value being tested"); + assert.sameValue(view[3], 0); + + // In-bounds boundary cases for indexing + testWithAtomicsInBoundsIndices(function(IdxGen) { + let Idx = IdxGen(view); + view.fill(0); + // 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); + assert.sameValue(Atomics.compareExchange(view, Idx, 37, 0), 37); + }); +}); diff --git a/test/built-ins/Atomics/compareExchange/bigint/nonshared-int-views.js b/test/built-ins/Atomics/compareExchange/bigint/nonshared-int-views.js new file mode 100644 index 0000000000..2b044ca0c5 --- /dev/null +++ b/test/built-ins/Atomics/compareExchange/bigint/nonshared-int-views.js @@ -0,0 +1,16 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.compareexchange +description: > + Test Atomics.compareExchange on non-shared integer TypedArrays +includes: [testBigIntTypedArray.js] +features: [ArrayBuffer, arrow-function, Atomics, BigInt, TypedArray] +---*/ + +var buffer = new ArrayBuffer(16); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(TypeError, (() => Atomics.compareExchange(new TA(buffer), 0, 0, 0))); +}); diff --git a/test/built-ins/Atomics/exchange/bigint/bad-range.js b/test/built-ins/Atomics/exchange/bigint/bad-range.js new file mode 100644 index 0000000000..2ccd1b9460 --- /dev/null +++ b/test/built-ins/Atomics/exchange/bigint/bad-range.js @@ -0,0 +1,19 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.exchange +description: > + Test range checking of Atomics.exchange on arrays that allow atomic operations +includes: [testAtomics.js, testBigIntTypedArray.js] +features: [ArrayBuffer, arrow-function, Atomics, BigInt, DataView, for-of, let, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(8); + +testWithBigIntTypedArrayConstructors(function(TA) { + let view = new TA(buffer); + testWithAtomicsOutOfBoundsIndices(function(IdxGen) { + assert.throws(RangeError, () => Atomics.exchange(view, IdxGen(view), 10, 0)); + }); +}); diff --git a/test/built-ins/Atomics/exchange/bigint/good-views.js b/test/built-ins/Atomics/exchange/bigint/good-views.js new file mode 100644 index 0000000000..ba2b14e9e1 --- /dev/null +++ b/test/built-ins/Atomics/exchange/bigint/good-views.js @@ -0,0 +1,54 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.exchange +description: Test Atomics.exchange on arrays that allow atomic operations. +includes: [testAtomics.js, testBigIntTypedArray.js] +features: [ArrayBuffer, Atomics, BigInt, computed-property-names, DataView, for-of, let, SharedArrayBuffer, TypedArray] +---*/ + +var sab = new SharedArrayBuffer(1024); +var ab = new ArrayBuffer(16); + +testWithBigIntTypedArrayConstructors(function(TA) { + // Make it interesting - use non-zero byteOffsets and non-zero indexes. + + var view = new TA(sab, 32, 20); + var control = new TA(ab, 0, 2); + + view[8] = 0; + assert.sameValue(Atomics.exchange(view, 8, 10), 0, + "Exchange returns the value previously in the array"); + assert.sameValue(view[8], 10); + + assert.sameValue(Atomics.exchange(view, 8, -5), 10, + "Exchange returns the value previously in the array"); + control[0] = -5; + assert.sameValue(view[8], control[0]); + + view[3] = -5; + control[0] = -5; + assert.sameValue(Atomics.exchange(view, 3, 0), control[0], + "Result is subject to coercion"); + + control[0] = 12345; + view[3] = 12345; + assert.sameValue(Atomics.exchange(view, 3, 0), control[0], + "Result is subject to chopping"); + + control[0] = 123456789; + view[3] = 123456789; + assert.sameValue(Atomics.exchange(view, 3, 0), control[0], + "Result is subject to chopping"); + + // In-bounds boundary cases for indexing + testWithAtomicsInBoundsIndices(function(IdxGen) { + let Idx = IdxGen(view); + view.fill(0); + // 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); + assert.sameValue(Atomics.exchange(view, Idx, 0), 37); + }); +}); diff --git a/test/built-ins/Atomics/exchange/bigint/nonshared-int-views.js b/test/built-ins/Atomics/exchange/bigint/nonshared-int-views.js new file mode 100644 index 0000000000..13f49c28f2 --- /dev/null +++ b/test/built-ins/Atomics/exchange/bigint/nonshared-int-views.js @@ -0,0 +1,16 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.exchange +description: > + Test Atomics.exchange on non-shared integer TypedArrays +includes: [testBigIntTypedArray.js] +features: [ArrayBuffer, arrow-function, Atomics, BigInt, TypedArray] +---*/ + +var buffer = new ArrayBuffer(16); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(TypeError, (() => Atomics.exchange(new TA(buffer), 0, 0))); +}); diff --git a/test/built-ins/Atomics/isLockFree/bigint/corner-cases.js b/test/built-ins/Atomics/isLockFree/bigint/corner-cases.js new file mode 100644 index 0000000000..a0127ee288 --- /dev/null +++ b/test/built-ins/Atomics/isLockFree/bigint/corner-cases.js @@ -0,0 +1,32 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.islockfree +description: > + Test isLockFree on various non-intuitive arguments +features: [arrow-function, Atomics] +includes: [testAtomics.js, testBigIntTypedArray.js] +---*/ + +assert.sameValue(Atomics.isLockFree(hide(3, Number.NaN)), false); +assert.sameValue(Atomics.isLockFree(hide(3, -1)), false); +assert.sameValue(Atomics.isLockFree(hide(3, 3.14)), false); +assert.sameValue(Atomics.isLockFree(hide(3, 0)), false); + +assert.sameValue(Atomics.isLockFree('1'), Atomics.isLockFree(1)); +assert.sameValue(Atomics.isLockFree('3'), Atomics.isLockFree(3)); + +assert.sameValue(Atomics.isLockFree(true), Atomics.isLockFree(1)); + +assert.sameValue(Atomics.isLockFree(1), Atomics.isLockFree({valueOf: () => 1})); +assert.sameValue(Atomics.isLockFree(3), Atomics.isLockFree({valueOf: () => 3})); +assert.sameValue(Atomics.isLockFree(1), Atomics.isLockFree({toString: () => '1'})); +assert.sameValue(Atomics.isLockFree(3), Atomics.isLockFree({toString: () => '3'})); + +function hide(k, x) { + if (k) { + return hide(k - 3, x) + x; + } + return 0; +} diff --git a/test/built-ins/Atomics/isLockFree/bigint/value.js b/test/built-ins/Atomics/isLockFree/bigint/value.js new file mode 100644 index 0000000000..0743f1c0fa --- /dev/null +++ b/test/built-ins/Atomics/isLockFree/bigint/value.js @@ -0,0 +1,46 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.islockfree +description: > + Test isLockFree on nonnegative integer arguments +features: [Atomics, computed-property-names] +includes: [testAtomics.js, testBigIntTypedArray.js] +---*/ + +var sizes = [ 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12]; +var answers = [ {}, {}, false, true, false, false, false, false, + false, false, false, false]; + +var saved = {}; + +// This should defeat most optimizations. + +for (var i = 0; i < sizes.length; i++) { + var v = Atomics.isLockFree(sizes[i]); + var a = answers[i]; + assert.sameValue(typeof v, 'boolean'); + if (typeof a == 'boolean') { + assert.sameValue(v, a); + } else { + saved[sizes[i]] = v; + } +} + +// This ought to be optimizable. Make sure the answers are the same +// as for the unoptimized case. + +assert.sameValue(Atomics.isLockFree(1), saved[1]); +assert.sameValue(Atomics.isLockFree(2), saved[2]); +assert.sameValue(Atomics.isLockFree(3), false); +assert.sameValue(Atomics.isLockFree(4), true); +assert.sameValue(Atomics.isLockFree(5), false); +assert.sameValue(Atomics.isLockFree(6), false); +assert.sameValue(Atomics.isLockFree(7), false); +assert.sameValue(Atomics.isLockFree(8), false); +assert.sameValue(Atomics.isLockFree(9), false); +assert.sameValue(Atomics.isLockFree(10), false); +assert.sameValue(Atomics.isLockFree(11), false); +assert.sameValue(Atomics.isLockFree(12), false); diff --git a/test/built-ins/Atomics/load/bigint/bad-range.js b/test/built-ins/Atomics/load/bigint/bad-range.js new file mode 100644 index 0000000000..b69a416042 --- /dev/null +++ b/test/built-ins/Atomics/load/bigint/bad-range.js @@ -0,0 +1,19 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.load +description: > + Test range checking of Atomics.load on arrays that allow atomic operations +includes: [testAtomics.js, testBigIntTypedArray.js] +features: [ArrayBuffer, arrow-function, Atomics, BigInt, DataView, for-of, let, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(8); + +testWithBigIntTypedArrayConstructors(function(TA) { + let view = new TA(buffer); + testWithAtomicsOutOfBoundsIndices(function(IdxGen) { + assert.throws(RangeError, () => Atomics.load(view, IdxGen(view))); + }); +}); diff --git a/test/built-ins/Atomics/load/bigint/good-views.js b/test/built-ins/Atomics/load/bigint/good-views.js new file mode 100644 index 0000000000..96bab85e13 --- /dev/null +++ b/test/built-ins/Atomics/load/bigint/good-views.js @@ -0,0 +1,45 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.load +description: Test Atomics.load on arrays that allow atomic operations. +includes: [testAtomics.js, testBigIntTypedArray.js] +features: [ArrayBuffer, Atomics, BigInt, computed-property-names, DataView, for-of, let, SharedArrayBuffer, TypedArray] +---*/ + +var sab = new SharedArrayBuffer(1024); +var ab = new ArrayBuffer(16); + + +testWithBigIntTypedArrayConstructors(function(TA) { + // Make it interesting - use non-zero byteOffsets and non-zero indexes. + + var view = new TA(sab, 32, 20); + var control = new TA(ab, 0, 2); + + view[3] = -5; + control[0] = -5; + assert.sameValue(Atomics.load(view, 3), control[0], + "Result is subject to coercion"); + + control[0] = 12345; + view[3] = 12345; + assert.sameValue(Atomics.load(view, 3), control[0], + "Result is subject to chopping"); + + control[0] = 123456789; + view[3] = 123456789; + assert.sameValue(Atomics.load(view, 3), control[0], + "Result is subject to chopping"); + + // In-bounds boundary cases for indexing + testWithAtomicsInBoundsIndices(function(IdxGen) { + let Idx = IdxGen(view); + view.fill(0); + // 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); + assert.sameValue(Atomics.load(view, Idx), 37); + }); +}); diff --git a/test/built-ins/Atomics/load/bigint/nonshared-int-views.js b/test/built-ins/Atomics/load/bigint/nonshared-int-views.js new file mode 100644 index 0000000000..ae9c5f27ce --- /dev/null +++ b/test/built-ins/Atomics/load/bigint/nonshared-int-views.js @@ -0,0 +1,19 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.load +description: > + Test Atomics.load on non-shared integer TypedArrays +includes: [testBigIntTypedArray.js] +features: [ArrayBuffer, arrow-function, Atomics, BigInt, TypedArray] +---*/ + +var ab = new ArrayBuffer(16); + + +testWithBigIntTypedArrayConstructors(function(TA) { + var view = new TA(ab); + + assert.throws(TypeError, (() => Atomics.load(view, 0))); +}); diff --git a/test/built-ins/Atomics/or/bigint/bad-range.js b/test/built-ins/Atomics/or/bigint/bad-range.js new file mode 100644 index 0000000000..2642445846 --- /dev/null +++ b/test/built-ins/Atomics/or/bigint/bad-range.js @@ -0,0 +1,19 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.or +description: > + Test range checking of Atomics.or on arrays that allow atomic operations +includes: [testAtomics.js, testBigIntTypedArray.js] +features: [ArrayBuffer, arrow-function, Atomics, BigInt, DataView, for-of, let, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(8); + +testWithBigIntTypedArrayConstructors(function(TA) { + let view = new TA(buffer); + testWithAtomicsOutOfBoundsIndices(function(IdxGen) { + assert.throws(RangeError, () => Atomics.or(view, IdxGen(view), 10)); + }); +}); diff --git a/test/built-ins/Atomics/or/bigint/good-views.js b/test/built-ins/Atomics/or/bigint/good-views.js new file mode 100644 index 0000000000..21a35fc899 --- /dev/null +++ b/test/built-ins/Atomics/or/bigint/good-views.js @@ -0,0 +1,60 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.or +description: Test Atomics.or on arrays that allow atomic operations +includes: [testAtomics.js, testBigIntTypedArray.js] +features: [ArrayBuffer, Atomics, BigInt, computed-property-names, DataView, for-of, let, SharedArrayBuffer, TypedArray] +---*/ + +var sab = new SharedArrayBuffer(1024); +var ab = new ArrayBuffer(16); + +testWithBigIntTypedArrayConstructors(function(TA) { + // Make it interesting - use non-zero byteOffsets and non-zero indexes. + + var view = new TA(sab, 32, 20); + var control = new TA(ab, 0, 2); + + view[8] = 0x33333333; + control[0] = 0x33333333; + assert.sameValue(Atomics.or(view, 8, 0x55555555), control[0], + "Result is subject to chopping"); + + control[0] = 0x77777777; + assert.sameValue(view[8], control[0]); + assert.sameValue(Atomics.or(view, 8, 0xF0F0F0F0), control[0], + "Result is subject to chopping"); + + control[0] = 0xF7F7F7F7; + assert.sameValue(view[8], control[0]); + + view[3] = -5; + control[0] = -5; + assert.sameValue(Atomics.or(view, 3, 0), control[0], + "Result is negative and subject to coercion"); + assert.sameValue(view[3], control[0]); + + control[0] = 12345; + view[3] = 12345; + assert.sameValue(Atomics.or(view, 3, 0), control[0], + "Result is subject to chopping"); + assert.sameValue(view[3], control[0]); + + control[0] = 123456789; + view[3] = 123456789; + assert.sameValue(Atomics.or(view, 3, 0), control[0], + "Result is subject to chopping"); + assert.sameValue(view[3], control[0]); + + // In-bounds boundary cases for indexing + testWithAtomicsInBoundsIndices(function(IdxGen) { + let Idx = IdxGen(view); + view.fill(0); + // 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); + assert.sameValue(Atomics.or(view, Idx, 0), 37); + }); +}); diff --git a/test/built-ins/Atomics/or/bigint/nonshared-int-views.js b/test/built-ins/Atomics/or/bigint/nonshared-int-views.js new file mode 100644 index 0000000000..9fbb6fce61 --- /dev/null +++ b/test/built-ins/Atomics/or/bigint/nonshared-int-views.js @@ -0,0 +1,16 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.or +description: > + Test Atomics.or on non-shared integer TypedArrays +includes: [testBigIntTypedArray.js] +features: [ArrayBuffer, arrow-function, Atomics, BigInt, TypedArray] +---*/ + +var buffer = new ArrayBuffer(16); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(TypeError, (() => Atomics.or(new TA(buffer), 0, 0))); +}); diff --git a/test/built-ins/Atomics/store/bigint/bad-range.js b/test/built-ins/Atomics/store/bigint/bad-range.js new file mode 100644 index 0000000000..dfcb100ee1 --- /dev/null +++ b/test/built-ins/Atomics/store/bigint/bad-range.js @@ -0,0 +1,19 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.store +description: > + Test range checking of Atomics.store on arrays that allow atomic operations +includes: [testAtomics.js, testBigIntTypedArray.js] +features: [ArrayBuffer, arrow-function, Atomics, BigInt, DataView, for-of, let, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(8); + +testWithBigIntTypedArrayConstructors(function(TA) { + let view = new TA(buffer); + testWithAtomicsOutOfBoundsIndices(function(IdxGen) { + assert.throws(RangeError, () => Atomics.store(view, IdxGen(view), 10)); + }); +}); diff --git a/test/built-ins/Atomics/store/bigint/good-views.js b/test/built-ins/Atomics/store/bigint/good-views.js new file mode 100644 index 0000000000..75ebedf26a --- /dev/null +++ b/test/built-ins/Atomics/store/bigint/good-views.js @@ -0,0 +1,59 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.store +description: Test Atomics.store on arrays that allow atomic operations. +includes: [testAtomics.js, testBigIntTypedArray.js] +features: [ArrayBuffer, arrow-function, Atomics, BigInt, computed-property-names, DataView, for-of, let, SharedArrayBuffer, TypedArray] +---*/ + +var sab = new SharedArrayBuffer(1024); +var ab = new ArrayBuffer(16); + +testWithBigIntTypedArrayConstructors(function(TA) { + // Make it interesting - use non-zero byteOffsets and non-zero indexes. + + var view = new TA(sab, 32, 20); + var control = new TA(ab, 0, 2); + + for (let val of [10, -5, + 12345, + 123456789, + Math.PI, + "33", + { + valueOf: () => 33 + }, + undefined + ]) + { + assert.sameValue(Atomics.store(view, 3, val), ToInteger(val), + "Atomics.store returns its third argument (" + val + ") converted to Integer, not the input value nor the value that was stored"); + + control[0] = val; + assert.sameValue(view[3], control[0]); + } + + // In-bounds boundary cases for indexing + testWithAtomicsInBoundsIndices(function(IdxGen) { + let Idx = IdxGen(view); + view.fill(0); + Atomics.store(view, Idx, 37); + assert.sameValue(Atomics.load(view, Idx), 37); + }); +}); + +function ToInteger(v) { + v = +v; + if (isNaN(v)) { + return 0; + } + if (v == 0 || !isFinite(v)) { + return v; + } + if (v < 0) { + return -Math.floor(Math.abs(v)); + } + return Math.floor(v); +} diff --git a/test/built-ins/Atomics/store/bigint/nonshared-int-views.js b/test/built-ins/Atomics/store/bigint/nonshared-int-views.js new file mode 100644 index 0000000000..e9abab09ce --- /dev/null +++ b/test/built-ins/Atomics/store/bigint/nonshared-int-views.js @@ -0,0 +1,16 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.store +description: > + Test Atomics.store on non-shared integer TypedArrays +includes: [testBigIntTypedArray.js] +features: [ArrayBuffer, arrow-function, Atomics, BigInt, TypedArray] +---*/ + +var buffer = new ArrayBuffer(16); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(TypeError, (() => Atomics.store(new TA(buffer), 0, 0))); +}); diff --git a/test/built-ins/Atomics/sub/bigint/bad-range.js b/test/built-ins/Atomics/sub/bigint/bad-range.js new file mode 100644 index 0000000000..4454cefeb1 --- /dev/null +++ b/test/built-ins/Atomics/sub/bigint/bad-range.js @@ -0,0 +1,19 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.sub +description: > + Test range checking of Atomics.sub on arrays that allow atomic operations +includes: [testAtomics.js, testBigIntTypedArray.js] +features: [ArrayBuffer, arrow-function, Atomics, BigInt, DataView, for-of, let, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(8); + +testWithBigIntTypedArrayConstructors(function(TA) { + let view = new TA(buffer); + testWithAtomicsOutOfBoundsIndices(function(IdxGen) { + assert.throws(RangeError, () => Atomics.sub(view, IdxGen(view), 10)); + }); +}); diff --git a/test/built-ins/Atomics/sub/bigint/good-views.js b/test/built-ins/Atomics/sub/bigint/good-views.js new file mode 100644 index 0000000000..756dd22d7c --- /dev/null +++ b/test/built-ins/Atomics/sub/bigint/good-views.js @@ -0,0 +1,53 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.sub +description: Test Atomics.sub on arrays that allow atomic operations +includes: [testAtomics.js, testBigIntTypedArray.js] +features: [ArrayBuffer, Atomics, BigInt, computed-property-names, DataView, for-of, let, SharedArrayBuffer, TypedArray] +---*/ + +var sab = new SharedArrayBuffer(1024); +var ab = new ArrayBuffer(16); + +testWithBigIntTypedArrayConstructors(function(TA) { + // Make it interesting - use non-zero byteOffsets and non-zero indexes. + + var view = new TA(sab, 32, 20); + var control = new TA(ab, 0, 2); + + view[8] = 100; + assert.sameValue(Atomics.sub(view, 8, 10), 100, + "Subtract positive number"); + assert.sameValue(view[8], 90); + + assert.sameValue(Atomics.sub(view, 8, -5), 90, + "Subtract negative number, though result remains positive"); + assert.sameValue(view[8], 95); + + view[3] = -5; + control[0] = -5; + assert.sameValue(Atomics.sub(view, 3, 0), control[0], + "Result is negative and subject to coercion"); + + control[0] = 12345; + view[3] = 12345; + assert.sameValue(Atomics.sub(view, 3, 0), control[0], + "Result is subject to chopping"); + + control[0] = 123456789; + view[3] = 123456789; + assert.sameValue(Atomics.sub(view, 3, 0), control[0], + "Result is subject to chopping"); + + // In-bounds boundary cases for indexing + testWithAtomicsInBoundsIndices(function(IdxGen) { + let Idx = IdxGen(view); + view.fill(0); + // 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); + assert.sameValue(Atomics.sub(view, Idx, 0), 37); + }); +}); diff --git a/test/built-ins/Atomics/sub/bigint/nonshared-int-views.js b/test/built-ins/Atomics/sub/bigint/nonshared-int-views.js new file mode 100644 index 0000000000..c570a47902 --- /dev/null +++ b/test/built-ins/Atomics/sub/bigint/nonshared-int-views.js @@ -0,0 +1,16 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.sub +description: > + Test Atomics.sub on non-shared integer TypedArrays +includes: [testBigIntTypedArray.js] +features: [ArrayBuffer, arrow-function, Atomics, BigInt, TypedArray] +---*/ + +var buffer = new ArrayBuffer(16); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(TypeError, (() => Atomics.sub(new TA(buffer), 0, 0))); +}); diff --git a/test/built-ins/Atomics/wait/bad-range.js b/test/built-ins/Atomics/wait/bad-range.js index 3bb8da937c..eb051f381b 100644 --- a/test/built-ins/Atomics/wait/bad-range.js +++ b/test/built-ins/Atomics/wait/bad-range.js @@ -11,16 +11,13 @@ info: | 1. Let buffer be ? ValidateSharedIntegerTypedArray(typedArray, true). ... -includes: [testAtomics.js, testTypedArray.js] +includes: [testAtomics.js] features: [ArrayBuffer, arrow-function, Atomics, DataView, for-of, let, SharedArrayBuffer, TypedArray] ---*/ var sab = new SharedArrayBuffer(8); -var views = [Int32Array]; +let i32a = new Int32Array(sab); -testWithTypedArrayConstructors(function(TA) { - let view = new TA(sab); - testWithAtomicsOutOfBoundsIndices(function(IdxGen) { - assert.throws(RangeError, () => Atomics.wake(view, IdxGen(view), 0)); // Even with waking zero - }); -}, views); +testWithAtomicsOutOfBoundsIndices(function(IdxGen) { + assert.throws(RangeError, () => Atomics.wait(i32a, IdxGen(i32a), 0, 0)); +}); diff --git a/test/built-ins/Atomics/wait/bigint/bad-range.js b/test/built-ins/Atomics/wait/bigint/bad-range.js new file mode 100644 index 0000000000..eda06ac002 --- /dev/null +++ b/test/built-ins/Atomics/wait/bigint/bad-range.js @@ -0,0 +1,23 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.wake +description: > + Test range checking of Atomics.wake on arrays that allow atomic operations +info: | + Atomics.wait( typedArray, index, value, timeout ) + + 1. Let buffer be ? ValidateSharedIntegerTypedArray(typedArray, true). + ... + +includes: [testAtomics.js] +features: [ArrayBuffer, arrow-function, Atomics, BigInt, DataView, for-of, let, SharedArrayBuffer, TypedArray] +---*/ + +var sab = new SharedArrayBuffer(8); +let i64a = new BigInt64Array(sab); + +testWithAtomicsOutOfBoundsIndices(function(IdxGen) { + assert.throws(RangeError, () => Atomics.wait(i64a, IdxGen(i64a), 0, 0)); +}); diff --git a/test/built-ins/Atomics/wait/bigint/cannot-suspend-throws.js b/test/built-ins/Atomics/wait/bigint/cannot-suspend-throws.js new file mode 100644 index 0000000000..a78000ac82 --- /dev/null +++ b/test/built-ins/Atomics/wait/bigint/cannot-suspend-throws.js @@ -0,0 +1,26 @@ +// Copyright (C) 2018 Amal Hussein. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.wait +description: > + Atomics.wait throws if agent cannot be suspended, CanBlock is false +info: | + Assuming [[CanBlock]] is false for the main host. + + Atomics.wait( typedArray, index, value, timeout ) + + ... (after args validation) + 6. Let B be AgentCanSuspend(). + 7. If B is false, throw a TypeError exception. + ... +features: [Atomics, BigInt, SharedArrayBuffer, TypedArray] +flags: [CanBlockIsFalse] +---*/ + +var buffer = new SharedArrayBuffer(4); +var i64a = new BigInt64Array(buffer); + +assert.throws(TypeError, function() { + Atomics.wait(i64a, 0, 0, 0); +}); diff --git a/test/built-ins/Atomics/wait/bigint/did-timeout.js b/test/built-ins/Atomics/wait/bigint/did-timeout.js new file mode 100644 index 0000000000..fee3b1982c --- /dev/null +++ b/test/built-ins/Atomics/wait/bigint/did-timeout.js @@ -0,0 +1,41 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.wait +description: > + Test that Atomics.wait returns the right result when it timed out and that + the time to time out is reasonable. + info: | + 17. Let awoken be Suspend(WL, W, t). + 18. If awoken is true, then + a. Assert: W is not on the list of waiters in WL. + 19. Else, + a.Perform RemoveWaiter(WL, W). +features: [Atomics, BigInt, SharedArrayBuffer, TypedArray] +---*/ + +function getReport() { + var r; + while ((r = $262.agent.getReport()) == null) { + $262.agent.sleep(10); + } + return r; +} + +$262.agent.start(` +$262.agent.receiveBroadcast(function(sab, id) { + var ia = new BigInt64Array(sab); + var then = Date.now(); + $262.agent.report(Atomics.wait(ia, 0, 0, 500)); // Timeout 500ms + $262.agent.report(Date.now() - then); // Actual time can be more than 500ms + $262.agent.leaving(); +}); +`); + +var ia = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT)); + +$262.agent.broadcast(ia.buffer); +assert.sameValue(getReport(), "timed-out"); +assert.sameValue((getReport() | 0) >= 500 - $ATOMICS_MAX_TIME_EPSILON, true); + diff --git a/test/built-ins/Atomics/wait/bigint/false-for-timeout-agent.js b/test/built-ins/Atomics/wait/bigint/false-for-timeout-agent.js new file mode 100644 index 0000000000..cc2d8a292d --- /dev/null +++ b/test/built-ins/Atomics/wait/bigint/false-for-timeout-agent.js @@ -0,0 +1,66 @@ +// Copyright (C) 2018 Amal Hussein. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.wait +description: > + False timeout arg should result in an +0 timeout +info: | + Atomics.wait( typedArray, index, value, timeout ) + + 4. Let q be ? ToNumber(timeout). + + Boolean -> If argument is true, return 1. If argument is false, return +0. + +features: [Atomics, BigInt, SharedArrayBuffer, TypedArray] +---*/ + +function getReport() { + var r; + while ((r = $262.agent.getReport()) == null) { + $262.agent.sleep(10); + } + return r; +} + +$262.agent.start(` +var valueOf = { + valueOf: function() { + return false; + } +}; + +var toPrimitive = { + [Symbol.toPrimitive]: function() { + return false; + } +}; + +$262.agent.receiveBroadcast(function(sab) { + var i64a = new BigInt64Array(sab); + var start = Date.now(); + $262.agent.report(Atomics.wait(i64a, 0, 0, false)); + $262.agent.report(Atomics.wait(i64a, 0, 0, valueOf)); + $262.agent.report(Atomics.wait(i64a, 0, 0, toPrimitive)); + $262.agent.report(Date.now() - start); + $262.agent.leaving(); +}); +`); + +var i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT)); + +$262.agent.broadcast(i64a.buffer); +$262.agent.sleep(150); + +assert.sameValue(getReport(), 'timed-out'); +assert.sameValue(getReport(), 'timed-out'); +assert.sameValue(getReport(), 'timed-out'); + +var timeDiffReport = getReport(); + +assert(timeDiffReport >= 0, 'timeout should be a min of 0ms'); + +assert(timeDiffReport <= $ATOMICS_MAX_TIME_EPSILON, 'timeout should be a max of $$ATOMICS_MAX_TIME_EPSILON'); + +assert.sameValue(Atomics.wake(i64a, 0), 0); + diff --git a/test/built-ins/Atomics/wait/bigint/false-for-timeout.js b/test/built-ins/Atomics/wait/bigint/false-for-timeout.js new file mode 100644 index 0000000000..6ca7a1df11 --- /dev/null +++ b/test/built-ins/Atomics/wait/bigint/false-for-timeout.js @@ -0,0 +1,37 @@ +// Copyright (C) 2018 Amal Hussein. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.wait +description: > + False timeout arg should result in an +0 timeout +info: | + Atomics.wait( typedArray, index, value, timeout ) + + 4. Let q be ? ToNumber(timeout). + + Boolean -> If argument is true, return 1. If argument is false, return +0. + +features: [Atomics, BigInt, computed-property-names, SharedArrayBuffer, Symbol, Symbol.toPrimitive, TypedArray] +flags: [CanBlockIsFalse] +---*/ + +var buffer = new SharedArrayBuffer(1024); +var i64a = new BigInt64Array(buffer); + +var valueOf = { + valueOf: function() { + return false; + } +}; + +var toPrimitive = { + [Symbol.toPrimitive]: function() { + return false; + } +}; + +assert.sameValue(Atomics.wait(i64a, 0, 0, false), "timed-out"); +assert.sameValue(Atomics.wait(i64a, 0, 0, valueOf), "timed-out"); +assert.sameValue(Atomics.wait(i64a, 0, 0, toPrimitive), "timed-out"); + diff --git a/test/built-ins/Atomics/wait/bigint/good-views.js b/test/built-ins/Atomics/wait/bigint/good-views.js new file mode 100644 index 0000000000..063d52ea82 --- /dev/null +++ b/test/built-ins/Atomics/wait/bigint/good-views.js @@ -0,0 +1,59 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.wait +description: > + Test Atomics.wait on arrays that allow atomic operations, + in an Agent that is allowed to wait. +features: [Atomics, BigInt] +---*/ + +// Let's assume 'wait' is not allowed on the main thread, +// even in the shell. + +$262.agent.start(` +var sab = new SharedArrayBuffer(1024); +var ab = new ArrayBuffer(16); + +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] = 0; +$262.agent.report("A " + Atomics.wait(view, 0, 0, 0)) +$262.agent.report("B " + Atomics.wait(view, 0, 37, 0)); + +// In-bounds boundary cases for indexing +for ( let IdxGen of good_indices ) { + let Idx = IdxGen(view); + view.fill(0); + // 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 " + Atomics.wait(view, Idx, 0)); +} + +$262.agent.report("done"); +$262.agent.leaving(); +`); + +assert.sameValue(getReport(), "A timed-out"); +assert.sameValue(getReport(), "B not-equal"); // Even with zero timeout +var r; +while ((r = getReport()) != "done") { + assert.sameValue(r, "C not-equal"); +} + +function getReport() { + var r; + while ((r = $262.agent.getReport()) == null) { + $262.agent.sleep(10); + } + return r; +} diff --git a/test/built-ins/Atomics/wait/bigint/nan-for-timeout.js b/test/built-ins/Atomics/wait/bigint/nan-for-timeout.js new file mode 100644 index 0000000000..2ff89fe540 --- /dev/null +++ b/test/built-ins/Atomics/wait/bigint/nan-for-timeout.js @@ -0,0 +1,42 @@ +// Copyright (C) 2018 Amal Hussein. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.wait +description: > + NaN timeout arg should result in an infinite timeout +info: | + Atomics.wait( typedArray, index, value, timeout ) + + 4.Let q be ? ToNumber(timeout). + ... + Undefined Return NaN. + 5.If q is NaN, let t be +∞, else let t be max(q, 0) + +features: [Atomics, BigInt, SharedArrayBuffer, TypedArray] +---*/ + +function getReport() { + var r; + while ((r = $262.agent.getReport()) == null) { + $262.agent.sleep(10); + } + return r; +} + +$262.agent.start( + ` +$262.agent.receiveBroadcast(function(sab) { + var i64a = new BigInt64Array(sab); + $262.agent.report(Atomics.wait(i64a, 0, 0, NaN)); // NaN => +Infinity + $262.agent.leaving(); +}); +`); + +var i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT)); + +$262.agent.broadcast(i64a.buffer); +$262.agent.sleep(500); // Ample time + +assert.sameValue(Atomics.wake(i64a, 0), 1); +assert.sameValue(getReport(), "ok"); diff --git a/test/built-ins/Atomics/wait/bigint/negative-index-throws.js b/test/built-ins/Atomics/wait/bigint/negative-index-throws.js new file mode 100644 index 0000000000..d3871ce5de --- /dev/null +++ b/test/built-ins/Atomics/wait/bigint/negative-index-throws.js @@ -0,0 +1,38 @@ +// Copyright (C) 2018 Amal Hussein. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.wait +description: > + Throws a RangeError is index < 0 +info: | + Atomics.wait( typedArray, index, value, timeout ) + + 2.Let i be ? ValidateAtomicAccess(typedArray, index). + ... + 2.Let accessIndex be ? ToIndex(requestIndex). + ... + 2.b If integerIndex < 0, throw a RangeError exception +features: [Atomics, BigInt, SharedArrayBuffer, TypedArray] +---*/ + +var sab = new SharedArrayBuffer(1024); +var i64a = new BigInt64Array(sab); +var poisoned = { + valueOf: function() { + throw new Test262Error("should not evaluate this code"); + } +}; + +assert.throws(RangeError, function() { + Atomics.wait(i64a, -Infinity, poisoned, poisoned); +}); +assert.throws(RangeError, function() { + Atomics.wait(i64a, -7.999, poisoned, poisoned); +}); +assert.throws(RangeError, function() { + Atomics.wait(i64a, -1, poisoned, poisoned); +}); +assert.throws(RangeError, function() { + Atomics.wait(i64a, -300, poisoned, poisoned); +}); diff --git a/test/built-ins/Atomics/wait/bigint/negative-timeout-agent.js b/test/built-ins/Atomics/wait/bigint/negative-timeout-agent.js new file mode 100644 index 0000000000..ed8d10f020 --- /dev/null +++ b/test/built-ins/Atomics/wait/bigint/negative-timeout-agent.js @@ -0,0 +1,32 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.wait +description: > + Test that Atomics.wait times out with a negative timeout +features: [Atomics, BigInt, SharedArrayBuffer, TypedArray] +---*/ + +function getReport() { + var r; + while ((r = $262.agent.getReport()) == null) { + $262.agent.sleep(10); + } + return r; +} + +$262.agent.start(` +$262.agent.receiveBroadcast(function(sab, id) { + var ia = new BigInt64Array(sab); + $262.agent.report(Atomics.wait(ia, 0, 0, -5)); // -5 => 0 + $262.agent.leaving(); +}); +`); + +var buffer = new SharedArrayBuffer(1024); +var i64a = new BigInt64Array(buffer); + +$262.agent.broadcast(i64a.buffer); +assert.sameValue(getReport(), "timed-out"); +assert.sameValue(Atomics.wake(i64a, 0), 0); diff --git a/test/built-ins/Atomics/wait/bigint/negative-timeout.js b/test/built-ins/Atomics/wait/bigint/negative-timeout.js new file mode 100644 index 0000000000..f0838f673e --- /dev/null +++ b/test/built-ins/Atomics/wait/bigint/negative-timeout.js @@ -0,0 +1,15 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.wait +description: > + Test that Atomics.wait times out with a negative timeout +features: [Atomics, BigInt, SharedArrayBuffer, TypedArray] +flags: [CanBlockIsFalse] +---*/ + +var buffer = new SharedArrayBuffer(1024); +var i64a = new BigInt64Array(buffer); + +assert.sameValue(Atomics.wait(i64a, 0, 0, -1), "timed-out"); diff --git a/test/built-ins/Atomics/wait/no-spurious-wakeup.js b/test/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-store-padded-time.js similarity index 77% rename from test/built-ins/Atomics/wait/no-spurious-wakeup.js rename to test/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-store-padded-time.js index a504fd5bde..5a6461d36c 100644 --- a/test/built-ins/Atomics/wait/no-spurious-wakeup.js +++ b/test/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-store-padded-time.js @@ -1,4 +1,4 @@ -// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// Copyright (C) 2018 Rick Waldron. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- @@ -10,10 +10,9 @@ includes: [atomicsHelper.js] features: [Atomics, SharedArrayBuffer, TypedArray] ---*/ -$262.agent.start( -` -$262.agent.receiveBroadcast(function (sab, id) { - var ia = new Int32Array(sab); +$262.agent.start(` +$262.agent.receiveBroadcast(function(sab, id) { + var ia = new BigInt64Array(sab); var then = Date.now(); Atomics.wait(ia, 0, 0); var diff = Date.now() - then; // Should be about 1000 ms but can be more @@ -22,7 +21,7 @@ $262.agent.receiveBroadcast(function (sab, id) { }) `); -var ia = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)); +var ia = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT)); $262.agent.broadcast(ia.buffer); $262.agent.sleep(500); // Give the agent a chance to wait @@ -34,7 +33,7 @@ assert.sameValue((getReport() | 0) >= 1000 - $ATOMICS_MAX_TIME_EPSILON, true); function getReport() { var r; while ((r = $262.agent.getReport()) == null) { - $262.agent.sleep(100); + $262.agent.sleep(10); } return r; } diff --git a/test/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-store.js b/test/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-store.js new file mode 100644 index 0000000000..5c43128336 --- /dev/null +++ b/test/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-store.js @@ -0,0 +1,50 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.wait +description: > + Demonstrates that Atomics.store(...) is causing a waiting +features: [Atomics, computed-property-names, SharedArrayBuffer, TypedArray] +---*/ +function getReport() { + var r; + while ((r = $262.agent.getReport()) == null) { + $262.agent.sleep(10); + } + return r; +} + +const TWO_SECOND_TIMEOUT = 2000; +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT) +); + +$262.agent.start(` + $262.agent.receiveBroadcast(function(sab) { + var i64a = new BigInt64Array(sab); + var before = Date.now(); + $262.agent.report("ready"); + Atomics.wait(i64a, 0, 0, ${TWO_SECOND_TIMEOUT}); + $262.agent.report(Date.now() - before); + $262.agent.leaving(); + }); +`); + +$262.agent.broadcast(i64a.buffer); + +assert.sameValue(getReport(), "ready"); + +Atomics.store(i64a, 0, 0x111111); + +// We should expect that the waiting agents will continue to +// wait until they both timeout. If either of them reports +// a value that is less than the timeout value, it may mean that +// calling Atomics.store(...) is causing the agents to wake. +// +var lapse = getReport(); + +assert( + lapse >= TWO_SECOND_TIMEOUT, + `${lapse} should be at least ${TWO_SECOND_TIMEOUT}` +); diff --git a/test/built-ins/Atomics/wait/bigint/non-bigint64-typedarray-throws.js b/test/built-ins/Atomics/wait/bigint/non-bigint64-typedarray-throws.js new file mode 100644 index 0000000000..dfcc193b22 --- /dev/null +++ b/test/built-ins/Atomics/wait/bigint/non-bigint64-typedarray-throws.js @@ -0,0 +1,28 @@ +// Copyright (C) 2018 Amal Hussein. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.wait +description: > + Throws a TypeError if typedArray arg is not an BigInt64Array +info: | + Atomics.wait( typedArray, index, value, timeout ) + + 1.Let buffer be ? ValidateSharedIntegerTypedArray(typedArray, true). + ... + 5.If onlyInt32 is true, then + If typeName is not "Int32Array" or "BigInt64Array", throw a TypeError exception. +features: [Atomics, Float32Array, Float64Array, Int8Array, TypedArray, Uint16Array, Uint8Array, Uint8ClampedArray] +includes: [testAtomics.js, testBigIntTypedArray.js] +---*/ + +var poisoned = { + valueOf: function() { + throw new Test262Error("should not evaluate this code"); + } +}; + +assert.throws(TypeError, function() { + Atomics.wait(new BigUint64Array(), poisoned, poisoned, poisoned); +}, 'BigUint64Array'); + diff --git a/test/built-ins/Atomics/wait/bigint/non-shared-bufferdata-throws.js b/test/built-ins/Atomics/wait/bigint/non-shared-bufferdata-throws.js new file mode 100644 index 0000000000..9322fff966 --- /dev/null +++ b/test/built-ins/Atomics/wait/bigint/non-shared-bufferdata-throws.js @@ -0,0 +1,32 @@ +// Copyright (C) 2018 Amal Hussein. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-atomics.wait +description: > + Throws a TypeError if typedArray.buffer is not a SharedArrayBuffer +info: | + Atomics.wait( typedArray, index, value, timeout ) + + 1.Let buffer be ? ValidateSharedIntegerTypedArray(typedArray, true). + ... + 9.If IsSharedArrayBuffer(buffer) is false, throw a TypeError exception. + ... + 4.If bufferData is a Data Block, return false. +features: [ArrayBuffer, Atomics, TypedArray] +includes: [testAtomics.js, testBigIntTypedArray.js] +---*/ + +var i64a = new BigInt64Array(new ArrayBuffer(4)); +var poisoned = { + valueOf: function() { + throw new Test262Error("should not evaluate this code"); + } +}; + +assert.throws(TypeError, function() { + Atomics.wait(i64a, 0, 0, 0); +}); + +assert.throws(TypeError, function() { + Atomics.wait(i64a, poisoned, poisoned, poisoned); +}); diff --git a/test/built-ins/Atomics/wait/bigint/null-bufferdata-throws.js b/test/built-ins/Atomics/wait/bigint/null-bufferdata-throws.js new file mode 100644 index 0000000000..cf640b2910 --- /dev/null +++ b/test/built-ins/Atomics/wait/bigint/null-bufferdata-throws.js @@ -0,0 +1,30 @@ +// Copyright (C) 2018 Amal Hussein. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-atomics.wait +description: > + A null value for bufferData throws a TypeError +info: | + Atomics.wait( typedArray, index, value, timeout ) + + 1.Let buffer be ? ValidateSharedIntegerTypedArray(typedArray, true). + ... + 9.If IsSharedArrayBuffer(buffer) is false, throw a TypeError exception. + ... + 3.If bufferData is null, return false. +includes: [detachArrayBuffer.js] +features: [ArrayBuffer, BigInt, Atomics, TypedArray] +---*/ + +var i64a = new BigInt64Array(new ArrayBuffer(1024)); +var poisoned = { + valueOf: function() { + throw new Test262Error("should not evaluate this code"); + } +}; + +$DETACHBUFFER(i64a.buffer); // Detaching a non-shared ArrayBuffer sets the [[ArrayBufferData]] value to null + +assert.throws(TypeError, function() { + Atomics.wait(i64a, poisoned, poisoned, poisoned); +}); diff --git a/test/built-ins/Atomics/wait/bigint/out-of-range-index-throws.js b/test/built-ins/Atomics/wait/bigint/out-of-range-index-throws.js new file mode 100644 index 0000000000..e325592fa1 --- /dev/null +++ b/test/built-ins/Atomics/wait/bigint/out-of-range-index-throws.js @@ -0,0 +1,35 @@ +// Copyright (C) 2018 Amal Hussein. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.wait +description: > + Throws a RangeError if value of index arg is out of range +info: | + Atomics.wait( 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, BigInt, SharedArrayBuffer, TypedArray] +---*/ + +var i64a = new BigInt64Array(new SharedArrayBuffer(4)); + +var poisoned = { + valueOf: function() { + throw new Test262Error("should not evaluate this code"); + } +}; + +assert.throws(RangeError, function() { + Atomics.wait(i64a, Infinity, poisoned, poisoned); +}); +assert.throws(RangeError, function() { + Atomics.wait(i64a, 2, poisoned, poisoned); +}); +assert.throws(RangeError, function() { + Atomics.wait(i64a, 200, poisoned, poisoned); +}); diff --git a/test/built-ins/Atomics/wait/bigint/value-not-equal.js b/test/built-ins/Atomics/wait/bigint/value-not-equal.js new file mode 100644 index 0000000000..9e41c30404 --- /dev/null +++ b/test/built-ins/Atomics/wait/bigint/value-not-equal.js @@ -0,0 +1,47 @@ +// Copyright (C) 2018 Amal Hussein. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.wait +description: > + Returns "not-equal" when value arg does not match an index in the typedArray +info: | + Atomics.wait( typedArray, index, value, timeout ) + + 3.Let v be ? ToInt32(value). + ... + 14.If v is not equal to w, then + a.Perform LeaveCriticalSection(WL). + b. Return the String "not-equal". + +features: [Atomics, SharedArrayBuffer, TypedArray] +includes: [atomicsHelper.js, testBigIntTypedArray.js] +---*/ + +function getReport() { + var r; + while ((r = $262.agent.getReport()) == null) { + $262.agent.sleep(10); + } + return r; +} + +var value = 42; + +$262.agent.start(` +$262.agent.receiveBroadcast(function(sab) { + var i64a = new BigInt64Array(sab); + + $262.agent.report(Atomics.store(i64a, 0, ${value})); + $262.agent.report(Atomics.wait(i64a, 0, 0)); + $262.agent.leaving(); +}); +`); + +var i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT)); + +$262.agent.broadcast(i64a.buffer); + +assert.sameValue(getReport(), value.toString()); +assert.sameValue(getReport(), "not-equal"); + diff --git a/test/built-ins/Atomics/wait/bigint/waiterlist-block-indexedposition-wake.js b/test/built-ins/Atomics/wait/bigint/waiterlist-block-indexedposition-wake.js new file mode 100644 index 0000000000..8f8c396e9b --- /dev/null +++ b/test/built-ins/Atomics/wait/bigint/waiterlist-block-indexedposition-wake.js @@ -0,0 +1,62 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.wait +description: > + Get the correct WaiterList +info: | + Atomics.wait( typedArray, index, value, timeout ) + + ... + 11. Let WL be GetWaiterList(block, indexedPosition). + ... + + + GetWaiterList( block, i ) + + ... + 4. Return the WaiterList that is referenced by the pair (block, i). + +features: [Atomics, BigInt, SharedArrayBuffer, TypedArray] +---*/ +function getReport() { + var r; + while ((r = $262.agent.getReport()) == null) { + $262.agent.sleep(10); + } + return r; +} + +$262.agent.start(` +$262.agent.receiveBroadcast(function(sab) { + var i64a = new BigInt64Array(sab); + + // Wait on index 0 + Atomics.wait(i64a, 0, 0, 200); + $262.agent.report("fail"); + $262.agent.leaving(); +}); +`); + +$262.agent.start(` +$262.agent.receiveBroadcast(function(sab) { + var i64a = new BigInt64Array(sab); + + // Wait on index 2 + Atomics.wait(i64a, 2, 0, 200); + $262.agent.report("pass"); + $262.agent.leaving(); +}); +`); + +var length = 4 * BigInt64Array.BYTES_PER_ELEMENT; +var i64a = new BigInt64Array(new SharedArrayBuffer(length)); + +$262.agent.broadcast(i64a.buffer); +$262.agent.sleep(10); + +// Wake index 2 +Atomics.wake(i64a, 2, 1); + +assert.sameValue(getReport(), "pass"); diff --git a/test/built-ins/Atomics/wait/bigint/waiterlist-order-of-operations-is-fifo.js b/test/built-ins/Atomics/wait/bigint/waiterlist-order-of-operations-is-fifo.js new file mode 100644 index 0000000000..ae7b4fa1ff --- /dev/null +++ b/test/built-ins/Atomics/wait/bigint/waiterlist-order-of-operations-is-fifo.js @@ -0,0 +1,89 @@ +// Copyright (C) 2018 Amal Hussein. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.wait +description: > + New waiters should be applied to the end of the list and woken by order they entered the list (FIFO) +info: | + Atomics.wait( typedArray, index, value, timeout ) + + 16.Perform AddWaiter(WL, W). + ... + 3.Add W to the end of the list of waiters in WL. + +features: [Atomics, BigInt, SharedArrayBuffer, TypedArray] +---*/ + +function getReport() { + var r; + while ((r = $262.agent.getReport()) == null) { + $262.agent.sleep(10); + } + return r; +} + +var agent1 = '1'; +var agent2 = '2'; +var agent3 = '3'; + +$262.agent.start(` +$262.agent.receiveBroadcast(function(sab) { + var i64a = new BigInt64Array(sab); + + $262.agent.report(${agent1}); + Atomics.wait(i64a, 0, 0); + $262.agent.report(${agent1}); + + $262.agent.leaving(); +}) +`); + +$262.agent.start( + ` +$262.agent.receiveBroadcast(function(sab) { + var i64a = new BigInt64Array(sab); + + $262.agent.report(${agent2}); + + Atomics.wait(i64a, 0, 0); + $262.agent.report(${agent2}); + + $262.agent.leaving(); +}) +`); + +$262.agent.start( + ` +$262.agent.receiveBroadcast(function(sab) { + var i64a = new BigInt64Array(sab); + + $262.agent.report(${agent3}); + + Atomics.wait(i64a, 0, 0); + $262.agent.report(${agent3}); + + $262.agent.leaving(); +}) +`); + + +var i64a = new BigInt64Array(new SharedArrayBuffer(4)); + +$262.agent.broadcast(i64a.buffer); + +var orderWhichAgentsWereStarted = getReport() + getReport() + getReport(); // can be started in any order + +assert.sameValue(Atomics.wake(i64a, 0, 1), 1); + +var orderAgentsWereWoken = getReport(); + +assert.sameValue(Atomics.wake(i64a, 0, 1), 1); + +orderAgentsWereWoken += getReport(); + +assert.sameValue(Atomics.wake(i64a, 0, 1), 1); + +orderAgentsWereWoken += getReport(); + +assert.sameValue(orderWhichAgentsWereStarted, orderAgentsWereWoken); // agents should wake in the same order as they were started FIFO diff --git a/test/built-ins/Atomics/wait/bigint/was-woken-before-timeout.js b/test/built-ins/Atomics/wait/bigint/was-woken-before-timeout.js new file mode 100644 index 0000000000..fd452d1bd8 --- /dev/null +++ b/test/built-ins/Atomics/wait/bigint/was-woken-before-timeout.js @@ -0,0 +1,55 @@ +// Copyright (C) 2018 Amal Hussein. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-atomics.wait +description: > + Test that Atomics.wait returns the right result when it was awoken before + a timeout +info: | + Atomics.wait( 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. +features: [Atomics, BigInt, SharedArrayBuffer, TypedArray] +---*/ + +var sleeping = 10; +var timeout = 20000; + +function getReport() { + var r; + while ((r = $262.agent.getReport()) == null) { + sleeping += 10; + $262.agent.sleep(10); + } + return r; +} + +$262.agent.start(` +$262.agent.receiveBroadcast(function(sab) { + var i64a = new BigInt64Array(sab); + $262.agent.report(Atomics.wait(i64a, 0, 0, ${timeout})); + $262.agent.leaving(); +}); +`); + +var sab = new SharedArrayBuffer(4); +var i64a = new BigInt64Array(sab); + + +$262.agent.broadcast(i64a.buffer); +$262.agent.sleep(sleeping); + +assert.sameValue(Atomics.wake(i64a, 0), 1); + +assert.sameValue(getReport(), "ok"); +assert(sleeping < timeout, "this test assumes it won't last for more than 20 seconds"); + diff --git a/test/built-ins/Atomics/wait/bigint/was-woken.js b/test/built-ins/Atomics/wait/bigint/was-woken.js new file mode 100644 index 0000000000..2d4f20577e --- /dev/null +++ b/test/built-ins/Atomics/wait/bigint/was-woken.js @@ -0,0 +1,33 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.wait +description: > + Test that Atomics.wait returns the right result when it was awoken. +features: [Atomics, SharedArrayBuffer, TypedArray] +includes: [testAtomics.js, testBigIntTypedArray.js] +---*/ + +function getReport() { + var r; + while ((r = $262.agent.getReport()) == null) { + $262.agent.sleep(10); + } + return r; +} + +$262.agent.start(` +$262.agent.receiveBroadcast(function(sab, id) { + var i64a = new BigInt64Array(sab); + $262.agent.report(Atomics.wait(i64a, 0, 0)); // No timeout => Infinity + $262.agent.leaving(); +}); +`); + +var i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT)); + +$262.agent.broadcast(i64a.buffer); +$262.agent.sleep(50); // Give the agent a chance to wait +Atomics.wake(i64a, 0); +assert.sameValue(getReport(), "ok"); diff --git a/test/built-ins/Atomics/wait/cannot-suspend-throws.js b/test/built-ins/Atomics/wait/cannot-suspend-throws.js index 30fc2d1f06..dc34bde85a 100644 --- a/test/built-ins/Atomics/wait/cannot-suspend-throws.js +++ b/test/built-ins/Atomics/wait/cannot-suspend-throws.js @@ -19,8 +19,8 @@ flags: [CanBlockIsFalse] ---*/ var buffer = new SharedArrayBuffer(4); -var int32Array = new Int32Array(buffer); +var i32a = new Int32Array(buffer); assert.throws(TypeError, function() { - Atomics.wait(int32Array, 0, 0, 0); + Atomics.wait(i32a, 0, 0, 0); }); diff --git a/test/built-ins/Atomics/wait/did-timeout.js b/test/built-ins/Atomics/wait/did-timeout.js index a647bb6486..82c1f1beb1 100644 --- a/test/built-ins/Atomics/wait/did-timeout.js +++ b/test/built-ins/Atomics/wait/did-timeout.js @@ -19,25 +19,24 @@ features: [Atomics, SharedArrayBuffer, TypedArray] function getReport() { var r; while ((r = $262.agent.getReport()) == null) { - $262.agent.sleep(100); + $262.agent.sleep(10); } return r; } -$262.agent.start( -` -$262.agent.receiveBroadcast(function (sab, id) { - var ia = new Int32Array(sab); +$262.agent.start(` +$262.agent.receiveBroadcast(function(sab, id) { + var i32a = new Int32Array(sab); var then = Date.now(); - $262.agent.report(Atomics.wait(ia, 0, 0, 500)); // Timeout 500ms + $262.agent.report(Atomics.wait(i32a, 0, 0, 500)); // Timeout 500ms $262.agent.report(Date.now() - then); // Actual time can be more than 500ms $262.agent.leaving(); }) `); -var ia = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)); +var i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)); -$262.agent.broadcast(ia.buffer); +$262.agent.broadcast(i32a.buffer); assert.sameValue(getReport(), "timed-out"); assert.sameValue((getReport() | 0) >= 500 - $ATOMICS_MAX_TIME_EPSILON, true); diff --git a/test/built-ins/Atomics/wait/false-for-timeout-agent.js b/test/built-ins/Atomics/wait/false-for-timeout-agent.js index c88b4900d0..d54e57cf45 100644 --- a/test/built-ins/Atomics/wait/false-for-timeout-agent.js +++ b/test/built-ins/Atomics/wait/false-for-timeout-agent.js @@ -19,7 +19,7 @@ includes: [ atomicsHelper.js ] function getReport() { var r; while ((r = $262.agent.getReport()) == null) { - $262.agent.sleep(100); + $262.agent.sleep(10); } return r; } @@ -38,20 +38,20 @@ var toPrimitive = { } }; -$262.agent.receiveBroadcast(function (sab) { - var int32Array = new Int32Array(sab); +$262.agent.receiveBroadcast(function(sab) { + var i32a = new Int32Array(sab); var start = Date.now(); - $262.agent.report(Atomics.wait(int32Array, 0, 0, false)); - $262.agent.report(Atomics.wait(int32Array, 0, 0, valueOf)); - $262.agent.report(Atomics.wait(int32Array, 0, 0, toPrimitive)); + $262.agent.report(Atomics.wait(i32a, 0, 0, false)); + $262.agent.report(Atomics.wait(i32a, 0, 0, valueOf)); + $262.agent.report(Atomics.wait(i32a, 0, 0, toPrimitive)); $262.agent.report(Date.now() - start); $262.agent.leaving(); }) `); -var int32Array = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)); +var i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)); -$262.agent.broadcast(int32Array.buffer); +$262.agent.broadcast(i32a.buffer); $262.agent.sleep(150); assert.sameValue(getReport(), 'timed-out'); @@ -64,5 +64,5 @@ assert(timeDiffReport >= 0, 'timeout should be a min of 0ms'); assert(timeDiffReport <= $ATOMICS_MAX_TIME_EPSILON, 'timeout should be a max of $$ATOMICS_MAX_TIME_EPSILON'); -assert.sameValue(Atomics.wake(int32Array, 0), 0); +assert.sameValue(Atomics.wake(i32a, 0), 0); diff --git a/test/built-ins/Atomics/wait/false-for-timeout.js b/test/built-ins/Atomics/wait/false-for-timeout.js index 72f234baab..c33ac86270 100644 --- a/test/built-ins/Atomics/wait/false-for-timeout.js +++ b/test/built-ins/Atomics/wait/false-for-timeout.js @@ -17,7 +17,7 @@ flags: [CanBlockIsFalse] ---*/ var buffer = new SharedArrayBuffer(1024); -var int32Array = new Int32Array(buffer); +var i32a = new Int32Array(buffer); var valueOf = { valueOf: function() { @@ -31,7 +31,7 @@ var toPrimitive = { } }; -assert.sameValue(Atomics.wait(int32Array, 0, 0, false), "timed-out"); -assert.sameValue(Atomics.wait(int32Array, 0, 0, valueOf), "timed-out"); -assert.sameValue(Atomics.wait(int32Array, 0, 0, toPrimitive), "timed-out"); +assert.sameValue(Atomics.wait(i32a, 0, 0, false), "timed-out"); +assert.sameValue(Atomics.wait(i32a, 0, 0, valueOf), "timed-out"); +assert.sameValue(Atomics.wait(i32a, 0, 0, toPrimitive), "timed-out"); diff --git a/test/built-ins/Atomics/wait/good-views.js b/test/built-ins/Atomics/wait/good-views.js index bf9fd6b508..efbaa86950 100644 --- a/test/built-ins/Atomics/wait/good-views.js +++ b/test/built-ins/Atomics/wait/good-views.js @@ -12,8 +12,7 @@ features: [Atomics] // Let's assume 'wait' is not allowed on the main thread, // even in the shell. -$262.agent.start( -` +$262.agent.start(` var sab = new SharedArrayBuffer(1024); var ab = new ArrayBuffer(16); @@ -54,7 +53,7 @@ while ((r = getReport()) != "done") { function getReport() { var r; while ((r = $262.agent.getReport()) == null) { - $262.agent.sleep(100); + $262.agent.sleep(10); } return r; } diff --git a/test/built-ins/Atomics/wait/nan-for-timeout.js b/test/built-ins/Atomics/wait/nan-for-timeout.js index a9026163bc..dc9f8d7b6b 100644 --- a/test/built-ins/Atomics/wait/nan-for-timeout.js +++ b/test/built-ins/Atomics/wait/nan-for-timeout.js @@ -19,24 +19,24 @@ features: [Atomics, SharedArrayBuffer, TypedArray] function getReport() { var r; while ((r = $262.agent.getReport()) == null) { - $262.agent.sleep(100); + $262.agent.sleep(10); } return r; } $262.agent.start( ` -$262.agent.receiveBroadcast(function (sab) { - var int32Array = new Int32Array(sab); - $262.agent.report(Atomics.wait(int32Array, 0, 0, NaN)); // NaN => +Infinity +$262.agent.receiveBroadcast(function(sab) { + var i32a = new Int32Array(sab); + $262.agent.report(Atomics.wait(i32a, 0, 0, NaN)); // NaN => +Infinity $262.agent.leaving(); }) `); -var int32Array = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)); +var i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)); -$262.agent.broadcast(int32Array.buffer); +$262.agent.broadcast(i32a.buffer); $262.agent.sleep(500); // Ample time -assert.sameValue(Atomics.wake(int32Array, 0), 1); +assert.sameValue(Atomics.wake(i32a, 0), 1); assert.sameValue(getReport(), "ok"); diff --git a/test/built-ins/Atomics/wait/negative-index-throws.js b/test/built-ins/Atomics/wait/negative-index-throws.js index baba9e0394..6b72e73417 100644 --- a/test/built-ins/Atomics/wait/negative-index-throws.js +++ b/test/built-ins/Atomics/wait/negative-index-throws.js @@ -17,7 +17,7 @@ features: [Atomics, SharedArrayBuffer, TypedArray] ---*/ var sab = new SharedArrayBuffer(1024); -var int32Array = new Int32Array(sab); +var i32a = new Int32Array(sab); var poisoned = { valueOf: function() { throw new Test262Error("should not evaluate this code"); @@ -25,14 +25,14 @@ var poisoned = { }; assert.throws(RangeError, function() { - Atomics.wait(int32Array, -Infinity, poisoned, poisoned); + Atomics.wait(i32a, -Infinity, poisoned, poisoned); }); assert.throws(RangeError, function() { - Atomics.wait(int32Array, -7.999, poisoned, poisoned); + Atomics.wait(i32a, -7.999, poisoned, poisoned); }); assert.throws(RangeError, function() { - Atomics.wait(int32Array, -1, poisoned, poisoned); + Atomics.wait(i32a, -1, poisoned, poisoned); }); assert.throws(RangeError, function() { - Atomics.wait(int32Array, -300, poisoned, poisoned); + Atomics.wait(i32a, -300, poisoned, poisoned); }); diff --git a/test/built-ins/Atomics/wait/negative-timeout-agent.js b/test/built-ins/Atomics/wait/negative-timeout-agent.js index a5dd786680..92199fad5a 100644 --- a/test/built-ins/Atomics/wait/negative-timeout-agent.js +++ b/test/built-ins/Atomics/wait/negative-timeout-agent.js @@ -11,13 +11,12 @@ features: [Atomics, SharedArrayBuffer, TypedArray] function getReport() { var r; while ((r = $262.agent.getReport()) == null) { - $262.agent.sleep(100); + $262.agent.sleep(10); } return r; } -$262.agent.start( -` +$262.agent.start(` $262.agent.receiveBroadcast(function(sab, id) { var ia = new Int32Array(sab); $262.agent.report(Atomics.wait(ia, 0, 0, -5)); // -5 => 0 @@ -26,8 +25,8 @@ $262.agent.receiveBroadcast(function(sab, id) { `); var buffer = new SharedArrayBuffer(1024); -var int32Array = new Int32Array(buffer); +var i32a = new Int32Array(buffer); -$262.agent.broadcast(int32Array.buffer); +$262.agent.broadcast(i32a.buffer); assert.sameValue(getReport(), "timed-out"); -assert.sameValue(Atomics.wake(int32Array, 0), 0); +assert.sameValue(Atomics.wake(i32a, 0), 0); diff --git a/test/built-ins/Atomics/wait/negative-timeout.js b/test/built-ins/Atomics/wait/negative-timeout.js index 46961c5be2..019ca1db96 100644 --- a/test/built-ins/Atomics/wait/negative-timeout.js +++ b/test/built-ins/Atomics/wait/negative-timeout.js @@ -10,6 +10,6 @@ flags: [CanBlockIsFalse] ---*/ var buffer = new SharedArrayBuffer(1024); -var int32Array = new Int32Array(buffer); +var i32a = new Int32Array(buffer); -assert.sameValue(Atomics.wait(int32Array, 0, 0, -1), "timed-out"); +assert.sameValue(Atomics.wait(i32a, 0, 0, -1), "timed-out"); diff --git a/test/built-ins/Atomics/wait/no-spurious-wakeup-on-add.js b/test/built-ins/Atomics/wait/no-spurious-wakeup-on-add.js new file mode 100644 index 0000000000..ff2869f3e0 --- /dev/null +++ b/test/built-ins/Atomics/wait/no-spurious-wakeup-on-add.js @@ -0,0 +1,52 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.wait +description: > + Demonstrates that Atomics.store(...) is causing a waiting +features: [Atomics, computed-property-names, SharedArrayBuffer, TypedArray] +---*/ +function getReport() { + var r; + while ((r = $262.agent.getReport()) == null) { + $262.agent.sleep(10); + } + return r; +} + +const TWO_SECOND_TIMEOUT = 2000; +const i32 = new Int32Array( + new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT) +); + +$262.agent.start(` + $262.agent.receiveBroadcast(function(sab) { + var i32 = new Int32Array(sab); + var before = Date.now(); + $262.agent.report("ready"); + Atomics.wait(i32, 0, 0, ${TWO_SECOND_TIMEOUT}); + $262.agent.report(Date.now() - before); + $262.agent.leaving(); + }); +`); + +$262.agent.broadcast(i32.buffer); + +assert.sameValue(getReport(), "ready"); + +Atomics.add(i32, 0, 1); + +// We should expect that the waiting agents will continue to +// wait until they both timeout. If either of them reports +// a value that is less than the timeout value, it may mean that +// calling Atomics.store(...) is causing the agents to wake. +// +var lapse = getReport(); + +assert( + lapse >= TWO_SECOND_TIMEOUT, + `${lapse} should be at least ${TWO_SECOND_TIMEOUT}` +); + + diff --git a/test/built-ins/Atomics/wait/no-spurious-wakeup-on-store-padded-time.js b/test/built-ins/Atomics/wait/no-spurious-wakeup-on-store-padded-time.js new file mode 100644 index 0000000000..cc538140dd --- /dev/null +++ b/test/built-ins/Atomics/wait/no-spurious-wakeup-on-store-padded-time.js @@ -0,0 +1,39 @@ +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.wait +description: > + Test that Atomics.wait actually waits and does not spuriously wake + up when the memory value is changed. +includes: [atomicsHelper.js] +features: [Atomics, SharedArrayBuffer, TypedArray] +---*/ + +$262.agent.start(` +$262.agent.receiveBroadcast(function(sab, id) { + var i32a = new Int32Array(sab); + var then = Date.now(); + Atomics.wait(i32a, 0, 0); + var diff = Date.now() - then; // Should be about 1000 ms but can be more + $262.agent.report(diff); + $262.agent.leaving(); +}) +`); + +var i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)); + +$262.agent.broadcast(i32a.buffer); +$262.agent.sleep(500); // Give the agent a chance to wait +Atomics.store(i32a, 0, 1); // Change the value, should not wake the agent +$262.agent.sleep(500); // Wait some more so that we can tell +Atomics.wake(i32a, 0); // Really wake it up +assert.sameValue((getReport() | 0) >= 1000 - $ATOMICS_MAX_TIME_EPSILON, true); + +function getReport() { + var r; + while ((r = $262.agent.getReport()) == null) { + $262.agent.sleep(10); + } + return r; +} diff --git a/test/built-ins/Atomics/wait/no-spurious-wakeup-on-store.js b/test/built-ins/Atomics/wait/no-spurious-wakeup-on-store.js new file mode 100644 index 0000000000..b89556dfe5 --- /dev/null +++ b/test/built-ins/Atomics/wait/no-spurious-wakeup-on-store.js @@ -0,0 +1,52 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.wait +description: > + Demonstrates that Atomics.store(...) is causing a waiting +features: [Atomics, computed-property-names, SharedArrayBuffer, TypedArray] +---*/ +function getReport() { + var r; + while ((r = $262.agent.getReport()) == null) { + $262.agent.sleep(10); + } + return r; +} + +const TWO_SECOND_TIMEOUT = 2000; +const i32a = new Int32Array( + new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT) +); + +$262.agent.start(` + $262.agent.receiveBroadcast(function(sab) { + var i32a = new Int32Array(sab); + var before = Date.now(); + $262.agent.report("ready"); + Atomics.wait(i32a, 0, 0, ${TWO_SECOND_TIMEOUT}); + $262.agent.report(Date.now() - before); + $262.agent.leaving(); + }); +`); + +$262.agent.broadcast(i32a.buffer); + +assert.sameValue(getReport(), "ready"); + +Atomics.store(i32a, 0, 0x111111); + +// We should expect that the waiting agents will continue to +// wait until they both timeout. If either of them reports +// a value that is less than the timeout value, it may mean that +// calling Atomics.store(...) is causing the agents to wake. +// +var lapse = getReport(); + +assert( + lapse >= TWO_SECOND_TIMEOUT, + `${lapse} should be at least ${TWO_SECOND_TIMEOUT}` +); + + diff --git a/test/built-ins/Atomics/wait/non-shared-bufferdata-throws.js b/test/built-ins/Atomics/wait/non-shared-bufferdata-throws.js index d14ae2cf7b..3db334f895 100644 --- a/test/built-ins/Atomics/wait/non-shared-bufferdata-throws.js +++ b/test/built-ins/Atomics/wait/non-shared-bufferdata-throws.js @@ -15,7 +15,7 @@ info: | features: [ArrayBuffer, Atomics, TypedArray] ---*/ -var int32Array = new Int32Array(new ArrayBuffer(4)); +var i32a = new Int32Array(new ArrayBuffer(4)); var poisoned = { valueOf: function() { throw new Test262Error("should not evaluate this code"); @@ -23,9 +23,9 @@ var poisoned = { }; assert.throws(TypeError, function() { - Atomics.wait(int32Array, 0, 0, 0); + Atomics.wait(i32a, 0, 0, 0); }); assert.throws(TypeError, function() { - Atomics.wait(int32Array, poisoned, poisoned, poisoned); + Atomics.wait(i32a, poisoned, poisoned, poisoned); }); diff --git a/test/built-ins/Atomics/wait/null-bufferdata-throws.js b/test/built-ins/Atomics/wait/null-bufferdata-throws.js index 04c613397f..511ba811ae 100644 --- a/test/built-ins/Atomics/wait/null-bufferdata-throws.js +++ b/test/built-ins/Atomics/wait/null-bufferdata-throws.js @@ -16,15 +16,15 @@ includes: [detachArrayBuffer.js] features: [ArrayBuffer, Atomics, TypedArray] ---*/ -var int32Array = new Int32Array(new ArrayBuffer(1024)); +var i32a = new Int32Array(new ArrayBuffer(1024)); var poisoned = { valueOf: function() { throw new Test262Error("should not evaluate this code"); } }; -$DETACHBUFFER(int32Array.buffer); // Detaching a non-shared ArrayBuffer sets the [[ArrayBufferData]] value to null +$DETACHBUFFER(i32a.buffer); // Detaching a non-shared ArrayBuffer sets the [[ArrayBufferData]] value to null assert.throws(TypeError, function() { - Atomics.wait(int32Array, poisoned, poisoned, poisoned); + Atomics.wait(i32a, poisoned, poisoned, poisoned); }); diff --git a/test/built-ins/Atomics/wait/null-for-timeout-agent.js b/test/built-ins/Atomics/wait/null-for-timeout-agent.js index fd106e807e..c7d376f457 100644 --- a/test/built-ins/Atomics/wait/null-for-timeout-agent.js +++ b/test/built-ins/Atomics/wait/null-for-timeout-agent.js @@ -19,7 +19,7 @@ includes: [ atomicsHelper.js ] function getReport() { var r; while ((r = $262.agent.getReport()) == null) { - $262.agent.sleep(100); + $262.agent.sleep(10); } return r; } @@ -38,20 +38,20 @@ var toPrimitive = { } }; -$262.agent.receiveBroadcast(function (sab) { - var int32Array = new Int32Array(sab); +$262.agent.receiveBroadcast(function(sab) { + var i32a = new Int32Array(sab); var start = Date.now(); - $262.agent.report(Atomics.wait(int32Array, 0, 0, null)); - $262.agent.report(Atomics.wait(int32Array, 0, 0, valueOf)); - $262.agent.report(Atomics.wait(int32Array, 0, 0, toPrimitive)); + $262.agent.report(Atomics.wait(i32a, 0, 0, null)); + $262.agent.report(Atomics.wait(i32a, 0, 0, valueOf)); + $262.agent.report(Atomics.wait(i32a, 0, 0, toPrimitive)); $262.agent.report(Date.now() - start); $262.agent.leaving(); }) `); -var int32Array = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)); +var i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)); -$262.agent.broadcast(int32Array.buffer); +$262.agent.broadcast(i32a.buffer); $262.agent.sleep(150); assert.sameValue(getReport(), 'timed-out'); @@ -64,5 +64,5 @@ assert(timeDiffReport >= 0, 'timeout should be a min of 0ms'); assert(timeDiffReport <= $ATOMICS_MAX_TIME_EPSILON, 'timeout should be a max of $$ATOMICS_MAX_TIME_EPSILON'); -assert.sameValue(Atomics.wake(int32Array, 0), 0); +assert.sameValue(Atomics.wake(i32a, 0), 0); diff --git a/test/built-ins/Atomics/wait/null-for-timeout.js b/test/built-ins/Atomics/wait/null-for-timeout.js index 70de069ae1..354d29cc42 100644 --- a/test/built-ins/Atomics/wait/null-for-timeout.js +++ b/test/built-ins/Atomics/wait/null-for-timeout.js @@ -17,7 +17,7 @@ flags: [CanBlockIsFalse] ---*/ var buffer = new SharedArrayBuffer(1024); -var int32Array = new Int32Array(buffer); +var i32a = new Int32Array(buffer); var valueOf = { valueOf: function() { @@ -31,7 +31,7 @@ var toPrimitive = { } }; -assert.sameValue(Atomics.wait(int32Array, 0, 0, null), "timed-out"); -assert.sameValue(Atomics.wait(int32Array, 0, 0, valueOf), "timed-out"); -assert.sameValue(Atomics.wait(int32Array, 0, 0, toPrimitive), "timed-out"); +assert.sameValue(Atomics.wait(i32a, 0, 0, null), "timed-out"); +assert.sameValue(Atomics.wait(i32a, 0, 0, valueOf), "timed-out"); +assert.sameValue(Atomics.wait(i32a, 0, 0, toPrimitive), "timed-out"); diff --git a/test/built-ins/Atomics/wait/object-for-timeout-agent.js b/test/built-ins/Atomics/wait/object-for-timeout-agent.js index 7db064617a..cca80c08c2 100644 --- a/test/built-ins/Atomics/wait/object-for-timeout-agent.js +++ b/test/built-ins/Atomics/wait/object-for-timeout-agent.js @@ -19,7 +19,7 @@ includes: [ atomicsHelper.js ] function getReport() { var r; while ((r = $262.agent.getReport()) == null) { - $262.agent.sleep(100); + $262.agent.sleep(10); } return r; } @@ -45,20 +45,20 @@ var toPrimitive = { }; -$262.agent.receiveBroadcast(function (sab) { - var int32Array = new Int32Array(sab); +$262.agent.receiveBroadcast(function(sab) { + var i32a = new Int32Array(sab); var start = Date.now(); - $262.agent.report(Atomics.wait(int32Array, 0, 0, valueOf)); - $262.agent.report(Atomics.wait(int32Array, 0, 0, toString)); - $262.agent.report(Atomics.wait(int32Array, 0, 0, toPrimitive)); + $262.agent.report(Atomics.wait(i32a, 0, 0, valueOf)); + $262.agent.report(Atomics.wait(i32a, 0, 0, toString)); + $262.agent.report(Atomics.wait(i32a, 0, 0, toPrimitive)); $262.agent.report(Date.now() - start); $262.agent.leaving(); }) `); -var int32Array = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)); +var i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)); -$262.agent.broadcast(int32Array.buffer); +$262.agent.broadcast(i32a.buffer); $262.agent.sleep(150); assert.sameValue(getReport(), 'timed-out'); @@ -71,5 +71,5 @@ assert(timeDiffReport >= 0, 'timeout should be a min of 0ms'); assert(timeDiffReport <= $ATOMICS_MAX_TIME_EPSILON, 'timeout should be a max of $$ATOMICS_MAX_TIME_EPSILON'); -assert.sameValue(Atomics.wake(int32Array, 0), 0); +assert.sameValue(Atomics.wake(i32a, 0), 0); diff --git a/test/built-ins/Atomics/wait/object-for-timeout.js b/test/built-ins/Atomics/wait/object-for-timeout.js index 3fc07cc11b..f2374ce096 100644 --- a/test/built-ins/Atomics/wait/object-for-timeout.js +++ b/test/built-ins/Atomics/wait/object-for-timeout.js @@ -20,7 +20,7 @@ flags: [CanBlockIsFalse] ---*/ var buffer = new SharedArrayBuffer(1024); -var int32Array = new Int32Array(buffer); +var i32a = new Int32Array(buffer); var valueOf = { valueOf: function() { @@ -40,6 +40,6 @@ var toPrimitive = { } }; -assert.sameValue(Atomics.wait(int32Array, 0, 0, valueOf), "timed-out"); -assert.sameValue(Atomics.wait(int32Array, 0, 0, toString), "timed-out"); -assert.sameValue(Atomics.wait(int32Array, 0, 0, toPrimitive), "timed-out"); +assert.sameValue(Atomics.wait(i32a, 0, 0, valueOf), "timed-out"); +assert.sameValue(Atomics.wait(i32a, 0, 0, toString), "timed-out"); +assert.sameValue(Atomics.wait(i32a, 0, 0, toPrimitive), "timed-out"); diff --git a/test/built-ins/Atomics/wait/out-of-range-index-throws.js b/test/built-ins/Atomics/wait/out-of-range-index-throws.js index d9925b8006..7d467a218f 100644 --- a/test/built-ins/Atomics/wait/out-of-range-index-throws.js +++ b/test/built-ins/Atomics/wait/out-of-range-index-throws.js @@ -16,7 +16,7 @@ info: | features: [Atomics, SharedArrayBuffer, TypedArray] ---*/ -var int32Array = new Int32Array(new SharedArrayBuffer(4)); +var i32a = new Int32Array(new SharedArrayBuffer(4)); var poisoned = { valueOf: function() { @@ -25,11 +25,11 @@ var poisoned = { }; assert.throws(RangeError, function() { - Atomics.wait(int32Array, Infinity, poisoned, poisoned); + Atomics.wait(i32a, Infinity, poisoned, poisoned); }); assert.throws(RangeError, function() { - Atomics.wait(int32Array, 2, poisoned, poisoned); + Atomics.wait(i32a, 2, poisoned, poisoned); }); assert.throws(RangeError, function() { - Atomics.wait(int32Array, 200, poisoned, poisoned); + Atomics.wait(i32a, 200, poisoned, poisoned); }); diff --git a/test/built-ins/Atomics/wait/poisoned-object-for-timeout-throws-agent.js b/test/built-ins/Atomics/wait/poisoned-object-for-timeout-throws-agent.js index 4708214512..738c78072e 100644 --- a/test/built-ins/Atomics/wait/poisoned-object-for-timeout-throws-agent.js +++ b/test/built-ins/Atomics/wait/poisoned-object-for-timeout-throws-agent.js @@ -19,7 +19,7 @@ includes: [ atomicsHelper.js ] function getReport() { var r; while ((r = $262.agent.getReport()) == null) { - $262.agent.sleep(100); + $262.agent.sleep(10); } return r; } @@ -38,16 +38,16 @@ var poisonedToPrimitive = { } }; -$262.agent.receiveBroadcast(function (sab) { - var int32Array = new Int32Array(sab); +$262.agent.receiveBroadcast(function(sab) { + var i32a = new Int32Array(sab); var start = Date.now(); try { - Atomics.wait(int32Array, 0, 0, poisonedValueOf); + Atomics.wait(i32a, 0, 0, poisonedValueOf); } catch (error) { $262.agent.report("poisonedValueOf"); } try { - Atomics.wait(int32Array, 0, 0, poisonedToPrimitive); + Atomics.wait(i32a, 0, 0, poisonedToPrimitive); } catch (error) { $262.agent.report("poisonedToPrimitive"); } @@ -56,9 +56,9 @@ $262.agent.receiveBroadcast(function (sab) { }); `); -var int32Array = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)); +var i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)); -$262.agent.broadcast(int32Array.buffer); +$262.agent.broadcast(i32a.buffer); $262.agent.sleep(150); assert.sameValue(getReport(), "poisonedValueOf"); @@ -70,5 +70,5 @@ assert(timeDiffReport >= 0, "timeout should be a min of 0ms"); assert(timeDiffReport <= $ATOMICS_MAX_TIME_EPSILON, "timeout should be a max of $$ATOMICS_MAX_TIME_EPSILON"); -assert.sameValue(Atomics.wake(int32Array, 0), 0); +assert.sameValue(Atomics.wake(i32a, 0), 0); diff --git a/test/built-ins/Atomics/wait/poisoned-object-for-timeout-throws.js b/test/built-ins/Atomics/wait/poisoned-object-for-timeout-throws.js index f157f07b11..70c5ef495c 100644 --- a/test/built-ins/Atomics/wait/poisoned-object-for-timeout-throws.js +++ b/test/built-ins/Atomics/wait/poisoned-object-for-timeout-throws.js @@ -19,7 +19,7 @@ features: [Atomics, SharedArrayBuffer, Symbol, Symbol.toPrimitive, TypedArray] ---*/ var buffer = new SharedArrayBuffer(1024); -var int32Array = new Int32Array(buffer); +var i32a = new Int32Array(buffer); var poisonedValueOf = { valueOf: function() { @@ -34,9 +34,9 @@ var poisonedToPrimitive = { }; assert.throws(Test262Error, function() { - Atomics.wait(int32Array, 0, 0, poisonedValueOf); + Atomics.wait(i32a, 0, 0, poisonedValueOf); }); assert.throws(Test262Error, function() { - Atomics.wait(int32Array, 0, 0, poisonedToPrimitive); + Atomics.wait(i32a, 0, 0, poisonedToPrimitive); }); diff --git a/test/built-ins/Atomics/wait/symbol-for-index-throws-agent.js b/test/built-ins/Atomics/wait/symbol-for-index-throws-agent.js index 0873f64eb9..e341a344c9 100644 --- a/test/built-ins/Atomics/wait/symbol-for-index-throws-agent.js +++ b/test/built-ins/Atomics/wait/symbol-for-index-throws-agent.js @@ -32,7 +32,7 @@ includes: [ atomicsHelper.js ] function getReport() { var r; while ((r = $262.agent.getReport()) == null) { - $262.agent.sleep(100); + $262.agent.sleep(10); } return r; } @@ -51,16 +51,16 @@ var poisonedToPrimitive = { } }; -$262.agent.receiveBroadcast(function (sab) { - var int32Array = new Int32Array(sab); +$262.agent.receiveBroadcast(function(sab) { + var i32a = new Int32Array(sab); var start = Date.now(); try { - Atomics.wait(int32Array, Symbol("1"), poisonedValueOf, poisonedValueOf); + Atomics.wait(i32a, Symbol("1"), poisonedValueOf, poisonedValueOf); } catch (error) { $262.agent.report('Symbol("1")'); } try { - Atomics.wait(int32Array, Symbol("2"), poisonedToPrimitive, poisonedToPrimitive); + Atomics.wait(i32a, Symbol("2"), poisonedToPrimitive, poisonedToPrimitive); } catch (error) { $262.agent.report('Symbol("2")'); } @@ -69,9 +69,9 @@ $262.agent.receiveBroadcast(function (sab) { }); `); -var int32Array = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)); +var i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)); -$262.agent.broadcast(int32Array.buffer); +$262.agent.broadcast(i32a.buffer); $262.agent.sleep(150); assert.sameValue(getReport(), 'Symbol("1")'); @@ -82,5 +82,5 @@ var timeDiffReport = getReport(); assert(timeDiffReport >= 0, "timeout should be a min of 0ms"); assert(timeDiffReport <= $ATOMICS_MAX_TIME_EPSILON, "timeout should be a max of $$ATOMICS_MAX_TIME_EPSILON"); -assert.sameValue(Atomics.wake(int32Array, 0), 0); +assert.sameValue(Atomics.wake(i32a, 0), 0); diff --git a/test/built-ins/Atomics/wait/symbol-for-index-throws.js b/test/built-ins/Atomics/wait/symbol-for-index-throws.js index fc8e8d55a1..8b630f4c77 100644 --- a/test/built-ins/Atomics/wait/symbol-for-index-throws.js +++ b/test/built-ins/Atomics/wait/symbol-for-index-throws.js @@ -29,7 +29,7 @@ features: [Atomics, SharedArrayBuffer, Symbol, Symbol.toPrimitive, TypedArray] ---*/ var buffer = new SharedArrayBuffer(1024); -var int32Array = new Int32Array(buffer); +var i32a = new Int32Array(buffer); var poisonedValueOf = { valueOf: function() { @@ -44,17 +44,17 @@ var poisonedToPrimitive = { }; assert.throws(Test262Error, function() { - Atomics.wait(int32Array, poisonedValueOf, poisonedValueOf, poisonedValueOf); + Atomics.wait(i32a, poisonedValueOf, poisonedValueOf, poisonedValueOf); }); assert.throws(Test262Error, function() { - Atomics.wait(int32Array, poisonedToPrimitive, poisonedToPrimitive, poisonedToPrimitive); + Atomics.wait(i32a, poisonedToPrimitive, poisonedToPrimitive, poisonedToPrimitive); }); assert.throws(TypeError, function() { - Atomics.wait(int32Array, Symbol("foo"), poisonedValueOf, poisonedValueOf); + Atomics.wait(i32a, Symbol("foo"), poisonedValueOf, poisonedValueOf); }); assert.throws(TypeError, function() { - Atomics.wait(int32Array, Symbol("foo"), poisonedToPrimitive, poisonedToPrimitive); + Atomics.wait(i32a, Symbol("foo"), poisonedToPrimitive, poisonedToPrimitive); }); diff --git a/test/built-ins/Atomics/wait/symbol-for-timeout-throws-agent.js b/test/built-ins/Atomics/wait/symbol-for-timeout-throws-agent.js index a6734c6ad1..9dc6526e57 100644 --- a/test/built-ins/Atomics/wait/symbol-for-timeout-throws-agent.js +++ b/test/built-ins/Atomics/wait/symbol-for-timeout-throws-agent.js @@ -18,23 +18,22 @@ includes: [ atomicsHelper.js ] function getReport() { var r; while ((r = $262.agent.getReport()) == null) { - $262.agent.sleep(100); + $262.agent.sleep(10); } return r; } -$262.agent.start( -` -$262.agent.receiveBroadcast(function (sab) { - var int32Array = new Int32Array(sab); +$262.agent.start(` +$262.agent.receiveBroadcast(function(sab) { + var i32a = new Int32Array(sab); var start = Date.now(); try { - Atomics.wait(int32Array, 0, 0, Symbol("1")); + Atomics.wait(i32a, 0, 0, Symbol("1")); } catch (error) { $262.agent.report('Symbol("1")'); } try { - Atomics.wait(int32Array, 0, 0, Symbol("2")); + Atomics.wait(i32a, 0, 0, Symbol("2")); } catch (error) { $262.agent.report('Symbol("2")'); } @@ -43,9 +42,9 @@ $262.agent.receiveBroadcast(function (sab) { }); `); -var int32Array = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)); +var i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)); -$262.agent.broadcast(int32Array.buffer); +$262.agent.broadcast(i32a.buffer); $262.agent.sleep(150); assert.sameValue(getReport(), 'Symbol("1")'); @@ -56,4 +55,4 @@ var timeDiffReport = getReport(); assert(timeDiffReport >= 0, "timeout should be a min of 0ms"); assert(timeDiffReport <= $ATOMICS_MAX_TIME_EPSILON, "timeout should be a max of $$ATOMICS_MAX_TIME_EPSILON"); -assert.sameValue(Atomics.wake(int32Array, 0), 0); +assert.sameValue(Atomics.wake(i32a, 0), 0); diff --git a/test/built-ins/Atomics/wait/symbol-for-timeout-throws.js b/test/built-ins/Atomics/wait/symbol-for-timeout-throws.js index c133032348..b0cc8a7c31 100644 --- a/test/built-ins/Atomics/wait/symbol-for-timeout-throws.js +++ b/test/built-ins/Atomics/wait/symbol-for-timeout-throws.js @@ -16,7 +16,7 @@ features: [Atomics, SharedArrayBuffer, Symbol, Symbol.toPrimitive, TypedArray] ---*/ var buffer = new SharedArrayBuffer(1024); -var int32Array = new Int32Array(buffer); +var i32a = new Int32Array(buffer); var poisonedValueOf = { valueOf: function() { @@ -31,17 +31,17 @@ var poisonedToPrimitive = { }; assert.throws(Test262Error, function() { - Atomics.wait(int32Array, 0, 0, poisonedValueOf); + Atomics.wait(i32a, 0, 0, poisonedValueOf); }); assert.throws(Test262Error, function() { - Atomics.wait(int32Array, 0, 0, poisonedToPrimitive); + Atomics.wait(i32a, 0, 0, poisonedToPrimitive); }); assert.throws(TypeError, function() { - Atomics.wait(int32Array, 0, 0, Symbol("foo")); + Atomics.wait(i32a, 0, 0, Symbol("foo")); }); assert.throws(TypeError, function() { - Atomics.wait(int32Array, 0, 0, Symbol("foo")); + Atomics.wait(i32a, 0, 0, Symbol("foo")); }); diff --git a/test/built-ins/Atomics/wait/symbol-for-value-throws-agent.js b/test/built-ins/Atomics/wait/symbol-for-value-throws-agent.js index 701c551f58..35f1c9aae3 100644 --- a/test/built-ins/Atomics/wait/symbol-for-value-throws-agent.js +++ b/test/built-ins/Atomics/wait/symbol-for-value-throws-agent.js @@ -23,13 +23,12 @@ includes: [ atomicsHelper.js ] function getReport() { var r; while ((r = $262.agent.getReport()) == null) { - $262.agent.sleep(100); + $262.agent.sleep(10); } return r; } -$262.agent.start( -` +$262.agent.start(` var poisonedValueOf = { valueOf: function() { throw new Test262Error("should not evaluate this code"); @@ -42,16 +41,16 @@ var poisonedToPrimitive = { } }; -$262.agent.receiveBroadcast(function (sab) { - var int32Array = new Int32Array(sab); +$262.agent.receiveBroadcast(function(sab) { + var i32a = new Int32Array(sab); var start = Date.now(); try { - Atomics.wait(int32Array, 0, Symbol("1"), poisonedValueOf); + Atomics.wait(i32a, 0, Symbol("1"), poisonedValueOf); } catch (error) { $262.agent.report('Symbol("1")'); } try { - Atomics.wait(int32Array, 0, Symbol("2"), poisonedToPrimitive); + Atomics.wait(i32a, 0, Symbol("2"), poisonedToPrimitive); } catch (error) { $262.agent.report('Symbol("2")'); } @@ -60,9 +59,9 @@ $262.agent.receiveBroadcast(function (sab) { }); `); -var int32Array = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)); +var i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)); -$262.agent.broadcast(int32Array.buffer); +$262.agent.broadcast(i32a.buffer); $262.agent.sleep(150); assert.sameValue(getReport(), 'Symbol("1")'); @@ -73,4 +72,4 @@ var timeDiffReport = getReport(); assert(timeDiffReport >= 0, "timeout should be a min of 0ms"); assert(timeDiffReport <= $ATOMICS_MAX_TIME_EPSILON, "timeout should be a max of $$ATOMICS_MAX_TIME_EPSILON"); -assert.sameValue(Atomics.wake(int32Array, 0), 0); +assert.sameValue(Atomics.wake(i32a, 0), 0); diff --git a/test/built-ins/Atomics/wait/symbol-for-value-throws.js b/test/built-ins/Atomics/wait/symbol-for-value-throws.js index e4d230da89..232195055f 100644 --- a/test/built-ins/Atomics/wait/symbol-for-value-throws.js +++ b/test/built-ins/Atomics/wait/symbol-for-value-throws.js @@ -20,7 +20,7 @@ features: [Atomics, SharedArrayBuffer, Symbol, Symbol.toPrimitive, TypedArray] ---*/ var buffer = new SharedArrayBuffer(1024); -var int32Array = new Int32Array(buffer); +var i32a = new Int32Array(buffer); var poisonedValueOf = { valueOf: function() { @@ -35,18 +35,18 @@ var poisonedToPrimitive = { }; assert.throws(Test262Error, function() { - Atomics.wait(int32Array, 0, poisonedValueOf, poisonedValueOf); + Atomics.wait(i32a, 0, poisonedValueOf, poisonedValueOf); }); assert.throws(Test262Error, function() { - Atomics.wait(int32Array, 0, poisonedToPrimitive, poisonedToPrimitive); + Atomics.wait(i32a, 0, poisonedToPrimitive, poisonedToPrimitive); }); assert.throws(TypeError, function() { - Atomics.wait(int32Array, 0, Symbol("foo"), poisonedValueOf); + Atomics.wait(i32a, 0, Symbol("foo"), poisonedValueOf); }); assert.throws(TypeError, function() { - Atomics.wait(int32Array, 0, Symbol("foo"), poisonedToPrimitive); + Atomics.wait(i32a, 0, Symbol("foo"), poisonedToPrimitive); }); diff --git a/test/built-ins/Atomics/wait/true-for-timeout-agent.js b/test/built-ins/Atomics/wait/true-for-timeout-agent.js index 08e712a7d6..53b3b50e2f 100644 --- a/test/built-ins/Atomics/wait/true-for-timeout-agent.js +++ b/test/built-ins/Atomics/wait/true-for-timeout-agent.js @@ -19,7 +19,7 @@ includes: [ atomicsHelper.js ] function getReport() { var r; while ((r = $262.agent.getReport()) == null) { - $262.agent.sleep(100); + $262.agent.sleep(10); } return r; } @@ -38,20 +38,20 @@ var toPrimitive = { } }; -$262.agent.receiveBroadcast(function (sab) { - var int32Array = new Int32Array(sab); +$262.agent.receiveBroadcast(function(sab) { + var i32a = new Int32Array(sab); var start = Date.now(); - $262.agent.report(Atomics.wait(int32Array, 0, 0, true)); - $262.agent.report(Atomics.wait(int32Array, 0, 0, valueOf)); - $262.agent.report(Atomics.wait(int32Array, 0, 0, toPrimitive)); + $262.agent.report(Atomics.wait(i32a, 0, 0, true)); + $262.agent.report(Atomics.wait(i32a, 0, 0, valueOf)); + $262.agent.report(Atomics.wait(i32a, 0, 0, toPrimitive)); $262.agent.report(Date.now() - start); $262.agent.leaving(); }) `); -var int32Array = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)); +var i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)); -$262.agent.broadcast(int32Array.buffer); +$262.agent.broadcast(i32a.buffer); $262.agent.sleep(150); assert.sameValue(getReport(), 'timed-out'); @@ -64,5 +64,5 @@ assert(timeDiffReport >= 0, 'timeout should be a min of 0ms'); assert(timeDiffReport <= $ATOMICS_MAX_TIME_EPSILON, 'timeout should be a max of $$ATOMICS_MAX_TIME_EPSILON'); -assert.sameValue(Atomics.wake(int32Array, 0), 0); +assert.sameValue(Atomics.wake(i32a, 0), 0); diff --git a/test/built-ins/Atomics/wait/true-for-timeout.js b/test/built-ins/Atomics/wait/true-for-timeout.js index c099e9d058..9e9bea15dd 100644 --- a/test/built-ins/Atomics/wait/true-for-timeout.js +++ b/test/built-ins/Atomics/wait/true-for-timeout.js @@ -17,7 +17,7 @@ flags: [CanBlockIsFalse] ---*/ var buffer = new SharedArrayBuffer(1024); -var int32Array = new Int32Array(buffer); +var i32a = new Int32Array(buffer); var valueOf = { valueOf: function() { @@ -31,7 +31,7 @@ var toPrimitive = { } }; -assert.sameValue(Atomics.wait(int32Array, 0, 0, true), "timed-out"); -assert.sameValue(Atomics.wait(int32Array, 0, 0, valueOf), "timed-out"); -assert.sameValue(Atomics.wait(int32Array, 0, 0, toPrimitive), "timed-out"); +assert.sameValue(Atomics.wait(i32a, 0, 0, true), "timed-out"); +assert.sameValue(Atomics.wait(i32a, 0, 0, valueOf), "timed-out"); +assert.sameValue(Atomics.wait(i32a, 0, 0, toPrimitive), "timed-out"); diff --git a/test/built-ins/Atomics/wait/undefined-for-timeout.js b/test/built-ins/Atomics/wait/undefined-for-timeout.js index 4d9ff9054b..8a8fd19461 100644 --- a/test/built-ins/Atomics/wait/undefined-for-timeout.js +++ b/test/built-ins/Atomics/wait/undefined-for-timeout.js @@ -22,38 +22,37 @@ var WAKECOUNT = 2; // Total number of agents to wake up function getReport() { var r; while ((r = $262.agent.getReport()) == null) { - $262.agent.sleep(100); + $262.agent.sleep(10); } return r; } -$262.agent.start( -` -$262.agent.receiveBroadcast(function (sab) { - var int32Array = new Int32Array(sab); - $262.agent.report("A " + Atomics.wait(int32Array, 0, 0, undefined)); // undefined => NaN => +Infinity +$262.agent.start(` +$262.agent.receiveBroadcast(function(sab) { + var i32a = new Int32Array(sab); + $262.agent.report("A " + Atomics.wait(i32a, 0, 0, undefined)); // undefined => NaN => +Infinity $262.agent.leaving(); }) `); $262.agent.start( ` -$262.agent.receiveBroadcast(function (sab) { - var int32Array = new Int32Array(sab); - $262.agent.report("B " + Atomics.wait(int32Array, 0, 0)); // undefined timeout arg => NaN => +Infinity +$262.agent.receiveBroadcast(function(sab) { + var i32a = new Int32Array(sab); + $262.agent.report("B " + Atomics.wait(i32a, 0, 0)); // undefined timeout arg => NaN => +Infinity $262.agent.leaving(); }) `); -var int32Array = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)); +var i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)); -$262.agent.broadcast(int32Array.buffer); +$262.agent.broadcast(i32a.buffer); $262.agent.sleep(500); // Ample time assert.sameValue($262.agent.getReport(), null); -assert.sameValue(Atomics.wake(int32Array, WAKEUP, WAKECOUNT), WAKECOUNT); +assert.sameValue(Atomics.wake(i32a, WAKEUP, WAKECOUNT), WAKECOUNT); var sortedReports = []; for (var i = 0; i < NUMAGENT; i++) { diff --git a/test/built-ins/Atomics/wait/undefined-index-defaults-to-zero.js b/test/built-ins/Atomics/wait/undefined-index-defaults-to-zero.js index 8e5ecffe33..ac3bda6bb6 100644 --- a/test/built-ins/Atomics/wait/undefined-index-defaults-to-zero.js +++ b/test/built-ins/Atomics/wait/undefined-index-defaults-to-zero.js @@ -20,31 +20,30 @@ info: | features: [Atomics, SharedArrayBuffer, TypedArray] ---*/ -$262.agent.start( -` -$262.agent.receiveBroadcast(function (sab) { - var int32Array = new Int32Array(sab); - $262.agent.report(Atomics.wait(int32Array, undefined, 0, 1000)); // undefined index => 0 +$262.agent.start(` +$262.agent.receiveBroadcast(function(sab) { + var i32a = new Int32Array(sab); + $262.agent.report(Atomics.wait(i32a, undefined, 0, 1000)); // undefined index => 0 $262.agent.leaving(); }) `); var sab = new SharedArrayBuffer(4); -var int32Array = new Int32Array(sab); +var i32a = new Int32Array(sab); -$262.agent.broadcast(int32Array.buffer); +$262.agent.broadcast(i32a.buffer); $262.agent.sleep(150); -assert.sameValue(Atomics.wake(int32Array, 0), 1); // wake at index 0 -assert.sameValue(Atomics.wake(int32Array, 0), 0); // wake again at index 0, and 0 agents should be woken +assert.sameValue(Atomics.wake(i32a, 0), 1); // wake at index 0 +assert.sameValue(Atomics.wake(i32a, 0), 0); // wake again at index 0, and 0 agents should be woken assert.sameValue(getReport(), "ok"); function getReport() { var r; while ((r = $262.agent.getReport()) == null) { - $262.agent.sleep(100); + $262.agent.sleep(10); } return r; } diff --git a/test/built-ins/Atomics/wait/value-not-equal.js b/test/built-ins/Atomics/wait/value-not-equal.js index 33f25df260..8240a3271a 100644 --- a/test/built-ins/Atomics/wait/value-not-equal.js +++ b/test/built-ins/Atomics/wait/value-not-equal.js @@ -21,29 +21,26 @@ includes: [atomicsHelper.js] function getReport() { var r; while ((r = $262.agent.getReport()) == null) { - $262.agent.sleep(100); + $262.agent.sleep(10); } return r; } var value = 42; -$262.agent.start( -` -$262.agent.receiveBroadcast(function (sab) { - var int32Array = new Int32Array(sab); - - $262.agent.report(Atomics.store(int32Array, 0, ${value})); - - $262.agent.report(Atomics.wait(int32Array, 0, 0)); +$262.agent.start(` +$262.agent.receiveBroadcast(function(sab) { + var i32a = new Int32Array(sab); + $262.agent.report(Atomics.store(i32a, 0, ${value})); + $262.agent.report(Atomics.wait(i32a, 0, 0)); $262.agent.leaving(); -}) +}); `); -var int32Array = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)); +var i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)); -$262.agent.broadcast(int32Array.buffer); +$262.agent.broadcast(i32a.buffer); assert.sameValue(getReport(), value.toString()); assert.sameValue(getReport(), "not-equal"); diff --git a/test/built-ins/Atomics/wait/wait-index-value-not-equal.js b/test/built-ins/Atomics/wait/wait-index-value-not-equal.js index db0ac699f6..94b6d4eabe 100644 --- a/test/built-ins/Atomics/wait/wait-index-value-not-equal.js +++ b/test/built-ins/Atomics/wait/wait-index-value-not-equal.js @@ -18,27 +18,24 @@ features: [Atomics, SharedArrayBuffer, TypedArray] function getReport() { var r; while ((r = $262.agent.getReport()) == null) { - $262.agent.sleep(100); + $262.agent.sleep(10); } return r; } -$262.agent.start( -` -$262.agent.receiveBroadcast(function (sab) { - var int32Array = new Int32Array(sab); - - $262.agent.report(Atomics.wait(int32Array, 0, 44, 1000)); - - $262.agent.report(Atomics.wait(int32Array, 0, 251.4, 1000)); +$262.agent.start(` +$262.agent.receiveBroadcast(function(sab) { + var i32a = new Int32Array(sab); + $262.agent.report(Atomics.wait(i32a, 0, 44, 1000)); + $262.agent.report(Atomics.wait(i32a, 0, 251.4, 1000)); $262.agent.leaving(); -}) +}); `); -var int32Array = new Int32Array(new SharedArrayBuffer(1024)); +var i32a = new Int32Array(new SharedArrayBuffer(1024)); -$262.agent.broadcast(int32Array.buffer); +$262.agent.broadcast(i32a.buffer); $262.agent.sleep(200); @@ -46,4 +43,4 @@ $262.agent.sleep(200); assert.sameValue(getReport(), "not-equal"); assert.sameValue(getReport(), "not-equal"); -assert.sameValue(Atomics.wake(int32Array, 0), 0); +assert.sameValue(Atomics.wake(i32a, 0), 0); diff --git a/test/built-ins/Atomics/wait/waiterlist-block-indexedposition-wake.js b/test/built-ins/Atomics/wait/waiterlist-block-indexedposition-wake.js index 8f9c1cfade..6c59ebabc1 100644 --- a/test/built-ins/Atomics/wait/waiterlist-block-indexedposition-wake.js +++ b/test/built-ins/Atomics/wait/waiterlist-block-indexedposition-wake.js @@ -30,10 +30,10 @@ function getReport() { $262.agent.start(` $262.agent.receiveBroadcast(function(sab) { - var i32 = new Int32Array(sab); + var i32a = new Int32Array(sab); // Wait on index 0 - Atomics.wait(i32, 0, 0, 200); + Atomics.wait(i32a, 0, 0, 200); $262.agent.report("fail"); $262.agent.leaving(); }); @@ -41,22 +41,22 @@ $262.agent.receiveBroadcast(function(sab) { $262.agent.start(` $262.agent.receiveBroadcast(function(sab) { - var i32 = new Int32Array(sab); + var i32a = new Int32Array(sab); // Wait on index 2 - Atomics.wait(i32, 2, 0, 200); + Atomics.wait(i32a, 2, 0, 200); $262.agent.report("pass"); $262.agent.leaving(); }); `); var length = 4 * Int32Array.BYTES_PER_ELEMENT; -var i32 = new Int32Array(new SharedArrayBuffer(length)); +var i32a = new Int32Array(new SharedArrayBuffer(length)); -$262.agent.broadcast(i32.buffer); +$262.agent.broadcast(i32a.buffer); $262.agent.sleep(10); // Wake index 2 -Atomics.wake(i32, 2, 1); +Atomics.wake(i32a, 2, 1); assert.sameValue(getReport(), "pass"); diff --git a/test/built-ins/Atomics/wait/waiterlist-order-of-operations-is-fifo.js b/test/built-ins/Atomics/wait/waiterlist-order-of-operations-is-fifo.js index 161c40e20d..b598647e07 100644 --- a/test/built-ins/Atomics/wait/waiterlist-order-of-operations-is-fifo.js +++ b/test/built-ins/Atomics/wait/waiterlist-order-of-operations-is-fifo.js @@ -18,7 +18,7 @@ features: [Atomics, SharedArrayBuffer, TypedArray] function getReport() { var r; while ((r = $262.agent.getReport()) == null) { - $262.agent.sleep(100); + $262.agent.sleep(10); } return r; } @@ -27,9 +27,8 @@ var agent1 = '1'; var agent2 = '2'; var agent3 = '3'; -$262.agent.start( -` -$262.agent.receiveBroadcast(function (sab) { +$262.agent.start(` +$262.agent.receiveBroadcast(function(sab) { var int32Array = new Int32Array(sab); $262.agent.report(${agent1}); @@ -37,12 +36,11 @@ $262.agent.receiveBroadcast(function (sab) { $262.agent.report(${agent1}); $262.agent.leaving(); -}) +}); `); -$262.agent.start( - ` -$262.agent.receiveBroadcast(function (sab) { +$262.agent.start(` +$262.agent.receiveBroadcast(function(sab) { var int32Array = new Int32Array(sab); $262.agent.report(${agent2}); @@ -51,12 +49,11 @@ $262.agent.receiveBroadcast(function (sab) { $262.agent.report(${agent2}); $262.agent.leaving(); -}) +}); `); -$262.agent.start( - ` -$262.agent.receiveBroadcast(function (sab) { +$262.agent.start(` +$262.agent.receiveBroadcast(function(sab) { var int32Array = new Int32Array(sab); $262.agent.report(${agent3}); @@ -65,7 +62,7 @@ $262.agent.receiveBroadcast(function (sab) { $262.agent.report(${agent3}); $262.agent.leaving(); -}) +}); `); diff --git a/test/built-ins/Atomics/wait/was-woken-before-timeout.js b/test/built-ins/Atomics/wait/was-woken-before-timeout.js index 0839fbb10c..936e10fb1a 100644 --- a/test/built-ins/Atomics/wait/was-woken-before-timeout.js +++ b/test/built-ins/Atomics/wait/was-woken-before-timeout.js @@ -33,8 +33,7 @@ function getReport() { return r; } -$262.agent.start( -` +$262.agent.start(` $262.agent.receiveBroadcast(function(sab) { var int32Array = new Int32Array(sab); $262.agent.report(Atomics.wait(int32Array, 0, 0, ${timeout})); diff --git a/test/built-ins/Atomics/wait/was-woken.js b/test/built-ins/Atomics/wait/was-woken.js index ccb180f5ae..6fcaefca10 100644 --- a/test/built-ins/Atomics/wait/was-woken.js +++ b/test/built-ins/Atomics/wait/was-woken.js @@ -11,14 +11,13 @@ features: [Atomics, SharedArrayBuffer, TypedArray] function getReport() { var r; while ((r = $262.agent.getReport()) == null) { - $262.agent.sleep(100); + $262.agent.sleep(10); } return r; } -$262.agent.start( -` -$262.agent.receiveBroadcast(function (sab, id) { +$262.agent.start(` +$262.agent.receiveBroadcast(function(sab, id) { var ia = new Int32Array(sab); $262.agent.report(Atomics.wait(ia, 0, 0)); // No timeout => Infinity $262.agent.leaving(); diff --git a/test/built-ins/Atomics/wake/bigint/bad-range.js b/test/built-ins/Atomics/wake/bigint/bad-range.js new file mode 100644 index 0000000000..70d35c17a3 --- /dev/null +++ b/test/built-ins/Atomics/wake/bigint/bad-range.js @@ -0,0 +1,23 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.wake +description: > + Test range checking of Atomics.wake on arrays that allow atomic operations +info: | + Atomics.wake( typedArray, index, count ) + + 1. Let buffer be ? ValidateSharedIntegerTypedArray(typedArray, true). + .. + +includes: [testAtomics.js] +features: [ArrayBuffer, arrow-function, Atomics, BigInt, DataView, for-of, let, SharedArrayBuffer, TypedArray] +---*/ + +var sab = new SharedArrayBuffer(8); +let i64a = new BigInt64Array(sab); + +testWithAtomicsOutOfBoundsIndices(function(IdxGen) { + assert.throws(RangeError, () => Atomics.wake(view, IdxGen(i64a), 0)); +}); diff --git a/test/built-ins/Atomics/wake/bigint/non-bigint64-typedarray-throws.js b/test/built-ins/Atomics/wake/bigint/non-bigint64-typedarray-throws.js new file mode 100644 index 0000000000..12108e3b02 --- /dev/null +++ b/test/built-ins/Atomics/wake/bigint/non-bigint64-typedarray-throws.js @@ -0,0 +1,26 @@ +// Copyright (C) 2018 Amal Hussein. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.wake +description: > + Throws a TypeError if typedArray arg is not an BigInt64Array +info: | + Atomics.wake( typedArray, index, count ) + + 1.Let buffer be ? ValidateSharedIntegerTypedArray(typedArray, true). + ... + 5.If onlyInt32 is true, then + If typeName is not "BigInt64Array", throw a TypeError exception. +features: [Atomics, BigInt] +---*/ + +var poisoned = { + valueOf: function() { + throw new Test262Error("should not evaluate this code"); + } +}; + +assert.throws(TypeError, function() { + Atomics.wake(new BigUint64Array(), poisoned, poisoned); +}, 'BigUint64Array'); diff --git a/test/built-ins/Atomics/wake/bigint/non-shared-bufferdata-throws.js b/test/built-ins/Atomics/wake/bigint/non-shared-bufferdata-throws.js new file mode 100644 index 0000000000..43185fbceb --- /dev/null +++ b/test/built-ins/Atomics/wake/bigint/non-shared-bufferdata-throws.js @@ -0,0 +1,31 @@ +// Copyright (C) 2018 Amal Hussein. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-atomics.wake +description: > + Throws a TypeError if typedArray.buffer is not a SharedArrayBuffer +info: | + Atomics.wake( typedArray, index, count ) + + 1.Let buffer be ? ValidateSharedIntegerTypedArray(typedArray, true). + ... + 9.If IsSharedArrayBuffer(buffer) is false, throw a TypeError exception. + ... + 4.If bufferData is a Data Block, return false. +features: [ArrayBuffer, BigInt, Atomics, TypedArray] +---*/ + +var i64a = new BigInt64Array(new ArrayBuffer(4)); +var poisoned = { + valueOf: function() { + throw new Test262Error("should not evaluate this code"); + } +}; + +assert.throws(TypeError, function() { + Atomics.wake(i64a, 0, 0); +}); + +assert.throws(TypeError, function() { + Atomics.wake(i64a, poisoned, poisoned); +}); diff --git a/test/built-ins/Atomics/wake/bigint/null-bufferdata-throws.js b/test/built-ins/Atomics/wake/bigint/null-bufferdata-throws.js new file mode 100644 index 0000000000..0e46e207a6 --- /dev/null +++ b/test/built-ins/Atomics/wake/bigint/null-bufferdata-throws.js @@ -0,0 +1,31 @@ +// Copyright (C) 2018 Amal Hussein. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-atomics.wake +description: > + A null value for bufferData throws a TypeError +info: | + Atomics.wake( typedArray, index, count ) + + 1.Let buffer be ? ValidateSharedIntegerTypedArray(typedArray, true). + ... + 9.If IsSharedArrayBuffer(buffer) is false, throw a TypeError exception. + ... + 3.If bufferData is null, return false. +includes: [detachArrayBuffer.js] +features: [ArrayBuffer, BigInt, Atomics, TypedArray] +---*/ + +var i64a = new BigInt64Array(new ArrayBuffer(1024)); +var poisoned = { + valueOf: function() { + throw new Test262Error("should not evaluate this code"); + } +}; + +// Detaching a non-shared ArrayBuffer sets the [[ArrayBufferData]] value to null +$DETACHBUFFER(i64a.buffer); + +assert.throws(TypeError, function() { + Atomics.wake(i64a, poisoned, poisoned); +}); diff --git a/test/built-ins/Atomics/wake/bigint/wake-all-on-loc.js b/test/built-ins/Atomics/wake/bigint/wake-all-on-loc.js new file mode 100644 index 0000000000..6494b0117a --- /dev/null +++ b/test/built-ins/Atomics/wake/bigint/wake-all-on-loc.js @@ -0,0 +1,78 @@ +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.wake +description: > + Test that Atomics.wake wakes all waiters on a location, but does not + wake waiters on other locations. +features: [Atomics, BigInt, SharedArrayBuffer, TypedArray] +---*/ + +var WAKEUP = 0; // Waiters on this will be woken +var DUMMY = 1; // Waiters on this will not be woken +var RUNNING = 2; // Accounting of live agents +var NUMELEM = 3; +var NUMAGENT = 3; + +for (var i = 0; i < NUMAGENT; i++) { +$262.agent.start(` +$262.agent.receiveBroadcast(function(sab) { + var i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1); + $262.agent.report("A " + Atomics.wait(i64a, ${WAKEUP}, 0)); + $262.agent.leaving(); +}); +`); +} + +$262.agent.start(` +$262.agent.receiveBroadcast(function(sab) { + var i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1); + // This will always time out. + $262.agent.report("B " + Atomics.wait(i64a, ${DUMMY}, 0, 10)); + $262.agent.leaving(); +}); +`); + +var i64a = new BigInt64Array(new SharedArrayBuffer(NUMELEM * BigInt64Array.BYTES_PER_ELEMENT)); +$262.agent.broadcast(i64a.buffer); + +// Wait for agents to be running. +waitUntil(i64a, RUNNING, NUMAGENT + 1); + +// Then wait some more to give the agents a fair chance to wait. If we don't, +// we risk sending the wakeup before agents are sleeping, and we hang. +$262.agent.sleep(50); + +// Wake all waiting on WAKEUP, should be 3 always, they won't time out. +assert.sameValue(Atomics.wake(i64a, WAKEUP), NUMAGENT); + +var rs = []; +for (var i = 0; i < NUMAGENT + 1; i++) { + rs.push(getReport()); +} +rs.sort(); + +for (var i = 0; i < NUMAGENT; i++) { + assert.sameValue(rs[i], "A ok"); +} +assert.sameValue(rs[NUMAGENT], "B timed-out"); + +function getReport() { + var r; + while ((r = $262.agent.getReport()) == null) { + $262.agent.sleep(10); + } + return r; +} + +function waitUntil(i64a, k, value) { + var i = 0; + while (Atomics.load(i64a, k) !== value && i < 15) { + $262.agent.sleep(10); + i++; + } + assert.sameValue(Atomics.load(i64a, k), value, "All agents are running"); +} diff --git a/test/built-ins/Atomics/wake/count-defaults-to-infinity-missing.js b/test/built-ins/Atomics/wake/count-defaults-to-infinity-missing.js index 5f3bd8da74..cb874c1521 100644 --- a/test/built-ins/Atomics/wake/count-defaults-to-infinity-missing.js +++ b/test/built-ins/Atomics/wake/count-defaults-to-infinity-missing.js @@ -27,7 +27,7 @@ function getReport() { } $262.agent.start(` -$262.agent.receiveBroadcast(function (sab) { +$262.agent.receiveBroadcast(function(sab) { var int32Array = new Int32Array(sab); $262.agent.report("A " + Atomics.wait(int32Array, ${WAKEUP}, 0, 50)); $262.agent.leaving(); @@ -35,7 +35,7 @@ $262.agent.receiveBroadcast(function (sab) { `); $262.agent.start(` -$262.agent.receiveBroadcast(function (sab) { +$262.agent.receiveBroadcast(function(sab) { var int32Array = new Int32Array(sab); $262.agent.report("B " + Atomics.wait(int32Array, ${WAKEUP}, 0, 50)); $262.agent.leaving(); @@ -43,7 +43,7 @@ $262.agent.receiveBroadcast(function (sab) { `); $262.agent.start(` -$262.agent.receiveBroadcast(function (sab) { +$262.agent.receiveBroadcast(function(sab) { var int32Array = new Int32Array(sab); $262.agent.report("C " + Atomics.wait(int32Array, ${WAKEUP}, 0, 50)); $262.agent.leaving(); @@ -51,7 +51,7 @@ $262.agent.receiveBroadcast(function (sab) { `); $262.agent.start(` -$262.agent.receiveBroadcast(function (sab) { +$262.agent.receiveBroadcast(function(sab) { var int32Array = new Int32Array(sab); $262.agent.report("D " + Atomics.wait(int32Array, ${WAKEUP}, 0, 50)); $262.agent.leaving(); diff --git a/test/built-ins/Atomics/wake/count-defaults-to-infinity-undefined.js b/test/built-ins/Atomics/wake/count-defaults-to-infinity-undefined.js index 45cf764351..3102906298 100644 --- a/test/built-ins/Atomics/wake/count-defaults-to-infinity-undefined.js +++ b/test/built-ins/Atomics/wake/count-defaults-to-infinity-undefined.js @@ -18,13 +18,14 @@ var WAKEUP = 0; // Index all agents are waiting on function getReport() { var r; - while ((r = $262.agent.getReport()) == null) + while ((r = $262.agent.getReport()) == null) { $262.agent.sleep(10); + } return r; } $262.agent.start(` -$262.agent.receiveBroadcast(function (sab) { +$262.agent.receiveBroadcast(function(sab) { var int32Array = new Int32Array(sab); $262.agent.report("A " + Atomics.wait(int32Array, ${WAKEUP}, 0, 50)); $262.agent.leaving(); @@ -32,7 +33,7 @@ $262.agent.receiveBroadcast(function (sab) { `); $262.agent.start(` -$262.agent.receiveBroadcast(function (sab) { +$262.agent.receiveBroadcast(function(sab) { var int32Array = new Int32Array(sab); $262.agent.report("B " + Atomics.wait(int32Array, ${WAKEUP}, 0, 50)); $262.agent.leaving(); @@ -41,7 +42,7 @@ $262.agent.receiveBroadcast(function (sab) { $262.agent.start(` -$262.agent.receiveBroadcast(function (sab) { +$262.agent.receiveBroadcast(function(sab) { var int32Array = new Int32Array(sab); $262.agent.report("C " + Atomics.wait(int32Array, ${WAKEUP}, 0, 50)); $262.agent.leaving(); @@ -50,7 +51,7 @@ $262.agent.receiveBroadcast(function (sab) { $262.agent.start(` -$262.agent.receiveBroadcast(function (sab) { +$262.agent.receiveBroadcast(function(sab) { var int32Array = new Int32Array(sab); $262.agent.report("D " + Atomics.wait(int32Array, ${WAKEUP}, 0, 50)); $262.agent.leaving(); diff --git a/test/built-ins/Atomics/wake/negative-count.js b/test/built-ins/Atomics/wake/negative-count.js index e1790d81c0..3c8c6c83b6 100644 --- a/test/built-ins/Atomics/wake/negative-count.js +++ b/test/built-ins/Atomics/wake/negative-count.js @@ -8,9 +8,8 @@ description: > features: [Atomics, SharedArrayBuffer, TypedArray] ---*/ -$262.agent.start( -` -$262.agent.receiveBroadcast(function (sab) { +$262.agent.start(` +$262.agent.receiveBroadcast(function(sab) { var ia = new Int32Array(sab); $262.agent.report(Atomics.wait(ia, 0, 0, 1000)); // We will timeout eventually $262.agent.leaving(); @@ -26,7 +25,8 @@ assert.sameValue(getReport(), "timed-out"); function getReport() { var r; - while ((r = $262.agent.getReport()) == null) - $262.agent.sleep(100); + while ((r = $262.agent.getReport()) == null) { + $262.agent.sleep(10); + } return r; } diff --git a/test/built-ins/Atomics/wake/undefined-index-defaults-to-zero.js b/test/built-ins/Atomics/wake/undefined-index-defaults-to-zero.js index aeb452720d..4b8d346a40 100644 --- a/test/built-ins/Atomics/wake/undefined-index-defaults-to-zero.js +++ b/test/built-ins/Atomics/wake/undefined-index-defaults-to-zero.js @@ -23,7 +23,7 @@ features: [Atomics, SharedArrayBuffer, TypedArray] $262.agent.start( ` -$262.agent.receiveBroadcast(function (sab) { +$262.agent.receiveBroadcast(function(sab) { var int32Array = new Int32Array(sab); $262.agent.report(Atomics.wait(int32Array, 0, 0, 200)); $262.agent.leaving(); @@ -34,7 +34,7 @@ $262.agent.receiveBroadcast(function (sab) { ;$262.agent.start( ` -$262.agent.receiveBroadcast(function (sab) { +$262.agent.receiveBroadcast(function(sab) { var int32Array = new Int32Array(sab); $262.agent.report(Atomics.wait(int32Array, 0, 0, 200)); $262.agent.leaving(); @@ -57,7 +57,7 @@ assert.sameValue(getReport(), "ok"); function getReport() { var r; while ((r = $262.agent.getReport()) == null) { - $262.agent.sleep(100); + $262.agent.sleep(10); } return r; } diff --git a/test/built-ins/Atomics/wake/wake-all-on-loc.js b/test/built-ins/Atomics/wake/wake-all-on-loc.js index ee404925c6..552eb52b6c 100644 --- a/test/built-ins/Atomics/wake/wake-all-on-loc.js +++ b/test/built-ins/Atomics/wake/wake-all-on-loc.js @@ -17,9 +17,8 @@ var NUMELEM = 3; var NUMAGENT = 3; for (var i=0; i < NUMAGENT; i++) { -$262.agent.start( -` -$262.agent.receiveBroadcast(function (sab) { +$262.agent.start(` +$262.agent.receiveBroadcast(function(sab) { var ia = new Int32Array(sab); Atomics.add(ia, ${RUNNING}, 1); $262.agent.report("A " + Atomics.wait(ia, ${WAKEUP}, 0)); @@ -28,9 +27,8 @@ $262.agent.receiveBroadcast(function (sab) { `); } -$262.agent.start( -` -$262.agent.receiveBroadcast(function (sab) { +$262.agent.start(` +$262.agent.receiveBroadcast(function(sab) { var ia = new Int32Array(sab); Atomics.add(ia, ${RUNNING}, 1); // This will always time out. diff --git a/test/built-ins/Atomics/wake/wake-all.js b/test/built-ins/Atomics/wake/wake-all.js index 2ea493456d..e211529280 100644 --- a/test/built-ins/Atomics/wake/wake-all.js +++ b/test/built-ins/Atomics/wake/wake-all.js @@ -16,9 +16,8 @@ var NUMELEM = 3; var NUMAGENT = 3; for (var i=0; i < NUMAGENT; i++) { -$262.agent.start( -` -$262.agent.receiveBroadcast(function (sab) { +$262.agent.start(` +$262.agent.receiveBroadcast(function(sab) { var ia = new Int32Array(sab); Atomics.add(ia, ${RUNNING}, 1); $262.agent.report("A " + Atomics.wait(ia, ${WAKEUP}, 0)); @@ -27,9 +26,8 @@ $262.agent.receiveBroadcast(function (sab) { `); } -$262.agent.start( -` -$262.agent.receiveBroadcast(function (sab) { +$262.agent.start(` +$262.agent.receiveBroadcast(function(sab) { var ia = new Int32Array(sab); Atomics.add(ia, ${RUNNING}, 1); // This will always time out. diff --git a/test/built-ins/Atomics/wake/wake-in-order.js b/test/built-ins/Atomics/wake/wake-in-order.js index 5e09afdc9c..8598b84b0d 100644 --- a/test/built-ins/Atomics/wake/wake-in-order.js +++ b/test/built-ins/Atomics/wake/wake-in-order.js @@ -20,9 +20,8 @@ var NUMELEM = RUNNING + 1; // one by one and observe the wakeup order. for ( var i=0 ; i < NUMAGENT ; i++ ) { -$262.agent.start( -` -$262.agent.receiveBroadcast(function (sab) { +$262.agent.start(` +$262.agent.receiveBroadcast(function(sab) { var ia = new Int32Array(sab); Atomics.add(ia, ${RUNNING}, 1); while (Atomics.load(ia, ${SPIN + i}) === 0) diff --git a/test/built-ins/Atomics/wake/wake-nan.js b/test/built-ins/Atomics/wake/wake-nan.js index 9c7f93537d..5fa193e20e 100644 --- a/test/built-ins/Atomics/wake/wake-nan.js +++ b/test/built-ins/Atomics/wake/wake-nan.js @@ -8,9 +8,8 @@ description: > features: [Atomics, SharedArrayBuffer, TypedArray] ---*/ -$262.agent.start( -` -$262.agent.receiveBroadcast(function (sab) { +$262.agent.start(` +$262.agent.receiveBroadcast(function(sab) { var ia = new Int32Array(sab); $262.agent.report(Atomics.wait(ia, 0, 0, 1000)); // We will timeout eventually $262.agent.leaving(); @@ -27,7 +26,7 @@ assert.sameValue(getReport(), "timed-out"); function getReport() { var r; while ((r = $262.agent.getReport()) == null) { - $262.agent.sleep(100); + $262.agent.sleep(10); } return r; } diff --git a/test/built-ins/Atomics/wake/wake-one.js b/test/built-ins/Atomics/wake/wake-one.js index b19a44fce1..844546ff57 100644 --- a/test/built-ins/Atomics/wake/wake-one.js +++ b/test/built-ins/Atomics/wake/wake-one.js @@ -17,9 +17,8 @@ var NUMELEM = 2; var WAKECOUNT = 1; for ( var i=0 ; i < NUMAGENT ; i++ ) { -$262.agent.start( -` -$262.agent.receiveBroadcast(function (sab) { +$262.agent.start(` +$262.agent.receiveBroadcast(function(sab) { var ia = new Int32Array(sab); Atomics.add(ia, ${RUNNING}, 1); // Waiters that are not woken will time out eventually. diff --git a/test/built-ins/Atomics/wake/wake-rewake-noop.js b/test/built-ins/Atomics/wake/wake-rewake-noop.js index 0dfeb3b95b..9c6362e34a 100644 --- a/test/built-ins/Atomics/wake/wake-rewake-noop.js +++ b/test/built-ins/Atomics/wake/wake-rewake-noop.js @@ -25,8 +25,7 @@ function waitUntil(ia, k, value) { assert.sameValue(Atomics.load(ia, k), value, "All agents are running"); } -$262.agent.start( -` +$262.agent.start(` $262.agent.receiveBroadcast(function(sab) { var ia = new Int32Array(sab); Atomics.add(ia, 1, 1); diff --git a/test/built-ins/Atomics/wake/wake-two.js b/test/built-ins/Atomics/wake/wake-two.js index 6ca7c52e73..b76c5f6933 100644 --- a/test/built-ins/Atomics/wake/wake-two.js +++ b/test/built-ins/Atomics/wake/wake-two.js @@ -18,9 +18,8 @@ var NUMELEM = 2; var WAKECOUNT = 2; for ( var i=0 ; i < NUMAGENT ; i++ ) { -$262.agent.start( -` -$262.agent.receiveBroadcast(function (sab) { +$262.agent.start(` +$262.agent.receiveBroadcast(function(sab) { var ia = new Int32Array(sab); Atomics.add(ia, ${RUNNING}, 1); // Waiters that are not woken will time out eventually. @@ -62,7 +61,7 @@ for (var i = WAKECOUNT; i < NUMAGENT; i++) { function getReport() { var r; while ((r = $262.agent.getReport()) == null) { - $262.agent.sleep(100); + $262.agent.sleep(10); } return r; } diff --git a/test/built-ins/Atomics/wake/wake-with-no-agents-waiting.js b/test/built-ins/Atomics/wake/wake-with-no-agents-waiting.js index a5fabee90e..b791ef7b26 100644 --- a/test/built-ins/Atomics/wake/wake-with-no-agents-waiting.js +++ b/test/built-ins/Atomics/wake/wake-with-no-agents-waiting.js @@ -9,9 +9,8 @@ features: [Atomics, SharedArrayBuffer, TypedArray] ---*/ -$262.agent.start( -` -$262.agent.receiveBroadcast(function (sab) { +$262.agent.start(` +$262.agent.receiveBroadcast(function(sab) { var ia = new Int32Array(sab); Atomics.add(ia, 1, 1); $262.agent.leaving(); diff --git a/test/built-ins/Atomics/wake/wake-with-no-matching-agents-waiting.js b/test/built-ins/Atomics/wake/wake-with-no-matching-agents-waiting.js index a88f349e60..9622bb67a2 100644 --- a/test/built-ins/Atomics/wake/wake-with-no-matching-agents-waiting.js +++ b/test/built-ins/Atomics/wake/wake-with-no-matching-agents-waiting.js @@ -10,9 +10,8 @@ features: [Atomics, SharedArrayBuffer, TypedArray] ---*/ -$262.agent.start( -` -$262.agent.receiveBroadcast(function (sab) { +$262.agent.start(` +$262.agent.receiveBroadcast(function(sab) { var ia = new Int32Array(sab); Atomics.add(ia, 1, 1); $262.agent.leaving(); diff --git a/test/built-ins/Atomics/wake/wake-zero.js b/test/built-ins/Atomics/wake/wake-zero.js index a82ab8415c..b32134ba64 100644 --- a/test/built-ins/Atomics/wake/wake-zero.js +++ b/test/built-ins/Atomics/wake/wake-zero.js @@ -16,9 +16,8 @@ var NUMELEM = 2; var WAKECOUNT = 0; for ( var i=0 ; i < NUMAGENT ; i++ ) { -$262.agent.start( -` -$262.agent.receiveBroadcast(function (sab) { +$262.agent.start(` +$262.agent.receiveBroadcast(function(sab) { var ia = new Int32Array(sab); Atomics.add(ia, ${RUNNING}, 1); // Waiters that are not woken will time out eventually. @@ -59,8 +58,9 @@ for (var i = WAKECOUNT; i < NUMAGENT; i++) { function getReport() { var r; - while ((r = $262.agent.getReport()) == null) + while ((r = $262.agent.getReport()) == null) { $262.agent.sleep(10); + } return r; } diff --git a/test/built-ins/Atomics/xor/bigint/bad-range.js b/test/built-ins/Atomics/xor/bigint/bad-range.js new file mode 100644 index 0000000000..3837ea022f --- /dev/null +++ b/test/built-ins/Atomics/xor/bigint/bad-range.js @@ -0,0 +1,19 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.xor +description: > + Test range checking of Atomics.xor on arrays that allow atomic operations +includes: [testAtomics.js, testBigIntTypedArray.js] +features: [ArrayBuffer, arrow-function, Atomics, BigInt, DataView, for-of, let, SharedArrayBuffer, TypedArray] +---*/ + +var sab = new SharedArrayBuffer(8); + +testWithBigIntTypedArrayConstructors(function(TA) { + let view = new TA(sab); + testWithAtomicsOutOfBoundsIndices(function(IdxGen) { + assert.throws(RangeError, () => Atomics.xor(view, IdxGen(view), 0)); + }); +}); diff --git a/test/built-ins/Atomics/xor/bigint/good-views.js b/test/built-ins/Atomics/xor/bigint/good-views.js new file mode 100644 index 0000000000..490bdb2dcc --- /dev/null +++ b/test/built-ins/Atomics/xor/bigint/good-views.js @@ -0,0 +1,61 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.xor +description: Test Atomics.xor on arrays that allow atomic operations +includes: [testAtomics.js, testBigIntTypedArray.js] +features: [ArrayBuffer, Atomics, BigInt, computed-property-names, DataView, for-of, let, SharedArrayBuffer, TypedArray] +---*/ + +var sab = new SharedArrayBuffer(1024); +var ab = new ArrayBuffer(16); + +testWithBigIntTypedArrayConstructors(function(TA) { + // Make it interesting - use non-zero byteOffsets and non-zero indexes. + + var view = new TA(sab, 32, 20); + var control = new TA(ab, 0, 2); + + view[8] = 0x33333333; + control[0] = 0x33333333; + assert.sameValue(Atomics.xor(view, 8, 0x55555555), control[0], + "Result is subject to chopping"); + + control[0] = 0x66666666; + assert.sameValue(view[8], control[0]); + assert.sameValue(Atomics.xor(view, 8, 0xF0F0F0F0), control[0], + "Result is subject to chopping"); + + control[0] = 0x96969696; + assert.sameValue(view[8], control[0]); + + view[3] = -5; + control[0] = -5; + assert.sameValue(Atomics.xor(view, 3, 0), control[0], + "Result is negative and subject to coercion"); + assert.sameValue(view[3], control[0]); + + control[0] = 12345; + view[3] = 12345; + assert.sameValue(Atomics.xor(view, 3, 0), control[0], + "Result is subject to chopping"); + assert.sameValue(view[3], control[0]); + + // And again + control[0] = 123456789; + view[3] = 123456789; + assert.sameValue(Atomics.xor(view, 3, 0), control[0], + "Result is subject to chopping"); + assert.sameValue(view[3], control[0]); + + // In-bounds boundary cases for indexing + testWithAtomicsInBoundsIndices(function(IdxGen) { + let Idx = IdxGen(view); + view.fill(0); + // 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); + assert.sameValue(Atomics.xor(view, Idx, 0), 37); + }); +}); diff --git a/test/built-ins/Atomics/xor/bigint/nonshared-int-views.js b/test/built-ins/Atomics/xor/bigint/nonshared-int-views.js new file mode 100644 index 0000000000..4bba3226fa --- /dev/null +++ b/test/built-ins/Atomics/xor/bigint/nonshared-int-views.js @@ -0,0 +1,16 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.xor +description: > + Test Atomics.xor on non-shared integer TypedArrays +includes: [testBigIntTypedArray.js] +features: [ArrayBuffer, arrow-function, Atomics, BigInt, TypedArray] +---*/ + +var buffer = new ArrayBuffer(16); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(TypeError, (() => Atomics.xor(new TA(buffer), 0, 0))); +});