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_SYMBOL_H
174514f5e3Sopenharmony_ci#define ECMASCRIPT_BUILTINS_BUILTINS_SYMBOL_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#define BUILTIN_WELL_KNOWN_SYMBOLS(V)                   \
244514f5e3Sopenharmony_ci    V(hasInstance,        HasInstance)                  \
254514f5e3Sopenharmony_ci    V(isConcatSpreadable, IsConcatSpreadable)           \
264514f5e3Sopenharmony_ci    V(toStringTag,        ToStringTag)
274514f5e3Sopenharmony_ci
284514f5e3Sopenharmony_ci#define BUILTIN_PUBLIC_SYMBOLS(V)                       \
294514f5e3Sopenharmony_ci    V(asyncIterator, AsyncIterator)                     \
304514f5e3Sopenharmony_ci    V(iterator,      Iterator)                          \
314514f5e3Sopenharmony_ci    V(match,         Match)                             \
324514f5e3Sopenharmony_ci    V(matchAll,      MatchAll)                          \
334514f5e3Sopenharmony_ci    V(nativeBinding, NativeBinding)                     \
344514f5e3Sopenharmony_ci    V(replace,       Replace)                           \
354514f5e3Sopenharmony_ci    V(search,        Search)                            \
364514f5e3Sopenharmony_ci    V(species,       Species)                           \
374514f5e3Sopenharmony_ci    V(split,         Split)                             \
384514f5e3Sopenharmony_ci    V(toPrimitive,   ToPrimitive)                       \
394514f5e3Sopenharmony_ci    V(unscopables,   Unscopables)
404514f5e3Sopenharmony_ci
414514f5e3Sopenharmony_ci#define BUILTIN_ALL_SYMBOLS(V)      \
424514f5e3Sopenharmony_ci    BUILTIN_WELL_KNOWN_SYMBOLS(V)   \
434514f5e3Sopenharmony_ci    BUILTIN_PUBLIC_SYMBOLS(V)
444514f5e3Sopenharmony_ci
454514f5e3Sopenharmony_ci// List of functions in Symbol, excluding the '@@' properties.
464514f5e3Sopenharmony_ci// V(name, func, length, stubIndex)
474514f5e3Sopenharmony_ci// where BuiltinsSymbol::func refers to the native implementation of Symbol[name].
484514f5e3Sopenharmony_ci//       kungfu::BuiltinsStubCSigns::stubIndex refers to the builtin stub index, or INVALID if no stub available.
494514f5e3Sopenharmony_ci#define BUILTIN_SYMBOL_FUNCTIONS(V)             \
504514f5e3Sopenharmony_ci    V("for",    For,    1, INVALID)             \
514514f5e3Sopenharmony_ci    V("keyFor", KeyFor, 1, INVALID)
524514f5e3Sopenharmony_ci
534514f5e3Sopenharmony_ci// List of get accessors in Symbol.prototype, excluding the '@@' properties.
544514f5e3Sopenharmony_ci// V(name, func, length, stubIndex)
554514f5e3Sopenharmony_ci// where BuiltinsSymbol::func refers to the native implementation of Symbol.prototype[name].
564514f5e3Sopenharmony_ci#define BUILTIN_SYMBOL_PROTOTYPE_FUNCTIONS(V)   \
574514f5e3Sopenharmony_ci    V("toString", ToString, 0, INVALID)         \
584514f5e3Sopenharmony_ci    V("valueOf",  ValueOf,  0, INVALID)
594514f5e3Sopenharmony_ci
604514f5e3Sopenharmony_cinamespace panda::ecmascript::builtins {
614514f5e3Sopenharmony_ciclass BuiltinsSymbol : public base::BuiltinsBase {
624514f5e3Sopenharmony_cipublic:
634514f5e3Sopenharmony_ci    // 19.4.1
644514f5e3Sopenharmony_ci    static JSTaggedValue SymbolConstructor(EcmaRuntimeCallInfo *argv);
654514f5e3Sopenharmony_ci
664514f5e3Sopenharmony_ci    // prototype
674514f5e3Sopenharmony_ci    // 19.4.3.2
684514f5e3Sopenharmony_ci    static JSTaggedValue ToString(EcmaRuntimeCallInfo *argv);
694514f5e3Sopenharmony_ci    // 19.4.3.3
704514f5e3Sopenharmony_ci    static JSTaggedValue ValueOf(EcmaRuntimeCallInfo *argv);
714514f5e3Sopenharmony_ci    // 19.4.2.1 Symbol.for (key)
724514f5e3Sopenharmony_ci    static JSTaggedValue For(EcmaRuntimeCallInfo *argv);
734514f5e3Sopenharmony_ci    // 19.4.2.5 Symbol.keyFor (sym)
744514f5e3Sopenharmony_ci    static JSTaggedValue KeyFor(EcmaRuntimeCallInfo *argv);
754514f5e3Sopenharmony_ci
764514f5e3Sopenharmony_ci    // 19.4.3.2 get Symbol.prototype.description
774514f5e3Sopenharmony_ci    static JSTaggedValue DescriptionGetter(EcmaRuntimeCallInfo *argv);
784514f5e3Sopenharmony_ci
794514f5e3Sopenharmony_ci    static JSTaggedValue ThisSymbolValue(JSThread *thread, const JSHandle<JSTaggedValue> &value);
804514f5e3Sopenharmony_ci
814514f5e3Sopenharmony_ci    // 19.4.3.4
824514f5e3Sopenharmony_ci    static JSTaggedValue ToPrimitive(EcmaRuntimeCallInfo *argv);
834514f5e3Sopenharmony_ci
844514f5e3Sopenharmony_ci    static JSTaggedValue SymbolDescriptiveString(JSThread *thread, JSTaggedValue sym);
854514f5e3Sopenharmony_ci
864514f5e3Sopenharmony_ci    // Excluding the '@@' internal properties
874514f5e3Sopenharmony_ci    static Span<const base::BuiltinFunctionEntry> GetSymbolFunctions()
884514f5e3Sopenharmony_ci    {
894514f5e3Sopenharmony_ci        return Span<const base::BuiltinFunctionEntry>(SYMBOL_FUNCTIONS);
904514f5e3Sopenharmony_ci    }
914514f5e3Sopenharmony_ci
924514f5e3Sopenharmony_ci    // Excluding the constructor and '@@' internal properties.
934514f5e3Sopenharmony_ci    static Span<const base::BuiltinFunctionEntry> GetSymbolPrototypeFunctions()
944514f5e3Sopenharmony_ci    {
954514f5e3Sopenharmony_ci        return Span<const base::BuiltinFunctionEntry>(SYMBOL_PROTOTYPE_FUNCTIONS);
964514f5e3Sopenharmony_ci    }
974514f5e3Sopenharmony_ci
984514f5e3Sopenharmony_ciprivate:
994514f5e3Sopenharmony_ci#define BUILTIN_SYMBOL_FUNCTION_ENTRY(name, func, length, id) \
1004514f5e3Sopenharmony_ci    base::BuiltinFunctionEntry::Create(name, BuiltinsSymbol::func, length, kungfu::BuiltinsStubCSigns::id),
1014514f5e3Sopenharmony_ci
1024514f5e3Sopenharmony_ci    static constexpr std::array SYMBOL_FUNCTIONS = {
1034514f5e3Sopenharmony_ci        BUILTIN_SYMBOL_FUNCTIONS(BUILTIN_SYMBOL_FUNCTION_ENTRY)
1044514f5e3Sopenharmony_ci    };
1054514f5e3Sopenharmony_ci    static constexpr std::array SYMBOL_PROTOTYPE_FUNCTIONS = {
1064514f5e3Sopenharmony_ci        BUILTIN_SYMBOL_PROTOTYPE_FUNCTIONS(BUILTIN_SYMBOL_FUNCTION_ENTRY)
1074514f5e3Sopenharmony_ci    };
1084514f5e3Sopenharmony_ci#undef BUILTIN_TYPED_ARRAY_FUNCTION_ENTRY
1094514f5e3Sopenharmony_ci#undef BUILTIN_TYPED_ARRAY_ACCESSOR_ENTRY
1104514f5e3Sopenharmony_ci};
1114514f5e3Sopenharmony_ci}  // namespace panda::ecmascript::builtins
1124514f5e3Sopenharmony_ci#endif  // ECMASCRIPT_BUILTINS_BUILTINS_SYMBOL_H
113