• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_MAP_H
17 #define ECMASCRIPT_JS_API_JS_API_TREE_MAP_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  * JSAPITreeMap provides ordered maps.
26  * */
27 class JSAPITreeMap : public JSObject {
28 public:
Cast(TaggedObject * object)29     static JSAPITreeMap *Cast(TaggedObject *object)
30     {
31         return static_cast<JSAPITreeMap *>(object);
32     }
33 
34     static void Set(JSThread *thread, const JSHandle<JSAPITreeMap> &map, const JSHandle<JSTaggedValue> &key,
35                     const JSHandle<JSTaggedValue> &value);
36 
37     static void Clear(const JSThread *thread, const JSHandle<JSAPITreeMap> &map);
38 
39     static JSTaggedValue Get(JSThread *thread, const JSHandle<JSAPITreeMap> &map, const JSHandle<JSTaggedValue> &key);
40 
41     static JSTaggedValue Delete(JSThread *thread, const JSHandle<JSAPITreeMap> &map,
42                                 const JSHandle<JSTaggedValue> &key);
43 
44     static bool HasKey(JSThread *thread, const JSHandle<JSAPITreeMap> &map, const JSHandle<JSTaggedValue> &key);
45     bool HasValue(JSThread *thread, const JSHandle<JSTaggedValue> &value) const;
46 
47     static bool Replace(JSThread *thread, const JSHandle<JSAPITreeMap> &map, const JSHandle<JSTaggedValue> &key,
48                         const JSHandle<JSTaggedValue> &value);
49 
50     int GetSize() const;
51 
52     JSTaggedValue GetKey(int entry) const;
53 
54     JSTaggedValue GetValue(int entry) const;
55 
56     static constexpr size_t TREE_MAP_OFFSET = JSObject::SIZE;
57     ACCESSORS(TreeMap, TREE_MAP_OFFSET, SIZE)
58 
59     DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, TREE_MAP_OFFSET, SIZE)
60 
61     DECL_DUMP()
62 };
63 }  // namespace panda::ecmascript
64 
65 #endif  // ECMASCRIPT_JS_API_JS_API_TREE_MAP_H
66