diff options
Diffstat (limited to 'js/src/jit-test/tests/typedarray/typed-array-change-by-copy.js')
-rw-r--r-- | js/src/jit-test/tests/typedarray/typed-array-change-by-copy.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/typedarray/typed-array-change-by-copy.js b/js/src/jit-test/tests/typedarray/typed-array-change-by-copy.js new file mode 100644 index 0000000000..f339d4d94a --- /dev/null +++ b/js/src/jit-test/tests/typedarray/typed-array-change-by-copy.js @@ -0,0 +1,43 @@ +// |jit-test| --enable-change-array-by-copy + +load(libdir + 'array-compare.js'); +load(libdir + "asserts.js"); + +let typedArray123 = new Uint8Array([1, 2, 3]); +let typedArray12345 = new Uint8Array([1, 2, 3, 4, 5]); +let typedArray = new Uint8Array([1, 2, 3]); +let typedArray2 = new Uint8Array([3, 2, 1]); + +let a_with = typedArray.with(1, 42); +assertEq(arraysEqual(typedArray, new Uint8Array([1, 2, 3])), true); +assertEq(arraysEqual(a_with, new Uint8Array([1, 42, 3])), true); + +let tarray1 = new Uint8Array([42, 2, 3]); +let tarray2 = new Uint8Array([1, 2, 42]); + +assertEq(arraysEqual(typedArray.with(-0, 42), tarray1), true); + +/* null => 0 */ +assertEq(arraysEqual(typedArray.with(null, 42), tarray1), true); +/* [] => 0 */ +assertEq(arraysEqual(typedArray.with([], 42), tarray1), true); + +assertEq(arraysEqual(typedArray.with("2", 42), tarray2), true); + +/* Non-numeric indices => 0 */ +assertEq(arraysEqual(typedArray.with("monkeys", 42), tarray1), true); +assertEq(arraysEqual(typedArray.with(undefined, 42), tarray1), true); +assertEq(arraysEqual(typedArray.with(function() {}, 42), tarray1), true); + +assertThrowsInstanceOf(() => typedArray.with(3, 42), RangeError); +assertThrowsInstanceOf(() => typedArray.with(5, 42), RangeError); +assertThrowsInstanceOf(() => typedArray.with(-10, 42), RangeError); +assertThrowsInstanceOf(() => typedArray.with(Infinity, 42), RangeError); + +let reversedIntArray = typedArray.toReversed(); +assertEq(arraysEqual(typedArray, typedArray123), true); +assertEq(arraysEqual(reversedIntArray, typedArray2), true); + +let sortedIntArray = typedArray2.toSorted(); +assertEq(arraysEqual(typedArray2, new Uint8Array([3, 2, 1])), true); +assertEq(arraysEqual(sortedIntArray, typedArray), true); |