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 doDelete(x: any): any { 264514f5e3Sopenharmony_ci return mySet.delete(x); 274514f5e3Sopenharmony_ci} 284514f5e3Sopenharmony_ci 294514f5e3Sopenharmony_cifunction printDelete(x: any) { 304514f5e3Sopenharmony_ci try { 314514f5e3Sopenharmony_ci print(doDelete(x)); 324514f5e3Sopenharmony_ci } finally { 334514f5e3Sopenharmony_ci } 344514f5e3Sopenharmony_ci} 354514f5e3Sopenharmony_ci 364514f5e3Sopenharmony_cifunction printDelete2(x: any, y: any) { 374514f5e3Sopenharmony_ci try { 384514f5e3Sopenharmony_ci print(x.delete(y)); 394514f5e3Sopenharmony_ci } finally { 404514f5e3Sopenharmony_ci } 414514f5e3Sopenharmony_ci} 424514f5e3Sopenharmony_ci 434514f5e3Sopenharmony_cilet mySet = new Set([0, 0.0, -5, 2.5, 1e-78, NaN, "xyz", "12345"]); 444514f5e3Sopenharmony_ci 454514f5e3Sopenharmony_ci// Check without params 464514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:func_main_0@builtinSetDelete 474514f5e3Sopenharmony_ciprint(mySet.delete()); //: false 484514f5e3Sopenharmony_ci 494514f5e3Sopenharmony_ci// Check with adding element undefined 504514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.add, caller function name:func_main_0@builtinSetDelete 514514f5e3Sopenharmony_cimySet.add(undefined, 42); 524514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:func_main_0@builtinSetDelete 534514f5e3Sopenharmony_ciprint(mySet.delete()); //: true 544514f5e3Sopenharmony_ci 554514f5e3Sopenharmony_ci// Check with single param 564514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:func_main_0@builtinSetDelete 574514f5e3Sopenharmony_ciprint(mySet.delete(0)); //: true 584514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:func_main_0@builtinSetDelete 594514f5e3Sopenharmony_ciprint(mySet.delete(3)); //: false 604514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:func_main_0@builtinSetDelete 614514f5e3Sopenharmony_ciprint(mySet.delete(NaN)); //: true 624514f5e3Sopenharmony_ci 634514f5e3Sopenharmony_ci// Check with 2 params 644514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:func_main_0@builtinSetDelete 654514f5e3Sopenharmony_ciprint(mySet.delete(-5, 0)); //: true 664514f5e3Sopenharmony_ci 674514f5e3Sopenharmony_ci// Check with 3 params 684514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:func_main_0@builtinSetDelete 694514f5e3Sopenharmony_ciprint(mySet.delete(-51, 10.2, 15)); //: false 704514f5e3Sopenharmony_ci 714514f5e3Sopenharmony_ci// Check after inserting elements 724514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.add, caller function name:func_main_0@builtinSetDelete 734514f5e3Sopenharmony_cimySet.add(2000); 744514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:func_main_0@builtinSetDelete 754514f5e3Sopenharmony_ciprint(mySet.delete(2000)); //: true 764514f5e3Sopenharmony_ci 774514f5e3Sopenharmony_ci// Replace standard builtin 784514f5e3Sopenharmony_cilet true_delete = mySet.delete 794514f5e3Sopenharmony_cimySet.delete = replace 804514f5e3Sopenharmony_ci// no deopt 814514f5e3Sopenharmony_ciprint(mySet.delete(2.5)); //: 2.5 824514f5e3Sopenharmony_ci 834514f5e3Sopenharmony_cimySet.delete = true_delete 844514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:#*#doDelete@builtinSetDelete 854514f5e3Sopenharmony_ciprintDelete(1e-78); //: true 864514f5e3Sopenharmony_ci 874514f5e3Sopenharmony_ci// Call standard builtin with non-number param 884514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:func_main_0@builtinSetDelete 894514f5e3Sopenharmony_ciprint(mySet.delete("abc")); //: false 904514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:func_main_0@builtinSetDelete 914514f5e3Sopenharmony_ciprint(mySet.delete("2.5")); //: false 924514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:func_main_0@builtinSetDelete 934514f5e3Sopenharmony_ciprint(mySet.delete("xyz")); //: true 944514f5e3Sopenharmony_ci 954514f5e3Sopenharmony_ciif (ArkTools.isAOTCompiled(printDelete)) { 964514f5e3Sopenharmony_ci // Replace standard builtin after call to standard builtin was profiled 974514f5e3Sopenharmony_ci mySet.delete = replace 984514f5e3Sopenharmony_ci} 994514f5e3Sopenharmony_ci 1004514f5e3Sopenharmony_ciprintDelete(2.5); //pgo: true 1014514f5e3Sopenharmony_ci //aot: [trace] Check Type: NotCallTarget1 1024514f5e3Sopenharmony_ci //aot: 2.5 1034514f5e3Sopenharmony_ci 1044514f5e3Sopenharmony_ciprintDelete("abc"); //pgo: false 1054514f5e3Sopenharmony_ci //aot: [trace] Check Type: NotCallTarget1 1064514f5e3Sopenharmony_ci //aot: abc 1074514f5e3Sopenharmony_ci 1084514f5e3Sopenharmony_cimySet.delete = true_delete 1094514f5e3Sopenharmony_ci 1104514f5e3Sopenharmony_ci// Check IR correctness inside try-block 1114514f5e3Sopenharmony_citry { 1124514f5e3Sopenharmony_ci print("try-block"); //: try-block 1134514f5e3Sopenharmony_ci //aot: [trace] aot inline builtin: Set.delete, caller function name:#*#doDelete@builtinSetDelete 1144514f5e3Sopenharmony_ci printDelete(0); //: false 1154514f5e3Sopenharmony_ci //aot: [trace] aot inline builtin: Set.delete, caller function name:#*#doDelete@builtinSetDelete 1164514f5e3Sopenharmony_ci printDelete("xyz"); //: false 1174514f5e3Sopenharmony_ci} catch (e) { 1184514f5e3Sopenharmony_ci} 1194514f5e3Sopenharmony_ci 1204514f5e3Sopenharmony_cilet obj = {}; 1214514f5e3Sopenharmony_ciobj.valueOf = (() => { return 0; }); 1224514f5e3Sopenharmony_ci 1234514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.add, caller function name:func_main_0@builtinSetDelete 1244514f5e3Sopenharmony_cimySet.add(0, 0); 1254514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:func_main_0@builtinSetDelete 1264514f5e3Sopenharmony_ciprint(mySet.delete(obj)); //: false 1274514f5e3Sopenharmony_ci 1284514f5e3Sopenharmony_cifunction Throwing() { 1294514f5e3Sopenharmony_ci this.value = 2; 1304514f5e3Sopenharmony_ci Throwing.prototype.valueOf = function() { 1314514f5e3Sopenharmony_ci if (this.value > 0) { 1324514f5e3Sopenharmony_ci throw new Error("positive"); 1334514f5e3Sopenharmony_ci } 1344514f5e3Sopenharmony_ci return this.value; 1354514f5e3Sopenharmony_ci } 1364514f5e3Sopenharmony_ci} 1374514f5e3Sopenharmony_ci 1384514f5e3Sopenharmony_cilet throwingObj = new Throwing(); 1394514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.add, caller function name:func_main_0@builtinSetDelete 1404514f5e3Sopenharmony_cimySet.add(2); 1414514f5e3Sopenharmony_citry { 1424514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:func_main_0@builtinSetDelete 1434514f5e3Sopenharmony_ciprint(mySet.delete(throwingObj)); //: false 1444514f5e3Sopenharmony_ci} catch(e) { 1454514f5e3Sopenharmony_ci print(e); 1464514f5e3Sopenharmony_ci} finally { 1474514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:func_main_0@builtinSetDelete 1484514f5e3Sopenharmony_ciprint(mySet.delete(obj)); //: false 1494514f5e3Sopenharmony_ci} 1504514f5e3Sopenharmony_ci 1514514f5e3Sopenharmony_ci// Check after clearing 1524514f5e3Sopenharmony_cimySet.clear(); 1534514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.clear, caller function name:func_main_0@builtinSetDelete 1544514f5e3Sopenharmony_ciprint(mySet.delete(2000)); 1554514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:func_main_0@builtinSetDelete 1564514f5e3Sopenharmony_ci//: false 1574514f5e3Sopenharmony_ci 1584514f5e3Sopenharmony_cilet truedelete = Set.prototype.delete; 1594514f5e3Sopenharmony_cilet m = new Set(); 1604514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.add, caller function name:func_main_0@builtinSetDelete 1614514f5e3Sopenharmony_cim.add(1); 1624514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.add, caller function name:func_main_0@builtinSetDelete 1634514f5e3Sopenharmony_cim.add(2); 1644514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.add, caller function name:func_main_0@builtinSetDelete 1654514f5e3Sopenharmony_cim.add("ab"); 1664514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.add, caller function name:func_main_0@builtinSetDelete 1674514f5e3Sopenharmony_cim.add("cd"); 1684514f5e3Sopenharmony_cilet obj1 = {}; 1694514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.add, caller function name:func_main_0@builtinSetDelete 1704514f5e3Sopenharmony_cim.add(obj1); 1714514f5e3Sopenharmony_ci 1724514f5e3Sopenharmony_ciprint("prototype"); //: prototype 1734514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:func_main_0@builtinSetDelete 1744514f5e3Sopenharmony_ciprint(m.delete(1)); //: true 1754514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:func_main_0@builtinSetDelete 1764514f5e3Sopenharmony_ciprint(m.delete(2)); //: true 1774514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:func_main_0@builtinSetDelete 1784514f5e3Sopenharmony_ciprint(m.delete(3)); //: false 1794514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:func_main_0@builtinSetDelete 1804514f5e3Sopenharmony_ciprint(m.delete("ab")); //: true 1814514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:func_main_0@builtinSetDelete 1824514f5e3Sopenharmony_ciprint(m.delete("cd")); //: true 1834514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:func_main_0@builtinSetDelete 1844514f5e3Sopenharmony_ciprint(m.delete("x")); //: false 1854514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:func_main_0@builtinSetDelete 1864514f5e3Sopenharmony_ciprint(m.delete(obj1)); //: true 1874514f5e3Sopenharmony_ci 1884514f5e3Sopenharmony_cilet obj2 = {}; 1894514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:func_main_0@builtinSetDelete 1904514f5e3Sopenharmony_ciprint(m.delete(obj2)); //: false 1914514f5e3Sopenharmony_ci 1924514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:func_main_0@builtinSetDelete 1934514f5e3Sopenharmony_ciprint(m.delete()); //: false 1944514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.add, caller function name:func_main_0@builtinSetDelete 1954514f5e3Sopenharmony_cim.add(undefined, -1); 1964514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:func_main_0@builtinSetDelete 1974514f5e3Sopenharmony_ciprint(m.delete()); //: true 1984514f5e3Sopenharmony_ci 1994514f5e3Sopenharmony_ciprint("baseline"); //: baseline 2004514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.add, caller function name:func_main_0@builtinSetDelete 2014514f5e3Sopenharmony_cim.add(10); 2024514f5e3Sopenharmony_cilet m2 = new Set([1]); 2034514f5e3Sopenharmony_cilet m3 = new Set([1]); 2044514f5e3Sopenharmony_cilet m4 = new Set([1]); 2054514f5e3Sopenharmony_ci 2064514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:#*#printDelete2@builtinSetDelete 2074514f5e3Sopenharmony_ciprintDelete2(m, 10); //: true 2084514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:#*#printDelete2@builtinSetDelete 2094514f5e3Sopenharmony_ciprintDelete2(m2, 1); //: true 2104514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:#*#printDelete2@builtinSetDelete 2114514f5e3Sopenharmony_ciprintDelete2(m3, 1); //: true 2124514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:#*#printDelete2@builtinSetDelete 2134514f5e3Sopenharmony_ciprintDelete2(m4, 1); //: true 2144514f5e3Sopenharmony_ci 2154514f5e3Sopenharmony_ciprint("case 0") //: case 0 2164514f5e3Sopenharmony_ciif (ArkTools.isAOTCompiled(printDelete2)) { 2174514f5e3Sopenharmony_ci m4.garbage = function(x: any) { 2184514f5e3Sopenharmony_ci return undefined; 2194514f5e3Sopenharmony_ci } 2204514f5e3Sopenharmony_ci} 2214514f5e3Sopenharmony_ci 2224514f5e3Sopenharmony_ci// Nothing changed 2234514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.add, caller function name:func_main_0@builtinSetDelete 2244514f5e3Sopenharmony_cim.add(10); 2254514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.add, caller function name:func_main_0@builtinSetDelete 2264514f5e3Sopenharmony_cim2.add(10); 2274514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.add, caller function name:func_main_0@builtinSetDelete 2284514f5e3Sopenharmony_cim3.add(10); 2294514f5e3Sopenharmony_ci//aot: [trace] Check Type: BuiltinInstanceHClassMismatch 2304514f5e3Sopenharmony_cim4.add(10); 2314514f5e3Sopenharmony_ci 2324514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:#*#printDelete2@builtinSetDelete 2334514f5e3Sopenharmony_ciprintDelete2(m, 10); //: true 2344514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:#*#printDelete2@builtinSetDelete 2354514f5e3Sopenharmony_ciprintDelete2(m2, 10); //: true 2364514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:#*#printDelete2@builtinSetDelete 2374514f5e3Sopenharmony_ciprintDelete2(m3, 10); //: true 2384514f5e3Sopenharmony_ciprintDelete2(m4, 10); //aot: [trace] Check Type: BuiltinInstanceHClassMismatch 2394514f5e3Sopenharmony_ci //: true 2404514f5e3Sopenharmony_ci 2414514f5e3Sopenharmony_ciprint("case 1") //: case 1 2424514f5e3Sopenharmony_ciif (ArkTools.isAOTCompiled(printDelete2)) { 2434514f5e3Sopenharmony_ci m3.delete = function(x: any) { 2444514f5e3Sopenharmony_ci return -x; 2454514f5e3Sopenharmony_ci } 2464514f5e3Sopenharmony_ci} 2474514f5e3Sopenharmony_ci 2484514f5e3Sopenharmony_cim.add(10); 2494514f5e3Sopenharmony_cim2.add(10); 2504514f5e3Sopenharmony_cim3.add(10); 2514514f5e3Sopenharmony_ci 2524514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:#*#printDelete2@builtinSetDelete 2534514f5e3Sopenharmony_ciprintDelete2(m, 10); //: true 2544514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:#*#printDelete2@builtinSetDelete 2554514f5e3Sopenharmony_ciprintDelete2(m2, 10); //: true 2564514f5e3Sopenharmony_ciprintDelete2(m3, 10); //pgo: true 2574514f5e3Sopenharmony_ci //aot: [trace] Check Type: BuiltinInstanceHClassMismatch 2584514f5e3Sopenharmony_ci //aot: -10 2594514f5e3Sopenharmony_ci 2604514f5e3Sopenharmony_ciprint("case 2") //: case 2 2614514f5e3Sopenharmony_cilet mimicset = { 2624514f5e3Sopenharmony_ci delete: truedelete 2634514f5e3Sopenharmony_ci} 2644514f5e3Sopenharmony_cilet mm = new Set([1]); 2654514f5e3Sopenharmony_ci 2664514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Set.delete, caller function name:#*#printDelete2@builtinSetDelete 2674514f5e3Sopenharmony_ciprintDelete2(mm, 1) //: true 2684514f5e3Sopenharmony_ciif (ArkTools.isAOTCompiled(printDelete2)) { 2694514f5e3Sopenharmony_ci Object.setPrototypeOf(mm, mimicset) 2704514f5e3Sopenharmony_ci} 2714514f5e3Sopenharmony_ciprintDelete2(mm, 1); //aot: [trace] Check Type: BuiltinInstanceHClassMismatch 2724514f5e3Sopenharmony_ci //: false 2734514f5e3Sopenharmony_ci 2744514f5e3Sopenharmony_ciprint("case 3"); //: case 3 2754514f5e3Sopenharmony_ci 2764514f5e3Sopenharmony_cifunction checkObjWithSetProto() { 2774514f5e3Sopenharmony_ci let o = {}; 2784514f5e3Sopenharmony_ci Object.setPrototypeOf(o, Set.prototype); 2794514f5e3Sopenharmony_ci try { 2804514f5e3Sopenharmony_ci o.delete(1); 2814514f5e3Sopenharmony_ci } catch(e) { 2824514f5e3Sopenharmony_ci print(e); 2834514f5e3Sopenharmony_ci } 2844514f5e3Sopenharmony_ci} 2854514f5e3Sopenharmony_ci 2864514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotCallTarget1 2874514f5e3Sopenharmony_ci//: TypeError: obj is not JSSet 2884514f5e3Sopenharmony_cicheckObjWithSetProto(); 2894514f5e3Sopenharmony_ci 2904514f5e3Sopenharmony_ci 2914514f5e3Sopenharmony_ciif (ArkTools.isAOTCompiled(printDelete2)) { 2924514f5e3Sopenharmony_ci Set.prototype.delete = function(x: any) { 2934514f5e3Sopenharmony_ci return -x * 10; 2944514f5e3Sopenharmony_ci } 2954514f5e3Sopenharmony_ci} 2964514f5e3Sopenharmony_ci 2974514f5e3Sopenharmony_cim.add(10); 2984514f5e3Sopenharmony_cim2.add(10); 2994514f5e3Sopenharmony_ci 3004514f5e3Sopenharmony_ciprintDelete2(m, 10); //pgo: true 3014514f5e3Sopenharmony_ci //aot: [trace] Check Type: NotCallTarget1 3024514f5e3Sopenharmony_ci //aot: -100 3034514f5e3Sopenharmony_ciprintDelete2(m2, 10); //pgo: true 3044514f5e3Sopenharmony_ci //aot: [trace] Check Type: NotCallTarget1 3054514f5e3Sopenharmony_ci //aot: -100 306