mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-11-23 10:09:54 +00:00
修改BuiltinsString::Match,Replace,Search 等函数
Signed-off-by: yanpeng <yanpeng51@huawei.com> Change-Id: I0607ff10ad301385ac2933b847e5b1b14eb90ab2
This commit is contained in:
parent
1b70ab26d6
commit
53156998ec
@ -639,17 +639,15 @@ JSTaggedValue BuiltinsString::Match(EcmaRuntimeCallInfo *argv)
|
||||
}
|
||||
}
|
||||
if (!regexp->IsUndefined() && !regexp->IsNull()) {
|
||||
if (regexp->IsECMAObject()) {
|
||||
JSHandle<JSTaggedValue> matcher = JSObject::GetMethod(thread, regexp, matchTag);
|
||||
JSHandle<JSTaggedValue> matcher = JSObject::GetMethod(thread, regexp, matchTag);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
if (!matcher->IsUndefined()) {
|
||||
ASSERT(matcher->IsJSFunction());
|
||||
EcmaRuntimeCallInfo *info =
|
||||
EcmaInterpreter::NewRuntimeCallInfo(thread, matcher, regexp, undefined, 1);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
if (!matcher->IsUndefined()) {
|
||||
ASSERT(matcher->IsJSFunction());
|
||||
EcmaRuntimeCallInfo *info =
|
||||
EcmaInterpreter::NewRuntimeCallInfo(thread, matcher, regexp, undefined, 1);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
info->SetCallArg(thisTag.GetTaggedValue());
|
||||
return JSFunction::Call(info);
|
||||
}
|
||||
info->SetCallArg(thisTag.GetTaggedValue());
|
||||
return JSFunction::Call(info);
|
||||
}
|
||||
}
|
||||
JSHandle<EcmaString> thisVal = JSTaggedValue::ToString(thread, thisTag);
|
||||
@ -706,20 +704,17 @@ JSTaggedValue BuiltinsString::MatchAll(EcmaRuntimeCallInfo *argv)
|
||||
}
|
||||
}
|
||||
|
||||
if (regexp->IsECMAObject()) {
|
||||
// c. c. Let matcher be ? GetMethod(regexp, @@matchAll).
|
||||
// d. d. If matcher is not undefined, then
|
||||
JSHandle<JSTaggedValue> matcher = JSObject::GetMethod(thread, regexp, matchAllTag);
|
||||
// c. Let matcher be ? GetMethod(regexp, @@matchAll).
|
||||
// d. If matcher is not undefined, then
|
||||
JSHandle<JSTaggedValue> matcher = JSObject::GetMethod(thread, regexp, matchAllTag);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
if (!matcher->IsUndefined()) {
|
||||
// i. Return ? Call(matcher, regexp, « O »).
|
||||
EcmaRuntimeCallInfo *info =
|
||||
EcmaInterpreter::NewRuntimeCallInfo(thread, matcher, regexp, undefined, 1);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
if (!matcher->IsUndefined()) {
|
||||
ASSERT(matcher->IsJSFunction());
|
||||
// i. i. Return ? Call(matcher, regexp, « O »).
|
||||
EcmaRuntimeCallInfo *info =
|
||||
EcmaInterpreter::NewRuntimeCallInfo(thread, matcher, regexp, undefined, 1);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
info->SetCallArg(thisTag.GetTaggedValue());
|
||||
return JSFunction::Call(info);
|
||||
}
|
||||
info->SetCallArg(thisTag.GetTaggedValue());
|
||||
return JSFunction::Call(info);
|
||||
}
|
||||
}
|
||||
// 3. Let S be ? ToString(O).
|
||||
@ -887,7 +882,7 @@ JSTaggedValue BuiltinsString::Replace(EcmaRuntimeCallInfo *argv)
|
||||
}
|
||||
|
||||
// If searchValue is neither undefined nor null, then
|
||||
if (searchTag->IsECMAObject()) {
|
||||
if (!searchTag->IsUndefined() && !searchTag->IsNull()) {
|
||||
JSHandle<JSTaggedValue> replaceKey = env->GetReplaceSymbol();
|
||||
// Let replacer be GetMethod(searchValue, @@replace).
|
||||
JSHandle<JSTaggedValue> replaceMethod = JSObject::GetMethod(thread, searchTag, replaceKey);
|
||||
@ -1320,17 +1315,15 @@ JSTaggedValue BuiltinsString::Search(EcmaRuntimeCallInfo *argv)
|
||||
JSHandle<JSTaggedValue> searchTag = thread->GetEcmaVM()->GetGlobalEnv()->GetSearchSymbol();
|
||||
JSHandle<JSTaggedValue> undefined = globalConst->GetHandledUndefined();
|
||||
if (!regexp->IsUndefined() && !regexp->IsNull()) {
|
||||
if (regexp->IsECMAObject()) {
|
||||
JSHandle<JSTaggedValue> searcher = JSObject::GetMethod(thread, regexp, searchTag);
|
||||
JSHandle<JSTaggedValue> searcher = JSObject::GetMethod(thread, regexp, searchTag);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
if (!searcher->IsUndefined()) {
|
||||
ASSERT(searcher->IsJSFunction());
|
||||
EcmaRuntimeCallInfo *info =
|
||||
EcmaInterpreter::NewRuntimeCallInfo(thread, searcher, regexp, undefined, 1);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
if (!searcher->IsUndefined()) {
|
||||
ASSERT(searcher->IsJSFunction());
|
||||
EcmaRuntimeCallInfo *info =
|
||||
EcmaInterpreter::NewRuntimeCallInfo(thread, searcher, regexp, undefined, 1);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
info->SetCallArg(thisTag.GetTaggedValue());
|
||||
return JSFunction::Call(info);
|
||||
}
|
||||
info->SetCallArg(thisTag.GetTaggedValue());
|
||||
return JSFunction::Call(info);
|
||||
}
|
||||
}
|
||||
JSHandle<EcmaString> thisVal = JSTaggedValue::ToString(thread, thisTag);
|
||||
@ -1425,7 +1418,7 @@ JSTaggedValue BuiltinsString::Split(EcmaRuntimeCallInfo *argv)
|
||||
}
|
||||
|
||||
// If separator is neither undefined nor null, then
|
||||
if (seperatorTag->IsECMAObject()) {
|
||||
if (!seperatorTag->IsUndefined() && !seperatorTag->IsNull()) {
|
||||
JSHandle<JSTaggedValue> splitKey = env->GetSplitSymbol();
|
||||
// Let splitter be GetMethod(separator, @@split).
|
||||
JSHandle<JSTaggedValue> splitter = JSObject::GetMethod(thread, seperatorTag, splitKey);
|
||||
|
@ -120,6 +120,7 @@ group("ark_js_moduletest") {
|
||||
"regexpflagd",
|
||||
"regress",
|
||||
"regressdefineproperty",
|
||||
"regresssstring",
|
||||
"require",
|
||||
"setobjectwithproto",
|
||||
"spreadoperator",
|
||||
|
18
test/moduletest/regresssstring/BUILD.gn
Executable file
18
test/moduletest/regresssstring/BUILD.gn
Executable 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("regresssstring") {
|
||||
deps = []
|
||||
}
|
16
test/moduletest/regresssstring/expect_output.txt
Executable file
16
test/moduletest/regresssstring/expect_output.txt
Executable file
@ -0,0 +1,16 @@
|
||||
# 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.
|
||||
|
||||
true
|
||||
true
|
||||
true
|
39
test/moduletest/regresssstring/regresssstring.js
Executable file
39
test/moduletest/regresssstring/regresssstring.js
Executable file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
const str = "Umbridge has been reading your mail, Harry."
|
||||
|
||||
{
|
||||
let monkey_called = false;
|
||||
str.__proto__.__proto__[Symbol.replace] =
|
||||
() => { monkey_called = true; };
|
||||
str.replace(str);
|
||||
print(monkey_called);
|
||||
}
|
||||
|
||||
{
|
||||
let monkey_called = false;
|
||||
str.__proto__.__proto__[Symbol.search] =
|
||||
() => { monkey_called = true; };
|
||||
str.search(str);
|
||||
print(monkey_called);
|
||||
}
|
||||
|
||||
{
|
||||
let monkey_called = false;
|
||||
str.__proto__.__proto__[Symbol.match] =
|
||||
() => { monkey_called = true; };
|
||||
str.match(str);
|
||||
print(monkey_called);
|
||||
}
|
Loading…
Reference in New Issue
Block a user