From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../tests/typedarray/typed-array-change-by-copy.js | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 js/src/jit-test/tests/typedarray/typed-array-change-by-copy.js (limited to 'js/src/jit-test/tests/typedarray/typed-array-change-by-copy.js') 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..4aa12a615d --- /dev/null +++ b/js/src/jit-test/tests/typedarray/typed-array-change-by-copy.js @@ -0,0 +1,43 @@ +// |jit-test| + +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); -- cgit v1.2.3