5#ifndef INCLUDE_V8_FUNCTION_CALLBACK_H_
6#define INCLUDE_V8_FUNCTION_CALLBACK_H_
19class BasicTracedReference;
26class FunctionCallbackArguments;
27class PropertyCallbackArguments;
32class ConsoleCallArguments;
35namespace api_internal {
45 static_assert(std::is_base_of_v<T, S>,
"type check");
96 template <
class F,
class G,
class H>
109 static constexpr int kIsolateValueIndex = -1;
158 kNewTargetIndex = -1,
171 kFrameConstantPoolIndex,
176 kFirstApiArgumentIndex,
177 kIsolateIndex = kFirstApiArgumentIndex,
184 kFirstJSArgumentIndex,
187 kArgsLength = kReceiverIndex + 1,
189 kOptionalArgsLength = 1,
192 kApiArgsLength = kReceiverIndex - kFirstApiArgumentIndex,
195 static_assert(kArgcIndex == 0);
197 kIsolateIndex - kReturnValueIndex);
200 return &values_[kFirstJSArgumentIndex];
203 V8_INLINE FunctionCallbackInfo() =
default;
207 FunctionCallbackInfo(
const FunctionCallbackInfo&) =
delete;
208 FunctionCallbackInfo& operator=(
const FunctionCallbackInfo&) =
delete;
209 FunctionCallbackInfo(FunctionCallbackInfo&&) =
delete;
210 FunctionCallbackInfo& operator=(FunctionCallbackInfo&&) =
delete;
280 "Access to receiver will be deprecated soon. Use HolderV2() instead. \n"
281 "See http://crbug.com/455600234. ")
321 template <typename U>
327 using
I = internal::Internals;
336 static constexpr
bool HasShouldThrowOnError() {
337 return std::is_same_v<T, v8::Boolean> || std::is_same_v<T, void>;
353 kFrameConstantPoolIndex,
358 kFirstApiArgumentIndex,
359 kIsolateIndex = kFirstApiArgumentIndex,
371 kFirstOptionalArgument,
372 kShouldThrowOnErrorIndex = kFirstOptionalArgument,
378 kMandatoryArgsLength = kFirstOptionalArgument,
379 kOptionalArgsLength = kFullArgsLength - kFirstOptionalArgument,
382 kMandatoryApiArgsLength = kMandatoryArgsLength - kFirstApiArgumentIndex,
383 kFullApiArgsLength = kFullArgsLength - kFirstApiArgumentIndex,
410void ReturnValue<T>::SetInternal(internal::Address value) {
411#if V8_STATIC_ROOTS_BOOL
412 using I = internal::Internals;
417 *value_ = I::DecompressTaggedField(*value_, I::CompressTagged(value));
426 static_assert(std::is_base_of_v<T, S>,
"type check");
430 SetInternal(handle.
ptr());
437 static_assert(std::is_base_of_v<T, S>,
"type check");
438#ifdef V8_ENABLE_CHECKS
439 internal::VerifyHandleIsNonEmpty(handle.
IsEmpty());
441 SetInternal(handle.
ptr());
447 static_assert(std::is_base_of_v<T, S>,
"type check");
451 SetInternal(handle.
ptr());
458 static_assert(std::is_base_of_v<T, S>,
"type check");
459#ifdef V8_ENABLE_CHECKS
460 internal::VerifyHandleIsNonEmpty(handle.
IsEmpty());
462 SetInternal(handle.
ptr());
468 static_assert(std::is_base_of_v<T, S>,
"type check");
472 SetInternal(handle.
ptr());
479 static_assert(std::is_base_of_v<T, S>,
"type check");
480#ifdef V8_ENABLE_CHECKS
481 internal::VerifyHandleIsNonEmpty(handle.
IsEmpty());
483 SetInternal(handle.
ptr());
488 static_assert(std::is_base_of_v<T, Number>,
"type check");
489 SetNonEmpty(Number::New(GetIsolate(), i));
494 static_assert(std::is_base_of_v<T, Integer>,
"type check");
496 static_assert(I::IsValidSmi(std::numeric_limits<int16_t>::min()));
497 static_assert(I::IsValidSmi(std::numeric_limits<int16_t>::max()));
498 SetInternal(I::IntegralToSmi(i));
503 static_assert(std::is_base_of_v<T, Integer>,
"type check");
504 if (
const auto result = internal::Internals::TryIntegralToSmi(i)) {
505 SetInternal(*result);
508 SetNonEmpty(Integer::New(GetIsolate(), i));
513 static_assert(std::is_base_of_v<T, Integer>,
"type check");
514 if (
const auto result = internal::Internals::TryIntegralToSmi(i)) {
515 SetInternal(*result);
518 SetNonEmpty(Number::New(GetIsolate(),
static_cast<double>(i)));
523 static_assert(std::is_base_of_v<T, Integer>,
"type check");
525 static_assert(I::IsValidSmi(std::numeric_limits<uint16_t>::min()));
526 static_assert(I::IsValidSmi(std::numeric_limits<uint16_t>::max()));
527 SetInternal(I::IntegralToSmi(i));
532 static_assert(std::is_base_of_v<T, Integer>,
"type check");
533 if (
const auto result = internal::Internals::TryIntegralToSmi(i)) {
534 SetInternal(*result);
537 SetNonEmpty(Integer::NewFromUnsigned(GetIsolate(), i));
542 static_assert(std::is_base_of_v<T, Integer>,
"type check");
543 if (
const auto result = internal::Internals::TryIntegralToSmi(i)) {
544 SetInternal(*result);
547 SetNonEmpty(Number::New(GetIsolate(),
static_cast<double>(i)));
552 static_assert(std::is_void_v<T> || std::is_base_of_v<T, Boolean>,
555#if V8_STATIC_ROOTS_BOOL
556#ifdef V8_ENABLE_CHECKS
557 internal::PerformCastCheck(
558 internal::ValueHelper::SlotAsValue<Value, true>(value_));
560 SetInternal(value ? I::StaticReadOnlyRoot::kTrueValue
561 : I::StaticReadOnlyRoot::kFalseValue);
565 root_index = I::kTrueValueRootIndex;
567 root_index = I::kFalseValueRootIndex;
569 *value_ = I::GetRoot(GetIsolate(), root_index);
576 if constexpr (std::is_same_v<void, T> || std::is_same_v<v8::Boolean, T>) {
578 }
else if constexpr (std::is_same_v<v8::Integer, T>) {
579 SetInternal(I::IntegralToSmi(0));
581 static_assert(std::is_same_v<v8::Value, T> || std::is_same_v<v8::Array, T>);
582#if V8_STATIC_ROOTS_BOOL
583 SetInternal(I::StaticReadOnlyRoot::kUndefinedValue);
585 *value_ = I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex);
592 static_assert(std::is_base_of_v<T, Primitive>,
"type check");
594#if V8_STATIC_ROOTS_BOOL
595#ifdef V8_ENABLE_CHECKS
596 internal::PerformCastCheck(
597 internal::ValueHelper::SlotAsValue<Value, true>(value_));
599 SetInternal(I::StaticReadOnlyRoot::kNullValue);
601 *value_ = I::GetRoot(GetIsolate(), I::kNullValueRootIndex);
607 static_assert(std::is_base_of_v<T, Primitive>,
"type check");
609#if V8_STATIC_ROOTS_BOOL
610#ifdef V8_ENABLE_CHECKS
611 internal::PerformCastCheck(
612 internal::ValueHelper::SlotAsValue<Value, true>(value_));
614 SetInternal(I::StaticReadOnlyRoot::kUndefinedValue);
616 *value_ = I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex);
622 static_assert(std::is_void_v<T> || std::is_base_of_v<T, Boolean>,
625#if V8_STATIC_ROOTS_BOOL
626#ifdef V8_ENABLE_CHECKS
627 internal::PerformCastCheck(
628 internal::ValueHelper::SlotAsValue<Value, true>(value_));
630 SetInternal(I::StaticReadOnlyRoot::kFalseValue);
632 *value_ = I::GetRoot(GetIsolate(), I::kFalseValueRootIndex);
638 static_assert(std::is_base_of_v<T, String>,
"type check");
640#if V8_STATIC_ROOTS_BOOL
641#ifdef V8_ENABLE_CHECKS
642 internal::PerformCastCheck(
643 internal::ValueHelper::SlotAsValue<Value, true>(value_));
645 SetInternal(I::StaticReadOnlyRoot::kEmptyString);
647 *value_ = I::GetRoot(GetIsolate(), I::kEmptyStringRootIndex);
653 return *
reinterpret_cast<Isolate**
>(&value_[kIsolateValueIndex]);
659 internal::ValueHelper::SlotAsValue<Value>(value_));
665 static_assert(
sizeof(S) < 0,
"incompilable to prevent inadvertent misuse");
670 if (i < 0 || Length() <= i)
return Undefined(GetIsolate());
681 if (IsConstructCall()) {
693 return api_internal::GetFunctionTemplateData(GetIsolate(), target);
698 return reinterpret_cast<Isolate*
>(values_[kIsolateIndex]);
708 return I::SmiValue(values_[kFrameTypeIndex]) == I::kFrameTypeApiConstructExit;
713 return static_cast<int>(values_[kArgcIndex]);
718 return I::SmiValue(args_[kFrameTypeIndex]) ==
719 I::kFrameTypeApiNamedAccessorExit;
724 return *
reinterpret_cast<Isolate**
>(&args_[kIsolateIndex]);
731 I::ReadTaggedPointerField(callback_info, I::kCallbackInfoDataOffset);
752 if constexpr (!HasShouldThrowOnError())
return false;
753 if (args_[kShouldThrowOnErrorIndex] !=
754 I::IntegralToSmi(I::kInferShouldThrowMode)) {
755 return args_[kShouldThrowOnErrorIndex] != I::IntegralToSmi(I::kDontThrow);
758 reinterpret_cast<v8::internal::Isolate*
>(GetIsolate()));
Definition: v8-traced-handle.h:124
Definition: v8-function-callback.h:121
ReturnValue< T > GetReturnValue() const
Definition: v8-function-callback.h:702
Local< Object > This() const
Definition: v8-function-callback.h:675
Local< Value > operator[](int i) const
Definition: v8-function-callback.h:669
Isolate * GetIsolate() const
Definition: v8-function-callback.h:697
Local< Value > NewTarget() const
Definition: v8-function-callback.h:680
friend class debug::ConsoleCallArguments
Definition: v8-function-callback.h:146
friend class internal::FunctionCallbackArguments
Definition: v8-function-callback.h:144
Local< Value > Data() const
Definition: v8-function-callback.h:691
bool IsConstructCall() const
Definition: v8-function-callback.h:707
int Length() const
Definition: v8-function-callback.h:712
Definition: v8-persistent-handle.h:349
Definition: v8-isolate.h:291
Definition: v8-local-handle.h:366
Definition: v8-object.h:262
Definition: v8-util.h:166
Definition: v8-function-callback.h:224
Local< Value > Data() const
Definition: v8-function-callback.h:728
friend class internal::PropertyCallbackArguments
Definition: v8-function-callback.h:324
friend class PropertyCallbackInfo
Definition: v8-function-callback.h:322
bool ShouldThrowOnError() const
Definition: v8-function-callback.h:751
ReturnValue< T > GetReturnValue() const
Definition: v8-function-callback.h:746
Local< Object > HolderV2() const
Definition: v8-function-callback.h:741
friend void internal::PrintPropertyCallbackInfo(void *)
friend class MacroAssembler
Definition: v8-function-callback.h:323
Local< Object > This() const
Definition: v8-function-callback.h:736
Isolate * GetIsolate() const
Definition: v8-function-callback.h:723
Definition: v8-function-callback.h:41
void SetFalse()
Definition: v8-function-callback.h:621
void SetEmptyString()
Definition: v8-function-callback.h:637
friend class ReturnValue
Definition: v8-function-callback.h:91
ReturnValue(const ReturnValue< S > &that)
Definition: v8-function-callback.h:44
void SetNonEmpty(const Global< S > &handle)
Definition: v8-function-callback.h:436
Local< Value > Get() const
Definition: v8-function-callback.h:657
void SetNull()
Definition: v8-function-callback.h:591
Isolate * GetIsolate() const
Definition: v8-function-callback.h:652
void SetUndefined()
Definition: v8-function-callback.h:606
Definition: v8-container.h:148
internal::Address ptr() const
Definition: v8-handle-base.h:80
bool IsEmpty() const
Definition: v8-handle-base.h:60
Definition: v8-local-handle.h:75
Definition: v8-internal.h:885
static constexpr int kSPAlignmentSlotCount
Definition: v8-internal.h:1036
static constexpr int kFrameCPSlotCount
Definition: v8-internal.h:1029
v8::Local< v8::Value > GetFunctionTemplateData(v8::Isolate *isolate, v8::Local< v8::Data > raw_target)
bool ShouldThrowOnError(internal::Isolate *isolate)
uintptr_t Address
Definition: v8-internal.h:38
void PrintFunctionCallbackInfo(void *function_callback_info)
Definition: libplatform.h:15
Local< Primitive > Undefined(Isolate *isolate)
Definition: v8-primitive.h:1018
void(*)(const FunctionCallbackInfo< Value > &info) FunctionCallback
Definition: v8-function-callback.h:402
#define V8_EXPORT
Definition: v8config.h:855
#define V8_INLINE
Definition: v8config.h:508
#define V8_DEPRECATED(message)
Definition: v8config.h:614
#define V8_UNLIKELY(condition)
Definition: v8config.h:668