!5207 字符串拼接没有抛异常

Merge pull request !5207 from 韩靖/master
This commit is contained in:
openharmony_ci 2023-11-14 11:20:47 +00:00 committed by Gitee
commit c4f04ac3b1
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
8 changed files with 89 additions and 2 deletions

View File

@ -1713,10 +1713,20 @@ GateRef BuiltinsStringStubBuilder::StringConcat(GateRef glue, GateRef leftString
Label exit(env);
Label equalZero(env);
Label notEqualZero(env);
Label lessThanMax(env);
Label throwError(env);
GateRef leftLength = GetLengthFromString(leftString);
GateRef rightLength = GetLengthFromString(rightString);
GateRef newLength = Int32Add(leftLength, rightLength);
Branch(Int32GreaterThanOrEqual(newLength, Int32(EcmaString::MAX_STRING_LENGTH)), &throwError, &lessThanMax);
Bind(&throwError);
{
GateRef taggedId = Int32(GET_MESSAGE_STRING_ID(InvalidStringLength));
CallRuntime(glue, RTSTUB_ID(ThrowRangeError), { IntToTaggedInt(taggedId) });
Jump(&exit);
}
Bind(&lessThanMax);
Branch(Int32Equal(newLength, Int32(0)), &equalZero, &notEqualZero);
Bind(&equalZero);
{

View File

@ -42,7 +42,8 @@ namespace panda::ecmascript {
V(LenGreaterThanMax, "len is bigger than 2^32 - 1") \
V(ElementTypeNoElementTypes, "CreateListFromArrayLike: not an element of elementTypes") \
V(TargetIsDetachedBuffer, "Is Detached Buffer") \
V(ThisBranchIsUnreachable, "this branch is unreachable")
V(ThisBranchIsUnreachable, "this branch is unreachable") \
V(InvalidStringLength, "Invalid string length")
#define DEBUG_CHECK_MESSAGE_STRING_LIST(V) \
V(IsCallable) \

View File

@ -1532,6 +1532,16 @@ DEF_RUNTIME_STUBS(ThrowTypeError)
THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error.GetTaggedValue(), JSTaggedValue::Hole().GetRawData());
}
DEF_RUNTIME_STUBS(ThrowRangeError)
{
RUNTIME_STUBS_HEADER(ThrowRangeError);
JSTaggedValue argMessageStringId = GetArg(argv, argc, 0);
std::string message = MessageString::GetMessageString(argMessageStringId.GetInt());
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
JSHandle<JSObject> error = factory->GetJSError(ErrorType::RANGE_ERROR, message.c_str());
THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error.GetTaggedValue(), JSTaggedValue::Hole().GetRawData());
}
DEF_RUNTIME_STUBS(LoadMiss)
{
RUNTIME_STUBS_HEADER(LoadMiss);

View File

@ -341,7 +341,8 @@ using FastCallAotEntryType = JSTaggedValue (*)(uintptr_t glue, uint32_t argc, co
V(HClassCloneWithAddProto) \
V(LocaleCompareWithGc) \
V(ArrayForEachContinue) \
V(NumberDictionaryPut)
V(NumberDictionaryPut) \
V(ThrowRangeError)
#define RUNTIME_STUB_LIST(V) \
RUNTIME_ASM_STUB_LIST(V) \

View File

@ -105,6 +105,7 @@ group("ark_js_moduletest") {
"propertydetector",
"protobuf",
"proxy",
"rangeerror",
"regexpcallthrow",
"regexpflagd",
"require",
@ -238,6 +239,7 @@ group("ark_asm_test") {
"promise",
"propertydetector",
"proxy",
"rangeerror",
"regexpcallthrow",
"regexpflagd",
"setobjectwithproto",
@ -355,6 +357,7 @@ group("ark_asm_single_step_test") {
"promise",
"propertydetector",
"proxy",
"rangeerror",
"regexpcallthrow",
"regexpflagd",
"setobjectwithproto",

View File

@ -0,0 +1,18 @@
# Copyright (c) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_runtime/test/test_helper.gni")
host_moduletest_action("rangeerror") {
deps = []
}

View File

@ -0,0 +1,14 @@
# Copyright (c) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
RangeError: Invalid string length

View File

@ -0,0 +1,30 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* @tc.name:regexp
* @tc.desc:test Regexp
* @tc.type: FUNC
* @tc.require: issueI5NO8G
*/
try {
var v0 = "";
var v1 = "";
for(var v2 = 0; v2 < 10000; ++v2) {
v0 += v0 + v2 + v0 + v1 + v2 + "";
}
} catch(e) {
print(e);
}