14514f5e3Sopenharmony_ci/*
24514f5e3Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd.
34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License.
54514f5e3Sopenharmony_ci * You may obtain a copy of the License at
64514f5e3Sopenharmony_ci *
74514f5e3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
84514f5e3Sopenharmony_ci *
94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and
134514f5e3Sopenharmony_ci * limitations under the License.
144514f5e3Sopenharmony_ci */
154514f5e3Sopenharmony_ci
164514f5e3Sopenharmony_ci#ifndef ECMASCRIPT_BUILTINS_BUILTINS_STRING_H
174514f5e3Sopenharmony_ci#define ECMASCRIPT_BUILTINS_BUILTINS_STRING_H
184514f5e3Sopenharmony_ci
194514f5e3Sopenharmony_ci#include "ecmascript/base/builtins_base.h"
204514f5e3Sopenharmony_ci#include "ecmascript/ecma_runtime_call_info.h"
214514f5e3Sopenharmony_ci#include "ecmascript/js_tagged_value.h"
224514f5e3Sopenharmony_ci
234514f5e3Sopenharmony_ci// List of functions in String, excluding the '@@' properties.
244514f5e3Sopenharmony_ci// V(name, func, length, stubIndex)
254514f5e3Sopenharmony_ci// where BuiltinsString::func refers to the native implementation of String[name].
264514f5e3Sopenharmony_ci//       kungfu::BuiltinsStubCSigns::stubIndex refers to the builtin stub index, or INVALID if no stub available.
274514f5e3Sopenharmony_ci#define BUILTIN_STRING_FUNCTIONS(V)                             \
284514f5e3Sopenharmony_ci    /* String.fromCharCode ( ...codeUnits ) */                  \
294514f5e3Sopenharmony_ci    V("fromCharCode",  FromCharCode,  1, StringFromCharCode)    \
304514f5e3Sopenharmony_ci    /* String.fromCodePoint ( ...codePoints ) */                \
314514f5e3Sopenharmony_ci    V("fromCodePoint", FromCodePoint, 1, INVALID)               \
324514f5e3Sopenharmony_ci    /* String.raw ( template, ...substitutions ) */             \
334514f5e3Sopenharmony_ci    V("raw",           Raw,           1, INVALID)
344514f5e3Sopenharmony_ci
354514f5e3Sopenharmony_ci// List of functions in String.prototype, excluding the constructor and '@@' properties.
364514f5e3Sopenharmony_ci// V(name, func, length, stubIndex)
374514f5e3Sopenharmony_ci// where BuiltinsString::func refers to the native implementation of String.prototype[name].
384514f5e3Sopenharmony_ci// The following functions in String.prototype are not implemented yet:
394514f5e3Sopenharmony_ci//   - String.prototype.isWellFormed ( )
404514f5e3Sopenharmony_ci//   - String.prototype.toWellFormed ( )
414514f5e3Sopenharmony_ci#define BUILTIN_STRING_PROTOTYPE_FUNCTIONS(V)                                       \
424514f5e3Sopenharmony_ci    /* String.prototype.at ( index ) */                                             \
434514f5e3Sopenharmony_ci    V("at",                At,                1, INVALID)                           \
444514f5e3Sopenharmony_ci    /* String.prototype.charAt ( pos ) */                                           \
454514f5e3Sopenharmony_ci    V("charAt",            CharAt,            1, StringCharAt)                      \
464514f5e3Sopenharmony_ci    /* String.prototype.charCodeAt ( pos ) */                                       \
474514f5e3Sopenharmony_ci    V("charCodeAt",        CharCodeAt,        1, StringCharCodeAt)                  \
484514f5e3Sopenharmony_ci    /* String.prototype.codePointAt ( pos ) */                                      \
494514f5e3Sopenharmony_ci    V("codePointAt",       CodePointAt,       1, StringCodePointAt)                 \
504514f5e3Sopenharmony_ci    /* String.prototype.concat ( ...args ) */                                       \
514514f5e3Sopenharmony_ci    V("concat",            Concat,            1, StringConcat)                      \
524514f5e3Sopenharmony_ci    /* String.prototype.endsWith ( searchString [ , endPosition ] ) */              \
534514f5e3Sopenharmony_ci    V("endsWith",          EndsWith,          1, StringEndsWith)                    \
544514f5e3Sopenharmony_ci    /* String.prototype.includes ( searchString [ , position ] ) */                 \
554514f5e3Sopenharmony_ci    V("includes",          Includes,          1, INVALID)                           \
564514f5e3Sopenharmony_ci    /* String.prototype.indexOf ( searchString [ , position ] ) */                  \
574514f5e3Sopenharmony_ci    V("indexOf",           IndexOf,           1, StringIndexOf)                     \
584514f5e3Sopenharmony_ci    /* String.prototype.lastIndexOf ( searchString [ , position ] ) */              \
594514f5e3Sopenharmony_ci    V("lastIndexOf",       LastIndexOf,       1, INVALID)                           \
604514f5e3Sopenharmony_ci    /* String.prototype.localeCompare ( that [ , reserved1 [ , reserved2 ] ] ) */   \
614514f5e3Sopenharmony_ci    V("localeCompare",     LocaleCompare,     1, StringLocaleCompare)               \
624514f5e3Sopenharmony_ci    /* String.prototype.match ( regexp ) */                                         \
634514f5e3Sopenharmony_ci    V("match",             Match,             1, INVALID)                           \
644514f5e3Sopenharmony_ci    /* String.prototype.matchAll ( regexp ) */                                      \
654514f5e3Sopenharmony_ci    V("matchAll",          MatchAll,          1, INVALID)                           \
664514f5e3Sopenharmony_ci    /* String.prototype.normalize ( [ form ] ) */                                   \
674514f5e3Sopenharmony_ci    V("normalize",         Normalize,         0, INVALID)                           \
684514f5e3Sopenharmony_ci    /* String.prototype.isWellFormed ( ) */                                         \
694514f5e3Sopenharmony_ci    V("isWellFormed",      IsWellFormed,      0, INVALID)                           \
704514f5e3Sopenharmony_ci    /* String.prototype.toWellFormed ( ) */                                         \
714514f5e3Sopenharmony_ci    V("toWellFormed",      ToWellFormed,      0, INVALID)                           \
724514f5e3Sopenharmony_ci    /* String.prototype.padEnd ( maxLength [ , fillString ] ) */                    \
734514f5e3Sopenharmony_ci    V("padEnd",            PadEnd,            1, StringPadEnd)                      \
744514f5e3Sopenharmony_ci    /* String.prototype.padStart ( maxLength [ , fillString ] ) */                  \
754514f5e3Sopenharmony_ci    V("padStart",          PadStart,          1, StringPadStart)                    \
764514f5e3Sopenharmony_ci    /* String.prototype.repeat ( count ) */                                         \
774514f5e3Sopenharmony_ci    V("repeat",            Repeat,            1, INVALID)                           \
784514f5e3Sopenharmony_ci    /* String.prototype.replace ( searchValue, replaceValue ) */                    \
794514f5e3Sopenharmony_ci    V("replace",           Replace,           2, StringReplace)                     \
804514f5e3Sopenharmony_ci    /* String.prototype.replaceAll ( searchValue, replaceValue ) */                 \
814514f5e3Sopenharmony_ci    V("replaceAll",        ReplaceAll,        2, INVALID)                           \
824514f5e3Sopenharmony_ci    /* String.prototype.search ( regexp ) */                                        \
834514f5e3Sopenharmony_ci    V("search",            Search,            1, INVALID)                           \
844514f5e3Sopenharmony_ci    /* String.prototype.slice ( start, end ) */                                     \
854514f5e3Sopenharmony_ci    V("slice",             Slice,             2, StringSlice)                       \
864514f5e3Sopenharmony_ci    /* String.prototype.split ( separator, limit ) */                               \
874514f5e3Sopenharmony_ci    V("split",             Split,             2, INVALID)                           \
884514f5e3Sopenharmony_ci    /* String.prototype.startsWith ( searchString [ , position ] ) */               \
894514f5e3Sopenharmony_ci    V("startsWith",        StartsWith,        1, StringStartsWith)                  \
904514f5e3Sopenharmony_ci    /* In Annex B.2.2: Additional Properties of the String.prototype Object */      \
914514f5e3Sopenharmony_ci    /* String.prototype.substr ( start, length ) */                                 \
924514f5e3Sopenharmony_ci    V("substr",            SubStr,            2, StringSubStr)                      \
934514f5e3Sopenharmony_ci    /* String.prototype.substring ( start, end ) */                                 \
944514f5e3Sopenharmony_ci    V("substring",         Substring,         2, StringSubstring)                   \
954514f5e3Sopenharmony_ci    /* String.prototype.toLocaleLowerCase ( [ reserved1 [ , reserved2 ] ] ) */      \
964514f5e3Sopenharmony_ci    V("toLocaleLowerCase", ToLocaleLowerCase, 0, INVALID)                           \
974514f5e3Sopenharmony_ci    /* String.prototype.toLocaleUpperCase ( [ reserved1 [ , reserved2 ] ] ) */      \
984514f5e3Sopenharmony_ci    V("toLocaleUpperCase", ToLocaleUpperCase, 0, INVALID)                           \
994514f5e3Sopenharmony_ci    /* String.prototype.toLowerCase ( ) */                                          \
1004514f5e3Sopenharmony_ci    V("toLowerCase",       ToLowerCase,       0, StringToLowerCase)                 \
1014514f5e3Sopenharmony_ci    /* String.prototype.toString ( ) */                                             \
1024514f5e3Sopenharmony_ci    V("toString",          ToString,          0, INVALID)                           \
1034514f5e3Sopenharmony_ci    /* String.prototype.toUpperCase ( ) */                                          \
1044514f5e3Sopenharmony_ci    V("toUpperCase",       ToUpperCase,       0, INVALID)                           \
1054514f5e3Sopenharmony_ci    /* String.prototype.trim ( ) */                                                 \
1064514f5e3Sopenharmony_ci    V("trim",              Trim,              0, StringTrim)                        \
1074514f5e3Sopenharmony_ci    /* String.prototype.trimEnd ( ) */                                              \
1084514f5e3Sopenharmony_ci    V("trimEnd",           TrimEnd,           0, StringTrimEnd)                     \
1094514f5e3Sopenharmony_ci    /* In Annex B.2.2: Additional Properties of the String.prototype Object */      \
1104514f5e3Sopenharmony_ci    /* Equivalent to trimStart. For compatibility only. */                          \
1114514f5e3Sopenharmony_ci    /* String.prototype.trimLeft ( ) */                                             \
1124514f5e3Sopenharmony_ci    V("trimLeft",          TrimLeft,          0, StringTrimLeft)                    \
1134514f5e3Sopenharmony_ci    /* In Annex B.2.2: Additional Properties of the String.prototype Object */      \
1144514f5e3Sopenharmony_ci    /* Equivalent to trimEnd. For compatibility only. */                            \
1154514f5e3Sopenharmony_ci    /* String.prototype.trimEnd ( ) */                                              \
1164514f5e3Sopenharmony_ci    V("trimRight",         TrimRight,         0, StringTrimRight)                   \
1174514f5e3Sopenharmony_ci    /* String.prototype.trimStart ( ) */                                            \
1184514f5e3Sopenharmony_ci    V("trimStart",         TrimStart,         0, StringTrimStart)                   \
1194514f5e3Sopenharmony_ci    /* String.prototype.valueOf ( ) */                                              \
1204514f5e3Sopenharmony_ci    V("valueOf",           ValueOf,           0, INVALID)
1214514f5e3Sopenharmony_ci
1224514f5e3Sopenharmony_cinamespace panda::ecmascript {
1234514f5e3Sopenharmony_cienum class CompareStringsOption : uint8_t;
1244514f5e3Sopenharmony_ci}
1254514f5e3Sopenharmony_ci
1264514f5e3Sopenharmony_cinamespace panda::ecmascript::builtins {
1274514f5e3Sopenharmony_ciconstexpr int32_t ENCODE_MAX_UTF16 = 0X10FFFF;
1284514f5e3Sopenharmony_ciconstexpr uint16_t ENCODE_LEAD_LOW = 0xD800;
1294514f5e3Sopenharmony_ciconstexpr uint16_t ENCODE_TRAIL_LOW = 0xDC00;
1304514f5e3Sopenharmony_ciconstexpr uint32_t ENCODE_FIRST_FACTOR = 0x400;
1314514f5e3Sopenharmony_ciconstexpr uint32_t ENCODE_SECOND_FACTOR = 0x10000;
1324514f5e3Sopenharmony_ciconstexpr double DOUBLE_INT_MAX = static_cast<double>(INT_MAX);
1334514f5e3Sopenharmony_ciconstexpr double DOUBLE_INT_MIN = static_cast<double>(INT_MIN);
1344514f5e3Sopenharmony_ci
1354514f5e3Sopenharmony_ciclass BuiltinsString : public base::BuiltinsBase {
1364514f5e3Sopenharmony_cipublic:
1374514f5e3Sopenharmony_ci    // 21.1.1.1
1384514f5e3Sopenharmony_ci    static JSTaggedValue StringConstructor(EcmaRuntimeCallInfo *argv);
1394514f5e3Sopenharmony_ci    // 21.1.2.1
1404514f5e3Sopenharmony_ci    static JSTaggedValue FromCharCode(EcmaRuntimeCallInfo *argv);
1414514f5e3Sopenharmony_ci    // 21.1.2.2
1424514f5e3Sopenharmony_ci    static JSTaggedValue FromCodePoint(EcmaRuntimeCallInfo *argv);
1434514f5e3Sopenharmony_ci    // 21.1.2.4
1444514f5e3Sopenharmony_ci    static JSTaggedValue Raw(EcmaRuntimeCallInfo *argv);
1454514f5e3Sopenharmony_ci
1464514f5e3Sopenharmony_ci    static JSTaggedValue GetSubstitution(JSThread *thread, const JSHandle<EcmaString> &matched,
1474514f5e3Sopenharmony_ci                                         const JSHandle<EcmaString> &srcString, int position,
1484514f5e3Sopenharmony_ci                                         const JSHandle<TaggedArray> &captureList,
1494514f5e3Sopenharmony_ci                                         const JSHandle<JSTaggedValue> &namedCaptures,
1504514f5e3Sopenharmony_ci                                         const JSHandle<EcmaString> &replacement);
1514514f5e3Sopenharmony_ci    // 21.1.3.1
1524514f5e3Sopenharmony_ci    static JSTaggedValue CharAt(EcmaRuntimeCallInfo *argv);
1534514f5e3Sopenharmony_ci    // 21.1.3.2
1544514f5e3Sopenharmony_ci    static JSTaggedValue CharCodeAt(EcmaRuntimeCallInfo *argv);
1554514f5e3Sopenharmony_ci    // 21.1.3.3
1564514f5e3Sopenharmony_ci    static JSTaggedValue CodePointAt(EcmaRuntimeCallInfo *argv);
1574514f5e3Sopenharmony_ci    // 21.1.3.4
1584514f5e3Sopenharmony_ci    static JSTaggedValue Concat(EcmaRuntimeCallInfo *argv);
1594514f5e3Sopenharmony_ci    // 21.1.3.5 String.prototype.constructor
1604514f5e3Sopenharmony_ci    // 21.1.3.6
1614514f5e3Sopenharmony_ci    static JSTaggedValue EndsWith(EcmaRuntimeCallInfo *argv);
1624514f5e3Sopenharmony_ci    // 21.1.3.7
1634514f5e3Sopenharmony_ci    static JSTaggedValue Includes(EcmaRuntimeCallInfo *argv);
1644514f5e3Sopenharmony_ci    // 21.1.3.8
1654514f5e3Sopenharmony_ci    static JSTaggedValue IndexOf(EcmaRuntimeCallInfo *argv);
1664514f5e3Sopenharmony_ci    // 21.1.3.9
1674514f5e3Sopenharmony_ci    static JSTaggedValue LastIndexOf(EcmaRuntimeCallInfo *argv);
1684514f5e3Sopenharmony_ci    // 21.1.3.10
1694514f5e3Sopenharmony_ci    static JSTaggedValue LocaleCompare(EcmaRuntimeCallInfo *argv);
1704514f5e3Sopenharmony_ci    static JSTaggedValue DoLocaleCompare(JSThread *thread,
1714514f5e3Sopenharmony_ci                                         const JSHandle<EcmaString> &thisHandle,
1724514f5e3Sopenharmony_ci                                         const JSHandle<EcmaString> &thatHandle,
1734514f5e3Sopenharmony_ci                                         const JSHandle<JSTaggedValue> &locales,
1744514f5e3Sopenharmony_ci                                         const JSHandle<JSTaggedValue> &options);
1754514f5e3Sopenharmony_ci    static JSTaggedValue LocaleCompareGC(JSThread *thread,
1764514f5e3Sopenharmony_ci                                         const JSHandle<EcmaString> &thisHandle,
1774514f5e3Sopenharmony_ci                                         const JSHandle<EcmaString> &thatHandle,
1784514f5e3Sopenharmony_ci                                         const JSHandle<JSTaggedValue> &locales,
1794514f5e3Sopenharmony_ci                                         const JSHandle<JSTaggedValue> &options,
1804514f5e3Sopenharmony_ci                                         CompareStringsOption csOption,
1814514f5e3Sopenharmony_ci                                         bool cacheable);
1824514f5e3Sopenharmony_ci    // 21.1.3.11
1834514f5e3Sopenharmony_ci    static JSTaggedValue Match(EcmaRuntimeCallInfo *argv);
1844514f5e3Sopenharmony_ci
1854514f5e3Sopenharmony_ci    static JSTaggedValue MatchAll(EcmaRuntimeCallInfo *argv);
1864514f5e3Sopenharmony_ci    // 21.1.3.12
1874514f5e3Sopenharmony_ci    static JSTaggedValue Normalize(EcmaRuntimeCallInfo *argv);
1884514f5e3Sopenharmony_ci
1894514f5e3Sopenharmony_ci    static JSTaggedValue IsWellFormed(EcmaRuntimeCallInfo *argv);
1904514f5e3Sopenharmony_ci
1914514f5e3Sopenharmony_ci    static JSTaggedValue ToWellFormed(EcmaRuntimeCallInfo *argv);
1924514f5e3Sopenharmony_ci
1934514f5e3Sopenharmony_ci    static JSTaggedValue PadStart(EcmaRuntimeCallInfo *argv);
1944514f5e3Sopenharmony_ci
1954514f5e3Sopenharmony_ci    static JSTaggedValue PadEnd(EcmaRuntimeCallInfo *argv);
1964514f5e3Sopenharmony_ci    // 21.1.3.13
1974514f5e3Sopenharmony_ci    static JSTaggedValue Repeat(EcmaRuntimeCallInfo *argv);
1984514f5e3Sopenharmony_ci    // 21.1.3.14
1994514f5e3Sopenharmony_ci    static JSTaggedValue Replace(EcmaRuntimeCallInfo *argv);
2004514f5e3Sopenharmony_ci    // 21.1.3.14.1 Runtime Semantics: GetSubstitution()
2014514f5e3Sopenharmony_ci    static JSTaggedValue ReplaceAll(EcmaRuntimeCallInfo *argv);
2024514f5e3Sopenharmony_ci    // 21.1.3.15
2034514f5e3Sopenharmony_ci    static JSTaggedValue Search(EcmaRuntimeCallInfo *argv);
2044514f5e3Sopenharmony_ci    // 21.1.3.16
2054514f5e3Sopenharmony_ci    static JSTaggedValue Slice(EcmaRuntimeCallInfo *argv);
2064514f5e3Sopenharmony_ci    // 21.1.3.17
2074514f5e3Sopenharmony_ci    static JSTaggedValue Split(EcmaRuntimeCallInfo *argv);
2084514f5e3Sopenharmony_ci    // 21.1.3.18
2094514f5e3Sopenharmony_ci    static JSTaggedValue StartsWith(EcmaRuntimeCallInfo *argv);
2104514f5e3Sopenharmony_ci    // 21.1.3.19
2114514f5e3Sopenharmony_ci    static JSTaggedValue Substring(EcmaRuntimeCallInfo *argv);
2124514f5e3Sopenharmony_ci    // 21.1.3.20
2134514f5e3Sopenharmony_ci    static JSTaggedValue ToLocaleLowerCase(EcmaRuntimeCallInfo *argv);
2144514f5e3Sopenharmony_ci    // 21.1.3.21
2154514f5e3Sopenharmony_ci    static JSTaggedValue ToLocaleUpperCase(EcmaRuntimeCallInfo *argv);
2164514f5e3Sopenharmony_ci    // 21.1.3.22
2174514f5e3Sopenharmony_ci    static JSTaggedValue ToLowerCase(EcmaRuntimeCallInfo *argv);
2184514f5e3Sopenharmony_ci    // 21.1.3.23
2194514f5e3Sopenharmony_ci    static JSTaggedValue ToString(EcmaRuntimeCallInfo *argv);
2204514f5e3Sopenharmony_ci    // 21.1.3.24
2214514f5e3Sopenharmony_ci    static JSTaggedValue ToUpperCase(EcmaRuntimeCallInfo *argv);
2224514f5e3Sopenharmony_ci    // 21.1.3.25
2234514f5e3Sopenharmony_ci    static JSTaggedValue Trim(EcmaRuntimeCallInfo *argv);
2244514f5e3Sopenharmony_ci
2254514f5e3Sopenharmony_ci    static JSTaggedValue TrimStart(EcmaRuntimeCallInfo *argv);
2264514f5e3Sopenharmony_ci
2274514f5e3Sopenharmony_ci    static JSTaggedValue TrimEnd(EcmaRuntimeCallInfo *argv);
2284514f5e3Sopenharmony_ci
2294514f5e3Sopenharmony_ci    static JSTaggedValue TrimLeft(EcmaRuntimeCallInfo *argv);
2304514f5e3Sopenharmony_ci
2314514f5e3Sopenharmony_ci    static JSTaggedValue TrimRight(EcmaRuntimeCallInfo *argv);
2324514f5e3Sopenharmony_ci    // 21.1.3.26
2334514f5e3Sopenharmony_ci    static JSTaggedValue ValueOf(EcmaRuntimeCallInfo *argv);
2344514f5e3Sopenharmony_ci    // 21.1.3.27
2354514f5e3Sopenharmony_ci    static JSTaggedValue GetStringIterator(EcmaRuntimeCallInfo *argv);
2364514f5e3Sopenharmony_ci    // 21.1.3
2374514f5e3Sopenharmony_ci    static JSTaggedValue ThisStringValue(JSThread *thread, JSTaggedValue value);
2384514f5e3Sopenharmony_ci    // 21.1.2.27
2394514f5e3Sopenharmony_ci    static JSTaggedValue CreateIterator(EcmaRuntimeCallInfo *argv);
2404514f5e3Sopenharmony_ci    // 10.1.2
2414514f5e3Sopenharmony_ci    static uint16_t UTF16Decode(uint16_t lead, uint16_t trail);
2424514f5e3Sopenharmony_ci    // annexB B.2.3.1
2434514f5e3Sopenharmony_ci    static JSTaggedValue SubStr(EcmaRuntimeCallInfo *argv);
2444514f5e3Sopenharmony_ci    // 22.1.3.1
2454514f5e3Sopenharmony_ci    static JSTaggedValue At(EcmaRuntimeCallInfo *argv);
2464514f5e3Sopenharmony_ci
2474514f5e3Sopenharmony_ci    static JSTaggedValue GetLength(EcmaRuntimeCallInfo *argv);
2484514f5e3Sopenharmony_ci
2494514f5e3Sopenharmony_ci    // Excluding the '@@' internal properties
2504514f5e3Sopenharmony_ci    static Span<const base::BuiltinFunctionEntry> GetStringFunctions()
2514514f5e3Sopenharmony_ci    {
2524514f5e3Sopenharmony_ci        return Span<const base::BuiltinFunctionEntry>(STRING_FUNCTIONS);
2534514f5e3Sopenharmony_ci    }
2544514f5e3Sopenharmony_ci
2554514f5e3Sopenharmony_ci    // Excluding the constructor and '@@' internal properties.
2564514f5e3Sopenharmony_ci    static Span<const base::BuiltinFunctionEntry> GetStringPrototypeFunctions()
2574514f5e3Sopenharmony_ci    {
2584514f5e3Sopenharmony_ci        return Span<const base::BuiltinFunctionEntry>(STRING_PROTOTYPE_FUNCTIONS);
2594514f5e3Sopenharmony_ci    }
2604514f5e3Sopenharmony_ci
2614514f5e3Sopenharmony_ci    static size_t GetNumPrototypeInlinedProperties()
2624514f5e3Sopenharmony_ci    {
2634514f5e3Sopenharmony_ci        // 3 : 3 more inline properties in String.prototype:
2644514f5e3Sopenharmony_ci        //   (1) String.prototype.constructor
2654514f5e3Sopenharmony_ci        //   (2) String.prototype [ @@iterator ]
2664514f5e3Sopenharmony_ci        //   (3) get length
2674514f5e3Sopenharmony_ci        return GetStringPrototypeFunctions().Size() + 3;
2684514f5e3Sopenharmony_ci    }
2694514f5e3Sopenharmony_ci    static JSTaggedValue StringToList(JSThread *thread, JSHandle<EcmaString> &str);
2704514f5e3Sopenharmony_ci    static JSTaggedValue StringToSList(JSThread *thread, JSHandle<EcmaString> &str);
2714514f5e3Sopenharmony_ci
2724514f5e3Sopenharmony_ciprivate:
2734514f5e3Sopenharmony_ci#define BUILTIN_STRING_FUNCTION_ENTRY(name, method, length, builtinId) \
2744514f5e3Sopenharmony_ci    base::BuiltinFunctionEntry::Create(name, BuiltinsString::method, length, kungfu::BuiltinsStubCSigns::builtinId),
2754514f5e3Sopenharmony_ci
2764514f5e3Sopenharmony_ci    static constexpr std::array STRING_FUNCTIONS = {
2774514f5e3Sopenharmony_ci        BUILTIN_STRING_FUNCTIONS(BUILTIN_STRING_FUNCTION_ENTRY)
2784514f5e3Sopenharmony_ci    };
2794514f5e3Sopenharmony_ci    static constexpr std::array STRING_PROTOTYPE_FUNCTIONS = {
2804514f5e3Sopenharmony_ci        BUILTIN_STRING_PROTOTYPE_FUNCTIONS(BUILTIN_STRING_FUNCTION_ENTRY)
2814514f5e3Sopenharmony_ci    };
2824514f5e3Sopenharmony_ci#undef BUILTIN_STRING_FUNCTION_ENTRY
2834514f5e3Sopenharmony_ci
2844514f5e3Sopenharmony_ci    static JSTaggedValue Pad(EcmaRuntimeCallInfo *argv, bool isStart);
2854514f5e3Sopenharmony_ci    static int32_t ConvertDoubleToInt(double d);
2864514f5e3Sopenharmony_ci    static JSTaggedValue CreateArrayFromString(JSThread *thread, EcmaVM *ecmaVm,
2874514f5e3Sopenharmony_ci        const JSHandle<EcmaString> &thisString, uint32_t thisLength, uint32_t lim = UINT32_MAX - 1);
2884514f5e3Sopenharmony_ci    static JSTaggedValue CreateArrayBySplitString(JSThread *thread, EcmaVM *ecmaVm,
2894514f5e3Sopenharmony_ci        const JSHandle<EcmaString> &thisString, const JSHandle<EcmaString> &seperatorString,
2904514f5e3Sopenharmony_ci        uint32_t thisLength, uint32_t seperatorLength, uint32_t lim);
2914514f5e3Sopenharmony_ci    static JSTaggedValue CreateArrayThisStringAndSeperatorStringAreNotEmpty(
2924514f5e3Sopenharmony_ci        JSThread *thread, EcmaVM *ecmaVm,
2934514f5e3Sopenharmony_ci        const JSHandle<EcmaString> &thisString, const JSHandle<EcmaString> &seperatorString,
2944514f5e3Sopenharmony_ci        uint32_t thisLength, uint32_t seperatorLength, uint32_t lim = UINT32_MAX - 1);
2954514f5e3Sopenharmony_ci    static bool IsUTF16HighSurrogate(uint16_t ch)
2964514f5e3Sopenharmony_ci    {
2974514f5e3Sopenharmony_ci        return base::utf_helper::DECODE_LEAD_LOW <= ch && ch <= base::utf_helper::DECODE_LEAD_HIGH;
2984514f5e3Sopenharmony_ci    }
2994514f5e3Sopenharmony_ci    static bool IsUTF16LowSurrogate(uint16_t ch)
3004514f5e3Sopenharmony_ci    {
3014514f5e3Sopenharmony_ci        return base::utf_helper::DECODE_TRAIL_LOW <= ch && ch <= base::utf_helper::DECODE_TRAIL_HIGH;
3024514f5e3Sopenharmony_ci    }
3034514f5e3Sopenharmony_ci    static uint32_t UTF16SurrogatePairToCodePoint(uint16_t lead, uint16_t trail);
3044514f5e3Sopenharmony_ci    // 21.1.3.17.1
3054514f5e3Sopenharmony_ci};
3064514f5e3Sopenharmony_ci
3074514f5e3Sopenharmony_ciclass StringSplitResultCache : public TaggedArray {
3084514f5e3Sopenharmony_cipublic:
3094514f5e3Sopenharmony_ci    static StringSplitResultCache *Cast(TaggedObject *object)
3104514f5e3Sopenharmony_ci    {
3114514f5e3Sopenharmony_ci        return reinterpret_cast<StringSplitResultCache*>(object);
3124514f5e3Sopenharmony_ci    }
3134514f5e3Sopenharmony_ci    static JSTaggedValue CreateCacheTable(const JSThread *thread);
3144514f5e3Sopenharmony_ci    static JSTaggedValue FindCachedResult(const JSThread *thread, const JSHandle<StringSplitResultCache> &cache,
3154514f5e3Sopenharmony_ci        const JSHandle<EcmaString> &string, const JSHandle<EcmaString> &pattern, bool isOneByte = false);
3164514f5e3Sopenharmony_ci    static void SetCachedResult(const JSThread *thread, const JSHandle<StringSplitResultCache> &cache,
3174514f5e3Sopenharmony_ci        const JSHandle<EcmaString> &string, const JSHandle<EcmaString> &pattern,
3184514f5e3Sopenharmony_ci        const JSHandle<TaggedArray> &result);
3194514f5e3Sopenharmony_ci
3204514f5e3Sopenharmony_ciprivate:
3214514f5e3Sopenharmony_ci    static constexpr int CACHE_SIZE = 256;
3224514f5e3Sopenharmony_ci    static constexpr int STRING_INDEX = 0;
3234514f5e3Sopenharmony_ci    static constexpr int PATTERN_INDEX = 1;
3244514f5e3Sopenharmony_ci    static constexpr int ARRAY_INDEX = 2;
3254514f5e3Sopenharmony_ci    static constexpr int ENTRY_SIZE = 3;
3264514f5e3Sopenharmony_ci};
3274514f5e3Sopenharmony_ci
3284514f5e3Sopenharmony_ciclass StringToListResultCache : public TaggedArray {
3294514f5e3Sopenharmony_cipublic:
3304514f5e3Sopenharmony_ci    static StringToListResultCache *Cast(TaggedObject *object)
3314514f5e3Sopenharmony_ci    {
3324514f5e3Sopenharmony_ci        return reinterpret_cast<StringToListResultCache*>(object);
3334514f5e3Sopenharmony_ci    }
3344514f5e3Sopenharmony_ci    static JSTaggedValue CreateCacheTable(const JSThread *thread);
3354514f5e3Sopenharmony_ci    static JSTaggedValue FindCachedResult(const JSThread *thread, const JSHandle<StringToListResultCache> &cache,
3364514f5e3Sopenharmony_ci        const JSHandle<EcmaString> &string);
3374514f5e3Sopenharmony_ci    static void SetCachedResult(const JSThread *thread, const JSHandle<StringToListResultCache> &cache,
3384514f5e3Sopenharmony_ci        const JSHandle<EcmaString> &string, const JSHandle<TaggedArray> &result);
3394514f5e3Sopenharmony_ci
3404514f5e3Sopenharmony_ci    static constexpr int MAX_STRING_LENGTH = 20;
3414514f5e3Sopenharmony_ci    static constexpr int CACHE_SIZE = 128;
3424514f5e3Sopenharmony_ci    static constexpr int STRING_INDEX = 0;
3434514f5e3Sopenharmony_ci    static constexpr int ARRAY_INDEX = 1;
3444514f5e3Sopenharmony_ci    static constexpr int ENTRY_SIZE = 2;
3454514f5e3Sopenharmony_ci};
3464514f5e3Sopenharmony_ci}  // namespace panda::ecmascript::builtins
3474514f5e3Sopenharmony_ci#endif  // ECMASCRIPT_BUILTINS_BUILTINS_STRING_H
348