BugFix Iterators

Description:
	Fix bugs on Iterators on map and set classes
	Fix bugs on LinkedList and List when iterating.

Issues: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I5XJM5

Signed-off-by: yuan-yao14 <yuanyao14@huawei.com>
Change-Id: I16233a943032a13d20bca66eec43beb771743bf6
This commit is contained in:
yuan-yao14 2022-10-25 12:01:41 +08:00
parent f185f6c02f
commit 9be2661742
20 changed files with 88 additions and 94 deletions

View File

@ -68,11 +68,11 @@ JSTaggedValue JSAPIHashMapIterator::Next(EcmaRuntimeCallInfo *argv)
if (itemKind == IterationKind::VALUE) {
return JSIterator::CreateIterResultObject(thread, valueHandle, false).GetTaggedValue();
}
JSHandle<JSTaggedValue> keyAndValue(thread, iter->GetKeyValueResult());
JSHandle<JSTaggedValue> zeroHandle(thread, JSTaggedValue(0));
JSHandle<JSTaggedValue> oneHandle(thread, JSTaggedValue(1));
JSArray::FastSetPropertyByValue(thread, keyAndValue, zeroHandle, keyHandle);
JSArray::FastSetPropertyByValue(thread, keyAndValue, oneHandle, valueHandle);
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
JSHandle<TaggedArray> array = factory->NewTaggedArray(2); // 2 means the length of array
array->Set(thread, 0, keyHandle);
array->Set(thread, 1, valueHandle);
JSHandle<JSTaggedValue> keyAndValue(JSArray::CreateArrayFromList(thread, array));
return JSIterator::CreateIterResultObject(thread, keyAndValue, false).GetTaggedValue();
}
index++;

View File

@ -41,8 +41,7 @@ public:
static constexpr size_t ITERATED_HASHMAP_OFFSET = JSObject::SIZE;
ACCESSORS(IteratedHashMap, ITERATED_HASHMAP_OFFSET, TAGGED_QUEUE_OFFSET);
ACCESSORS(TaggedQueue, TAGGED_QUEUE_OFFSET, KEY_VALUE_RESULT_OFFSET);
ACCESSORS(KeyValueResult, KEY_VALUE_RESULT_OFFSET, CURRENT_NODE_RESULT);
ACCESSORS(TaggedQueue, TAGGED_QUEUE_OFFSET, CURRENT_NODE_RESULT);
ACCESSORS(CurrentNodeResult, CURRENT_NODE_RESULT, NEXT_INDEX_OFFSET);
ACCESSORS_PRIMITIVE_FIELD(NextIndex, uint32_t, NEXT_INDEX_OFFSET, BIT_FIELD_OFFSET)
ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET)

View File

@ -63,12 +63,11 @@ JSTaggedValue JSAPIHashSetIterator::Next(EcmaRuntimeCallInfo *argv)
if (itemKind == IterationKind::VALUE) {
return JSIterator::CreateIterResultObject(thread, valueHandle, false).GetTaggedValue();
}
JSHandle<JSTaggedValue> keyAndValue(thread, iter->GetKeyValueResult());
JSHandle<JSTaggedValue> keyHandle(thread, JSTaggedValue(--index));
JSHandle<JSTaggedValue> zeroHandle(thread, JSTaggedValue(0));
JSHandle<JSTaggedValue> oneHandle(thread, JSTaggedValue(1));
JSArray::FastSetPropertyByValue(thread, keyAndValue, zeroHandle, keyHandle);
JSArray::FastSetPropertyByValue(thread, keyAndValue, oneHandle, valueHandle);
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
JSHandle<TaggedArray> array = factory->NewTaggedArray(2); // 2 means the length of array
array->Set(thread, 0, JSTaggedValue(--index));
array->Set(thread, 1, valueHandle);
JSHandle<JSTaggedValue> keyAndValue(JSArray::CreateArrayFromList(thread, array));
return JSIterator::CreateIterResultObject(thread, keyAndValue, false).GetTaggedValue();
}
tableIndex++;

View File

@ -40,8 +40,7 @@ public:
static constexpr size_t ITERATED_HASHSET_OFFSET = JSObject::SIZE;
ACCESSORS(IteratedHashSet, ITERATED_HASHSET_OFFSET, TAGGED_QUEUE_OFFSET);
ACCESSORS(TaggedQueue, TAGGED_QUEUE_OFFSET, KEY_VALUE_RESULT_OFFSET);
ACCESSORS(KeyValueResult, KEY_VALUE_RESULT_OFFSET, CURRENT_NODE_RESULT);
ACCESSORS(TaggedQueue, TAGGED_QUEUE_OFFSET, CURRENT_NODE_RESULT);
ACCESSORS(CurrentNodeResult, CURRENT_NODE_RESULT, NEXT_INDEX_OFFSET);
ACCESSORS_PRIMITIVE_FIELD(NextIndex, uint32_t, NEXT_INDEX_OFFSET, TABLE_INDEX_OFFSET)
ACCESSORS_PRIMITIVE_FIELD(TableIndex, uint32_t, TABLE_INDEX_OFFSET, BIT_FIELD_OFFSET)

View File

@ -64,12 +64,11 @@ JSTaggedValue JSAPILightWeightMapIterator::Next(EcmaRuntimeCallInfo *argv)
if (itemKind == IterationKind::VALUE) {
return JSIterator::CreateIterResultObject(thread, value, false).GetTaggedValue();
}
JSHandle<JSTaggedValue> keyAndValue(thread, iter->GetKeyValueResult());
JSHandle<JSTaggedValue> zeroHandle(thread, JSTaggedValue(0));
JSHandle<JSTaggedValue> oneHandle(thread, JSTaggedValue(1));
JSArray::FastSetPropertyByValue(thread, keyAndValue, zeroHandle, key);
JSArray::FastSetPropertyByValue(thread, keyAndValue, oneHandle, value);
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
JSHandle<TaggedArray> array = factory->NewTaggedArray(2); // 2 means the length of array
array->Set(thread, 0, key);
array->Set(thread, 1, value);
JSHandle<JSTaggedValue> keyAndValue(JSArray::CreateArrayFromList(thread, array));
return JSIterator::CreateIterResultObject(thread, keyAndValue, false).GetTaggedValue();
}

View File

@ -33,8 +33,7 @@ public:
static JSTaggedValue Next(EcmaRuntimeCallInfo *argv);
static constexpr size_t ITERATED_LIGHT_WEIGHT_MAP_OFFSET = JSObject::SIZE;
ACCESSORS(IteratedLightWeightMap, ITERATED_LIGHT_WEIGHT_MAP_OFFSET, KEY_VALUE_RESULT_OFFSET);
ACCESSORS(KeyValueResult, KEY_VALUE_RESULT_OFFSET, NEXT_INDEX_OFFSET);
ACCESSORS(IteratedLightWeightMap, ITERATED_LIGHT_WEIGHT_MAP_OFFSET, NEXT_INDEX_OFFSET);
ACCESSORS_PRIMITIVE_FIELD(NextIndex, int32_t, NEXT_INDEX_OFFSET, BIT_FIELD_OFFSET)
ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET)
DEFINE_ALIGN_SIZE(LAST_OFFSET);

View File

@ -66,13 +66,11 @@ JSTaggedValue JSAPILightWeightSetIterator::Next(EcmaRuntimeCallInfo *argv)
TaggedArray *hashArray =
TaggedArray::Cast(JSHandle<JSAPILightWeightSet>(lightWeightSet)->GetHashes().GetTaggedObject());
JSHandle<JSTaggedValue> keyHandle(thread, hashArray->Get(index));
JSHandle<JSTaggedValue> keyAndValue(thread, iter->GetKeyValueResult());
JSHandle<JSTaggedValue> zeroHandle(thread, JSTaggedValue(0));
JSHandle<JSTaggedValue> oneHandle(thread, JSTaggedValue(1));
JSArray::FastSetPropertyByValue(thread, keyAndValue, zeroHandle, keyHandle);
JSArray::FastSetPropertyByValue(thread, keyAndValue, oneHandle, value);
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
JSHandle<TaggedArray> array = factory->NewTaggedArray(2); // 2 means the length of array
array->Set(thread, 0, keyHandle);
array->Set(thread, 1, value);
JSHandle<JSTaggedValue> keyAndValue(JSArray::CreateArrayFromList(thread, array));
return JSIterator::CreateIterResultObject(thread, keyAndValue, false).GetTaggedValue();
}
} // namespace panda::ecmascript

View File

@ -29,8 +29,7 @@ public:
}
static JSTaggedValue Next(EcmaRuntimeCallInfo *argv);
static constexpr size_t ITERATED_LIGHT_WEIGHT_SET_OFFSET = JSObject::SIZE;
ACCESSORS(IteratedLightWeightSet, ITERATED_LIGHT_WEIGHT_SET_OFFSET, KEY_VALUE_RESULT_OFFSET);
ACCESSORS(KeyValueResult, KEY_VALUE_RESULT_OFFSET, NEXT_INDEX_OFFSET);
ACCESSORS(IteratedLightWeightSet, ITERATED_LIGHT_WEIGHT_SET_OFFSET, NEXT_INDEX_OFFSET);
ACCESSORS_PRIMITIVE_FIELD(NextIndex, uint32_t, NEXT_INDEX_OFFSET, BIT_FIELD_OFFSET)
ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET)
DEFINE_ALIGN_SIZE(LAST_OFFSET);

View File

@ -55,7 +55,10 @@ JSTaggedValue JSAPILinkedListIterator::Next(EcmaRuntimeCallInfo *argv)
return globalConst->GetUndefinedIterResult();
}
iter->SetNextIndex(index + 1);
JSHandle<JSTaggedValue> value(thread, list->Get(index));
int dataIndex = static_cast<int>(iter->GetDataIndex());
std::pair<int, JSTaggedValue> resultPair = list->GetByDataIndex(dataIndex);
iter->SetDataIndex(resultPair.first);
JSHandle<JSTaggedValue> value(thread, resultPair.second);
return JSIterator::CreateIterResultObject(thread, value, false).GetTaggedValue();
}

View File

@ -30,11 +30,12 @@ public:
static JSTaggedValue Next(EcmaRuntimeCallInfo *argv);
static JSHandle<JSTaggedValue> CreateLinkedListIterator(JSThread *thread, JSHandle<JSTaggedValue> &obj);
static constexpr size_t ITERATED_LINKED_LIST_OFFSET = JSObject::SIZE;
ACCESSORS(IteratedLinkedList, ITERATED_LINKED_LIST_OFFSET, NEXT_INDEX_OFFSET);
ACCESSORS(IteratedLinkedList, ITERATED_LINKED_LIST_OFFSET, DATA_INDEX_OFFSET);
ACCESSORS_PRIMITIVE_FIELD(DataIndex, uint32_t, DATA_INDEX_OFFSET, NEXT_INDEX_OFFSET)
ACCESSORS_PRIMITIVE_FIELD(NextIndex, uint32_t, NEXT_INDEX_OFFSET, LAST_OFFSET)
DEFINE_ALIGN_SIZE(LAST_OFFSET);
DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, ITERATED_LINKED_LIST_OFFSET, NEXT_INDEX_OFFSET)
DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, ITERATED_LINKED_LIST_OFFSET, DATA_INDEX_OFFSET)
DECL_DUMP()
};

View File

@ -54,7 +54,10 @@ JSTaggedValue JSAPIListIterator::Next(EcmaRuntimeCallInfo *argv)
return globalConst->GetUndefinedIterResult();
}
iter->SetNextIndex(index + 1);
JSHandle<JSTaggedValue> value(thread, singleList->Get(index));
int dataIndex = static_cast<int>(iter->GetDataIndex());
std::pair<int, JSTaggedValue> resultPair = singleList->GetByDataIndex(dataIndex);
iter->SetDataIndex(resultPair.first);
JSHandle<JSTaggedValue> value(thread, resultPair.second);
return JSIterator::CreateIterResultObject(thread, value, false).GetTaggedValue();
}

View File

@ -30,11 +30,12 @@ public:
static JSTaggedValue Next(EcmaRuntimeCallInfo *argv);
static JSHandle<JSTaggedValue> CreateListIterator(JSThread *thread, JSHandle<JSTaggedValue> &obj);
static constexpr size_t ITERATED_LIST_OFFSET = JSObject::SIZE;
ACCESSORS(IteratedList, ITERATED_LIST_OFFSET, NEXT_INDEX_OFFSET);
ACCESSORS(IteratedList, ITERATED_LIST_OFFSET, DATA_INDEX_OFFSET);
ACCESSORS_PRIMITIVE_FIELD(DataIndex, uint32_t, DATA_INDEX_OFFSET, NEXT_INDEX_OFFSET)
ACCESSORS_PRIMITIVE_FIELD(NextIndex, uint32_t, NEXT_INDEX_OFFSET, LAST_OFFSET)
DEFINE_ALIGN_SIZE(LAST_OFFSET);
DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, ITERATED_LIST_OFFSET, NEXT_INDEX_OFFSET)
DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, ITERATED_LIST_OFFSET, DATA_INDEX_OFFSET)
DECL_DUMP()
};

View File

@ -75,13 +75,11 @@ JSTaggedValue JSAPITreeMapIterator::Next(EcmaRuntimeCallInfo *argv)
if (itemKind == IterationKind::VALUE) {
return JSIterator::CreateIterResultObject(thread, value, false).GetTaggedValue();
}
JSHandle<JSTaggedValue> keyAndValue(thread, iter->GetKeyValueResult());
JSHandle<JSTaggedValue> zeroHandle(thread, JSTaggedValue(0));
JSHandle<JSTaggedValue> oneHandle(thread, JSTaggedValue(1));
JSArray::FastSetPropertyByValue(thread, keyAndValue, zeroHandle, key);
JSArray::FastSetPropertyByValue(thread, keyAndValue, oneHandle, value);
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
JSHandle<TaggedArray> array = factory->NewTaggedArray(2); // 2 means the length of array
array->Set(thread, 0, key);
array->Set(thread, 1, value);
JSHandle<JSTaggedValue> keyAndValue(JSArray::CreateArrayFromList(thread, array));
return JSIterator::CreateIterResultObject(thread, keyAndValue, false).GetTaggedValue();
}

View File

@ -38,8 +38,7 @@ public:
static constexpr size_t ITERATED_MAP_OFFSET = JSObject::SIZE;
ACCESSORS(IteratedMap, ITERATED_MAP_OFFSET, ITERATED_ENTRIES_OFFSET);
ACCESSORS(Entries, ITERATED_ENTRIES_OFFSET, KEY_VALUE_RESULT_OFFSET);
ACCESSORS(KeyValueResult, KEY_VALUE_RESULT_OFFSET, NEXT_INDEX_OFFSET);
ACCESSORS(Entries, ITERATED_ENTRIES_OFFSET, NEXT_INDEX_OFFSET);
ACCESSORS_PRIMITIVE_FIELD(NextIndex, uint32_t, NEXT_INDEX_OFFSET, BIT_FIELD_OFFSET)
ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET)
DEFINE_ALIGN_SIZE(LAST_OFFSET);

View File

@ -70,11 +70,11 @@ JSTaggedValue JSAPITreeSetIterator::Next(EcmaRuntimeCallInfo *argv)
if (itemKind == IterationKind::VALUE || itemKind == IterationKind::KEY) {
return JSIterator::CreateIterResultObject(thread, key, false).GetTaggedValue();
}
JSHandle<JSTaggedValue> keyAndValue(thread, iter->GetKeyValueResult());
JSHandle<JSTaggedValue> zeroHandle(thread, JSTaggedValue(0));
JSHandle<JSTaggedValue> oneHandle(thread, JSTaggedValue(1));
JSArray::FastSetPropertyByValue(thread, keyAndValue, zeroHandle, key);
JSArray::FastSetPropertyByValue(thread, keyAndValue, oneHandle, key);
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
JSHandle<TaggedArray> array = factory->NewTaggedArray(2); // 2 means the length of array
array->Set(thread, 0, key);
array->Set(thread, 1, key);
JSHandle<JSTaggedValue> keyAndValue(JSArray::CreateArrayFromList(thread, array));
return JSIterator::CreateIterResultObject(thread, keyAndValue, false).GetTaggedValue();
}

View File

@ -38,8 +38,7 @@ public:
static constexpr size_t ITERATED_SET_OFFSET = JSObject::SIZE;
ACCESSORS(IteratedSet, ITERATED_SET_OFFSET, ITERATED_ENTRIES_OFFSET);
ACCESSORS(Entries, ITERATED_ENTRIES_OFFSET, KEY_VALUE_RESULT_OFFSET);
ACCESSORS(KeyValueResult, KEY_VALUE_RESULT_OFFSET, NEXT_INDEX_OFFSET);
ACCESSORS(Entries, ITERATED_ENTRIES_OFFSET, NEXT_INDEX_OFFSET);
ACCESSORS_PRIMITIVE_FIELD(NextIndex, uint32_t, NEXT_INDEX_OFFSET, BIT_FIELD_OFFSET)
ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET)
DEFINE_ALIGN_SIZE(LAST_OFFSET);

View File

@ -2518,16 +2518,11 @@ JSHandle<JSAPIHashMapIterator> ObjectFactory::NewJSAPIHashMapIterator(const JSHa
NewObjectHook();
const GlobalEnvConstants *globalConst = thread_->GlobalConstants();
JSHandle<JSTaggedValue> undefinedHandle = globalConst->GetHandledUndefined();
JSHandle<TaggedArray> array = NewTaggedArray(2); // 2 means the length of array
array->Set(thread_, 0, undefinedHandle);
array->Set(thread_, 1, undefinedHandle);
JSHandle<JSTaggedValue> keyAndValue(JSArray::CreateArrayFromList(thread_, array));
JSHandle<JSTaggedValue> proto(thread_, globalConst->GetHashMapIteratorPrototype());
JSHandle<JSHClass> hclassHandle(globalConst->GetHandledJSAPIHashMapIteratorClass());
hclassHandle->SetPrototype(thread_, proto);
JSHandle<JSAPIHashMapIterator> iter(NewJSObject(hclassHandle));
iter->GetJSHClass()->SetExtensible(true);
iter->SetKeyValueResult(thread_, keyAndValue);
iter->SetCurrentNodeResult(thread_, undefinedHandle);
iter->SetIteratedHashMap(thread_, hashMap);
iter->SetNextIndex(0);
@ -2544,16 +2539,11 @@ JSHandle<JSAPIHashSetIterator> ObjectFactory::NewJSAPIHashSetIterator(const JSHa
NewObjectHook();
const GlobalEnvConstants *globalConst = thread_->GlobalConstants();
JSHandle<JSTaggedValue> undefinedHandle = globalConst->GetHandledUndefined();
JSHandle<TaggedArray> array = NewTaggedArray(2); // 2 means the length of array
array->Set(thread_, 0, undefinedHandle);
array->Set(thread_, 1, undefinedHandle);
JSHandle<JSTaggedValue> keyAndValue(JSArray::CreateArrayFromList(thread_, array));
JSHandle<JSTaggedValue> proto(thread_, globalConst->GetHashSetIteratorPrototype());
JSHandle<JSHClass> hclassHandle(globalConst->GetHandledJSAPIHashSetIteratorClass());
hclassHandle->SetPrototype(thread_, proto);
JSHandle<JSAPIHashSetIterator> iter(NewJSObject(hclassHandle));
iter->GetJSHClass()->SetExtensible(true);
iter->SetKeyValueResult(thread_, keyAndValue);
iter->SetCurrentNodeResult(thread_, undefinedHandle);
iter->SetIteratedHashSet(thread_, hashSet);
iter->SetNextIndex(0);
@ -3296,17 +3286,11 @@ JSHandle<JSAPILightWeightMapIterator> ObjectFactory::NewJSAPILightWeightMapItera
{
NewObjectHook();
const GlobalEnvConstants *globalConst = thread_->GlobalConstants();
JSHandle<JSTaggedValue> undefinedHandle = globalConst->GetHandledUndefined();
JSHandle<TaggedArray> array = NewTaggedArray(2); // 2 means the length of array
array->Set(thread_, 0, undefinedHandle);
array->Set(thread_, 1, undefinedHandle);
JSHandle<JSTaggedValue> keyAndValue(JSArray::CreateArrayFromList(thread_, array));
JSHandle<JSTaggedValue> protoValue(thread_, globalConst->GetLightWeightMapIteratorPrototype());
JSHandle<JSHClass> hclassHandle(globalConst->GetHandledJSAPILightWeightMapIteratorClass());
hclassHandle->SetPrototype(thread_, protoValue);
JSHandle<JSAPILightWeightMapIterator> iter(NewJSObject(hclassHandle));
iter->GetJSHClass()->SetExtensible(true);
iter->SetKeyValueResult(thread_, keyAndValue);
iter->SetIteratedLightWeightMap(thread_, obj);
iter->SetNextIndex(0);
iter->SetIterationKind(kind);
@ -3318,17 +3302,11 @@ JSHandle<JSAPILightWeightSetIterator> ObjectFactory::NewJSAPILightWeightSetItera
{
NewObjectHook();
const GlobalEnvConstants *globalConst = thread_->GlobalConstants();
JSHandle<JSTaggedValue> undefinedHandle = globalConst->GetHandledUndefined();
JSHandle<TaggedArray> array = NewTaggedArray(2); // 2 means the length of array
array->Set(thread_, 0, undefinedHandle);
array->Set(thread_, 1, undefinedHandle);
JSHandle<JSTaggedValue> keyAndValue(JSArray::CreateArrayFromList(thread_, array));
JSHandle<JSTaggedValue> protoValue(thread_, globalConst->GetLightWeightSetIteratorPrototype());
JSHandle<JSHClass> hclassHandle(globalConst->GetHandledJSAPILightWeightSetIteratorClass());
hclassHandle->SetPrototype(thread_, protoValue);
JSHandle<JSAPILightWeightSetIterator> iter(NewJSObject(hclassHandle));
iter->GetJSHClass()->SetExtensible(true);
iter->SetKeyValueResult(thread_, keyAndValue);
iter->SetIteratedLightWeightSet(thread_, obj);
iter->SetNextIndex(0);
iter->SetIterationKind(kind);
@ -3460,17 +3438,11 @@ JSHandle<JSAPITreeMapIterator> ObjectFactory::NewJSAPITreeMapIterator(const JSHa
{
NewObjectHook();
const GlobalEnvConstants *globalConst = thread_->GlobalConstants();
JSHandle<JSTaggedValue> undefinedHandle = globalConst->GetHandledUndefined();
JSHandle<TaggedArray> array = NewTaggedArray(2); // 2 means the length of array
array->Set(thread_, 0, undefinedHandle);
array->Set(thread_, 1, undefinedHandle);
JSHandle<JSTaggedValue> keyAndValue(JSArray::CreateArrayFromList(thread_, array));
JSHandle<JSTaggedValue> proto(thread_, globalConst->GetTreeMapIteratorPrototype());
JSHandle<JSHClass> hclassHandle(globalConst->GetHandledJSAPITreeMapIteratorClass());
hclassHandle->SetPrototype(thread_, proto);
JSHandle<JSAPITreeMapIterator> iter(NewJSObject(hclassHandle));
iter->GetJSHClass()->SetExtensible(true);
iter->SetKeyValueResult(thread_, keyAndValue);
iter->SetIteratedMap(thread_, map);
iter->SetNextIndex(0);
iter->SetEntries(thread_, JSTaggedValue::Hole());
@ -3483,17 +3455,11 @@ JSHandle<JSAPITreeSetIterator> ObjectFactory::NewJSAPITreeSetIterator(const JSHa
{
NewObjectHook();
const GlobalEnvConstants *globalConst = thread_->GlobalConstants();
JSHandle<JSTaggedValue> undefinedHandle = globalConst->GetHandledUndefined();
JSHandle<TaggedArray> array = NewTaggedArray(2); // 2 means the length of array
array->Set(thread_, 0, undefinedHandle);
array->Set(thread_, 1, undefinedHandle);
JSHandle<JSTaggedValue> keyAndValue(JSArray::CreateArrayFromList(thread_, array));
JSHandle<JSTaggedValue> proto(thread_, globalConst->GetTreeSetIteratorPrototype());
JSHandle<JSHClass> hclassHandle(globalConst->GetHandledJSAPITreeSetIteratorClass());
hclassHandle->SetPrototype(thread_, proto);
JSHandle<JSAPITreeSetIterator> iter(NewJSObject(hclassHandle));
iter->GetJSHClass()->SetExtensible(true);
iter->SetKeyValueResult(thread_, keyAndValue);
iter->SetIteratedSet(thread_, set);
iter->SetNextIndex(0);
iter->SetEntries(thread_, JSTaggedValue::Hole());
@ -3537,6 +3503,8 @@ JSHandle<JSAPILinkedListIterator> ObjectFactory::NewJSAPILinkedListIterator(cons
iter->GetJSHClass()->SetExtensible(true);
iter->SetIteratedLinkedList(thread_, linkedList->GetDoubleList());
iter->SetNextIndex(0);
const uint32_t linkedListElementStartIndex = 4;
iter->SetDataIndex(linkedListElementStartIndex);
return iter;
}
@ -3551,6 +3519,8 @@ JSHandle<JSAPIListIterator> ObjectFactory::NewJSAPIListIterator(const JSHandle<J
iter->GetJSHClass()->SetExtensible(true);
iter->SetIteratedList(thread_, List->GetSingleList());
iter->SetNextIndex(0);
const uint32_t linkedListElementStartIndex = 4;
iter->SetDataIndex(linkedListElementStartIndex);
return iter;
}

View File

@ -278,6 +278,21 @@ JSTaggedValue TaggedList<Derived>::FindElementByIndex(int index) const
return JSTaggedValue::Undefined();
}
template<typename Derived>
std::pair<int, JSTaggedValue> TaggedList<Derived>::FindElementByDataIndex(int dataindex) const
{
int targetDataIndex = GetElement(dataindex + NEXT_PTR_OFFSET).GetInt();
JSTaggedValue value = GetElement(targetDataIndex);
while (value.IsHole() && targetDataIndex != ELEMENTS_START_INDEX) {
targetDataIndex = GetElement(targetDataIndex + NEXT_PTR_OFFSET).GetInt();
value = GetElement(targetDataIndex);
}
if (targetDataIndex == ELEMENTS_START_INDEX) {
return std::make_pair(-1, JSTaggedValue::Undefined());
}
return std::make_pair(targetDataIndex, value);
}
template<typename Derived>
JSTaggedValue TaggedList<Derived>::RemoveByIndex(JSThread *thread, const int &index)
{
@ -341,6 +356,11 @@ JSTaggedValue TaggedSingleList::Get(const int index)
return FindElementByIndex(index);
}
std::pair<int, JSTaggedValue> TaggedSingleList::GetByDataIndex(const int dataIndex)
{
return FindElementByDataIndex(dataIndex);
}
int TaggedSingleList::GetIndexOf(const JSTaggedValue &element)
{
return FindIndexByElement(element);
@ -579,6 +599,11 @@ JSTaggedValue TaggedDoubleList::Get(const int index)
}
}
std::pair<int, JSTaggedValue> TaggedDoubleList::GetByDataIndex(const int dataIndex)
{
return FindElementByDataIndex(dataIndex);
}
int TaggedDoubleList::GetIndexOf(const JSTaggedValue &element)
{
return FindIndexByElement(element);

View File

@ -44,6 +44,7 @@ public:
void CopyArray(const JSThread *thread, JSHandle<Derived> &taggedList);
void Clear(const JSThread *thread);
JSTaggedValue FindElementByIndex(int index) const;
std::pair<int, JSTaggedValue> FindElementByDataIndex(int dataindex) const;
int FindIndexByElement(const JSTaggedValue &element);
int FindLastIndexByElement(const JSTaggedValue &element);
int FindDataIndexByNodeIndex(int index) const;
@ -140,6 +141,7 @@ public:
bool IsEmpty() const;
bool Has(const JSTaggedValue &value);
JSTaggedValue Get(const int index);
std::pair<int, JSTaggedValue> GetByDataIndex(const int dataIndex);
int GetIndexOf(const JSTaggedValue &value);
int GetLastIndexOf(const JSTaggedValue &value);
void InsertNode(const JSThread *thread, const JSHandle<JSTaggedValue> &value, const int prevDataIndex,
@ -175,6 +177,7 @@ public:
const JSTaggedValue &element);
void Clear(const JSThread *thread);
JSTaggedValue Get(const int index);
std::pair<int, JSTaggedValue> GetByDataIndex(const int dataIndex);
bool Has(const JSTaggedValue &value);
void InsertNode(const JSThread *thread, const JSHandle<JSTaggedValue> &value, const int prevDataIndex,
const int finalDataIndex);

View File

@ -1033,7 +1033,7 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump)
break;
}
case JSType::JS_API_HASHMAP_ITERATOR: {
CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIHashMapIterator::SIZE, 5U);
CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIHashMapIterator::SIZE, 4U);
JSHandle<JSAPIHashMap> jsHashMap = NewJSAPIHashMap(thread, factory);
JSHandle<JSAPIHashMapIterator> jsHashMapIter =
factory->NewJSAPIHashMapIterator(jsHashMap, IterationKind::KEY);
@ -1041,7 +1041,7 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump)
break;
}
case JSType::JS_API_HASHSET_ITERATOR: {
CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIHashSetIterator::SIZE, 6U);
CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIHashSetIterator::SIZE, 5U);
JSHandle<JSAPIHashSet> jsHashSet = NewJSAPIHashSet(thread, factory);
JSHandle<JSAPIHashSetIterator> jsHashSetIter =
factory->NewJSAPIHashSetIterator(jsHashSet, IterationKind::KEY);
@ -1055,7 +1055,7 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump)
break;
}
case JSType::JS_API_LIGHT_WEIGHT_MAP_ITERATOR: {
CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPILightWeightMapIterator::SIZE, 3U);
CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPILightWeightMapIterator::SIZE, 2U);
JSHandle<JSAPILightWeightMap> jSAPILightWeightMap = NewJSAPILightWeightMap(thread, factory);
JSHandle<JSAPILightWeightMapIterator> jSAPILightWeightMapIterator =
factory->NewJSAPILightWeightMapIterator(jSAPILightWeightMap, IterationKind::KEY);
@ -1069,7 +1069,7 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump)
break;
}
case JSType::JS_API_LIGHT_WEIGHT_SET_ITERATOR: {
CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPILightWeightSetIterator::SIZE, 3U);
CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPILightWeightSetIterator::SIZE, 2U);
JSHandle<JSAPILightWeightSetIterator> jSAPILightWeightSetIter =
factory->NewJSAPILightWeightSetIterator(NewJSAPILightWeightSet(thread, factory),
IterationKind::KEY);
@ -1122,7 +1122,7 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump)
}
case JSType::JS_API_TREEMAP_ITERATOR: {
// 3 : 3 dump fileds number
CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPITreeMapIterator::SIZE, 4U);
CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPITreeMapIterator::SIZE, 3U);
JSHandle<JSAPITreeMap> jsTreeMap = NewJSAPITreeMap(thread, factory);
JSHandle<JSAPITreeMapIterator> jsTreeMapIter =
factory->NewJSAPITreeMapIterator(jsTreeMap, IterationKind::KEY);
@ -1131,7 +1131,7 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump)
}
case JSType::JS_API_TREESET_ITERATOR: {
// 3 : 3 dump fileds number
CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPITreeSetIterator::SIZE, 4U);
CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPITreeSetIterator::SIZE, 3U);
JSHandle<JSAPITreeSet> jsTreeSet = NewJSAPITreeSet(thread, factory);
JSHandle<JSAPITreeSetIterator> jsTreeSetIter =
factory->NewJSAPITreeSetIterator(jsTreeSet, IterationKind::KEY);