Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/Atomics/store/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.store
6 description: Test Atomics.store 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 for (let val of [10, -5,
23 12345,
24 123456789,
25 Math.PI,
26 "33",
27 {
28 valueOf: () => 33
29 },
30 undefined
31 ])
32 {
33 assert.sameValue(Atomics.store(view, 3, val), ToInteger(val),
34 "Atomics.store returns its third argument (" + val + ") converted to Integer, not the input value nor the value that was stored");
35
36 control[0] = val;
37 assert.sameValue(view[3], control[0]);
38 }
39
40 // In-bounds boundary cases for indexing
41 testWithAtomicsInBoundsIndices(function(IdxGen) {
42 let Idx = IdxGen(view);
43 view.fill(0);
44 Atomics.store(view, Idx, 37);
45 assert.sameValue(Atomics.load(view, Idx), 37);
46 });
47 }, int_views);
48
49 function ToInteger(v) {
50 v = +v;
51 if (isNaN(v))
52 return 0;
53 if (v == 0 || !isFinite(v))
54 return v;
55 if (v < 0)
56 return -Math.floor(Math.abs(v));
57 return Math.floor(v);
58 }