Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/Atomics/and/good-views.js

raw
1 // Copyright (C) 2017 Mozilla Corporation. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3
4 /*---
5 esid: sec-atomics.and
6 description: Test Atomics.and on arrays that allow atomic operations
7 includes: [testAtomics.js, testTypedArray.js]
8 features: [SharedArrayBuffer, ArrayBuffer, DataView, Atomics, arrow-function, let, TypedArray, for-of]
9 ---*/
10
11 var sab = new SharedArrayBuffer(1024);
12 var ab = new ArrayBuffer(16);
13
14 var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];
15
16 testWithTypedArrayConstructors(function(View) {
17 // Make it interesting - use non-zero byteOffsets and non-zero indexes.
18
19 var view = new View(sab, 32, 20);
20 var control = new View(ab, 0, 2);
21
22 view[8] = 0x33333333;
23 control[0] = 0x33333333;
24 assert.sameValue(Atomics.and(view, 8, 0x55555555), control[0],
25 "Result is subject to chopping");
26
27 control[0] = 0x11111111;
28 assert.sameValue(view[8], control[0]);
29 assert.sameValue(Atomics.and(view, 8, 0xF0F0F0F0), control[0],
30 "Result is subject to chopping");
31
32 control[0] = 0x10101010;
33 assert.sameValue(view[8], control[0]);
34
35 view[3] = -5;
36 control[0] = -5;
37 assert.sameValue(Atomics.and(view, 3, 0), control[0],
38 "Result is negative and subject to coercion");
39 assert.sameValue(view[3], 0);
40
41 control[0] = 12345;
42 view[3] = 12345;
43 assert.sameValue(Atomics.and(view, 3, 0), control[0],
44 "Result is subjective to chopping");
45 assert.sameValue(view[3], 0);
46
47 control[0] = 123456789;
48 view[3] = 123456789;
49 assert.sameValue(Atomics.and(view, 3, 0), control[0],
50 "Result is subjective to chopping");
51 assert.sameValue(view[3], 0);
52
53 // In-bounds boundary cases for indexing
54 testWithAtomicsInBoundsIndices(function(IdxGen) {
55 let Idx = IdxGen(view);
56 view.fill(0);
57 // Atomics.store() computes an index from Idx in the same way as other
58 // Atomics operations, not quite like view[Idx].
59 Atomics.store(view, Idx, 37);
60 assert.sameValue(Atomics.and(view, Idx, 0), 37);
61 });
62 }, int_views);