• 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_TREESET_H
17 #define ECMASCRIPT_CONTAINERS_CONTAINERS_TREESET_H
18 
19 #include "ecmascript/base/builtins_base.h"
20 #include "ecmascript/ecma_runtime_call_info.h"
21 
22 // List of functions in TreeSet.prototype, excluding the constructor and '@@' properties.
23 // V(name, func, length, stubIndex)
24 // where ContainersTreeSet::func refers to the native implementation of TreeSet.prototype[name].
25 #define CONTAINER_TREESET_PROTOTYPE_FUNCTIONS(V)                                \
26     V("add",                    Add,                1,          INVALID)        \
27     V("remove",                 Remove,             1,          INVALID)        \
28     V("has",                    Has,                1,          INVALID)        \
29     V("getFirstValue",          GetFirstValue,      0,          INVALID)        \
30     V("getLastValue",           GetLastValue,       0,          INVALID)        \
31     V("clear",                  Clear,              0,          INVALID)        \
32     V("getLowerValue",          GetLowerValue,      1,          INVALID)        \
33     V("getHigherValue",         GetHigherValue,     1,          INVALID)        \
34     V("popFirst",               PopFirst,           0,          INVALID)        \
35     V("popLast",                PopLast,            0,          INVALID)        \
36     V("isEmpty",                IsEmpty,            0,          INVALID)        \
37     V("values",                 Values,             0,          INVALID)        \
38     V("forEach",                ForEach,            2,          INVALID)        \
39     V("entries",                Entries,            0,          INVALID)
40 
41 namespace panda::ecmascript::containers {
42 /**
43  * High performance container interface in jsapi.
44  * TreeSet provides ordered sets.
45  * */
46 class ContainersTreeSet : public base::BuiltinsBase {
47 public:
48     static JSTaggedValue TreeSetConstructor(EcmaRuntimeCallInfo *argv);
49 
50     static JSTaggedValue Add(EcmaRuntimeCallInfo *argv);
51 
52     static JSTaggedValue Remove(EcmaRuntimeCallInfo *argv);
53     static JSTaggedValue Clear(EcmaRuntimeCallInfo *argv);
54 
55     static JSTaggedValue Has(EcmaRuntimeCallInfo *argv);
56 
57     static JSTaggedValue GetFirstValue(EcmaRuntimeCallInfo *argv);
58     static JSTaggedValue GetLastValue(EcmaRuntimeCallInfo *argv);
59 
60     static JSTaggedValue GetLowerValue(EcmaRuntimeCallInfo *argv);
61     static JSTaggedValue GetHigherValue(EcmaRuntimeCallInfo *argv);
62 
63     static JSTaggedValue PopFirst(EcmaRuntimeCallInfo *argv);
64     static JSTaggedValue PopLast(EcmaRuntimeCallInfo *argv);
65 
66     static JSTaggedValue IsEmpty(EcmaRuntimeCallInfo *argv);
67     static JSTaggedValue GetLength(EcmaRuntimeCallInfo *argv);
68 
69     static JSTaggedValue Values(EcmaRuntimeCallInfo *argv);
70     static JSTaggedValue ForEach(EcmaRuntimeCallInfo *argv);
71     static JSTaggedValue Entries(EcmaRuntimeCallInfo *argv);
72 
73     // Excluding the constructor and '@@' internal properties.
GetTreeSetPrototypeFunctions()74     static Span<const base::BuiltinFunctionEntry> GetTreeSetPrototypeFunctions()
75     {
76         return Span<const base::BuiltinFunctionEntry>(TREESET_PROTOTYPE_FUNCTIONS);
77     }
78 
79 private:
80 #define CONTAINER_TREESET_FUNCTION_ENTRY(name, method, length, id) \
81     base::BuiltinFunctionEntry::Create(name, ContainersTreeSet::method, length, kungfu::BuiltinsStubCSigns::id),
82 
83     static constexpr std::array TREESET_PROTOTYPE_FUNCTIONS = {
84         CONTAINER_TREESET_PROTOTYPE_FUNCTIONS(CONTAINER_TREESET_FUNCTION_ENTRY)
85     };
86 #undef CONTAINER_TREESET_FUNCTION_ENTRY
87 };
88 }  // namespace panda::ecmascript::containers
89 #endif  // ECMASCRIPT_CONTAINERS_CONTAINERS_TREESET_H_
90