• 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 interface ArkTools {
17    isAOTCompiled(args: any): boolean;
18}
19declare function print(arg:any):string;
20function replace(a : number)
21{
22    return a;
23}
24
25function doValues(x : any) {
26    return mySet.values(x);
27}
28
29function printValues(x : any) {
30    try {
31        print(doValues(x));
32    } finally {
33    }
34}
35
36let mySet = new Set([0, 0.0, 5, -200.5, 1e-78, NaN, "xyz", "12345"]);
37
38// Check without params
39//aot: [trace] aot call builtin: Set.values, caller function name:func_main_0@builtinSetValues
40print(mySet.values()); //: [object Set Iterator]
41
42// Check with single param
43//aot: [trace] aot call builtin: Set.values, caller function name:func_main_0@builtinSetValues
44//aot: [trace] aot call builtin: SetIterator.next, caller function name:func_main_0@builtinSetValues
45print(mySet.values(0).next().value); //: 0
46
47// Check with 2 params
48//aot: [trace] aot call builtin: Set.values, caller function name:func_main_0@builtinSetValues
49//aot: [trace] aot call builtin: SetIterator.next, caller function name:func_main_0@builtinSetValues
50print(mySet.values(0, 0).next().value); //: 0
51
52// Check with 3 params
53//aot: [trace] aot call builtin: Set.values, caller function name:func_main_0@builtinSetValues
54//aot: [trace] aot call builtin: SetIterator.next, caller function name:func_main_0@builtinSetValues
55print(mySet.values(-1, 10.2, 15).next().value); //: 0
56
57// Check own methods
58//aot: [trace] aot call builtin: Set.values, caller function name:func_main_0@builtinSetValues
59print(mySet.values().throw); //: function throw() { [native code] }
60//aot: [trace] aot call builtin: Set.values, caller function name:func_main_0@builtinSetValues
61print(mySet.values().return); //: function return() { [native code] }
62
63// Check using in loop
64//aot: [trace] aot call builtin: Set.values, caller function name:func_main_0@builtinSetValues
65for (let key of mySet.values()) {
66    print(key);
67}
68//aot: [trace] aot call builtin: SetIterator.next, caller function name:func_main_0@builtinSetValues
69//: 0
70//aot: [trace] aot call builtin: SetIterator.next, caller function name:func_main_0@builtinSetValues
71//: 5
72//aot: [trace] aot call builtin: SetIterator.next, caller function name:func_main_0@builtinSetValues
73//: -200.5
74//aot: [trace] aot call builtin: SetIterator.next, caller function name:func_main_0@builtinSetValues
75//: 1e-78
76//aot: [trace] aot call builtin: SetIterator.next, caller function name:func_main_0@builtinSetValues
77//: NaN
78//aot: [trace] aot call builtin: SetIterator.next, caller function name:func_main_0@builtinSetValues
79//: xyz
80//aot: [trace] aot call builtin: SetIterator.next, caller function name:func_main_0@builtinSetValues
81//: 12345
82//aot: [trace] aot call builtin: SetIterator.next, caller function name:func_main_0@builtinSetValues
83
84// Replace standard builtin
85let true_values = mySet.values
86mySet.values = replace
87
88// no deopt
89print(mySet.values(2.5)); //: 2.5
90mySet.values = true_values
91
92if (ArkTools.isAOTCompiled(printValues)) {
93    // Replace standard builtin after call to standard builtin was profiled
94    mySet.values = replace
95}
96printValues(2.5); //pgo: [object Set Iterator]
97//aot: [trace] Check Type: NotCallTarget1
98//aot: 2.5
99
100printValues("abc"); //pgo: [object Set Iterator]
101//aot: [trace] Check Type: NotCallTarget1
102//aot: abc
103
104mySet.values = true_values
105
106// Check IR correctness inside try-block
107try {
108    //aot: [trace] aot call builtin: Set.values, caller function name:#*#doValues@builtinSetValues
109    printValues(2.5); //: [object Set Iterator]
110    //aot: [trace] aot call builtin: Set.values, caller function name:#*#doValues@builtinSetValues
111    printValues("abc"); //: [object Set Iterator]
112} catch (e) {
113}
114
115// Check using out of boundaries
116//aot: [trace] aot call builtin: Set.values, caller function name:func_main_0@builtinSetValues
117let iter1 = mySet.values();
118
119for (let key of iter1) {
120    print(key);
121}
122//aot: [trace] aot call builtin: SetIterator.next, caller function name:func_main_0@builtinSetValues
123//: 0
124//aot: [trace] aot call builtin: SetIterator.next, caller function name:func_main_0@builtinSetValues
125//: 5
126//aot: [trace] aot call builtin: SetIterator.next, caller function name:func_main_0@builtinSetValues
127//: -200.5
128//aot: [trace] aot call builtin: SetIterator.next, caller function name:func_main_0@builtinSetValues
129//: 1e-78
130//aot: [trace] aot call builtin: SetIterator.next, caller function name:func_main_0@builtinSetValues
131//: NaN
132//aot: [trace] aot call builtin: SetIterator.next, caller function name:func_main_0@builtinSetValues
133//: xyz
134//aot: [trace] aot call builtin: SetIterator.next, caller function name:func_main_0@builtinSetValues
135//: 12345
136//aot: [trace] aot call builtin: SetIterator.next, caller function name:func_main_0@builtinSetValues
137
138// Check reusing possibility
139for (let key of iter1) {
140    //aot: [trace] aot call builtin: SetIterator.next, caller function name:func_main_0@builtinSetValues
141    print(key);
142} // <nothing>
143
144//aot: [trace] aot call builtin: SetIterator.next, caller function name:func_main_0@builtinSetValues
145print(iter1.next().value); //: undefined
146
147// Check using after inserting / deleting
148//aot: [trace] aot call builtin: Set.values, caller function name:func_main_0@builtinSetValues
149let iter2 = mySet.values();
150//aot: [trace] aot inline builtin: Set.delete, caller function name:func_main_0@builtinSetValues
151mySet.delete(5);
152mySet.add(30);  //aot: [trace] aot inline builtin: Set.add, caller function name:func_main_0@builtinSetValues
153mySet.add(NaN); //aot: [trace] aot inline builtin: Set.add, caller function name:func_main_0@builtinSetValues
154//aot: [trace] aot inline builtin: Set.delete, caller function name:func_main_0@builtinSetValues
155mySet.delete("12345");
156for (let key of iter2) {
157    print(key);
158}
159//aot: [trace] aot call builtin: SetIterator.next, caller function name:func_main_0@builtinSetValues
160//: 0
161//aot: [trace] aot call builtin: SetIterator.next, caller function name:func_main_0@builtinSetValues
162//: -200.5
163//aot: [trace] aot call builtin: SetIterator.next, caller function name:func_main_0@builtinSetValues
164//: 1e-78
165//aot: [trace] aot call builtin: SetIterator.next, caller function name:func_main_0@builtinSetValues
166//: NaN
167//aot: [trace] aot call builtin: SetIterator.next, caller function name:func_main_0@builtinSetValues
168//: xyz
169//aot: [trace] aot call builtin: SetIterator.next, caller function name:func_main_0@builtinSetValues
170//: 30
171//aot: [trace] aot call builtin: SetIterator.next, caller function name:func_main_0@builtinSetValues
172