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;
274 template <
typename U>
289 static constexpr bool HasShouldThrowOnError() {
290 return std::is_same_v<T, v8::Boolean> || std::is_same_v<T, void>;
306 kFrameConstantPoolIndex,
311 kFirstApiArgumentIndex,
312 kIsolateIndex = kFirstApiArgumentIndex,
320 kFirstOptionalArgument,
321 kShouldThrowOnErrorIndex = kFirstOptionalArgument,
327 kMandatoryArgsLength = kFirstOptionalArgument,
328 kOptionalArgsLength = kFullArgsLength - kFirstOptionalArgument,
331 kMandatoryApiArgsLength = kMandatoryArgsLength - kFirstApiArgumentIndex,
332 kFullApiArgsLength = kFullArgsLength - kFirstApiArgumentIndex,
359void ReturnValue<T>::SetInternal(internal::Address value) {
360#if V8_STATIC_ROOTS_BOOL
361 using I = internal::Internals;
366 *value_ = I::DecompressTaggedField(*value_, I::CompressTagged(value));
375 static_assert(std::is_base_of_v<T, S>,
"type check");
379 SetInternal(handle.
ptr());
386 static_assert(std::is_base_of_v<T, S>,
"type check");
387#ifdef V8_ENABLE_CHECKS
388 internal::VerifyHandleIsNonEmpty(handle.
IsEmpty());
390 SetInternal(handle.
ptr());
396 static_assert(std::is_base_of_v<T, S>,
"type check");
400 SetInternal(handle.
ptr());
407 static_assert(std::is_base_of_v<T, S>,
"type check");
408#ifdef V8_ENABLE_CHECKS
409 internal::VerifyHandleIsNonEmpty(handle.
IsEmpty());
411 SetInternal(handle.
ptr());
417 static_assert(std::is_base_of_v<T, S>,
"type check");
421 SetInternal(handle.
ptr());
428 static_assert(std::is_base_of_v<T, S>,
"type check");
429#ifdef V8_ENABLE_CHECKS
430 internal::VerifyHandleIsNonEmpty(handle.
IsEmpty());
432 SetInternal(handle.
ptr());
437 static_assert(std::is_base_of_v<T, Number>,
"type check");
438 SetNonEmpty(Number::New(GetIsolate(), i));
443 static_assert(std::is_base_of_v<T, Integer>,
"type check");
445 static_assert(I::IsValidSmi(std::numeric_limits<int16_t>::min()));
446 static_assert(I::IsValidSmi(std::numeric_limits<int16_t>::max()));
447 SetInternal(I::IntegralToSmi(i));
452 static_assert(std::is_base_of_v<T, Integer>,
"type check");
453 if (
const auto result = internal::Internals::TryIntegralToSmi(i)) {
454 SetInternal(*result);
457 SetNonEmpty(Integer::New(GetIsolate(), i));
462 static_assert(std::is_base_of_v<T, Integer>,
"type check");
463 if (
const auto result = internal::Internals::TryIntegralToSmi(i)) {
464 SetInternal(*result);
467 SetNonEmpty(Number::New(GetIsolate(),
static_cast<double>(i)));
472 static_assert(std::is_base_of_v<T, Integer>,
"type check");
474 static_assert(I::IsValidSmi(std::numeric_limits<uint16_t>::min()));
475 static_assert(I::IsValidSmi(std::numeric_limits<uint16_t>::max()));
476 SetInternal(I::IntegralToSmi(i));
481 static_assert(std::is_base_of_v<T, Integer>,
"type check");
482 if (
const auto result = internal::Internals::TryIntegralToSmi(i)) {
483 SetInternal(*result);
486 SetNonEmpty(Integer::NewFromUnsigned(GetIsolate(), i));
491 static_assert(std::is_base_of_v<T, Integer>,
"type check");
492 if (
const auto result = internal::Internals::TryIntegralToSmi(i)) {
493 SetInternal(*result);
496 SetNonEmpty(Number::New(GetIsolate(),
static_cast<double>(i)));
501 static_assert(std::is_void_v<T> || std::is_base_of_v<T, Boolean>,
504#if V8_STATIC_ROOTS_BOOL
505#ifdef V8_ENABLE_CHECKS
506 internal::PerformCastCheck(
507 internal::ValueHelper::SlotAsValue<Value, true>(value_));
509 SetInternal(value ? I::StaticReadOnlyRoot::kTrueValue
510 : I::StaticReadOnlyRoot::kFalseValue);
514 root_index = I::kTrueValueRootIndex;
516 root_index = I::kFalseValueRootIndex;
518 *value_ = I::GetRoot(GetIsolate(), root_index);
525 if constexpr (std::is_same_v<void, T> || std::is_same_v<v8::Boolean, T>) {
527 }
else if constexpr (std::is_same_v<v8::Integer, T>) {
528 SetInternal(I::IntegralToSmi(0));
530 static_assert(std::is_same_v<v8::Value, T> || std::is_same_v<v8::Array, T>);
531#if V8_STATIC_ROOTS_BOOL
532 SetInternal(I::StaticReadOnlyRoot::kUndefinedValue);
534 *value_ = I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex);
541 static_assert(std::is_base_of_v<T, Primitive>,
"type check");
543#if V8_STATIC_ROOTS_BOOL
544#ifdef V8_ENABLE_CHECKS
545 internal::PerformCastCheck(
546 internal::ValueHelper::SlotAsValue<Value, true>(value_));
548 SetInternal(I::StaticReadOnlyRoot::kNullValue);
550 *value_ = I::GetRoot(GetIsolate(), I::kNullValueRootIndex);
556 static_assert(std::is_base_of_v<T, Primitive>,
"type check");
558#if V8_STATIC_ROOTS_BOOL
559#ifdef V8_ENABLE_CHECKS
560 internal::PerformCastCheck(
561 internal::ValueHelper::SlotAsValue<Value, true>(value_));
563 SetInternal(I::StaticReadOnlyRoot::kUndefinedValue);
565 *value_ = I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex);
571 static_assert(std::is_void_v<T> || std::is_base_of_v<T, Boolean>,
574#if V8_STATIC_ROOTS_BOOL
575#ifdef V8_ENABLE_CHECKS
576 internal::PerformCastCheck(
577 internal::ValueHelper::SlotAsValue<Value, true>(value_));
579 SetInternal(I::StaticReadOnlyRoot::kFalseValue);
581 *value_ = I::GetRoot(GetIsolate(), I::kFalseValueRootIndex);
587 static_assert(std::is_base_of_v<T, String>,
"type check");
589#if V8_STATIC_ROOTS_BOOL
590#ifdef V8_ENABLE_CHECKS
591 internal::PerformCastCheck(
592 internal::ValueHelper::SlotAsValue<Value, true>(value_));
594 SetInternal(I::StaticReadOnlyRoot::kEmptyString);
596 *value_ = I::GetRoot(GetIsolate(), I::kEmptyStringRootIndex);
602 return *
reinterpret_cast<Isolate**
>(&value_[kIsolateValueIndex]);
608 internal::ValueHelper::SlotAsValue<Value>(value_));
614 static_assert(
sizeof(S) < 0,
"incompilable to prevent inadvertent misuse");
619 if (i < 0 || Length() <= i)
return Undefined(GetIsolate());
630 if (IsConstructCall()) {
642 return api_internal::GetFunctionTemplateData(GetIsolate(), target);
647 return reinterpret_cast<Isolate*
>(values_[kIsolateIndex]);
657 return I::SmiValue(values_[kFrameTypeIndex]) == I::kFrameTypeApiConstructExit;
662 return static_cast<int>(values_[kArgcIndex]);
667 return I::SmiValue(args_[kFrameTypeIndex]) ==
668 I::kFrameTypeApiNamedAccessorExit;
673 return *
reinterpret_cast<Isolate**
>(&args_[kIsolateIndex]);
680 I::ReadTaggedPointerField(callback_info, I::kCallbackInfoDataOffset);
696 if constexpr (!HasShouldThrowOnError())
return false;
697 if (args_[kShouldThrowOnErrorIndex] !=
698 I::IntegralToSmi(I::kInferShouldThrowMode)) {
699 return args_[kShouldThrowOnErrorIndex] != I::IntegralToSmi(I::kDontThrow);
702 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:651
Local< Object > This() const
Definition: v8-function-callback.h:624
Local< Value > operator[](int i) const
Definition: v8-function-callback.h:618
Isolate * GetIsolate() const
Definition: v8-function-callback.h:646
Local< Value > NewTarget() const
Definition: v8-function-callback.h:629
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:640
bool IsConstructCall() const
Definition: v8-function-callback.h:656
int Length() const
Definition: v8-function-callback.h:661
Definition: v8-persistent-handle.h:353
Definition: v8-isolate.h:292
Definition: v8-local-handle.h:366
Definition: v8-util.h:166
Definition: v8-function-callback.h:224
Local< Value > Data() const
Definition: v8-function-callback.h:677
friend class internal::PropertyCallbackArguments
Definition: v8-function-callback.h:277
friend class PropertyCallbackInfo
Definition: v8-function-callback.h:275
Local< Object > Holder() const
Definition: v8-function-callback.h:685
bool ShouldThrowOnError() const
Definition: v8-function-callback.h:695
ReturnValue< T > GetReturnValue() const
Definition: v8-function-callback.h:690
friend class MacroAssembler
Definition: v8-function-callback.h:276
Isolate * GetIsolate() const
Definition: v8-function-callback.h:672
Definition: v8-function-callback.h:41
void SetFalse()
Definition: v8-function-callback.h:570
void SetEmptyString()
Definition: v8-function-callback.h:586
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:385
Local< Value > Get() const
Definition: v8-function-callback.h:606
void SetNull()
Definition: v8-function-callback.h:540
Isolate * GetIsolate() const
Definition: v8-function-callback.h:601
void SetUndefined()
Definition: v8-function-callback.h:555
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:975
static constexpr int kFrameCPSlotCount
Definition: v8-internal.h:1119
v8::Local< v8::Value > GetFunctionTemplateData(v8::Isolate *isolate, v8::Local< v8::Data > raw_target)
void PrintPropertyCallbackInfo(void *property_callback_info)
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:1057
void(*)(const FunctionCallbackInfo< Value > &info) FunctionCallback
Definition: v8-function-callback.h:351
#define V8_EXPORT
Definition: v8config.h:867
#define V8_INLINE
Definition: v8config.h:511
#define V8_UNLIKELY(condition)
Definition: v8config.h:670