OLD | NEW |
(Empty) | |
| 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 has_writable_(false) {} |
| 28 |
| 29 // ES6 6.2.4.1 |
| 30 static bool IsAccessorDescriptor(PropertyDescriptor* desc) { |
| 31 return desc->has_get() || desc->has_set(); |
| 32 } |
| 33 |
| 34 // ES6 6.2.4.2 |
| 35 static bool IsDataDescriptor(PropertyDescriptor* desc) { |
| 36 return desc->has_value() || desc->has_writable(); |
| 37 } |
| 38 |
| 39 // ES6 6.2.4.3 |
| 40 static bool IsGenericDescriptor(PropertyDescriptor* desc) { |
| 41 return !IsAccessorDescriptor(desc) && !IsDataDescriptor(desc); |
| 42 } |
| 43 |
| 44 bool is_empty() const { |
| 45 return !has_enumerable() && !has_configurable() && !has_writable() && |
| 46 !has_value() && !has_get() && !has_set(); |
| 47 } |
| 48 |
| 49 bool enumerable() const { return enumerable_; } |
| 50 void set_enumerable(bool enumerable) { |
| 51 enumerable_ = enumerable; |
| 52 has_enumerable_ = true; |
| 53 } |
| 54 bool has_enumerable() const { return has_enumerable_; } |
| 55 |
| 56 bool configurable() const { return configurable_; } |
| 57 void set_configurable(bool configurable) { |
| 58 configurable_ = configurable; |
| 59 has_configurable_ = true; |
| 60 } |
| 61 bool has_configurable() const { return has_configurable_; } |
| 62 |
| 63 Handle<Object> value() const { return value_; } |
| 64 void set_value(Handle<Object> value) { value_ = value; } |
| 65 bool has_value() const { return !value_.is_null(); } |
| 66 |
| 67 bool writable() const { return writable_; } |
| 68 void set_writable(bool writable) { |
| 69 writable_ = writable; |
| 70 has_writable_ = true; |
| 71 } |
| 72 bool has_writable() const { return has_writable_; } |
| 73 |
| 74 Handle<Object> get() const { return get_; } |
| 75 void set_get(Handle<Object> get) { get_ = get; } |
| 76 bool has_get() const { return !get_.is_null(); } |
| 77 |
| 78 Handle<Object> set() const { return set_; } |
| 79 void set_set(Handle<Object> set) { set_ = set; } |
| 80 bool has_set() const { return !set_.is_null(); } |
| 81 |
| 82 Handle<Object> name() const { return name_; } |
| 83 void set_name(Handle<Object> name) { name_ = name; } |
| 84 |
| 85 PropertyAttributes ToAttributes() { |
| 86 return static_cast<PropertyAttributes>( |
| 87 (has_enumerable() && !enumerable() ? DONT_ENUM : NONE) | |
| 88 (has_configurable() && !configurable() ? DONT_DELETE : NONE) | |
| 89 (has_writable() && !writable() ? READ_ONLY : NONE)); |
| 90 } |
| 91 |
| 92 static bool ToPropertyDescriptor(Isolate* isolate, Handle<Object> obj, |
| 93 PropertyDescriptor* desc); |
| 94 |
| 95 private: |
| 96 bool enumerable_ : 1; |
| 97 bool has_enumerable_ : 1; |
| 98 bool configurable_ : 1; |
| 99 bool has_configurable_ : 1; |
| 100 bool writable_ : 1; |
| 101 bool has_writable_ : 1; |
| 102 Handle<Object> value_; |
| 103 Handle<Object> get_; |
| 104 Handle<Object> set_; |
| 105 Handle<Object> name_; |
| 106 |
| 107 DISALLOW_COPY_AND_ASSIGN(PropertyDescriptor); |
| 108 }; |
| 109 |
| 110 } // namespace internal |
| 111 } // namespace v8 |
| 112 |
| 113 #endif // V8_PROPERTY_DESCRIPTOR_H_ |
OLD | NEW |