1/*
2 * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/*
17 * @tc.name:property detector
18 * @tc.desc:test property detector
19 * @tc.type: FUNC
20 * @tc.require: issueI83B0E
21 */
22
23print(ArkTools.isRegExpFlagsDetectorValid())
24Object.defineProperty(RegExp.prototype, 'flags', {
25  get: function () {
26    return undefined;
27  }
28});
29print(ArkTools.isRegExpFlagsDetectorValid())
30
31let str = '这是一段原始文本,"3c这要替换4d"!';
32let regexp = /([0-9])([a-z])/g
33let newStr1 = str.replace(regexp, "$1" );
34print(newStr1)
35print(ArkTools.isRegExpReplaceDetectorValid())
36
37let p = RegExp.prototype
38let unused = p[Symbol.replace]
39print(ArkTools.isRegExpReplaceDetectorValid())
40
41p["replace"] = function () {return "abc"}
42print(ArkTools.isRegExpReplaceDetectorValid())
43
44regexp.__proto__ = {}
45let newStr2 = str.replace(regexp, "$2" );
46print(newStr2)
47print(ArkTools.isRegExpReplaceDetectorValid())
48
49// resume regexp.__proto__
50regexp.__proto__ = p
51p[Symbol.replace] = function () {return "aaa"}
52let newStr3 = str.replace(regexp, "$3" );
53print(newStr3)
54print(ArkTools.isRegExpReplaceDetectorValid())
55
56p[Symbol.replace] = function () {return 4}
57let newStr4 = str.replace( /([0-9])([a-z])/g,"$4" );
58print(newStr4)
59print(ArkTools.isRegExpReplaceDetectorValid())
60
61print(ArkTools.isNumberStringNotRegexpLikeDetectorValid());
62String.prototype[Symbol.matchAll] = function () {return "aaa"}
63print(ArkTools.isNumberStringNotRegexpLikeDetectorValid());