!7327 修复String endsWith输入越界值结果错误问题

Merge pull request !7327 from liujia178/mjsunit_string_endwith
This commit is contained in:
openharmony_ci 2024-05-25 16:05:33 +00:00 committed by Gitee
commit bc8109c947
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 9 additions and 22 deletions

View File

@ -404,7 +404,7 @@ JSTaggedValue BuiltinsString::EndsWith(EcmaRuntimeCallInfo *argv)
if (posVal.GetNumber() == BuiltinsNumber::POSITIVE_INFINITY) {
pos = static_cast<int32_t>(thisLen);
} else {
pos = posVal.ToInt32();
pos = base::NumberHelper::DoubleInRangeInt32(posVal.GetNumber());
}
}
pos = std::min(std::max(pos, 0), static_cast<int32_t>(thisLen));

View File

@ -2732,7 +2732,6 @@ void BuiltinsStringStubBuilder::EndsWith(GateRef glue, GateRef thisValue, GateRe
Label posTagNotExists(env);
Label posTagIsNumber(env);
Label posTagIsInt(env);
Label posTagIsDouble(env);
Label afterCallArg(env);
Label endPosLessThanZero(env);
Label endPosNotLessThanZero(env);
@ -2768,30 +2767,12 @@ void BuiltinsStringStubBuilder::EndsWith(GateRef glue, GateRef thisValue, GateRe
GateRef posTag = GetCallArg1(numArgs);
BRANCH(TaggedIsNumber(posTag), &posTagIsNumber, slowPath);
Bind(&posTagIsNumber);
BRANCH(TaggedIsInt(posTag), &posTagIsInt, &posTagIsDouble);
BRANCH(TaggedIsInt(posTag), &posTagIsInt, slowPath);
Bind(&posTagIsInt);
{
searchPos = GetInt32OfTInt(posTag);
Jump(&afterCallArg);
}
Bind(&posTagIsDouble);
{
Label posTagIsPositiveInfinity(env);
Label posTagNotPositiveInfinity(env);
GateRef doubleVal = GetDoubleOfTDouble(posTag);
BRANCH(DoubleEqual(doubleVal, Double(builtins::BuiltinsNumber::POSITIVE_INFINITY)),
&posTagIsPositiveInfinity, &posTagNotPositiveInfinity);
Bind(&posTagIsPositiveInfinity);
{
searchPos = thisLen;
Jump(&afterCallArg);
}
Bind(&posTagNotPositiveInfinity);
{
searchPos = DoubleToInt(glue, doubleVal);
Jump(&afterCallArg);
}
}
}
Bind(&posTagNotExists);
{

View File

@ -142,3 +142,5 @@ abc
abc
bc
c
true
true

View File

@ -387,3 +387,8 @@ print(abc_str.substr(0, positiveHeapNumber));
print(abc_str.substr(-2, positiveHeapNumber));
print(abc_str.substr(-1, positiveHeapNumber));
{
function f(n) { return "cba".endsWith("a", n); }
print(f());
print(f(4294967296));
}

View File

@ -2494,7 +2494,6 @@
"mjsunit/compiler/fast-api-calls-pointer.js",
"mjsunit/compiler/number-constructor-deopt.js",
"mjsunit/compiler/fast-api-clamp-annotations.js",
"mjsunit/compiler/string-endswith.js",
"mjsunit/compiler/osr-forin.js",
"mjsunit/compiler/bigint-multiply-truncate.js",
"mjsunit/compiler/construct-receiver.js",