Debian Codegraph @

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