!9323 修复SendableArray.create频繁扩容问题

Merge pull request !9323 from lukai/cherry-pick-1726288143
This commit is contained in:
openharmony_ci 2024-09-14 20:40:39 +00:00 committed by Gitee
commit d9678ccf4d
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -353,13 +353,14 @@ JSTaggedValue BuiltinsSharedArray::Create(EcmaRuntimeCallInfo *argv)
THROW_TYPE_ERROR_AND_RETURN(thread, "Failed to construct the array.", JSTaggedValue::Exception());
}
JSHandle<JSObject> newArrayHandle(thread, newArray);
JSMutableHandle<JSTaggedValue> key(thread, JSTaggedValue::Undefined());
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
auto elements = factory->NewSOldSpaceTaggedArray(arrayLength, JSTaggedValue::Hole());
for (uint32_t k = 0; k < arrayLength; k++) {
key.Update(JSTaggedValue(k));
JSObject::CreateDataPropertyOrThrow(thread, newArrayHandle, key, initValue, SCheckMode::SKIP);
elements->Set(thread, k, initValue);
}
key.Update(JSTaggedValue(arrayLength));
JSSharedArray::LengthSetter(thread, newArrayHandle, key, true);
newArrayHandle->SetElements(thread, elements);
auto len = JSHandle<JSTaggedValue>(thread, JSTaggedValue(arrayLength));
JSSharedArray::LengthSetter(thread, newArrayHandle, len, true);
newArrayHandle->GetJSHClass()->SetExtensible(false);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
// Return A.