• 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_SYMBOL_TABLE_H
17 #define ECMASCRIPT_SYMBOL_TABLE_H
18 
19 #include "ecmascript/tagged_hash_table.h"
20 #include "ecmascript/ecma_string.h"
21 #include "ecmascript/js_thread.h"
22 
23 namespace panda::ecmascript {
24 class SymbolTable : public TaggedHashTable<SymbolTable> {
25 public:
26     using HashTable = TaggedHashTable<SymbolTable>;
Cast(ObjectHeader * object)27     static SymbolTable *Cast(ObjectHeader *object)
28     {
29         return reinterpret_cast<SymbolTable *>(object);
30     }
GetKeyIndex(int entry)31     inline static int GetKeyIndex(int entry)
32     {
33         return HashTable::TABLE_HEADER_SIZE + entry * GetEntrySize() + ENTRY_KEY_INDEX;
34     }
GetValueIndex(int entry)35     inline static int GetValueIndex(int entry)
36     {
37         return HashTable::TABLE_HEADER_SIZE + entry * GetEntrySize() + ENTRY_VALUE_INDEX;
38     }
GetEntryIndex(int entry)39     inline static int GetEntryIndex(int entry)
40     {
41         return HashTable::TABLE_HEADER_SIZE + entry * GetEntrySize();
42     }
GetEntrySize()43     inline static int GetEntrySize()
44     {
45         return ENTRY_SIZE;
46     }
47     static inline bool IsMatch(const JSTaggedValue &name, const JSTaggedValue &other);
48     static inline uint32_t Hash(const JSTaggedValue &obj);
49 
50     static const int DEFAULT_ELEMENTS_NUMBER = 64;
51     static JSHandle<SymbolTable> Create(JSThread *thread, int numberOfElements = DEFAULT_ELEMENTS_NUMBER)
52     {
53         return HashTable::Create(thread, numberOfElements);
54     }
55 
56     inline bool ContainsKey(JSThread *thread, const JSTaggedValue &key);
57 
58     inline JSTaggedValue GetSymbol(const JSTaggedValue &key);
59 
60     inline JSTaggedValue FindSymbol(JSThread *thread, const JSTaggedValue &value);
61     static constexpr int ENTRY_KEY_INDEX = 0;
62     static constexpr int ENTRY_VALUE_INDEX = 1;
63     static constexpr int ENTRY_SIZE = 2;
64 };
65 }  // namespace panda::ecmascript
66 #endif  // ECMASCRIPT_SYMBOL_TABLE_H