Debian Codegraph @

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