Line data Source code
1 : // Copyright 2015 the V8 project authors. All rights reserved.
2 : // Use of this source code is governed by a BSD-style license that can be
3 : // found in the LICENSE file.
4 :
5 : #ifndef V8_PROPERTY_DESCRIPTOR_H_
6 : #define V8_PROPERTY_DESCRIPTOR_H_
7 :
8 :
9 : #include "src/handles.h"
10 : #include "src/property-details.h"
11 :
12 :
13 : namespace v8 {
14 : namespace internal {
15 :
16 : class Isolate;
17 : class Object;
18 : class PropertyDescriptorObject;
19 :
20 : class PropertyDescriptor {
21 : public:
22 : PropertyDescriptor()
23 : : enumerable_(false),
24 : has_enumerable_(false),
25 : configurable_(false),
26 : has_configurable_(false),
27 : writable_(false),
28 4160459 : has_writable_(false) {}
29 :
30 : // ES6 6.2.4.1
31 : static bool IsAccessorDescriptor(PropertyDescriptor* desc) {
32 1300394 : return desc->has_get() || desc->has_set();
33 : }
34 :
35 : // ES6 6.2.4.2
36 : static bool IsDataDescriptor(PropertyDescriptor* desc) {
37 1294151 : return desc->has_value() || desc->has_writable();
38 : }
39 :
40 : // ES6 6.2.4.3
41 : static bool IsGenericDescriptor(PropertyDescriptor* desc) {
42 887193 : return !IsAccessorDescriptor(desc) && !IsDataDescriptor(desc);
43 : }
44 :
45 : // ES6 6.2.4.4
46 : Handle<Object> ToObject(Isolate* isolate);
47 :
48 : Handle<PropertyDescriptorObject> ToPropertyDescriptorObject(Isolate* isolate);
49 :
50 : // ES6 6.2.4.5
51 : static bool ToPropertyDescriptor(Isolate* isolate, Handle<Object> obj,
52 : PropertyDescriptor* desc);
53 :
54 : // ES6 6.2.4.6
55 : static void CompletePropertyDescriptor(Isolate* isolate,
56 : PropertyDescriptor* desc);
57 :
58 : bool is_empty() const {
59 1067666 : return !has_enumerable() && !has_configurable() && !has_writable() &&
60 1254020 : !has_value() && !has_get() && !has_set();
61 : }
62 :
63 : bool IsRegularAccessorProperty() const {
64 19766 : return has_configurable() && has_enumerable() && !has_value() &&
65 19235 : !has_writable() && has_get() && has_set();
66 : }
67 :
68 : bool IsRegularDataProperty() const {
69 29109 : return has_configurable() && has_enumerable() && has_value() &&
70 38107 : has_writable() && !has_get() && !has_set();
71 : }
72 :
73 3667681 : bool enumerable() const { return enumerable_; }
74 : void set_enumerable(bool enumerable) {
75 3710864 : enumerable_ = enumerable;
76 3713702 : has_enumerable_ = true;
77 : }
78 4624491 : bool has_enumerable() const { return has_enumerable_; }
79 :
80 3739111 : bool configurable() const { return configurable_; }
81 : void set_configurable(bool configurable) {
82 3728525 : configurable_ = configurable;
83 3732405 : has_configurable_ = true;
84 : }
85 4322586 : bool has_configurable() const { return has_configurable_; }
86 :
87 : Handle<Object> value() const { return value_; }
88 3595871 : void set_value(Handle<Object> value) { value_ = value; }
89 74021 : bool has_value() const { return !value_.is_null(); }
90 :
91 3356956 : bool writable() const { return writable_; }
92 : void set_writable(bool writable) {
93 3501231 : writable_ = writable;
94 3504581 : has_writable_ = true;
95 : }
96 4404996 : bool has_writable() const { return has_writable_; }
97 :
98 : Handle<Object> get() const { return get_; }
99 223649 : void set_get(Handle<Object> get) { get_ = get; }
100 74021 : bool has_get() const { return !get_.is_null(); }
101 :
102 : Handle<Object> set() const { return set_; }
103 80459 : void set_set(Handle<Object> set) { set_ = set; }
104 74021 : bool has_set() const { return !set_.is_null(); }
105 :
106 : Handle<Object> name() const { return name_; }
107 3875 : void set_name(Handle<Object> name) { name_ = name; }
108 :
109 : PropertyAttributes ToAttributes() {
110 : return static_cast<PropertyAttributes>(
111 1418736 : (has_enumerable() && !enumerable() ? DONT_ENUM : NONE) |
112 1064054 : (has_configurable() && !configurable() ? DONT_DELETE : NONE) |
113 641516 : (has_writable() && !writable() ? READ_ONLY : NONE));
114 : }
115 :
116 : private:
117 : bool enumerable_ : 1;
118 : bool has_enumerable_ : 1;
119 : bool configurable_ : 1;
120 : bool has_configurable_ : 1;
121 : bool writable_ : 1;
122 : bool has_writable_ : 1;
123 : Handle<Object> value_;
124 : Handle<Object> get_;
125 : Handle<Object> set_;
126 : Handle<Object> name_;
127 :
128 : // Some compilers (Xcode 5.1, ARM GCC 4.9) insist on having a copy
129 : // constructor for std::vector<PropertyDescriptor>, so we can't
130 : // DISALLOW_COPY_AND_ASSIGN(PropertyDescriptor); here.
131 : };
132 :
133 : } // namespace internal
134 : } // namespace v8
135 :
136 : #endif // V8_PROPERTY_DESCRIPTOR_H_
|