diff --git a/ecmascript/builtins/builtins_array.cpp b/ecmascript/builtins/builtins_array.cpp index 25a0f1a8b705757a589b1f23a907b1624c14b3f3..93608ae76a2a038c54e5bf94b1892f059113d0f5 100644 --- a/ecmascript/builtins/builtins_array.cpp +++ b/ecmascript/builtins/builtins_array.cpp @@ -1235,15 +1235,6 @@ JSTaggedValue BuiltinsArray::Join(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle thisHandle = GetThis(argv); - auto factory = thread->GetEcmaVM()->GetFactory(); - auto context = thread->GetCurrentEcmaContext(); - bool noCircular = context->JoinStackPushFastPath(thisHandle); - if (!noCircular) { - return factory->GetEmptyString().GetTaggedValue(); - } - if (thisHandle->IsStableJSArray(thread)) { - return JSStableArray::Join(JSHandle::Cast(thisHandle), argv); - } // 1. Let O be ToObject(this value). JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); @@ -1284,6 +1275,19 @@ JSTaggedValue BuiltinsArray::Join(EcmaRuntimeCallInfo *argv) } JSHandle sepStringHandle = JSTaggedValue::ToString(thread, sepHandle); + RETURN_EXCEPTION_AND_POP_JOINSTACK(thread, thisObjVal); + + auto factory = thread->GetEcmaVM()->GetFactory(); + auto context = thread->GetCurrentEcmaContext(); + bool noCircular = context->JoinStackPushFastPath(thisHandle); + if (!noCircular) { + return factory->GetEmptyString().GetTaggedValue(); + } + + if (thisHandle->IsStableJSArray(thread)) { + return JSStableArray::Join(thisObjVal, len, sepStringHandle, argv); + } + uint32_t allocateLength = 0; uint32_t sepLength = EcmaStringAccessor(sepStringHandle).GetLength(); diff --git a/ecmascript/js_stable_array.cpp b/ecmascript/js_stable_array.cpp index 9e7e925a99173d932c0501c67d2a5820dcff8c7a..c6e4799f1191746ad0d38877b9bc2ad23d2e737d 100644 --- a/ecmascript/js_stable_array.cpp +++ b/ecmascript/js_stable_array.cpp @@ -232,30 +232,18 @@ void JSStableArray::SetSepValue(JSHandle sepStringHandle, int &sep, } } -JSTaggedValue JSStableArray::Join(JSHandle receiver, EcmaRuntimeCallInfo *argv) +JSTaggedValue JSStableArray::Join(JSHandle receiverValue, uint32_t length, JSHandle sepStringHandle, EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); - uint32_t length = receiver->GetArrayLength(); - JSHandle sepHandle = base::BuiltinsBase::GetCallArg(argv, 0); int sep = ','; uint32_t sepLength = 1; - JSHandle sepStringHandle; auto context = thread->GetCurrentEcmaContext(); - JSHandle receiverValue = JSHandle::Cast(receiver); - if (!sepHandle->IsUndefined()) { - if (sepHandle->IsString()) { - sepStringHandle = JSHandle::Cast(sepHandle); - } else { - sepStringHandle = JSTaggedValue::ToString(thread, sepHandle); - RETURN_EXCEPTION_AND_POP_JOINSTACK(thread, receiverValue); - } - SetSepValue(sepStringHandle, sep, sepLength); - } if (length == 0) { const GlobalEnvConstants *globalConst = thread->GlobalConstants(); context->JoinStackPopFastPath(receiverValue); return globalConst->GetEmptyString(); } + SetSepValue(sepStringHandle, sep, sepLength); JSHandle obj(thread, receiverValue.GetTaggedValue()); size_t allocateLength = 0; bool isOneByte = (sep != JSStableArray::SeparatorFlag::MINUS_ONE) || EcmaStringAccessor(sepStringHandle).IsUtf8(); diff --git a/ecmascript/js_stable_array.h b/ecmascript/js_stable_array.h index 15ae5e0c3c217960e8234dccae72c4e943382e9d..500c4a90b20d1c41ed2459ed760b7a6fe32475f0 100644 --- a/ecmascript/js_stable_array.h +++ b/ecmascript/js_stable_array.h @@ -31,7 +31,7 @@ public: uint32_t insertCount, uint32_t actualDeleteCount, JSHandle newArrayHandle, uint32_t len); static JSTaggedValue Shift(JSHandle receiver, EcmaRuntimeCallInfo *argv); - static JSTaggedValue Join(JSHandle receiver, EcmaRuntimeCallInfo *argv); + static JSTaggedValue Join(JSHandle receiverValue, uint32_t length, JSHandle sepStringHandle, EcmaRuntimeCallInfo *argv); static JSTaggedValue HandleFindIndexOfStable(JSThread *thread, JSHandle thisObjHandle, JSHandle callbackFnHandle, JSHandle thisArgHandle, uint32_t &k);