Atomics.load will operate on TA when TA.buffer is not a SharedArrayBuffer

This commit is contained in:
Rick Waldron 2020-05-06 15:26:38 -04:00
parent 302f37eeff
commit 11a1eabcc6
7 changed files with 90 additions and 31 deletions

View File

@ -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]);
}

View File

@ -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

View File

@ -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);

View File

@ -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`);
});

View File

@ -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');
});

View File

@ -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);

View File

@ -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`);
});