1 /*
2  * Copyright (c) 2024 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_SHARED_MAP_H
17 #define ECMASCRIPT_JS_SHARED_MAP_H
18 
19 #include "ecmascript/js_object.h"
20 #include "ecmascript/js_tagged_value-inl.h"
21 
22 namespace panda::ecmascript {
23 class JSSharedMap : public JSObject {
24 public:
25     CAST_CHECK(JSSharedMap, IsJSSharedMap);
26 
27     static bool Delete(JSThread *thread, const JSHandle<JSSharedMap> &map, const JSHandle<JSTaggedValue> &key);
28 
29     static void PUBLIC_API Set(JSThread *thread, const JSHandle<JSSharedMap> &map, const JSHandle<JSTaggedValue> &key,
30                                const JSHandle<JSTaggedValue> &value);
31     static void Clear(JSThread *thread, const JSHandle<JSSharedMap> &map);
32 
33     static bool Has(JSThread *thread, const JSHandle<JSSharedMap> &map, JSTaggedValue key);
34 
35     static JSTaggedValue Get(JSThread *thread, const JSHandle<JSSharedMap> &map, JSTaggedValue key);
36 
37     static uint32_t GetSize(JSThread *thread, const JSHandle<JSSharedMap> &map);
38 
39     static JSTaggedValue GetKey(JSThread *thread, const JSHandle<JSSharedMap> &map, uint32_t entry);
40 
41     static JSTaggedValue GetValue(JSThread *thread, const JSHandle<JSSharedMap> &map, uint32_t entry);
42 
43     static constexpr size_t LINKED_MAP_OFFSET = JSObject::SIZE;
44     ACCESSORS(LinkedMap, LINKED_MAP_OFFSET, MOD_RECORD_OFFSET)
45     ACCESSORS_SYNCHRONIZED_PRIMITIVE_FIELD(ModRecord, uint32_t, MOD_RECORD_OFFSET, LAST_OFFSET)
46     DEFINE_ALIGN_SIZE(LAST_OFFSET);
47 
48     static constexpr uint32_t MAX_INLINE = PropertyAttributes::MAX_FAST_PROPS_CAPACITY -
49         SIZE / JSTaggedValue::TaggedTypeSize() + 1;
50     DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, LINKED_MAP_OFFSET, MOD_RECORD_OFFSET)
51     DECL_DUMP()
52 };
53 }  // namespace panda::ecmascript
54 
55 #endif  // ECMASCRIPT_JS_SHARED_MAP_H
56