v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
property-descriptor.h
Go to the documentation of this file.
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_OBJECTS_PROPERTY_DESCRIPTOR_H_
6#define V8_OBJECTS_PROPERTY_DESCRIPTOR_H_
7
10
11namespace v8 {
12namespace internal {
13
14class Isolate;
15class Object;
16class PropertyDescriptorObject;
17
19 public:
21 : enumerable_(false),
22 has_enumerable_(false),
23 configurable_(false),
24 has_configurable_(false),
25 writable_(false),
26 has_writable_(false) {}
27
28 // ES6 6.2.4.1
30 return desc->has_get() || desc->has_set();
31 }
32
33 // ES6 6.2.4.2
35 return desc->has_value() || desc->has_writable();
36 }
37
38 // ES6 6.2.4.3
40 return !IsAccessorDescriptor(desc) && !IsDataDescriptor(desc);
41 }
42
43 // ES6 6.2.4.4
45
47 Isolate* isolate);
48
49 // ES6 6.2.4.5
50 static bool ToPropertyDescriptor(Isolate* isolate, Handle<JSAny> obj,
51 PropertyDescriptor* desc);
52
53 // ES6 6.2.4.6
54 static void CompletePropertyDescriptor(Isolate* isolate,
55 PropertyDescriptor* desc);
56
57 bool is_empty() const {
58 return !has_enumerable() && !has_configurable() && !has_writable() &&
59 !has_value() && !has_get() && !has_set();
60 }
61
63 return has_configurable() && has_enumerable() && !has_value() &&
64 !has_writable() && has_get() && has_set();
65 }
66
67 bool IsRegularDataProperty() const {
68 return has_configurable() && has_enumerable() && has_value() &&
69 has_writable() && !has_get() && !has_set();
70 }
71
72 bool enumerable() const { return enumerable_; }
77 bool has_enumerable() const { return has_enumerable_; }
78
79 bool configurable() const { return configurable_; }
84 bool has_configurable() const { return has_configurable_; }
85
86 Handle<JSAny> value() const { return value_; }
88 bool has_value() const { return !value_.is_null(); }
89
90 bool writable() const { return writable_; }
93 has_writable_ = true;
94 }
95 bool has_writable() const { return has_writable_; }
96
101 bool has_get() const { return !get_.is_null(); }
102
107 bool has_set() const { return !set_.is_null(); }
108
109 DirectHandle<JSAny> name() const { return name_; }
111
113 return static_cast<PropertyAttributes>(
116 (has_writable() && !writable() ? READ_ONLY : NONE));
117 }
118
119 private:
120 bool enumerable_ : 1;
124 bool writable_ : 1;
126 // TODO(42203211): When this class is only stack-allocated, the following
127 // fields can change to DirectHandle. So far, there is one vector of property
128 // descriptors used in JSReceiver::DefineProperties.
133};
134
135} // namespace internal
136} // namespace v8
137
138#endif // V8_OBJECTS_PROPERTY_DESCRIPTOR_H_
void set_value(DirectHandle< JSAny > value)
void set_configurable(bool configurable)
static bool IsAccessorDescriptor(PropertyDescriptor *desc)
void set_name(DirectHandle< JSAny > name)
Handle< UnionOf< JSAny, FunctionTemplateInfo > > get() const
void set_set(DirectHandle< UnionOf< JSAny, FunctionTemplateInfo > > set)
static bool IsGenericDescriptor(PropertyDescriptor *desc)
static void CompletePropertyDescriptor(Isolate *isolate, PropertyDescriptor *desc)
static bool ToPropertyDescriptor(Isolate *isolate, Handle< JSAny > obj, PropertyDescriptor *desc)
Handle< UnionOf< JSAny, FunctionTemplateInfo > > set() const
static bool IsDataDescriptor(PropertyDescriptor *desc)
DirectHandle< JSObject > ToObject(Isolate *isolate)
DirectHandle< JSAny > name() const
void set_get(DirectHandle< UnionOf< JSAny, FunctionTemplateInfo > > get)
DirectHandle< PropertyDescriptorObject > ToPropertyDescriptorObject(Isolate *isolate)
IndirectHandle< UnionOf< JSAny, FunctionTemplateInfo > > get_
IndirectHandle< UnionOf< JSAny, FunctionTemplateInfo > > set_
V8_INLINE IndirectHandle< T > indirect_handle(DirectHandle< T > handle)
Definition handles.h:757
typename detail::FlattenUnionHelper< Union<>, Ts... >::type UnionOf
Definition union.h:123