• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.h"
10 
11 // Has to be the last include (doesn't have include guards):
12 #include "src/objects/object-macros.h"
13 
14 namespace v8 {
15 namespace internal {
16 
17 #include "torque-generated/src/objects/api-callbacks-tq.inc"
18 
19 // An accessor must have a getter, but can have no setter.
20 //
21 // When setting a property, V8 searches accessors in prototypes.
22 // If an accessor was found and it does not have a setter,
23 // the request is ignored.
24 //
25 // If the accessor in the prototype has the READ_ONLY property attribute, then
26 // a new value is added to the derived object when the property is set.
27 // This shadows the accessor in the prototype.
28 class AccessorInfo : public TorqueGeneratedAccessorInfo<AccessorInfo, Struct> {
29  public:
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 
36   static Address redirect(Address address, AccessorComponent component);
37   Address redirected_getter() const;
38 
39   DECL_BOOLEAN_ACCESSORS(all_can_read)
40   DECL_BOOLEAN_ACCESSORS(all_can_write)
41   DECL_BOOLEAN_ACCESSORS(is_special_data_property)
42   DECL_BOOLEAN_ACCESSORS(replace_on_access)
43   DECL_BOOLEAN_ACCESSORS(is_sloppy)
44 
45   inline SideEffectType getter_side_effect_type() const;
46   inline void set_getter_side_effect_type(SideEffectType type);
47 
48   inline SideEffectType setter_side_effect_type() const;
49   inline void set_setter_side_effect_type(SideEffectType type);
50 
51   // The property attributes used when an API object template is instantiated
52   // for the first time. Changing of this value afterwards does not affect
53   // the actual attributes of a property.
54   inline PropertyAttributes initial_property_attributes() const;
55   inline void set_initial_property_attributes(PropertyAttributes attributes);
56 
57   // Checks whether the given receiver is compatible with this accessor.
58   static bool IsCompatibleReceiverMap(Handle<AccessorInfo> info,
59                                       Handle<Map> map);
60   inline bool IsCompatibleReceiver(Object receiver);
61 
62   // Append all descriptors to the array that are not already there.
63   // Return number added.
64   static int AppendUnique(Isolate* isolate, Handle<Object> descriptors,
65                           Handle<FixedArray> array, int valid_descriptors);
66 
67  private:
68   inline bool HasExpectedReceiverType();
69 
70   // Bit positions in |flags|.
71   DEFINE_TORQUE_GENERATED_ACCESSOR_INFO_FLAGS()
72 
73   TQ_OBJECT_CONSTRUCTORS(AccessorInfo)
74 };
75 
76 class AccessCheckInfo
77     : public TorqueGeneratedAccessCheckInfo<AccessCheckInfo, Struct> {
78  public:
79   static AccessCheckInfo Get(Isolate* isolate, Handle<JSObject> receiver);
80 
81   TQ_OBJECT_CONSTRUCTORS(AccessCheckInfo)
82 };
83 
84 class InterceptorInfo
85     : public TorqueGeneratedInterceptorInfo<InterceptorInfo, Struct> {
86  public:
87   DECL_BOOLEAN_ACCESSORS(can_intercept_symbols)
88   DECL_BOOLEAN_ACCESSORS(all_can_read)
89   DECL_BOOLEAN_ACCESSORS(non_masking)
90   DECL_BOOLEAN_ACCESSORS(is_named)
91   DECL_BOOLEAN_ACCESSORS(has_no_side_effect)
92 
93   DEFINE_TORQUE_GENERATED_INTERCEPTOR_INFO_FLAGS()
94 
95   TQ_OBJECT_CONSTRUCTORS(InterceptorInfo)
96 };
97 
98 class CallHandlerInfo
99     : public TorqueGeneratedCallHandlerInfo<CallHandlerInfo, Struct> {
100  public:
101   inline bool IsSideEffectFreeCallHandlerInfo() const;
102   inline bool IsSideEffectCallHandlerInfo() const;
103   inline void SetNextCallHasNoSideEffect();
104   // Returns whether or not the next call can be side effect free.
105   // Calling this will change the state back to having a side effect.
106   inline bool NextCallHasNoSideEffect();
107 
108   // Dispatched behavior.
109   DECL_PRINTER(CallHandlerInfo)
110   DECL_VERIFIER(CallHandlerInfo)
111 
112   Address redirected_callback() const;
113 
114   TQ_OBJECT_CONSTRUCTORS(CallHandlerInfo)
115 };
116 
117 }  // namespace internal
118 }  // namespace v8
119 
120 #include "src/objects/object-macros-undef.h"
121 
122 #endif  // V8_OBJECTS_API_CALLBACKS_H_
123