Debian Codegraph @

js/src/tests/test262/built-ins/Atomics/and/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) 2017 Mozilla Corporation. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4
5 /*---
6 esid: sec-atomics.and
7 description: Test Atomics.and on arrays that allow atomic operations
8 includes: [testAtomics.js, testTypedArray.js]
9 features: [ArrayBuffer, Atomics, DataView, SharedArrayBuffer, Symbol, TypedArray]
10 ---*/
11
12 const sab = new SharedArrayBuffer(1024);
13 const ab = new ArrayBuffer(16);
14 const views = nonClampedIntArrayConstructors.slice();
15
16 testWithTypedArrayConstructors(function(TA) {
17 // Make it interesting - use non-zero byteOffsets and non-zero indexes.
18
19 const view = new TA(sab, 32, 20);
20 const control = new TA(ab, 0, 2);
21
22 view[8] = 0x33333333;
23 control[0] = 0x33333333;
24 assert.sameValue(Atomics.and(view, 8, 0x55555555), control[0],
25 'Atomics.and(view, 8, 0x55555555) returns the value of `control[0]` (0x33333333)');
26
27 control[0] = 0x11111111;
28 assert.sameValue(
29 view[8],
30 control[0],
31 'The value of view[8] equals the value of `control[0]` (0x11111111)'
32 );
33 assert.sameValue(Atomics.and(view, 8, 0xF0F0F0F0), control[0],
34 'Atomics.and(view, 8, 0xF0F0F0F0) returns the value of `control[0]` (0x11111111)');
35
36 control[0] = 0x10101010;
37 assert.sameValue(
38 view[8],
39 control[0],
40 'The value of view[8] equals the value of `control[0]` (0x10101010)'
41 );
42
43 view[3] = -5;
44 control[0] = -5;
45 assert.sameValue(Atomics.and(view, 3, 0), control[0],
46 'Atomics.and(view, 3, 0) returns the value of `control[0]` (-5)');
47 assert.sameValue(view[3], 0, 'The value of view[3] is 0');
48
49 control[0] = 12345;
50 view[3] = 12345;
51 assert.sameValue(Atomics.and(view, 3, 0), control[0],
52 'Atomics.and(view, 3, 0) returns the value of `control[0]` (12345)');
53 assert.sameValue(view[3], 0, 'The value of view[3] is 0');
54
55 control[0] = 123456789;
56 view[3] = 123456789;
57 assert.sameValue(Atomics.and(view, 3, 0), control[0],
58 'Atomics.and(view, 3, 0) returns the value of `control[0]` (123456789)');
59 assert.sameValue(view[3], 0, 'The value of view[3] is 0');
60
61 // In-bounds boundary cases for indexing
62 testWithAtomicsInBoundsIndices(function(IdxGen) {
63 let Idx = IdxGen(view);
64 view.fill(0);
65 // Atomics.store() computes an index from Idx in the same way as other
66 // Atomics operations, not quite like view[Idx].
67 Atomics.store(view, Idx, 37);
68 assert.sameValue(Atomics.and(view, Idx, 0), 37, 'Atomics.and(view, Idx, 0) returns 37');
69 });
70 }, views);
71
72 reportCompare(0, 0);