[Bug]: Bugfix do forin with nativepointer

Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IB2SZ0

Signed-off-by: hecunmao <hecunmao@huawei.com>
Change-Id: I8ebef8c2378eede93d85d96b5abb25032404e704
This commit is contained in:
hecunmao 2024-11-07 18:50:37 +08:00
parent 421fb045ea
commit 2fd7636b6f
3 changed files with 15 additions and 2 deletions

View File

@ -1214,6 +1214,7 @@ GateRef NewObjectStubBuilder::EnumerateObjectProperties(GateRef glue, GateRef ob
Label empty(env);
Label tryGetEnumCache(env);
Label cacheHit(env);
Label checkNativePointer(env);
BRANCH(TaggedIsString(obj), &isString, &isNotString);
Bind(&isString);
{
@ -1226,7 +1227,9 @@ GateRef NewObjectStubBuilder::EnumerateObjectProperties(GateRef glue, GateRef ob
Jump(&afterObjectTransform);
}
Bind(&afterObjectTransform);
BRANCH(TaggedIsUndefinedOrNull(*object), &empty, &tryGetEnumCache);
BRANCH(TaggedIsUndefinedOrNull(*object), &empty, &checkNativePointer);
Bind(&checkNativePointer);
BRANCH(IsNativePointer(*object), &empty, &tryGetEnumCache);
Bind(&tryGetEnumCache);
GateRef enumCache = TryGetEnumCache(glue, *object);
BRANCH(TaggedIsUndefined(enumCache), &slowpath, &cacheHit);

View File

@ -2627,7 +2627,7 @@ JSHandle<JSForInIterator> JSObject::EnumerateObjectProperties(JSThread *thread,
JSMutableHandle<JSTaggedValue> keys(thread, JSTaggedValue::Undefined());
JSMutableHandle<JSTaggedValue> cachedHclass(thread, JSTaggedValue::Undefined());
if (object->IsNull() || object->IsUndefined()) {
if (object->IsNull() || object->IsUndefined() || object->IsJSNativePointer()) {
JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
keys.Update(factory->EmptyArray());

View File

@ -62,4 +62,14 @@ HWTEST_F_L0(JSForinIteratorTest, Create)
JSTaggedValue n4 = JSForInIterator::NextInternal(thread, it);
EXPECT_EQ(n4, JSTaggedValue::Undefined());
}
HWTEST_F_L0(JSForinIteratorTest, ForinNativePointer)
{
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
int pointArr[10];
auto *nativePointer = pointArr;
JSHandle<JSNativePointer> pointer = factory->NewJSNativePointer(nativePointer);
JSHandle<JSForInIterator> it = JSObject::EnumerateObjectProperties(thread, JSHandle<JSTaggedValue>(pointer));
EXPECT_EQ(it->GetLength(), 0);
}
} // namespace panda::test