!10130 Fix array join

Merge pull request !10130 from XinweiCai/fix_array_join
This commit is contained in:
openharmony_ci 2024-11-07 11:40:36 +00:00 committed by Gitee
commit 1663fc47e9
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 9 additions and 4 deletions

View File

@ -484,7 +484,8 @@ JSTaggedValue JSStableArray::Join(JSHandle<JSArray> receiver, EcmaRuntimeCallInf
JSHandle<JSTaggedValue> sepHandle = base::BuiltinsBase::GetCallArg(argv, 0);
int sep = ',';
uint32_t sepLength = 1;
JSHandle<EcmaString> sepStringHandle;
const GlobalEnvConstants *globalConst = thread->GlobalConstants();
JSHandle<EcmaString> sepStringHandle = JSHandle<EcmaString>::Cast(globalConst->GetHandledCommaString());
auto context = thread->GetCurrentEcmaContext();
JSHandle<JSTaggedValue> receiverValue = JSHandle<JSTaggedValue>::Cast(receiver);
if (!sepHandle->IsUndefined()) {
@ -497,7 +498,6 @@ JSTaggedValue JSStableArray::Join(JSHandle<JSArray> receiver, EcmaRuntimeCallInf
SetSepValue(sepStringHandle, sep, sepLength);
}
if (length == 0) {
const GlobalEnvConstants *globalConst = thread->GlobalConstants();
context->JoinStackPopFastPath(receiverValue);
return globalConst->GetEmptyString();
}
@ -505,7 +505,6 @@ JSTaggedValue JSStableArray::Join(JSHandle<JSArray> receiver, EcmaRuntimeCallInf
uint64_t allocateLength = 0;
bool isOneByte = (sep != JSStableArray::SeparatorFlag::MINUS_ONE) || EcmaStringAccessor(sepStringHandle).IsUtf8();
JSMutableHandle<JSTaggedValue> elementHandle(thread, JSTaggedValue::Undefined());
const GlobalEnvConstants *globalConst = thread->GlobalConstants();
uint32_t elementsLength = ElementAccessor::GetElementsLength(obj);
uint32_t len = elementsLength > length ? length : elementsLength;
if (elementsLength == 0 && length != 0) {

View File

@ -111,4 +111,9 @@ const element = {
}
};
const arr_join = [element, ,'c'];
print("abc" == arr_join.join(''));
print("abc" == arr_join.join(''));
const v9 = new Int16Array(128);
const v10 = new Int8Array(128);
v9[11] = [v9, v10];
print(v9[11]);

View File

@ -30,3 +30,4 @@ NaN
NaN
NaN0
true
0