1/*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/*
17 * @tc.name:arrayfindIndex
18 * @tc.desc:test Array.findlastIndex
19 * @tc.type: FUNC
20 * @tc.require: issueI8FBM3
21 */
22
23(function() {
24    var a = [0, 1,,3];
25    var index = a.findLastIndex(function(val){
26        return val === undefined;
27    });
28    print(index);
29})();
30
31var arr1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
32var arr2 = new Array();
33function testFunction(element, index, array) {
34    if (index == 9) {
35        array.length = 6;
36    }
37    return element < 1;
38}
39for (let i = 0; i < 10; i++) arr2[i] = i;
40
41var result1 = arr1.findLastIndex(testFunction);
42print(result1);
43var result2 = arr2.findLastIndex(testFunction);
44print(result2);
45
46let arr3 = [1, 2, , 7, , undefined];
47arr3.__proto__.push(9);
48arr3.__proto__.push(9);
49arr3.__proto__.push(9);
50function fun1(element) {
51    return element === 1;
52}
53print(arr3.findLastIndex(fun1));
54arr3.__proto__.pop(9);
55arr3.__proto__.pop(9);
56arr3.__proto__.pop(9);
57
58//slowPath
59let arr4 = [1, 2, 3, 4, 5, 6, 7, 8];
60function func2(element, index, arr) {
61    return element === 6;
62}
63print(arr4.findLastIndex(func2));
64
65//notFound
66let arr5 = new Array(5, 2, 7, 9, 20);
67function func3(element, index, arr) {
68    arr.length = 3;
69    return element === 100;
70}
71print(arr5.findLastIndex(func3));