Debian Codegraph @

js/src/jit-test/tests/typedarray/resizable-typedarray-get-elem.js

raw
1 const TypedArrays = [
2 Int8Array,
3 Uint8Array,
4 Int16Array,
5 Uint16Array,
6 Int32Array,
7 Uint32Array,
8 Uint8ClampedArray,
9 Float16Array,
10 Float32Array,
11 Float64Array,
12 BigInt64Array,
13 BigUint64Array,
14 ];
15
16 function test(TA) {
17 const length = 4;
18 const byteLength = length * TA.BYTES_PER_ELEMENT;
19
20 let rab = new ArrayBuffer(byteLength, {maxByteLength: byteLength});
21 let actual = new TA(rab);
22 let expected = new TA(length);
23 let type = expected[0].constructor;
24
25 for (let i = 0; i < length; ++i) {
26 actual[i] = type(i * i);
27 expected[i] = type(i * i);
28 }
29
30 // In-bounds access
31 for (let i = 0; i < 200; ++i) {
32 let index = i % length;
33 assertEq(actual[index], expected[index]);
34 }
35
36 // Out-of-bounds access
37 for (let i = 0; i < 200; ++i) {
38 let index = i % (length + 4);
39 assertEq(actual[index], expected[index]);
40 }
41 }
42
43 for (let TA of TypedArrays) {
44 // Copy test function to ensure monomorphic ICs.
45 let copy = Function(`return ${test}`)();
46
47 copy(TA);
48 }