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 interface ArkTools {
174514f5e3Sopenharmony_ci    isAOTCompiled(args: any): boolean;
184514f5e3Sopenharmony_ci}
194514f5e3Sopenharmony_cideclare function print(arg:any): string;
204514f5e3Sopenharmony_ci
214514f5e3Sopenharmony_cifunction replace()
224514f5e3Sopenharmony_ci{
234514f5e3Sopenharmony_ci    return 12345;
244514f5e3Sopenharmony_ci}
254514f5e3Sopenharmony_ci
264514f5e3Sopenharmony_cifunction doDateGetTimeOneParam(x: any): number {
274514f5e3Sopenharmony_ci    return time.getTime(x);
284514f5e3Sopenharmony_ci}
294514f5e3Sopenharmony_ci
304514f5e3Sopenharmony_cifunction printDateGetTimeOneParam(x: any) {
314514f5e3Sopenharmony_ci    try {
324514f5e3Sopenharmony_ci        print(doDateGetTimeOneParam(x));
334514f5e3Sopenharmony_ci    } finally {
344514f5e3Sopenharmony_ci    }
354514f5e3Sopenharmony_ci}
364514f5e3Sopenharmony_ci
374514f5e3Sopenharmony_cifunction doDateGetTimeWithoutParam(): number {
384514f5e3Sopenharmony_ci    return time.getTime();
394514f5e3Sopenharmony_ci}
404514f5e3Sopenharmony_ci
414514f5e3Sopenharmony_cifunction printDateGetTimeWithoutParam() {
424514f5e3Sopenharmony_ci    try {
434514f5e3Sopenharmony_ci        print(doDateGetTimeWithoutParam());
444514f5e3Sopenharmony_ci    } finally {
454514f5e3Sopenharmony_ci    }
464514f5e3Sopenharmony_ci}
474514f5e3Sopenharmony_ci
484514f5e3Sopenharmony_cilet time = new Date('July 20, 99 20:17:40 GMT+00:00')
494514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Date.prototype.getTime, caller function name:func_main_0@builtinDateGetTime
504514f5e3Sopenharmony_ciprint(time.getTime()); //: 932501860000
514514f5e3Sopenharmony_ci
524514f5e3Sopenharmony_citime = new Date(990000000000)
534514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Date.prototype.getTime, caller function name:func_main_0@builtinDateGetTime
544514f5e3Sopenharmony_ciprint(time.getTime()); //: 990000000000
554514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Date.prototype.getTime, caller function name:func_main_0@builtinDateGetTime
564514f5e3Sopenharmony_cilet temp = time.getTime() + 1
574514f5e3Sopenharmony_ciprint(temp) //: 990000000001
584514f5e3Sopenharmony_ci
594514f5e3Sopenharmony_citime = new Date(1990, 2, 15, 16, 17, 18);
604514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Date.prototype.getTime, caller function name:func_main_0@builtinDateGetTime
614514f5e3Sopenharmony_ciprint(time.getTime()); //: 637489038000
624514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Date.prototype.getTime, caller function name:func_main_0@builtinDateGetTime
634514f5e3Sopenharmony_ciprint(time.getTime(123)); //: 637489038000
644514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Date.prototype.getTime, caller function name:func_main_0@builtinDateGetTime
654514f5e3Sopenharmony_ciprint(time.getTime("string")); //: 637489038000
664514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Date.prototype.getTime, caller function name:func_main_0@builtinDateGetTime
674514f5e3Sopenharmony_ciprint(time.getTime(1, 2)); //: 637489038000
684514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Date.prototype.getTime, caller function name:func_main_0@builtinDateGetTime
694514f5e3Sopenharmony_ciprint(time.getTime(1, 2, 3)); //: 637489038000
704514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Date.prototype.getTime, caller function name:func_main_0@builtinDateGetTime
714514f5e3Sopenharmony_ciprint(time.getTime(1, 2, 3, 4)); //: 637489038000
724514f5e3Sopenharmony_ci
734514f5e3Sopenharmony_ci
744514f5e3Sopenharmony_citime = new Date('May 1, 69 8:0:0 GMT+00:00');
754514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Date.prototype.getTime, caller function name:func_main_0@builtinDateGetTime
764514f5e3Sopenharmony_ciprint(time.getTime()); //: -21139200000
774514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Date.prototype.getTime, caller function name:func_main_0@builtinDateGetTime
784514f5e3Sopenharmony_ciprint(time.getTime({})); //: -21139200000
794514f5e3Sopenharmony_ci
804514f5e3Sopenharmony_citime = new Date('Jan 0, 2000 10:11:12 GMT+00:00');
814514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Date.prototype.getTime, caller function name:func_main_0@builtinDateGetTime
824514f5e3Sopenharmony_ciprint(time.getTime()); //: NaN
834514f5e3Sopenharmony_ci
844514f5e3Sopenharmony_citime = new Date(50000000000)
854514f5e3Sopenharmony_cilet true_func = time.getTime
864514f5e3Sopenharmony_ci
874514f5e3Sopenharmony_ciprint(true_func.call(time)) //: 50000000000
884514f5e3Sopenharmony_ciprint(true_func.call(time, 1)) //: 50000000000
894514f5e3Sopenharmony_ciprint(true_func.call(time, 1, 2)) //: 50000000000
904514f5e3Sopenharmony_ci
914514f5e3Sopenharmony_ciif (ArkTools.isAOTCompiled(printDateGetTimeOneParam)) {
924514f5e3Sopenharmony_ci    // Replace standard builtin after call to standard builtin was profiled
934514f5e3Sopenharmony_ci    time.getTime = replace;
944514f5e3Sopenharmony_ci}
954514f5e3Sopenharmony_ci
964514f5e3Sopenharmony_ciprintDateGetTimeWithoutParam() //pgo: 50000000000
974514f5e3Sopenharmony_ci                               //aot: [trace] Check Type: BuiltinInstanceHClassMismatch
984514f5e3Sopenharmony_ci                               //aot: 12345
994514f5e3Sopenharmony_ciprintDateGetTimeOneParam(123); //pgo: 50000000000
1004514f5e3Sopenharmony_ci                               //aot: [trace] Check Type: BuiltinInstanceHClassMismatch
1014514f5e3Sopenharmony_ci                               //aot: 12345
1024514f5e3Sopenharmony_ciprintDateGetTimeOneParam("abc"); //pgo: 50000000000
1034514f5e3Sopenharmony_ci                                 //aot: [trace] Check Type: BuiltinInstanceHClassMismatch
1044514f5e3Sopenharmony_ci                                 //aot: 12345
1054514f5e3Sopenharmony_ci
1064514f5e3Sopenharmony_citime.getTime = true_func
1074514f5e3Sopenharmony_ci
1084514f5e3Sopenharmony_cilet obj = {
1094514f5e3Sopenharmony_ci    valueOf: () => { return -23; }
1104514f5e3Sopenharmony_ci};
1114514f5e3Sopenharmony_cifunction Throwing() {
1124514f5e3Sopenharmony_ci    this.value = -14;
1134514f5e3Sopenharmony_ci};
1144514f5e3Sopenharmony_ciThrowing.prototype.valueOf = function() {
1154514f5e3Sopenharmony_ci    if (this.value > 0) {
1164514f5e3Sopenharmony_ci        throw new Error("already positive");
1174514f5e3Sopenharmony_ci    }
1184514f5e3Sopenharmony_ci    return this.value;
1194514f5e3Sopenharmony_ci}
1204514f5e3Sopenharmony_cilet throwingObj = new Throwing();
1214514f5e3Sopenharmony_ci
1224514f5e3Sopenharmony_citry {
1234514f5e3Sopenharmony_ci    //aot: [trace] aot inline builtin: Date.prototype.getTime, caller function name:func_main_0@builtinDateGetTime
1244514f5e3Sopenharmony_ci    print(time.getTime(throwingObj)); //: 50000000000
1254514f5e3Sopenharmony_ci    throwingObj.value = 10;
1264514f5e3Sopenharmony_ci    //aot: [trace] aot inline builtin: Date.prototype.getTime, caller function name:func_main_0@builtinDateGetTime
1274514f5e3Sopenharmony_ci    print(time.getTime(throwingObj)); //: 50000000000
1284514f5e3Sopenharmony_ci} catch(e) {
1294514f5e3Sopenharmony_ci    print(e);
1304514f5e3Sopenharmony_ci} finally {
1314514f5e3Sopenharmony_ci    //aot: [trace] aot inline builtin: Date.prototype.getTime, caller function name:func_main_0@builtinDateGetTime
1324514f5e3Sopenharmony_ci    print(time.getTime(obj)); //: 50000000000
1334514f5e3Sopenharmony_ci}
1344514f5e3Sopenharmony_ci
1354514f5e3Sopenharmony_cifunction checkObjWithDateProto() {
1364514f5e3Sopenharmony_ci    let o = {};
1374514f5e3Sopenharmony_ci    Object.setPrototypeOf(o, Date.prototype);
1384514f5e3Sopenharmony_ci    try {
1394514f5e3Sopenharmony_ci        o.getTime();
1404514f5e3Sopenharmony_ci    } catch(e) {
1414514f5e3Sopenharmony_ci        print(e);
1424514f5e3Sopenharmony_ci    }
1434514f5e3Sopenharmony_ci}
1444514f5e3Sopenharmony_ci
1454514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotCallTarget1
1464514f5e3Sopenharmony_ci//: TypeError: Not a Date Object
1474514f5e3Sopenharmony_cicheckObjWithDateProto();
148