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 {
47 static_assert(std::is_base_of_v<T, S>,
"type check");
98 template <
class F,
class G,
class H>
111 static constexpr int kIsolateValueIndex = -1;
163 kNewTargetIndex = -1,
176 kFrameConstantPoolIndex,
181 kFirstApiArgumentIndex,
182 kIsolateIndex = kFirstApiArgumentIndex,
189 kFirstJSArgumentIndex,
192 kArgsLength = kReceiverIndex + 1,
194 kOptionalArgsLength = 1,
197 kApiArgsLength = kReceiverIndex - kFirstApiArgumentIndex,
200 static_assert(kArgcIndex == 0);
202 kIsolateIndex - kReturnValueIndex);
205 return &values_[kFirstJSArgumentIndex];
208 V8_INLINE FunctionCallbackInfo() =
default;
212 FunctionCallbackInfo(
const FunctionCallbackInfo&) =
delete;
213 FunctionCallbackInfo& operator=(
const FunctionCallbackInfo&) =
delete;
214 FunctionCallbackInfo(FunctionCallbackInfo&&) =
delete;
215 FunctionCallbackInfo& operator=(FunctionCallbackInfo&&) =
delete;
285 template <typename U>
291 using
I = internal::Internals;
300 static constexpr
bool HasShouldThrowOnError() {
301 return std::is_same_v<T, v8::Boolean> || std::is_same_v<T, void>;
317 kFrameConstantPoolIndex,
322 kFirstApiArgumentIndex,
323 kIsolateIndex = kFirstApiArgumentIndex,
331 kFirstOptionalArgument,
332 kShouldThrowOnErrorIndex = kFirstOptionalArgument,
338 kMandatoryArgsLength = kFirstOptionalArgument,
339 kOptionalArgsLength = kFullArgsLength - kFirstOptionalArgument,
342 kMandatoryApiArgsLength = kMandatoryArgsLength - kFirstApiArgumentIndex,
343 kFullApiArgsLength = kFullArgsLength - kFirstApiArgumentIndex,
370void ReturnValue<T>::SetInternal(internal::Address value) {
371#if V8_STATIC_ROOTS_BOOL
372 using I = internal::Internals;
377 *value_ = I::DecompressTaggedField(*value_, I::CompressTagged(value));
386 static_assert(std::is_base_of_v<T, S>,
"type check");
390 SetInternal(handle.
ptr());
397 static_assert(std::is_base_of_v<T, S>,
"type check");
398#ifdef V8_ENABLE_CHECKS
399 internal::VerifyHandleIsNonEmpty(handle.
IsEmpty());
401 SetInternal(handle.
ptr());
407 static_assert(std::is_base_of_v<T, S>,
"type check");
411 SetInternal(handle.
ptr());
418 static_assert(std::is_base_of_v<T, S>,
"type check");
419#ifdef V8_ENABLE_CHECKS
420 internal::VerifyHandleIsNonEmpty(handle.
IsEmpty());
422 SetInternal(handle.
ptr());
428 static_assert(std::is_base_of_v<T, S>,
"type check");
432 SetInternal(handle.
ptr());
439 static_assert(std::is_base_of_v<T, S>,
"type check");
440#ifdef V8_ENABLE_CHECKS
441 internal::VerifyHandleIsNonEmpty(handle.
IsEmpty());
443 SetInternal(handle.
ptr());
448 static_assert(std::is_base_of_v<T, Number>,
"type check");
449 SetNonEmpty(Number::New(GetIsolate(), i));
454 static_assert(std::is_base_of_v<T, Integer>,
"type check");
456 static_assert(I::IsValidSmi(std::numeric_limits<int16_t>::min()));
457 static_assert(I::IsValidSmi(std::numeric_limits<int16_t>::max()));
458 SetInternal(I::IntegralToSmi(i));
463 static_assert(std::is_base_of_v<T, Integer>,
"type check");
464 if (
const auto result = internal::Internals::TryIntegralToSmi(i)) {
465 SetInternal(*result);
468 SetNonEmpty(Integer::New(GetIsolate(), i));
473 static_assert(std::is_base_of_v<T, Integer>,
"type check");
474 if (
const auto result = internal::Internals::TryIntegralToSmi(i)) {
475 SetInternal(*result);
478 SetNonEmpty(Number::New(GetIsolate(),
static_cast<double>(i)));
483 static_assert(std::is_base_of_v<T, Integer>,
"type check");
485 static_assert(I::IsValidSmi(std::numeric_limits<uint16_t>::min()));
486 static_assert(I::IsValidSmi(std::numeric_limits<uint16_t>::max()));
487 SetInternal(I::IntegralToSmi(i));
492 static_assert(std::is_base_of_v<T, Integer>,
"type check");
493 if (
const auto result = internal::Internals::TryIntegralToSmi(i)) {
494 SetInternal(*result);
497 SetNonEmpty(Integer::NewFromUnsigned(GetIsolate(), i));
502 static_assert(std::is_base_of_v<T, Integer>,
"type check");
503 if (
const auto result = internal::Internals::TryIntegralToSmi(i)) {
504 SetInternal(*result);
507 SetNonEmpty(Number::New(GetIsolate(),
static_cast<double>(i)));
512 static_assert(std::is_void_v<T> || std::is_base_of_v<T, Boolean>,
515#if V8_STATIC_ROOTS_BOOL
516#ifdef V8_ENABLE_CHECKS
517 internal::PerformCastCheck(
518 internal::ValueHelper::SlotAsValue<Value, true>(value_));
520 SetInternal(value ? I::StaticReadOnlyRoot::kTrueValue
521 : I::StaticReadOnlyRoot::kFalseValue);
525 root_index = I::kTrueValueRootIndex;
527 root_index = I::kFalseValueRootIndex;
529 *value_ = I::GetRoot(GetIsolate(), root_index);
536 if constexpr (std::is_same_v<void, T> || std::is_same_v<v8::Boolean, T>) {
538 }
else if constexpr (std::is_same_v<v8::Integer, T>) {
539 SetInternal(I::IntegralToSmi(0));
541 static_assert(std::is_same_v<v8::Value, T> || std::is_same_v<v8::Array, T>);
542#if V8_STATIC_ROOTS_BOOL
543 SetInternal(I::StaticReadOnlyRoot::kUndefinedValue);
545 *value_ = I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex);
552 static_assert(std::is_base_of_v<T, Primitive>,
"type check");
554#if V8_STATIC_ROOTS_BOOL
555#ifdef V8_ENABLE_CHECKS
556 internal::PerformCastCheck(
557 internal::ValueHelper::SlotAsValue<Value, true>(value_));
559 SetInternal(I::StaticReadOnlyRoot::kNullValue);
561 *value_ = I::GetRoot(GetIsolate(), I::kNullValueRootIndex);
567 static_assert(std::is_base_of_v<T, Primitive>,
"type check");
569#if V8_STATIC_ROOTS_BOOL
570#ifdef V8_ENABLE_CHECKS
571 internal::PerformCastCheck(
572 internal::ValueHelper::SlotAsValue<Value, true>(value_));
574 SetInternal(I::StaticReadOnlyRoot::kUndefinedValue);
576 *value_ = I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex);
582 static_assert(std::is_void_v<T> || std::is_base_of_v<T, Boolean>,
585#if V8_STATIC_ROOTS_BOOL
586#ifdef V8_ENABLE_CHECKS
587 internal::PerformCastCheck(
588 internal::ValueHelper::SlotAsValue<Value, true>(value_));
590 SetInternal(I::StaticReadOnlyRoot::kFalseValue);
592 *value_ = I::GetRoot(GetIsolate(), I::kFalseValueRootIndex);
598 static_assert(std::is_base_of_v<T, String>,
"type check");
600#if V8_STATIC_ROOTS_BOOL
601#ifdef V8_ENABLE_CHECKS
602 internal::PerformCastCheck(
603 internal::ValueHelper::SlotAsValue<Value, true>(value_));
605 SetInternal(I::StaticReadOnlyRoot::kEmptyString);
607 *value_ = I::GetRoot(GetIsolate(), I::kEmptyStringRootIndex);
613 return *
reinterpret_cast<Isolate**
>(&value_[kIsolateValueIndex]);
619 internal::ValueHelper::SlotAsValue<Value>(value_));
625 static_assert(
sizeof(S) < 0,
"incompilable to prevent inadvertent misuse");
630 if (i < 0 || Length() <= i)
return Undefined(GetIsolate());
641 if (IsConstructCall()) {
653 return api_internal::GetFunctionTemplateData(GetIsolate(), target);
659 return api_internal::GetFunctionTemplateDataV2(GetIsolate(), target);
664 return reinterpret_cast<Isolate*
>(values_[kIsolateIndex]);
674 return I::SmiValue(values_[kFrameTypeIndex]) == I::kFrameTypeApiConstructExit;
679 return static_cast<int>(values_[kArgcIndex]);
684 return I::SmiValue(args_[kFrameTypeIndex]) ==
685 I::kFrameTypeApiNamedAccessorExit;
690 return *
reinterpret_cast<Isolate**
>(&args_[kIsolateIndex]);
697 I::ReadTaggedPointerField(callback_info, I::kCallbackInfoDataOffset);
705 I::ReadTaggedPointerField(callback_info, I::kCallbackInfoDataOffset);
721 if constexpr (!HasShouldThrowOnError())
return false;
722 if (args_[kShouldThrowOnErrorIndex] !=
723 I::IntegralToSmi(I::kInferShouldThrowMode)) {
724 return args_[kShouldThrowOnErrorIndex] != I::IntegralToSmi(I::kDontThrow);
727 reinterpret_cast<v8::internal::Isolate*
>(GetIsolate()));
Definition: v8-traced-handle.h:125
Definition: v8-function-callback.h:123
ReturnValue< T > GetReturnValue() const
Definition: v8-function-callback.h:668
Local< Object > This() const
Definition: v8-function-callback.h:635
Local< Value > operator[](int i) const
Definition: v8-function-callback.h:629
Isolate * GetIsolate() const
Definition: v8-function-callback.h:663
Local< Value > NewTarget() const
Definition: v8-function-callback.h:640
friend class debug::ConsoleCallArguments
Definition: v8-function-callback.h:151
friend class internal::FunctionCallbackArguments
Definition: v8-function-callback.h:149
Local< Value > Data() const
Definition: v8-function-callback.h:651
Local< v8::Data > DataV2() const
Definition: v8-function-callback.h:657
bool IsConstructCall() const
Definition: v8-function-callback.h:673
int Length() const
Definition: v8-function-callback.h:678
Definition: v8-persistent-handle.h:353
Definition: v8-isolate.h:298
Definition: v8-local-handle.h:366
Definition: v8-object.h:267
Definition: v8-util.h:166
Definition: v8-function-callback.h:229
friend class internal::PropertyCallbackArguments
Definition: v8-function-callback.h:288
friend class PropertyCallbackInfo
Definition: v8-function-callback.h:286
Local< Object > Holder() const
Definition: v8-function-callback.h:710
bool ShouldThrowOnError() const
Definition: v8-function-callback.h:720
ReturnValue< T > GetReturnValue() const
Definition: v8-function-callback.h:715
Local< v8::Data > DataV2() const
Definition: v8-function-callback.h:702
friend void internal::PrintPropertyCallbackInfo(void *)
friend class MacroAssembler
Definition: v8-function-callback.h:287
Isolate * GetIsolate() const
Definition: v8-function-callback.h:689
Definition: v8-function-callback.h:43
void SetFalse()
Definition: v8-function-callback.h:581
void SetEmptyString()
Definition: v8-function-callback.h:597
friend class ReturnValue
Definition: v8-function-callback.h:93
ReturnValue(const ReturnValue< S > &that)
Definition: v8-function-callback.h:46
void SetNonEmpty(const Global< S > &handle)
Definition: v8-function-callback.h:396
Local< Value > Get() const
Definition: v8-function-callback.h:617
void SetNull()
Definition: v8-function-callback.h:551
Isolate * GetIsolate() const
Definition: v8-function-callback.h:612
void SetUndefined()
Definition: v8-function-callback.h:566
Definition: v8-container.h:139
Definition: v8-value.h:32
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:986
static constexpr int kFrameCPSlotCount
Definition: v8-internal.h:1126
v8::Local< v8::Data > GetFunctionTemplateDataV2(v8::Isolate *isolate, v8::Local< v8::Data > raw_target)
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:1057
void(*)(const FunctionCallbackInfo< Value > &info) FunctionCallback
Definition: v8-function-callback.h:362
#define V8_EXPORT
Definition: v8config.h:874
#define V8_INLINE
Definition: v8config.h:518
#define V8_DEPRECATE_SOON(message)
Definition: v8config.h:631
#define V8_UNLIKELY(condition)
Definition: v8config.h:677