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 16function test_dropframe() { 17 function test_nested() { 18 a = 2; 19 var d = 0; 20 function nested_inner1() { 21 b = 3; 22 d = 1; 23 var e = 0; 24 function nested_inner2() { 25 c = 4; 26 d = 2; 27 e = 1; 28 } 29 nested_inner2(); 30 } 31 nested_inner1(); 32 } 33 34 function test_parallel() { 35 a = 6; 36 b = 4; 37 c = 5; 38 var d = 1; 39 function parallel_inner1() { 40 a = 4; 41 b = 5; 42 c = 6; 43 d = d * 2; 44 } 45 function parallel_inner2() { 46 d = d + 1; 47 parallel_inner1(); 48 } 49 parallel_inner2(); 50 } 51 52 function test_multicall() { 53 var d = 1; 54 function multicall_inner() { 55 a = a * 2; 56 b = b + a; 57 c = c * b; 58 d = d * c + b * a; 59 } 60 multicall_inner(); 61 multicall_inner(); 62 } 63 64 function test_forloop1() { 65 var d = 1; 66 function forloop1_inner() { 67 a = a * 2; 68 b = b + a; 69 c = c + b * a; 70 d = d * (b - a); 71 } 72 for (let i = 1; i <= 2; i++) { 73 for (let j = 3; j <= 4; j++) { 74 forloop1_inner(); 75 } 76 } 77 } 78 79 function test_forloop2() { 80 var d = 1; 81 for (let i = 1; i <= 2; i++) { 82 for (let j = 3; j <= 4; j++) { 83 d = d + i * j; 84 function forloop2_inner() { 85 a = a * i; 86 b = b + a * j; 87 c = c + a + b; 88 d = d * i * j + c; 89 } 90 forloop2_inner(); 91 } 92 } 93 } 94 95 function test_assign() { 96 var func = undefined 97 function func1() { 98 function func2() { 99 var s = 2 100 func = function func3() { 101 s++ 102 } 103 func() 104 } 105 func2() 106 func() 107 } 108 func1(); 109 } 110 111 function test_recursion() { 112 var x = 6; 113 x = x + 1; 114 a = a + 1; 115 if (a < 10) { 116 test_recursion(); 117 } 118 x = x + 1; 119 a = a + 1; 120 } 121 122 var a = 1; 123 var b = 2; 124 var c = 3; 125 test_nested(); 126 test_parallel(); 127 test_multicall(); 128 test_forloop1(); 129 test_forloop2(); 130 test_assign(); 131 a = 1; 132 test_recursion(); 133 134 function test_args() { 135 var d = 1; 136 function args_inner(...args) { 137 var numArgs = args.length; 138 for (var i = 0; i < numArgs; i++) { 139 a += args[i]; 140 b += args[i]; 141 c += args[i]; 142 d += args[i]; 143 } 144 d += 1; 145 } 146 args_inner(); 147 args_inner(1); 148 args_inner(1, 2); 149 args_inner(1, 2, 3); 150 args_inner(1, 2, 3, 4); 151 args_inner(1, 2, 3, 4, 5); 152 args_inner(1, 2, 3, 4, 5, 6); 153 } 154 155 function test_newobj() { 156 var d = 1; 157 class TestClass { 158 constructor() { 159 var e = 1; 160 function foo1() { 161 e += a - b + c - d + e; 162 a += 1; 163 b += 2; 164 c += 3; 165 d += 4; 166 } 167 foo1(); 168 } 169 foo2() { 170 a += d; 171 b += d; 172 c += d; 173 d += 1; 174 } 175 176 foo3() { 177 var e = 1; 178 function foo3_inner() { 179 e += a - b + c - d + e; 180 a += 1; 181 b += 2; 182 c += 3; 183 d += 4; 184 } 185 foo3_inner(); 186 } 187 } 188 189 var obj = new TestClass(); 190 obj.foo2(); 191 obj.foo2(); 192 obj.foo3(); 193 obj.foo3(); 194 } 195 196 function test_newobjsuper() { 197 var d = 10; 198 199 class TestClassSuper { 200 constructor() { 201 var e = 1; 202 function fooSuper() { 203 e = e + d; 204 d = d + a; 205 a = a + b + c; 206 b = b + d; 207 c = c + e; 208 } 209 fooSuper(); 210 } 211 } 212 213 class TestClass2 extends TestClassSuper { 214 constructor() { 215 super(); 216 a = a + 1; 217 b = b + 1; 218 c = c + 1; 219 } 220 221 foo() { 222 a = a + 1; 223 b = b + 2; 224 c = c + 3; 225 d = d + a; 226 } 227 } 228 229 var obj2 = new TestClass2(); 230 obj2.foo(); 231 obj2.foo(); 232 } 233 234 b = 2; 235 c = 3; 236 test_args(); 237 test_newobj(); 238 a = 1; 239 b = 2; 240 c = 3; 241 test_newobjsuper(); 242 a = a + c; 243 b = b + a; 244} 245 246test_dropframe();