!7491 string.replace compressed 断言失败

Merge pull request !7491 from zhangyouyou/master
This commit is contained in:
openharmony_ci 2024-06-07 08:07:14 +00:00 committed by Gitee
commit 191dc31469
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 14 additions and 2 deletions

View File

@ -1153,7 +1153,7 @@ JSTaggedValue BuiltinsRegExp::ReplaceInternal(JSThread *thread,
}
}
// 14. Let accumulatedResult be the empty String value.
bool isUtf8 = EcmaStringAccessor(srcString).IsUtf8();
bool isUtf8 = true;
uint32_t resultStrLength = 0;
uint32_t resultArrayLength = (static_cast<uint32_t>(resultsIndex) + 1) * 2;
JSHandle<TaggedArray> resultArray = factory->NewTaggedArray(resultArrayLength);
@ -1296,6 +1296,9 @@ JSTaggedValue BuiltinsRegExp::ReplaceInternal(JSThread *thread,
// store position and length bits in resultLengthArray
resultLengthArray[REPLACE_RESULT_VAL * i] = bits;
resultStrLength += (position - nextSourcePosition);
auto subString = EcmaStringAccessor::FastSubString(
thread->GetEcmaVM(), srcString, nextSourcePosition, position - nextSourcePosition);
isUtf8 &= EcmaStringAccessor(subString).IsUtf8();
// store replacement string in resultArray
resultArray->Set(thread, REPLACE_RESULT_VAL * i + 1, replacementString.GetTaggedValue());
uint32_t replacementLength = EcmaStringAccessor(replacementString).GetLength();
@ -1315,6 +1318,9 @@ JSTaggedValue BuiltinsRegExp::ReplaceInternal(JSThread *thread,
uint64_t bits = 0;
bits |= ReplaceLengthField::Encode(length - nextSourcePosition);
bits |= ReplacePositionField::Encode(nextSourcePosition);
auto subStringEnd = EcmaStringAccessor::FastSubString(
thread->GetEcmaVM(), srcString, nextSourcePosition, length - nextSourcePosition);
isUtf8 &= EcmaStringAccessor(subStringEnd).IsUtf8();
// store position and length bits in resultLengthArray
resultLengthArray[REPLACE_RESULT_VAL * resultsIndex] = bits;
resultStrLength += (length - nextSourcePosition);

View File

@ -26,3 +26,5 @@ aaaa哈哈哈哈哈哈哈嘻嘻嘻嘻嘻嘻嘻嘻嘻bbbb哈哈哈哈哈哈哈嘻
aaaa哈哈哈哈哈哈哈哈哈哈哈哈哈哈bbbb哈哈哈哈哈哈哈哈哈哈哈哈哈哈cccc哈哈哈哈哈哈哈哈哈哈哈哈哈哈aaaabbbbcccc
aaaa哈哈哈哈哈哈哈哈哈嘻嘻嘻嘻嘻嘻嘻bbbb哈哈哈哈哈哈哈哈哈嘻嘻嘻嘻嘻嘻嘻cccc哈哈哈哈哈哈哈哈哈嘻嘻嘻嘻嘻嘻嘻aaaabbbbcccc
aaaa哈哈哈哈哈哈哈哈哈嘻bbbb哈哈哈哈哈哈哈哈哈嘻cccc哈哈哈哈哈哈哈哈哈嘻aaaabbbbcccc
undefinedss
undefinedss

View File

@ -100,4 +100,8 @@ function func8() {
return "哈哈哈哈哈哈哈哈哈".concat("嘻")
}
res = lineString2.replace(re2, func8);
print(res)
print(res)
let v5 = String.fromCharCode(0).replaceAll(/(?<a>.)/ug);
print("undefinedss".replace(undefined,v5));
print("undefinedss".replaceAll(undefined,v5));