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 --- .../return-found-value-predicate-result-is-true.js | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 js/src/tests/test262/built-ins/TypedArray/prototype/findLast/return-found-value-predicate-result-is-true.js (limited to 'js/src/tests/test262/built-ins/TypedArray/prototype/findLast/return-found-value-predicate-result-is-true.js') diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/findLast/return-found-value-predicate-result-is-true.js b/js/src/tests/test262/built-ins/TypedArray/prototype/findLast/return-found-value-predicate-result-is-true.js new file mode 100644 index 0000000000..842492b522 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/findLast/return-found-value-predicate-result-is-true.js @@ -0,0 +1,55 @@ +// Copyright (C) 2021 Microsoft. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.findlast +description: > + Return found value if predicate return a boolean true value. +info: | + %TypedArray%.prototype.findLast (predicate [ , thisArg ] ) + + 6. Repeat, while k ≥ 0, + ... + c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + d. If testResult is true, return kValue. + ... +includes: [testTypedArray.js] +features: [Symbol, TypedArray, array-find-from-last] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([39, 2, 62]); + var called, result; + + called = 0; + result = sample.findLast(function() { + called++; + return true; + }); + assert.sameValue(result, 62, "returned true on sample[2]"); + assert.sameValue(called, 1, "predicate was called once"); + + called = 0; + result = sample.findLast(function(val) { + called++; + return val === 39; + }); + assert.sameValue(called, 3, "predicate was called three times"); + assert.sameValue(result, 39, "returned true on sample[0]"); + + result = sample.findLast(function() { return "string"; }); + assert.sameValue(result, 62, "ToBoolean(string)"); + + result = sample.findLast(function() { return {}; }); + assert.sameValue(result, 62, "ToBoolean(object)"); + + result = sample.findLast(function() { return Symbol(""); }); + assert.sameValue(result, 62, "ToBoolean(symbol)"); + + result = sample.findLast(function() { return 1; }); + assert.sameValue(result, 62, "ToBoolean(number)"); + + result = sample.findLast(function() { return -1; }); + assert.sameValue(result, 62, "ToBoolean(negative number)"); +}); + +reportCompare(0, 0); -- cgit v1.2.3