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;
277 template <typename U>
283 using
I = internal::Internals;
292 static constexpr
bool HasShouldThrowOnError() {
293 return std::is_same_v<T, v8::Boolean> || std::is_same_v<T, void>;
309 kFrameConstantPoolIndex,
314 kFirstApiArgumentIndex,
315 kIsolateIndex = kFirstApiArgumentIndex,
323 kFirstOptionalArgument,
324 kShouldThrowOnErrorIndex = kFirstOptionalArgument,
330 kMandatoryArgsLength = kFirstOptionalArgument,
331 kOptionalArgsLength = kFullArgsLength - kFirstOptionalArgument,
334 kMandatoryApiArgsLength = kMandatoryArgsLength - kFirstApiArgumentIndex,
335 kFullApiArgsLength = kFullArgsLength - kFirstApiArgumentIndex,
362void ReturnValue<T>::SetInternal(internal::Address value) {
363#if V8_STATIC_ROOTS_BOOL
364 using I = internal::Internals;
369 *value_ = I::DecompressTaggedField(*value_, I::CompressTagged(value));
378 static_assert(std::is_base_of_v<T, S>,
"type check");
382 SetInternal(handle.
ptr());
389 static_assert(std::is_base_of_v<T, S>,
"type check");
390#ifdef V8_ENABLE_CHECKS
391 internal::VerifyHandleIsNonEmpty(handle.
IsEmpty());
393 SetInternal(handle.
ptr());
399 static_assert(std::is_base_of_v<T, S>,
"type check");
403 SetInternal(handle.
ptr());
410 static_assert(std::is_base_of_v<T, S>,
"type check");
411#ifdef V8_ENABLE_CHECKS
412 internal::VerifyHandleIsNonEmpty(handle.
IsEmpty());
414 SetInternal(handle.
ptr());
420 static_assert(std::is_base_of_v<T, S>,
"type check");
424 SetInternal(handle.
ptr());
431 static_assert(std::is_base_of_v<T, S>,
"type check");
432#ifdef V8_ENABLE_CHECKS
433 internal::VerifyHandleIsNonEmpty(handle.
IsEmpty());
435 SetInternal(handle.
ptr());
440 static_assert(std::is_base_of_v<T, Number>,
"type check");
441 SetNonEmpty(Number::New(GetIsolate(), i));
446 static_assert(std::is_base_of_v<T, Integer>,
"type check");
448 static_assert(I::IsValidSmi(std::numeric_limits<int16_t>::min()));
449 static_assert(I::IsValidSmi(std::numeric_limits<int16_t>::max()));
450 SetInternal(I::IntegralToSmi(i));
455 static_assert(std::is_base_of_v<T, Integer>,
"type check");
456 if (
const auto result = internal::Internals::TryIntegralToSmi(i)) {
457 SetInternal(*result);
460 SetNonEmpty(Integer::New(GetIsolate(), i));
465 static_assert(std::is_base_of_v<T, Integer>,
"type check");
466 if (
const auto result = internal::Internals::TryIntegralToSmi(i)) {
467 SetInternal(*result);
470 SetNonEmpty(Number::New(GetIsolate(),
static_cast<double>(i)));
475 static_assert(std::is_base_of_v<T, Integer>,
"type check");
477 static_assert(I::IsValidSmi(std::numeric_limits<uint16_t>::min()));
478 static_assert(I::IsValidSmi(std::numeric_limits<uint16_t>::max()));
479 SetInternal(I::IntegralToSmi(i));
484 static_assert(std::is_base_of_v<T, Integer>,
"type check");
485 if (
const auto result = internal::Internals::TryIntegralToSmi(i)) {
486 SetInternal(*result);
489 SetNonEmpty(Integer::NewFromUnsigned(GetIsolate(), i));
494 static_assert(std::is_base_of_v<T, Integer>,
"type check");
495 if (
const auto result = internal::Internals::TryIntegralToSmi(i)) {
496 SetInternal(*result);
499 SetNonEmpty(Number::New(GetIsolate(),
static_cast<double>(i)));
504 static_assert(std::is_void_v<T> || std::is_base_of_v<T, Boolean>,
507#if V8_STATIC_ROOTS_BOOL
508#ifdef V8_ENABLE_CHECKS
509 internal::PerformCastCheck(
510 internal::ValueHelper::SlotAsValue<Value, true>(value_));
512 SetInternal(value ? I::StaticReadOnlyRoot::kTrueValue
513 : I::StaticReadOnlyRoot::kFalseValue);
517 root_index = I::kTrueValueRootIndex;
519 root_index = I::kFalseValueRootIndex;
521 *value_ = I::GetRoot(GetIsolate(), root_index);
528 if constexpr (std::is_same_v<void, T> || std::is_same_v<v8::Boolean, T>) {
530 }
else if constexpr (std::is_same_v<v8::Integer, T>) {
531 SetInternal(I::IntegralToSmi(0));
533 static_assert(std::is_same_v<v8::Value, T> || std::is_same_v<v8::Array, T>);
534#if V8_STATIC_ROOTS_BOOL
535 SetInternal(I::StaticReadOnlyRoot::kUndefinedValue);
537 *value_ = I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex);
544 static_assert(std::is_base_of_v<T, Primitive>,
"type check");
546#if V8_STATIC_ROOTS_BOOL
547#ifdef V8_ENABLE_CHECKS
548 internal::PerformCastCheck(
549 internal::ValueHelper::SlotAsValue<Value, true>(value_));
551 SetInternal(I::StaticReadOnlyRoot::kNullValue);
553 *value_ = I::GetRoot(GetIsolate(), I::kNullValueRootIndex);
559 static_assert(std::is_base_of_v<T, Primitive>,
"type check");
561#if V8_STATIC_ROOTS_BOOL
562#ifdef V8_ENABLE_CHECKS
563 internal::PerformCastCheck(
564 internal::ValueHelper::SlotAsValue<Value, true>(value_));
566 SetInternal(I::StaticReadOnlyRoot::kUndefinedValue);
568 *value_ = I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex);
574 static_assert(std::is_void_v<T> || std::is_base_of_v<T, Boolean>,
577#if V8_STATIC_ROOTS_BOOL
578#ifdef V8_ENABLE_CHECKS
579 internal::PerformCastCheck(
580 internal::ValueHelper::SlotAsValue<Value, true>(value_));
582 SetInternal(I::StaticReadOnlyRoot::kFalseValue);
584 *value_ = I::GetRoot(GetIsolate(), I::kFalseValueRootIndex);
590 static_assert(std::is_base_of_v<T, String>,
"type check");
592#if V8_STATIC_ROOTS_BOOL
593#ifdef V8_ENABLE_CHECKS
594 internal::PerformCastCheck(
595 internal::ValueHelper::SlotAsValue<Value, true>(value_));
597 SetInternal(I::StaticReadOnlyRoot::kEmptyString);
599 *value_ = I::GetRoot(GetIsolate(), I::kEmptyStringRootIndex);
605 return *
reinterpret_cast<Isolate**
>(&value_[kIsolateValueIndex]);
611 internal::ValueHelper::SlotAsValue<Value>(value_));
617 static_assert(
sizeof(S) < 0,
"incompilable to prevent inadvertent misuse");
622 if (i < 0 || Length() <= i)
return Undefined(GetIsolate());
633 if (IsConstructCall()) {
645 return api_internal::GetFunctionTemplateData(GetIsolate(), target);
650 return reinterpret_cast<Isolate*
>(values_[kIsolateIndex]);
660 return I::SmiValue(values_[kFrameTypeIndex]) == I::kFrameTypeApiConstructExit;
665 return static_cast<int>(values_[kArgcIndex]);
670 return I::SmiValue(args_[kFrameTypeIndex]) ==
671 I::kFrameTypeApiNamedAccessorExit;
676 return *
reinterpret_cast<Isolate**
>(&args_[kIsolateIndex]);
683 I::ReadTaggedPointerField(callback_info, I::kCallbackInfoDataOffset);
703 if constexpr (!HasShouldThrowOnError())
return false;
704 if (args_[kShouldThrowOnErrorIndex] !=
705 I::IntegralToSmi(I::kInferShouldThrowMode)) {
706 return args_[kShouldThrowOnErrorIndex] != I::IntegralToSmi(I::kDontThrow);
709 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:654
Local< Object > This() const
Definition: v8-function-callback.h:627
Local< Value > operator[](int i) const
Definition: v8-function-callback.h:621
Isolate * GetIsolate() const
Definition: v8-function-callback.h:649
Local< Value > NewTarget() const
Definition: v8-function-callback.h:632
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:643
bool IsConstructCall() const
Definition: v8-function-callback.h:659
int Length() const
Definition: v8-function-callback.h:664
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:680
friend class internal::PropertyCallbackArguments
Definition: v8-function-callback.h:280
friend class PropertyCallbackInfo
Definition: v8-function-callback.h:278
Local< Object > Holder() const
Definition: v8-function-callback.h:688
bool ShouldThrowOnError() const
Definition: v8-function-callback.h:702
ReturnValue< T > GetReturnValue() const
Definition: v8-function-callback.h:697
Local< Object > HolderV2() const
Definition: v8-function-callback.h:692
friend void internal::PrintPropertyCallbackInfo(void *)
friend class MacroAssembler
Definition: v8-function-callback.h:279
Isolate * GetIsolate() const
Definition: v8-function-callback.h:675
Definition: v8-function-callback.h:41
void SetFalse()
Definition: v8-function-callback.h:573
void SetEmptyString()
Definition: v8-function-callback.h:589
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:388
Local< Value > Get() const
Definition: v8-function-callback.h:609
void SetNull()
Definition: v8-function-callback.h:543
Isolate * GetIsolate() const
Definition: v8-function-callback.h:604
void SetUndefined()
Definition: v8-function-callback.h:558
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:934
static constexpr int kFrameCPSlotCount
Definition: v8-internal.h:1074
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:1024
void(*)(const FunctionCallbackInfo< Value > &info) FunctionCallback
Definition: v8-function-callback.h:354
#define V8_EXPORT
Definition: v8config.h:854
#define V8_INLINE
Definition: v8config.h:508
#define V8_DEPRECATE_SOON(message)
Definition: v8config.h:621
#define V8_UNLIKELY(condition)
Definition: v8config.h:667