diff --git a/ecmascript/builtins/builtins_shared_array.cpp b/ecmascript/builtins/builtins_shared_array.cpp index 7a78674073..a23a7a457b 100644 --- a/ecmascript/builtins/builtins_shared_array.cpp +++ b/ecmascript/builtins/builtins_shared_array.cpp @@ -353,13 +353,14 @@ JSTaggedValue BuiltinsSharedArray::Create(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "Failed to construct the array.", JSTaggedValue::Exception()); } JSHandle newArrayHandle(thread, newArray); - JSMutableHandle 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(thread, JSTaggedValue(arrayLength)); + JSSharedArray::LengthSetter(thread, newArrayHandle, len, true); newArrayHandle->GetJSHClass()->SetExtensible(false); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // Return A.