Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/Atomics/or/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.or
6 description: Test Atomics.or 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 var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];
14
15 testWithTypedArrayConstructors(function(View) {
16 // Make it interesting - use non-zero byteOffsets and non-zero indexes.
17
18 var view = new View(sab, 32, 20);
19 var control = new View(ab, 0, 2);
20
21 view[8] = 0x33333333;
22 control[0] = 0x33333333;
23 assert.sameValue(Atomics.or(view, 8, 0x55555555), control[0],
24 "Result is subject to chopping");
25
26 control[0] = 0x77777777;
27 assert.sameValue(view[8], control[0]);
28 assert.sameValue(Atomics.or(view, 8, 0xF0F0F0F0), control[0],
29 "Result is subject to chopping");
30
31 control[0] = 0xF7F7F7F7;
32 assert.sameValue(view[8], control[0]);
33
34 view[3] = -5;
35 control[0] = -5;
36 assert.sameValue(Atomics.or(view, 3, 0), control[0],
37 "Result is negative and subject to coercion");
38 assert.sameValue(view[3], control[0]);
39
40 control[0] = 12345;
41 view[3] = 12345;
42 assert.sameValue(Atomics.or(view, 3, 0), control[0],
43 "Result is subject to chopping");
44 assert.sameValue(view[3], control[0]);
45
46 control[0] = 123456789;
47 view[3] = 123456789;
48 assert.sameValue(Atomics.or(view, 3, 0), control[0],
49 "Result is subject to chopping");
50 assert.sameValue(view[3], control[0]);
51
52 // In-bounds boundary cases for indexing
53 testWithAtomicsInBoundsIndices(function(IdxGen) {
54 let Idx = IdxGen(view);
55 view.fill(0);
56 // Atomics.store() computes an index from Idx in the same way as other
57 // Atomics operations, not quite like view[Idx].
58 Atomics.store(view, Idx, 37);
59 assert.sameValue(Atomics.or(view, Idx, 0), 37);
60 });
61 }, int_views);