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: PropertyDescriptor()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 IsAccessorDescriptor(PropertyDescriptor * desc)30 static bool IsAccessorDescriptor(PropertyDescriptor* desc) { 31 return desc->has_get() || desc->has_set(); 32 } 33 34 // ES6 6.2.4.2 IsDataDescriptor(PropertyDescriptor * desc)35 static bool IsDataDescriptor(PropertyDescriptor* desc) { 36 return desc->has_value() || desc->has_writable(); 37 } 38 39 // ES6 6.2.4.3 IsGenericDescriptor(PropertyDescriptor * desc)40 static bool IsGenericDescriptor(PropertyDescriptor* desc) { 41 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 is_empty()55 bool is_empty() const { 56 return !has_enumerable() && !has_configurable() && !has_writable() && 57 !has_value() && !has_get() && !has_set(); 58 } 59 enumerable()60 bool enumerable() const { return enumerable_; } set_enumerable(bool enumerable)61 void set_enumerable(bool enumerable) { 62 enumerable_ = enumerable; 63 has_enumerable_ = true; 64 } has_enumerable()65 bool has_enumerable() const { return has_enumerable_; } 66 configurable()67 bool configurable() const { return configurable_; } set_configurable(bool configurable)68 void set_configurable(bool configurable) { 69 configurable_ = configurable; 70 has_configurable_ = true; 71 } has_configurable()72 bool has_configurable() const { return has_configurable_; } 73 value()74 Handle<Object> value() const { return value_; } set_value(Handle<Object> value)75 void set_value(Handle<Object> value) { value_ = value; } has_value()76 bool has_value() const { return !value_.is_null(); } 77 writable()78 bool writable() const { return writable_; } set_writable(bool writable)79 void set_writable(bool writable) { 80 writable_ = writable; 81 has_writable_ = true; 82 } has_writable()83 bool has_writable() const { return has_writable_; } 84 get()85 Handle<Object> get() const { return get_; } set_get(Handle<Object> get)86 void set_get(Handle<Object> get) { get_ = get; } has_get()87 bool has_get() const { return !get_.is_null(); } 88 set()89 Handle<Object> set() const { return set_; } set_set(Handle<Object> set)90 void set_set(Handle<Object> set) { set_ = set; } has_set()91 bool has_set() const { return !set_.is_null(); } 92 name()93 Handle<Object> name() const { return name_; } set_name(Handle<Object> name)94 void set_name(Handle<Object> name) { name_ = name; } 95 ToAttributes()96 PropertyAttributes ToAttributes() { 97 return static_cast<PropertyAttributes>( 98 (has_enumerable() && !enumerable() ? DONT_ENUM : NONE) | 99 (has_configurable() && !configurable() ? DONT_DELETE : NONE) | 100 (has_writable() && !writable() ? READ_ONLY : NONE)); 101 } 102 103 private: 104 bool enumerable_ : 1; 105 bool has_enumerable_ : 1; 106 bool configurable_ : 1; 107 bool has_configurable_ : 1; 108 bool writable_ : 1; 109 bool has_writable_ : 1; 110 Handle<Object> value_; 111 Handle<Object> get_; 112 Handle<Object> set_; 113 Handle<Object> name_; 114 115 // Some compilers (Xcode 5.1, ARM GCC 4.9) insist on having a copy 116 // constructor for std::vector<PropertyDescriptor>, so we can't 117 // DISALLOW_COPY_AND_ASSIGN(PropertyDescriptor); here. 118 }; 119 120 } // namespace internal 121 } // namespace v8 122 123 #endif // V8_PROPERTY_DESCRIPTOR_H_ 124