• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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}
19declare function print(arg:any): string;
20
21function replace()
22{
23    return 12345;
24}
25
26function doDateGetTimeOneParam(x: any): number {
27    return time.getTime(x);
28}
29
30function printDateGetTimeOneParam(x: any) {
31    try {
32        print(doDateGetTimeOneParam(x));
33    } finally {
34    }
35}
36
37function doDateGetTimeWithoutParam(): number {
38    return time.getTime();
39}
40
41function printDateGetTimeWithoutParam() {
42    try {
43        print(doDateGetTimeWithoutParam());
44    } finally {
45    }
46}
47
48let time = new Date('July 20, 99 20:17:40 GMT+00:00')
49//aot: [trace] aot inline builtin: Date.prototype.getTime, caller function name:func_main_0@builtinDateGetTime
50print(time.getTime()); //: 932501860000
51
52time = new Date(990000000000)
53//aot: [trace] aot inline builtin: Date.prototype.getTime, caller function name:func_main_0@builtinDateGetTime
54print(time.getTime()); //: 990000000000
55//aot: [trace] aot inline builtin: Date.prototype.getTime, caller function name:func_main_0@builtinDateGetTime
56let temp = time.getTime() + 1
57print(temp) //: 990000000001
58
59time = new Date(1990, 2, 15, 16, 17, 18);
60//aot: [trace] aot inline builtin: Date.prototype.getTime, caller function name:func_main_0@builtinDateGetTime
61print(time.getTime()); //: 637489038000
62//aot: [trace] aot inline builtin: Date.prototype.getTime, caller function name:func_main_0@builtinDateGetTime
63print(time.getTime(123)); //: 637489038000
64//aot: [trace] aot inline builtin: Date.prototype.getTime, caller function name:func_main_0@builtinDateGetTime
65print(time.getTime("string")); //: 637489038000
66//aot: [trace] aot inline builtin: Date.prototype.getTime, caller function name:func_main_0@builtinDateGetTime
67print(time.getTime(1, 2)); //: 637489038000
68//aot: [trace] aot inline builtin: Date.prototype.getTime, caller function name:func_main_0@builtinDateGetTime
69print(time.getTime(1, 2, 3)); //: 637489038000
70//aot: [trace] aot inline builtin: Date.prototype.getTime, caller function name:func_main_0@builtinDateGetTime
71print(time.getTime(1, 2, 3, 4)); //: 637489038000
72
73
74time = new Date('May 1, 69 8:0:0 GMT+00:00');
75//aot: [trace] aot inline builtin: Date.prototype.getTime, caller function name:func_main_0@builtinDateGetTime
76print(time.getTime()); //: -21139200000
77//aot: [trace] aot inline builtin: Date.prototype.getTime, caller function name:func_main_0@builtinDateGetTime
78print(time.getTime({})); //: -21139200000
79
80time = new Date('Jan 0, 2000 10:11:12 GMT+00:00');
81//aot: [trace] aot inline builtin: Date.prototype.getTime, caller function name:func_main_0@builtinDateGetTime
82print(time.getTime()); //: NaN
83
84time = new Date(50000000000)
85let true_func = time.getTime
86
87//aot: [trace] aot call builtin: Function.prototype.call, caller function name:func_main_0@builtinDateGetTime
88print(true_func.call(time)) //: 50000000000
89//aot: [trace] aot call builtin: Function.prototype.call, caller function name:func_main_0@builtinDateGetTime
90print(true_func.call(time, 1)) //: 50000000000
91//aot: [trace] aot call builtin: Function.prototype.call, caller function name:func_main_0@builtinDateGetTime
92print(true_func.call(time, 1, 2)) //: 50000000000
93
94if (ArkTools.isAOTCompiled(printDateGetTimeOneParam)) {
95    // Replace standard builtin after call to standard builtin was profiled
96    time.getTime = replace;
97}
98
99printDateGetTimeWithoutParam() //pgo: 50000000000
100                               //aot: [trace] Check Type: BuiltinInstanceHClassMismatch
101                               //aot: 12345
102printDateGetTimeOneParam(123); //pgo: 50000000000
103                               //aot: [trace] Check Type: BuiltinInstanceHClassMismatch
104                               //aot: 12345
105printDateGetTimeOneParam("abc"); //pgo: 50000000000
106                                 //aot: [trace] Check Type: BuiltinInstanceHClassMismatch
107                                 //aot: 12345
108
109time.getTime = true_func
110
111let obj = {
112    valueOf: () => { return -23; }
113};
114function Throwing() {
115    this.value = -14;
116};
117Throwing.prototype.valueOf = function() {
118    if (this.value > 0) {
119        throw new Error("already positive");
120    }
121    return this.value;
122}
123let throwingObj = new Throwing();
124
125try {
126    //aot: [trace] aot inline builtin: Date.prototype.getTime, caller function name:func_main_0@builtinDateGetTime
127    print(time.getTime(throwingObj)); //: 50000000000
128    throwingObj.value = 10;
129    //aot: [trace] aot inline builtin: Date.prototype.getTime, caller function name:func_main_0@builtinDateGetTime
130    print(time.getTime(throwingObj)); //: 50000000000
131} catch(e) {
132    print(e);
133} finally {
134    //aot: [trace] aot inline builtin: Date.prototype.getTime, caller function name:func_main_0@builtinDateGetTime
135    print(time.getTime(obj)); //: 50000000000
136}
137
138function checkObjWithDateProto() {
139    let o = {};
140    //aot: [trace] aot call builtin: Object.SetPrototypeOf, caller function name:#*#checkObjWithDateProto@builtinDateGetTime
141    Object.setPrototypeOf(o, Date.prototype);
142    try {
143        o.getTime();
144    } catch(e) {
145        print(e);
146    }
147}
148
149//aot: [trace] Check Type: NotCallTarget1
150//: TypeError: Not a Date Object
151checkObjWithDateProto();
152