• 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_LINKED_LIST_H
17 #define ECMASCRIPT_CONTAINERS_CONTAINERS_LINKED_LIST_H
18 
19 #include "ecmascript/base/builtins_base.h"
20 #include "ecmascript/ecma_runtime_call_info.h"
21 
22 // List of functions in LinkedList.prototype, excluding the constructor and '@@' properties.
23 // V(name, func, length, stubIndex)
24 // where ContainersLinkedList::func refers to the native implementation of LinkedList.prototype[name].
25 #define CONTAINER_LINKEDLIST_PROTOTYPE_FUNCTIONS(V)                                         \
26     V("add",                    Add,                    1,          INVALID)                \
27     V("insert",                 Insert,                 2,          INVALID)                \
28     V("clear",                  Clear,                  0,          INVALID)                \
29     V("clone",                  Clone,                  0,          INVALID)                \
30     V("removeFirst",            RemoveFirst,            0,          INVALID)                \
31     V("removeLast",             RemoveLast,             0,          INVALID)                \
32     V("removeFirstFound",       RemoveFirstFound,       1,          INVALID)                \
33     V("removeByIndex",          RemoveByIndex,          1,          INVALID)                \
34     V("remove",                 Remove,                 1,          INVALID)                \
35     V("removeLastFound",        RemoveLastFound,        1,          INVALID)                \
36     V("has",                    Has,                    1,          INVALID)                \
37     V("get",                    Get,                    1,          INVALID)                \
38     V("addFirst",               AddFirst,               1,          INVALID)                \
39     V("getFirst",               GetFirst,               0,          INVALID)                \
40     V("getLast",                GetLast,                0,          INVALID)                \
41     V("getIndexOf",             GetIndexOf,             1,          INVALID)                \
42     V("getLastIndexOf",         GetLastIndexOf,         1,          INVALID)                \
43     V("convertToArray",         ConvertToArray,         0,          INVALID)                \
44     V("set",                    Set,                    2,          INVALID)                \
45     V("forEach",                ForEach,                2,          LinkedListForEach)
46 
47 namespace panda::ecmascript::containers {
48 class ContainersLinkedList : public base::BuiltinsBase {
49 public:
50     static JSTaggedValue LinkedListConstructor(EcmaRuntimeCallInfo *argv);
51 
52     static JSTaggedValue Add(EcmaRuntimeCallInfo *argv);
53     static JSTaggedValue GetFirst(EcmaRuntimeCallInfo *argv);
54     static JSTaggedValue GetLast(EcmaRuntimeCallInfo *argv);
55     static JSTaggedValue Insert(EcmaRuntimeCallInfo *argv);
56     static JSTaggedValue AddFirst(EcmaRuntimeCallInfo *argv);
57     static JSTaggedValue Clear(EcmaRuntimeCallInfo *argv);
58     static JSTaggedValue Clone(EcmaRuntimeCallInfo *argv);
59     static JSTaggedValue Has(EcmaRuntimeCallInfo *argv);
60     static JSTaggedValue Get(EcmaRuntimeCallInfo *argv);
61     static JSTaggedValue GetIndexOf(EcmaRuntimeCallInfo *argv);
62     static JSTaggedValue GetLastIndexOf(EcmaRuntimeCallInfo *argv);
63     static JSTaggedValue RemoveByIndex(EcmaRuntimeCallInfo *argv);
64     static JSTaggedValue Remove(EcmaRuntimeCallInfo *argv);
65     static JSTaggedValue RemoveFirst(EcmaRuntimeCallInfo *argv);
66     static JSTaggedValue RemoveFirstFound(EcmaRuntimeCallInfo *argv);
67     static JSTaggedValue RemoveLast(EcmaRuntimeCallInfo *argv);
68     static JSTaggedValue RemoveLastFound(EcmaRuntimeCallInfo *argv);
69     static JSTaggedValue Set(EcmaRuntimeCallInfo *argv);
70     static JSTaggedValue Length(EcmaRuntimeCallInfo *argv);
71     static JSTaggedValue ConvertToArray(EcmaRuntimeCallInfo *argv);
72     static JSTaggedValue ForEach(EcmaRuntimeCallInfo *argv);
73     static JSTaggedValue GetIteratorObj(EcmaRuntimeCallInfo *argv);
74 
75     // Excluding the constructor and '@@' internal properties.
GetLinkedListPrototypeFunctions()76     static Span<const base::BuiltinFunctionEntry> GetLinkedListPrototypeFunctions()
77     {
78         return Span<const base::BuiltinFunctionEntry>(LINKEDLIST_PROTOTYPE_FUNCTIONS);
79     }
80 
81 private:
82 #define CONTAINER_LINKEDLIST_FUNCTION_ENTRY(name, method, length, id) \
83     base::BuiltinFunctionEntry::Create(name, ContainersLinkedList::method, length, kungfu::BuiltinsStubCSigns::id),
84 
85     static constexpr std::array LINKEDLIST_PROTOTYPE_FUNCTIONS = {
86         CONTAINER_LINKEDLIST_PROTOTYPE_FUNCTIONS(CONTAINER_LINKEDLIST_FUNCTION_ENTRY)
87     };
88 #undef CONTAINER_LINKEDLIST_FUNCTION_ENTRY
89 
90 };
91 }  // namespace panda::ecmascript::containers
92 #endif  // ECMASCRIPT_CONTAINERS_CONTAINERS_LINKED_LIST_H
93