11cb0ef41Sopenharmony_ci// Copyright 2018 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#ifndef V8_OBJECTS_API_CALLBACKS_INL_H_
61cb0ef41Sopenharmony_ci#define V8_OBJECTS_API_CALLBACKS_INL_H_
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci#include "src/objects/api-callbacks.h"
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci#include "src/heap/heap-write-barrier-inl.h"
111cb0ef41Sopenharmony_ci#include "src/heap/heap-write-barrier.h"
121cb0ef41Sopenharmony_ci#include "src/objects/foreign-inl.h"
131cb0ef41Sopenharmony_ci#include "src/objects/js-objects-inl.h"
141cb0ef41Sopenharmony_ci#include "src/objects/name.h"
151cb0ef41Sopenharmony_ci#include "src/objects/templates.h"
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ci// Has to be the last include (doesn't have include guards):
181cb0ef41Sopenharmony_ci#include "src/objects/object-macros.h"
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_cinamespace v8 {
211cb0ef41Sopenharmony_cinamespace internal {
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ci#include "torque-generated/src/objects/api-callbacks-tq-inl.inc"
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(AccessCheckInfo)
261cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(AccessorInfo)
271cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(InterceptorInfo)
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(CallHandlerInfo)
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ciACCESSORS_CHECKED2(AccessorInfo, getter, Object, kGetterOffset, true,
321cb0ef41Sopenharmony_ci                   Foreign::IsNormalized(value))
331cb0ef41Sopenharmony_ciACCESSORS_CHECKED2(AccessorInfo, setter, Object, kSetterOffset, true,
341cb0ef41Sopenharmony_ci                   Foreign::IsNormalized(value))
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_cibool AccessorInfo::has_getter() {
371cb0ef41Sopenharmony_ci  bool result = getter() != Smi::zero();
381cb0ef41Sopenharmony_ci  DCHECK_EQ(result,
391cb0ef41Sopenharmony_ci            getter() != Smi::zero() &&
401cb0ef41Sopenharmony_ci                Foreign::cast(getter()).foreign_address() != kNullAddress);
411cb0ef41Sopenharmony_ci  return result;
421cb0ef41Sopenharmony_ci}
431cb0ef41Sopenharmony_ci
441cb0ef41Sopenharmony_cibool AccessorInfo::has_setter() {
451cb0ef41Sopenharmony_ci  bool result = setter() != Smi::zero();
461cb0ef41Sopenharmony_ci  DCHECK_EQ(result,
471cb0ef41Sopenharmony_ci            setter() != Smi::zero() &&
481cb0ef41Sopenharmony_ci                Foreign::cast(setter()).foreign_address() != kNullAddress);
491cb0ef41Sopenharmony_ci  return result;
501cb0ef41Sopenharmony_ci}
511cb0ef41Sopenharmony_ci
521cb0ef41Sopenharmony_ciBIT_FIELD_ACCESSORS(AccessorInfo, flags, all_can_read,
531cb0ef41Sopenharmony_ci                    AccessorInfo::AllCanReadBit)
541cb0ef41Sopenharmony_ciBIT_FIELD_ACCESSORS(AccessorInfo, flags, all_can_write,
551cb0ef41Sopenharmony_ci                    AccessorInfo::AllCanWriteBit)
561cb0ef41Sopenharmony_ciBIT_FIELD_ACCESSORS(AccessorInfo, flags, is_special_data_property,
571cb0ef41Sopenharmony_ci                    AccessorInfo::IsSpecialDataPropertyBit)
581cb0ef41Sopenharmony_ciBIT_FIELD_ACCESSORS(AccessorInfo, flags, replace_on_access,
591cb0ef41Sopenharmony_ci                    AccessorInfo::ReplaceOnAccessBit)
601cb0ef41Sopenharmony_ciBIT_FIELD_ACCESSORS(AccessorInfo, flags, is_sloppy, AccessorInfo::IsSloppyBit)
611cb0ef41Sopenharmony_ciBIT_FIELD_ACCESSORS(AccessorInfo, flags, getter_side_effect_type,
621cb0ef41Sopenharmony_ci                    AccessorInfo::GetterSideEffectTypeBits)
631cb0ef41Sopenharmony_ci
641cb0ef41Sopenharmony_ciSideEffectType AccessorInfo::setter_side_effect_type() const {
651cb0ef41Sopenharmony_ci  return SetterSideEffectTypeBits::decode(flags());
661cb0ef41Sopenharmony_ci}
671cb0ef41Sopenharmony_ci
681cb0ef41Sopenharmony_civoid AccessorInfo::set_setter_side_effect_type(SideEffectType value) {
691cb0ef41Sopenharmony_ci  // We do not support describing setters as having no side effect, since
701cb0ef41Sopenharmony_ci  // calling set accessors must go through a store bytecode. Store bytecodes
711cb0ef41Sopenharmony_ci  // support checking receivers for temporary objects, but still expect
721cb0ef41Sopenharmony_ci  // the receiver to be written to.
731cb0ef41Sopenharmony_ci  CHECK_NE(value, SideEffectType::kHasNoSideEffect);
741cb0ef41Sopenharmony_ci  set_flags(SetterSideEffectTypeBits::update(flags(), value));
751cb0ef41Sopenharmony_ci}
761cb0ef41Sopenharmony_ci
771cb0ef41Sopenharmony_ciBIT_FIELD_ACCESSORS(AccessorInfo, flags, initial_property_attributes,
781cb0ef41Sopenharmony_ci                    AccessorInfo::InitialAttributesBits)
791cb0ef41Sopenharmony_ci
801cb0ef41Sopenharmony_cibool AccessorInfo::IsCompatibleReceiver(Object receiver) {
811cb0ef41Sopenharmony_ci  if (!HasExpectedReceiverType()) return true;
821cb0ef41Sopenharmony_ci  if (!receiver.IsJSObject()) return false;
831cb0ef41Sopenharmony_ci  return FunctionTemplateInfo::cast(expected_receiver_type())
841cb0ef41Sopenharmony_ci      .IsTemplateFor(JSObject::cast(receiver).map());
851cb0ef41Sopenharmony_ci}
861cb0ef41Sopenharmony_ci
871cb0ef41Sopenharmony_cibool AccessorInfo::HasExpectedReceiverType() {
881cb0ef41Sopenharmony_ci  return expected_receiver_type().IsFunctionTemplateInfo();
891cb0ef41Sopenharmony_ci}
901cb0ef41Sopenharmony_ci
911cb0ef41Sopenharmony_ciBOOL_ACCESSORS(InterceptorInfo, flags, can_intercept_symbols,
921cb0ef41Sopenharmony_ci               CanInterceptSymbolsBit::kShift)
931cb0ef41Sopenharmony_ciBOOL_ACCESSORS(InterceptorInfo, flags, all_can_read, AllCanReadBit::kShift)
941cb0ef41Sopenharmony_ciBOOL_ACCESSORS(InterceptorInfo, flags, non_masking, NonMaskingBit::kShift)
951cb0ef41Sopenharmony_ciBOOL_ACCESSORS(InterceptorInfo, flags, is_named, NamedBit::kShift)
961cb0ef41Sopenharmony_ciBOOL_ACCESSORS(InterceptorInfo, flags, has_no_side_effect,
971cb0ef41Sopenharmony_ci               HasNoSideEffectBit::kShift)
981cb0ef41Sopenharmony_ci
991cb0ef41Sopenharmony_cibool CallHandlerInfo::IsSideEffectFreeCallHandlerInfo() const {
1001cb0ef41Sopenharmony_ci  ReadOnlyRoots roots = GetReadOnlyRoots();
1011cb0ef41Sopenharmony_ci  DCHECK(map() == roots.side_effect_call_handler_info_map() ||
1021cb0ef41Sopenharmony_ci         map() == roots.side_effect_free_call_handler_info_map() ||
1031cb0ef41Sopenharmony_ci         map() == roots.next_call_side_effect_free_call_handler_info_map());
1041cb0ef41Sopenharmony_ci  return map() == roots.side_effect_free_call_handler_info_map();
1051cb0ef41Sopenharmony_ci}
1061cb0ef41Sopenharmony_ci
1071cb0ef41Sopenharmony_cibool CallHandlerInfo::IsSideEffectCallHandlerInfo() const {
1081cb0ef41Sopenharmony_ci  ReadOnlyRoots roots = GetReadOnlyRoots();
1091cb0ef41Sopenharmony_ci  DCHECK(map() == roots.side_effect_call_handler_info_map() ||
1101cb0ef41Sopenharmony_ci         map() == roots.side_effect_free_call_handler_info_map() ||
1111cb0ef41Sopenharmony_ci         map() == roots.next_call_side_effect_free_call_handler_info_map());
1121cb0ef41Sopenharmony_ci  return map() == roots.side_effect_call_handler_info_map();
1131cb0ef41Sopenharmony_ci}
1141cb0ef41Sopenharmony_ci
1151cb0ef41Sopenharmony_civoid CallHandlerInfo::SetNextCallHasNoSideEffect() {
1161cb0ef41Sopenharmony_ci  set_map(
1171cb0ef41Sopenharmony_ci      GetReadOnlyRoots().next_call_side_effect_free_call_handler_info_map());
1181cb0ef41Sopenharmony_ci}
1191cb0ef41Sopenharmony_ci
1201cb0ef41Sopenharmony_cibool CallHandlerInfo::NextCallHasNoSideEffect() {
1211cb0ef41Sopenharmony_ci  ReadOnlyRoots roots = GetReadOnlyRoots();
1221cb0ef41Sopenharmony_ci  if (map() == roots.next_call_side_effect_free_call_handler_info_map()) {
1231cb0ef41Sopenharmony_ci    set_map(roots.side_effect_call_handler_info_map());
1241cb0ef41Sopenharmony_ci    return true;
1251cb0ef41Sopenharmony_ci  }
1261cb0ef41Sopenharmony_ci  return false;
1271cb0ef41Sopenharmony_ci}
1281cb0ef41Sopenharmony_ci
1291cb0ef41Sopenharmony_ci}  // namespace internal
1301cb0ef41Sopenharmony_ci}  // namespace v8
1311cb0ef41Sopenharmony_ci
1321cb0ef41Sopenharmony_ci#include "src/objects/object-macros-undef.h"
1331cb0ef41Sopenharmony_ci
1341cb0ef41Sopenharmony_ci#endif  // V8_OBJECTS_API_CALLBACKS_INL_H_
135