• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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);
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
245// Test10: test not found ic (ldobjbyvalue)
246function Test10() {
247    let obj1 = {};
248    let obj2 = {};
249    let obj3 = {};
250    obj1.__proto__ = obj2;
251
252    let sum = 0;
253    function add(obj) {
254        if (obj["x"] != undefined) {
255            sum += obj["x"];
256        }
257    }
258
259    for (let i = 0 ; i < 200; i++) {
260        add(obj1);
261        if (i == 100) {
262            obj3.x = 233;
263        }
264        if (i == 105) {
265            obj2.__proto__ = obj3;
266        }
267        if (i == 110) {
268            obj2.x = 234;
269        }
270    }
271    print("Test10 ans:", sum);
272}
273
274Test1();
275Test2();
276Test3();
277Test4();
278Test5();
279Test6();
280Test7();
281Test8();
282Test9();
283Test10()