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");
93 template <
class F,
class G,
class H>
106 static constexpr int kIsolateAndFlagsIndex = -2;
149 static constexpr int kUnusedIndex = 0;
150 static constexpr int kIsolateAndFlagsIndex = 1;
151 static constexpr int kContextIndex = 2;
152 static constexpr int kReturnValueIndex = 3;
153 static constexpr int kTargetIndex = 4;
154 static constexpr int kNewTargetIndex = 5;
155 static constexpr int kArgsLength = 6;
157 static constexpr int kArgsLengthWithReceiver = kArgsLength + 1;
161 static constexpr int kImplicitArgsOffset = 0;
162 static constexpr int kValuesOffset =
164 static constexpr int kLengthOffset =
167 static constexpr int kThisValuesIndex = -1;
169 kIsolateAndFlagsIndex - kReturnValueIndex);
243 "Access to receiver will be deprecated soon. Use HolderV2() instead. \n"
244 "See http://crbug.com/455600234. ")
284 template <typename U>
291 static constexpr
int kPropertyKeyIndex = 0;
292 static constexpr
int kShouldThrowOnErrorIndex = 1;
293 static constexpr
int kHolderIndex = 2;
294 static constexpr
int kIsolateAndFlagsIndex = 3;
296 static constexpr
int kUnusedIndex = 4;
297 static constexpr
int kReturnValueIndex = 5;
298 static constexpr
int kCallbackInfoIndex = 6;
299 static constexpr
int kThisIndex = 7;
300 static constexpr
int kArgsLength = 8;
302 static constexpr
int kSize = kArgsLength * internal::kApiSystemPointerSize;
306 mutable internal::Address args_[kArgsLength];
318#if V8_STATIC_ROOTS_BOOL
319 using I = internal::Internals;
324 *value_ = I::DecompressTaggedField(*value_, I::CompressTagged(value));
333 static_assert(std::is_base_of_v<T, S>,
"type check");
337 SetInternal(handle.
ptr());
344 static_assert(std::is_base_of_v<T, S>,
"type check");
345#ifdef V8_ENABLE_CHECKS
348 SetInternal(handle.
ptr());
354 static_assert(std::is_base_of_v<T, S>,
"type check");
358 SetInternal(handle.
ptr());
365 static_assert(std::is_base_of_v<T, S>,
"type check");
366#ifdef V8_ENABLE_CHECKS
369 SetInternal(handle.
ptr());
376#if defined(V8_DEPRECATION_WARNINGS) || \
377 defined(V8_IMMINENT_DEPRECATION_WARNINGS)
378 static constexpr bool is_allowed_void =
false;
379 static_assert(!std::is_void_v<T>,
380 "ReturnValue<void>::Set(const Local<S>) is deprecated. "
381 "Do nothing to indicate that the operation succeeded or use "
382 "SetFalse() to indicate that the operation failed (don't "
383 "forget to handle info.ShouldThrowOnError()). "
384 "See http://crbug.com/348660658 for details.");
386 static constexpr bool is_allowed_void = std::is_void_v<T>;
389 static_assert(is_allowed_void || std::is_base_of_v<T, S>,
"type check");
392 }
else if constexpr (is_allowed_void) {
397 SetInternal(handle.
ptr());
405#if defined(V8_DEPRECATION_WARNINGS) || \
406 defined(V8_IMMINENT_DEPRECATION_WARNINGS)
407 static constexpr bool is_allowed_void =
false;
408 static_assert(!std::is_void_v<T>,
409 "ReturnValue<void>::SetNonEmpty(const Local<S>) is deprecated. "
410 "Do nothing to indicate that the operation succeeded or use "
411 "SetFalse() to indicate that the operation failed (don't "
412 "forget to handle info.ShouldThrowOnError()). "
413 "See http://crbug.com/348660658 for details.");
415 static constexpr bool is_allowed_void = std::is_void_v<T>;
419 static_assert(is_allowed_void || std::is_base_of_v<T, S>,
"type check");
420#ifdef V8_ENABLE_CHECKS
423 if constexpr (is_allowed_void) {
428 SetInternal(handle.
ptr());
434 static_assert(std::is_base_of_v<T, Number>,
"type check");
440 static_assert(std::is_base_of_v<T, Integer>,
"type check");
442 static_assert(I::IsValidSmi(std::numeric_limits<int16_t>::min()));
443 static_assert(I::IsValidSmi(std::numeric_limits<int16_t>::max()));
444 SetInternal(I::IntegralToSmi(i));
449 static_assert(std::is_base_of_v<T, Integer>,
"type check");
451 SetInternal(*result);
459 static_assert(std::is_base_of_v<T, Integer>,
"type check");
461 SetInternal(*result);
469 static_assert(std::is_base_of_v<T, Integer>,
"type check");
471 static_assert(I::IsValidSmi(std::numeric_limits<uint16_t>::min()));
472 static_assert(I::IsValidSmi(std::numeric_limits<uint16_t>::max()));
473 SetInternal(I::IntegralToSmi(i));
478 static_assert(std::is_base_of_v<T, Integer>,
"type check");
480 SetInternal(*result);
488 static_assert(std::is_base_of_v<T, Integer>,
"type check");
490 SetInternal(*result);
498 static_assert(std::is_void_v<T> || std::is_base_of_v<T, Boolean>,
501#if V8_STATIC_ROOTS_BOOL
502#ifdef V8_ENABLE_CHECKS
504 internal::ValueHelper::SlotAsValue<Value, true>(value_));
506 SetInternal(value ? I::StaticReadOnlyRoot::kTrueValue
507 : I::StaticReadOnlyRoot::kFalseValue);
511 root_index = I::kTrueValueRootIndex;
513 root_index = I::kFalseValueRootIndex;
515 *value_ = I::GetRoot(
GetIsolate(), root_index);
522 if constexpr (std::is_same_v<void, T> || std::is_same_v<v8::Boolean, T>) {
524 }
else if constexpr (std::is_same_v<v8::Integer, T>) {
525 SetInternal(I::IntegralToSmi(0));
527 static_assert(std::is_same_v<v8::Value, T> || std::is_same_v<v8::Array, T>);
528#if V8_STATIC_ROOTS_BOOL
529 SetInternal(I::StaticReadOnlyRoot::kUndefinedValue);
531 *value_ = I::GetRoot(
GetIsolate(), I::kUndefinedValueRootIndex);
538 static_assert(std::is_base_of_v<T, Primitive>,
"type check");
540#if V8_STATIC_ROOTS_BOOL
541#ifdef V8_ENABLE_CHECKS
543 internal::ValueHelper::SlotAsValue<Value, true>(value_));
545 SetInternal(I::StaticReadOnlyRoot::kNullValue);
547 *value_ = I::GetRoot(
GetIsolate(), I::kNullValueRootIndex);
553 static_assert(std::is_base_of_v<T, Primitive>,
"type check");
555#if V8_STATIC_ROOTS_BOOL
556#ifdef V8_ENABLE_CHECKS
558 internal::ValueHelper::SlotAsValue<Value, true>(value_));
560 SetInternal(I::StaticReadOnlyRoot::kUndefinedValue);
562 *value_ = I::GetRoot(
GetIsolate(), I::kUndefinedValueRootIndex);
568 static_assert(std::is_void_v<T> || std::is_base_of_v<T, Boolean>,
571#if V8_STATIC_ROOTS_BOOL
572#ifdef V8_ENABLE_CHECKS
574 internal::ValueHelper::SlotAsValue<Value, true>(value_));
576 SetInternal(I::StaticReadOnlyRoot::kFalseValue);
578 *value_ = I::GetRoot(
GetIsolate(), I::kFalseValueRootIndex);
584 static_assert(std::is_base_of_v<T, String>,
"type check");
586#if V8_STATIC_ROOTS_BOOL
587#ifdef V8_ENABLE_CHECKS
589 internal::ValueHelper::SlotAsValue<Value, true>(value_));
591 SetInternal(I::StaticReadOnlyRoot::kEmptyString);
593 *value_ = I::GetRoot(
GetIsolate(), I::kEmptyStringRootIndex);
601 return reinterpret_cast<Isolate*
>(isolate_and_flags &
602 ~I::kCallbackInfoIsolateFlagsMask);
608 internal::ValueHelper::SlotAsValue<Value>(value_));
614 static_assert(
sizeof(S) < 0,
"incompilable to prevent inadvertent misuse");
621 : implicit_args_(implicit_args), values_(values), length_(length) {}
626 if (i < 0 || Length() <= i)
return Undefined(GetIsolate());
651 return reinterpret_cast<Isolate*
>(isolate_and_flags &
652 ~I::kCallbackInfoIsolateFlagsMask);
662 return !NewTarget()->IsUndefined();
667 return static_cast<int>(length_);
674 return reinterpret_cast<Isolate*
>(isolate_and_flags &
675 ~I::kCallbackInfoIsolateFlagsMask);
683 I::ReadTaggedPointerField(callback_info, I::kCallbackInfoDataOffset);
705 if (args_[kShouldThrowOnErrorIndex] !=
706 I::IntegralToSmi(I::kInferShouldThrowMode)) {
707 return args_[kShouldThrowOnErrorIndex] != I::IntegralToSmi(I::kDontThrow);
710 reinterpret_cast<v8::internal::Isolate*
>(GetIsolate()));
Definition: v8-traced-handle.h:124
Definition: v8-function-callback.h:118
ReturnValue< T > GetReturnValue() const
Definition: v8-function-callback.h:656
Local< Object > This() const
Definition: v8-function-callback.h:631
Local< Value > operator[](int i) const
Definition: v8-function-callback.h:624
Isolate * GetIsolate() const
Definition: v8-function-callback.h:648
Local< Value > NewTarget() const
Definition: v8-function-callback.h:637
friend class debug::ConsoleCallArguments
Definition: v8-function-callback.h:143
friend class internal::FunctionCallbackArguments
Definition: v8-function-callback.h:141
Local< Value > Data() const
Definition: v8-function-callback.h:642
bool IsConstructCall() const
Definition: v8-function-callback.h:661
int Length() const
Definition: v8-function-callback.h:666
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:187
Local< Value > Data() const
Definition: v8-function-callback.h:679
friend class internal::PropertyCallbackArguments
Definition: v8-function-callback.h:287
bool ShouldThrowOnError() const
Definition: v8-function-callback.h:703
ReturnValue< T > GetReturnValue() const
Definition: v8-function-callback.h:698
Local< Object > HolderV2() const
Definition: v8-function-callback.h:693
friend void internal::PrintPropertyCallbackInfo(void *)
friend class MacroAssembler
Definition: v8-function-callback.h:286
Local< Object > This() const
Definition: v8-function-callback.h:688
Isolate * GetIsolate() const
Definition: v8-function-callback.h:671
Definition: v8-function-callback.h:41
void SetFalse()
Definition: v8-function-callback.h:567
void SetEmptyString()
Definition: v8-function-callback.h:583
friend class ReturnValue
Definition: v8-function-callback.h:88
void Set(const Global< S > &handle)
Definition: v8-function-callback.h:332
ReturnValue(const ReturnValue< S > &that)
Definition: v8-function-callback.h:44
void SetNonEmpty(const Global< S > &handle)
Definition: v8-function-callback.h:343
Local< Value > Get() const
Definition: v8-function-callback.h:606
void SetNull()
Definition: v8-function-callback.h:537
Isolate * GetIsolate() const
Definition: v8-function-callback.h:598
void SetUndefined()
Definition: v8-function-callback.h:552
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:878
static constexpr std::optional< Address > TryIntegralToSmi(T value)
Definition: v8-internal.h:1159
v8::Local< v8::Value > GetFunctionTemplateData(v8::Isolate *isolate, v8::Local< v8::Data > raw_target)
const int kApiSystemPointerSize
Definition: v8-internal.h:51
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:1454
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:309
#define V8_EXPORT
Definition: v8config.h:855
#define V8_INLINE
Definition: v8config.h:508
#define V8_DEPRECATE_SOON(message)
Definition: v8config.h:622
#define V8_UNLIKELY(condition)
Definition: v8config.h:668