From 11a1eabcc627ff46190c9b84631fdfac57434431 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Wed, 6 May 2020 15:26:38 -0400 Subject: [PATCH] Atomics.load will operate on TA when TA.buffer is not a SharedArrayBuffer --- harness/testBigIntTypedArray.js | 19 ++++++++++++++--- harness/testTypedArray.js | 20 ++++++++++++++++++ .../load/bigint/non-shared-bufferdata.js | 15 +++++++++++++ .../bigint/non-shared-int-views-throws.js | 19 +++++++++++++++++ .../load/bigint/nonshared-int-views.js | 21 ------------------- .../Atomics/load/non-shared-bufferdata.js | 15 +++++++++++++ ...iews.js => non-shared-int-views-throws.js} | 12 +++++------ 7 files changed, 90 insertions(+), 31 deletions(-) create mode 100644 test/built-ins/Atomics/load/bigint/non-shared-bufferdata.js create mode 100644 test/built-ins/Atomics/load/bigint/non-shared-int-views-throws.js delete mode 100644 test/built-ins/Atomics/load/bigint/nonshared-int-views.js create mode 100644 test/built-ins/Atomics/load/non-shared-bufferdata.js rename test/built-ins/Atomics/load/{nonshared-int-views.js => non-shared-int-views-throws.js} (57%) diff --git a/harness/testBigIntTypedArray.js b/harness/testBigIntTypedArray.js index 5db37178b9..c9d559de09 100644 --- a/harness/testBigIntTypedArray.js +++ b/harness/testBigIntTypedArray.js @@ -3,7 +3,10 @@ /*--- description: | Collection of functions used to assert the correctness of BigInt TypedArray objects. -defines: [TypedArray, testWithBigIntTypedArrayConstructors] +defines: + - TypedArray + - testWithBigIntTypedArrayConstructors + - testWithNonShareableBigIntTypedArrayConstructors ---*/ /** @@ -15,12 +18,13 @@ var TypedArray = Object.getPrototypeOf(Int8Array); * Calls the provided function for every typed array constructor. * * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays */ -function testWithBigIntTypedArrayConstructors(f) { +function testWithBigIntTypedArrayConstructors(f, selected) { /** * Array containing every BigInt typed array constructor. */ - var constructors = [ + var constructors = selected || [ BigInt64Array, BigUint64Array ]; @@ -35,3 +39,12 @@ function testWithBigIntTypedArrayConstructors(f) { } } } + +/** + * Calls the provided function for every NON SHARABLE bigint typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + */ +function testWithNonShareableBigIntTypedArrayConstructors(f) { + testWithBigIntTypedArrayConstructors(f, [BigUint64Array]); +} diff --git a/harness/testTypedArray.js b/harness/testTypedArray.js index 13b2387835..8d91ab3a6b 100644 --- a/harness/testTypedArray.js +++ b/harness/testTypedArray.js @@ -9,6 +9,7 @@ defines: - intArrayConstructors - TypedArray - testWithTypedArrayConstructors + - testWithNonSharableTypedArrayConstructors - testTypedArrayConversions ---*/ @@ -61,6 +62,25 @@ function testWithTypedArrayConstructors(f, selected) { } } +/** + * Calls the provided function for every NON SHARABLE typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithNonSharableTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Float64Array, + Float32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray + ]); +} + /** * Helper for conversion operations on TypedArrays, the expected values * properties are indexed in order to match the respective value for each diff --git a/test/built-ins/Atomics/load/bigint/non-shared-bufferdata.js b/test/built-ins/Atomics/load/bigint/non-shared-bufferdata.js new file mode 100644 index 0000000000..414e3b1b80 --- /dev/null +++ b/test/built-ins/Atomics/load/bigint/non-shared-bufferdata.js @@ -0,0 +1,15 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.load +description: > + Atomics.load 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.load(i64a, 0), 0n); diff --git a/test/built-ins/Atomics/load/bigint/non-shared-int-views-throws.js b/test/built-ins/Atomics/load/bigint/non-shared-int-views-throws.js new file mode 100644 index 0000000000..f47ceb655d --- /dev/null +++ b/test/built-ins/Atomics/load/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.load +description: > + Atomics.load 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.load(view, 0); + }, `Atomics.load(new ${TA.name}(view), 0) throws TypeError`); +}); diff --git a/test/built-ins/Atomics/load/bigint/nonshared-int-views.js b/test/built-ins/Atomics/load/bigint/nonshared-int-views.js deleted file mode 100644 index 949fb74596..0000000000 --- a/test/built-ins/Atomics/load/bigint/nonshared-int-views.js +++ /dev/null @@ -1,21 +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.load -description: > - Test Atomics.load 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) { - var view = new TA(ab); - - assert.throws(TypeError, function() { - Atomics.load(view, 0); - }, '`Atomics.load(view, 0)` throws TypeError'); -}); diff --git a/test/built-ins/Atomics/load/non-shared-bufferdata.js b/test/built-ins/Atomics/load/non-shared-bufferdata.js new file mode 100644 index 0000000000..0d08d772c6 --- /dev/null +++ b/test/built-ins/Atomics/load/non-shared-bufferdata.js @@ -0,0 +1,15 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.load +description: > + Atomics.load 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.load(i32a, 0), 0); diff --git a/test/built-ins/Atomics/load/nonshared-int-views.js b/test/built-ins/Atomics/load/non-shared-int-views-throws.js similarity index 57% rename from test/built-ins/Atomics/load/nonshared-int-views.js rename to test/built-ins/Atomics/load/non-shared-int-views-throws.js index 58f04ddc7a..1bda4bb893 100644 --- a/test/built-ins/Atomics/load/nonshared-int-views.js +++ b/test/built-ins/Atomics/load/non-shared-int-views-throws.js @@ -4,18 +4,16 @@ /*--- esid: sec-atomics.load description: > - Test Atomics.load on non-shared integer TypedArrays + Atomics.load throws when operating on non-sharable integer TypedArrays includes: [testTypedArray.js] features: [ArrayBuffer, Atomics, TypedArray] ---*/ -const buffer = new ArrayBuffer(16); -const views = intArrayConstructors.slice(); +const buffer = new ArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4); -testWithTypedArrayConstructors(function(TA) { +testWithNonSharableTypedArrayConstructors(function(TA) { const view = new TA(buffer); - assert.throws(TypeError, function() { Atomics.load(view, 0); - }, '`Atomics.load(view, 0)` throws TypeError'); -}, views); + }, `Atomics.load(new ${TA.name}(view), 0) throws TypeError`); +});