mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-10-06 23:54:03 +00:00
!7361 超大函数整改:JSTaggedValue JSStableArray::Splice
Merge pull request !7361 from 马志伟/master
This commit is contained in:
commit
f74723b03e
@ -150,67 +150,40 @@ JSTaggedValue JSStableArray::Pop(JSHandle<JSArray> receiver, EcmaRuntimeCallInfo
|
||||
return result->IsHole() ? JSTaggedValue::Undefined() : result.GetTaggedValue();
|
||||
}
|
||||
|
||||
JSTaggedValue JSStableArray::Splice(JSHandle<JSArray> receiver, EcmaRuntimeCallInfo *argv,
|
||||
uint32_t start, uint32_t insertCount, uint32_t actualDeleteCount,
|
||||
JSHandle<JSObject> newArrayHandle, uint32_t len)
|
||||
void JSStableArray::HandleArray(JSHandle<JSObject> &newArrayHandle, uint32_t &actualDeleteCount,
|
||||
JSThread *thread, uint32_t &start, JSHandle<JSObject> &thisObjHandle,
|
||||
JSHandle<JSTaggedValue> &holeHandle)
|
||||
{
|
||||
JSThread *thread = argv->GetThread();
|
||||
uint32_t argc = argv->GetArgsNumber();
|
||||
|
||||
JSHandle<JSTaggedValue> holeHandle(thread, JSTaggedValue::Hole());
|
||||
JSHandle<JSObject> thisObjHandle(receiver);
|
||||
JSHandle<JSTaggedValue> thisObjVal(thisObjHandle);
|
||||
JSArray::CheckAndCopyArray(thread, receiver);
|
||||
JSHandle<JSTaggedValue> lengthKey = thread->GlobalConstants()->GetHandledLengthString();
|
||||
TaggedArray *srcElements = TaggedArray::Cast(thisObjHandle->GetElements().GetTaggedObject());
|
||||
JSMutableHandle<TaggedArray> srcElementsHandle(thread, srcElements);
|
||||
bool needTransition = true;
|
||||
if (newArrayHandle.GetTaggedValue().IsStableJSArray(thread)) {
|
||||
TaggedArray *destElements = TaggedArray::Cast(newArrayHandle->GetElements().GetTaggedObject());
|
||||
TaggedArray *destElements = TaggedArray::Cast(newArrayHandle->GetElements().GetTaggedObject());
|
||||
if (actualDeleteCount > ElementAccessor::GetElementsLength(newArrayHandle)) {
|
||||
destElements = *JSObject::GrowElementsCapacity(thread, newArrayHandle, actualDeleteCount);
|
||||
}
|
||||
|
||||
for (uint32_t idx = 0; idx < actualDeleteCount; idx++) {
|
||||
if ((start + idx) >= ElementAccessor::GetElementsLength(thisObjHandle)) {
|
||||
ElementAccessor::Set(thread, newArrayHandle, idx, holeHandle, needTransition);
|
||||
ElementAccessor::Set(thread, newArrayHandle, idx, holeHandle, true);
|
||||
} else {
|
||||
JSHandle<JSTaggedValue> valueHandle(thread, ElementAccessor::Get(thisObjHandle, start + idx));
|
||||
ElementAccessor::Set(thread, newArrayHandle, idx, valueHandle, needTransition);
|
||||
ElementAccessor::Set(thread, newArrayHandle, idx, valueHandle, true);
|
||||
}
|
||||
}
|
||||
JSHandle<JSArray>::Cast(newArrayHandle)->SetArrayLength(thread, actualDeleteCount);
|
||||
} else {
|
||||
JSMutableHandle<JSTaggedValue> fromKey(thread, JSTaggedValue::Undefined());
|
||||
JSMutableHandle<JSTaggedValue> toKey(thread, JSTaggedValue::Undefined());
|
||||
uint32_t k = 0;
|
||||
while (k < actualDeleteCount) {
|
||||
uint32_t from = start + k;
|
||||
fromKey.Update(JSTaggedValue(from));
|
||||
bool exists = JSTaggedValue::HasProperty(thread, thisObjVal, fromKey);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
if (exists) {
|
||||
JSHandle<JSTaggedValue> fromValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, fromKey);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
toKey.Update(JSTaggedValue(k));
|
||||
if (newArrayHandle->IsJSProxy()) {
|
||||
toKey.Update(JSTaggedValue::ToString(thread, toKey).GetTaggedValue());
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
}
|
||||
JSObject::CreateDataPropertyOrThrow(thread, newArrayHandle, toKey, fromValue);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
}
|
||||
k++;
|
||||
}
|
||||
}
|
||||
|
||||
JSHandle<JSTaggedValue> deleteCount(thread, JSTaggedValue(actualDeleteCount));
|
||||
JSTaggedValue::SetProperty(thread, JSHandle<JSTaggedValue>::Cast(newArrayHandle), lengthKey, deleteCount,
|
||||
true);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
}
|
||||
JSTaggedValue JSStableArray::UpdateArrayCapacity(JSHandle<JSObject> &thisObjHandle, uint32_t &len,
|
||||
uint32_t &insertCount, uint32_t &actualDeleteCount,
|
||||
JSHandle<JSArray> &receiver, uint32_t &start,
|
||||
JSThread *thread, bool &needTransition,
|
||||
JSHandle<JSTaggedValue> &holeHandle,
|
||||
EcmaRuntimeCallInfo *argv, JSHandle<JSTaggedValue> &thisObjVal,
|
||||
JSHandle<JSTaggedValue> &lengthKey)
|
||||
{
|
||||
uint32_t oldCapacity = ElementAccessor::GetElementsLength(thisObjHandle);
|
||||
ASSERT(len + insertCount >= actualDeleteCount);
|
||||
uint32_t newCapacity = len - actualDeleteCount + insertCount;
|
||||
TaggedArray *srcElements = TaggedArray::Cast(thisObjHandle->GetElements().GetTaggedObject());
|
||||
JSMutableHandle<TaggedArray> srcElementsHandle(thread, srcElements);
|
||||
uint32_t argc = argv->GetArgsNumber();
|
||||
if (newCapacity > oldCapacity) {
|
||||
srcElementsHandle.Update(JSObject::GrowElementsCapacity(thread, thisObjHandle, newCapacity));
|
||||
}
|
||||
@ -251,6 +224,54 @@ JSTaggedValue JSStableArray::Splice(JSHandle<JSArray> receiver, EcmaRuntimeCallI
|
||||
JSHandle<JSTaggedValue> newLenHandle(thread, JSTaggedValue(newCapacity));
|
||||
JSTaggedValue::SetProperty(thread, thisObjVal, lengthKey, newLenHandle, true);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
return JSTaggedValue::Undefined();
|
||||
}
|
||||
|
||||
JSTaggedValue JSStableArray::Splice(JSHandle<JSArray> receiver, EcmaRuntimeCallInfo *argv,
|
||||
uint32_t start, uint32_t insertCount, uint32_t actualDeleteCount,
|
||||
JSHandle<JSObject> newArrayHandle, uint32_t len)
|
||||
{
|
||||
JSThread *thread = argv->GetThread();
|
||||
|
||||
JSHandle<JSTaggedValue> holeHandle(thread, JSTaggedValue::Hole());
|
||||
JSHandle<JSObject> thisObjHandle(receiver);
|
||||
JSHandle<JSTaggedValue> thisObjVal(thisObjHandle);
|
||||
JSArray::CheckAndCopyArray(thread, receiver);
|
||||
JSHandle<JSTaggedValue> lengthKey = thread->GlobalConstants()->GetHandledLengthString();
|
||||
bool needTransition = true;
|
||||
if (newArrayHandle.GetTaggedValue().IsStableJSArray(thread)) {
|
||||
HandleArray(newArrayHandle, actualDeleteCount, thread, start, thisObjHandle, holeHandle);
|
||||
} else {
|
||||
JSMutableHandle<JSTaggedValue> fromKey(thread, JSTaggedValue::Undefined());
|
||||
JSMutableHandle<JSTaggedValue> toKey(thread, JSTaggedValue::Undefined());
|
||||
uint32_t k = 0;
|
||||
while (k < actualDeleteCount) {
|
||||
uint32_t from = start + k;
|
||||
fromKey.Update(JSTaggedValue(from));
|
||||
bool exists = JSTaggedValue::HasProperty(thread, thisObjVal, fromKey);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
if (exists) {
|
||||
JSHandle<JSTaggedValue> fromValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, fromKey);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
toKey.Update(JSTaggedValue(k));
|
||||
if (newArrayHandle->IsJSProxy()) {
|
||||
toKey.Update(JSTaggedValue::ToString(thread, toKey).GetTaggedValue());
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
}
|
||||
JSObject::CreateDataPropertyOrThrow(thread, newArrayHandle, toKey, fromValue);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
}
|
||||
k++;
|
||||
}
|
||||
|
||||
JSHandle<JSTaggedValue> deleteCount(thread, JSTaggedValue(actualDeleteCount));
|
||||
JSTaggedValue::SetProperty(thread, JSHandle<JSTaggedValue>::Cast(newArrayHandle), lengthKey, deleteCount,
|
||||
true);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
}
|
||||
UpdateArrayCapacity(thisObjHandle, len, insertCount, actualDeleteCount, receiver, start,
|
||||
thread, needTransition, holeHandle, argv, thisObjVal, lengthKey);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
return newArrayHandle.GetTaggedValue();
|
||||
}
|
||||
|
||||
|
@ -126,6 +126,16 @@ private:
|
||||
static JSTaggedValue IndexOfString(IndexOfType type, IndexOfContext &ctx, JSTaggedValue searchElement);
|
||||
static JSTaggedValue IndexOfBigInt(IndexOfType type, IndexOfContext &ctx, JSTaggedValue searchElement);
|
||||
static JSTaggedValue IndexOfDispatch(IndexOfType type, IndexOfContext &ctx, JSTaggedValue searchElement);
|
||||
static JSTaggedValue UpdateArrayCapacity(JSHandle<JSObject> &thisObjHandle, uint32_t &len,
|
||||
uint32_t &insertCount, uint32_t &actualDeleteCount,
|
||||
JSHandle<JSArray> &receiver, uint32_t &start,
|
||||
JSThread *thread, bool &needTransition,
|
||||
JSHandle<JSTaggedValue> &holeHandle,
|
||||
EcmaRuntimeCallInfo *argv, JSHandle<JSTaggedValue> &thisObjVal,
|
||||
JSHandle<JSTaggedValue> &lengthKey);
|
||||
static void HandleArray(JSHandle<JSObject> &newArrayHandle, uint32_t &actualDeleteCount,
|
||||
JSThread *thread, uint32_t &start, JSHandle<JSObject> &thisObjHandle,
|
||||
JSHandle<JSTaggedValue> &holeHandle);
|
||||
};
|
||||
} // namespace panda::ecmascript
|
||||
#endif // ECMASCRIPT_JS_STABLE_ARRAY_H
|
||||
|
Loading…
Reference in New Issue
Block a user