Debian Codegraph @

js/src/tests/test262/built-ins/Atomics/exchange/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.exchange
6 description: Test Atomics.exchange 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(BigInt64Array.BYTES_PER_ELEMENT * 2);
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.exchange(view, 8, 10n), 0n, 'Atomics.exchange(view, 8, 10n) returns 0n');
18 assert.sameValue(view[8], 10n, 'The value of view[8] is 10n');
19
20 assert.sameValue(
21 Atomics.exchange(view, 8, -5n),
22 10n,
23 'Atomics.exchange(view, 8, -5n) returns 10n'
24 );
25
26 control[0] = -5n;
27
28 assert.sameValue(
29 view[8],
30 control[0],
31 'The value of view[8] equals the value of `control[0]` (-5n)'
32 );
33
34 view[3] = -5n;
35 control[0] = -5n;
36
37 assert.sameValue(
38 Atomics.exchange(view, 3, 0n),
39 control[0],
40 'Atomics.exchange(view, 3, 0n) returns the value of `control[0]` (-5n)'
41 );
42
43 control[0] = 12345n;
44 view[3] = 12345n;
45
46 assert.sameValue(
47 Atomics.exchange(view, 3, 0n),
48 control[0],
49 'Atomics.exchange(view, 3, 0n) returns the value of `control[0]` (12345n)'
50 );
51
52 control[0] = 123456789n;
53 view[3] = 123456789n;
54
55 assert.sameValue(
56 Atomics.exchange(view, 3, 0n),
57 control[0],
58 'Atomics.exchange(view, 3, 0n) returns the value of `control[0]` (123456789n)'
59 );
60
61 testWithAtomicsInBoundsIndices(function(IdxGen) {
62 let Idx = IdxGen(view);
63 view.fill(0n);
64 Atomics.store(view, Idx, 37n);
65
66 assert.sameValue(
67 Atomics.exchange(view, Idx, 0n),
68 37n,
69 'Atomics.exchange(view, Idx, 0n) returns 37n'
70 );
71 });
72 });
73
74 reportCompare(0, 0);