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 --- .../non262/Array/splice-species-changes-length.js | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 js/src/tests/non262/Array/splice-species-changes-length.js (limited to 'js/src/tests/non262/Array/splice-species-changes-length.js') diff --git a/js/src/tests/non262/Array/splice-species-changes-length.js b/js/src/tests/non262/Array/splice-species-changes-length.js new file mode 100644 index 0000000000..0e4ed32b01 --- /dev/null +++ b/js/src/tests/non262/Array/splice-species-changes-length.js @@ -0,0 +1,48 @@ +// Case 1: splice() removes an element from the array. +{ + let array = []; + array.push(0, 1, 2); + + array.constructor = { + [Symbol.species]: function(n) { + // Increase the initialized length of the array. + array.push(3, 4, 5); + + // Make the length property non-writable. + Object.defineProperty(array, "length", {writable: false}); + + return new Array(n); + } + } + + assertThrowsInstanceOf(() => Array.prototype.splice.call(array, 0, 1), TypeError); + + assertEq(array.length, 6); + assertEqArray(array, [1, 2, /* hole */, 3, 4, 5]); +} + +// Case 2: splice() adds an element to the array. +{ + let array = []; + array.push(0, 1, 2); + + array.constructor = { + [Symbol.species]: function(n) { + // Increase the initialized length of the array. + array.push(3, 4, 5); + + // Make the length property non-writable. + Object.defineProperty(array, "length", {writable: false}); + + return new Array(n); + } + } + + assertThrowsInstanceOf(() => Array.prototype.splice.call(array, 0, 0, 123), TypeError); + + assertEq(array.length, 6); + assertEqArray(array, [123, 0, 1, 2, 4, 5]); +} + +if (typeof reportCompare === "function") + reportCompare(true, true); -- cgit v1.2.3