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 = -2;
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;
280 "Access to receiver will be deprecated soon. Use HolderV2() instead. \n"
281 "See http://crbug.com/455600234. ")
321 template <typename U>
328 static constexpr
int kPropertyKeyIndex = 0;
329 static constexpr
int kShouldThrowOnErrorIndex = 1;
330 static constexpr
int kHolderIndex = 2;
331 static constexpr
int kIsolateIndex = 3;
333 static constexpr
int kUnusedIndex = 4;
334 static constexpr
int kReturnValueIndex = 5;
335 static constexpr
int kCallbackInfoIndex = 6;
336 static constexpr
int kThisIndex = 7;
337 static constexpr
int kArgsLength = 8;
339 static constexpr
int kSize = kArgsLength * internal::kApiSystemPointerSize;
343 mutable internal::Address args_[kArgsLength];
355#if V8_STATIC_ROOTS_BOOL
356 using I = internal::Internals;
361 *value_ = I::DecompressTaggedField(*value_, I::CompressTagged(value));
370 static_assert(std::is_base_of_v<T, S>,
"type check");
374 SetInternal(handle.
ptr());
381 static_assert(std::is_base_of_v<T, S>,
"type check");
382#ifdef V8_ENABLE_CHECKS
385 SetInternal(handle.
ptr());
391 static_assert(std::is_base_of_v<T, S>,
"type check");
395 SetInternal(handle.
ptr());
402 static_assert(std::is_base_of_v<T, S>,
"type check");
403#ifdef V8_ENABLE_CHECKS
406 SetInternal(handle.
ptr());
412 static_assert(std::is_base_of_v<T, S>,
"type check");
416 SetInternal(handle.
ptr());
423 static_assert(std::is_base_of_v<T, S>,
"type check");
424#ifdef V8_ENABLE_CHECKS
427 SetInternal(handle.
ptr());
432 static_assert(std::is_base_of_v<T, Number>,
"type check");
438 static_assert(std::is_base_of_v<T, Integer>,
"type check");
440 static_assert(I::IsValidSmi(std::numeric_limits<int16_t>::min()));
441 static_assert(I::IsValidSmi(std::numeric_limits<int16_t>::max()));
442 SetInternal(I::IntegralToSmi(i));
447 static_assert(std::is_base_of_v<T, Integer>,
"type check");
449 SetInternal(*result);
457 static_assert(std::is_base_of_v<T, Integer>,
"type check");
459 SetInternal(*result);
467 static_assert(std::is_base_of_v<T, Integer>,
"type check");
469 static_assert(I::IsValidSmi(std::numeric_limits<uint16_t>::min()));
470 static_assert(I::IsValidSmi(std::numeric_limits<uint16_t>::max()));
471 SetInternal(I::IntegralToSmi(i));
476 static_assert(std::is_base_of_v<T, Integer>,
"type check");
478 SetInternal(*result);
486 static_assert(std::is_base_of_v<T, Integer>,
"type check");
488 SetInternal(*result);
496 static_assert(std::is_void_v<T> || std::is_base_of_v<T, Boolean>,
499#if V8_STATIC_ROOTS_BOOL
500#ifdef V8_ENABLE_CHECKS
502 internal::ValueHelper::SlotAsValue<Value, true>(value_));
504 SetInternal(value ? I::StaticReadOnlyRoot::kTrueValue
505 : I::StaticReadOnlyRoot::kFalseValue);
509 root_index = I::kTrueValueRootIndex;
511 root_index = I::kFalseValueRootIndex;
513 *value_ = I::GetRoot(
GetIsolate(), root_index);
520 if constexpr (std::is_same_v<void, T> || std::is_same_v<v8::Boolean, T>) {
522 }
else if constexpr (std::is_same_v<v8::Integer, T>) {
523 SetInternal(I::IntegralToSmi(0));
525 static_assert(std::is_same_v<v8::Value, T> || std::is_same_v<v8::Array, T>);
526#if V8_STATIC_ROOTS_BOOL
527 SetInternal(I::StaticReadOnlyRoot::kUndefinedValue);
529 *value_ = I::GetRoot(
GetIsolate(), I::kUndefinedValueRootIndex);
536 static_assert(std::is_base_of_v<T, Primitive>,
"type check");
538#if V8_STATIC_ROOTS_BOOL
539#ifdef V8_ENABLE_CHECKS
541 internal::ValueHelper::SlotAsValue<Value, true>(value_));
543 SetInternal(I::StaticReadOnlyRoot::kNullValue);
545 *value_ = I::GetRoot(
GetIsolate(), I::kNullValueRootIndex);
551 static_assert(std::is_base_of_v<T, Primitive>,
"type check");
553#if V8_STATIC_ROOTS_BOOL
554#ifdef V8_ENABLE_CHECKS
556 internal::ValueHelper::SlotAsValue<Value, true>(value_));
558 SetInternal(I::StaticReadOnlyRoot::kUndefinedValue);
560 *value_ = I::GetRoot(
GetIsolate(), I::kUndefinedValueRootIndex);
566 static_assert(std::is_void_v<T> || std::is_base_of_v<T, Boolean>,
569#if V8_STATIC_ROOTS_BOOL
570#ifdef V8_ENABLE_CHECKS
572 internal::ValueHelper::SlotAsValue<Value, true>(value_));
574 SetInternal(I::StaticReadOnlyRoot::kFalseValue);
576 *value_ = I::GetRoot(
GetIsolate(), I::kFalseValueRootIndex);
582 static_assert(std::is_base_of_v<T, String>,
"type check");
584#if V8_STATIC_ROOTS_BOOL
585#ifdef V8_ENABLE_CHECKS
587 internal::ValueHelper::SlotAsValue<Value, true>(value_));
589 SetInternal(I::StaticReadOnlyRoot::kEmptyString);
591 *value_ = I::GetRoot(
GetIsolate(), I::kEmptyStringRootIndex);
597 return *
reinterpret_cast<Isolate**
>(&value_[kIsolateValueIndex]);
603 internal::ValueHelper::SlotAsValue<Value>(value_));
609 static_assert(
sizeof(S) < 0,
"incompilable to prevent inadvertent misuse");
625 if (IsConstructCall()) {
642 return reinterpret_cast<Isolate*
>(values_[kIsolateIndex]);
652 return I::SmiValue(values_[kFrameTypeIndex]) == I::kFrameTypeApiConstructExit;
657 return static_cast<int>(values_[kArgcIndex]);
662 return *
reinterpret_cast<Isolate**
>(&args_[kIsolateIndex]);
670 I::ReadTaggedPointerField(callback_info, I::kCallbackInfoDataOffset);
692 if (args_[kShouldThrowOnErrorIndex] !=
693 I::IntegralToSmi(I::kInferShouldThrowMode)) {
694 return args_[kShouldThrowOnErrorIndex] != I::IntegralToSmi(I::kDontThrow);
697 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:646
Local< Object > This() const
Definition: v8-function-callback.h:619
Local< Value > operator[](int i) const
Definition: v8-function-callback.h:613
Isolate * GetIsolate() const
Definition: v8-function-callback.h:641
Local< Value > NewTarget() const
Definition: v8-function-callback.h:624
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:635
bool IsConstructCall() const
Definition: v8-function-callback.h:651
int Length() const
Definition: v8-function-callback.h:656
Definition: v8-persistent-handle.h:349
static Local< Integer > New(Isolate *isolate, int32_t value)
static Local< Integer > NewFromUnsigned(Isolate *isolate, uint32_t value)
Definition: v8-isolate.h:291
Definition: v8-local-handle.h:366
static Local< T > New(Isolate *isolate, Local< T > that)
Definition: v8-local-handle.h:448
static Local< Number > New(Isolate *isolate, double value)
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:666
friend class internal::PropertyCallbackArguments
Definition: v8-function-callback.h:324
bool ShouldThrowOnError() const
Definition: v8-function-callback.h:690
ReturnValue< T > GetReturnValue() const
Definition: v8-function-callback.h:685
Local< Object > HolderV2() const
Definition: v8-function-callback.h:680
friend void internal::PrintPropertyCallbackInfo(void *)
friend class MacroAssembler
Definition: v8-function-callback.h:323
Local< Object > This() const
Definition: v8-function-callback.h:675
Isolate * GetIsolate() const
Definition: v8-function-callback.h:661
Definition: v8-function-callback.h:41
void SetFalse()
Definition: v8-function-callback.h:565
void SetEmptyString()
Definition: v8-function-callback.h:581
friend class ReturnValue
Definition: v8-function-callback.h:91
void Set(const Global< S > &handle)
Definition: v8-function-callback.h:369
ReturnValue(const ReturnValue< S > &that)
Definition: v8-function-callback.h:44
void SetNonEmpty(const Global< S > &handle)
Definition: v8-function-callback.h:380
Local< Value > Get() const
Definition: v8-function-callback.h:601
void SetNull()
Definition: v8-function-callback.h:535
Isolate * GetIsolate() const
Definition: v8-function-callback.h:596
void SetUndefined()
Definition: v8-function-callback.h:550
Definition: v8-container.h:148
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:885
static constexpr int kFrameCPSlotCount
Definition: v8-internal.h:1029
static constexpr std::optional< Address > TryIntegralToSmi(T value)
Definition: v8-internal.h:1162
v8::Local< v8::Value > GetFunctionTemplateData(v8::Isolate *isolate, v8::Local< v8::Data > raw_target)
void VerifyHandleIsNonEmpty(bool is_empty)
bool ShouldThrowOnError(internal::Isolate *isolate)
uintptr_t Address
Definition: v8-internal.h:38
void PerformCastCheck(T *data)
Definition: v8-internal.h:1457
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:346
#define V8_EXPORT
Definition: v8config.h:855
#define V8_INLINE
Definition: v8config.h:508
#define V8_DEPRECATED(message)
Definition: v8config.h:614
#define V8_UNLIKELY(condition)
Definition: v8config.h:668