1/* 2 * Copyright (c) 2025 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 16print("Test for NotFoud IC Case."); 17 18// Test1: test not found ic 19function Test1() { 20 let obj1 = {}; 21 let obj2 = {}; 22 let obj3 = {}; 23 obj1.__proto__ = obj2; 24 obj2.__proto__ = obj3; 25 26 let sum = 0; 27 function add(obj) { 28 if (obj.x != undefined) { 29 sum += obj.x; 30 } 31 } 32 33 for (let i = 0 ; i < 200; i++) { 34 add(obj1); 35 if (i == 100) { 36 obj3.x = 233; 37 } 38 } 39 print("Test1 ans:", sum); 40} 41 42// Test2: test not found ic 43function Test2() { 44 let obj1 = {}; 45 let obj2 = {}; 46 let obj3 = {}; 47 obj1.__proto__ = obj2; 48 49 let sum = 0; 50 function add(obj) { 51 if (obj.x != undefined) { 52 sum += obj.x; 53 } 54 } 55 56 for (let i = 0 ; i < 200; i++) { 57 add(obj1); 58 if (i == 100) { 59 obj3.x = 233; 60 } 61 if (i == 105) { 62 obj2.__proto__ = obj3; 63 } 64 } 65 print("Test2 ans:", sum); 66} 67 68// Test3: test not found ic 69function Test3() { 70 let obj1 = {}; 71 let obj2 = {}; 72 let obj3 = {}; 73 obj1.__proto__ = obj2; 74 75 let sum = 0; 76 function add(obj) { 77 if (obj.x != undefined) { 78 sum += obj.x; 79 } 80 } 81 82 for (let i = 0 ; i < 200; i++) { 83 add(obj1); 84 if (i == 100) { 85 obj3.x = 233; 86 } 87 if (i == 105) { 88 obj2.__proto__ = obj3; 89 } 90 if (i == 110) { 91 obj2.x = 234; 92 } 93 } 94 print("Test3 ans:", sum); 95} 96 97// Test4: test not found ic 98function Test4() { 99 let obj1 = {}; 100 let obj2 = {}; 101 let obj3 = {}; 102 obj1.__proto__ = obj2; 103 obj2.__proto__ = obj3; 104 105 let sum = 0; 106 function add(obj) { 107 if (obj.x != undefined) { 108 sum += obj.x; 109 } 110 } 111 112 for (let i = 0 ; i < 200; i++) { 113 add(obj1); 114 if (i == 100) { 115 obj1.x = 233; 116 } 117 if (i == 105) { 118 delete obj1.x; 119 } 120 if (i == 110) { 121 obj3.x = 234; 122 } 123 } 124 print("Test4 ans:", sum); 125} 126 127// Test5: test not found ic 128function Test5() { 129 let obj1 = {}; 130 let obj2 = {}; 131 let obj3 = {}; 132 obj1.__proto__ = obj2; 133 obj2.__proto__ = obj3; 134 135 let sum = 0; 136 function add(obj) { 137 if (obj.x != undefined) { 138 sum += obj.x; 139 } 140 } 141 142 obj2.x = 235; 143 for (let i = 0 ; i < 200; i++) { 144 add(obj1); 145 if (i == 100) { 146 obj1.x = 233; 147 } 148 if (i == 105) { 149 delete obj1.x; 150 } 151 } 152 print("Test5 ans:", sum); 153} 154 155// Test6: test not found ic (method on itself) 156function Test6() { 157 class F1 {} 158 let f1 = new F1(); 159 let P1 = F1.prototype; 160 let sum = 0; 161 function add(f, num) { 162 if (f != undefined) { 163 sum += f(num); 164 } 165 } 166 for (let i = 0; i < 200; i++) { 167 add(f1.toNumber, "233"); 168 if (i === 100) { 169 f1.toNumber = function (str) { 170 return parseInt(str); 171 }; 172 } 173 } 174 print("Test6 ans:", sum); 175} 176 177// Test7: test not found ic (method on prototype) 178function Test7() { 179 class F1 {} 180 let f1 = new F1(); 181 let P1 = F1.prototype; 182 let sum = 0; 183 function add(f, num) { 184 if (f != undefined) { 185 sum += f(num); 186 } 187 } 188 for (let i = 0; i < 200; i++) { 189 add(f1.toNumber, "233"); 190 if (i === 100) { 191 P1.toNumber = function (str) { 192 return parseInt(str); 193 }; 194 } 195 } 196 print("Test7 ans:", sum); 197} 198 199// Test8: test not found ic (method on Object's prototype) 200function Test8() { 201 class F1 {} 202 let f1 = new F1(); 203 let P1 = F1.prototype; 204 let sum = 0; 205 function add(f, num) { 206 if (f != undefined) { 207 sum += f(num); 208 } 209 } 210 for (let i = 0; i < 200; i++) { 211 add(f1.toNumber, "233"); 212 if (i === 100) { 213 Object.prototype.toNumber = function (str) { 214 return parseInt(str) + 10; 215 }; 216 } 217 } 218 print("Test8 ans:", sum); 219} 220 221// Test9: test not found ic (global object) 222function Test9() { 223 var obj1 = {}; 224 var obj2 = {}; 225 var obj3 = {}; 226 obj1.__proto__ = obj2; 227 obj2.__proto__ = obj3; 228 229 let sum = 0; 230 function add(obj) { 231 if (obj.x != undefined) { 232 sum += obj.x; 233 } 234 } 235 236 for (let i = 0 ; i < 200; i++) { 237 add(obj1); 238 if (i == 100) { 239 obj3.x = 233; 240 } 241 } 242 print("Test9 ans:", sum); 243} 244 245function Test10() 246{ 247 print("Test10 ans:"); 248 class A {} 249 class B extends A {} 250 let b = new B(); 251 b.x = 1; 252 print(b.y); 253 254 255 let arr = [1, 2, 3]; 256 print(arr.x); 257 258 let s = "123"; 259 print(s.concatt); 260 261 let n = 1; 262 print(n.toNumberr); 263} 264 265Test1(); 266Test2(); 267Test3(); 268Test4(); 269Test5(); 270Test6(); 271Test7(); 272Test8(); 273Test9(); 274Test10(); 275 276ArkTools.jitCompileAsync(Test1); 277print(ArkTools.waitJitCompileFinish(Test1)); 278ArkTools.jitCompileAsync(Test2); 279print(ArkTools.waitJitCompileFinish(Test2)); 280ArkTools.jitCompileAsync(Test3); 281print(ArkTools.waitJitCompileFinish(Test3)); 282ArkTools.jitCompileAsync(Test4); 283print(ArkTools.waitJitCompileFinish(Test4)); 284ArkTools.jitCompileAsync(Test5); 285print(ArkTools.waitJitCompileFinish(Test5)); 286ArkTools.jitCompileAsync(Test6); 287print(ArkTools.waitJitCompileFinish(Test6)); 288ArkTools.jitCompileAsync(Test7); 289print(ArkTools.waitJitCompileFinish(Test7)); 290ArkTools.jitCompileAsync(Test8); 291print(ArkTools.waitJitCompileFinish(Test8)); 292ArkTools.jitCompileAsync(Test9); 293print(ArkTools.waitJitCompileFinish(Test9)); 294ArkTools.jitCompileAsync(Test10); 295print(ArkTools.waitJitCompileFinish(Test10)); 296 297Test1(); 298Test2(); 299Test3(); 300Test4(); 301Test5(); 302Test6(); 303Test7(); 304Test8(); 305Test9(); 306Test10(); 307 308function Test11(obj) 309{ 310 print(obj.y); 311} 312 313{ 314 print("Test 11 ans:") 315 class A {} 316 class B extends A {} 317 let b = new B(); 318 b.x = 1; 319 Test11(b); 320 let a = new A(); 321 a.x = 1; 322 Test11(a); 323 let s = "1"; 324 Test11(s); 325 let n = 123; 326 327 ArkTools.jitCompileAsync(Test11); 328 print(ArkTools.waitJitCompileFinish(Test11)); 329 Test11(b); 330 Test11(a); 331 Test11(s); 332 Test11(n); 333 B.prototype.y = 2; 334 Test11(b); 335 Test11(a); 336 Test11(s); 337 Test11(n); 338}