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 {
50 static_assert(std::is_base_of_v<S, T>,
"type check");
101 template <
class F,
class G,
class H>
114 static constexpr int kIsolateValueIndex = -1;
165 kNewTargetIndex = -1,
178 kFrameConstantPoolIndex,
183 kFirstApiArgumentIndex,
184 kIsolateIndex = kFirstApiArgumentIndex,
191 kFirstJSArgumentIndex,
194 kArgsLength = kReceiverIndex + 1,
196 kOptionalArgsLength = 1,
199 kApiArgsLength = kReceiverIndex - kFirstApiArgumentIndex,
202 static_assert(kArgcIndex == 0);
204 kIsolateIndex - kReturnValueIndex);
207 return &values_[kFirstJSArgumentIndex];
210 V8_INLINE FunctionCallbackInfo() =
default;
214 FunctionCallbackInfo(
const FunctionCallbackInfo&) =
delete;
215 FunctionCallbackInfo& operator=(
const FunctionCallbackInfo&) =
delete;
216 FunctionCallbackInfo(FunctionCallbackInfo&&) =
delete;
217 FunctionCallbackInfo& operator=(FunctionCallbackInfo&&) =
delete;
281 template <typename U>
287 using
I = internal::Internals;
293 static constexpr
bool HasShouldThrowOnError() {
294 return std::is_same_v<T, v8::Boolean>;
310 kFrameConstantPoolIndex,
315 kFirstApiArgumentIndex,
316 kIsolateIndex = kFirstApiArgumentIndex,
324 kFirstOptionalArgument,
325 kShouldThrowOnErrorIndex = kFirstOptionalArgument,
331 kMandatoryArgsLength = kFirstOptionalArgument,
332 kOptionalArgsLength = kFullArgsLength - kFirstOptionalArgument,
335 kMandatoryApiArgsLength = kMandatoryArgsLength - kFirstApiArgumentIndex,
336 kFullApiArgsLength = kFullArgsLength - kFirstApiArgumentIndex,
363void ReturnValue<T>::SetInternal(internal::Address value) {
364#if V8_STATIC_ROOTS_BOOL
365 using I = internal::Internals;
370 *value_ = I::DecompressTaggedField(*value_, I::CompressTagged(value));
379 static_assert(std::is_base_of_v<T, S>,
"type check");
383 SetInternal(handle.
ptr());
390 static_assert(std::is_base_of_v<T, S>,
"type check");
391#ifdef V8_ENABLE_CHECKS
392 internal::VerifyHandleIsNonEmpty(handle.
IsEmpty());
394 SetInternal(handle.
ptr());
400 static_assert(std::is_base_of_v<T, S>,
"type check");
404 SetInternal(handle.
ptr());
411 static_assert(std::is_base_of_v<T, S>,
"type check");
412#ifdef V8_ENABLE_CHECKS
413 internal::VerifyHandleIsNonEmpty(handle.
IsEmpty());
415 SetInternal(handle.
ptr());
421 static_assert(std::is_base_of_v<T, S>,
"type check");
425 SetInternal(handle.
ptr());
432 static_assert(std::is_base_of_v<T, S>,
"type check");
433#ifdef V8_ENABLE_CHECKS
434 internal::VerifyHandleIsNonEmpty(handle.
IsEmpty());
436 SetInternal(handle.
ptr());
441 static_assert(std::is_base_of_v<T, Number>,
"type check");
442 SetNonEmpty(Number::New(GetIsolate(), i));
447 static_assert(std::is_base_of_v<T, Integer>,
"type check");
449 static_assert(I::IsValidSmi(std::numeric_limits<int16_t>::min()));
450 static_assert(I::IsValidSmi(std::numeric_limits<int16_t>::max()));
451 SetInternal(I::IntegralToSmi(i));
456 static_assert(std::is_base_of_v<T, Integer>,
"type check");
457 if (
const auto result = internal::Internals::TryIntegralToSmi(i)) {
458 SetInternal(*result);
461 SetNonEmpty(Integer::New(GetIsolate(), i));
466 static_assert(std::is_base_of_v<T, Integer>,
"type check");
467 if (
const auto result = internal::Internals::TryIntegralToSmi(i)) {
468 SetInternal(*result);
471 SetNonEmpty(Number::New(GetIsolate(),
static_cast<double>(i)));
476 static_assert(std::is_base_of_v<T, Integer>,
"type check");
478 static_assert(I::IsValidSmi(std::numeric_limits<uint16_t>::min()));
479 static_assert(I::IsValidSmi(std::numeric_limits<uint16_t>::max()));
480 SetInternal(I::IntegralToSmi(i));
485 static_assert(std::is_base_of_v<T, Integer>,
"type check");
486 if (
const auto result = internal::Internals::TryIntegralToSmi(i)) {
487 SetInternal(*result);
490 SetNonEmpty(Integer::NewFromUnsigned(GetIsolate(), i));
495 static_assert(std::is_base_of_v<T, Integer>,
"type check");
496 if (
const auto result = internal::Internals::TryIntegralToSmi(i)) {
497 SetInternal(*result);
500 SetNonEmpty(Number::New(GetIsolate(),
static_cast<double>(i)));
505 static_assert(std::is_void_v<T> || std::is_base_of_v<T, Boolean>,
508#if V8_STATIC_ROOTS_BOOL
509#ifdef V8_ENABLE_CHECKS
510 internal::PerformCastCheck(
511 internal::ValueHelper::SlotAsValue<Value, true>(value_));
513 SetInternal(value ? I::StaticReadOnlyRoot::kTrueValue
514 : I::StaticReadOnlyRoot::kFalseValue);
518 root_index = I::kTrueValueRootIndex;
520 root_index = I::kFalseValueRootIndex;
522 *value_ = I::GetRoot(GetIsolate(), root_index);
529 if constexpr (std::is_same_v<void, T> || std::is_same_v<v8::Boolean, T>) {
531 }
else if constexpr (std::is_same_v<v8::Integer, T>) {
532 SetInternal(I::IntegralToSmi(0));
534 static_assert(std::is_same_v<v8::Value, T> || std::is_same_v<v8::Array, T>);
535#if V8_STATIC_ROOTS_BOOL
536 SetInternal(I::StaticReadOnlyRoot::kUndefinedValue);
538 *value_ = I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex);
545 static_assert(std::is_base_of_v<T, Primitive>,
"type check");
547#if V8_STATIC_ROOTS_BOOL
548#ifdef V8_ENABLE_CHECKS
549 internal::PerformCastCheck(
550 internal::ValueHelper::SlotAsValue<Value, true>(value_));
552 SetInternal(I::StaticReadOnlyRoot::kNullValue);
554 *value_ = I::GetRoot(GetIsolate(), I::kNullValueRootIndex);
560 static_assert(std::is_base_of_v<T, Primitive>,
"type check");
562#if V8_STATIC_ROOTS_BOOL
563#ifdef V8_ENABLE_CHECKS
564 internal::PerformCastCheck(
565 internal::ValueHelper::SlotAsValue<Value, true>(value_));
567 SetInternal(I::StaticReadOnlyRoot::kUndefinedValue);
569 *value_ = I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex);
575 static_assert(std::is_void_v<T> || std::is_base_of_v<T, Boolean>,
578#if V8_STATIC_ROOTS_BOOL
579#ifdef V8_ENABLE_CHECKS
580 internal::PerformCastCheck(
581 internal::ValueHelper::SlotAsValue<Value, true>(value_));
583 SetInternal(I::StaticReadOnlyRoot::kFalseValue);
585 *value_ = I::GetRoot(GetIsolate(), I::kFalseValueRootIndex);
591 static_assert(std::is_base_of_v<T, String>,
"type check");
593#if V8_STATIC_ROOTS_BOOL
594#ifdef V8_ENABLE_CHECKS
595 internal::PerformCastCheck(
596 internal::ValueHelper::SlotAsValue<Value, true>(value_));
598 SetInternal(I::StaticReadOnlyRoot::kEmptyString);
600 *value_ = I::GetRoot(GetIsolate(), I::kEmptyStringRootIndex);
606 return *
reinterpret_cast<Isolate**
>(&value_[kIsolateValueIndex]);
612 internal::ValueHelper::SlotAsValue<Value>(value_));
618 static_assert(
sizeof(S) < 0,
"incompilable to prevent inadvertent misuse");
623 if (i < 0 || Length() <= i)
return Undefined(GetIsolate());
634 if (IsConstructCall()) {
646 return api_internal::GetFunctionTemplateData(GetIsolate(), target);
656 return reinterpret_cast<Isolate*
>(values_[kIsolateIndex]);
666 return I::SmiValue(values_[kFrameTypeIndex]) == I::kFrameTypeApiConstructExit;
671 return static_cast<int>(values_[kArgcIndex]);
676 return I::SmiValue(args_[kFrameTypeIndex]) ==
677 I::kFrameTypeApiNamedAccessorExit;
682 return *
reinterpret_cast<Isolate**
>(&args_[kIsolateIndex]);
689 I::ReadTaggedPointerField(callback_info, I::kCallbackInfoDataOffset);
710 if constexpr (!HasShouldThrowOnError())
return false;
711 if (args_[kShouldThrowOnErrorIndex] !=
712 I::IntegralToSmi(I::kInferShouldThrowMode)) {
713 return args_[kShouldThrowOnErrorIndex] != I::IntegralToSmi(I::kDontThrow);
716 reinterpret_cast<v8::internal::Isolate*
>(GetIsolate()));
Definition: v8-traced-handle.h:125
Definition: v8-function-callback.h:126
Local< v8::Data > Data() const
Definition: v8-function-callback.h:644
ReturnValue< T > GetReturnValue() const
Definition: v8-function-callback.h:660
Local< Object > This() const
Definition: v8-function-callback.h:628
Local< Value > operator[](int i) const
Definition: v8-function-callback.h:622
Isolate * GetIsolate() const
Definition: v8-function-callback.h:655
Local< Value > NewTarget() const
Definition: v8-function-callback.h:633
friend class debug::ConsoleCallArguments
Definition: v8-function-callback.h:153
friend class internal::FunctionCallbackArguments
Definition: v8-function-callback.h:151
Local< v8::Data > DataV2() const
Definition: v8-function-callback.h:650
bool IsConstructCall() const
Definition: v8-function-callback.h:665
int Length() const
Definition: v8-function-callback.h:670
Definition: v8-persistent-handle.h:353
Definition: v8-isolate.h:305
Definition: v8-local-handle.h:356
Definition: v8-object.h:269
Definition: v8-util.h:166
Definition: v8-function-callback.h:231
friend class internal::PropertyCallbackArguments
Definition: v8-function-callback.h:284
Local< v8::Data > Data() const
Definition: v8-function-callback.h:686
friend class PropertyCallbackInfo
Definition: v8-function-callback.h:282
Local< Object > Holder() const
Definition: v8-function-callback.h:699
bool ShouldThrowOnError() const
Definition: v8-function-callback.h:709
ReturnValue< T > GetReturnValue() const
Definition: v8-function-callback.h:704
Local< v8::Data > DataV2() const
Definition: v8-function-callback.h:694
friend void internal::PrintPropertyCallbackInfo(void *)
friend class MacroAssembler
Definition: v8-function-callback.h:283
Isolate * GetIsolate() const
Definition: v8-function-callback.h:681
Definition: v8-function-callback.h:41
void SetFalse()
Definition: v8-function-callback.h:574
void SetEmptyString()
Definition: v8-function-callback.h:590
friend class ReturnValue
Definition: v8-function-callback.h:96
ReturnValue(const ReturnValue< S > &that)
Definition: v8-function-callback.h:44
void SetNonEmpty(const Global< S > &handle)
Definition: v8-function-callback.h:389
Local< Value > Get() const
Definition: v8-function-callback.h:610
void SetNull()
Definition: v8-function-callback.h:544
Isolate * GetIsolate() const
Definition: v8-function-callback.h:605
void SetUndefined()
Definition: v8-function-callback.h:559
Definition: v8-container.h:147
internal::Address ptr() const
Definition: v8-handle-base.h:80
bool IsEmpty() const
Definition: v8-handle-base.h:60
Definition: v8-local-handle.h:73
Definition: v8-internal.h:969
static constexpr int kFrameCPSlotCount
Definition: v8-internal.h:1117
v8::Local< v8::Data > 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:1080
void(*)(const FunctionCallbackInfo< Value > &info) FunctionCallback
Definition: v8-function-callback.h:355
#define V8_EXPORT
Definition: v8config.h:875
#define V8_INLINE
Definition: v8config.h:519
#define V8_DEPRECATE_SOON(message)
Definition: v8config.h:632
#define V8_UNLIKELY(condition)
Definition: v8config.h:678