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_MAP_H
174514f5e3Sopenharmony_ci#define ECMASCRIPT_BUILTINS_BUILTINS_MAP_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 Map.prototype, excluding the constructor and '@@' properties.
234514f5e3Sopenharmony_ci// V(name, func, length, stubIndex)
244514f5e3Sopenharmony_ci// where BuiltinsMap::func refers to the native implementation of Map.prototype[name].
254514f5e3Sopenharmony_ci//       kungfu::BuiltinsStubCSigns::stubIndex refers to the builtin stub index, or INVALID if no stub available.
264514f5e3Sopenharmony_ci#define BUILTIN_MAP_PROTOTYPE_FUNCTIONS(V)                      \
274514f5e3Sopenharmony_ci    /* Map.prototype.clear ( ) */                               \
284514f5e3Sopenharmony_ci    V("clear",   Clear,   0, MapClear)                          \
294514f5e3Sopenharmony_ci    /* Map.prototype.delete ( key ) */                          \
304514f5e3Sopenharmony_ci    V("delete",  Delete,  1, MapDelete)                         \
314514f5e3Sopenharmony_ci    /* Map.prototype.entries ( ) */                             \
324514f5e3Sopenharmony_ci    V("entries", Entries, 0, MapEntries)                        \
334514f5e3Sopenharmony_ci    /* Map.prototype.forEach ( callbackfn [ , thisArg ] ) */    \
344514f5e3Sopenharmony_ci    V("forEach", ForEach, 1, MapForEach)                        \
354514f5e3Sopenharmony_ci    /* Map.prototype.get ( key ) */                             \
364514f5e3Sopenharmony_ci    V("get",     Get,     1, MapGet)                            \
374514f5e3Sopenharmony_ci    /* Map.prototype.has ( key ) */                             \
384514f5e3Sopenharmony_ci    V("has",     Has,     1, MapHas)                            \
394514f5e3Sopenharmony_ci    /* Map.prototype.keys ( ) */                                \
404514f5e3Sopenharmony_ci    V("keys",    Keys,    0, MapKeys)                           \
414514f5e3Sopenharmony_ci    /* Map.prototype.set ( key, value ) */                      \
424514f5e3Sopenharmony_ci    V("set",     Set,     2, MapSet)                            \
434514f5e3Sopenharmony_ci    /* Map.prototype.values ( ) */                              \
444514f5e3Sopenharmony_ci    V("values",  Values,  0, MapValues)
454514f5e3Sopenharmony_ci
464514f5e3Sopenharmony_cinamespace panda::ecmascript::builtins {
474514f5e3Sopenharmony_ciclass BuiltinsMap : public base::BuiltinsBase {
484514f5e3Sopenharmony_cipublic:
494514f5e3Sopenharmony_ci    // 23.1.1.1
504514f5e3Sopenharmony_ci    static JSTaggedValue MapConstructor(EcmaRuntimeCallInfo *argv);
514514f5e3Sopenharmony_ci    // 23.1.2.2
524514f5e3Sopenharmony_ci    static JSTaggedValue Species(EcmaRuntimeCallInfo *argv);
534514f5e3Sopenharmony_ci    // 23.1.3.1
544514f5e3Sopenharmony_ci    static JSTaggedValue Clear(EcmaRuntimeCallInfo *argv);
554514f5e3Sopenharmony_ci    // 23.1.3.3
564514f5e3Sopenharmony_ci    static JSTaggedValue Delete(EcmaRuntimeCallInfo *argv);
574514f5e3Sopenharmony_ci    // 23.1.3.4
584514f5e3Sopenharmony_ci    static JSTaggedValue Entries(EcmaRuntimeCallInfo *argv);
594514f5e3Sopenharmony_ci    // 23.1.3.5
604514f5e3Sopenharmony_ci    static JSTaggedValue ForEach(EcmaRuntimeCallInfo *argv);
614514f5e3Sopenharmony_ci    // 23.1.3.6
624514f5e3Sopenharmony_ci    static JSTaggedValue Get(EcmaRuntimeCallInfo *argv);
634514f5e3Sopenharmony_ci    // 23.1.3.7
644514f5e3Sopenharmony_ci    static JSTaggedValue Has(EcmaRuntimeCallInfo *argv);
654514f5e3Sopenharmony_ci    // 23.1.3.8
664514f5e3Sopenharmony_ci    static JSTaggedValue Keys(EcmaRuntimeCallInfo *argv);
674514f5e3Sopenharmony_ci    // 23.1.3.9
684514f5e3Sopenharmony_ci    static JSTaggedValue Set(EcmaRuntimeCallInfo *argv);
694514f5e3Sopenharmony_ci    // 23.1.3.10
704514f5e3Sopenharmony_ci    static JSTaggedValue GetSize(EcmaRuntimeCallInfo *argv);
714514f5e3Sopenharmony_ci    // 23.1.3.11
724514f5e3Sopenharmony_ci    static JSTaggedValue Values(EcmaRuntimeCallInfo *argv);
734514f5e3Sopenharmony_ci
744514f5e3Sopenharmony_ci    // es12 24.1.1.2 AddEntriesFromIterable ( target, iterable, adder )
754514f5e3Sopenharmony_ci    static JSTaggedValue AddEntriesFromIterable(JSThread *thread, const JSHandle<JSObject> &target,
764514f5e3Sopenharmony_ci                                                const JSHandle<JSTaggedValue> &iterable,
774514f5e3Sopenharmony_ci                                                const JSHandle<JSTaggedValue> &adder, ObjectFactory *factory);
784514f5e3Sopenharmony_ci
794514f5e3Sopenharmony_ci    // Excluding the constructor and '@@' internal properties.
804514f5e3Sopenharmony_ci    static Span<const base::BuiltinFunctionEntry> GetMapPrototypeFunctions()
814514f5e3Sopenharmony_ci    {
824514f5e3Sopenharmony_ci        return Span<const base::BuiltinFunctionEntry>(MAP_PROTOTYPE_FUNCTIONS);
834514f5e3Sopenharmony_ci    }
844514f5e3Sopenharmony_ci
854514f5e3Sopenharmony_ci    static size_t GetNumPrototypeInlinedProperties()
864514f5e3Sopenharmony_ci    {
874514f5e3Sopenharmony_ci        // 4 : 4 more inline properties in Map.prototype
884514f5e3Sopenharmony_ci        //   (1) Map.prototype.constructor
894514f5e3Sopenharmony_ci        //   (2) Map.prototype [ @@toStringTag ]
904514f5e3Sopenharmony_ci        //   (3) Map.prototype [ @@iterator ] ( )
914514f5e3Sopenharmony_ci        //   (4) get Map.prototype.size
924514f5e3Sopenharmony_ci        return GetMapPrototypeFunctions().Size() + 4;
934514f5e3Sopenharmony_ci    }
944514f5e3Sopenharmony_ci
954514f5e3Sopenharmony_ciprivate:
964514f5e3Sopenharmony_ci#define BUILTIN_MAP_FUNCTION_ENTRY(name, func, length, id) \
974514f5e3Sopenharmony_ci    base::BuiltinFunctionEntry::Create(name, BuiltinsMap::func, length, kungfu::BuiltinsStubCSigns::id),
984514f5e3Sopenharmony_ci
994514f5e3Sopenharmony_ci    static constexpr std::array MAP_PROTOTYPE_FUNCTIONS = {
1004514f5e3Sopenharmony_ci        BUILTIN_MAP_PROTOTYPE_FUNCTIONS(BUILTIN_MAP_FUNCTION_ENTRY)
1014514f5e3Sopenharmony_ci    };
1024514f5e3Sopenharmony_ci
1034514f5e3Sopenharmony_ci#undef BUILTIN_MAP_FUNCTION_ENTRY
1044514f5e3Sopenharmony_ci};
1054514f5e3Sopenharmony_ci}  // namespace panda::ecmascript::builtins
1064514f5e3Sopenharmony_ci#endif  // ECMASCRIPT_BUILTINS_BUILTINS_MAP_H
107