• 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_TREEMAP_H
17 #define ECMASCRIPT_CONTAINERS_CONTAINERS_TREEMAP_H
18 
19 #include "ecmascript/base/builtins_base.h"
20 #include "ecmascript/ecma_runtime_call_info.h"
21 
22 // List of functions in TreeMap.prototype, excluding the constructor and '@@' properties.
23 // V(name, func, length, stubIndex)
24 // where ContainersTreeMap::func refers to the native implementation of TreeMap.prototype[name].
25 #define CONTAINER_TREEMAP_PROTOTYPE_FUNCTIONS(V)                                \
26     V("set",                    Set,                2,          INVALID)        \
27     V("get",                    Get,                1,          INVALID)        \
28     V("remove",                 Remove,             1,          INVALID)        \
29     V("hasKey",                 HasKey,             1,          INVALID)        \
30     V("hasValue",               HasValue,           1,          INVALID)        \
31     V("getFirstKey",            GetFirstKey,        0,          INVALID)        \
32     V("getLastKey",             GetLastKey,         0,          INVALID)        \
33     V("setAll",                 SetAll,             1,          INVALID)        \
34     V("clear",                  Clear,              0,          INVALID)        \
35     V("getLowerKey",            GetLowerKey,        1,          INVALID)        \
36     V("getHigherKey",           GetHigherKey,       1,          INVALID)        \
37     V("keys",                   Keys,               0,          INVALID)        \
38     V("values",                 Values,             0,          INVALID)        \
39     V("replace",                Replace,            2,          INVALID)        \
40     V("forEach",                ForEach,            2,          INVALID)        \
41     V("isEmpty",                IsEmpty,            0,          INVALID)        \
42     V("entries",                Entries,            0,          INVALID)
43 
44 namespace panda::ecmascript::containers {
45 /**
46  * High performance container interface in jsapi.
47  * TreeMap provides ordered maps.
48  * */
49 class ContainersTreeMap : public base::BuiltinsBase {
50 public:
51     static JSTaggedValue TreeMapConstructor(EcmaRuntimeCallInfo *argv);
52 
53     static JSTaggedValue HasKey(EcmaRuntimeCallInfo *argv);
54     static JSTaggedValue HasValue(EcmaRuntimeCallInfo *argv);
55 
56     static JSTaggedValue GetFirstKey(EcmaRuntimeCallInfo *argv);
57     static JSTaggedValue GetLastKey(EcmaRuntimeCallInfo *argv);
58 
59     static JSTaggedValue Set(EcmaRuntimeCallInfo *argv);
60     static JSTaggedValue Get(EcmaRuntimeCallInfo *argv);
61     static JSTaggedValue SetAll(EcmaRuntimeCallInfo *argv);
62 
63     static JSTaggedValue Remove(EcmaRuntimeCallInfo *argv);
64     static JSTaggedValue Clear(EcmaRuntimeCallInfo *argv);
65 
66     static JSTaggedValue GetLowerKey(EcmaRuntimeCallInfo *argv);
67     static JSTaggedValue GetHigherKey(EcmaRuntimeCallInfo *argv);
68 
69     static JSTaggedValue Replace(EcmaRuntimeCallInfo *argv);
70     static JSTaggedValue IsEmpty(EcmaRuntimeCallInfo *argv);
71     static JSTaggedValue GetLength(EcmaRuntimeCallInfo *argv);
72 
73     static JSTaggedValue Keys(EcmaRuntimeCallInfo *argv);
74     static JSTaggedValue Values(EcmaRuntimeCallInfo *argv);
75     static JSTaggedValue Entries(EcmaRuntimeCallInfo *argv);
76     static JSTaggedValue ForEach(EcmaRuntimeCallInfo *argv);
77 
78     // Excluding the constructor and '@@' internal properties.
GetTreeMapPrototypeFunctions()79     static Span<const base::BuiltinFunctionEntry> GetTreeMapPrototypeFunctions()
80     {
81         return Span<const base::BuiltinFunctionEntry>(TREEMAP_PROTOTYPE_FUNCTIONS);
82     }
83 
84 private:
85 #define CONTAINER_TREEMAP_FUNCTION_ENTRY(name, method, length, id) \
86     base::BuiltinFunctionEntry::Create(name, ContainersTreeMap::method, length, kungfu::BuiltinsStubCSigns::id),
87 
88     static constexpr std::array TREEMAP_PROTOTYPE_FUNCTIONS = {
89         CONTAINER_TREEMAP_PROTOTYPE_FUNCTIONS(CONTAINER_TREEMAP_FUNCTION_ENTRY)
90     };
91 #undef CONTAINER_TREEMAP_FUNCTION_ENTRY
92 };
93 }  // namespace panda::ecmascript::containers
94 #endif  // ECMASCRIPT_CONTAINERS_CONTAINERS_TREEMAP_H_
95