Bug in nativepointer Hash

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

Signed-off-by: hecunmao <hecunmao@huawei.com>
Change-Id: I94d72f31c6bbaa716057c3df829f31da6c214af0
This commit is contained in:
hecunmao 2024-11-09 15:46:34 +08:00
parent 1bf3bbee91
commit 66389d6674
2 changed files with 4 additions and 3 deletions

View File

@ -2910,11 +2910,12 @@ void ECMAObject::SetHash(const JSThread *thread, int32_t hash, const JSHandle<EC
TaggedArray *array = TaggedArray::Cast(value.GetTaggedObject());
array->Set(thread, array->GetExtraLength() + HASH_INDEX, JSTaggedValue(hash));
} else if (value.IsNativePointer()) { // FunctionExtraInfo
JSHandle<JSTaggedValue> nativePointer(thread, value);
JSHandle<TaggedArray> newArray =
thread->GetEcmaVM()->GetFactory()->NewTaggedArray(RESOLVED_MAX_SIZE);
newArray->SetExtraLength(0);
newArray->Set(thread, HASH_INDEX, JSTaggedValue(hash));
newArray->Set(thread, FUNCTION_EXTRA_INDEX, value);
newArray->Set(thread, FUNCTION_EXTRA_INDEX, nativePointer.GetTaggedValue());
Barriers::SetObject<true>(thread, *obj, HASH_OFFSET, newArray.GetTaggedValue().GetRawData());
} else {
LOG_ECMA(FATAL) << "this branch is unreachable";

View File

@ -103,10 +103,10 @@ HWTEST_F_L0(JSMapTest, DeleteAndGet2)
JSHandle<JSObject> obj = factory->NewEmptyJSObject(0);
auto *nativePointer = pointArr + i;
JSHandle<JSNativePointer> pointer = factory->NewJSNativePointer(nativePointer);
Barriers::SetPrimitive<JSTaggedType>(*obj, ECMAObject::HASH_OFFSET, pointer.GetTaggedValue().GetRawData());
Barriers::SetObject<true>(thread, *obj, ECMAObject::HASH_OFFSET, pointer.GetTaggedValue().GetRawData());
taggedArray->Set(thread, i, obj);
}
thread->GetEcmaVM()->CollectGarbage(TriggerGCType::FULL_GC);
JSHandle<JSTaggedValue> setfunc =
JSObject::GetProperty(thread, mapvalue, thread->GlobalConstants()->GetHandledSetString()).GetValue();
JSHandle<JSTaggedValue> getfunc = thread->GlobalConstants()->GetHandledMapGet();