!7197 bugfix:The FlatMap IR function has a logical error.

Merge pull request !7197 from 贺存茂/flatMapIR
This commit is contained in:
openharmony_ci 2024-05-04 06:39:36 +00:00 committed by Gitee
commit 42c8902a3a
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 41 additions and 7 deletions

View File

@ -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);
}

View File

@ -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)

View File

@ -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