From b4517aa192f5025d7d5eb3ada7c5c278690b4271 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Wed, 13 May 2020 13:24:51 -0400 Subject: [PATCH] Atomics.add will operate on TA when TA.buffer is not a SharedArrayBuffer --- .../add/bigint/non-shared-bufferdata.js | 16 +++++++++++++++ .../add/bigint/non-shared-int-views-throws.js | 19 ++++++++++++++++++ .../Atomics/add/bigint/nonshared-int-views.js | 16 --------------- .../Atomics/add/non-shared-bufferdata.js | 17 ++++++++++++++++ .../add/non-shared-int-views-throws.js | 20 +++++++++++++++++++ .../Atomics/add/nonshared-int-views.js | 19 ------------------ 6 files changed, 72 insertions(+), 35 deletions(-) create mode 100644 test/built-ins/Atomics/add/bigint/non-shared-bufferdata.js create mode 100644 test/built-ins/Atomics/add/bigint/non-shared-int-views-throws.js delete mode 100644 test/built-ins/Atomics/add/bigint/nonshared-int-views.js create mode 100644 test/built-ins/Atomics/add/non-shared-bufferdata.js create mode 100644 test/built-ins/Atomics/add/non-shared-int-views-throws.js delete mode 100644 test/built-ins/Atomics/add/nonshared-int-views.js diff --git a/test/built-ins/Atomics/add/bigint/non-shared-bufferdata.js b/test/built-ins/Atomics/add/bigint/non-shared-bufferdata.js new file mode 100644 index 0000000000..ad0029cc5f --- /dev/null +++ b/test/built-ins/Atomics/add/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.add +description: > + Atomics.add 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.add(i64a, 0, 1n), 0n); +assert.sameValue(Atomics.load(i64a, 0), 1n); diff --git a/test/built-ins/Atomics/add/bigint/non-shared-int-views-throws.js b/test/built-ins/Atomics/add/bigint/non-shared-int-views-throws.js new file mode 100644 index 0000000000..bbbb29111f --- /dev/null +++ b/test/built-ins/Atomics/add/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.add +description: > + Atomics.add 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.add(view, 0, 1n); + }, `Atomics.add(new ${TA.name}(view), 0, 1n) throws TypeError`); +}); diff --git a/test/built-ins/Atomics/add/bigint/nonshared-int-views.js b/test/built-ins/Atomics/add/bigint/nonshared-int-views.js deleted file mode 100644 index 919a01d439..0000000000 --- a/test/built-ins/Atomics/add/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.add -description: > - Test Atomics.add on non-shared integer TypedArrays -includes: [testBigIntTypedArray.js] -features: [ArrayBuffer, arrow-function, Atomics, BigInt, TypedArray] ----*/ -var ab = new ArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 2); - -testWithBigIntTypedArrayConstructors(function(TA) { - assert.throws(TypeError, function() { - Atomics.add(new TA(ab), 0, 0n); - }, '`Atomics.add(new TA(ab), 0, 0n)` throws TypeError'); -}); diff --git a/test/built-ins/Atomics/add/non-shared-bufferdata.js b/test/built-ins/Atomics/add/non-shared-bufferdata.js new file mode 100644 index 0000000000..ffa2371270 --- /dev/null +++ b/test/built-ins/Atomics/add/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.add +description: > + Atomics.add 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.add(i32a, 0, 1), 0); +assert.sameValue(Atomics.load(i32a, 0), 1); + diff --git a/test/built-ins/Atomics/add/non-shared-int-views-throws.js b/test/built-ins/Atomics/add/non-shared-int-views-throws.js new file mode 100644 index 0000000000..4ddc2e36e5 --- /dev/null +++ b/test/built-ins/Atomics/add/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`); +}); diff --git a/test/built-ins/Atomics/add/nonshared-int-views.js b/test/built-ins/Atomics/add/nonshared-int-views.js deleted file mode 100644 index fd90fa0054..0000000000 --- a/test/built-ins/Atomics/add/nonshared-int-views.js +++ /dev/null @@ -1,19 +0,0 @@ -// 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: > - Test Atomics.add on non-shared integer TypedArrays -includes: [testTypedArray.js] -features: [ArrayBuffer, Atomics, TypedArray] ----*/ - -const ab = new ArrayBuffer(16); -const views = intArrayConstructors.slice(); - -testWithTypedArrayConstructors(function(TA) { - assert.throws(TypeError, function() { - Atomics.add(new TA(ab), 0, 0); - }, '`Atomics.add(new TA(ab), 0, 0)` throws TypeError'); -}, views);