• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device 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 #ifndef ECMASCRIPT_BUILTINS_BUILTINS_STRING_H
17 #define ECMASCRIPT_BUILTINS_BUILTINS_STRING_H
18 
19 #include "ecmascript/base/builtins_base.h"
20 #include "ecmascript/ecma_runtime_call_info.h"
21 #include "ecmascript/js_tagged_value.h"
22 
23 namespace panda::ecmascript::builtins {
24 constexpr int32_t ENCODE_MAX_UTF16 = 0X10FFFF;
25 constexpr uint16_t ENCODE_LEAD_LOW = 0xD800;
26 constexpr uint16_t ENCODE_TRAIL_LOW = 0xDC00;
27 constexpr uint32_t ENCODE_FIRST_FACTOR = 0x400;
28 constexpr uint32_t ENCODE_SECOND_FACTOR = 0x10000;
29 constexpr double DOUBLE_INT_MAX = static_cast<double>(INT_MAX);
30 constexpr double DOUBLE_INT_MIN = static_cast<double>(INT_MIN);
31 
32 class BuiltinsString : public base::BuiltinsBase {
33 public:
34     // 21.1.1.1
35     static JSTaggedValue StringConstructor(EcmaRuntimeCallInfo *argv);
36     // 21.1.2.1
37     static JSTaggedValue FromCharCode(EcmaRuntimeCallInfo *argv);
38     // 21.1.2.2
39     static JSTaggedValue FromCodePoint(EcmaRuntimeCallInfo *argv);
40     // 21.1.2.4
41     static JSTaggedValue Raw(EcmaRuntimeCallInfo *argv);
42 
43     static JSTaggedValue GetSubstitution(JSThread *thread, const JSHandle<EcmaString> &matched,
44                                          const JSHandle<EcmaString> &srcString, int position,
45                                          const JSHandle<TaggedArray> &captureList,
46                                          const JSHandle<EcmaString> &replacement);
47     // 21.1.3.1
48     static JSTaggedValue CharAt(EcmaRuntimeCallInfo *argv);
49     // 21.1.3.2
50     static JSTaggedValue CharCodeAt(EcmaRuntimeCallInfo *argv);
51     // 21.1.3.3
52     static JSTaggedValue CodePointAt(EcmaRuntimeCallInfo *argv);
53     // 21.1.3.4
54     static JSTaggedValue Concat(EcmaRuntimeCallInfo *argv);
55     // 21.1.3.5 String.prototype.constructor
56     // 21.1.3.6
57     static JSTaggedValue EndsWith(EcmaRuntimeCallInfo *argv);
58     // 21.1.3.7
59     static JSTaggedValue Includes(EcmaRuntimeCallInfo *argv);
60     // 21.1.3.8
61     static JSTaggedValue IndexOf(EcmaRuntimeCallInfo *argv);
62     // 21.1.3.9
63     static JSTaggedValue LastIndexOf(EcmaRuntimeCallInfo *argv);
64     // 21.1.3.10
65     static JSTaggedValue LocaleCompare(EcmaRuntimeCallInfo *argv);
66     // 21.1.3.11
67     static JSTaggedValue Match(EcmaRuntimeCallInfo *argv);
68     // 21.1.3.12
69     static JSTaggedValue Normalize(EcmaRuntimeCallInfo *argv);
70     // 21.1.3.13
71     static JSTaggedValue Repeat(EcmaRuntimeCallInfo *argv);
72     // 21.1.3.14
73     static JSTaggedValue Replace(EcmaRuntimeCallInfo *argv);
74     // 21.1.3.14.1 Runtime Semantics: GetSubstitution()
75     // 21.1.3.15
76     static JSTaggedValue Search(EcmaRuntimeCallInfo *argv);
77     // 21.1.3.16
78     static JSTaggedValue Slice(EcmaRuntimeCallInfo *argv);
79     // 21.1.3.17
80     static JSTaggedValue Split(EcmaRuntimeCallInfo *argv);
81     // 21.1.3.17.1 Runtime Semantics: SplitMatch
82     // 21.1.3.18
83     static JSTaggedValue StartsWith(EcmaRuntimeCallInfo *argv);
84     // 21.1.3.19
85     static JSTaggedValue Substring(EcmaRuntimeCallInfo *argv);
86     // 21.1.3.20
87     static JSTaggedValue ToLocaleLowerCase(EcmaRuntimeCallInfo *argv);
88     // 21.1.3.21
89     static JSTaggedValue ToLocaleUpperCase(EcmaRuntimeCallInfo *argv);
90     // 21.1.3.22
91     static JSTaggedValue ToLowerCase(EcmaRuntimeCallInfo *argv);
92     // 21.1.3.23
93     static JSTaggedValue ToString(EcmaRuntimeCallInfo *argv);
94     // 21.1.3.24
95     static JSTaggedValue ToUpperCase(EcmaRuntimeCallInfo *argv);
96     // 21.1.3.25
97     static JSTaggedValue Trim(EcmaRuntimeCallInfo *argv);
98     // 21.1.3.26
99     static JSTaggedValue ValueOf(EcmaRuntimeCallInfo *argv);
100     // 21.1.3.27
101     static JSTaggedValue GetStringIterator(EcmaRuntimeCallInfo *argv);
102     // 21.1.3
103     static JSTaggedValue ThisStringValue(JSThread *thread, JSTaggedValue value);
104     // 21.1.2.27
105     static JSTaggedValue CreateIterator(EcmaRuntimeCallInfo *argv);
106     // 10.1.2
107     static uint16_t UTF16Decode(uint16_t lead, uint16_t trail);
108     // annexB B.2.3.1
109     static JSTaggedValue SubStr(EcmaRuntimeCallInfo *argv);
110 
111     static JSTaggedValue GetLength(EcmaRuntimeCallInfo *argv);
112 
113 private:
114     static int32_t ConvertDoubleToInt(double d);
115     // 21.1.3.17.1
116     static int32_t SplitMatch(const JSHandle<EcmaString> &str, int32_t q, const JSHandle<EcmaString> &reg);
117 };
118 }  // namespace panda::ecmascript::builtins
119 #endif  // ECMASCRIPT_BUILTINS_BUILTINS_STRING_H
120