Bug 1892041 - Part 2: Update test262. r=spidermonkey-reviewers,dminor
[gecko.git] / js / src / tests / test262 / built-ins / Atomics / sub / good-views.js
blob60ea4ad56901b4449a03e1a57c4af1bc9795548a
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.
5 /*---
6 esid: sec-atomics.sub
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]
10 ---*/
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);
22   view[8] = 100;
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');
31   view[3] = -5;
32   control[0] = -5;
33   assert.sameValue(Atomics.sub(view, 3, 0), control[0],
34     'Atomics.sub(view, 3, 0) returns the value of `control[0]` (-5)');
36   control[0] = 12345;
37   view[3] = 12345;
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;
42   view[3] = 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);
49     view.fill(0);
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');
54   });
55 }, views);
57 reportCompare(0, 0);