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_ci 214514f5e3Sopenharmony_cifunction printZero(x: any) { 224514f5e3Sopenharmony_ci if (Object.is(x, -0)) { 234514f5e3Sopenharmony_ci print("-0"); 244514f5e3Sopenharmony_ci } else { 254514f5e3Sopenharmony_ci print(x); 264514f5e3Sopenharmony_ci } 274514f5e3Sopenharmony_ci} 284514f5e3Sopenharmony_cifunction replace(a : number) 294514f5e3Sopenharmony_ci{ 304514f5e3Sopenharmony_ci return a; 314514f5e3Sopenharmony_ci} 324514f5e3Sopenharmony_ci 334514f5e3Sopenharmony_ci// Use try to prevent inlining to main 344514f5e3Sopenharmony_cifunction printMin(x: any, y: any) { 354514f5e3Sopenharmony_ci try { 364514f5e3Sopenharmony_ci print(Math.min(x, y)); 374514f5e3Sopenharmony_ci } finally { 384514f5e3Sopenharmony_ci } 394514f5e3Sopenharmony_ci} 404514f5e3Sopenharmony_ci 414514f5e3Sopenharmony_cifunction printMin1(x: any) { 424514f5e3Sopenharmony_ci try { 434514f5e3Sopenharmony_ci print(Math.min(x)); 444514f5e3Sopenharmony_ci } finally { 454514f5e3Sopenharmony_ci } 464514f5e3Sopenharmony_ci} 474514f5e3Sopenharmony_ci 484514f5e3Sopenharmony_ci 494514f5e3Sopenharmony_cilet doubleObj = { 504514f5e3Sopenharmony_ci valueOf: () => { return 2.7; } 514514f5e3Sopenharmony_ci} 524514f5e3Sopenharmony_ci 534514f5e3Sopenharmony_cilet nanObj = { 544514f5e3Sopenharmony_ci valueOf: () => { return "something"; } 554514f5e3Sopenharmony_ci} 564514f5e3Sopenharmony_ci 574514f5e3Sopenharmony_cilet obj = { 584514f5e3Sopenharmony_ci valueOf: () => { 594514f5e3Sopenharmony_ci print("obj.valueOf") 604514f5e3Sopenharmony_ci return -23; 614514f5e3Sopenharmony_ci } 624514f5e3Sopenharmony_ci}; 634514f5e3Sopenharmony_ci 644514f5e3Sopenharmony_ci// Check without params 654514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 664514f5e3Sopenharmony_ciprint(Math.min()); //: Infinity 674514f5e3Sopenharmony_ci 684514f5e3Sopenharmony_ci// Check with single param 694514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 704514f5e3Sopenharmony_ciprint(Math.min(0)); //: 0 714514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 724514f5e3Sopenharmony_ciprint(Math.min(567)); //: 567 734514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 744514f5e3Sopenharmony_ciprint(Math.min(-1e80)); //: -1e+80 754514f5e3Sopenharmony_ci 764514f5e3Sopenharmony_ci// Check with special float params 774514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 784514f5e3Sopenharmony_ciprint(Math.min(Infinity)); //: Infinity 794514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 804514f5e3Sopenharmony_ciprint(Math.min(-Infinity)); //: -Infinity 814514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 824514f5e3Sopenharmony_ciprint(Math.min(NaN)); //: NaN 834514f5e3Sopenharmony_ci 844514f5e3Sopenharmony_ci// Check with 2 int params 854514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 864514f5e3Sopenharmony_ciprint(Math.min(3, 300)); //: 3 874514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 884514f5e3Sopenharmony_ciprint(Math.min(300, 3)); //: 3 894514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 904514f5e3Sopenharmony_ciprint(Math.min(3, -2)); //: -2 914514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 924514f5e3Sopenharmony_ciprint(Math.min(-22, -2)); //: -22 934514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 944514f5e3Sopenharmony_ciprint(Math.min(-1, -1)); //: -1 954514f5e3Sopenharmony_ci 964514f5e3Sopenharmony_ci// // Check with 2 float params 974514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 984514f5e3Sopenharmony_ciprint(Math.min(3.2, 300.7)); //: 3.2 994514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 1004514f5e3Sopenharmony_ciprint(Math.min(300.7, 3.2)); //: 3.2 1014514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 1024514f5e3Sopenharmony_ciprint(Math.min(3e11, -2e10)); //: -20000000000 1034514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 1044514f5e3Sopenharmony_ciprint(Math.min(-22.1, -2e-10)); //: -22.1 1054514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 1064514f5e3Sopenharmony_ciprint(Math.min(-1.8, -1.8)); //: -1.8 1074514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 1084514f5e3Sopenharmony_ciprint(Math.min(Infinity, -1.8)); //: -1.8 1094514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 1104514f5e3Sopenharmony_ciprint(Math.min(-1.8, Infinity)); //: -1.8 1114514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 1124514f5e3Sopenharmony_ciprint(Math.min(-Infinity, -1.8)); //: -Infinity 1134514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 1144514f5e3Sopenharmony_ciprint(Math.min(-1.8, -Infinity)); //: -Infinity 1154514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 1164514f5e3Sopenharmony_ciprint(Math.min(-1.8, NaN)); //: NaN 1174514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 1184514f5e3Sopenharmony_ciprint(Math.min(NaN, -1.8)); //: NaN 1194514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 1204514f5e3Sopenharmony_ciprint(Math.min(-Infinity, NaN)); //: NaN 1214514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 1224514f5e3Sopenharmony_ciprint(Math.min(Infinity, NaN)); //: NaN 1234514f5e3Sopenharmony_ci 1244514f5e3Sopenharmony_ci 1254514f5e3Sopenharmony_ci// Check 0 and -0 1264514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 1274514f5e3Sopenharmony_ci//aot: [trace] aot inline function name: #*#printZero@builtinMathMin caller function name: func_main_0@builtinMathMin 1284514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Object.is, caller function name:#*#printZero@builtinMathMin 1294514f5e3Sopenharmony_ciprintZero(Math.min(0, -0)); //: -0 1304514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 1314514f5e3Sopenharmony_ci//aot: [trace] aot inline function name: #*#printZero@builtinMathMin caller function name: func_main_0@builtinMathMin 1324514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Object.is, caller function name:#*#printZero@builtinMathMin 1334514f5e3Sopenharmony_ciprintZero(Math.min(-0, 0)); //: -0 1344514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 1354514f5e3Sopenharmony_ci//aot: [trace] aot inline function name: #*#printZero@builtinMathMin caller function name: func_main_0@builtinMathMin 1364514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Object.is, caller function name:#*#printZero@builtinMathMin 1374514f5e3Sopenharmony_ciprintZero(Math.min(0, 0)); //: 0 1384514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 1394514f5e3Sopenharmony_ci//aot: [trace] aot inline function name: #*#printZero@builtinMathMin caller function name: func_main_0@builtinMathMin 1404514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Object.is, caller function name:#*#printZero@builtinMathMin 1414514f5e3Sopenharmony_ciprintZero(Math.min(-0, -0)); //: -0 1424514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 1434514f5e3Sopenharmony_ci//aot: [trace] aot inline function name: #*#printZero@builtinMathMin caller function name: func_main_0@builtinMathMin 1444514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Object.is, caller function name:#*#printZero@builtinMathMin 1454514f5e3Sopenharmony_ciprintZero(Math.min(5, -0)); //: -0 1464514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 1474514f5e3Sopenharmony_ci//aot: [trace] aot inline function name: #*#printZero@builtinMathMin caller function name: func_main_0@builtinMathMin 1484514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Object.is, caller function name:#*#printZero@builtinMathMin 1494514f5e3Sopenharmony_ciprintZero(Math.min(5, 0)); //: 0 1504514f5e3Sopenharmony_ci 1514514f5e3Sopenharmony_ci// Check with int and float param 1524514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 1534514f5e3Sopenharmony_ciprint(Math.min(1.5, 3)); //: 1.5 1544514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 1554514f5e3Sopenharmony_ciprint(Math.min(3, 1.5)); //: 1.5 1564514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 1574514f5e3Sopenharmony_ciprint(Math.min(2.5, 1)); //: 1 1584514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 1594514f5e3Sopenharmony_ciprint(Math.min(1, 2.5)); //: 1 1604514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 1614514f5e3Sopenharmony_ciprint(Math.min(1, Infinity)); //: 1 1624514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 1634514f5e3Sopenharmony_ciprint(Math.min(5, NaN)); //: NaN 1644514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 1654514f5e3Sopenharmony_ciprint(Math.min(NaN, 5)); //: NaN 1664514f5e3Sopenharmony_ci 1674514f5e3Sopenharmony_ci// Check with 3 params 1684514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 1694514f5e3Sopenharmony_ciprint(Math.min(2, 4, 6)); //: 2 1704514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 1714514f5e3Sopenharmony_ciprint(Math.min(4, 6, 2)); //: 2 1724514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 1734514f5e3Sopenharmony_ciprint(Math.min(6, 2, 4)); //: 2 1744514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 1754514f5e3Sopenharmony_ciprint(Math.min(-1, 1, -2.5)); //: -2.5 1764514f5e3Sopenharmony_ci 1774514f5e3Sopenharmony_ci// Check with 4 params 1784514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 1794514f5e3Sopenharmony_ciprint(Math.min(4, 0, -2, Infinity)); //: -2 1804514f5e3Sopenharmony_ci 1814514f5e3Sopenharmony_ci// Check with 5 params 1824514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 1834514f5e3Sopenharmony_ciprint(Math.min(-1, -2, -1.5, -2, -8)); //: -8 1844514f5e3Sopenharmony_ci 1854514f5e3Sopenharmony_ci// Replace standard builtin 1864514f5e3Sopenharmony_cilet trueMin = Math.min 1874514f5e3Sopenharmony_ciMath.min = replace 1884514f5e3Sopenharmony_ciprint(Math.min(-1.001, -90)); //: -1.001 1894514f5e3Sopenharmony_ciMath.min = trueMin 1904514f5e3Sopenharmony_ci 1914514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:#*#printMin@builtinMathMin 1924514f5e3Sopenharmony_ciprintMin(-12, 1); //: -12 1934514f5e3Sopenharmony_ci// Call standard builtin with non-number param 1944514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:#*#printMin@builtinMathMin 1954514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotNumber2 1964514f5e3Sopenharmony_ciprintMin("abc", 1); //: NaN 1974514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:#*#printMin@builtinMathMin 1984514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotNumber2 1994514f5e3Sopenharmony_ciprintMin("-12", 1); //: -12 2004514f5e3Sopenharmony_ci 2014514f5e3Sopenharmony_ciif (ArkTools.isAOTCompiled(printMin)) { 2024514f5e3Sopenharmony_ci // Replace standard builtin after call to standard builtin was profiled 2034514f5e3Sopenharmony_ci Math.min = replace 2044514f5e3Sopenharmony_ci} 2054514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotCallTarget1 2064514f5e3Sopenharmony_ciprintMin(5, -12); //pgo: -12 2074514f5e3Sopenharmony_ci //aot: 5 2084514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotCallTarget1 2094514f5e3Sopenharmony_ciprintMin("abc", 2); //pgo: NaN 2104514f5e3Sopenharmony_ci //aot: abc 2114514f5e3Sopenharmony_ciMath.min = trueMin 2124514f5e3Sopenharmony_ci 2134514f5e3Sopenharmony_ci// Check IR correctness inside try-block 2144514f5e3Sopenharmony_citry { 2154514f5e3Sopenharmony_ci //aot: [trace] aot inline builtin: Math.min, caller function name:#*#printMin@builtinMathMin 2164514f5e3Sopenharmony_ci printMin(19, 12); //: 12 2174514f5e3Sopenharmony_ci //aot: [trace] aot inline builtin: Math.min, caller function name:#*#printMin@builtinMathMin 2184514f5e3Sopenharmony_ci //aot: [trace] Check Type: NotNumber2 2194514f5e3Sopenharmony_ci printMin("abc", 5); //: NaN 2204514f5e3Sopenharmony_ci} catch (e) { 2214514f5e3Sopenharmony_ci} 2224514f5e3Sopenharmony_ci 2234514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:#*#printMin1@builtinMathMin 2244514f5e3Sopenharmony_ci//aot: [trace] Check Type: InconsistentType1 2254514f5e3Sopenharmony_ci//: obj.valueOf 2264514f5e3Sopenharmony_ciprintMin1(obj); //: -23 2274514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:#*#printMin1@builtinMathMin 2284514f5e3Sopenharmony_ci//aot: [trace] Check Type: InconsistentType1 2294514f5e3Sopenharmony_ciprintMin1(doubleObj); //: 2.7 2304514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:#*#printMin@builtinMathMin 2314514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotNumber2 2324514f5e3Sopenharmony_ciprintMin(doubleObj, doubleObj); //: 2.7 2334514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:#*#printMin@builtinMathMin 2344514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotNumber2 2354514f5e3Sopenharmony_ci//: obj.valueOf 2364514f5e3Sopenharmony_ciprintMin(nanObj, obj); //: NaN 2374514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:#*#printMin@builtinMathMin 2384514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotNumber2 2394514f5e3Sopenharmony_ci//: obj.valueOf 2404514f5e3Sopenharmony_ciprintMin(24, obj); //: -23 2414514f5e3Sopenharmony_ci 2424514f5e3Sopenharmony_ci// call obj.valueOf twice 2434514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.min, caller function name:func_main_0@builtinMathMin 2444514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotNumber2 2454514f5e3Sopenharmony_ci//: obj.valueOf 2464514f5e3Sopenharmony_ci//: obj.valueOf 2474514f5e3Sopenharmony_ciprint(Math.min(NaN, obj, obj)); //: NaN 248