Fix arrayList fuzz bug

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

Signed-off-by: 王笑佳 <wangxiaojia5@huawei.com>
This commit is contained in:
王笑佳 2024-09-04 17:08:27 +08:00
parent f87fd7f329
commit 2950293081
4 changed files with 21 additions and 2 deletions

View File

@ -119,6 +119,10 @@ void JSAPIArrayList::TrimToCurrentLength(JSThread *thread, const JSHandle<JSAPIA
JSTaggedValue JSAPIArrayList::Get(JSThread *thread, const uint32_t index)
{
if (GetLength().GetArrayLength() == 0) {
JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::RANGE_ERROR, "Container is empty");
THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception());
}
if (index >= GetLength().GetArrayLength()) {
ASSERT(GetLength().GetArrayLength() > 0);
std::ostringstream oss;
@ -280,6 +284,10 @@ JSTaggedValue JSAPIArrayList::ReplaceAllElements(JSThread *thread, const JSHandl
JSTaggedValue JSAPIArrayList::Set(JSThread *thread, const uint32_t index, JSTaggedValue value)
{
if (GetLength().GetArrayLength() == 0) {
JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::RANGE_ERROR, "Container is empty");
THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception());
}
if (index >= GetLength().GetArrayLength()) {
ASSERT(GetLength().GetArrayLength() > 0);
std::ostringstream oss;

View File

@ -118,7 +118,7 @@ JSTaggedValue JSAPIQueue::Get(JSThread *thread, const uint32_t index)
JSTaggedValue JSAPIQueue::Set(JSThread *thread, const uint32_t index, JSTaggedValue value)
{
if (GetLength().GetArrayLength() <= 0) {
if (GetLength().GetArrayLength() == 0) {
JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::RANGE_ERROR, "Container is empty");
THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception());
}

View File

@ -291,7 +291,17 @@ if (globalThis["ArkPrivate"] != undefined) {
temp.add(val)
})
print(oldLen * 2 === v1.length)
const v3 = new arrayList();
const v4 = [arrayList,arrayList];
class C4{
["100"] = v4
}
const v5 = new C4();
try {
Object.assign(v3,v5)
} catch (error) {
print(error)
}
if (!flag) {
print("Test ArrayList success!!!");
} else {

View File

@ -12,6 +12,7 @@
# limitations under the License.
true
BusinessError: Container is empty
Test ArrayList success!!!
Test Deque success!!!
{}