From 1f977dc9fcaacb457e82e4321e1a0d5cf292e608 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Wed, 13 May 2020 16:24:24 -0400 Subject: [PATCH] Atomics.exchange will operate on TA when TA.buffer is not a SharedArrayBuffer --- .../exchange/bigint/non-shared-bufferdata.js | 16 +++++++++++++++ .../bigint/non-shared-int-views-throws.js | 19 ++++++++++++++++++ .../exchange/bigint/nonshared-int-views.js | 16 --------------- .../Atomics/exchange/non-shared-bufferdata.js | 17 ++++++++++++++++ .../exchange/non-shared-int-views-throws.js | 20 +++++++++++++++++++ 5 files changed, 72 insertions(+), 16 deletions(-) create mode 100644 test/built-ins/Atomics/exchange/bigint/non-shared-bufferdata.js create mode 100644 test/built-ins/Atomics/exchange/bigint/non-shared-int-views-throws.js delete mode 100644 test/built-ins/Atomics/exchange/bigint/nonshared-int-views.js create mode 100644 test/built-ins/Atomics/exchange/non-shared-bufferdata.js create mode 100644 test/built-ins/Atomics/exchange/non-shared-int-views-throws.js diff --git a/test/built-ins/Atomics/exchange/bigint/non-shared-bufferdata.js b/test/built-ins/Atomics/exchange/bigint/non-shared-bufferdata.js new file mode 100644 index 0000000000..b0385a834a --- /dev/null +++ b/test/built-ins/Atomics/exchange/bigint/non-shared-bufferdata.js @@ -0,0 +1,16 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.exchange +description: > + Atomics.exchange will operate on TA when TA.buffer is not a SharedArrayBuffer +features: [ArrayBuffer, Atomics, BigInt, TypedArray] +---*/ + +const i64a = new BigInt64Array( + new ArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4) +); + +assert.sameValue(Atomics.exchange(i64a, 0, 1n), 0n); +assert.sameValue(Atomics.load(i64a, 0), 1n); diff --git a/test/built-ins/Atomics/exchange/bigint/non-shared-int-views-throws.js b/test/built-ins/Atomics/exchange/bigint/non-shared-int-views-throws.js new file mode 100644 index 0000000000..29290e6620 --- /dev/null +++ b/test/built-ins/Atomics/exchange/bigint/non-shared-int-views-throws.js @@ -0,0 +1,19 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.exchange +description: > + Atomics.exchange throws when operating on non-sharable integer TypedArrays +includes: [testBigIntTypedArray.js] +features: [ArrayBuffer, Atomics, BigInt, TypedArray] +---*/ + +const buffer = new ArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4); + +testWithNonShareableBigIntTypedArrayConstructors(function(TA) { + const view = new TA(buffer); + assert.throws(TypeError, function() { + Atomics.exchange(view, 0, 0n); + }, `Atomics.exchange(new ${TA.name}(view), 0, 0n) throws TypeError`); +}); diff --git a/test/built-ins/Atomics/exchange/bigint/nonshared-int-views.js b/test/built-ins/Atomics/exchange/bigint/nonshared-int-views.js deleted file mode 100644 index 0d8e607b48..0000000000 --- a/test/built-ins/Atomics/exchange/bigint/nonshared-int-views.js +++ /dev/null @@ -1,16 +0,0 @@ -// 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(BigInt64Array.BYTES_PER_ELEMENT * 2); - -testWithBigIntTypedArrayConstructors(function(TA) { - assert.throws(TypeError, function() { - Atomics.exchange(new TA(buffer), 0n, 0n); - }, '`Atomics.exchange(new TA(buffer), 0n, 0n)` throws TypeError'); -}); diff --git a/test/built-ins/Atomics/exchange/non-shared-bufferdata.js b/test/built-ins/Atomics/exchange/non-shared-bufferdata.js new file mode 100644 index 0000000000..4681feb338 --- /dev/null +++ b/test/built-ins/Atomics/exchange/non-shared-bufferdata.js @@ -0,0 +1,17 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.exchange +description: > + Atomics.exchange will operate on TA when TA.buffer is not a SharedArrayBuffer +features: [ArrayBuffer, Atomics, TypedArray] +---*/ + +const i32a = new Int32Array( + new ArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4) +); + +assert.sameValue(Atomics.exchange(i32a, 0, 1), 0); +assert.sameValue(Atomics.load(i32a, 0), 1); + diff --git a/test/built-ins/Atomics/exchange/non-shared-int-views-throws.js b/test/built-ins/Atomics/exchange/non-shared-int-views-throws.js new file mode 100644 index 0000000000..4ddc2e36e5 --- /dev/null +++ b/test/built-ins/Atomics/exchange/non-shared-int-views-throws.js @@ -0,0 +1,20 @@ +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.add +description: > + Atomics.add throws when operating on non-sharable integer TypedArrays +includes: [testTypedArray.js] +features: [ArrayBuffer, Atomics, TypedArray] +---*/ + +const buffer = new ArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4); + +testWithNonSharableTypedArrayConstructors(function(TA) { + const view = new TA(buffer); + + assert.throws(TypeError, function() { + Atomics.add(view, 0, 1); + }, `Atomics.add(new ${TA.name}(view), 0, 1) throws TypeError`); +});