Debian Codegraph @

js/src/tests/test262/built-ins/Atomics/load/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.load
7 description: Test Atomics.load 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
15 const views = nonClampedIntArrayConstructors.slice();
16
17 testWithTypedArrayConstructors(function(TA) {
18 // Make it interesting - use non-zero byteOffsets and non-zero indexes.
19
20 const view = new TA(sab, 32, 20);
21 const control = new TA(ab, 0, 2);
22
23 view[3] = -5;
24 control[0] = -5;
25 assert.sameValue(Atomics.load(view, 3), control[0],
26 'Atomics.load(view, 3) returns the value of `control[0]` (-5)');
27
28 control[0] = 12345;
29 view[3] = 12345;
30 assert.sameValue(Atomics.load(view, 3), control[0],
31 'Atomics.load(view, 3) returns the value of `control[0]` (12345)');
32
33 control[0] = 123456789;
34 view[3] = 123456789;
35 assert.sameValue(Atomics.load(view, 3), control[0],
36 'Atomics.load(view, 3) returns the value of `control[0]` (123456789)');
37
38 // In-bounds boundary cases for indexing
39 testWithAtomicsInBoundsIndices(function(IdxGen) {
40 let Idx = IdxGen(view);
41 view.fill(0);
42 // Atomics.store() computes an index from Idx in the same way as other
43 // Atomics operations, not quite like view[Idx].
44 Atomics.store(view, Idx, 37);
45 assert.sameValue(Atomics.load(view, Idx), 37, 'Atomics.load(view, Idx) returns 37');
46 });
47 }, views);
48
49 reportCompare(0, 0);