From f095d100cc4ba3993b5189889173348f3d0dba1b Mon Sep 17 00:00:00 2001 From: l00809476 Date: Thu, 14 Aug 2025 11:48:04 +0800 Subject: [PATCH] bugfix for instance of exception Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICSWI7 Signed-off-by: l00809476 Change-Id: I6f3bc932548e4ef39fbcebfe89cb2843004c9ad3 --- .../compiler/typed_bytecode_lowering.cpp | 2 +- ecmascript/compiler/typed_hcr_lowering.cpp | 2 +- test/jittest/instance_of_001/BUILD.gn | 18 +++++++++ .../jittest/instance_of_001/expect_output.txt | 16 ++++++++ .../instance_of_001/instance_of_001.ts | 37 +++++++++++++++++++ 5 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 test/jittest/instance_of_001/BUILD.gn create mode 100644 test/jittest/instance_of_001/expect_output.txt create mode 100644 test/jittest/instance_of_001/instance_of_001.ts diff --git a/ecmascript/compiler/typed_bytecode_lowering.cpp b/ecmascript/compiler/typed_bytecode_lowering.cpp index 8e320f31a8..0517a10973 100644 --- a/ecmascript/compiler/typed_bytecode_lowering.cpp +++ b/ecmascript/compiler/typed_bytecode_lowering.cpp @@ -2809,7 +2809,7 @@ void TypedBytecodeLowering::LowerInstanceOf(GateRef gate) builder_.ProtoChangeMarkerCheck(target); result = builder_.OrdinaryHasInstance(obj, target); - acc_.ReplaceHirAndReplaceDeadIfException(gate, builder_.GetStateDepend(), *result); + ReplaceGateWithPendingException(glue_, gate, builder_.GetState(), builder_.GetDepend(), *result); } void TypedBytecodeLowering::LowerCreateEmptyObject(GateRef gate) diff --git a/ecmascript/compiler/typed_hcr_lowering.cpp b/ecmascript/compiler/typed_hcr_lowering.cpp index d2cad71ce8..baf7e6891d 100644 --- a/ecmascript/compiler/typed_hcr_lowering.cpp +++ b/ecmascript/compiler/typed_hcr_lowering.cpp @@ -2703,7 +2703,7 @@ void TypedHCRLowering::LowerOrdinaryHasInstanceForJIT(GateRef gate, GateRef glue GateRef target = acc_.GetValueIn(gate, 1); auto result = builder_.CallStub(glue, gate, CommonStubCSigns::OrdinaryHasInstance, {glue, obj, target, circuit_->GetGlobalEnvCache()}, "OrdinaryHasInstance stub"); - ReplaceGateWithPendingException(glue, gate, builder_.GetState(), builder_.GetDepend(), result); + acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), result); } void TypedHCRLowering::LowerOrdinaryHasInstance(GateRef gate, GateRef glue) diff --git a/test/jittest/instance_of_001/BUILD.gn b/test/jittest/instance_of_001/BUILD.gn new file mode 100644 index 0000000000..88704eb6b1 --- /dev/null +++ b/test/jittest/instance_of_001/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("instance_of_001") { + deps = [] +} diff --git a/test/jittest/instance_of_001/expect_output.txt b/test/jittest/instance_of_001/expect_output.txt new file mode 100644 index 0000000000..0bdf529dea --- /dev/null +++ b/test/jittest/instance_of_001/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. + +catch: TypeError: InstanceOf error when target is not Callable +true +catch: TypeError: InstanceOf error when target is not Callable diff --git a/test/jittest/instance_of_001/instance_of_001.ts b/test/jittest/instance_of_001/instance_of_001.ts new file mode 100644 index 0000000000..77128580b6 --- /dev/null +++ b/test/jittest/instance_of_001/instance_of_001.ts @@ -0,0 +1,37 @@ +/* + * 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. + */ + + +function InstanceTest(x, func) { + try { + var answer = (x instanceof func); + } catch (e) { + print("catch: ", e) + } +} + +function Test() { + var Foo = function() {} + Foo.prototype = 12; + var x = new Foo(); + InstanceTest(x, Foo); +} + +Test(); + +ArkTools.jitCompileAsync(InstanceTest); +print(ArkTools.waitJitCompileFinish(InstanceTest)); + +Test(); -- Gitee