14514f5e3Sopenharmony_ci/* 24514f5e3Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License. 54514f5e3Sopenharmony_ci * You may obtain a copy of the License at 64514f5e3Sopenharmony_ci * 74514f5e3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 84514f5e3Sopenharmony_ci * 94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and 134514f5e3Sopenharmony_ci * limitations under the License. 144514f5e3Sopenharmony_ci */ 154514f5e3Sopenharmony_ci 164514f5e3Sopenharmony_cideclare interface ArkTools { 174514f5e3Sopenharmony_ci isAOTCompiled(args: any): boolean; 184514f5e3Sopenharmony_ci} 194514f5e3Sopenharmony_cideclare function print(arg:any):string; 204514f5e3Sopenharmony_cifunction replace(a : number) 214514f5e3Sopenharmony_ci{ 224514f5e3Sopenharmony_ci return a; 234514f5e3Sopenharmony_ci} 244514f5e3Sopenharmony_ci 254514f5e3Sopenharmony_cifunction doValues(x : any) { 264514f5e3Sopenharmony_ci return mySet.values(x); 274514f5e3Sopenharmony_ci} 284514f5e3Sopenharmony_ci 294514f5e3Sopenharmony_cifunction printValues(x : any) { 304514f5e3Sopenharmony_ci try { 314514f5e3Sopenharmony_ci print(doValues(x)); 324514f5e3Sopenharmony_ci } finally { 334514f5e3Sopenharmony_ci } 344514f5e3Sopenharmony_ci} 354514f5e3Sopenharmony_ci 364514f5e3Sopenharmony_cilet mySet = new Set([0, 0.0, 5, -200.5, 1e-78, NaN, "xyz", "12345"]); 374514f5e3Sopenharmony_ci 384514f5e3Sopenharmony_ci// Check without params 394514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.values, caller function name:func_main_0@builtinSetValues 404514f5e3Sopenharmony_ciprint(mySet.values()); //: [object Set Iterator] 414514f5e3Sopenharmony_ci 424514f5e3Sopenharmony_ci// Check with single param 434514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.values, caller function name:func_main_0@builtinSetValues 444514f5e3Sopenharmony_ciprint(mySet.values(0).next().value); //: 0 454514f5e3Sopenharmony_ci 464514f5e3Sopenharmony_ci// Check with 2 params 474514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.values, caller function name:func_main_0@builtinSetValues 484514f5e3Sopenharmony_ciprint(mySet.values(0, 0).next().value); //: 0 494514f5e3Sopenharmony_ci 504514f5e3Sopenharmony_ci// Check with 3 params 514514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.values, caller function name:func_main_0@builtinSetValues 524514f5e3Sopenharmony_ciprint(mySet.values(-1, 10.2, 15).next().value); //: 0 534514f5e3Sopenharmony_ci 544514f5e3Sopenharmony_ci// Check own methods 554514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.values, caller function name:func_main_0@builtinSetValues 564514f5e3Sopenharmony_ciprint(mySet.values().throw); //: function throw() { [native code] } 574514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.values, caller function name:func_main_0@builtinSetValues 584514f5e3Sopenharmony_ciprint(mySet.values().return); //: function return() { [native code] } 594514f5e3Sopenharmony_ci 604514f5e3Sopenharmony_ci// Check using in loop 614514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.values, caller function name:func_main_0@builtinSetValues 624514f5e3Sopenharmony_cifor (let key of mySet.values()) { 634514f5e3Sopenharmony_ci print(key); 644514f5e3Sopenharmony_ci} 654514f5e3Sopenharmony_ci//: 0 664514f5e3Sopenharmony_ci//: 5 674514f5e3Sopenharmony_ci//: -200.5 684514f5e3Sopenharmony_ci//: 1e-78 694514f5e3Sopenharmony_ci//: NaN 704514f5e3Sopenharmony_ci//: xyz 714514f5e3Sopenharmony_ci//: 12345 724514f5e3Sopenharmony_ci 734514f5e3Sopenharmony_ci// Replace standard builtin 744514f5e3Sopenharmony_cilet true_values = mySet.values 754514f5e3Sopenharmony_cimySet.values = replace 764514f5e3Sopenharmony_ci 774514f5e3Sopenharmony_ci// no deopt 784514f5e3Sopenharmony_ciprint(mySet.values(2.5)); //: 2.5 794514f5e3Sopenharmony_cimySet.values = true_values 804514f5e3Sopenharmony_ci 814514f5e3Sopenharmony_ciif (ArkTools.isAOTCompiled(printValues)) { 824514f5e3Sopenharmony_ci // Replace standard builtin after call to standard builtin was profiled 834514f5e3Sopenharmony_ci mySet.values = replace 844514f5e3Sopenharmony_ci} 854514f5e3Sopenharmony_ciprintValues(2.5); //pgo: [object Set Iterator] 864514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotCallTarget1 874514f5e3Sopenharmony_ci//aot: 2.5 884514f5e3Sopenharmony_ci 894514f5e3Sopenharmony_ciprintValues("abc"); //pgo: [object Set Iterator] 904514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotCallTarget1 914514f5e3Sopenharmony_ci//aot: abc 924514f5e3Sopenharmony_ci 934514f5e3Sopenharmony_cimySet.values = true_values 944514f5e3Sopenharmony_ci 954514f5e3Sopenharmony_ci// Check IR correctness inside try-block 964514f5e3Sopenharmony_citry { 974514f5e3Sopenharmony_ci //aot: [trace] aot inline builtin: Set.values, caller function name:#*#doValues@builtinSetValues 984514f5e3Sopenharmony_ci printValues(2.5); //: [object Set Iterator] 994514f5e3Sopenharmony_ci //aot: [trace] aot inline builtin: Set.values, caller function name:#*#doValues@builtinSetValues 1004514f5e3Sopenharmony_ci printValues("abc"); //: [object Set Iterator] 1014514f5e3Sopenharmony_ci} catch (e) { 1024514f5e3Sopenharmony_ci} 1034514f5e3Sopenharmony_ci 1044514f5e3Sopenharmony_ci// Check using out of boundaries 1054514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.values, caller function name:func_main_0@builtinSetValues 1064514f5e3Sopenharmony_cilet iter1 = mySet.values(); 1074514f5e3Sopenharmony_ci 1084514f5e3Sopenharmony_cifor (let key of iter1) { 1094514f5e3Sopenharmony_ci print(key); 1104514f5e3Sopenharmony_ci} 1114514f5e3Sopenharmony_ci//: 0 1124514f5e3Sopenharmony_ci//: 5 1134514f5e3Sopenharmony_ci//: -200.5 1144514f5e3Sopenharmony_ci//: 1e-78 1154514f5e3Sopenharmony_ci//: NaN 1164514f5e3Sopenharmony_ci//: xyz 1174514f5e3Sopenharmony_ci//: 12345 1184514f5e3Sopenharmony_ci 1194514f5e3Sopenharmony_ci// Check reusing possibility 1204514f5e3Sopenharmony_cifor (let key of iter1) { 1214514f5e3Sopenharmony_ci print(key); 1224514f5e3Sopenharmony_ci} // <nothing> 1234514f5e3Sopenharmony_ci 1244514f5e3Sopenharmony_ciprint(iter1.next().value); //: undefined 1254514f5e3Sopenharmony_ci 1264514f5e3Sopenharmony_ci// Check using after inserting / deleting 1274514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.values, caller function name:func_main_0@builtinSetValues 1284514f5e3Sopenharmony_cilet iter2 = mySet.values(); 1294514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:func_main_0@builtinSetValues 1304514f5e3Sopenharmony_cimySet.delete(5); 1314514f5e3Sopenharmony_cimySet.add(30); //aot: [trace] aot inline builtin: Set.add, caller function name:func_main_0@builtinSetValues 1324514f5e3Sopenharmony_cimySet.add(NaN); //aot: [trace] aot inline builtin: Set.add, caller function name:func_main_0@builtinSetValues 1334514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:func_main_0@builtinSetValues 1344514f5e3Sopenharmony_cimySet.delete("12345"); 1354514f5e3Sopenharmony_cifor (let key of iter2) { 1364514f5e3Sopenharmony_ci print(key); 1374514f5e3Sopenharmony_ci} 1384514f5e3Sopenharmony_ci//: 0 1394514f5e3Sopenharmony_ci//: -200.5 1404514f5e3Sopenharmony_ci//: 1e-78 1414514f5e3Sopenharmony_ci//: NaN 1424514f5e3Sopenharmony_ci//: xyz 1434514f5e3Sopenharmony_ci//: 30 144