[Bug]: Bugfix on Array.slice call ArrayCreate to create dictionary mode array

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

Signed-off-by: quiet-thought <chenjingxiang1@huawei.com>
Change-Id: I01d729837f59ea9197686f3144a688ec1429ae54
This commit is contained in:
quiet-thought 2023-07-19 10:04:13 +08:00
parent 2bafcd9845
commit 3fe4f36d1c
3 changed files with 12 additions and 4 deletions

View File

@ -115,7 +115,7 @@ JSTaggedValue JSArray::ArraySpeciesCreate(JSThread *thread, const JSHandle<JSObj
// Let C be Get(originalArray, "constructor").
auto *hclass = originalArray->GetJSHClass();
if (hclass->IsJSArray() && !hclass->HasConstructor()) {
return JSArray::ArrayCreate(thread, length).GetTaggedValue();
return JSArray::ArrayCreate(thread, length, ArrayMode::LITERAL).GetTaggedValue();
}
JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString();
constructor = JSTaggedValue::GetProperty(thread, originalValue, constructorKey).GetValue();
@ -133,7 +133,7 @@ JSTaggedValue JSArray::ArraySpeciesCreate(JSThread *thread, const JSHandle<JSObj
JSTaggedValue realmArrayConstructor = realmC->GetArrayFunction().GetTaggedValue();
// If SameValue(C, realmC.[[intrinsics]].[[%Array%]]) is true, let C be undefined.
if (JSTaggedValue::SameValue(constructor.GetTaggedValue(), realmArrayConstructor)) {
return JSArray::ArrayCreate(thread, length).GetTaggedValue();
return JSArray::ArrayCreate(thread, length, ArrayMode::LITERAL).GetTaggedValue();
}
}
}
@ -147,14 +147,14 @@ JSTaggedValue JSArray::ArraySpeciesCreate(JSThread *thread, const JSHandle<JSObj
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
// If C is null, let C be undefined.
if (constructor->IsNull()) {
return JSArray::ArrayCreate(thread, length).GetTaggedValue();
return JSArray::ArrayCreate(thread, length, ArrayMode::LITERAL).GetTaggedValue();
}
}
}
// If C is undefined, return ArrayCreate(length).
if (constructor->IsUndefined()) {
return JSArray::ArrayCreate(thread, length).GetTaggedValue();
return JSArray::ArrayCreate(thread, length, ArrayMode::LITERAL).GetTaggedValue();
}
// If IsConstructor(C) is false, throw a TypeError exception.
if (!constructor->IsConstructor()) {

View File

@ -13,3 +13,4 @@
33333
18001
0

View File

@ -39,3 +39,10 @@ do {
}
} while (t++ < 18000)
print(t);
let bytes = new Uint8Array(new ArrayBuffer(43584));
let arr2 = [].slice.call(bytes);
while (arr2.length) {
arr2.pop();
}
print(arr2.length);