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 --- .../Tuple/prototype/toReversed/toReversed.js | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 js/src/tests/non262/Tuple/prototype/toReversed/toReversed.js (limited to 'js/src/tests/non262/Tuple/prototype/toReversed/toReversed.js') diff --git a/js/src/tests/non262/Tuple/prototype/toReversed/toReversed.js b/js/src/tests/non262/Tuple/prototype/toReversed/toReversed.js new file mode 100644 index 0000000000..2c672ef1ce --- /dev/null +++ b/js/src/tests/non262/Tuple/prototype/toReversed/toReversed.js @@ -0,0 +1,29 @@ +// |reftest| skip-if(!this.hasOwnProperty("Tuple")) +/* +8.2.3.28 Tuple.prototype.toReversed ( ) +When the toReversed method is called, the following steps are taken: + +1. Let T be ? thisTupleValue(this value). +2. Let oldList be a new List containing the elements of T.[[Sequence]]. +3. Let newList be a new empty List. +4. Repeat, while oldList is not empty, +a. Remove the last element from oldList, and let E be the value of the element. +b. Append E to the end of List newList. +5. Return a new Tuple value whose [[Sequence]] is newList. +*/ +/* Step 1 */ +/* toReversed() should throw on a non-Tuple */ +let method = Tuple.prototype.toReversed; +assertEq(method.call(#[1,2,3,4,5,6]), #[6,5,4,3,2,1]); +assertEq(method.call(Object(#[1,2,3,4,5,6])), #[6,5,4,3,2,1]); +assertThrowsInstanceOf(() => method.call("monkeys"), TypeError, + "value of TupleObject must be a Tuple"); + +assertEq(#[].toReversed(), #[]); +assertEq(#[1].toReversed(), #[1]); + +/* Test that length is still handled correctly if it's overridden */ +Object.defineProperty(Tuple.prototype, "length", { get() { return 0 } }) +assertEq(#[1,2,3,4,5].toReversed(), #[5,4,3,2,1]); + +reportCompare(0, 0); -- cgit v1.2.3