1/*
2 * Copyright (c) 2024 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
16declare function print(arg:any):string;
17
18
19function normalForEach(){
20  var x = [1,2.5,NaN,undefined,null,false,true]
21  x.forEach(ele=>{
22    if (ele != 1 || ele != true){
23      print(ele)
24    }
25    })
26}
27function lenthChangeLess(){
28  var y = [1,2.5,NaN,undefined,null,false,true]
29  y.forEach(ele=>{
30    if (ele == 2.5) {
31      y.length = 5
32    }
33    if (ele != null) {
34      print(ele)
35    }
36  })
37}
38function lengthChangeBigToDic(){
39    var y = [1,2.5,NaN,undefined,null,false,true]
40    y.forEach(ele=>{
41    if (ele == 2.5) {
42        y.length = 10000
43        y[9999] = 9999
44    }
45    if (ele != null) {
46        print(ele)
47    }
48    })
49}
50function prototypeChange(){
51  var z = [1,,NaN,false,undefined,,,true]
52  z.forEach(ele=>{
53    if (ele == false){
54      Array.prototype[1] = "position2"
55      Array.prototype[5] = "position5"
56      Object.prototype[6] = "position6"
57    }
58    if (ele == "position2" || ele == "position5" || ele == "position6"){
59      print(ele)
60    }
61  })
62}
63//aot: [trace] aot inline function name: #*#normalForEach@builtinArrayForEachProtoChange caller function name: func_main_0@builtinArrayForEachProtoChange
64//aot: [trace] aot inline builtin: Array.prototype.foreach, caller function name:#*#normalForEach@builtinArrayForEachProtoChange
65//: 2.5
66//: NaN
67//: undefined
68//: null
69//: false
70normalForEach()
71//aot: [trace] aot inline function name: #*#lenthChangeLess@builtinArrayForEachProtoChange caller function name: func_main_0@builtinArrayForEachProtoChange
72//: 1
73//: 2.5
74//: NaN
75lenthChangeLess()
76//aot: [trace] aot inline function name: #*#lengthChangeBigToDic@builtinArrayForEachProtoChange caller function name: func_main_0@builtinArrayForEachProtoChange
77//: 1
78//: 2.5
79//: NaN
80//: false
81//: true
82lengthChangeBigToDic()
83//aot: [trace] aot inline function name: #*#prototypeChange@builtinArrayForEachProtoChange caller function name: func_main_0@builtinArrayForEachProtoChange
84//: position5
85//: position6
86prototypeChange()
87