• 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_HASHMAP_H
17 #define ECMASCRIPT_CONTAINERS_CONTAINERS_HASHMAP_H
18 
19 #include "ecmascript/base/builtins_base.h"
20 #include "ecmascript/ecma_runtime_call_info.h"
21 
22 // List of functions in HashMap.prototype, excluding the constructor and '@@' properties.
23 // V(name, func, length, stubIndex)
24 // where ContainersHashMap::func refers to the native implementation of HashMap.prototype[name].
25 #define CONTAINER_HASHMAP_PROTOTYPE_FUNCTIONS(V)                                    \
26     V("set",            Set,            2,          INVALID)                        \
27     V("setAll",         SetAll,         1,          INVALID)                        \
28     V("isEmpty",        IsEmpty,        0,          INVALID)                        \
29     V("remove",         Remove,         1,          INVALID)                        \
30     V("clear",          Clear,          0,          INVALID)                        \
31     V("get",            Get,            1,          INVALID)                        \
32     V("forEach",        ForEach,        2,          HashMapForEach)                 \
33     V("hasKey",         HasKey,         1,          INVALID)                        \
34     V("hasValue",       HasValue,       1,          INVALID)                        \
35     V("replace",        Replace,        2,          INVALID)                        \
36     V("keys",           Keys,           0,          INVALID)                        \
37     V("values",         Values,         0,          INVALID)                        \
38     V("entries",        Entries,        0,          INVALID)
39 
40 namespace panda::ecmascript::containers {
41 class ContainersHashMap : public base::BuiltinsBase {
42 public:
43     static JSTaggedValue HashMapConstructor(EcmaRuntimeCallInfo *argv);
44     static JSTaggedValue HasKey(EcmaRuntimeCallInfo *argv);
45     static JSTaggedValue HasValue(EcmaRuntimeCallInfo *argv);
46     static JSTaggedValue Replace(EcmaRuntimeCallInfo *argv);
47     static JSTaggedValue Keys(EcmaRuntimeCallInfo *argv);
48     static JSTaggedValue Values(EcmaRuntimeCallInfo *argv);
49     static JSTaggedValue GetIteratorObj(EcmaRuntimeCallInfo *argv);
50     static JSTaggedValue Entries(EcmaRuntimeCallInfo *argv);
51     static JSTaggedValue ForEach(EcmaRuntimeCallInfo *argv);
52     static JSTaggedValue Set(EcmaRuntimeCallInfo *argv);
53     static JSTaggedValue SetAll(EcmaRuntimeCallInfo *argv);
54     static JSTaggedValue Remove(EcmaRuntimeCallInfo *argv);
55     static JSTaggedValue Get(EcmaRuntimeCallInfo *argv);
56     static JSTaggedValue Clear(EcmaRuntimeCallInfo *argv);
57     static JSTaggedValue GetLength(EcmaRuntimeCallInfo *argv);
58     static JSTaggedValue IsEmpty(EcmaRuntimeCallInfo *argv);
59 
60     // Excluding the constructor and '@@' internal properties.
GetHashMapPrototypeFunctions()61     static Span<const base::BuiltinFunctionEntry> GetHashMapPrototypeFunctions()
62     {
63         return Span<const base::BuiltinFunctionEntry>(HASHMAP_PROTOTYPE_FUNCTIONS);
64     }
65 
66 private:
67 #define CONTAINER_HASHMAP_FUNCTION_ENTRY(name, method, length, id) \
68     base::BuiltinFunctionEntry::Create(name, ContainersHashMap::method, length, BUILTINS_STUB_ID(id)),
69 
70     static constexpr std::array HASHMAP_PROTOTYPE_FUNCTIONS = {
71         CONTAINER_HASHMAP_PROTOTYPE_FUNCTIONS(CONTAINER_HASHMAP_FUNCTION_ENTRY)
72     };
73 #undef CONTAINER_HASHMAP_FUNCTION_ENTRY
74 };
75 }  // namespace panda::ecmascript::containers
76 #endif  // ECMASCRIPT_CONTAINERS_CONTAINERS_HASHMAP_H
77