1 // |reftest| skip-if(!this.hasOwnProperty('Atomics')||!this.hasOwnProperty('SharedArrayBuffer')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration('arm64-simulator'))) -- Atomics,SharedArrayBuffer is not enabled unconditionally, ARM64 Simulator cannot emulate atomics
2 // Copyright (C) 2017 Mozilla Corporation. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
7 description: Test Atomics.sub on arrays that allow atomic operations
8 includes: [testAtomics.js, testTypedArray.js]
9 features: [ArrayBuffer, Atomics, DataView, SharedArrayBuffer, Symbol, TypedArray]
12 var sab = new SharedArrayBuffer(1024);
13 var ab = new ArrayBuffer(16);
14 var views = nonClampedIntArrayConstructors.slice();
16 testWithTypedArrayConstructors(function(TA) {
17 // Make it interesting - use non-zero byteOffsets and non-zero indexes.
19 var view = new TA(sab, 32, 20);
20 var control = new TA(ab, 0, 2);
23 assert.sameValue(Atomics.sub(view, 8, 10), 100,
24 'Atomics.sub(view, 8, 10) returns 100');
25 assert.sameValue(view[8], 90, 'The value of view[8] is 90');
27 assert.sameValue(Atomics.sub(view, 8, -5), 90,
28 'Atomics.sub(view, 8, -5) returns 90');
29 assert.sameValue(view[8], 95, 'The value of view[8] is 95');
33 assert.sameValue(Atomics.sub(view, 3, 0), control[0],
34 'Atomics.sub(view, 3, 0) returns the value of `control[0]` (-5)');
38 assert.sameValue(Atomics.sub(view, 3, 0), control[0],
39 'Atomics.sub(view, 3, 0) returns the value of `control[0]` (12345)');
41 control[0] = 123456789;
43 assert.sameValue(Atomics.sub(view, 3, 0), control[0],
44 'Atomics.sub(view, 3, 0) returns the value of `control[0]` (123456789)');
46 // In-bounds boundary cases for indexing
47 testWithAtomicsInBoundsIndices(function(IdxGen) {
48 let Idx = IdxGen(view);
50 // Atomics.store() computes an index from Idx in the same way as other
51 // Atomics operations, not quite like view[Idx].
52 Atomics.store(view, Idx, 37);
53 assert.sameValue(Atomics.sub(view, Idx, 0), 37, 'Atomics.sub(view, Idx, 0) returns 37');