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/struct.h"
9 #include "torque-generated/bit-fields-tq.h"
10 #include "torque-generated/class-definitions-tq.h"
11 
12 // Has to be the last include (doesn't have include guards):
13 #include "src/objects/object-macros.h"
14 
15 namespace v8 {
16 namespace internal {
17 
18 // An accessor must have a getter, but can have no setter.
19 //
20 // When setting a property, V8 searches accessors in prototypes.
21 // If an accessor was found and it does not have a setter,
22 // the request is ignored.
23 //
24 // If the accessor in the prototype has the READ_ONLY property attribute, then
25 // a new value is added to the derived object when the property is set.
26 // This shadows the accessor in the prototype.
27 class AccessorInfo : public Struct {
28  public:
29   DECL_ACCESSORS(name, Name)
30   DECL_INT_ACCESSORS(flags)
31   DECL_ACCESSORS(expected_receiver_type, Object)
32   // This directly points at a foreign C function to be used from the runtime.
33   DECL_ACCESSORS(getter, Object)
34   inline bool has_getter();
35   DECL_ACCESSORS(setter, Object)
36   inline bool has_setter();
37   // This either points at the same as above, or a trampoline in case we are
38   // running with the simulator. Use these entries from generated code.
39   DECL_ACCESSORS(js_getter, Object)
40   DECL_ACCESSORS(data, Object)
41 
42   static Address redirect(Address address, AccessorComponent component);
43   Address redirected_getter() const;
44 
45   // Dispatched behavior.
46   DECL_PRINTER(AccessorInfo)
47 
48   DECL_BOOLEAN_ACCESSORS(all_can_read)
49   DECL_BOOLEAN_ACCESSORS(all_can_write)
50   DECL_BOOLEAN_ACCESSORS(is_special_data_property)
51   DECL_BOOLEAN_ACCESSORS(replace_on_access)
52   DECL_BOOLEAN_ACCESSORS(is_sloppy)
53 
54   inline SideEffectType getter_side_effect_type() const;
55   inline void set_getter_side_effect_type(SideEffectType type);
56 
57   inline SideEffectType setter_side_effect_type() const;
58   inline void set_setter_side_effect_type(SideEffectType type);
59 
60   // The property attributes used when an API object template is instantiated
61   // for the first time. Changing of this value afterwards does not affect
62   // the actual attributes of a property.
63   inline PropertyAttributes initial_property_attributes() const;
64   inline void set_initial_property_attributes(PropertyAttributes attributes);
65 
66   // Checks whether the given receiver is compatible with this accessor.
67   static bool IsCompatibleReceiverMap(Handle<AccessorInfo> info,
68                                       Handle<Map> map);
69   inline bool IsCompatibleReceiver(Object receiver);
70 
71   DECL_CAST(AccessorInfo)
72 
73   // Dispatched behavior.
74   DECL_VERIFIER(AccessorInfo)
75 
76   // Append all descriptors to the array that are not already there.
77   // Return number added.
78   static int AppendUnique(Isolate* isolate, Handle<Object> descriptors,
79                           Handle<FixedArray> array, int valid_descriptors);
80 
81   // Layout description.
82   DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize,
83                                 TORQUE_GENERATED_ACCESSOR_INFO_FIELDS)
84 
85  private:
86   inline bool HasExpectedReceiverType();
87 
88   // Bit positions in |flags|.
89   DEFINE_TORQUE_GENERATED_ACCESSOR_INFO_FLAGS()
90 
91   OBJECT_CONSTRUCTORS(AccessorInfo, Struct);
92 };
93 
94 class AccessCheckInfo
95     : public TorqueGeneratedAccessCheckInfo<AccessCheckInfo, Struct> {
96  public:
97   // Dispatched behavior.
98   DECL_PRINTER(AccessCheckInfo)
99 
100   static AccessCheckInfo Get(Isolate* isolate, Handle<JSObject> receiver);
101 
102   TQ_OBJECT_CONSTRUCTORS(AccessCheckInfo)
103 };
104 
105 class InterceptorInfo
106     : public TorqueGeneratedInterceptorInfo<InterceptorInfo, Struct> {
107  public:
108   DECL_BOOLEAN_ACCESSORS(can_intercept_symbols)
109   DECL_BOOLEAN_ACCESSORS(all_can_read)
110   DECL_BOOLEAN_ACCESSORS(non_masking)
111   DECL_BOOLEAN_ACCESSORS(is_named)
112   DECL_BOOLEAN_ACCESSORS(has_no_side_effect)
113 
114   // Dispatched behavior.
115   DECL_PRINTER(InterceptorInfo)
116 
117   static const int kCanInterceptSymbolsBit = 0;
118   static const int kAllCanReadBit = 1;
119   static const int kNonMasking = 2;
120   static const int kNamed = 3;
121   static const int kHasNoSideEffect = 4;
122 
123   TQ_OBJECT_CONSTRUCTORS(InterceptorInfo)
124 };
125 
126 class CallHandlerInfo
127     : public TorqueGeneratedCallHandlerInfo<CallHandlerInfo, Struct> {
128  public:
129   inline bool IsSideEffectFreeCallHandlerInfo() const;
130   inline bool IsSideEffectCallHandlerInfo() const;
131   inline void SetNextCallHasNoSideEffect();
132   // Returns whether or not the next call can be side effect free.
133   // Calling this will change the state back to having a side effect.
134   inline bool NextCallHasNoSideEffect();
135 
136   // Dispatched behavior.
137   DECL_PRINTER(CallHandlerInfo)
138   DECL_VERIFIER(CallHandlerInfo)
139 
140   Address redirected_callback() const;
141 
142   TQ_OBJECT_CONSTRUCTORS(CallHandlerInfo)
143 };
144 
145 }  // namespace internal
146 }  // namespace v8
147 
148 #include "src/objects/object-macros-undef.h"
149 
150 #endif  // V8_OBJECTS_API_CALLBACKS_H_
151