Merge pull request #1533 from rwaldron/1527

Atomics: various corrections, nit-picking and BigInt variants
This commit is contained in:
Leo Balter 2018-06-27 13:49:18 -04:00 committed by GitHub
commit 56091a0c5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
240 changed files with 5639 additions and 2120 deletions

4
.gitignore vendored
View File

@ -11,3 +11,7 @@ node_modules
package-lock.json
yarn.lock
npm-shrinkwrap.json
# Created by test262-harness
*.fail
*.pass

View File

@ -1,9 +1,54 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: |
The amount of slack allowed for testing time-related Atomics methods (i.e.
wait and wake). The absolute value of the difference of the observed time
and the expected time must be epsilon-close.
description: >
Collection of functions used to interact with Atomics.* operations across agent boundaries.
---*/
var $ATOMICS_MAX_TIME_EPSILON = 100;
/**
* The amount of slack allowed for testing time-related Atomics methods (i.e. wait and wake).
* The absolute value of the difference of the observed time and the expected time must
* be epsilon-close.
*/
$262.agent.MAX_TIME_EPSILON = 100;
/**
* @return {String} A report sent from an agent.
*/
{
// This is only necessary because the original
// $262.agent.getReport API was insufficient.
//
// All runtimes currently have their own
// $262.agent.getReport which is wrong, so we
// will pave over it with a corrected version.
//
// Binding $262.agent is necessary to prevent
// breaking SpiderMonkey's $262.agent.getReport
let getReport = $262.agent.getReport.bind($262.agent);
$262.agent.getReport = function() {
var r;
while ((r = getReport()) == null) {
$262.agent.sleep(1);
}
return r;
};
}
/**
* With a given Int32Array, wait until the expected number of agents have reported themselves by
* calling:
*
* Atomics.add(i32a, index, 1);
*
* @param {Int32Array} i32a An Int32Array with a SharedArrayBuffer
* @param {Number} index The index of which all agents will report.
* @param {Number} expected The number of agents that are expected to report as active.
*/
$262.agent.waitUntil = function(i32a, index, expected) {
let agents = 0;
while ((agents = Atomics.load(i32a, index)) !== expected) {
/* nothing */
}
assert.sameValue(agents, expected, `Reporting number of 'agents' equals the value of 'expected' (${expected})`);
};

View File

@ -1,3 +1,4 @@
atomicsHelper: [Atomics]
typeCoercion.js: [Symbol.toPrimitive, BigInt]
testAtomics.js: [ArrayBuffer, Atomics, DataView, SharedArrayBuffer, arrow-function, let, for-of]
testBigIntTypedArray.js: [BigInt, TypedArray]

View File

@ -17,7 +17,7 @@ function testWithAtomicsOutOfBoundsIndices(f) {
var bad_indices = [
(view) => -1,
(view) => view.length,
(view) => view.length*2,
(view) => view.length * 2,
(view) => Number.POSITIVE_INFINITY,
(view) => Number.NEGATIVE_INFINITY,
(view) => ({ valueOf: () => 125 }),
@ -28,7 +28,7 @@ function testWithAtomicsOutOfBoundsIndices(f) {
try {
f(IdxGen);
} catch (e) {
e.message += " (Testing with index gen " + IdxGen + ".)";
e.message += ' (Testing with index gen ' + IdxGen + '.)';
throw e;
}
}
@ -52,7 +52,7 @@ function testWithAtomicsInBoundsIndices(f) {
(view) => 0.5,
(view) => '0.5',
(view) => -0.9,
(view) => ({ password: "qumquat" }),
(view) => ({ password: 'qumquat' }),
(view) => view.length - 1,
(view) => ({ valueOf: () => 0 }),
(view) => ({ toString: () => '0', valueOf: false }) // non-callable valueOf triggers invocation of toString
@ -62,7 +62,7 @@ function testWithAtomicsInBoundsIndices(f) {
try {
f(IdxGen);
} catch (e) {
e.message += " (Testing with index gen " + IdxGen + ".)";
e.message += ' (Testing with index gen ' + IdxGen + '.)';
throw e;
}
}
@ -85,21 +85,21 @@ function testWithAtomicsNonViewValues(f) {
10,
3.14,
new Number(4),
"Hi there",
'Hi there',
new Date,
/a*utomaton/g,
{ password: "qumquat" },
{ password: 'qumquat' },
new DataView(new ArrayBuffer(10)),
new ArrayBuffer(128),
new SharedArrayBuffer(128),
new Error("Ouch"),
new Error('Ouch'),
[1,1,2,3,5,8],
((x) => -x),
new Map(),
new Set(),
new WeakMap(),
new WeakSet(),
Symbol("halleluja"),
Symbol('halleluja'),
// TODO: Proxy?
Object,
Int32Array,
@ -112,8 +112,9 @@ function testWithAtomicsNonViewValues(f) {
try {
f(nonView);
} catch (e) {
e.message += " (Testing with non-view value " + nonView + ".)";
e.message += ' (Testing with non-view value ' + nonView + '.)';
throw e;
}
}
}

View File

@ -14,7 +14,11 @@ includes: [propertyHelper.js]
features: [Atomics, Symbol, Symbol.toStringTag]
---*/
assert.sameValue(Atomics[Symbol.toStringTag], 'Atomics');
assert.sameValue(
Atomics[Symbol.toStringTag],
'Atomics',
'The value of Atomics[Symbol.toStringTag] is "Atomics"'
);
verifyNotEnumerable(Atomics, Symbol.toStringTag);
verifyNotWritable(Atomics, Symbol.toStringTag);

View File

@ -6,20 +6,17 @@ esid: sec-atomics.add
description: >
Test range checking of Atomics.add on arrays that allow atomic operations
includes: [testAtomics.js, testTypedArray.js]
features: [ArrayBuffer, arrow-function, Atomics, BigInt, DataView, for-of, let, SharedArrayBuffer, TypedArray]
features: [ArrayBuffer, arrow-function, Atomics, DataView, for-of, let, SharedArrayBuffer, TypedArray]
---*/
var buffer = new SharedArrayBuffer(8);
var views = intArrayConstructors.slice();
if (typeof BigInt !== "undefined") {
views.push(BigInt64Array);
views.push(BigUint64Array);
}
const buffer = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 2);
const views = intArrayConstructors.slice();
testWithTypedArrayConstructors(function(TA) {
let view = new TA(buffer);
testWithAtomicsOutOfBoundsIndices(function(IdxGen) {
assert.throws(RangeError, () => Atomics.add(view, IdxGen(view), 10));
assert.throws(RangeError, function() {
Atomics.add(view, IdxGen(view), 10);
}, '`Atomics.add(view, IdxGen(view), 10)` throws RangeError');
});
}, views);

View File

@ -0,0 +1,20 @@
// 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(BigInt64Array.BYTES_PER_ELEMENT * 2);
testWithBigIntTypedArrayConstructors(function(TA) {
let view = new TA(buffer);
testWithAtomicsOutOfBoundsIndices(function(IdxGen) {
assert.throws(RangeError, function() {
Atomics.add(view, IdxGen(view), 10n);
}, '`Atomics.add(view, IdxGen(view), 10n)` throws RangeError');
});
});

View File

@ -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, arrow-function, Atomics, BigInt, DataView, for-of, let, SharedArrayBuffer, TypedArray]
---*/
const sab = new SharedArrayBuffer(1024);
const ab = new ArrayBuffer(16);
testWithBigIntTypedArrayConstructors(function(TA) {
const view = new TA(sab, 32, 20);
const control = new TA(ab, 0, 2);
view[8] = 0n;
assert.sameValue(Atomics.add(view, 8, 10n), 0, 'Atomics.add(view, 8, 10n) returns 0');
assert.sameValue(view[8], 10n, 'The value of view[8] is 10n');
assert.sameValue(Atomics.add(view, 8, -5n), 10n, 'Atomics.add(view, 8, -5n) returns 10n');
assert.sameValue(view[8], 5n, 'The value of view[8] is 5n');
view[3] = -5n;
control[0] = -5n;
assert.sameValue(
Atomics.add(view, 3, 0n),
control[0],
'Atomics.add(view, 3, 0n) returns the value of `control[0]` (-5n)'
);
control[0] = 12345n;
view[3] = 12345n;
assert.sameValue(
Atomics.add(view, 3, 0n),
control[0],
'Atomics.add(view, 3, 0n) returns the value of `control[0]` (12345n)'
);
control[0] = 123456789n;
view[3] = 123456789n;
assert.sameValue(
Atomics.add(view, 3, 0n),
control[0],
'Atomics.add(view, 3, 0n) returns the value of `control[0]` (123456789n)'
);
testWithAtomicsInBoundsIndices(function(IdxGen) {
let Idx = IdxGen(view);
view.fill(0);
Atomics.store(view, Idx, 37n);
assert.sameValue(Atomics.add(view, Idx, 0), 37n, 'Atomics.add(view, Idx, 0) returns 37n');
});
});

View File

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

View File

@ -1,4 +1,3 @@
// Copyright 2015 Microsoft Corporation. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
@ -9,6 +8,8 @@ includes: [propertyHelper.js]
features: [Atomics]
---*/
verifyWritable(Atomics, "add");
verifyNotEnumerable(Atomics, "add");
verifyConfigurable(Atomics, "add");
verifyProperty(Atomics, 'add', {
enumerable: false,
writable: true,
configurable: true,
});

View File

@ -0,0 +1,36 @@
// 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: >
Atomics.add returns the value that existed at the
index prior to the operation.
info: |
Atomics.add( typedArray, index, value )
1. Return ? AtomicReadModifyWrite(typedArray, index, value, add).
AtomicReadModifyWrite( typedArray, index, value, op )
...
9. Return GetModifySetValueInBuffer(buffer, indexedPosition,
elementType, v, op).
GetModifySetValueInBuffer( arrayBuffer,
byteIndex, type, value, op [ , isLittleEndian ] )
...
16. Return RawBytesToNumber(type, rawBytesRead, isLittleEndian).
features: [Atomics, SharedArrayBuffer, TypedArray]
---*/
const i32a = new Int32Array(
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
);
const newValue = 0b00000001000000001000000010000001;
assert.sameValue(Atomics.add(i32a, 0, newValue), 0, 'Atomics.add(i32a, 0, newValue) returns 0');
assert.sameValue(i32a[0], newValue, 'The value of i32a[0] equals the value of `newValue` (0b00000001000000001000000010000001)');

View File

@ -8,39 +8,39 @@ includes: [testAtomics.js, testTypedArray.js]
features: [ArrayBuffer, arrow-function, Atomics, DataView, for-of, let, SharedArrayBuffer, TypedArray]
---*/
var sab = new SharedArrayBuffer(1024);
var ab = new ArrayBuffer(16);
var views = intArrayConstructors.slice();
const sab = new SharedArrayBuffer(1024);
const ab = new ArrayBuffer(16);
const views = intArrayConstructors.slice();
testWithTypedArrayConstructors(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);
const view = new TA(sab, 32, 20);
const 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);
assert.sameValue(Atomics.add(view, 8, 10), 0, 'Atomics.add(view, 8, 10) returns 0');
assert.sameValue(view[8], 10, 'The value of view[8] is 10');
// Add negative number
assert.sameValue(Atomics.add(view, 8, -5), 10);
assert.sameValue(view[8], 5);
assert.sameValue(Atomics.add(view, 8, -5), 10, 'Atomics.add(view, 8, -5) returns 10');
assert.sameValue(view[8], 5, 'The value of view[8] is 5');
view[3] = -5;
control[0] = -5;
assert.sameValue(Atomics.add(view, 3, 0), control[0],
"Result is negative and subject to coercion");
'Atomics.add(view, 3, 0) returns the value of `control[0]` (-5)');
control[0] = 12345;
view[3] = 12345;
assert.sameValue(Atomics.add(view, 3, 0), control[0],
"Result is subject to chopping");
'Atomics.add(view, 3, 0) returns the value of `control[0]` (12345)');
control[0] = 123456789;
view[3] = 123456789;
assert.sameValue(Atomics.add(view, 3, 0), control[0],
"Result is subject to chopping");
'Atomics.add(view, 3, 0) returns the value of `control[0]` (123456789)');
// In-bounds boundary cases for indexing
testWithAtomicsInBoundsIndices(function(IdxGen) {
@ -49,6 +49,6 @@ testWithTypedArrayConstructors(function(TA) {
// 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);
assert.sameValue(Atomics.add(view, Idx, 0), 37, 'Atomics.add(view, Idx, 0) returns 37');
});
}, views);

View File

@ -24,8 +24,9 @@ includes: [propertyHelper.js]
features: [Atomics]
---*/
assert.sameValue(Atomics.add.length, 3);
verifyNotEnumerable(Atomics.add, "length");
verifyNotWritable(Atomics.add, "length");
verifyConfigurable(Atomics.add, "length");
verifyProperty(Atomics.add, 'length', {
value: 3,
enumerable: false,
writable: false,
configurable: true,
});

View File

@ -10,8 +10,9 @@ includes: [propertyHelper.js]
features: [Atomics]
---*/
assert.sameValue(Atomics.add.name, "add");
verifyNotEnumerable(Atomics.add, "name");
verifyNotWritable(Atomics.add, "name");
verifyConfigurable(Atomics.add, "name");
verifyProperty(Atomics.add, 'name', {
value: 'add',
enumerable: false,
writable: false,
configurable: true,
});

View File

@ -10,5 +10,7 @@ features: [ArrayBuffer, arrow-function, Atomics, DataView, for-of, let, SharedAr
---*/
testWithAtomicsNonViewValues(function(view) {
assert.throws(TypeError, (() => Atomics.add(view, 0, 0)));
assert.throws(TypeError, function() {
Atomics.add(view, 0, 0);
}, '`Atomics.add(view, 0, 0)` throws TypeError');
});

View File

@ -6,17 +6,14 @@ esid: sec-atomics.add
description: >
Test Atomics.add on non-shared integer TypedArrays
includes: [testTypedArray.js]
features: [ArrayBuffer, Atomics, BigInt, TypedArray]
features: [ArrayBuffer, Atomics, TypedArray]
---*/
var ab = new ArrayBuffer(16);
var views = intArrayConstructors.slice();
if (typeof BigInt !== "undefined") {
views.push(BigInt64Array);
views.push(BigUint64Array);
}
const ab = new ArrayBuffer(16);
const views = intArrayConstructors.slice();
testWithTypedArrayConstructors(function(TA) {
assert.throws(TypeError, (() => Atomics.add(new TA(ab), 0, 0)));
assert.throws(TypeError, function() {
Atomics.add(new TA(ab), 0, 0);
}, '`Atomics.add(new TA(ab), 0, 0)` throws TypeError');
}, views);

View File

@ -9,8 +9,10 @@ includes: [testTypedArray.js]
features: [Atomics, SharedArrayBuffer, TypedArray]
---*/
var buffer = new SharedArrayBuffer(1024);
const buffer = new SharedArrayBuffer(1024);
testWithTypedArrayConstructors(function(TA) {
assert.throws(TypeError, (() => Atomics.add(new TA(buffer), 0, 0)));
assert.throws(TypeError, function() {
Atomics.add(new TA(buffer), 0, 0);
}, '`Atomics.add(new TA(buffer), 0, 0)` throws TypeError');
}, floatArrayConstructors);

View File

@ -6,20 +6,17 @@ esid: sec-atomics.and
description: >
Test range checking of Atomics.and on arrays that allow atomic operations
includes: [testAtomics.js, testTypedArray.js]
features: [ArrayBuffer, arrow-function, Atomics, BigInt, DataView, for-of, let, SharedArrayBuffer, TypedArray]
features: [ArrayBuffer, arrow-function, Atomics, DataView, for-of, let, SharedArrayBuffer, TypedArray]
---*/
var buffer = new SharedArrayBuffer(8);
var views = intArrayConstructors.slice();
if (typeof BigInt !== "undefined") {
views.push(BigInt64Array);
views.push(BigUint64Array);
}
const buffer = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 2);
const views = intArrayConstructors.slice();
testWithTypedArrayConstructors(function(TA) {
let view = new TA(buffer);
const view = new TA(buffer);
testWithAtomicsOutOfBoundsIndices(function(IdxGen) {
assert.throws(RangeError, () => Atomics.and(view, IdxGen(view), 10));
assert.throws(RangeError, function() {
Atomics.and(view, IdxGen(view), 10);
}, '`Atomics.and(view, IdxGen(view), 10)` throws RangeError');
});
}, views);

View File

@ -0,0 +1,20 @@
// 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]
---*/
const buffer = new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 2);
testWithBigIntTypedArrayConstructors(function(TA) {
const view = new TA(buffer);
testWithAtomicsOutOfBoundsIndices(function(IdxGen) {
assert.throws(RangeError, function() {
Atomics.and(view, IdxGen(view), 10n);
}, '`Atomics.and(view, IdxGen(view), 10n)` throws RangeError');
});
});

View File

@ -0,0 +1,83 @@
// 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, arrow-function, Atomics, BigInt, DataView, for-of, let, SharedArrayBuffer, TypedArray]
---*/
const sab = new SharedArrayBuffer(1024);
const ab = new ArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 2);
testWithBigIntTypedArrayConstructors(function(TA) {
const view = new TA(sab, 32, 20);
const control = new TA(ab, 0, 2);
view[8] = 0x33333333n;
control[0] = 0x33333333n;
assert.sameValue(
Atomics.and(view, 8, 0x55555555n),
control[0],
'Atomics.and(view, 8, 0x55555555n) returns the value of `control[0]` (0x33333333n)'
);
control[0] = 0x11111111n;
assert.sameValue(
view[8],
control[0],
'The value of view[8] equals the value of `control[0]` (0x11111111n)'
);
assert.sameValue(
Atomics.and(view, 8, 0xF0F0F0F0n),
control[0],
'Atomics.and(view, 8, 0xF0F0F0F0n) returns the value of `control[0]` (0x11111111n)'
);
control[0] = 0x10101010n;
assert.sameValue(
view[8],
control[0],
'The value of view[8] equals the value of `control[0]` (0x10101010n)'
);
view[3] = -5n;
control[0] = -5n;
assert.sameValue(
Atomics.and(view, 3, 0n),
control[0],
'Atomics.and(view, 3, 0n) returns the value of `control[0]` (-5n)'
);
assert.sameValue(view[3], 0n, 'The value of view[3] is 0n');
control[0] = 12345n;
view[3] = 12345n;
assert.sameValue(
Atomics.and(view, 3, 0n),
control[0],
'Atomics.and(view, 3, 0n) returns the value of `control[0]` (12345n)'
);
assert.sameValue(view[3], 0n, 'The value of view[3] is 0n');
control[0] = 123456789n;
view[3] = 123456789n;
assert.sameValue(
Atomics.and(view, 3, 0n),
control[0],
'Atomics.and(view, 3, 0n) returns the value of `control[0]` (123456789n)'
);
assert.sameValue(view[3], 0n, 'The value of view[3] is 0n');
testWithAtomicsInBoundsIndices(function(IdxGen) {
let Idx = IdxGen(view);
view.fill(0n);
Atomics.store(view, Idx, 37n);
assert.sameValue(Atomics.and(view, Idx, 0n), 37n, 'Atomics.and(view, Idx, 0n) returns 37n');
});
});

View File

@ -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]
---*/
const buffer = new ArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 2);
testWithBigIntTypedArrayConstructors(function(TA) {
assert.throws(TypeError, function() {
Atomics.and(new TA(buffer), 0, 0n);
}, '`Atomics.and(new TA(buffer), 0, 0n)` throws TypeError');
});

View File

@ -1,4 +1,3 @@
// Copyright 2015 Microsoft Corporation. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
@ -9,6 +8,8 @@ includes: [propertyHelper.js]
features: [Atomics]
---*/
verifyWritable(Atomics, "and");
verifyNotEnumerable(Atomics, "and");
verifyConfigurable(Atomics, "and");
verifyProperty(Atomics, 'and', {
enumerable: false,
writable: true,
configurable: true,
});

View File

@ -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.and
description: >
Atomics.and returns the value that existed at the
index prior to the operation.
info: |
Atomics.and( typedArray, index, value )
1. Return ? AtomicReadModifyWrite(typedArray, index, value, and).
AtomicReadModifyWrite( typedArray, index, value, op )
...
9. Return GetModifySetValueInBuffer(buffer, indexedPosition,
elementType, v, op).
GetModifySetValueInBuffer( arrayBuffer,
byteIndex, type, value, op [ , isLittleEndian ] )
...
16. Return RawBytesToNumber(type, rawBytesRead, isLittleEndian).
features: [Atomics, SharedArrayBuffer, TypedArray]
---*/
const i32a = new Int32Array(
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
);
const a = 0b00000001000000001000000010000001;
const b = 0b00000001111111111000000011111111;
const c = 0b00000001000000001000000010000001;
i32a[0] = a;
assert.sameValue(
Atomics.and(i32a, 0, b),
a,
'Atomics.and(i32a, 0, b) returns the value of `a` (0b00000001000000001000000010000001)'
);
assert.sameValue(i32a[0], c, 'The value of i32a[0] equals the value of `c` (0b00000001000000001000000010000001)');

View File

@ -8,46 +8,54 @@ includes: [testAtomics.js, testTypedArray.js]
features: [ArrayBuffer, arrow-function, Atomics, DataView, for-of, let, SharedArrayBuffer, TypedArray]
---*/
var sab = new SharedArrayBuffer(1024);
var ab = new ArrayBuffer(16);
var views = intArrayConstructors.slice();
const sab = new SharedArrayBuffer(1024);
const ab = new ArrayBuffer(16);
const views = intArrayConstructors.slice();
testWithTypedArrayConstructors(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);
const view = new TA(sab, 32, 20);
const 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");
'Atomics.and(view, 8, 0x55555555) returns the value of `control[0]` (0x33333333)');
control[0] = 0x11111111;
assert.sameValue(view[8], control[0]);
assert.sameValue(
view[8],
control[0],
'The value of view[8] equals the value of `control[0]` (0x11111111)'
);
assert.sameValue(Atomics.and(view, 8, 0xF0F0F0F0), control[0],
"Result is subject to chopping");
'Atomics.and(view, 8, 0xF0F0F0F0) returns the value of `control[0]` (0x11111111)');
control[0] = 0x10101010;
assert.sameValue(view[8], control[0]);
assert.sameValue(
view[8],
control[0],
'The value of view[8] equals the value of `control[0]` (0x10101010)'
);
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);
'Atomics.and(view, 3, 0) returns the value of `control[0]` (-5)');
assert.sameValue(view[3], 0, 'The value of view[3] is 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);
'Atomics.and(view, 3, 0) returns the value of `control[0]` (12345)');
assert.sameValue(view[3], 0, 'The value of view[3] is 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);
'Atomics.and(view, 3, 0) returns the value of `control[0]` (123456789)');
assert.sameValue(view[3], 0, 'The value of view[3] is 0');
// In-bounds boundary cases for indexing
testWithAtomicsInBoundsIndices(function(IdxGen) {
@ -56,6 +64,6 @@ testWithTypedArrayConstructors(function(TA) {
// 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);
assert.sameValue(Atomics.and(view, Idx, 0), 37, 'Atomics.and(view, Idx, 0) returns 37');
});
}, views);

View File

@ -24,8 +24,9 @@ includes: [propertyHelper.js]
features: [Atomics]
---*/
assert.sameValue(Atomics.and.length, 3);
verifyNotEnumerable(Atomics.and, "length");
verifyNotWritable(Atomics.and, "length");
verifyConfigurable(Atomics.and, "length");
verifyProperty(Atomics.and, 'length', {
value: 3,
enumerable: false,
writable: false,
configurable: true,
});

View File

@ -10,8 +10,9 @@ includes: [propertyHelper.js]
features: [Atomics]
---*/
assert.sameValue(Atomics.and.name, "and");
verifyNotEnumerable(Atomics.and, "name");
verifyNotWritable(Atomics.and, "name");
verifyConfigurable(Atomics.and, "name");
verifyProperty(Atomics.and, 'name', {
value: 'and',
enumerable: false,
writable: false,
configurable: true,
});

View File

@ -10,5 +10,7 @@ features: [ArrayBuffer, arrow-function, Atomics, DataView, for-of, let, SharedAr
---*/
testWithAtomicsNonViewValues(function(view) {
assert.throws(TypeError, (() => Atomics.and(view, 0, 0)));
assert.throws(TypeError, function() {
Atomics.and(view, 0, 0);
}, '`Atomics.and(view, 0, 0)` throws TypeError');
});

View File

@ -6,17 +6,14 @@ esid: sec-atomics.and
description: >
Test Atomics.and on non-shared integer TypedArrays
includes: [testTypedArray.js]
features: [ArrayBuffer, Atomics, BigInt, TypedArray]
features: [ArrayBuffer, Atomics, TypedArray]
---*/
var buffer = new ArrayBuffer(16);
var views = intArrayConstructors.slice();
if (typeof BigInt !== "undefined") {
views.push(BigInt64Array);
views.push(BigUint64Array);
}
const buffer = new ArrayBuffer(16);
const views = intArrayConstructors.slice();
testWithTypedArrayConstructors(function(TA) {
assert.throws(TypeError, (() => Atomics.and(new TA(buffer), 0, 0)));
assert.throws(TypeError, function() {
Atomics.and(new TA(buffer), 0, 0);
}, '`Atomics.and(new TA(buffer), 0, 0)` throws TypeError');
}, views);

View File

@ -9,8 +9,10 @@ includes: [testTypedArray.js]
features: [Atomics, SharedArrayBuffer, TypedArray]
---*/
var buffer = new SharedArrayBuffer(1024);
const buffer = new SharedArrayBuffer(1024);
testWithTypedArrayConstructors(function(TA) {
assert.throws(TypeError, (() => Atomics.and(new TA(buffer), 0, 0)));
assert.throws(TypeError, function() {
Atomics.and(new TA(buffer), 0, 0);
}, '`Atomics.and(new TA(buffer), 0, 0)` throws TypeError');
}, floatArrayConstructors);

View File

@ -6,20 +6,17 @@ esid: sec-atomics.compareexchange
description: >
Test range checking of Atomics.compareExchange on arrays that allow atomic operations
includes: [testAtomics.js, testTypedArray.js]
features: [ArrayBuffer, arrow-function, Atomics, BigInt, DataView, for-of, let, SharedArrayBuffer, TypedArray]
features: [ArrayBuffer, arrow-function, Atomics, DataView, for-of, let, SharedArrayBuffer, TypedArray]
---*/
var buffer = new SharedArrayBuffer(8);
var views = intArrayConstructors.slice();
if (typeof BigInt !== "undefined") {
views.push(BigInt64Array);
views.push(BigUint64Array);
}
const buffer = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 2);
const views = intArrayConstructors.slice();
testWithTypedArrayConstructors(function(TA) {
let view = new TA(buffer);
const view = new TA(buffer);
testWithAtomicsOutOfBoundsIndices(function(IdxGen) {
assert.throws(RangeError, () => Atomics.compareExchange(view, IdxGen(view), 10, 0));
assert.throws(RangeError, function() {
Atomics.compareExchange(view, IdxGen(view), 10, 0);
}, '`Atomics.compareExchange(view, IdxGen(view), 10, 0)` throws RangeError');
});
}, views);

View File

@ -0,0 +1,20 @@
// 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]
---*/
const buffer = new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 2);
testWithBigIntTypedArrayConstructors(function(TA) {
const view = new TA(buffer);
testWithAtomicsOutOfBoundsIndices(function(IdxGen) {
assert.throws(RangeError, function() {
Atomics.compareExchange(view, IdxGen(view), 10, 0n);
}, '`Atomics.compareExchange(view, IdxGen(view), 10, 0n)` throws RangeError');
});
});

View File

@ -0,0 +1,91 @@
// 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, arrow-function, Atomics, BigInt, DataView, for-of, let, SharedArrayBuffer, TypedArray]
---*/
const sab = new SharedArrayBuffer(1024);
const ab = new ArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 2);
testWithBigIntTypedArrayConstructors(function(TA) {
const view = new TA(sab, 32, 20);
const control = new TA(ab, 0, 2);
view[8] = 0n;
assert.sameValue(
Atomics.compareExchange(view, 8, 0n, 10n),
0n,
'Atomics.compareExchange(view, 8, 0n, 10n) returns 0n'
);
assert.sameValue(view[8], 10n, 'The value of view[8] is 10n');
view[8] = 0n;
assert.sameValue(
Atomics.compareExchange(view, 8, 1n, 10n),
0n,
'Atomics.compareExchange(view, 8, 1n, 10n) returns 0n'
);
assert.sameValue(view[8], 0n, 'The value of view[8] is 0n');
view[8] = 0n;
assert.sameValue(
Atomics.compareExchange(view, 8, 0n, -5n),
0n,
'Atomics.compareExchange(view, 8, 0n, -5n) returns 0n'
);
control[0] = -5n;
assert.sameValue(
view[8],
control[0],
'The value of view[8] equals the value of `control[0]` (-5n)'
);
view[3] = -5n;
control[0] = -5n;
assert.sameValue(
Atomics.compareExchange(view, 3, -5n, 0n),
control[0],
'Atomics.compareExchange(view, 3, -5n, 0n) returns the value of `control[0]` (-5n)'
);
assert.sameValue(view[3], 0n, 'The value of view[3] is 0n');
control[0] = 12345n;
view[3] = 12345n;
assert.sameValue(
Atomics.compareExchange(view, 3, 12345n, 0n),
control[0],
'Atomics.compareExchange(view, 3, 12345n, 0n) returns the value of `control[0]` (12345n)'
);
assert.sameValue(view[3], 0n, 'The value of view[3] is 0n');
control[0] = 123456789n;
view[3] = 123456789n;
assert.sameValue(
Atomics.compareExchange(view, 3, 123456789n, 0n),
control[0],
'Atomics.compareExchange(view, 3, 123456789n, 0n) returns the value of `control[0]` (123456789n)'
);
assert.sameValue(view[3], 0n, 'The value of view[3] is 0n');
testWithAtomicsInBoundsIndices(function(IdxGen) {
let Idx = IdxGen(view);
view.fill(0n);
Atomics.store(view, Idx, 37n);
assert.sameValue(
Atomics.compareExchange(view, Idx, 37n, 0n),
37n,
'Atomics.compareExchange(view, Idx, 37n, 0n) returns 37n'
);
});
});

View File

@ -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]
---*/
const buffer = new ArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 2);
testWithBigIntTypedArrayConstructors(function(TA) {
assert.throws(TypeError, function() {
Atomics.compareExchange(new TA(buffer), 0, 0n, 0n);
}, '`Atomics.compareExchange(new TA(buffer), 0, 0n, 0n)` throws TypeError');
});

View File

@ -1,4 +1,3 @@
// Copyright 2015 Microsoft Corporation. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
@ -9,6 +8,8 @@ includes: [propertyHelper.js]
features: [Atomics]
---*/
verifyWritable(Atomics, "compareExchange");
verifyNotEnumerable(Atomics, "compareExchange");
verifyConfigurable(Atomics, "compareExchange");
verifyProperty(Atomics, 'compareExchange', {
enumerable: false,
writable: true,
configurable: true,
});

View File

@ -0,0 +1,40 @@
// 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: >
Atomics.compareExchange returns the value that existed at the
index prior to the operation.
info: |
Atomics.compareExchange( typedArray, index, expectedValue, replacementValue )
...
12. Let compareExchange denote a semantic function of two List of
byte values arguments that returns the second argument if the
first argument is element-wise equal to expectedBytes.
13. Return GetModifySetValueInBuffer(buffer, indexedPosition,
elementType, replacement, compareExchange).
GetModifySetValueInBuffer( arrayBuffer,
byteIndex, type, value, op [ , isLittleEndian ] )
...
16. Return RawBytesToNumber(type, rawBytesRead, isLittleEndian).
features: [Atomics, SharedArrayBuffer, TypedArray]
---*/
const buffer = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4);
const i32a = new Int32Array(buffer);
const update = 0b00000001000000001000000010000001;
i32a[0] = update;
assert.sameValue(
Atomics.compareExchange(i32a, 0, update, 0),
update,
'Atomics.compareExchange(i32a, 0, update, 0) returns the value of `update` (0b00000001000000001000000010000001)'
);
assert.sameValue(i32a[0], 0, 'The value of i32a[0] is 0');

View File

@ -8,51 +8,55 @@ includes: [testAtomics.js, testTypedArray.js]
features: [ArrayBuffer, arrow-function, Atomics, DataView, for-of, let, SharedArrayBuffer, TypedArray]
---*/
var sab = new SharedArrayBuffer(1024);
var ab = new ArrayBuffer(16);
var views = intArrayConstructors.slice();
const sab = new SharedArrayBuffer(1024);
const ab = new ArrayBuffer(16);
const views = intArrayConstructors.slice();
testWithTypedArrayConstructors(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);
const view = new TA(sab, 32, 20);
const 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);
assert.sameValue(
Atomics.compareExchange(view, 8, 0, 10),
0,
'Atomics.compareExchange(view, 8, 0, 10) returns 0'
);
assert.sameValue(view[8], 10, 'The value of view[8] is 10');
view[8] = 0;
assert.sameValue(Atomics.compareExchange(view, 8, 1, 10), 0,
"Does not perform the exchange");
assert.sameValue(view[8], 0);
'Atomics.compareExchange(view, 8, 1, 10) returns 0');
assert.sameValue(view[8], 0, 'The value of view[8] is 0');
view[8] = 0;
assert.sameValue(Atomics.compareExchange(view, 8, 0, -5), 0,
"Performs the exchange, coercing the value being stored");
'Atomics.compareExchange(view, 8, 0, -5) returns 0');
control[0] = -5;
assert.sameValue(view[8], control[0]);
assert.sameValue(view[8], control[0], 'The value of view[8] equals the value of `control[0]` (-5)');
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);
'Atomics.compareExchange(view, 3, -5, 0) returns the value of `control[0]` (-5)');
assert.sameValue(view[3], 0, 'The value of view[3] is 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);
'Atomics.compareExchange(view, 3, 12345, 0) returns the value of `control[0]` (12345)');
assert.sameValue(view[3], 0, 'The value of view[3] is 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);
'Atomics.compareExchange(view, 3, 123456789, 0) returns the value of `control[0]` (123456789)');
assert.sameValue(view[3], 0, 'The value of view[3] is 0');
// In-bounds boundary cases for indexing
testWithAtomicsInBoundsIndices(function(IdxGen) {
@ -61,6 +65,10 @@ testWithTypedArrayConstructors(function(TA) {
// 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);
assert.sameValue(
Atomics.compareExchange(view, Idx, 37, 0),
37,
'Atomics.compareExchange(view, Idx, 37, 0) returns 37'
);
});
}, views);

View File

@ -24,8 +24,9 @@ includes: [propertyHelper.js]
features: [Atomics]
---*/
assert.sameValue(Atomics.compareExchange.length, 4);
verifyNotEnumerable(Atomics.compareExchange, "length");
verifyNotWritable(Atomics.compareExchange, "length");
verifyConfigurable(Atomics.compareExchange, "length");
verifyProperty(Atomics.compareExchange, 'length', {
value: 4,
enumerable: false,
writable: false,
configurable: true,
});

View File

@ -10,8 +10,9 @@ includes: [propertyHelper.js]
features: [Atomics]
---*/
assert.sameValue(Atomics.compareExchange.name, "compareExchange");
verifyNotEnumerable(Atomics.compareExchange, "name");
verifyNotWritable(Atomics.compareExchange, "name");
verifyConfigurable(Atomics.compareExchange, "name");
verifyProperty(Atomics.compareExchange, 'name', {
value: 'compareExchange',
enumerable: false,
writable: false,
configurable: true,
});

View File

@ -10,5 +10,7 @@ features: [ArrayBuffer, arrow-function, Atomics, DataView, for-of, let, SharedAr
---*/
testWithAtomicsNonViewValues(function(view) {
assert.throws(TypeError, (() => Atomics.compareExchange(view, 0, 0, 0)));
assert.throws(TypeError, function() {
Atomics.compareExchange(view, 0, 0, 0);
}, '`Atomics.compareExchange(view, 0, 0, 0)` throws TypeError');
});

View File

@ -6,17 +6,14 @@ esid: sec-atomics.compareexchange
description: >
Test Atomics.compareExchange on non-shared integer TypedArrays
includes: [testTypedArray.js]
features: [ArrayBuffer, Atomics, BigInt, TypedArray]
features: [ArrayBuffer, Atomics, TypedArray]
---*/
var buffer = new ArrayBuffer(16);
var views = intArrayConstructors.slice();
if (typeof BigInt !== "undefined") {
views.push(BigInt64Array);
views.push(BigUint64Array);
}
testWithTypedArrayConstructors(function(TA) {
assert.throws(TypeError, (() => Atomics.compareExchange(new TA(buffer), 0, 0, 0)));
assert.throws(TypeError, function() {
Atomics.compareExchange(new TA(buffer), 0, 0, 0);
}, '`Atomics.compareExchange(new TA(buffer), 0, 0, 0)` throws TypeError');
}, views);

View File

@ -12,5 +12,7 @@ features: [Atomics, SharedArrayBuffer, TypedArray]
var buffer = new SharedArrayBuffer(1024);
testWithTypedArrayConstructors(function(TA) {
assert.throws(TypeError, (() => Atomics.compareExchange(new TA(buffer), 0, 0, 0)));
assert.throws(TypeError, function() {
Atomics.compareExchange(new TA(buffer), 0, 0, 0);
}, '`Atomics.compareExchange(new TA(buffer), 0, 0, 0)` throws TypeError');
}, floatArrayConstructors);

View File

@ -6,20 +6,17 @@ esid: sec-atomics.exchange
description: >
Test range checking of Atomics.exchange on arrays that allow atomic operations
includes: [testAtomics.js, testTypedArray.js]
features: [ArrayBuffer, arrow-function, Atomics, BigInt, DataView, for-of, let, SharedArrayBuffer, TypedArray]
features: [ArrayBuffer, arrow-function, Atomics, DataView, for-of, let, SharedArrayBuffer, TypedArray]
---*/
var buffer = new SharedArrayBuffer(8);
var views = intArrayConstructors.slice();
if (typeof BigInt !== "undefined") {
views.push(BigInt64Array);
views.push(BigUint64Array);
}
const buffer = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 2);
const views = intArrayConstructors.slice();
testWithTypedArrayConstructors(function(TA) {
let view = new TA(buffer);
const view = new TA(buffer);
testWithAtomicsOutOfBoundsIndices(function(IdxGen) {
assert.throws(RangeError, () => Atomics.exchange(view, IdxGen(view), 10, 0));
assert.throws(RangeError, function() {
Atomics.exchange(view, IdxGen(view), 10, 0);
}, '`Atomics.exchange(view, IdxGen(view), 10, 0)` throws RangeError');
});
}, views);

View File

@ -0,0 +1,20 @@
// 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(BigInt64Array.BYTES_PER_ELEMENT * 2);
testWithBigIntTypedArrayConstructors(function(TA) {
let view = new TA(buffer);
testWithAtomicsOutOfBoundsIndices(function(IdxGen) {
assert.throws(RangeError, function() {
Atomics.exchange(view, IdxGen(view), 10n, 0n);
}, '`Atomics.exchange(view, IdxGen(view), 10n, 0n)` throws RangeError');
});
});

View File

@ -0,0 +1,71 @@
// 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, arrow-function, Atomics, BigInt, DataView, for-of, let, SharedArrayBuffer, TypedArray]
---*/
const sab = new SharedArrayBuffer(1024);
const ab = new ArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 2);
testWithBigIntTypedArrayConstructors(function(TA) {
const view = new TA(sab, 32, 20);
const control = new TA(ab, 0, 2);
view[8] = 0n;
assert.sameValue(Atomics.exchange(view, 8, 10n), 0n, 'Atomics.exchange(view, 8, 10n) returns 0n');
assert.sameValue(view[8], 10n, 'The value of view[8] is 10n');
assert.sameValue(
Atomics.exchange(view, 8, -5n),
10n,
'Atomics.exchange(view, 8, -5n) returns 10n'
);
control[0] = -5n;
assert.sameValue(
view[8],
control[0],
'The value of view[8] equals the value of `control[0]` (-5n)'
);
view[3] = -5n;
control[0] = -5n;
assert.sameValue(
Atomics.exchange(view, 3, 0n),
control[0],
'Atomics.exchange(view, 3, 0n) returns the value of `control[0]` (-5n)'
);
control[0] = 12345n;
view[3] = 12345n;
assert.sameValue(
Atomics.exchange(view, 3, 0n),
control[0],
'Atomics.exchange(view, 3, 0n) returns the value of `control[0]` (12345n)'
);
control[0] = 123456789n;
view[3] = 123456789n;
assert.sameValue(
Atomics.exchange(view, 3, 0n),
control[0],
'Atomics.exchange(view, 3, 0n) returns the value of `control[0]` (123456789n)'
);
testWithAtomicsInBoundsIndices(function(IdxGen) {
let Idx = IdxGen(view);
view.fill(0n);
Atomics.store(view, Idx, 37n);
assert.sameValue(
Atomics.exchange(view, Idx, 0n),
37n,
'Atomics.exchange(view, Idx, 0n) returns 37n'
);
});
});

View File

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

View File

@ -1,4 +1,3 @@
// Copyright 2015 Microsoft Corporation. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
@ -9,6 +8,8 @@ includes: [propertyHelper.js]
features: [Atomics]
---*/
verifyWritable(Atomics, "exchange");
verifyNotEnumerable(Atomics, "exchange");
verifyConfigurable(Atomics, "exchange");
verifyProperty(Atomics, 'exchange', {
enumerable: false,
writable: true,
configurable: true,
});

View File

@ -0,0 +1,44 @@
// 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: >
Atomics.and returns the value that existed at the
index prior to the operation.
info: |
Atomics.exchange( typedArray, index, value )
1. Return ? AtomicReadModifyWrite(typedArray, index, value, second).
AtomicReadModifyWrite( typedArray, index, value, op )
...
9. Return GetModifySetValueInBuffer(buffer, indexedPosition,
elementType, v, op).
GetModifySetValueInBuffer( arrayBuffer,
byteIndex, type, value, op [ , isLittleEndian ] )
...
16. Return RawBytesToNumber(type, rawBytesRead, isLittleEndian).
features: [Atomics, SharedArrayBuffer, TypedArray]
---*/
const i32a = new Int32Array(
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
);
const update = 0b00000001000000001000000010000001;
assert.sameValue(
Atomics.exchange(i32a, 0, update),
0,
'Atomics.exchange(i32a, 0, update) returns 0'
);
assert.sameValue(
i32a[0],
update,
'The value of i32a[0] equals the value of `update` (0b00000001000000001000000010000001)'
);

View File

@ -8,40 +8,40 @@ includes: [testAtomics.js, testTypedArray.js]
features: [ArrayBuffer, arrow-function, Atomics, DataView, for-of, let, SharedArrayBuffer, TypedArray]
---*/
var sab = new SharedArrayBuffer(1024);
var ab = new ArrayBuffer(16);
var views = intArrayConstructors.slice();
const sab = new SharedArrayBuffer(1024);
const ab = new ArrayBuffer(16);
const views = intArrayConstructors.slice();
testWithTypedArrayConstructors(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);
const view = new TA(sab, 32, 20);
const 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);
'Atomics.exchange(view, 8, 10) returns 0');
assert.sameValue(view[8], 10, 'The value of view[8] is 10');
assert.sameValue(Atomics.exchange(view, 8, -5), 10,
"Exchange returns the value previously in the array");
'Atomics.exchange(view, 8, -5) returns 10');
control[0] = -5;
assert.sameValue(view[8], control[0]);
assert.sameValue(view[8], control[0], 'The value of view[8] equals the value of `control[0]` (-5)');
view[3] = -5;
control[0] = -5;
assert.sameValue(Atomics.exchange(view, 3, 0), control[0],
"Result is subject to coercion");
'Atomics.exchange(view, 3, 0) returns the value of `control[0]` (-5)');
control[0] = 12345;
view[3] = 12345;
assert.sameValue(Atomics.exchange(view, 3, 0), control[0],
"Result is subject to chopping");
'Atomics.exchange(view, 3, 0) returns the value of `control[0]` (12345)');
control[0] = 123456789;
view[3] = 123456789;
assert.sameValue(Atomics.exchange(view, 3, 0), control[0],
"Result is subject to chopping");
'Atomics.exchange(view, 3, 0) returns the value of `control[0]` (123456789)');
// In-bounds boundary cases for indexing
testWithAtomicsInBoundsIndices(function(IdxGen) {
@ -50,6 +50,6 @@ testWithTypedArrayConstructors(function(TA) {
// 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);
assert.sameValue(Atomics.exchange(view, Idx, 0), 37, 'Atomics.exchange(view, Idx, 0) returns 37');
});
}, views);

View File

@ -24,8 +24,9 @@ includes: [propertyHelper.js]
features: [Atomics]
---*/
assert.sameValue(Atomics.exchange.length, 3);
verifyNotEnumerable(Atomics.exchange, "length");
verifyNotWritable(Atomics.exchange, "length");
verifyConfigurable(Atomics.exchange, "length");
verifyProperty(Atomics.exchange, 'length', {
value: 3,
enumerable: false,
writable: false,
configurable: true,
});

View File

@ -10,8 +10,9 @@ includes: [propertyHelper.js]
features: [Atomics]
---*/
assert.sameValue(Atomics.exchange.name, "exchange");
verifyNotEnumerable(Atomics.exchange, "name");
verifyNotWritable(Atomics.exchange, "name");
verifyConfigurable(Atomics.exchange, "name");
verifyProperty(Atomics.exchange, 'name', {
value: 'exchange',
enumerable: false,
writable: false,
configurable: true,
});

View File

@ -10,5 +10,7 @@ features: [ArrayBuffer, arrow-function, Atomics, DataView, for-of, let, SharedAr
---*/
testWithAtomicsNonViewValues(function(view) {
assert.throws(TypeError, (() => Atomics.exchange(view, 0, 0)));
assert.throws(TypeError, function() {
Atomics.exchange(view, 0, 0);
}, '`Atomics.exchange(view, 0, 0)` throws TypeError');
});

View File

@ -6,17 +6,14 @@ esid: sec-atomics.exchange
description: >
Test Atomics.exchange on non-shared integer TypedArrays
includes: [testTypedArray.js]
features: [ArrayBuffer, Atomics, BigInt, TypedArray]
features: [ArrayBuffer, Atomics, TypedArray]
---*/
var buffer = new ArrayBuffer(16);
var views = intArrayConstructors.slice();
if (typeof BigInt !== "undefined") {
views.push(BigInt64Array);
views.push(BigUint64Array);
}
testWithTypedArrayConstructors(function(TA) {
assert.throws(TypeError, (() => Atomics.exchange(new TA(buffer), 0, 0)));
assert.throws(TypeError, function() {
Atomics.exchange(new TA(buffer), 0, 0);
}, '`Atomics.exchange(new TA(buffer), 0, 0)` throws TypeError');
}, views);

View File

@ -12,5 +12,7 @@ features: [Atomics, SharedArrayBuffer, TypedArray]
var buffer = new SharedArrayBuffer(1024);
testWithTypedArrayConstructors(function(TA) {
assert.throws(TypeError, (() => Atomics.exchange(new TA(buffer), 0, 0)));
assert.throws(TypeError, function() {
Atomics.exchange(new TA(buffer), 0, 0);
}, '`Atomics.exchange(new TA(buffer), 0, 0)` throws TypeError');
}, floatArrayConstructors);

View File

@ -0,0 +1,74 @@
// 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, SharedArrayBuffer, ArrayBuffer, DataView, BigInt, let, TypedArray, for-of]
includes: [testAtomics.js, testBigIntTypedArray.js]
---*/
assert.sameValue(
Atomics.isLockFree(hide(3, Number.NaN)),
false,
'Atomics.isLockFree(hide(3, Number.NaN)) returns false'
);
assert.sameValue(
Atomics.isLockFree(hide(3, -1)),
false,
'Atomics.isLockFree(hide(3, -1)) returns false'
);
assert.sameValue(
Atomics.isLockFree(hide(3, 3.14)),
false,
'Atomics.isLockFree(hide(3, 3.14)) returns false'
);
assert.sameValue(
Atomics.isLockFree(hide(3, 0)),
false,
'Atomics.isLockFree(hide(3, 0)) returns false'
);
assert.sameValue(
Atomics.isLockFree('1'),
Atomics.isLockFree(1),
'Atomics.isLockFree("1") returns Atomics.isLockFree(1)'
);
assert.sameValue(
Atomics.isLockFree('3'),
Atomics.isLockFree(3),
'Atomics.isLockFree("3") returns Atomics.isLockFree(3)'
);
assert.sameValue(
Atomics.isLockFree(true),
Atomics.isLockFree(1),
'Atomics.isLockFree(true) returns Atomics.isLockFree(1)'
);
assert.sameValue(Atomics.isLockFree(1), Atomics.isLockFree({
valueOf: () => 1
}), 'Atomics.isLockFree(1) returns Atomics.isLockFree({\n valueOf: () => 1\n})');
assert.sameValue(Atomics.isLockFree(3), Atomics.isLockFree({
valueOf: () => 3
}), 'Atomics.isLockFree(3) returns Atomics.isLockFree({\n valueOf: () => 3\n})');
assert.sameValue(Atomics.isLockFree(1), Atomics.isLockFree({
toString: () => '1'
}), 'Atomics.isLockFree(1) returns Atomics.isLockFree({\n toString: () => "1"\n})');
assert.sameValue(Atomics.isLockFree(3), Atomics.isLockFree({
toString: () => '3'
}), 'Atomics.isLockFree(3) returns Atomics.isLockFree({\n toString: () => "3"\n})');
function hide(k, x) {
if (k) {
return BigInt(hide(k - 3, x) + x);
}
return 0n;
}

View File

@ -0,0 +1,35 @@
// 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: >
Atomics.isLockFree returns a boolean that indicates whether
operations on datum of size will be performed without the agent
acquiring a lock outside of size bytes.
info: |
Atomics.isLockFree( size )
1. Let n be ? ToInteger(size).
2. Let AR be the Agent Record of the surrounding agent.
3. If n equals 1, return AR.[[IsLockFree1]].
4. If n equals 2, return AR.[[IsLockFree2]].
5. If n equals 4, return true.
6. If n equals 8, return AR.[[IsLockFree8]].
7. Return false.
features: [Atomics, BigInt, SharedArrayBuffer, TypedArray]
includes: [testBigIntTypedArray.js]
---*/
testWithBigIntTypedArrayConstructors(function(TA) {
var observed = Atomics.isLockFree(TA.BYTES_PER_ELEMENT);
assert.sameValue(
Atomics.isLockFree(TA.BYTES_PER_ELEMENT),
observed,
'Atomics.isLockFree(TA.BYTES_PER_ELEMENT) returns the value of `observed` (Atomics.isLockFree(TA.BYTES_PER_ELEMENT))'
);
});

View File

@ -8,20 +8,64 @@ description: >
features: [Atomics]
---*/
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(hide(3, Number.NaN)),
false,
'Atomics.isLockFree(hide(3, Number.NaN)) returns false'
);
assert.sameValue(
Atomics.isLockFree(hide(3, -1)),
false,
'Atomics.isLockFree(hide(3, -1)) returns false'
);
assert.sameValue(
Atomics.isLockFree(hide(3, 3.14)),
false,
'Atomics.isLockFree(hide(3, 3.14)) returns false'
);
assert.sameValue(
Atomics.isLockFree(hide(3, 0)),
false,
'Atomics.isLockFree(hide(3, 0)) returns false'
);
assert.sameValue(Atomics.isLockFree('1'), Atomics.isLockFree(1));
assert.sameValue(Atomics.isLockFree('3'), Atomics.isLockFree(3));
assert.sameValue(
Atomics.isLockFree('1'),
Atomics.isLockFree(1),
'Atomics.isLockFree(\'1\') returns Atomics.isLockFree(1)'
);
assert.sameValue(
Atomics.isLockFree('3'),
Atomics.isLockFree(3),
'Atomics.isLockFree(\'3\') returns Atomics.isLockFree(3)'
);
assert.sameValue(Atomics.isLockFree(true), Atomics.isLockFree(1));
assert.sameValue(
Atomics.isLockFree(true),
Atomics.isLockFree(1),
'Atomics.isLockFree(true) returns 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'}));
assert.sameValue(
Atomics.isLockFree(1),
Atomics.isLockFree({valueOf: () => 1}),
'Atomics.isLockFree(1) returns Atomics.isLockFree({valueOf: () => 1})'
);
assert.sameValue(
Atomics.isLockFree(3),
Atomics.isLockFree({valueOf: () => 3}),
'Atomics.isLockFree(3) returns Atomics.isLockFree({valueOf: () => 3})'
);
assert.sameValue(
Atomics.isLockFree(1),
Atomics.isLockFree({toString: () => '1'}),
'Atomics.isLockFree(1) returns Atomics.isLockFree({toString: () => \'1\'})'
);
assert.sameValue(
Atomics.isLockFree(3),
Atomics.isLockFree({toString: () => '3'}),
'Atomics.isLockFree(3) returns Atomics.isLockFree({toString: () => \'3\'})'
);
function hide(k, x) {
if (k) {

View File

@ -1,4 +1,3 @@
// Copyright 2015 Microsoft Corporation. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
@ -9,6 +8,8 @@ includes: [propertyHelper.js]
features: [Atomics]
---*/
verifyWritable(Atomics, "add");
verifyNotEnumerable(Atomics, "add");
verifyConfigurable(Atomics, "add");
verifyProperty(Atomics, 'add', {
enumerable: false,
writable: true,
configurable: true,
});

View File

@ -0,0 +1,111 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-atomics.islockfree
description: >
Atomics.isLockFree( size )
Let n be ? ToInteger(size).
Let AR be the Agent Record of the surrounding agent.
If n equals 1, return AR.[[IsLockFree1]].
If n equals 2, return AR.[[IsLockFree2]].
If n equals 4, return true.
If n equals 8, return AR.[[IsLockFree8]].
Return false.
features: [Atomics]
---*/
// These are the only counts that we care about tracking.
var isLockFree1;
var isLockFree2;
var isLockFree8;
{
isLockFree1 = Atomics.isLockFree(1);
//
// If n equals 1, return AR.[[IsLockFree1]].
//
assert.sameValue(typeof isLockFree1, 'boolean', 'The value of `typeof isLockFree1` is "boolean"');
// Once the values of [[Signifier]], [[IsLockFree1]], [[IsLockFree2]],
// and [[IsLockFree8]] have been observed by any agent in the agent
// cluster they cannot change.
assert.sameValue(
Atomics.isLockFree(1),
isLockFree1,
'Atomics.isLockFree(1) returns the value of `isLockFree1` (Atomics.isLockFree(1))'
);
};
{
isLockFree2 = Atomics.isLockFree(2);
//
// If n equals 2, return AR.[[IsLockFree2]].
//
assert.sameValue(typeof isLockFree2, 'boolean', 'The value of `typeof isLockFree2` is "boolean"');
// Once the values of [[Signifier]], [[IsLockFree1]], [[IsLockFree2]],
// and [[IsLockFree8]] have been observed by any agent in the agent
// cluster they cannot change.
assert.sameValue(
Atomics.isLockFree(2),
isLockFree2,
'Atomics.isLockFree(2) returns the value of `isLockFree2` (Atomics.isLockFree(2))'
);
};
{
let isLockFree4 = Atomics.isLockFree(4);
//
// If n equals 4, return true.
//
assert.sameValue(typeof isLockFree4, 'boolean', 'The value of `typeof isLockFree4` is "boolean"');
assert.sameValue(isLockFree4, true, 'The value of `isLockFree4` is true');
};
{
let isLockFree8 = Atomics.isLockFree(8);
//
// If n equals 8, return AR.[[IsLockFree8]].
//
assert.sameValue(typeof isLockFree8, 'boolean', 'The value of `typeof isLockFree8` is "boolean"');
// Once the values of [[Signifier]], [[IsLockFree1]], [[IsLockFree2]],
// and [[IsLockFree8]] have been observed by any agent in the agent
// cluster they cannot change.
assert.sameValue(
Atomics.isLockFree(8),
isLockFree8,
'Atomics.isLockFree(8) returns the value of `isLockFree8` (Atomics.isLockFree(8))'
);
};
{
for (let i = 0; i < 12; i++) {
if (![1, 2, 4, 8].includes(i)) {
assert.sameValue(Atomics.isLockFree(i), false, 'Atomics.isLockFree(i) returns false');
}
}
};
assert.sameValue(
Atomics.isLockFree(1),
isLockFree1,
'Atomics.isLockFree(1) returns the value of `isLockFree1` (Atomics.isLockFree(1))'
);
assert.sameValue(
Atomics.isLockFree(2),
isLockFree2,
'Atomics.isLockFree(2) returns the value of `isLockFree2` (Atomics.isLockFree(2))'
);
assert.sameValue(
Atomics.isLockFree(8),
isLockFree8,
'Atomics.isLockFree(8) returns the value of `isLockFree8` (Atomics.isLockFree(8))'
);
// Duplicates behavior created by loop from above
assert.sameValue(Atomics.isLockFree(3), false, 'Atomics.isLockFree(3) returns false');
assert.sameValue(Atomics.isLockFree(4), true, 'Atomics.isLockFree(4) returns true');
assert.sameValue(Atomics.isLockFree(5), false, 'Atomics.isLockFree(5) returns false');
assert.sameValue(Atomics.isLockFree(6), false, 'Atomics.isLockFree(6) returns false');
assert.sameValue(Atomics.isLockFree(7), false, 'Atomics.isLockFree(7) returns false');
assert.sameValue(Atomics.isLockFree(9), false, 'Atomics.isLockFree(9) returns false');
assert.sameValue(Atomics.isLockFree(10), false, 'Atomics.isLockFree(10) returns false');
assert.sameValue(Atomics.isLockFree(11), false, 'Atomics.isLockFree(11) returns false');
assert.sameValue(Atomics.isLockFree(12), false, 'Atomics.isLockFree(12) returns false');

View File

@ -24,8 +24,9 @@ includes: [propertyHelper.js]
features: [Atomics]
---*/
assert.sameValue(Atomics.isLockFree.length, 1);
verifyNotEnumerable(Atomics.isLockFree, "length");
verifyNotWritable(Atomics.isLockFree, "length");
verifyConfigurable(Atomics.isLockFree, "length");
verifyProperty(Atomics.isLockFree, 'length', {
value: 1,
enumerable: false,
writable: false,
configurable: true,
});

View File

@ -10,8 +10,9 @@ includes: [propertyHelper.js]
features: [Atomics]
---*/
assert.sameValue(Atomics.isLockFree.name, "isLockFree");
verifyNotEnumerable(Atomics.isLockFree, "name");
verifyNotWritable(Atomics.isLockFree, "name");
verifyConfigurable(Atomics.isLockFree, "name");
verifyProperty(Atomics.isLockFree, 'name', {
value: 'isLockFree',
enumerable: false,
writable: false,
configurable: true,
});

View File

@ -1,45 +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.islockfree
description: >
Test isLockFree on nonnegative integer arguments
features: [Atomics]
---*/
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);

View File

@ -6,20 +6,17 @@ esid: sec-atomics.load
description: >
Test range checking of Atomics.load on arrays that allow atomic operations
includes: [testAtomics.js, testTypedArray.js]
features: [ArrayBuffer, arrow-function, Atomics, BigInt, DataView, for-of, let, SharedArrayBuffer, TypedArray]
features: [ArrayBuffer, arrow-function, Atomics, DataView, for-of, let, SharedArrayBuffer, TypedArray]
---*/
var buffer = new SharedArrayBuffer(8);
var buffer = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 2);
var views = intArrayConstructors.slice();
if (typeof BigInt !== "undefined") {
views.push(BigInt64Array);
views.push(BigUint64Array);
}
testWithTypedArrayConstructors(function(TA) {
let view = new TA(buffer);
testWithAtomicsOutOfBoundsIndices(function(IdxGen) {
assert.throws(RangeError, () => Atomics.load(view, IdxGen(view)));
assert.throws(RangeError, function() {
Atomics.load(view, IdxGen(view));
}, '`Atomics.load(view, IdxGen(view))` throws RangeError');
});
}, views);

View File

@ -0,0 +1,21 @@
// 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(BigInt64Array.BYTES_PER_ELEMENT * 2);
testWithBigIntTypedArrayConstructors(function(TA) {
let view = new TA(buffer);
testWithAtomicsOutOfBoundsIndices(function(IdxGen) {
assert.throws(RangeError, function() {
Atomics.load(view, IdxGen(view));
}, '`Atomics.load(view, IdxGen(view))` throws RangeError');
});
});

View File

@ -0,0 +1,48 @@
// 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, arrow-function, Atomics, BigInt, DataView, for-of, let, SharedArrayBuffer, TypedArray]
---*/
const sab = new SharedArrayBuffer(1024);
const ab = new ArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 2);
testWithBigIntTypedArrayConstructors(function(TA) {
const view = new TA(sab, 32, 20);
const control = new TA(ab, 0, 2);
view[3] = -5n;
control[0] = -5n;
assert.sameValue(
Atomics.load(view, 3),
control[0],
'Atomics.load(view, 3) returns the value of `control[0]` (-5n)'
);
control[0] = 12345n;
view[3] = 12345n;
assert.sameValue(
Atomics.load(view, 3),
control[0],
'Atomics.load(view, 3) returns the value of `control[0]` (12345n)'
);
control[0] = 123456789n;
view[3] = 123456789n;
assert.sameValue(
Atomics.load(view, 3),
control[0],
'Atomics.load(view, 3) returns the value of `control[0]` (123456789n)'
);
testWithAtomicsInBoundsIndices(function(IdxGen) {
let Idx = IdxGen(view);
view.fill(0n);
Atomics.store(view, Idx, 37n);
assert.sameValue(Atomics.load(view, Idx), 37n, 'Atomics.load(view, Idx) returns 37n');
});
});

View File

@ -0,0 +1,21 @@
// 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

@ -1,4 +1,3 @@
// Copyright 2015 Microsoft Corporation. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
@ -9,6 +8,8 @@ includes: [propertyHelper.js]
features: [Atomics]
---*/
verifyWritable(Atomics, "load");
verifyNotEnumerable(Atomics, "load");
verifyConfigurable(Atomics, "load");
verifyProperty(Atomics, 'load', {
enumerable: false,
writable: true,
configurable: true,
});

View File

@ -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: >
Atomics.load returns the value that existed at the
index prior to the operation.
info: |
Atomics.load( typedArray, index, value )
1. Return ? AtomicLoad(typedArray, index).
AtomicLoad( typedArray, index )
1. Let buffer be ? ValidateSharedIntegerTypedArray(typedArray).
2. Let i be ? ValidateAtomicAccess(typedArray, index).
3. Let arrayTypeName be typedArray.[[TypedArrayName]].
4. Let elementSize be the Number value of the Element Size value
specified in Table 56 for arrayTypeName.
5. Let elementType be the String value of the Element Type value
in Table 56 for arrayTypeName.
6. Let offset be typedArray.[[ByteOffset]].
7. Let indexedPosition be (i × elementSize) + offset.
8. Return GetValueFromBuffer(buffer, indexedPosition, elementType,
true, "SeqCst").
features: [Atomics, SharedArrayBuffer, TypedArray]
---*/
const i32a = new Int32Array(
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
);
const update = 0b00000001000000001000000010000001;
assert.sameValue(Atomics.load(i32a, 0), 0, 'Atomics.load(i32a, 0) returns 0');
i32a[0] = update;
assert.sameValue(
Atomics.load(i32a, 0),
update,
'Atomics.load(i32a, 0) returns the value of `update` (0b00000001000000001000000010000001)'
);

View File

@ -8,31 +8,31 @@ includes: [testAtomics.js, testTypedArray.js]
features: [ArrayBuffer, arrow-function, Atomics, DataView, for-of, let, SharedArrayBuffer, TypedArray]
---*/
var sab = new SharedArrayBuffer(1024);
var ab = new ArrayBuffer(16);
const sab = new SharedArrayBuffer(1024);
const ab = new ArrayBuffer(16);
var views = intArrayConstructors.slice();
const views = intArrayConstructors.slice();
testWithTypedArrayConstructors(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);
const view = new TA(sab, 32, 20);
const 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");
'Atomics.load(view, 3) returns the value of `control[0]` (-5)');
control[0] = 12345;
view[3] = 12345;
assert.sameValue(Atomics.load(view, 3), control[0],
"Result is subject to chopping");
'Atomics.load(view, 3) returns the value of `control[0]` (12345)');
control[0] = 123456789;
view[3] = 123456789;
assert.sameValue(Atomics.load(view, 3), control[0],
"Result is subject to chopping");
'Atomics.load(view, 3) returns the value of `control[0]` (123456789)');
// In-bounds boundary cases for indexing
testWithAtomicsInBoundsIndices(function(IdxGen) {
@ -41,6 +41,6 @@ testWithTypedArrayConstructors(function(TA) {
// 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);
assert.sameValue(Atomics.load(view, Idx), 37, 'Atomics.load(view, Idx) returns 37');
});
}, views);

View File

@ -24,8 +24,9 @@ includes: [propertyHelper.js]
features: [Atomics]
---*/
assert.sameValue(Atomics.load.length, 2);
verifyNotEnumerable(Atomics.load, "length");
verifyNotWritable(Atomics.load, "length");
verifyConfigurable(Atomics.load, "length");
verifyProperty(Atomics.load, 'length', {
value: 2,
enumerable: false,
writable: false,
configurable: true,
});

View File

@ -10,8 +10,9 @@ includes: [propertyHelper.js]
features: [Atomics]
---*/
assert.sameValue(Atomics.load.name, "load");
verifyNotEnumerable(Atomics.load, "name");
verifyNotWritable(Atomics.load, "name");
verifyConfigurable(Atomics.load, "name");
verifyProperty(Atomics.load, 'name', {
value: 'load',
enumerable: false,
writable: false,
configurable: true,
});

View File

@ -10,5 +10,7 @@ features: [ArrayBuffer, arrow-function, Atomics, DataView, for-of, let, SharedAr
---*/
testWithAtomicsNonViewValues(function(view) {
assert.throws(TypeError, (() => Atomics.load(view, 0)));
assert.throws(TypeError, function() {
Atomics.load(view, 0);
}, '`Atomics.load(view, 0)` throws TypeError');
});

View File

@ -6,20 +6,16 @@ esid: sec-atomics.load
description: >
Test Atomics.load on non-shared integer TypedArrays
includes: [testTypedArray.js]
features: [ArrayBuffer, Atomics, BigInt, TypedArray]
features: [ArrayBuffer, Atomics, TypedArray]
---*/
var ab = new ArrayBuffer(16);
var views = intArrayConstructors.slice();
if (typeof BigInt !== "undefined") {
views.push(BigInt64Array);
views.push(BigUint64Array);
}
const buffer = new ArrayBuffer(16);
const views = intArrayConstructors.slice();
testWithTypedArrayConstructors(function(TA) {
var view = new TA(ab);
const view = new TA(buffer);
assert.throws(TypeError, (() => Atomics.load(view, 0)));
assert.throws(TypeError, function() {
Atomics.load(view, 0);
}, '`Atomics.load(view, 0)` throws TypeError');
}, views);

View File

@ -9,7 +9,9 @@ includes: [testTypedArray.js]
features: [Atomics, SharedArrayBuffer, TypedArray]
---*/
var buffer = new SharedArrayBuffer(1024);
const buffer = new SharedArrayBuffer(1024);
testWithTypedArrayConstructors(function(TA) {
assert.throws(TypeError, (() => Atomics.load(new TA(buffer), 0)));
assert.throws(TypeError, function() {
Atomics.load(new TA(buffer), 0);
}, '`Atomics.load(new TA(buffer), 0)` throws TypeError');
}, floatArrayConstructors);

View File

@ -6,20 +6,17 @@ esid: sec-atomics.or
description: >
Test range checking of Atomics.or on arrays that allow atomic operations
includes: [testAtomics.js, testTypedArray.js]
features: [ArrayBuffer, arrow-function, Atomics, BigInt, DataView, for-of, let, SharedArrayBuffer, TypedArray]
features: [ArrayBuffer, arrow-function, Atomics, DataView, for-of, let, SharedArrayBuffer, TypedArray]
---*/
var buffer = new SharedArrayBuffer(8);
var buffer = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 2);
var views = intArrayConstructors.slice();
if (typeof BigInt !== "undefined") {
views.push(BigInt64Array);
views.push(BigUint64Array);
}
testWithTypedArrayConstructors(function(TA) {
let view = new TA(buffer);
testWithAtomicsOutOfBoundsIndices(function(IdxGen) {
assert.throws(RangeError, () => Atomics.or(view, IdxGen(view), 10));
assert.throws(RangeError, function() {
Atomics.or(view, IdxGen(view), 10);
}, '`Atomics.or(view, IdxGen(view), 10)` throws RangeError');
});
}, views);

View File

@ -0,0 +1,20 @@
// 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(BigInt64Array.BYTES_PER_ELEMENT * 2);
testWithBigIntTypedArrayConstructors(function(TA) {
let view = new TA(buffer);
testWithAtomicsOutOfBoundsIndices(function(IdxGen) {
assert.throws(RangeError, function() {
Atomics.or(view, IdxGen(view), 10n);
}, '`Atomics.or(view, IdxGen(view), 10n)` throws RangeError');
});
});

View File

@ -0,0 +1,97 @@
// 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, arrow-function, Atomics, BigInt, DataView, for-of, let, SharedArrayBuffer, TypedArray]
---*/
const sab = new SharedArrayBuffer(1024);
const ab = new ArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 2);
testWithBigIntTypedArrayConstructors(function(TA) {
const view = new TA(sab, 32, 20);
const control = new TA(ab, 0, 2);
view[8] = 0x33333333n;
control[0] = 0x33333333n;
assert.sameValue(
Atomics.or(view, 8, 0x55555555n),
control[0],
'Atomics.or(view, 8, 0x55555555n) returns the value of `control[0]` (0x33333333n)'
);
control[0] = 0x77777777n;
assert.sameValue(
view[8],
control[0],
'The value of view[8] equals the value of `control[0]` (0x77777777n)'
);
assert.sameValue(
Atomics.or(view, 8, 0xF0F0F0F0n),
control[0],
'Atomics.or(view, 8, 0xF0F0F0F0n) returns the value of `control[0]` (0x77777777n)'
);
control[0] = 0xF7F7F7F7n;
assert.sameValue(
view[8],
control[0],
'The value of view[8] equals the value of `control[0]` (0xF7F7F7F7n)'
);
view[3] = -5n;
control[0] = -5n;
assert.sameValue(
Atomics.or(view, 3, 0n),
control[0],
'Atomics.or(view, 3, 0n) returns the value of `control[0]` (-5n)'
);
assert.sameValue(
view[3],
control[0],
'The value of view[3] equals the value of `control[0]` (-5n)'
);
control[0] = 12345n;
view[3] = 12345n;
assert.sameValue(
Atomics.or(view, 3, 0n),
control[0],
'Atomics.or(view, 3, 0n) returns the value of `control[0]` (12345n)'
);
assert.sameValue(
view[3],
control[0],
'The value of view[3] equals the value of `control[0]` (12345n)'
);
control[0] = 123456789n;
view[3] = 123456789n;
assert.sameValue(
Atomics.or(view, 3, 0n),
control[0],
'Atomics.or(view, 3, 0n) returns the value of `control[0]` (123456789n)'
);
assert.sameValue(
view[3],
control[0],
'The value of view[3] equals the value of `control[0]` (123456789n)'
);
testWithAtomicsInBoundsIndices(function(IdxGen) {
let Idx = IdxGen(view);
view.fill(0n);
Atomics.store(view, Idx, 37n);
assert.sameValue(Atomics.or(view, Idx, 0n), 37n, 'Atomics.or(view, Idx, 0n) returns 37n');
});
});

View File

@ -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]
---*/
const buffer = new ArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 2);
testWithBigIntTypedArrayConstructors(function(TA) {
assert.throws(TypeError, function() {
Atomics.or(new TA(buffer), 0, 0n);
}, '`Atomics.or(new TA(buffer), 0, 0n)` throws TypeError');
});

View File

@ -1,4 +1,3 @@
// Copyright 2015 Microsoft Corporation. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
@ -8,7 +7,8 @@ description: Testing descriptor property of Atomics.or
includes: [propertyHelper.js]
features: [Atomics]
---*/
verifyWritable(Atomics, "or");
verifyNotEnumerable(Atomics, "or");
verifyConfigurable(Atomics, "or");
verifyProperty(Atomics, 'or', {
enumerable: false,
writable: true,
configurable: true,
});

View File

@ -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.or
description: >
Atomics.and returns the value that existed at the
index prior to the operation.
info: |
Atomics.or( typedArray, index, value )
1. Return ? AtomicReadModifyWrite(typedArray, index, value, or).
AtomicReadModifyWrite( typedArray, index, value, op )
...
9. Return GetModifySetValueInBuffer(buffer, indexedPosition,
elementType, v, op).
GetModifySetValueInBuffer( arrayBuffer,
byteIndex, type, value, op [ , isLittleEndian ] )
...
16. Return RawBytesToNumber(type, rawBytesRead, isLittleEndian).
features: [Atomics, SharedArrayBuffer, TypedArray]
---*/
const i32a = new Int32Array(
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
);
const a = 0b00000001000000001000000010000001;
const b = 0b00000001111111111000000011111111;
const c = 0b00000001111111111000000011111111;
i32a[0] = a;
assert.sameValue(
Atomics.or(i32a, 0, b),
a,
'Atomics.or(i32a, 0, b) returns the value of `a` (0b00000001000000001000000010000001)'
);
assert.sameValue(i32a[0], c, 'The value of i32a[0] equals the value of `c` (0b00000001111111111000000011111111)');

View File

@ -21,33 +21,53 @@ testWithTypedArrayConstructors(function(TA) {
view[8] = 0x33333333;
control[0] = 0x33333333;
assert.sameValue(Atomics.or(view, 8, 0x55555555), control[0],
"Result is subject to chopping");
'Atomics.or(view, 8, 0x55555555) returns the value of `control[0]` (0x33333333)');
control[0] = 0x77777777;
assert.sameValue(view[8], control[0]);
assert.sameValue(
view[8],
control[0],
'The value of view[8] equals the value of `control[0]` (0x77777777)'
);
assert.sameValue(Atomics.or(view, 8, 0xF0F0F0F0), control[0],
"Result is subject to chopping");
'Atomics.or(view, 8, 0xF0F0F0F0) returns the value of `control[0]` (0x77777777)');
control[0] = 0xF7F7F7F7;
assert.sameValue(view[8], control[0]);
assert.sameValue(
view[8],
control[0],
'The value of view[8] equals the value of `control[0]` (0xF7F7F7F7)'
);
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]);
'Atomics.or(view, 3, 0) returns the value of `control[0]` (-5)');
assert.sameValue(
view[3],
control[0],
'The value of view[3] equals the value of `control[0]` (-5)'
);
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]);
'Atomics.or(view, 3, 0) returns the value of `control[0]` (12345)');
assert.sameValue(
view[3],
control[0],
'The value of view[3] equals the value of `control[0]` (12345)'
);
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]);
'Atomics.or(view, 3, 0) returns the value of `control[0]` (123456789)');
assert.sameValue(
view[3],
control[0],
'The value of view[3] equals the value of `control[0]` (123456789)'
);
// In-bounds boundary cases for indexing
testWithAtomicsInBoundsIndices(function(IdxGen) {
@ -56,6 +76,6 @@ testWithTypedArrayConstructors(function(TA) {
// 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);
assert.sameValue(Atomics.or(view, Idx, 0), 37, 'Atomics.or(view, Idx, 0) returns 37');
});
}, views);

View File

@ -24,8 +24,9 @@ includes: [propertyHelper.js]
features: [Atomics]
---*/
assert.sameValue(Atomics.or.length, 3);
verifyNotEnumerable(Atomics.or, "length");
verifyNotWritable(Atomics.or, "length");
verifyConfigurable(Atomics.or, "length");
verifyProperty(Atomics.or, 'length', {
value: 3,
enumerable: false,
writable: false,
configurable: true,
});

View File

@ -10,8 +10,9 @@ includes: [propertyHelper.js]
features: [Atomics]
---*/
assert.sameValue(Atomics.or.name, "or");
verifyNotEnumerable(Atomics.or, "name");
verifyNotWritable(Atomics.or, "name");
verifyConfigurable(Atomics.or, "name");
verifyProperty(Atomics.or, 'name', {
value: 'or',
enumerable: false,
writable: false,
configurable: true,
});

View File

@ -10,5 +10,7 @@ features: [ArrayBuffer, arrow-function, Atomics, DataView, for-of, let, SharedAr
---*/
testWithAtomicsNonViewValues(function(view) {
assert.throws(TypeError, (() => Atomics.or(view, 0, 0)));
assert.throws(TypeError, function() {
Atomics.or(view, 0, 0);
}, '`Atomics.or(view, 0, 0)` throws TypeError');
});

View File

@ -6,17 +6,14 @@ esid: sec-atomics.or
description: >
Test Atomics.or on non-shared integer TypedArrays
includes: [testTypedArray.js]
features: [ArrayBuffer, Atomics, BigInt, TypedArray]
features: [ArrayBuffer, Atomics, TypedArray]
---*/
var buffer = new ArrayBuffer(16);
var views = intArrayConstructors.slice();
if (typeof BigInt !== "undefined") {
views.push(BigInt64Array);
views.push(BigUint64Array);
}
const buffer = new ArrayBuffer(16);
const views = intArrayConstructors.slice();
testWithTypedArrayConstructors(function(TA) {
assert.throws(TypeError, (() => Atomics.or(new TA(buffer), 0, 0)));
assert.throws(TypeError, function() {
Atomics.or(new TA(buffer), 0, 0);
}, '`Atomics.or(new TA(buffer), 0, 0)` throws TypeError');
}, views);

View File

@ -12,7 +12,9 @@ features: [Atomics, SharedArrayBuffer, TypedArray]
var buffer = new SharedArrayBuffer(1024);
testWithTypedArrayConstructors(function(TA) {
assert.throws(TypeError, (() => Atomics.or(new TA(buffer), 0, 0)));
assert.throws(TypeError, function() {
Atomics.or(new TA(buffer), 0, 0);
}, '`Atomics.or(new TA(buffer), 0, 0)` throws TypeError');
}, floatArrayConstructors);

View File

@ -24,15 +24,15 @@ includes: [propertyHelper.js]
features: [Atomics]
---*/
assert.sameValue(typeof Atomics, "object");
assert.sameValue(typeof Atomics, "object", 'The value of `typeof Atomics` is "object"');
assert.throws(TypeError, function() {
Atomics();
}, "no [[Call]]");
}, '`Atomics()` throws TypeError');
assert.throws(TypeError, function() {
new Atomics();
}, "no [[Construct]]");
}, '`new Atomics()` throws TypeError');
verifyProperty(this, "Atomics", {
enumerable: false,

View File

@ -13,4 +13,8 @@ info: |
features: [Atomics]
---*/
assert.sameValue(Object.getPrototypeOf(Atomics), Object.prototype);
assert.sameValue(
Object.getPrototypeOf(Atomics),
Object.prototype,
'Object.getPrototypeOf(Atomics) returns the value of `Object.prototype`'
);

View File

@ -6,20 +6,17 @@ esid: sec-atomics.store
description: >
Test range checking of Atomics.store on arrays that allow atomic operations
includes: [testAtomics.js, testTypedArray.js]
features: [ArrayBuffer, arrow-function, Atomics, BigInt, DataView, for-of, let, SharedArrayBuffer, TypedArray]
features: [ArrayBuffer, arrow-function, Atomics, DataView, for-of, let, SharedArrayBuffer, TypedArray]
---*/
var buffer = new SharedArrayBuffer(8);
var views = intArrayConstructors.slice();
if (typeof BigInt !== "undefined") {
views.push(BigInt64Array);
views.push(BigUint64Array);
}
const buffer = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 2);
const views = intArrayConstructors.slice();
testWithTypedArrayConstructors(function(TA) {
let view = new TA(buffer);
const view = new TA(buffer);
testWithAtomicsOutOfBoundsIndices(function(IdxGen) {
assert.throws(RangeError, () => Atomics.store(view, IdxGen(view), 10));
assert.throws(RangeError, function() {
Atomics.store(view, IdxGen(view), 10);
}, '`Atomics.store(view, IdxGen(view), 10)` throws RangeError');
});
}, views);

View File

@ -0,0 +1,20 @@
// 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]
---*/
const buffer = new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 2);
testWithBigIntTypedArrayConstructors(function(TA) {
const view = new TA(buffer);
testWithAtomicsOutOfBoundsIndices(function(IdxGen) {
assert.throws(RangeError, function() {
Atomics.store(view, IdxGen(view), 10n);
}, '`Atomics.store(view, IdxGen(view), 10n)` throws RangeError');
});
});

View File

@ -0,0 +1,42 @@
// 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, DataView, for-of, let, SharedArrayBuffer, TypedArray]
---*/
// Make it interesting - use non-zero byteOffsets and non-zero indexes.
// In-bounds boundary cases for indexing
const sab = new SharedArrayBuffer(1024);
const ab = new ArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 2);
testWithBigIntTypedArrayConstructors(function(TA) {
const view = new TA(sab, 32, 20);
const control = new TA(ab, 0, 2);
for (let val of [10n, -5n, 12345n, 123456789n, BigInt('33'), {
valueOf: () => 33n
}, BigInt(undefined)]) {
assert.sameValue(
Atomics.store(view, 3, val),
BigInt(val),
'Atomics.store(view, 3, val) returns BigInt(val)'
);
control[0] = val;
assert.sameValue(
view[3],
control[0],
'The value of view[3] equals the value of `control[0]` (val)'
);
}
testWithAtomicsInBoundsIndices(function(IdxGen) {
let Idx = IdxGen(view);
view.fill(0n);
Atomics.store(view, Idx, 37n);
assert.sameValue(Atomics.load(view, Idx), 37n, 'Atomics.load(view, Idx) returns 37n');
});
});

View File

@ -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]
---*/
const buffer = new ArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 2);
testWithBigIntTypedArrayConstructors(function(TA) {
assert.throws(TypeError, function() {
Atomics.store(new TA(buffer), 0, 0n);
}, '`Atomics.store(new TA(buffer), 0, 0n)` throws TypeError');
});

View File

@ -1,4 +1,3 @@
// Copyright 2015 Microsoft Corporation. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
@ -8,7 +7,8 @@ description: Testing descriptor property of Atomics.store
includes: [propertyHelper.js]
features: [Atomics]
---*/
verifyWritable(Atomics, "store");
verifyNotEnumerable(Atomics, "store");
verifyConfigurable(Atomics, "store");
verifyProperty(Atomics, 'store', {
enumerable: false,
writable: true,
configurable: true,
});

View File

@ -0,0 +1,35 @@
// 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: >
Atomics.store returns the newly stored value
info: |
Atomics.store( typedArray, index, value )
...
3. Let v be ? ToInteger(value).
...
9. Perform SetValueInBuffer(buffer, indexedPosition,
elementType, v, true, "SeqCst").
10. Return v.
features: [Atomics, SharedArrayBuffer, TypedArray]
---*/
const i32a = new Int32Array(
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
);
const update = 0b00000001000000001000000010000001;
assert.sameValue(
Atomics.store(i32a, 0, update),
update,
'Atomics.store(i32a, 0, update) returns the value of `update` (0b00000001000000001000000010000001)'
);
assert.sameValue(
i32a[0],
update,
'The value of i32a[0] equals the value of `update` (0b00000001000000001000000010000001)'
);

View File

@ -8,15 +8,15 @@ includes: [testAtomics.js, testTypedArray.js]
features: [ArrayBuffer, arrow-function, Atomics, DataView, for-of, let, SharedArrayBuffer, TypedArray]
---*/
var sab = new SharedArrayBuffer(1024);
var ab = new ArrayBuffer(16);
var views = intArrayConstructors.slice();
const sab = new SharedArrayBuffer(1024);
const ab = new ArrayBuffer(16);
const views = intArrayConstructors.slice();
testWithTypedArrayConstructors(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);
const view = new TA(sab, 32, 20);
const control = new TA(ab, 0, 2);
for (let val of [10, -5,
12345,
@ -30,10 +30,14 @@ testWithTypedArrayConstructors(function(TA) {
])
{
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");
'Atomics.store(view, 3, val) returns ToInteger(val)');
control[0] = val;
assert.sameValue(view[3], control[0]);
assert.sameValue(
view[3],
control[0],
'The value of view[3] equals the value of `control[0]` (val)'
);
}
// In-bounds boundary cases for indexing
@ -41,7 +45,7 @@ testWithTypedArrayConstructors(function(TA) {
let Idx = IdxGen(view);
view.fill(0);
Atomics.store(view, Idx, 37);
assert.sameValue(Atomics.load(view, Idx), 37);
assert.sameValue(Atomics.load(view, Idx), 37, 'Atomics.load(view, Idx) returns 37');
});
}, views);

View File

@ -24,8 +24,9 @@ includes: [propertyHelper.js]
features: [Atomics]
---*/
assert.sameValue(Atomics.store.length, 3);
verifyNotEnumerable(Atomics.store, "length");
verifyNotWritable(Atomics.store, "length");
verifyConfigurable(Atomics.store, "length");
verifyProperty(Atomics.store, 'length', {
value: 3,
enumerable: false,
writable: false,
configurable: true,
});

View File

@ -10,8 +10,9 @@ includes: [propertyHelper.js]
features: [Atomics]
---*/
assert.sameValue(Atomics.store.name, "store");
verifyNotEnumerable(Atomics.store, "name");
verifyNotWritable(Atomics.store, "name");
verifyConfigurable(Atomics.store, "name");
verifyProperty(Atomics.store, 'name', {
value: 'store',
enumerable: false,
writable: false,
configurable: true,
});

View File

@ -10,5 +10,7 @@ features: [ArrayBuffer, arrow-function, Atomics, DataView, for-of, let, SharedAr
---*/
testWithAtomicsNonViewValues(function(view) {
assert.throws(TypeError, (() => Atomics.store(view, 0, 0)));
assert.throws(TypeError, function() {
Atomics.store(view, 0, 0);
}, '`Atomics.store(view, 0, 0)` throws TypeError');
});

View File

@ -6,17 +6,14 @@ esid: sec-atomics.store
description: >
Test Atomics.store on non-shared integer TypedArrays
includes: [testTypedArray.js]
features: [ArrayBuffer, Atomics, BigInt, TypedArray]
features: [ArrayBuffer, Atomics, TypedArray]
---*/
var buffer = new ArrayBuffer(16);
var views = intArrayConstructors.slice();
if (typeof BigInt !== "undefined") {
views.push(BigInt64Array);
views.push(BigUint64Array);
}
const buffer = new ArrayBuffer(16);
const views = intArrayConstructors.slice();
testWithTypedArrayConstructors(function(TA) {
assert.throws(TypeError, (() => Atomics.store(new TA(buffer), 0, 0)));
assert.throws(TypeError, function() {
Atomics.store(new TA(buffer), 0, 0);
}, '`Atomics.store(new TA(buffer), 0, 0)` throws TypeError');
}, views);

View File

@ -12,7 +12,9 @@ features: [Atomics, SharedArrayBuffer, TypedArray]
var buffer = new SharedArrayBuffer(1024);
testWithTypedArrayConstructors(function(TA) {
assert.throws(TypeError, (() => Atomics.store(new TA(buffer), 0, 0)));
assert.throws(TypeError, function() {
Atomics.store(new TA(buffer), 0, 0);
}, '`Atomics.store(new TA(buffer), 0, 0)` throws TypeError');
}, floatArrayConstructors);

View File

@ -6,20 +6,17 @@ esid: sec-atomics.sub
description: >
Test range checking of Atomics.sub on arrays that allow atomic operations
includes: [testAtomics.js, testTypedArray.js]
features: [ArrayBuffer, arrow-function, Atomics, BigInt, DataView, for-of, let, SharedArrayBuffer, TypedArray]
features: [ArrayBuffer, arrow-function, Atomics, DataView, for-of, let, SharedArrayBuffer, TypedArray]
---*/
var buffer = new SharedArrayBuffer(8);
var buffer = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 2);
var views = intArrayConstructors.slice();
if (typeof BigInt !== "undefined") {
views.push(BigInt64Array);
views.push(BigUint64Array);
}
testWithTypedArrayConstructors(function(TA) {
let view = new TA(buffer);
testWithAtomicsOutOfBoundsIndices(function(IdxGen) {
assert.throws(RangeError, () => Atomics.sub(view, IdxGen(view), 10));
assert.throws(RangeError, function() {
Atomics.sub(view, IdxGen(view), 10);
}, '`Atomics.sub(view, IdxGen(view), 10)` throws RangeError');
});
}, views);

Some files were not shown because too many files have changed in this diff Show More