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