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<JSTaggedValue> &namedCaptures, 47 const JSHandle<EcmaString> &replacement); 48 // 21.1.3.1 49 static JSTaggedValue CharAt(EcmaRuntimeCallInfo *argv); 50 // 21.1.3.2 51 static JSTaggedValue CharCodeAt(EcmaRuntimeCallInfo *argv); 52 // 21.1.3.3 53 static JSTaggedValue CodePointAt(EcmaRuntimeCallInfo *argv); 54 // 21.1.3.4 55 static JSTaggedValue Concat(EcmaRuntimeCallInfo *argv); 56 // 21.1.3.5 String.prototype.constructor 57 // 21.1.3.6 58 static JSTaggedValue EndsWith(EcmaRuntimeCallInfo *argv); 59 // 21.1.3.7 60 static JSTaggedValue Includes(EcmaRuntimeCallInfo *argv); 61 // 21.1.3.8 62 static JSTaggedValue IndexOf(EcmaRuntimeCallInfo *argv); 63 // 21.1.3.9 64 static JSTaggedValue LastIndexOf(EcmaRuntimeCallInfo *argv); 65 // 21.1.3.10 66 static JSTaggedValue LocaleCompare(EcmaRuntimeCallInfo *argv); 67 // 21.1.3.11 68 static JSTaggedValue Match(EcmaRuntimeCallInfo *argv); 69 70 static JSTaggedValue MatchAll(EcmaRuntimeCallInfo *argv); 71 // 21.1.3.12 72 static JSTaggedValue Normalize(EcmaRuntimeCallInfo *argv); 73 74 static JSTaggedValue PadStart(EcmaRuntimeCallInfo *argv); 75 76 static JSTaggedValue PadEnd(EcmaRuntimeCallInfo *argv); 77 // 21.1.3.13 78 static JSTaggedValue Repeat(EcmaRuntimeCallInfo *argv); 79 // 21.1.3.14 80 static JSTaggedValue Replace(EcmaRuntimeCallInfo *argv); 81 // 21.1.3.14.1 Runtime Semantics: GetSubstitution() 82 static JSTaggedValue ReplaceAll(EcmaRuntimeCallInfo *argv); 83 // 21.1.3.15 84 static JSTaggedValue Search(EcmaRuntimeCallInfo *argv); 85 // 21.1.3.16 86 static JSTaggedValue Slice(EcmaRuntimeCallInfo *argv); 87 // 21.1.3.17 88 static JSTaggedValue Split(EcmaRuntimeCallInfo *argv); 89 // 21.1.3.18 90 static JSTaggedValue StartsWith(EcmaRuntimeCallInfo *argv); 91 // 21.1.3.19 92 static JSTaggedValue Substring(EcmaRuntimeCallInfo *argv); 93 // 21.1.3.20 94 static JSTaggedValue ToLocaleLowerCase(EcmaRuntimeCallInfo *argv); 95 // 21.1.3.21 96 static JSTaggedValue ToLocaleUpperCase(EcmaRuntimeCallInfo *argv); 97 // 21.1.3.22 98 static JSTaggedValue ToLowerCase(EcmaRuntimeCallInfo *argv); 99 // 21.1.3.23 100 static JSTaggedValue ToString(EcmaRuntimeCallInfo *argv); 101 // 21.1.3.24 102 static JSTaggedValue ToUpperCase(EcmaRuntimeCallInfo *argv); 103 // 21.1.3.25 104 static JSTaggedValue Trim(EcmaRuntimeCallInfo *argv); 105 106 static JSTaggedValue TrimStart(EcmaRuntimeCallInfo *argv); 107 108 static JSTaggedValue TrimEnd(EcmaRuntimeCallInfo *argv); 109 110 static JSTaggedValue TrimLeft(EcmaRuntimeCallInfo *argv); 111 112 static JSTaggedValue TrimRight(EcmaRuntimeCallInfo *argv); 113 // 21.1.3.26 114 static JSTaggedValue ValueOf(EcmaRuntimeCallInfo *argv); 115 // 21.1.3.27 116 static JSTaggedValue GetStringIterator(EcmaRuntimeCallInfo *argv); 117 // 21.1.3 118 static JSTaggedValue ThisStringValue(JSThread *thread, JSTaggedValue value); 119 // 21.1.2.27 120 static JSTaggedValue CreateIterator(EcmaRuntimeCallInfo *argv); 121 // 10.1.2 122 static uint16_t UTF16Decode(uint16_t lead, uint16_t trail); 123 // annexB B.2.3.1 124 static JSTaggedValue SubStr(EcmaRuntimeCallInfo *argv); 125 // 22.1.3.1 126 static JSTaggedValue At(EcmaRuntimeCallInfo *argv); 127 128 static JSTaggedValue GetLength(EcmaRuntimeCallInfo *argv); 129 130 private: 131 static JSTaggedValue Pad(EcmaRuntimeCallInfo *argv, bool isStart); 132 static int32_t ConvertDoubleToInt(double d); 133 // 21.1.3.17.1 134 }; 135 } // namespace panda::ecmascript::builtins 136 #endif // ECMASCRIPT_BUILTINS_BUILTINS_STRING_H 137