fix array's dictionary assert prob

Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IALUWW
Signed-off-by: zhangtianqi <zhangtianqi3@huawei.com>
Change-Id: I2ec70fb15995ffdc66feb08390ba9ed310a0c7f5
This commit is contained in:
zhangtianqi 2024-08-22 18:39:55 +08:00
parent f972d1e20e
commit bb91bf679d
3 changed files with 6 additions and 4 deletions

View File

@ -365,15 +365,17 @@ inline bool JSObject::ShouldTransToDict(uint32_t capacity, uint32_t index)
return false;
}
inline bool JSObject::ShouldTransToFastElements(JSHandle<NumberDictionary> dictionary,
inline bool JSObject::ShouldTransToFastElements(JSThread *thread, TaggedArray *elements,
uint32_t capacity, uint32_t index)
{
JSHandle<NumberDictionary> dictionary(thread, elements);
if (index >= static_cast<uint32_t>(INT32_MAX)) {
return false;
}
uint32_t dictionarySize = static_cast<uint32_t>(dictionary->GetLength());
// Turn fast if only saves 50% space.
if (dictionarySize * SHOULD_TRANS_TO_FAST_ELEMENTS_FACTOR >= capacity) {
if (dictionarySize * SHOULD_TRANS_TO_FAST_ELEMENTS_FACTOR >= capacity ||
dictionary->NextEnumerationIndex(thread) > PropertyAttributes::DictionaryOrderField::MaxValue()) {
return true;
}
return false;

View File

@ -431,7 +431,7 @@ bool JSObject::AddElementInternal(JSThread *thread, const JSHandle<JSObject> &re
uint32_t capacity = arr->GetArrayLength();
TaggedArray *elements = TaggedArray::Cast(receiver->GetElements().GetTaggedObject());
ASSERT(elements->IsDictionaryMode());
if (ShouldTransToFastElements(JSHandle<NumberDictionary>(thread, elements), capacity, index)) {
if (ShouldTransToFastElements(thread, elements, capacity, index)) {
JSObject::TryOptimizeAsFastElements(thread, receiver);
}
}

View File

@ -742,7 +742,7 @@ public:
static bool IsArrayLengthWritable(JSThread *thread, const JSHandle<JSObject> &receiver);
bool UpdatePropertyInDictionary(const JSThread *thread, JSTaggedValue key, JSTaggedValue value);
static bool ShouldTransToDict(uint32_t capacity, uint32_t index);
static bool ShouldTransToFastElements(JSHandle<NumberDictionary> dictionary, uint32_t capacity, uint32_t index);
static bool ShouldTransToFastElements(JSThread *thread, TaggedArray *elements, uint32_t capacity, uint32_t index);
static bool ShouldOptimizeAsFastElements(const JSThread *thread, JSHandle<JSObject> obj);
static JSHandle<TaggedArray> GrowElementsCapacity(const JSThread *thread, const JSHandle<JSObject> &obj,
uint32_t capacity, bool highGrowth = false, bool isNew = false);