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;
275 template <
typename U>
290 static constexpr bool HasShouldThrowOnError() {
291 return std::is_same_v<T, v8::Boolean> || std::is_same_v<T, void>;
307 kFrameConstantPoolIndex,
312 kFirstApiArgumentIndex,
313 kIsolateIndex = kFirstApiArgumentIndex,
321 kFirstOptionalArgument,
322 kShouldThrowOnErrorIndex = kFirstOptionalArgument,
328 kMandatoryArgsLength = kFirstOptionalArgument,
329 kOptionalArgsLength = kFullArgsLength - kFirstOptionalArgument,
332 kMandatoryApiArgsLength = kMandatoryArgsLength - kFirstApiArgumentIndex,
333 kFullApiArgsLength = kFullArgsLength - kFirstApiArgumentIndex,
360void ReturnValue<T>::SetInternal(internal::Address value) {
361#if V8_STATIC_ROOTS_BOOL
362 using I = internal::Internals;
367 *value_ = I::DecompressTaggedField(*value_, I::CompressTagged(value));
376 static_assert(std::is_base_of_v<T, S>,
"type check");
380 SetInternal(handle.
ptr());
387 static_assert(std::is_base_of_v<T, S>,
"type check");
388#ifdef V8_ENABLE_CHECKS
389 internal::VerifyHandleIsNonEmpty(handle.
IsEmpty());
391 SetInternal(handle.
ptr());
397 static_assert(std::is_base_of_v<T, S>,
"type check");
401 SetInternal(handle.
ptr());
408 static_assert(std::is_base_of_v<T, S>,
"type check");
409#ifdef V8_ENABLE_CHECKS
410 internal::VerifyHandleIsNonEmpty(handle.
IsEmpty());
412 SetInternal(handle.
ptr());
418 static_assert(std::is_base_of_v<T, S>,
"type check");
422 SetInternal(handle.
ptr());
429 static_assert(std::is_base_of_v<T, S>,
"type check");
430#ifdef V8_ENABLE_CHECKS
431 internal::VerifyHandleIsNonEmpty(handle.
IsEmpty());
433 SetInternal(handle.
ptr());
438 static_assert(std::is_base_of_v<T, Number>,
"type check");
439 SetNonEmpty(Number::New(GetIsolate(), i));
444 static_assert(std::is_base_of_v<T, Integer>,
"type check");
446 static_assert(I::IsValidSmi(std::numeric_limits<int16_t>::min()));
447 static_assert(I::IsValidSmi(std::numeric_limits<int16_t>::max()));
448 SetInternal(I::IntegralToSmi(i));
453 static_assert(std::is_base_of_v<T, Integer>,
"type check");
454 if (
const auto result = internal::Internals::TryIntegralToSmi(i)) {
455 SetInternal(*result);
458 SetNonEmpty(Integer::New(GetIsolate(), 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(Number::New(GetIsolate(),
static_cast<double>(i)));
473 static_assert(std::is_base_of_v<T, Integer>,
"type check");
475 static_assert(I::IsValidSmi(std::numeric_limits<uint16_t>::min()));
476 static_assert(I::IsValidSmi(std::numeric_limits<uint16_t>::max()));
477 SetInternal(I::IntegralToSmi(i));
482 static_assert(std::is_base_of_v<T, Integer>,
"type check");
483 if (
const auto result = internal::Internals::TryIntegralToSmi(i)) {
484 SetInternal(*result);
487 SetNonEmpty(Integer::NewFromUnsigned(GetIsolate(), 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(Number::New(GetIsolate(),
static_cast<double>(i)));
502 static_assert(std::is_void_v<T> || std::is_base_of_v<T, Boolean>,
505#if V8_STATIC_ROOTS_BOOL
506#ifdef V8_ENABLE_CHECKS
507 internal::PerformCastCheck(
508 internal::ValueHelper::SlotAsValue<Value, true>(value_));
510 SetInternal(value ? I::StaticReadOnlyRoot::kTrueValue
511 : I::StaticReadOnlyRoot::kFalseValue);
515 root_index = I::kTrueValueRootIndex;
517 root_index = I::kFalseValueRootIndex;
519 *value_ = I::GetRoot(GetIsolate(), root_index);
526 if constexpr (std::is_same_v<void, T> || std::is_same_v<v8::Boolean, T>) {
528 }
else if constexpr (std::is_same_v<v8::Integer, T>) {
529 SetInternal(I::IntegralToSmi(0));
531 static_assert(std::is_same_v<v8::Value, T> || std::is_same_v<v8::Array, T>);
532#if V8_STATIC_ROOTS_BOOL
533 SetInternal(I::StaticReadOnlyRoot::kUndefinedValue);
535 *value_ = I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex);
542 static_assert(std::is_base_of_v<T, Primitive>,
"type check");
544#if V8_STATIC_ROOTS_BOOL
545#ifdef V8_ENABLE_CHECKS
546 internal::PerformCastCheck(
547 internal::ValueHelper::SlotAsValue<Value, true>(value_));
549 SetInternal(I::StaticReadOnlyRoot::kNullValue);
551 *value_ = I::GetRoot(GetIsolate(), I::kNullValueRootIndex);
557 static_assert(std::is_base_of_v<T, Primitive>,
"type check");
559#if V8_STATIC_ROOTS_BOOL
560#ifdef V8_ENABLE_CHECKS
561 internal::PerformCastCheck(
562 internal::ValueHelper::SlotAsValue<Value, true>(value_));
564 SetInternal(I::StaticReadOnlyRoot::kUndefinedValue);
566 *value_ = I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex);
572 static_assert(std::is_void_v<T> || std::is_base_of_v<T, Boolean>,
575#if V8_STATIC_ROOTS_BOOL
576#ifdef V8_ENABLE_CHECKS
577 internal::PerformCastCheck(
578 internal::ValueHelper::SlotAsValue<Value, true>(value_));
580 SetInternal(I::StaticReadOnlyRoot::kFalseValue);
582 *value_ = I::GetRoot(GetIsolate(), I::kFalseValueRootIndex);
588 static_assert(std::is_base_of_v<T, String>,
"type check");
590#if V8_STATIC_ROOTS_BOOL
591#ifdef V8_ENABLE_CHECKS
592 internal::PerformCastCheck(
593 internal::ValueHelper::SlotAsValue<Value, true>(value_));
595 SetInternal(I::StaticReadOnlyRoot::kEmptyString);
597 *value_ = I::GetRoot(GetIsolate(), I::kEmptyStringRootIndex);
603 return *
reinterpret_cast<Isolate**
>(&value_[kIsolateValueIndex]);
609 internal::ValueHelper::SlotAsValue<Value>(value_));
615 static_assert(
sizeof(S) < 0,
"incompilable to prevent inadvertent misuse");
620 if (i < 0 || Length() <= i)
return Undefined(GetIsolate());
631 if (IsConstructCall()) {
643 return api_internal::GetFunctionTemplateData(GetIsolate(), target);
648 return reinterpret_cast<Isolate*
>(values_[kIsolateIndex]);
658 return I::SmiValue(values_[kFrameTypeIndex]) == I::kFrameTypeApiConstructExit;
663 return static_cast<int>(values_[kArgcIndex]);
668 return I::SmiValue(args_[kFrameTypeIndex]) ==
669 I::kFrameTypeApiNamedAccessorExit;
674 return *
reinterpret_cast<Isolate**
>(&args_[kIsolateIndex]);
681 I::ReadTaggedPointerField(callback_info, I::kCallbackInfoDataOffset);
697 if constexpr (!HasShouldThrowOnError())
return false;
698 if (args_[kShouldThrowOnErrorIndex] !=
699 I::IntegralToSmi(I::kInferShouldThrowMode)) {
700 return args_[kShouldThrowOnErrorIndex] != I::IntegralToSmi(I::kDontThrow);
703 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:652
Local< Object > This() const
Definition: v8-function-callback.h:625
Local< Value > operator[](int i) const
Definition: v8-function-callback.h:619
Isolate * GetIsolate() const
Definition: v8-function-callback.h:647
Local< Value > NewTarget() const
Definition: v8-function-callback.h:630
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:641
bool IsConstructCall() const
Definition: v8-function-callback.h:657
int Length() const
Definition: v8-function-callback.h:662
Definition: v8-persistent-handle.h:349
Definition: v8-isolate.h:291
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:678
friend class internal::PropertyCallbackArguments
Definition: v8-function-callback.h:278
friend class PropertyCallbackInfo
Definition: v8-function-callback.h:276
bool ShouldThrowOnError() const
Definition: v8-function-callback.h:696
ReturnValue< T > GetReturnValue() const
Definition: v8-function-callback.h:691
Local< Object > HolderV2() const
Definition: v8-function-callback.h:686
friend class MacroAssembler
Definition: v8-function-callback.h:277
Isolate * GetIsolate() const
Definition: v8-function-callback.h:673
Definition: v8-function-callback.h:41
void SetFalse()
Definition: v8-function-callback.h:571
void SetEmptyString()
Definition: v8-function-callback.h:587
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:386
Local< Value > Get() const
Definition: v8-function-callback.h:607
void SetNull()
Definition: v8-function-callback.h:541
Isolate * GetIsolate() const
Definition: v8-function-callback.h:602
void SetUndefined()
Definition: v8-function-callback.h:556
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:920
static constexpr int kFrameCPSlotCount
Definition: v8-internal.h:1064
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:1018
void(*)(const FunctionCallbackInfo< Value > &info) FunctionCallback
Definition: v8-function-callback.h:352
#define V8_EXPORT
Definition: v8config.h:855
#define V8_INLINE
Definition: v8config.h:508
#define V8_UNLIKELY(condition)
Definition: v8config.h:668