From 69db5bca6007502bc6ddeb92bf67c173e4cd9691 Mon Sep 17 00:00:00 2001 From: l00809476 Date: Mon, 11 Aug 2025 20:56:57 +0800 Subject: [PATCH] bugfix for date constructor stub Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICSFT7 Signed-off-by: l00809476 Change-Id: Ibbf019c0057a78010ea7bcb78032bf0e36c84923 --- .../compiler/builtins/builtins_stubs.cpp | 12 ++----- test/jittest/date_constructor/BUILD.gn | 18 ++++++++++ .../date_constructor/date_constructor.ts | 33 +++++++++++++++++++ .../date_constructor/expect_output.txt | 16 +++++++++ 4 files changed, 69 insertions(+), 10 deletions(-) create mode 100644 test/jittest/date_constructor/BUILD.gn create mode 100644 test/jittest/date_constructor/date_constructor.ts create mode 100644 test/jittest/date_constructor/expect_output.txt diff --git a/ecmascript/compiler/builtins/builtins_stubs.cpp b/ecmascript/compiler/builtins/builtins_stubs.cpp index ab8e23aa64..7c16cc4933 100644 --- a/ecmascript/compiler/builtins/builtins_stubs.cpp +++ b/ecmascript/compiler/builtins/builtins_stubs.cpp @@ -521,7 +521,6 @@ DECLARE_BUILTINS(DateConstructor) Label newTargetIsHeapObject(env); Label newTargetIsJSFunction(env); Label slowPath(env); - Label slowPath1(env); Label exit(env); BRANCH(TaggedIsHeapObject(newTarget), &newTargetIsHeapObject, &slowPath); @@ -532,7 +531,7 @@ DECLARE_BUILTINS(DateConstructor) Label intialHClassIsHClass(env); GateRef intialHClass = Load(VariableType::JS_ANY(), glue, newTarget, IntPtr(JSFunction::PROTO_OR_DYNCLASS_OFFSET)); - BRANCH(IsJSHClass(glue, intialHClass), &intialHClassIsHClass, &slowPath1); + BRANCH(IsJSHClass(glue, intialHClass), &intialHClassIsHClass, &slowPath); Bind(&intialHClassIsHClass); { Label oneArg(env); @@ -587,18 +586,11 @@ DECLARE_BUILTINS(DateConstructor) } } } - Bind(&slowPath1); - { - GateRef argv = GetArgv(); - res = CallBuiltinRuntimeWithNewTarget(glue, - { glue, nativeCode, func, thisValue, numArgs, argv, newTarget }); - Jump(&exit); - } } Bind(&slowPath); { GateRef argv = GetArgv(); - res = CallBuiltinRuntime(glue, { glue, nativeCode, func, thisValue, numArgs, argv }, true); + res = CallBuiltinRuntimeWithNewTarget(glue, {glue, nativeCode, func, thisValue, numArgs, argv, newTarget}); Jump(&exit); } Bind(&exit); diff --git a/test/jittest/date_constructor/BUILD.gn b/test/jittest/date_constructor/BUILD.gn new file mode 100644 index 0000000000..93946b9c25 --- /dev/null +++ b/test/jittest/date_constructor/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//arkcompiler/ets_runtime/test/test_helper.gni") + +host_jit_test_action("date_constructor") { + deps = [] +} diff --git a/test/jittest/date_constructor/date_constructor.ts b/test/jittest/date_constructor/date_constructor.ts new file mode 100644 index 0000000000..f741662e7e --- /dev/null +++ b/test/jittest/date_constructor/date_constructor.ts @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class D extends Date {} +function Test() { + let d = new D(); + if (!(d instanceof D)) { + throw "d has incorrect prototype chain"; + } else { + print("success"); + } +} + +Test(); + +ArkTools.jitCompileAsync(Test); +print(ArkTools.waitJitCompileFinish(Test)); + +for (let i = 0; i < 2; i++) { + Test(); +} diff --git a/test/jittest/date_constructor/expect_output.txt b/test/jittest/date_constructor/expect_output.txt new file mode 100644 index 0000000000..78e3118538 --- /dev/null +++ b/test/jittest/date_constructor/expect_output.txt @@ -0,0 +1,16 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +true +success +success -- Gitee