1 /* 2 * Copyright (c) 2022-2023 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_API_JS_API_TREE_SET_H 17 #define ECMASCRIPT_JS_API_JS_API_TREE_SET_H 18 19 #include "ecmascript/js_object.h" 20 #include "ecmascript/js_tagged_value-inl.h" 21 22 namespace panda::ecmascript { 23 /** 24 * Provide the object of non ECMA standard jsapi container. 25 * JSAPITreeSet provides ordered sets. 26 * */ 27 class JSAPITreeSet : public JSObject { 28 public: Cast(TaggedObject * object)29 static JSAPITreeSet *Cast(TaggedObject *object) 30 { 31 return static_cast<JSAPITreeSet *>(object); 32 } 33 34 static void Add(JSThread *thread, const JSHandle<JSAPITreeSet> &set, const JSHandle<JSTaggedValue> &value); 35 36 static void Clear(const JSThread *thread, const JSHandle<JSAPITreeSet> &set); 37 38 static bool Delete(JSThread *thread, const JSHandle<JSAPITreeSet> &set, const JSHandle<JSTaggedValue> &key); 39 40 static bool Has(JSThread *thread, const JSHandle<JSAPITreeSet> &set, const JSHandle<JSTaggedValue> &key); 41 42 static JSTaggedValue PopFirst(JSThread *thread, const JSHandle<JSAPITreeSet> &set); 43 static JSTaggedValue PopLast(JSThread *thread, const JSHandle<JSAPITreeSet> &set); 44 45 int GetSize() const; 46 47 JSTaggedValue GetKey(int entry) const; 48 49 JSTaggedValue GetValue(int entry) const; 50 51 static constexpr size_t TREE_SET_OFFSET = JSObject::SIZE; 52 ACCESSORS(TreeSet, TREE_SET_OFFSET, SIZE) 53 54 DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, TREE_SET_OFFSET, SIZE) 55 56 DECL_DUMP() 57 }; 58 } // namespace panda::ecmascript 59 60 #endif // ECMASCRIPT_JS_API_JS_API_TREE_SET_H_ 61