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