Home | History | Annotate | Download | only in objects
      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_INL_H_
      6 #define V8_OBJECTS_API_CALLBACKS_INL_H_
      7 
      8 #include "src/objects/api-callbacks.h"
      9 
     10 #include "src/heap/heap-inl.h"
     11 #include "src/objects/name.h"
     12 #include "src/objects/templates.h"
     13 
     14 // Has to be the last include (doesn't have include guards):
     15 #include "src/objects/object-macros.h"
     16 
     17 namespace v8 {
     18 namespace internal {
     19 
     20 CAST_ACCESSOR(AccessorInfo)
     21 CAST_ACCESSOR(AccessCheckInfo)
     22 CAST_ACCESSOR(InterceptorInfo)
     23 CAST_ACCESSOR(CallHandlerInfo)
     24 
     25 ACCESSORS(AccessorInfo, name, Name, kNameOffset)
     26 SMI_ACCESSORS(AccessorInfo, flags, kFlagsOffset)
     27 ACCESSORS(AccessorInfo, expected_receiver_type, Object,
     28           kExpectedReceiverTypeOffset)
     29 
     30 ACCESSORS_CHECKED2(AccessorInfo, getter, Object, kGetterOffset, true,
     31                    Foreign::IsNormalized(value))
     32 ACCESSORS_CHECKED2(AccessorInfo, setter, Object, kSetterOffset, true,
     33                    Foreign::IsNormalized(value));
     34 ACCESSORS(AccessorInfo, js_getter, Object, kJsGetterOffset)
     35 ACCESSORS(AccessorInfo, data, Object, kDataOffset)
     36 
     37 bool AccessorInfo::has_getter() {
     38   bool result = getter() != Smi::kZero;
     39   DCHECK_EQ(result,
     40             getter() != Smi::kZero &&
     41                 Foreign::cast(getter())->foreign_address() != kNullAddress);
     42   return result;
     43 }
     44 
     45 bool AccessorInfo::has_setter() {
     46   bool result = setter() != Smi::kZero;
     47   DCHECK_EQ(result,
     48             setter() != Smi::kZero &&
     49                 Foreign::cast(setter())->foreign_address() != kNullAddress);
     50   return result;
     51 }
     52 
     53 BIT_FIELD_ACCESSORS(AccessorInfo, flags, all_can_read,
     54                     AccessorInfo::AllCanReadBit)
     55 BIT_FIELD_ACCESSORS(AccessorInfo, flags, all_can_write,
     56                     AccessorInfo::AllCanWriteBit)
     57 BIT_FIELD_ACCESSORS(AccessorInfo, flags, is_special_data_property,
     58                     AccessorInfo::IsSpecialDataPropertyBit)
     59 BIT_FIELD_ACCESSORS(AccessorInfo, flags, replace_on_access,
     60                     AccessorInfo::ReplaceOnAccessBit)
     61 BIT_FIELD_ACCESSORS(AccessorInfo, flags, is_sloppy, AccessorInfo::IsSloppyBit)
     62 BIT_FIELD_ACCESSORS(AccessorInfo, flags, has_no_side_effect,
     63                     AccessorInfo::HasNoSideEffectBit)
     64 BIT_FIELD_ACCESSORS(AccessorInfo, flags, initial_property_attributes,
     65                     AccessorInfo::InitialAttributesBits)
     66 
     67 bool AccessorInfo::IsCompatibleReceiver(Object* receiver) {
     68   if (!HasExpectedReceiverType()) return true;
     69   if (!receiver->IsJSObject()) return false;
     70   return FunctionTemplateInfo::cast(expected_receiver_type())
     71       ->IsTemplateFor(JSObject::cast(receiver)->map());
     72 }
     73 
     74 bool AccessorInfo::HasExpectedReceiverType() {
     75   return expected_receiver_type()->IsFunctionTemplateInfo();
     76 }
     77 
     78 ACCESSORS(AccessCheckInfo, callback, Object, kCallbackOffset)
     79 ACCESSORS(AccessCheckInfo, named_interceptor, Object, kNamedInterceptorOffset)
     80 ACCESSORS(AccessCheckInfo, indexed_interceptor, Object,
     81           kIndexedInterceptorOffset)
     82 ACCESSORS(AccessCheckInfo, data, Object, kDataOffset)
     83 
     84 ACCESSORS(InterceptorInfo, getter, Object, kGetterOffset)
     85 ACCESSORS(InterceptorInfo, setter, Object, kSetterOffset)
     86 ACCESSORS(InterceptorInfo, query, Object, kQueryOffset)
     87 ACCESSORS(InterceptorInfo, descriptor, Object, kDescriptorOffset)
     88 ACCESSORS(InterceptorInfo, deleter, Object, kDeleterOffset)
     89 ACCESSORS(InterceptorInfo, enumerator, Object, kEnumeratorOffset)
     90 ACCESSORS(InterceptorInfo, definer, Object, kDefinerOffset)
     91 ACCESSORS(InterceptorInfo, data, Object, kDataOffset)
     92 SMI_ACCESSORS(InterceptorInfo, flags, kFlagsOffset)
     93 BOOL_ACCESSORS(InterceptorInfo, flags, can_intercept_symbols,
     94                kCanInterceptSymbolsBit)
     95 BOOL_ACCESSORS(InterceptorInfo, flags, all_can_read, kAllCanReadBit)
     96 BOOL_ACCESSORS(InterceptorInfo, flags, non_masking, kNonMasking)
     97 BOOL_ACCESSORS(InterceptorInfo, flags, is_named, kNamed)
     98 BOOL_ACCESSORS(InterceptorInfo, flags, has_no_side_effect, kHasNoSideEffect)
     99 
    100 ACCESSORS(CallHandlerInfo, callback, Object, kCallbackOffset)
    101 ACCESSORS(CallHandlerInfo, js_callback, Object, kJsCallbackOffset)
    102 ACCESSORS(CallHandlerInfo, data, Object, kDataOffset)
    103 
    104 bool CallHandlerInfo::IsSideEffectFreeCallHandlerInfo() const {
    105   ReadOnlyRoots roots = GetReadOnlyRoots();
    106   DCHECK(map() == roots.side_effect_call_handler_info_map() ||
    107          map() == roots.side_effect_free_call_handler_info_map() ||
    108          map() == roots.next_call_side_effect_free_call_handler_info_map());
    109   return map() == roots.side_effect_free_call_handler_info_map();
    110 }
    111 
    112 bool CallHandlerInfo::IsSideEffectCallHandlerInfo() const {
    113   ReadOnlyRoots roots = GetReadOnlyRoots();
    114   DCHECK(map() == roots.side_effect_call_handler_info_map() ||
    115          map() == roots.side_effect_free_call_handler_info_map() ||
    116          map() == roots.next_call_side_effect_free_call_handler_info_map());
    117   return map() == roots.side_effect_call_handler_info_map();
    118 }
    119 
    120 void CallHandlerInfo::SetNextCallHasNoSideEffect() {
    121   set_map(
    122       GetReadOnlyRoots().next_call_side_effect_free_call_handler_info_map());
    123 }
    124 
    125 bool CallHandlerInfo::NextCallHasNoSideEffect() {
    126   ReadOnlyRoots roots = GetReadOnlyRoots();
    127   if (map() == roots.next_call_side_effect_free_call_handler_info_map()) {
    128     set_map(roots.side_effect_call_handler_info_map());
    129     return true;
    130   }
    131   return false;
    132 }
    133 
    134 }  // namespace internal
    135 }  // namespace v8
    136 
    137 #include "src/objects/object-macros-undef.h"
    138 
    139 #endif  // V8_OBJECTS_API_CALLBACKS_INL_H_
    140