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 :
19 : class PropertyDescriptor {
20 : public:
21 : PropertyDescriptor()
22 : : enumerable_(false),
23 : has_enumerable_(false),
24 : configurable_(false),
25 : has_configurable_(false),
26 : writable_(false),
27 4969488 : has_writable_(false) {}
28 :
29 : // ES6 6.2.4.1
30 : static bool IsAccessorDescriptor(PropertyDescriptor* desc) {
31 1858287 : return desc->has_get() || desc->has_set();
32 : }
33 :
34 : // ES6 6.2.4.2
35 : static bool IsDataDescriptor(PropertyDescriptor* desc) {
36 1729982 : return desc->has_value() || desc->has_writable();
37 : }
38 :
39 : // ES6 6.2.4.3
40 : static bool IsGenericDescriptor(PropertyDescriptor* desc) {
41 1215933 : return !IsAccessorDescriptor(desc) && !IsDataDescriptor(desc);
42 : }
43 :
44 : // ES6 6.2.4.4
45 : Handle<Object> ToObject(Isolate* isolate);
46 :
47 : // ES6 6.2.4.5
48 : static bool ToPropertyDescriptor(Isolate* isolate, Handle<Object> obj,
49 : PropertyDescriptor* desc);
50 :
51 : // ES6 6.2.4.6
52 : static void CompletePropertyDescriptor(Isolate* isolate,
53 : PropertyDescriptor* desc);
54 :
55 669524 : bool is_empty() const {
56 1568349 : return !has_enumerable() && !has_configurable() && !has_writable() &&
57 1715090 : !has_value() && !has_get() && !has_set();
58 : }
59 :
60 3487879 : bool IsRegularAccessorProperty() const {
61 6988439 : return has_configurable() && has_enumerable() && !has_value() &&
62 3520570 : !has_writable() && has_get() && has_set();
63 : }
64 :
65 3471544 : bool IsRegularDataProperty() const {
66 10408878 : return has_configurable() && has_enumerable() && has_value() &&
67 10410348 : has_writable() && !has_get() && !has_set();
68 : }
69 :
70 4157785 : bool enumerable() const { return enumerable_; }
71 : void set_enumerable(bool enumerable) {
72 4264607 : enumerable_ = enumerable;
73 4264628 : has_enumerable_ = true;
74 : }
75 8923340 : bool has_enumerable() const { return has_enumerable_; }
76 :
77 4292299 : bool configurable() const { return configurable_; }
78 : void set_configurable(bool configurable) {
79 4291798 : configurable_ = configurable;
80 4293234 : has_configurable_ = true;
81 : }
82 8780548 : bool has_configurable() const { return has_configurable_; }
83 :
84 : Handle<Object> value() const { return value_; }
85 4125733 : void set_value(Handle<Object> value) { value_ = value; }
86 82 : bool has_value() const { return !value_.is_null(); }
87 :
88 4078923 : bool writable() const { return writable_; }
89 : void set_writable(bool writable) {
90 4177360 : writable_ = writable;
91 4178078 : has_writable_ = true;
92 : }
93 5705166 : bool has_writable() const { return has_writable_; }
94 :
95 : Handle<Object> get() const { return get_; }
96 128738 : void set_get(Handle<Object> get) { get_ = get; }
97 82 : bool has_get() const { return !get_.is_null(); }
98 :
99 : Handle<Object> set() const { return set_; }
100 85847 : void set_set(Handle<Object> set) { set_ = set; }
101 82 : bool has_set() const { return !set_.is_null(); }
102 :
103 : Handle<Object> name() const { return name_; }
104 167964 : void set_name(Handle<Object> name) { name_ = name; }
105 :
106 520220 : PropertyAttributes ToAttributes() {
107 : return static_cast<PropertyAttributes>(
108 2080880 : (has_enumerable() && !enumerable() ? DONT_ENUM : NONE) |
109 1560660 : (has_configurable() && !configurable() ? DONT_DELETE : NONE) |
110 938727 : (has_writable() && !writable() ? READ_ONLY : NONE));
111 : }
112 :
113 : private:
114 : bool enumerable_ : 1;
115 : bool has_enumerable_ : 1;
116 : bool configurable_ : 1;
117 : bool has_configurable_ : 1;
118 : bool writable_ : 1;
119 : bool has_writable_ : 1;
120 : Handle<Object> value_;
121 : Handle<Object> get_;
122 : Handle<Object> set_;
123 : Handle<Object> name_;
124 :
125 : // Some compilers (Xcode 5.1, ARM GCC 4.9) insist on having a copy
126 : // constructor for std::vector<PropertyDescriptor>, so we can't
127 : // DISALLOW_COPY_AND_ASSIGN(PropertyDescriptor); here.
128 : };
129 :
130 : } // namespace internal
131 : } // namespace v8
132 :
133 : #endif // V8_PROPERTY_DESCRIPTOR_H_
|