diff --git a/ecmascript/compiler/typed_bytecode_lowering.cpp b/ecmascript/compiler/typed_bytecode_lowering.cpp index 8e320f31a8f598c53dc93dd1631a1eeed23877b0..0517a10973fbaeee0886d54d504e8d3110f2d845 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 d2cad71ce807721abfaac65f0937eda51709a638..baf7e6891dd0bf5786d1ad4cb2e821f329021f31 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 0000000000000000000000000000000000000000..88704eb6b1f01adb8effa69db35cd9d78af96ee5 --- /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 0000000000000000000000000000000000000000..0bdf529deace661640f386a33c42f9e66ebe6de9 --- /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 0000000000000000000000000000000000000000..77128580b6eecf5faa492158f48fdeb4e1a5ac82 --- /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();