Debian Codegraph @

js/src/jit-test/tests/typedarray/typed-array-change-by-copy.js

raw
1 // |jit-test|
2
3 load(libdir + 'array-compare.js');
4 load(libdir + "asserts.js");
5
6 let typedArray123 = new Uint8Array([1, 2, 3]);
7 let typedArray12345 = new Uint8Array([1, 2, 3, 4, 5]);
8 let typedArray = new Uint8Array([1, 2, 3]);
9 let typedArray2 = new Uint8Array([3, 2, 1]);
10
11 let a_with = typedArray.with(1, 42);
12 assertEq(arraysEqual(typedArray, new Uint8Array([1, 2, 3])), true);
13 assertEq(arraysEqual(a_with, new Uint8Array([1, 42, 3])), true);
14
15 let tarray1 = new Uint8Array([42, 2, 3]);
16 let tarray2 = new Uint8Array([1, 2, 42]);
17
18 assertEq(arraysEqual(typedArray.with(-0, 42), tarray1), true);
19
20 /* null => 0 */
21 assertEq(arraysEqual(typedArray.with(null, 42), tarray1), true);
22 /* [] => 0 */
23 assertEq(arraysEqual(typedArray.with([], 42), tarray1), true);
24
25 assertEq(arraysEqual(typedArray.with("2", 42), tarray2), true);
26
27 /* Non-numeric indices => 0 */
28 assertEq(arraysEqual(typedArray.with("monkeys", 42), tarray1), true);
29 assertEq(arraysEqual(typedArray.with(undefined, 42), tarray1), true);
30 assertEq(arraysEqual(typedArray.with(function() {}, 42), tarray1), true);
31
32 assertThrowsInstanceOf(() => typedArray.with(3, 42), RangeError);
33 assertThrowsInstanceOf(() => typedArray.with(5, 42), RangeError);
34 assertThrowsInstanceOf(() => typedArray.with(-10, 42), RangeError);
35 assertThrowsInstanceOf(() => typedArray.with(Infinity, 42), RangeError);
36
37 let reversedIntArray = typedArray.toReversed();
38 assertEq(arraysEqual(typedArray, typedArray123), true);
39 assertEq(arraysEqual(reversedIntArray, typedArray2), true);
40
41 let sortedIntArray = typedArray2.toSorted();
42 assertEq(arraysEqual(typedArray2, new Uint8Array([3, 2, 1])), true);
43 assertEq(arraysEqual(sortedIntArray, typedArray), true);