mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-11-23 10:09:54 +00:00
!10175 SendableArray API filter process based on StableArray
Merge pull request !10175 from 留红尘/ets_runtime/lhc/1108
This commit is contained in:
commit
f755a4c2aa
@ -699,8 +699,8 @@ JSTaggedValue BuiltinsSharedArray::Fill(EcmaRuntimeCallInfo *argv)
|
||||
return thisObjHandle.GetTaggedValue();
|
||||
}
|
||||
|
||||
JSTaggedValue BuiltinsSharedArray::FilterUnStableJSArray(JSThread *thread, JSHandle<JSTaggedValue> &thisArgHandle,
|
||||
JSHandle<JSTaggedValue> &thisObjVal, int64_t k, int64_t len, uint32_t toIndex, JSHandle<JSObject> newArrayHandle,
|
||||
JSTaggedValue BuiltinsSharedArray::FilterArray(JSThread *thread, JSHandle<JSTaggedValue> &thisArgHandle,
|
||||
JSHandle<JSTaggedValue> &thisObjVal, JSHandle<JSObject> newArrayHandle,
|
||||
JSHandle<JSTaggedValue> &callbackFnHandle)
|
||||
{
|
||||
JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
|
||||
@ -708,25 +708,29 @@ JSTaggedValue BuiltinsSharedArray::FilterUnStableJSArray(JSThread *thread, JSHan
|
||||
JSTaggedValue callResult = GetTaggedBoolean(true);
|
||||
JSMutableHandle<JSTaggedValue> key(thread, JSTaggedValue::Undefined());
|
||||
JSMutableHandle<JSTaggedValue> toIndexHandle(thread, JSTaggedValue::Undefined());
|
||||
int64_t k = 0;
|
||||
// 3. Let len be ToLength(Get(O, "length")).
|
||||
uint64_t len = static_cast<uint64_t>(ArrayHelper::GetArrayLength(thread, thisObjVal));
|
||||
// 4. ReturnIfAbrupt(len).
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
uint32_t toIndex = 0;
|
||||
JSHandle<JSObject> thisObjHandle = JSTaggedValue::ToObject(thread, thisObjVal);
|
||||
JSMutableHandle<JSTaggedValue> kValue(thread, JSTaggedValue::Undefined());
|
||||
while (k < len) {
|
||||
bool exists = JSTaggedValue::HasProperty(thread, thisObjVal, k);
|
||||
kValue.Update(BuiltinsSharedArray::GetElementByKey(thread, thisObjHandle, k));
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
if (exists) {
|
||||
JSHandle<JSTaggedValue> kValue = JSSharedArray::FastGetPropertyByValue(thread, thisObjVal, k);
|
||||
key.Update(JSTaggedValue(k));
|
||||
EcmaRuntimeCallInfo *info =
|
||||
EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, undefined, argsLength);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
info->SetCallArg(kValue.GetTaggedValue(), key.GetTaggedValue(), thisObjVal.GetTaggedValue());
|
||||
callResult = JSFunction::Call(info);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
if (callResult.ToBoolean()) {
|
||||
toIndexHandle.Update(JSTaggedValue(toIndex));
|
||||
JSObject::CreateDataPropertyOrThrow(thread, newArrayHandle, toIndexHandle, kValue, SCheckMode::SKIP);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
key.Update(JSTaggedValue(k));
|
||||
EcmaRuntimeCallInfo *info =
|
||||
EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, undefined, argsLength);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
info->SetCallArg(kValue.GetTaggedValue(), key.GetTaggedValue(), thisObjVal.GetTaggedValue());
|
||||
callResult = JSFunction::Call(info);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
if (callResult.ToBoolean()) {
|
||||
toIndexHandle.Update(JSTaggedValue(toIndex));
|
||||
JSObject::CreateDataPropertyOrThrow(thread, newArrayHandle, toIndexHandle, kValue, SCheckMode::SKIP);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
toIndex++;
|
||||
}
|
||||
toIndex++;
|
||||
}
|
||||
k++;
|
||||
}
|
||||
@ -749,12 +753,6 @@ JSTaggedValue BuiltinsSharedArray::Filter(EcmaRuntimeCallInfo *argv)
|
||||
[[maybe_unused]] ConcurrentApiScope<JSSharedArray> scope(thread, thisHandle);
|
||||
// 2. ReturnIfAbrupt(O).
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
JSHandle<JSTaggedValue> thisObjVal(thisObjHandle);
|
||||
|
||||
// 3. Let len be ToLength(Get(O, "length")).
|
||||
uint64_t len = static_cast<uint64_t>(ArrayHelper::GetArrayLength(thread, thisObjVal));
|
||||
// 4. ReturnIfAbrupt(len).
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
|
||||
// 5. If IsCallable(callbackfn) is false, throw a TypeError exception.
|
||||
JSHandle<JSTaggedValue> callbackFnHandle = GetCallArg(argv, 0);
|
||||
@ -766,8 +764,7 @@ JSTaggedValue BuiltinsSharedArray::Filter(EcmaRuntimeCallInfo *argv)
|
||||
JSHandle<JSTaggedValue> thisArgHandle = GetCallArg(argv, 1);
|
||||
|
||||
// 7. Let A be ArraySpeciesCreate(O, 0).
|
||||
int32_t arrayLen = 0;
|
||||
JSTaggedValue newArray = JSSharedArray::ArraySpeciesCreate(thread, thisObjHandle, JSTaggedNumber(arrayLen));
|
||||
JSTaggedValue newArray = JSSharedArray::ArraySpeciesCreate(thread, thisObjHandle, JSTaggedNumber(0));
|
||||
// 8. ReturnIfAbrupt(A).
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
JSHandle<JSObject> newArrayHandle(thread, newArray);
|
||||
@ -788,16 +785,8 @@ JSTaggedValue BuiltinsSharedArray::Filter(EcmaRuntimeCallInfo *argv)
|
||||
// 2. ReturnIfAbrupt(status).
|
||||
// 3. Increase to by 1.
|
||||
// e. Increase k by 1.
|
||||
uint32_t toIndex = 0;
|
||||
JSMutableHandle<JSTaggedValue> key(thread, JSTaggedValue::Undefined());
|
||||
JSMutableHandle<JSTaggedValue> toIndexHandle(thread, JSTaggedValue::Undefined());
|
||||
uint32_t k = 0;
|
||||
if (thisObjVal->IsStableJSArray(thread)) {
|
||||
JSStableArray::Filter(newArrayHandle, thisObjHandle, argv, k, toIndex);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
}
|
||||
auto opResult =
|
||||
FilterUnStableJSArray(thread, thisArgHandle, thisObjVal, k, len, toIndex, newArrayHandle, callbackFnHandle);
|
||||
FilterArray(thread, thisArgHandle, thisHandle, newArrayHandle, callbackFnHandle);
|
||||
|
||||
return opResult;
|
||||
}
|
||||
|
@ -177,9 +177,9 @@ public:
|
||||
JSHandle<JSTaggedValue> &thisObjVal, int64_t k, int64_t len, JSMutableHandle<JSTaggedValue> &accumulator,
|
||||
JSHandle<JSTaggedValue> &callbackFnHandle);
|
||||
|
||||
static JSTaggedValue FilterUnStableJSArray(JSThread *thread, JSHandle<JSTaggedValue> &thisArgHandle,
|
||||
JSHandle<JSTaggedValue> &thisObjVal, int64_t k, int64_t len, uint32_t toIndex,
|
||||
JSHandle<JSObject> newArrayHandle, JSHandle<JSTaggedValue> &callbackFnHandle);
|
||||
static JSTaggedValue FilterArray(JSThread *thread, JSHandle<JSTaggedValue> &thisArgHandle,
|
||||
JSHandle<JSTaggedValue> &thisObjVal, JSHandle<JSObject> newArrayHandle,
|
||||
JSHandle<JSTaggedValue> &callbackFnHandle);
|
||||
|
||||
static Span<const std::pair<std::string_view, bool>> GetPrototypeProperties()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user