• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_GLOBAL_DICTIONARY_H
17 #define ECMASCRIPT_GLOBAL_DICTIONARY_H
18 
19 #include "ecmascript/ecma_string.h"
20 #include "ecmascript/ic/property_box.h"
21 #include "ecmascript/js_handle.h"
22 #include "ecmascript/js_tagged_value.h"
23 #include "ecmascript/property_attributes.h"
24 #include "ecmascript/ecma_vm.h"
25 #include "ecmascript/object_factory.h"
26 #include "ecmascript/tagged_hash_table.h"
27 
28 namespace panda {
29 namespace ecmascript {
30 class GlobalDictionary : public OrderTaggedHashTable<GlobalDictionary> {
31 public:
32     using OrderHashTableT = OrderTaggedHashTable<GlobalDictionary>;
GetKeyIndex(int entry)33     inline static int GetKeyIndex(int entry)
34     {
35         return OrderHashTableT::TABLE_HEADER_SIZE + entry * GetEntrySize() + ENTRY_KEY_INDEX;
36     }
GetValueIndex(int entry)37     inline static int GetValueIndex(int entry)
38     {
39         return OrderHashTableT::TABLE_HEADER_SIZE + entry * GetEntrySize() + ENTRY_VALUE_INDEX;
40     }
GetEntryIndex(int entry)41     inline static int GetEntryIndex(int entry)
42     {
43         return OrderHashTableT::TABLE_HEADER_SIZE + entry * GetEntrySize();
44     }
GetEntrySize()45     inline static int GetEntrySize()
46     {
47         return ENTRY_SIZE;
48     }
49     static inline bool IsMatch(const JSTaggedValue &key, const JSTaggedValue &other);
50 
51     static inline int Hash(const JSTaggedValue &key);
52     inline static void InvalidatePropertyBox(JSThread *thread, const JSHandle<GlobalDictionary> &dictHandle, int entry,
53                                              const PropertyAttributes &metaData);
54 
55     inline static void InvalidateAndReplaceEntry(JSThread *thread, const JSHandle<GlobalDictionary> &dictHandle,
56                                                  int entry, const JSHandle<JSTaggedValue> &oldValue);
57 
58     inline bool IsValidateBox(int entry) const;
59 
60     inline PropertyBox *GetBox(int entry) const;
61 
62     inline JSTaggedValue GetValue(int entry) const;
63 
64     inline PropertyAttributes GetAttributes(int entry) const;
65 
66     inline void SetEntry(const JSThread *thread, int entry, const JSTaggedValue &key, const JSTaggedValue &value,
67                          const PropertyAttributes &detail);
68 
69     inline void ClearEntry(const JSThread *thread, int entry);
70 
71     inline void UpdateValueAndAttributes(const JSThread *thread, int entry, const JSTaggedValue &value,
72                                          const PropertyAttributes &metaData);
73 
74     inline void UpdateValue(const JSThread *thread, int entry, const JSTaggedValue &value);
75 
76     inline void SetAttributes(const JSThread *thread, int entry, const PropertyAttributes &metaData);
77 
78     inline void GetAllKeys(const JSThread *thread, int offset, TaggedArray *keyArray) const;
79     inline void GetAllKeysByFilter(const JSThread *thread,
80         uint32_t &keyArrayEffectivelength, TaggedArray *keyArray, uint32_t filter) const;
81 
82     inline void GetEnumAllKeys(const JSThread *thread, int offset, TaggedArray *keyArray, uint32_t *keys) const;
83 
84     static bool inline CompKey(const std::pair<JSTaggedValue, uint32_t> &a,
85                                const std::pair<JSTaggedValue, uint32_t> &b);
86 
87     DECL_DUMP()
88 
89 public:
90     static constexpr int ENTRY_KEY_INDEX = 0;
91     static constexpr int ENTRY_VALUE_INDEX = 1;
92     static constexpr int ENTRY_DETAILS_INDEX = 2;
93     static constexpr int ENTRY_SIZE = 3;
94 };
95 }  // namespace ecmascript
96 }  // namespace panda
97 #endif
98