Debian Codegraph @

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