mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-10-08 00:24:00 +00:00
!7197 bugfix:The FlatMap IR function has a logical error.
Merge pull request !7197 from 贺存茂/flatMapIR
This commit is contained in:
commit
42c8902a3a
@ -4610,8 +4610,9 @@ void BuiltinsArrayStubBuilder::FlatMap(GateRef glue, GateRef thisValue, GateRef
|
||||
}
|
||||
Bind(&retValueIsJsArray);
|
||||
{
|
||||
GateRef arrLen = ZExtInt32ToInt64(GetArrayLength(retValue));
|
||||
newArrLen = Int64Sub(Int64Add(*newArrLen, arrLen), Int64(1));
|
||||
GateRef elementsNum =
|
||||
ZExtInt32ToInt64(GetNumberOfElements(retValue)); // newArray only contains non-hole elements
|
||||
newArrLen = Int64Sub(Int64Add(*newArrLen, elementsNum), Int64(1));
|
||||
Jump(&loopEnd);
|
||||
}
|
||||
}
|
||||
@ -4690,8 +4691,9 @@ void BuiltinsArrayStubBuilder::FlatMap(GateRef glue, GateRef thisValue, GateRef
|
||||
}
|
||||
Bind(&retValueIsJsArray);
|
||||
{
|
||||
GateRef arrLen = ZExtInt32ToInt64(GetArrayLength(retValue));
|
||||
newArrLen = Int64Sub(Int64Add(*newArrLen, arrLen), Int64(1));
|
||||
GateRef elementsNum =
|
||||
ZExtInt32ToInt64(GetNumberOfElements(retValue)); // newArray only contains non-hole elements
|
||||
newArrLen = Int64Sub(Int64Add(*newArrLen, elementsNum), Int64(1));
|
||||
Jump(&loopEnd);
|
||||
}
|
||||
}
|
||||
@ -4708,6 +4710,7 @@ void BuiltinsArrayStubBuilder::FlatMap(GateRef glue, GateRef thisValue, GateRef
|
||||
{
|
||||
i = Int64(0);
|
||||
DEFVARIABLE(j, VariableType::INT64(), Int64(0));
|
||||
DEFVARIABLE(retValueItem, VariableType::JS_ANY(), Hole());
|
||||
GateRef newArray = NewArray(glue, *newArrLen);
|
||||
Label loopHead2(env);
|
||||
Label loopEnd2(env);
|
||||
@ -4731,19 +4734,36 @@ void BuiltinsArrayStubBuilder::FlatMap(GateRef glue, GateRef thisValue, GateRef
|
||||
BRANCH(IsJsArray(retValue), &retValueIsJsArray, &retValueIsNotJsArray);
|
||||
Bind(&retValueIsJsArray);
|
||||
{
|
||||
Label retValueIsStableArray(env);
|
||||
Label retValueNotStableArray(env);
|
||||
GateRef retValueIsStable = IsStableJSArray(glue, retValue);
|
||||
GateRef arrLen = ZExtInt32ToInt64(GetArrayLength(retValue));
|
||||
DEFVARIABLE(k, VariableType::INT64(), Int64(0));
|
||||
Label loopHead3(env);
|
||||
Label loopEnd3(env);
|
||||
Label next3(env);
|
||||
Label loopExit3(env);
|
||||
Label setValue(env);
|
||||
Label itemExist(env);
|
||||
Jump(&loopHead3);
|
||||
LoopBegin(&loopHead3);
|
||||
{
|
||||
BRANCH(Int64LessThan(*k, arrLen), &next3, &loopExit3);
|
||||
Bind(&next3);
|
||||
SetValueWithElementsKind(glue, newArray, GetTaggedValueWithElementsKind(retValue, *k), *j,
|
||||
Boolean(true), Int32(static_cast<uint32_t>(ElementsKind::NONE)));
|
||||
BRANCH(retValueIsStable, &retValueIsStableArray, &retValueNotStableArray);
|
||||
Bind(&retValueIsStableArray);
|
||||
retValueItem = GetTaggedValueWithElementsKind(retValue, *k);
|
||||
BRANCH(TaggedIsHole(*retValueItem), &loopEnd3, &setValue);
|
||||
Bind(&retValueNotStableArray);
|
||||
GateRef hasProp = CallRuntime(glue, RTSTUB_ID(HasProperty), { retValue, IntToTaggedInt(*k) });
|
||||
BRANCH(TaggedIsTrue(hasProp), &itemExist, &loopEnd3);
|
||||
Bind(&itemExist);
|
||||
retValueItem =
|
||||
FastGetPropertyByIndex(glue, retValue, TruncInt64ToInt32(*k), ProfileOperation());
|
||||
Jump(&setValue);
|
||||
Bind(&setValue);
|
||||
SetValueWithElementsKind(glue, newArray, *retValueItem, *j, Boolean(true),
|
||||
Int32(static_cast<uint32_t>(ElementsKind::NONE)));
|
||||
j = Int64Add(*j, Int64(1));
|
||||
Jump(&loopEnd3);
|
||||
}
|
||||
|
@ -62,4 +62,16 @@ arr3.__proto__.pop(3);
|
||||
|
||||
let arr4 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
||||
var result4 = arr4.flatMap(testFunction);
|
||||
print(result4);
|
||||
print(result4);
|
||||
|
||||
let arr = [1,,,,,5];
|
||||
let res = arr.flatMap((x)=>{
|
||||
let ret=[x,x+1];
|
||||
ret[105] = x+2;
|
||||
Object.defineProperty(ret,2000,{value:x+3});
|
||||
return ret;
|
||||
})
|
||||
print(res);
|
||||
print(res.length)
|
||||
|
||||
|
||||
|
@ -16,3 +16,5 @@ true
|
||||
1,1,1,3,9,4,16,5,25
|
||||
1,1,1,3,9,4,16
|
||||
1,1,1,3,9,4,16,5,25
|
||||
1,2,3,4,5,6,7,8
|
||||
8
|
||||
|
Loading…
Reference in New Issue
Block a user