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 function print(arg:any):string; 174514f5e3Sopenharmony_ci 184514f5e3Sopenharmony_cifunction testNumberParseFloat(a : any, shouldThrow = 0): any 194514f5e3Sopenharmony_ci{ 204514f5e3Sopenharmony_ci try { 214514f5e3Sopenharmony_ci if (shouldThrow == 1) { 224514f5e3Sopenharmony_ci throw Error("thr 1"); 234514f5e3Sopenharmony_ci } 244514f5e3Sopenharmony_ci let x = Number.parseFloat(a); 254514f5e3Sopenharmony_ci if (shouldThrow == 2) { 264514f5e3Sopenharmony_ci throw Error("thr 2"); 274514f5e3Sopenharmony_ci } 284514f5e3Sopenharmony_ci return x; 294514f5e3Sopenharmony_ci } catch (e) { 304514f5e3Sopenharmony_ci print("catch", "'" + e + "'", "in testNumberParseFloat"); 314514f5e3Sopenharmony_ci throw (e) 324514f5e3Sopenharmony_ci } finally { 334514f5e3Sopenharmony_ci print("exit testNumberParseFloat"); 344514f5e3Sopenharmony_ci } 354514f5e3Sopenharmony_ci} 364514f5e3Sopenharmony_ci 374514f5e3Sopenharmony_cifunction testParseFloat(a : any, shouldThrow = 0): any 384514f5e3Sopenharmony_ci{ 394514f5e3Sopenharmony_ci try { 404514f5e3Sopenharmony_ci if (shouldThrow == 1) { 414514f5e3Sopenharmony_ci throw Error("thr 1"); 424514f5e3Sopenharmony_ci } 434514f5e3Sopenharmony_ci let x = parseFloat(a); 444514f5e3Sopenharmony_ci if (shouldThrow == 2) { 454514f5e3Sopenharmony_ci throw Error("thr 2"); 464514f5e3Sopenharmony_ci } 474514f5e3Sopenharmony_ci return x; 484514f5e3Sopenharmony_ci } catch (e) { 494514f5e3Sopenharmony_ci print("catch", "'" + e + "'", "in testParseFloat"); 504514f5e3Sopenharmony_ci throw (e) 514514f5e3Sopenharmony_ci } finally { 524514f5e3Sopenharmony_ci print("exit testParseFloat"); 534514f5e3Sopenharmony_ci } 544514f5e3Sopenharmony_ci} 554514f5e3Sopenharmony_ci 564514f5e3Sopenharmony_ciprint(Number.parseFloat === parseFloat); 574514f5e3Sopenharmony_ci//: true 584514f5e3Sopenharmony_ci 594514f5e3Sopenharmony_cifunction test(a : any) 604514f5e3Sopenharmony_ci{ 614514f5e3Sopenharmony_ci let checks = [typeof a, a]; 624514f5e3Sopenharmony_ci print(checks) 634514f5e3Sopenharmony_ci} 644514f5e3Sopenharmony_ci 654514f5e3Sopenharmony_cifunction testParseFloatInt(a: number) { 664514f5e3Sopenharmony_ci try { 674514f5e3Sopenharmony_ci return parseFloat((a | 0) as any); 684514f5e3Sopenharmony_ci } catch (e) { 694514f5e3Sopenharmony_ci print("catch", "'" + e + "'", "in testParseFloat"); 704514f5e3Sopenharmony_ci throw (e) 714514f5e3Sopenharmony_ci } 724514f5e3Sopenharmony_ci} 734514f5e3Sopenharmony_citest(testParseFloatInt(-2)); 744514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Number.parseFloat, caller function name:#*#testParseFloatInt@builtinNumberParseFloatNumber 754514f5e3Sopenharmony_ci//aot: [trace] aot inline function name: #*#test@builtinNumberParseFloatNumber caller function name: func_main_0@builtinNumberParseFloatNumber 764514f5e3Sopenharmony_ci//: number,-2 774514f5e3Sopenharmony_ci 784514f5e3Sopenharmony_cilet negZero = testParseFloat(-0.0 as any); 794514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Number.parseFloat, caller function name:#*#testParseFloat@builtinNumberParseFloatNumber 804514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotString1 814514f5e3Sopenharmony_ci//: exit testParseFloat 824514f5e3Sopenharmony_ciprint(Object.is(negZero, -0)) 834514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Object.is, caller function name:func_main_0@builtinNumberParseFloatNumber 844514f5e3Sopenharmony_ci//: false 854514f5e3Sopenharmony_ciprint(Object.is(negZero, 0)) 864514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Object.is, caller function name:func_main_0@builtinNumberParseFloatNumber 874514f5e3Sopenharmony_ci//: true 884514f5e3Sopenharmony_ci 894514f5e3Sopenharmony_citest(testParseFloat(-2.01)); 904514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Number.parseFloat, caller function name:#*#testParseFloat@builtinNumberParseFloatNumber 914514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotString1 924514f5e3Sopenharmony_ci//: exit testParseFloat 934514f5e3Sopenharmony_ci//aot: [trace] aot inline function name: #*#test@builtinNumberParseFloatNumber caller function name: func_main_0@builtinNumberParseFloatNumber 944514f5e3Sopenharmony_ci//: number,-2.01 954514f5e3Sopenharmony_ci 964514f5e3Sopenharmony_citest(testNumberParseFloat(-2.01)); 974514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Number.parseFloat, caller function name:#*#testNumberParseFloat@builtinNumberParseFloatNumber 984514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotString1 994514f5e3Sopenharmony_ci//: exit testNumberParseFloat 1004514f5e3Sopenharmony_ci//aot: [trace] aot inline function name: #*#test@builtinNumberParseFloatNumber caller function name: func_main_0@builtinNumberParseFloatNumber 1014514f5e3Sopenharmony_ci//: number,-2.01 102