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} 19 20declare function print(arg:any):string; 21function replace(a : number) 22{ 23 return a; 24} 25 26function doFloor(x: any): number { 27 return Math.floor(x); 28} 29 30function printFloor(x: any) { 31 try { 32 print(doFloor(x)); 33 } finally { 34 } 35} 36 37// Check without params 38//aot: [trace] aot inline builtin: Math.floor, caller function name:func_main_0@builtinMathFloor 39print(Math.floor()); //: NaN 40 41// Replace standart builtin 42let backup = Math.floor 43//aot: [trace] Check Type: NotCallTarget1 44Math.floor = replace 45printFloor(111); //: 111 46Math.floor = backup 47 48// Check with NaN param 49//aot: [trace] aot inline builtin: Math.floor, caller function name:#*#doFloor@builtinMathFloor 50printFloor(NaN); //: NaN 51 52// Check with infinity param 53//aot: [trace] aot inline builtin: Math.floor, caller function name:#*#doFloor@builtinMathFloor 54printFloor(-Infinity); //: -Infinity 55//aot: [trace] aot inline builtin: Math.floor, caller function name:#*#doFloor@builtinMathFloor 56printFloor(+Infinity); //: Infinity 57 58// Check with zero param 59//aot: [trace] aot inline builtin: Math.floor, caller function name:#*#doFloor@builtinMathFloor 60printFloor(-0.0); //: 0 61//aot: [trace] aot inline builtin: Math.floor, caller function name:#*#doFloor@builtinMathFloor 62printFloor(0.0); //: 0 63//aot: [trace] aot inline builtin: Math.floor, caller function name:#*#doFloor@builtinMathFloor 64printFloor(+0.0); //: 0 65 66// Check with integer param 67//aot: [trace] aot inline builtin: Math.floor, caller function name:#*#doFloor@builtinMathFloor 68printFloor(-1.0); //: -1 69//aot: [trace] aot inline builtin: Math.floor, caller function name:#*#doFloor@builtinMathFloor 70printFloor(+1.0); //: 1 71//aot: [trace] aot inline builtin: Math.floor, caller function name:#*#doFloor@builtinMathFloor 72printFloor(-12.0); //: -12 73//aot: [trace] aot inline builtin: Math.floor, caller function name:#*#doFloor@builtinMathFloor 74printFloor(+12.0); //: 12 75//aot: [trace] aot inline builtin: Math.floor, caller function name:#*#doFloor@builtinMathFloor 76printFloor(-123.0); //: -123 77//aot: [trace] aot inline builtin: Math.floor, caller function name:#*#doFloor@builtinMathFloor 78printFloor(+123.0); //: 123 79 80//aot: [trace] aot inline builtin: Math.floor, caller function name:#*#doFloor@builtinMathFloor 81printFloor(1.5); //: 1 82// Call standard builtin with non-number param 83//aot: [trace] aot inline builtin: Math.floor, caller function name:#*#doFloor@builtinMathFloor 84printFloor("abc"); //aot: [trace] Check Type: NotNumber1 85 //: NaN 86//aot: [trace] aot inline builtin: Math.floor, caller function name:#*#doFloor@builtinMathFloor 87printFloor("1.5"); //aot: [trace] Check Type: NotNumber1 88 //: 1 89 90if (ArkTools.isAOTCompiled(printFloor)) { 91 // Replace standard builtin after call to standard builtin was profiled 92 Math.floor = replace 93} 94printFloor(1.5); //aot: [trace] Check Type: NotCallTarget1 95 //aot: 1.5 96 //pgo: 1 97printFloor("abc"); //aot: [trace] Check Type: NotCallTarget1 98 //aot: abc 99 //pgo: NaN 100 101Math.floor = backup 102 103// Check with fractional param 104//aot: [trace] aot inline builtin: Math.floor, caller function name:#*#doFloor@builtinMathFloor 105printFloor(-1.25); //: -2 106//aot: [trace] aot inline builtin: Math.floor, caller function name:#*#doFloor@builtinMathFloor 107printFloor(+1.25); //: 1 108//aot: [trace] aot inline builtin: Math.floor, caller function name:#*#doFloor@builtinMathFloor 109printFloor(-1.50); //: -2 110//aot: [trace] aot inline builtin: Math.floor, caller function name:#*#doFloor@builtinMathFloor 111printFloor(+1.50); //: 1 112//aot: [trace] aot inline builtin: Math.floor, caller function name:#*#doFloor@builtinMathFloor 113printFloor(-1.75); //: -2 114//aot: [trace] aot inline builtin: Math.floor, caller function name:#*#doFloor@builtinMathFloor 115printFloor(+1.75); //: 1 116 117// Check with non-number param 118//aot: [trace] aot inline builtin: Math.floor, caller function name:#*#doFloor@builtinMathFloor 119printFloor("string"); //aot: [trace] Check Type: NotNumber1 120 //: NaN 121//aot: [trace] aot inline builtin: Math.floor, caller function name:#*#doFloor@builtinMathFloor 122printFloor(null); //aot: [trace] Check Type: NotNumber1 123 //: 0 124//aot: [trace] aot inline builtin: Math.floor, caller function name:#*#doFloor@builtinMathFloor 125printFloor(undefined); //aot: [trace] Check Type: NotNumber1 126 //: NaN 127//aot: [trace] aot inline builtin: Math.floor, caller function name:#*#doFloor@builtinMathFloor 128printFloor(false); //aot: [trace] Check Type: NotNumber1 129 //: 0 130//aot: [trace] aot inline builtin: Math.floor, caller function name:#*#doFloor@builtinMathFloor 131printFloor(true); //aot: [trace] Check Type: NotNumber1 132 //: 1 133//aot: [trace] aot inline builtin: Math.floor, caller function name:#*#doFloor@builtinMathFloor 134printFloor(new Object); //aot: [trace] Check Type: NotNumber1 135 //: NaN 136printFloor("1.3333"); 137 //: 1 138