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_SET_H
174514f5e3Sopenharmony_ci#define ECMASCRIPT_BUILTINS_BUILTINS_SET_H
184514f5e3Sopenharmony_ci
194514f5e3Sopenharmony_ci#include "ecmascript/base/builtins_base.h"
204514f5e3Sopenharmony_ci#include "ecmascript/ecma_runtime_call_info.h"
214514f5e3Sopenharmony_ci
224514f5e3Sopenharmony_ci// List of functions in Set, excluding the constructor and '@@' properties.
234514f5e3Sopenharmony_ci// V(name, func, length, stubIndex)
244514f5e3Sopenharmony_ci// where BuiltinsSet::func refers to the native implementation of Set.prototype[name].
254514f5e3Sopenharmony_ci//       kungfu::BuiltinsStubCSigns::stubIndex refers to the builtin stub index, or INVALID if no stub available.
264514f5e3Sopenharmony_ci// The following functions are not listed:
274514f5e3Sopenharmony_ci//   - Set.prototype.keys ( ), which is strictly equal to Set.prototype.values
284514f5e3Sopenharmony_ci#define BUILTIN_SET_PROTOTYPE_FUNCTIONS(V)                      \
294514f5e3Sopenharmony_ci    /* Set.prototype.add ( value ) */                           \
304514f5e3Sopenharmony_ci    V("add",     Add,     1, SetAdd)                            \
314514f5e3Sopenharmony_ci    /* Set.prototype.clear ( ) */                               \
324514f5e3Sopenharmony_ci    V("clear",   Clear,   0, SetClear)                          \
334514f5e3Sopenharmony_ci    /* Set.prototype.delete ( value ) */                        \
344514f5e3Sopenharmony_ci    V("delete",  Delete,  1, SetDelete)                         \
354514f5e3Sopenharmony_ci    /* Set.prototype.entries ( ) */                             \
364514f5e3Sopenharmony_ci    V("entries", Entries, 0, SetEntries)                        \
374514f5e3Sopenharmony_ci    /* Set.prototype.forEach ( callbackfn [ , thisArg ] ) */    \
384514f5e3Sopenharmony_ci    V("forEach", ForEach, 1, SetForEach)                        \
394514f5e3Sopenharmony_ci    /* Set.prototype.has ( value ) */                           \
404514f5e3Sopenharmony_ci    V("has",     Has,     1, SetHas)                            \
414514f5e3Sopenharmony_ci    /* Set.prototype.values ( ) */                              \
424514f5e3Sopenharmony_ci    V("values",  Values,  0, SetValues)
434514f5e3Sopenharmony_ci
444514f5e3Sopenharmony_cinamespace panda::ecmascript::builtins {
454514f5e3Sopenharmony_ciclass BuiltinsSet : public base::BuiltinsBase {
464514f5e3Sopenharmony_cipublic:
474514f5e3Sopenharmony_ci    // 23.2.1.1
484514f5e3Sopenharmony_ci    static JSTaggedValue SetConstructor(EcmaRuntimeCallInfo *argv);
494514f5e3Sopenharmony_ci    // 23.2.2.2
504514f5e3Sopenharmony_ci    static JSTaggedValue Species(EcmaRuntimeCallInfo *argv);
514514f5e3Sopenharmony_ci    // 23.2.3.1
524514f5e3Sopenharmony_ci    static JSTaggedValue Add(EcmaRuntimeCallInfo *argv);
534514f5e3Sopenharmony_ci    // 23.2.3.2
544514f5e3Sopenharmony_ci    static JSTaggedValue Clear(EcmaRuntimeCallInfo *argv);
554514f5e3Sopenharmony_ci    // 23.2.3.4
564514f5e3Sopenharmony_ci    static JSTaggedValue Delete(EcmaRuntimeCallInfo *argv);
574514f5e3Sopenharmony_ci    // 23.2.3.5
584514f5e3Sopenharmony_ci    static JSTaggedValue Entries(EcmaRuntimeCallInfo *argv);
594514f5e3Sopenharmony_ci    // 23.2.3.6
604514f5e3Sopenharmony_ci    static JSTaggedValue ForEach(EcmaRuntimeCallInfo *argv);
614514f5e3Sopenharmony_ci    // 23.2.3.7
624514f5e3Sopenharmony_ci    static JSTaggedValue Has(EcmaRuntimeCallInfo *argv);
634514f5e3Sopenharmony_ci    // 23.2.3.9
644514f5e3Sopenharmony_ci    static JSTaggedValue GetSize(EcmaRuntimeCallInfo *argv);
654514f5e3Sopenharmony_ci    // 23.2.3.10
664514f5e3Sopenharmony_ci    static JSTaggedValue Values(EcmaRuntimeCallInfo *argv);
674514f5e3Sopenharmony_ci
684514f5e3Sopenharmony_ci    // Excluding the '@@' internal properties
694514f5e3Sopenharmony_ci    static Span<const base::BuiltinFunctionEntry> GetSetPrototypeFunctions()
704514f5e3Sopenharmony_ci    {
714514f5e3Sopenharmony_ci        return Span<const base::BuiltinFunctionEntry>(SET_PROTOTYPE_FUNCTIONS);
724514f5e3Sopenharmony_ci    }
734514f5e3Sopenharmony_ci
744514f5e3Sopenharmony_ci    static size_t GetNumPrototypeInlinedProperties()
754514f5e3Sopenharmony_ci    {
764514f5e3Sopenharmony_ci        // 5 : 5 more inline properties in Set.prototype
774514f5e3Sopenharmony_ci        //   (1) Set.prototype.constructor
784514f5e3Sopenharmony_ci        //   (2) Set.prototype [ @@toStringTag ]
794514f5e3Sopenharmony_ci        //   (3) Set.prototype [ @@iterator ]
804514f5e3Sopenharmony_ci        //   (4) get Set.prototype.size
814514f5e3Sopenharmony_ci        //   (5) Set.prototype.keys, which is not included in BuiltinsSet::GetSetPrototypeFunctions()
824514f5e3Sopenharmony_ci        return GetSetPrototypeFunctions().Size() + 5;
834514f5e3Sopenharmony_ci    }
844514f5e3Sopenharmony_ci
854514f5e3Sopenharmony_ciprivate:
864514f5e3Sopenharmony_ci#define BUILTIN_SET_FUNCTION_ENTRY(name, func, length, id) \
874514f5e3Sopenharmony_ci    base::BuiltinFunctionEntry::Create(name, BuiltinsSet::func, length, kungfu::BuiltinsStubCSigns::id),
884514f5e3Sopenharmony_ci
894514f5e3Sopenharmony_ci    static constexpr std::array SET_PROTOTYPE_FUNCTIONS = {
904514f5e3Sopenharmony_ci        BUILTIN_SET_PROTOTYPE_FUNCTIONS(BUILTIN_SET_FUNCTION_ENTRY)
914514f5e3Sopenharmony_ci    };
924514f5e3Sopenharmony_ci
934514f5e3Sopenharmony_ci#undef BUILTIN_SET_FUNCTION_ENTRY
944514f5e3Sopenharmony_ci};
954514f5e3Sopenharmony_ci}  // namespace panda::ecmascript::builtins
964514f5e3Sopenharmony_ci#endif  // ECMASCRIPT_BUILTINS_BUILTINS_SET_H
97