• 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_JS_WEAK_CONTAINER_H
17 #define ECMASCRIPT_JS_WEAK_CONTAINER_H
18 
19 #include <limits>
20 
21 #include "ecmascript/js_object.h"
22 
23 namespace panda::ecmascript {
24 class JSWeakMap : public JSObject {
25 public:
Cast(TaggedObject * object)26     static JSWeakMap *Cast(TaggedObject *object)
27     {
28         ASSERT(JSTaggedValue(object).IsJSWeakMap());
29         return static_cast<JSWeakMap *>(object);
30     }
31 
32     static bool Delete(JSThread *thread, const JSHandle<JSWeakMap> &map, const JSHandle<JSTaggedValue> &key);
33 
34     static void Set(JSThread *thread, const JSHandle<JSWeakMap> &map, const JSHandle<JSTaggedValue> &key,
35                     const JSHandle<JSTaggedValue> &value);
36 
37     bool Has(JSTaggedValue key) const;
38 
39     JSTaggedValue Get(JSTaggedValue key) const;
40 
41     int GetSize() const;
42 
43     static constexpr size_t LINKED_MAP_OFFSET = JSObject::SIZE;
44     ACCESSORS(LinkedMap, LINKED_MAP_OFFSET, SIZE)
45 
46     DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, LINKED_MAP_OFFSET, SIZE)
47     DECL_DUMP()
48 };
49 
50 class JSWeakSet : public JSObject {
51 public:
Cast(TaggedObject * object)52     static JSWeakSet *Cast(TaggedObject *object)
53     {
54         ASSERT(JSTaggedValue(object).IsJSWeakSet());
55         return static_cast<JSWeakSet *>(object);
56     }
57     static bool Delete(JSThread *thread, const JSHandle<JSWeakSet> &set, const JSHandle<JSTaggedValue> &value);
58 
59     static void Add(JSThread *thread, const JSHandle<JSWeakSet> &set, const JSHandle<JSTaggedValue> &value);
60 
61     bool Has(JSTaggedValue value) const;
62 
63     int GetSize() const;
64 
65     static constexpr size_t LINKED_SET_OFFSET = JSObject::SIZE;
66     ACCESSORS(LinkedSet, LINKED_SET_OFFSET, SIZE)
67 
68     DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, LINKED_SET_OFFSET, SIZE)
69 
70     DECL_DUMP()
71 };
72 }  // namespace panda::ecmascript
73 #endif  // ECMASCRIPT_JS_WEAK_CONTAINER_H