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 doCeil(x: any): number { 27 return Math.ceil(x); 28} 29 30function printCeil(x: any) { 31 try { 32 print(doCeil(x)); 33 } finally { 34 } 35} 36 37// Check without params 38//aot: [trace] aot inline builtin: Math.ceil, caller function name:func_main_0@builtinMathCeil 39print(Math.ceil()); //: NaN 40 41// Replace standart builtin 42let backup = Math.ceil 43Math.ceil = replace 44printCeil(111); //: 111 45Math.ceil = backup 46 47// Check with NaN param 48printCeil(NaN); //: NaN 49 50// Check with infinity param 51printCeil(-Infinity); //: -Infinity 52printCeil(+Infinity); //: Infinity 53 54// Check with zero param 55printCeil(-0.0); //: 0 56printCeil(0.0); //: 0 57printCeil(+0.0); //: 0 58 59// Check with integer param 60printCeil(-1.0); //: -1 61printCeil(+1.0); //: 1 62printCeil(-12.0); //: -12 63printCeil(+12.0); //: 12 64printCeil(-123.0); //: -123 65printCeil(+123.0); //: 123 66 67printCeil(1.5); //: 2 68// Call standard builtin with non-number param 69printCeil("abc"); //: NaN 70printCeil("1.5"); //: 2 71 72if (ArkTools.isAOTCompiled(printCeil)) { 73 // Replace standard builtin after call to standard builtin was profiled 74 Math.ceil = replace 75} 76printCeil(1.5); //aot: 1.5 77 //pgo: 2 78printCeil("abc"); //aot: abc 79 //pgo: NaN 80 81Math.ceil = backup 82 83// Check with fractional param 84printCeil(-1.25); //: -1 85printCeil(+1.25); //: 2 86printCeil(-1.50); //: -1 87printCeil(+1.50); //: 2 88printCeil(-1.75); //: -1 89printCeil(+1.75); //: 2 90 91// Check with non-number param 92printCeil("string"); //: NaN 93printCeil(null); //: 0 94printCeil(undefined); //: NaN 95printCeil(false); //: 0 96printCeil(true); //: 1 97printCeil(new Object); //: NaN 98printCeil("1.3333"); 99 //: 2