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 function print(arg:any):string;
17
18function testNumberParseFloat(a : any, shouldThrow = 0): any
19{
20    try {
21        if (shouldThrow == 1) {
22            throw Error("thr 1");
23        }
24        let x = Number.parseFloat(a);
25        if (shouldThrow == 2) {
26            throw Error("thr 2");
27        }
28        return x;
29    } catch (e) {
30        print("catch", "'" + e + "'", "in testNumberParseFloat");
31        throw (e)
32    } finally {
33        print("exit testNumberParseFloat");
34    }
35}
36
37function testParseFloat(a : any, shouldThrow = 0): any
38{
39    try {
40        if (shouldThrow == 1) {
41            throw Error("thr 1");
42        }
43        let x = parseFloat(a);
44        if (shouldThrow == 2) {
45            throw Error("thr 2");
46        }
47        return x;
48    } catch (e) {
49        print("catch", "'" + e + "'", "in testParseFloat");
50        throw (e)
51    } finally {
52        print("exit testParseFloat");
53    }
54}
55
56print(Number.parseFloat === parseFloat);
57//: true
58
59function test(a : any)
60{
61    let checks = [typeof a, a];
62    print(checks)
63}
64
65function testParseFloatInt(a: number) {
66    try {
67        return parseFloat((a | 0) as any);
68    } catch (e) {
69        print("catch", "'" + e + "'", "in testParseFloat");
70        throw (e)
71    }
72}
73test(testParseFloatInt(-2));
74//aot: [trace] aot inline builtin: Number.parseFloat, caller function name:#*#testParseFloatInt@builtinNumberParseFloatNumber
75//aot: [trace] aot inline function name: #*#test@builtinNumberParseFloatNumber caller function name: func_main_0@builtinNumberParseFloatNumber
76//: number,-2
77
78let negZero = testParseFloat(-0.0 as any);
79//aot: [trace] aot inline builtin: Number.parseFloat, caller function name:#*#testParseFloat@builtinNumberParseFloatNumber
80//aot: [trace] Check Type: NotString1
81//: exit testParseFloat
82print(Object.is(negZero, -0))
83//aot: [trace] aot inline builtin: Object.is, caller function name:func_main_0@builtinNumberParseFloatNumber
84//: false
85print(Object.is(negZero, 0))
86//aot: [trace] aot inline builtin: Object.is, caller function name:func_main_0@builtinNumberParseFloatNumber
87//: true
88
89test(testParseFloat(-2.01));
90//aot: [trace] aot inline builtin: Number.parseFloat, caller function name:#*#testParseFloat@builtinNumberParseFloatNumber
91//aot: [trace] Check Type: NotString1
92//: exit testParseFloat
93//aot: [trace] aot inline function name: #*#test@builtinNumberParseFloatNumber caller function name: func_main_0@builtinNumberParseFloatNumber
94//: number,-2.01
95
96test(testNumberParseFloat(-2.01));
97//aot: [trace] aot inline builtin: Number.parseFloat, caller function name:#*#testNumberParseFloat@builtinNumberParseFloatNumber
98//aot: [trace] Check Type: NotString1
99//: exit testNumberParseFloat
100//aot: [trace] aot inline function name: #*#test@builtinNumberParseFloatNumber caller function name: func_main_0@builtinNumberParseFloatNumber
101//: number,-2.01
102