• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2022-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 PANDA_TOOLING_INSPECTOR_TYPES_PROPERTY_DESCRIPTOR_H
17 #define PANDA_TOOLING_INSPECTOR_TYPES_PROPERTY_DESCRIPTOR_H
18 
19 #include "macros.h"
20 
21 #include "tooling/inspector/types/remote_object.h"
22 #include "tooling/inspector/json_serialization/serializable.h"
23 
24 #include "remote_object.h"
25 
26 namespace ark::tooling::inspector {
27 class PropertyDescriptor final : public JsonSerializable {
28 public:
PropertyDescriptor(std::string name,RemoteObject value)29     PropertyDescriptor(std::string name, RemoteObject value) : name_(std::move(name)), value_(std::move(value)) {}
30 
Accessor(std::string name,RemoteObject getter)31     static PropertyDescriptor Accessor(std::string name, RemoteObject getter)
32     {
33         PropertyDescriptor property(std::move(name), std::move(getter));
34         property.isAccessor_ = true;
35         return property;
36     }
37 
IsAccessor()38     bool IsAccessor() const
39     {
40         return isAccessor_;
41     }
42 
IsConfigurable()43     bool IsConfigurable() const
44     {
45         return configurable_;
46     }
47 
IsEnumerable()48     bool IsEnumerable() const
49     {
50         return enumerable_;
51     }
52 
IsWritable()53     bool IsWritable() const
54     {
55         ASSERT(!IsAccessor());
56         return writable_;
57     }
58 
GetGetter()59     const RemoteObject &GetGetter() const
60     {
61         ASSERT(IsAccessor());
62         return value_;
63     }
64 
GetName()65     const std::string &GetName() const
66     {
67         return name_;
68     }
69 
GetSymbol()70     const std::optional<RemoteObject> &GetSymbol() const
71     {
72         return symbol_;
73     }
74 
GetValue()75     const RemoteObject &GetValue() const
76     {
77         ASSERT(!IsAccessor());
78         return value_;
79     }
80 
GetValue()81     RemoteObject &GetValue()
82     {
83         ASSERT(!IsAccessor());
84         return value_;
85     }
86 
SetConfigurable(bool configurable)87     void SetConfigurable(bool configurable)
88     {
89         configurable_ = configurable;
90     }
91 
SetEnumerable(bool enumerable)92     void SetEnumerable(bool enumerable)
93     {
94         enumerable_ = enumerable;
95     }
96 
SetSymbol(RemoteObject symbol)97     void SetSymbol(RemoteObject symbol)
98     {
99         symbol_.emplace(std::move(symbol));
100     }
101 
SetWritable(bool writable)102     void SetWritable(bool writable)
103     {
104         ASSERT(!IsAccessor());
105         writable_ = writable;
106     }
107 
Serialize(JsonObjectBuilder & builder)108     void Serialize(JsonObjectBuilder &builder) const override
109     {
110         builder.AddProperty("name", name_);
111 
112         if (symbol_) {
113             builder.AddProperty("symbol", *symbol_);
114         }
115 
116         if (isAccessor_) {
117             builder.AddProperty("get", value_);
118         } else {
119             builder.AddProperty("value", value_);
120             builder.AddProperty("writable", writable_);
121         }
122 
123         builder.AddProperty("configurable", configurable_);
124         builder.AddProperty("enumerable", enumerable_);
125     }
126 
127 private:
128     std::string name_;
129     std::optional<RemoteObject> symbol_;
130     RemoteObject value_;
131     bool isAccessor_ {false};
132     bool configurable_ {false};
133     bool enumerable_ {true};
134     bool writable_ {true};
135 };
136 }  // namespace ark::tooling::inspector
137 
138 #endif  // PANDA_TOOLING_INSPECTOR_TYPES_PROPERTY_DESCRIPTOR_H
139