Debian Codegraph @

js/src/tests/test262/built-ins/Atomics/add/bigint/good-views.js

raw
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) 2018 Rick Waldron. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4 /*---
5 esid: sec-atomics.add
6 description: Test Atomics.add on arrays that allow atomic operations.
7 includes: [testAtomics.js, testBigIntTypedArray.js]
8 features: [ArrayBuffer, Atomics, BigInt, DataView, SharedArrayBuffer, Symbol, TypedArray]
9 ---*/
10 const sab = new SharedArrayBuffer(1024);
11 const ab = new ArrayBuffer(16);
12
13 testWithBigIntTypedArrayConstructors(function(TA) {
14 const view = new TA(sab, 32, 20);
15 const control = new TA(ab, 0, 2);
16 view[8] = 0n;
17 assert.sameValue(Atomics.add(view, 8, 10n), 0n, 'Atomics.add(view, 8, 10n) returns 0');
18 assert.sameValue(view[8], 10n, 'The value of view[8] is 10n');
19 assert.sameValue(Atomics.add(view, 8, -5n), 10n, 'Atomics.add(view, 8, -5n) returns 10n');
20 assert.sameValue(view[8], 5n, 'The value of view[8] is 5n');
21 view[3] = -5n;
22 control[0] = -5n;
23
24 assert.sameValue(
25 Atomics.add(view, 3, 0n),
26 control[0],
27 'Atomics.add(view, 3, 0n) returns the value of `control[0]` (-5n)'
28 );
29
30 control[0] = 12345n;
31 view[3] = 12345n;
32
33 assert.sameValue(
34 Atomics.add(view, 3, 0n),
35 control[0],
36 'Atomics.add(view, 3, 0n) returns the value of `control[0]` (12345n)'
37 );
38
39 control[0] = 123456789n;
40 view[3] = 123456789n;
41
42 assert.sameValue(
43 Atomics.add(view, 3, 0n),
44 control[0],
45 'Atomics.add(view, 3, 0n) returns the value of `control[0]` (123456789n)'
46 );
47
48 testWithAtomicsInBoundsIndices(function(IdxGen) {
49 let Idx = IdxGen(view);
50 view.fill(0n);
51 Atomics.store(view, Idx, 37n);
52 assert.sameValue(Atomics.add(view, Idx, 0n), 37n, 'Atomics.add(view, Idx, 0) returns 37n');
53 });
54 });
55
56 reportCompare(0, 0);