Debian Codegraph @

js/src/tests/test262/built-ins/Atomics/store/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.store
7 description: Test Atomics.store 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 const values = [
23 10,
24 -5,
25 12345,
26 123456789,
27 Math.PI,
28 "33",
29 {
30 valueOf: function() { return 33; }
31 },
32 undefined
33 ];
34
35 for (let i = 0; i < values.length; i++) {
36 let val = values[i];
37 assert.sameValue(Atomics.store(view, 3, val), ToInteger(val),
38 'Atomics.store(view, 3, val) returns ToInteger(val)');
39
40 control[0] = val;
41 assert.sameValue(
42 view[3],
43 control[0],
44 'The value of view[3] equals the value of `control[0]` (val)'
45 );
46 }
47
48 // In-bounds boundary cases for indexing
49 testWithAtomicsInBoundsIndices(function(IdxGen) {
50 let Idx = IdxGen(view);
51 view.fill(0);
52 Atomics.store(view, Idx, 37);
53 assert.sameValue(Atomics.load(view, Idx), 37, 'Atomics.load(view, Idx) returns 37');
54 });
55 }, views);
56
57 function ToInteger(v) {
58 v = +v;
59 if (isNaN(v)) {
60 return 0;
61 }
62 if (v == 0 || !isFinite(v)) {
63 return v;
64 }
65 if (v < 0) {
66 return -Math.floor(Math.abs(v));
67 }
68 return Math.floor(v);
69 }
70
71 reportCompare(0, 0);