diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/tests/non262/TypedArray/slice.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/TypedArray/slice.js')
-rw-r--r-- | js/src/tests/non262/TypedArray/slice.js | 45 |
1 files changed, 45 insertions, 0 deletions
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); + |