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