• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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_JS_API_JS_API_HASHMAP_H
17 #define ECMASCRIPT_JS_API_JS_API_HASHMAP_H
18 
19 #include "ecmascript/js_object-inl.h"
20 #include "ecmascript/js_object.h"
21 #include "ecmascript/js_tagged_value-inl.h"
22 #include "ecmascript/tagged_node.h"
23 
24 namespace panda::ecmascript {
25 class JSAPIHashMap : public JSObject {
26 public:
Cast(TaggedObject * object)27     static JSAPIHashMap *Cast(TaggedObject *object)
28     {
29         ASSERT(JSTaggedValue(object).IsJSAPIHashMap());
30         return static_cast<JSAPIHashMap *>(object);
31     }
32 
33     static void Set(JSThread *thread, JSHandle<JSAPIHashMap> hashMap,
34                     JSHandle<JSTaggedValue> key, JSHandle<JSTaggedValue> value);
35     static JSTaggedValue HasValue(JSThread *thread, JSHandle<JSAPIHashMap> hashMap,
36                                   JSHandle<JSTaggedValue> value);
37     static void SetAll(JSThread *thread, JSHandle<JSAPIHashMap> dst, JSHandle<JSAPIHashMap> src);
38     static JSTaggedValue Remove(JSThread *thread, JSHandle<JSAPIHashMap> hashMap, JSTaggedValue key);
39     JSTaggedValue IsEmpty();
40     JSTaggedValue HasKey(JSThread *thread, JSTaggedValue key);
41     JSTaggedValue Replace(JSThread *thread, JSTaggedValue key, JSTaggedValue newValue);
42     void Clear(JSThread *thread);
43     JSTaggedValue Get(JSThread *thread, JSTaggedValue key);
GetLength()44     inline JSTaggedValue GetLength()
45     {
46         return JSTaggedValue(GetSize());
47     }
48 
49     static constexpr size_t HASHMAP_TABLE_INDEX = JSObject::SIZE;
50     ACCESSORS(Table, HASHMAP_TABLE_INDEX, HASHMAP_SIZE_OFFSET);
51     ACCESSORS_PRIMITIVE_FIELD(Size, uint32_t, HASHMAP_SIZE_OFFSET, LAST_OFFSET)
52     DEFINE_ALIGN_SIZE(LAST_OFFSET);
53 
54     DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, HASHMAP_TABLE_INDEX, HASHMAP_SIZE_OFFSET)
55     DECL_DUMP()
56 
57 private:
58     static void SetAllLinkedNode(JSThread *thread, JSHandle<JSAPIHashMap> hashMap, JSMutableHandle<LinkedNode> node);
59     static void SetAllRBTreeNode(JSThread *thread, JSHandle<JSAPIHashMap> hashMap, JSHandle<RBTreeNode> node);
60     static bool HasValueLinkedNode(JSTaggedValue node, JSTaggedValue value);
61     static bool HasValueRBTreeNode(JSTaggedValue node, JSTaggedValue value);
62 };
63 }  // namespace panda::ecmascript
64 #endif  // ECMASCRIPT_JS_API_JS_API_HASHMAP_H
65