• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_CONTAINERS_CONTAINERS_LIGHT_WEIGHT_SET_H
17 #define ECMASCRIPT_CONTAINERS_CONTAINERS_LIGHT_WEIGHT_SET_H
18 
19 #include "ecmascript/base/builtins_base.h"
20 #include "ecmascript/ecma_runtime_call_info.h"
21 
22 // List of functions in LightWeightSet.prototype, excluding the constructor and '@@' properties.
23 // V(name, func, length, stubIndex)
24 // where ContainersLightWeightSet::func refers to the native implementation of LightWeightSet.prototype[name].
25 #define CONTAINER_LIGHTWEIGHTSET_PROTOTYPE_FUNCTIONS(V)                                             \
26     V("add",                    Add,                    1,          INVALID)                        \
27     V("addAll",                 AddAll,                 1,          INVALID)                        \
28     V("isEmpty",                IsEmpty,                0,          INVALID)                        \
29     V("getValueAt",             GetValueAt,             1,          INVALID)                        \
30     V("hasAll",                 HasAll,                 1,          INVALID)                        \
31     V("has",                    Has,                    1,          INVALID)                        \
32     V("equal",                  Equal,                  1,          INVALID)                        \
33     V("increaseCapacityTo",     IncreaseCapacityTo,     1,          INVALID)                        \
34     V("forEach",                ForEach,                2,          LightWeightSetForEach)          \
35     V("getIndexOf",             GetIndexOf,             1,          INVALID)                        \
36     V("remove",                 Remove,                 1,          INVALID)                        \
37     V("removeAt",               RemoveAt,               1,          INVALID)                        \
38     V("clear",                  Clear,                  0,          INVALID)                        \
39     V("toString",               ToString,               0,          INVALID)                        \
40     V("toArray",                ToArray,                0,          INVALID)                        \
41     V("values",                 Values,                 0,          INVALID)                        \
42     V("entries",                Entries,                0,          INVALID)
43 
44 namespace panda::ecmascript::containers {
45 class ContainersLightWeightSet : public base::BuiltinsBase {
46 public:
47     static JSTaggedValue LightWeightSetConstructor(EcmaRuntimeCallInfo *argv);
48     static JSTaggedValue Add(EcmaRuntimeCallInfo *argv);
49     static JSTaggedValue AddAll(EcmaRuntimeCallInfo *argv);
50     static JSTaggedValue IsEmpty(EcmaRuntimeCallInfo *argv);
51     static JSTaggedValue GetValueAt(EcmaRuntimeCallInfo *argv);
52     static JSTaggedValue HasAll(EcmaRuntimeCallInfo *argv);
53     static JSTaggedValue Has(EcmaRuntimeCallInfo *argv);
54     static JSTaggedValue HasHash(EcmaRuntimeCallInfo *argv);
55     static JSTaggedValue Equal(EcmaRuntimeCallInfo *argv);
56     static JSTaggedValue IncreaseCapacityTo(EcmaRuntimeCallInfo *argv);
57     static JSTaggedValue ForEach(EcmaRuntimeCallInfo *argv);
58     static JSTaggedValue GetIndexOf(EcmaRuntimeCallInfo *argv);
59     static JSTaggedValue Remove(EcmaRuntimeCallInfo *argv);
60     static JSTaggedValue RemoveAt(EcmaRuntimeCallInfo *argv);
61     static JSTaggedValue Clear(EcmaRuntimeCallInfo *argv);
62     static JSTaggedValue ToString(EcmaRuntimeCallInfo *argv);
63     static JSTaggedValue ToArray(EcmaRuntimeCallInfo *argv);
64     static JSTaggedValue GetSize(EcmaRuntimeCallInfo *argv);
65     static JSTaggedValue GetIteratorObj(EcmaRuntimeCallInfo *argv);
66     static JSTaggedValue Values(EcmaRuntimeCallInfo *argv);
67     static JSTaggedValue Entries(EcmaRuntimeCallInfo *argv);
68 
69     // Excluding the constructor and '@@' internal properties.
GetLightWeightSetPrototypeFunctions()70     static Span<const base::BuiltinFunctionEntry> GetLightWeightSetPrototypeFunctions()
71     {
72         return Span<const base::BuiltinFunctionEntry>(LIGHTWEIGHTSET_PROTOTYPE_FUNCTIONS);
73     }
74 
75 private:
76 #define CONTAINER_LIGHTWEIGHTSET_FUNCTION_ENTRY(name, method, length, id) \
77     base::BuiltinFunctionEntry::Create(name, ContainersLightWeightSet::method, length, kungfu::BuiltinsStubCSigns::id),
78 
79     static constexpr std::array LIGHTWEIGHTSET_PROTOTYPE_FUNCTIONS = {
80         CONTAINER_LIGHTWEIGHTSET_PROTOTYPE_FUNCTIONS(CONTAINER_LIGHTWEIGHTSET_FUNCTION_ENTRY)
81     };
82 #undef CONTAINER_LIGHTWEIGHTSET_FUNCTION_ENTRY
83 };
84 }  // namespace panda::ecmascript::containers
85 #endif  // ECMASCRIPT_CONTAINERS_CONTAINERS_LIGHT_WEIGHT_SET_H
86