From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- js/src/tests/non262/TypedArray/slice.js | 45 +++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 js/src/tests/non262/TypedArray/slice.js (limited to 'js/src/tests/non262/TypedArray/slice.js') diff --git a/js/src/tests/non262/TypedArray/slice.js b/js/src/tests/non262/TypedArray/slice.js new file mode 100644 index 0000000000..0a5ce4c50b --- /dev/null +++ b/js/src/tests/non262/TypedArray/slice.js @@ -0,0 +1,45 @@ +for (var constructor of anyTypedArrayConstructors) { + assertDeepEq(constructor.prototype.slice.length, 2); + + assertDeepEq(new constructor().slice(0), new constructor()); + assertDeepEq(new constructor().slice(0, 4), new constructor()); + assertDeepEq(new constructor(10).slice(0, 2), new constructor(2)); + + assertDeepEq(new constructor([1, 2]).slice(1), new constructor([2])); + assertDeepEq(new constructor([1, 2]).slice(0), new constructor([1, 2])); + assertDeepEq(new constructor([1, 2, 3]).slice(-1), new constructor([3])); + assertDeepEq(new constructor([1, 2, 3, 4]).slice(-3, -1), new constructor([2, 3])); + assertDeepEq(new constructor([.1, .2]).slice(0), new constructor([.1, .2])); + + assertDeepEq(new constructor([1, 2]).slice(-3), new constructor([1, 2])); + assertDeepEq(new constructor([1, 2]).slice(0, -3), new constructor()); + assertDeepEq(new constructor([1, 2]).slice(4), new constructor()); + assertDeepEq(new constructor([1, 2]).slice(1, 5), new constructor([2])); + + // Called from other globals. + if (typeof newGlobal === "function") { + var slice = newGlobal()[constructor.name].prototype.slice; + assertDeepEq(slice.call(new constructor([3, 2, 1]), 1), + new constructor([2, 1])); + } + + // Throws if `this` isn't a TypedArray. + var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, + new Proxy(new constructor(), {})]; + invalidReceivers.forEach(invalidReceiver => { + assertThrowsInstanceOf(() => { + constructor.prototype.slice.call(invalidReceiver, 0); + }, TypeError, "Assert that slice fails if this value is not a TypedArray"); + }); + + // Test that the length getter is never called. + Object.defineProperty(new constructor([1, 2, 3]), "length", { + get() { + throw new Error("length accessor called"); + } + }).slice(2); +} + +if (typeof reportCompare === "function") + reportCompare(true, true); + -- cgit v1.2.3