diff --git a/ecmascript/js_api/js_api_arraylist.cpp b/ecmascript/js_api/js_api_arraylist.cpp index 636ae371b2..59924cf107 100644 --- a/ecmascript/js_api/js_api_arraylist.cpp +++ b/ecmascript/js_api/js_api_arraylist.cpp @@ -119,6 +119,10 @@ void JSAPIArrayList::TrimToCurrentLength(JSThread *thread, const JSHandle= 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; diff --git a/ecmascript/js_api/js_api_queue.cpp b/ecmascript/js_api/js_api_queue.cpp index c144bdc675..930e38a96f 100644 --- a/ecmascript/js_api/js_api_queue.cpp +++ b/ecmascript/js_api/js_api_queue.cpp @@ -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()); } diff --git a/test/moduletest/container/container_arraylist.js b/test/moduletest/container/container_arraylist.js index 83e191c7e3..b6bc12dd52 100644 --- a/test/moduletest/container/container_arraylist.js +++ b/test/moduletest/container/container_arraylist.js @@ -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 { diff --git a/test/moduletest/container/expect_output.txt b/test/moduletest/container/expect_output.txt index 2bfced383d..2619e8c0f5 100644 --- a/test/moduletest/container/expect_output.txt +++ b/test/moduletest/container/expect_output.txt @@ -12,6 +12,7 @@ # limitations under the License. true +BusinessError: Container is empty Test ArrayList success!!! Test Deque success!!! {}