• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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//aot: [trace] aot call builtin: Array.prototype.foreach, caller function name:#*#lenthChangeLess@builtinArrayForEachProtoChange
73//: 1
74//: 2.5
75//: NaN
76lenthChangeLess()
77//aot: [trace] aot inline function name: #*#lengthChangeBigToDic@builtinArrayForEachProtoChange caller function name: func_main_0@builtinArrayForEachProtoChange
78//aot: [trace] aot call builtin: Array.prototype.foreach, caller function name:#*#lengthChangeBigToDic@builtinArrayForEachProtoChange
79//: 1
80//: 2.5
81//: NaN
82//: false
83//: true
84lengthChangeBigToDic()
85//aot: [trace] aot inline function name: #*#prototypeChange@builtinArrayForEachProtoChange caller function name: func_main_0@builtinArrayForEachProtoChange
86//aot: [trace] aot call builtin: Array.prototype.foreach, caller function name:#*#prototypeChange@builtinArrayForEachProtoChange
87//: position5
88//: position6
89prototypeChange()
90