V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
api-callbacks.h
1 // Copyright 2018 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_API_CALLBACKS_H_
6 #define V8_OBJECTS_API_CALLBACKS_H_
7 
8 #include "src/objects.h"
9 
10 // Has to be the last include (doesn't have include guards):
11 #include "src/objects/object-macros.h"
12 
13 namespace v8 {
14 namespace internal {
15 
16 // An accessor must have a getter, but can have no setter.
17 //
18 // When setting a property, V8 searches accessors in prototypes.
19 // If an accessor was found and it does not have a setter,
20 // the request is ignored.
21 //
22 // If the accessor in the prototype has the READ_ONLY property attribute, then
23 // a new value is added to the derived object when the property is set.
24 // This shadows the accessor in the prototype.
25 class AccessorInfo : public Struct {
26  public:
27  DECL_ACCESSORS2(name, Name)
28  DECL_INT_ACCESSORS(flags)
29  DECL_ACCESSORS(expected_receiver_type, Object)
30  // This directly points at a foreign C function to be used from the runtime.
31  DECL_ACCESSORS(getter, Object)
32  inline bool has_getter();
33  DECL_ACCESSORS(setter, Object)
34  inline bool has_setter();
35  // This either points at the same as above, or a trampoline in case we are
36  // running with the simulator. Use these entries from generated code.
37  DECL_ACCESSORS(js_getter, Object)
38  DECL_ACCESSORS(data, Object)
39 
40  static Address redirect(Address address, AccessorComponent component);
41  Address redirected_getter() const;
42 
43  // Dispatched behavior.
44  DECL_PRINTER(AccessorInfo)
45 
46  DECL_BOOLEAN_ACCESSORS(all_can_read)
47  DECL_BOOLEAN_ACCESSORS(all_can_write)
48  DECL_BOOLEAN_ACCESSORS(is_special_data_property)
49  DECL_BOOLEAN_ACCESSORS(replace_on_access)
50  DECL_BOOLEAN_ACCESSORS(is_sloppy)
51 
52  inline SideEffectType getter_side_effect_type() const;
53  inline void set_getter_side_effect_type(SideEffectType type);
54 
55  inline SideEffectType setter_side_effect_type() const;
56  inline void set_setter_side_effect_type(SideEffectType type);
57 
58  // The property attributes used when an API object template is instantiated
59  // for the first time. Changing of this value afterwards does not affect
60  // the actual attributes of a property.
61  inline PropertyAttributes initial_property_attributes() const;
62  inline void set_initial_property_attributes(PropertyAttributes attributes);
63 
64  // Checks whether the given receiver is compatible with this accessor.
65  static bool IsCompatibleReceiverMap(Handle<AccessorInfo> info,
66  Handle<Map> map);
67  inline bool IsCompatibleReceiver(Object* receiver);
68 
69  DECL_CAST(AccessorInfo)
70 
71  // Dispatched behavior.
72  DECL_VERIFIER(AccessorInfo)
73 
74  // Append all descriptors to the array that are not already there.
75  // Return number added.
76  static int AppendUnique(Isolate* isolate, Handle<Object> descriptors,
77  Handle<FixedArray> array, int valid_descriptors);
78 
79 // Layout description.
80 #define ACCESSOR_INFO_FIELDS(V) \
81  V(kNameOffset, kTaggedSize) \
82  V(kFlagsOffset, kTaggedSize) \
83  V(kExpectedReceiverTypeOffset, kTaggedSize) \
84  V(kSetterOffset, kTaggedSize) \
85  V(kGetterOffset, kTaggedSize) \
86  V(kJsGetterOffset, kTaggedSize) \
87  V(kDataOffset, kTaggedSize) \
88  V(kSize, 0)
89 
90  DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize, ACCESSOR_INFO_FIELDS)
91 #undef ACCESSOR_INFO_FIELDS
92 
93  private:
94  inline bool HasExpectedReceiverType();
95 
96 // Bit positions in |flags|.
97 #define ACCESSOR_INFO_FLAGS_BIT_FIELDS(V, _) \
98  V(AllCanReadBit, bool, 1, _) \
99  V(AllCanWriteBit, bool, 1, _) \
100  V(IsSpecialDataPropertyBit, bool, 1, _) \
101  V(IsSloppyBit, bool, 1, _) \
102  V(ReplaceOnAccessBit, bool, 1, _) \
103  V(GetterSideEffectTypeBits, SideEffectType, 2, _) \
104  /* We could save a bit from setter side-effect type, if necessary */ \
105  V(SetterSideEffectTypeBits, SideEffectType, 2, _) \
106  V(InitialAttributesBits, PropertyAttributes, 3, _)
107 
108  DEFINE_BIT_FIELDS(ACCESSOR_INFO_FLAGS_BIT_FIELDS)
109 #undef ACCESSOR_INFO_FLAGS_BIT_FIELDS
110 
111  DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorInfo);
112 };
113 
114 class AccessCheckInfo : public Struct {
115  public:
116  DECL_ACCESSORS(callback, Object)
117  DECL_ACCESSORS(named_interceptor, Object)
118  DECL_ACCESSORS(indexed_interceptor, Object)
119  DECL_ACCESSORS(data, Object)
120 
121  DECL_CAST(AccessCheckInfo)
122 
123  // Dispatched behavior.
124  DECL_PRINTER(AccessCheckInfo)
125  DECL_VERIFIER(AccessCheckInfo)
126 
127  static AccessCheckInfo* Get(Isolate* isolate, Handle<JSObject> receiver);
128 
129 // Layout description.
130 #define ACCESS_CHECK_INFO_FIELDS(V) \
131  V(kCallbackOffset, kTaggedSize) \
132  V(kNamedInterceptorOffset, kTaggedSize) \
133  V(kIndexedInterceptorOffset, kTaggedSize) \
134  V(kDataOffset, kTaggedSize) \
135  V(kSize, 0)
136 
137  DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize,
138  ACCESS_CHECK_INFO_FIELDS)
139 #undef ACCESS_CHECK_INFO_FIELDS
140 
141  private:
142  DISALLOW_IMPLICIT_CONSTRUCTORS(AccessCheckInfo);
143 };
144 
145 class InterceptorInfo : public Struct {
146  public:
147  DECL_ACCESSORS(getter, Object)
148  DECL_ACCESSORS(setter, Object)
149  DECL_ACCESSORS(query, Object)
150  DECL_ACCESSORS(descriptor, Object)
151  DECL_ACCESSORS(deleter, Object)
152  DECL_ACCESSORS(enumerator, Object)
153  DECL_ACCESSORS(definer, Object)
154  DECL_ACCESSORS(data, Object)
155  DECL_BOOLEAN_ACCESSORS(can_intercept_symbols)
156  DECL_BOOLEAN_ACCESSORS(all_can_read)
157  DECL_BOOLEAN_ACCESSORS(non_masking)
158  DECL_BOOLEAN_ACCESSORS(is_named)
159  DECL_BOOLEAN_ACCESSORS(has_no_side_effect)
160 
161  inline int flags() const;
162  inline void set_flags(int flags);
163 
164  DECL_CAST(InterceptorInfo)
165 
166  // Dispatched behavior.
167  DECL_PRINTER(InterceptorInfo)
168  DECL_VERIFIER(InterceptorInfo)
169 
170 // Layout description.
171 #define INTERCEPTOR_INFO_FIELDS(V) \
172  V(kGetterOffset, kTaggedSize) \
173  V(kSetterOffset, kTaggedSize) \
174  V(kQueryOffset, kTaggedSize) \
175  V(kDescriptorOffset, kTaggedSize) \
176  V(kDeleterOffset, kTaggedSize) \
177  V(kEnumeratorOffset, kTaggedSize) \
178  V(kDefinerOffset, kTaggedSize) \
179  V(kDataOffset, kTaggedSize) \
180  V(kFlagsOffset, kTaggedSize) \
181  V(kSize, 0)
182 
183  DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize,
184  INTERCEPTOR_INFO_FIELDS)
185 #undef INTERCEPTOR_INFO_FIELDS
186 
187  static const int kCanInterceptSymbolsBit = 0;
188  static const int kAllCanReadBit = 1;
189  static const int kNonMasking = 2;
190  static const int kNamed = 3;
191  static const int kHasNoSideEffect = 4;
192 
193  private:
194  DISALLOW_IMPLICIT_CONSTRUCTORS(InterceptorInfo);
195 };
196 
197 class CallHandlerInfo : public Tuple3 {
198  public:
199  DECL_ACCESSORS(callback, Object)
200  DECL_ACCESSORS(js_callback, Object)
201  DECL_ACCESSORS(data, Object)
202 
203  DECL_CAST(CallHandlerInfo)
204 
205  inline bool IsSideEffectFreeCallHandlerInfo() const;
206  inline bool IsSideEffectCallHandlerInfo() const;
207  inline void SetNextCallHasNoSideEffect();
208  // Returns whether or not the next call can be side effect free.
209  // Calling this will change the state back to having a side effect.
210  inline bool NextCallHasNoSideEffect();
211 
212  // Dispatched behavior.
213  DECL_PRINTER(CallHandlerInfo)
214  DECL_VERIFIER(CallHandlerInfo)
215 
216  Address redirected_callback() const;
217 
218  static const int kCallbackOffset = kValue1Offset;
219  static const int kJsCallbackOffset = kValue2Offset;
220  static const int kDataOffset = kValue3Offset;
221 
222  private:
223  DISALLOW_IMPLICIT_CONSTRUCTORS(CallHandlerInfo);
224 };
225 
226 } // namespace internal
227 } // namespace v8
228 
229 #include "src/objects/object-macros-undef.h"
230 
231 #endif // V8_OBJECTS_API_CALLBACKS_H_
Definition: libplatform.h:13
SideEffectType
Definition: v8.h:3204