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 kIsolateValueIndex = -2;
149 static constexpr int kUnusedIndex = 0;
150 static constexpr int kIsolateIndex = 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 kIsolateIndex - kReturnValueIndex);
243 "Access to receiver will be deprecated soon. Use HolderV2() instead. \n"
244 "See http://crbug.com/455600234. ")
277 template <typename U>
284 static constexpr
int kPropertyKeyIndex = 0;
285 static constexpr
int kShouldThrowOnErrorIndex = 1;
287 static constexpr
int kHolderIndex = 2;
288 static constexpr
int kIsolateIndex = 3;
289 static constexpr
int kHolderV2Index = 4;
290 static constexpr
int kReturnValueIndex = 5;
291 static constexpr
int kDataIndex = 6;
292 static constexpr
int kThisIndex = 7;
293 static constexpr
int kArgsLength = 8;
295 static constexpr
int kSize = kArgsLength * internal::kApiSystemPointerSize;
299 mutable internal::Address args_[kArgsLength];
311#if V8_STATIC_ROOTS_BOOL
312 using I = internal::Internals;
317 *value_ = I::DecompressTaggedField(*value_, I::CompressTagged(value));
326 static_assert(std::is_base_of_v<T, S>,
"type check");
330 SetInternal(handle.
ptr());
337 static_assert(std::is_base_of_v<T, S>,
"type check");
338#ifdef V8_ENABLE_CHECKS
341 SetInternal(handle.
ptr());
347 static_assert(std::is_base_of_v<T, S>,
"type check");
351 SetInternal(handle.
ptr());
358 static_assert(std::is_base_of_v<T, S>,
"type check");
359#ifdef V8_ENABLE_CHECKS
362 SetInternal(handle.
ptr());
369#ifdef V8_IMMINENT_DEPRECATION_WARNINGS
370 static constexpr bool is_allowed_void =
false;
371 static_assert(!std::is_void_v<T>,
372 "ReturnValue<void>::Set(const Local<S>) is deprecated. "
373 "Do nothing to indicate that the operation succeeded or use "
374 "SetFalse() to indicate that the operation failed (don't "
375 "forget to handle info.ShouldThrowOnError()). "
376 "See http://crbug.com/348660658 for details.");
378 static constexpr bool is_allowed_void = std::is_void_v<T>;
380 static_assert(is_allowed_void || std::is_base_of_v<T, S>,
"type check");
383 }
else if constexpr (is_allowed_void) {
388 SetInternal(handle.
ptr());
396#ifdef V8_IMMINENT_DEPRECATION_WARNINGS
397 static constexpr bool is_allowed_void =
false;
398 static_assert(!std::is_void_v<T>,
399 "ReturnValue<void>::SetNonEmpty(const Local<S>) is deprecated. "
400 "Do nothing to indicate that the operation succeeded or use "
401 "SetFalse() to indicate that the operation failed (don't "
402 "forget to handle info.ShouldThrowOnError()). "
403 "See http://crbug.com/348660658 for details.");
405 static constexpr bool is_allowed_void = std::is_void_v<T>;
407 static_assert(is_allowed_void || std::is_base_of_v<T, S>,
"type check");
408#ifdef V8_ENABLE_CHECKS
411 if constexpr (is_allowed_void) {
416 SetInternal(handle.
ptr());
422 static_assert(std::is_base_of_v<T, Number>,
"type check");
428 static_assert(std::is_base_of_v<T, Integer>,
"type check");
430 static_assert(I::IsValidSmi(std::numeric_limits<int16_t>::min()));
431 static_assert(I::IsValidSmi(std::numeric_limits<int16_t>::max()));
432 SetInternal(I::IntegralToSmi(i));
437 static_assert(std::is_base_of_v<T, Integer>,
"type check");
439 SetInternal(*result);
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 static_assert(I::IsValidSmi(std::numeric_limits<uint16_t>::min()));
460 static_assert(I::IsValidSmi(std::numeric_limits<uint16_t>::max()));
461 SetInternal(I::IntegralToSmi(i));
466 static_assert(std::is_base_of_v<T, Integer>,
"type check");
468 SetInternal(*result);
476 static_assert(std::is_base_of_v<T, Integer>,
"type check");
478 SetInternal(*result);
486 static_assert(std::is_void_v<T> || std::is_base_of_v<T, Boolean>,
489#if V8_STATIC_ROOTS_BOOL
490#ifdef V8_ENABLE_CHECKS
492 internal::ValueHelper::SlotAsValue<Value, true>(value_));
494 SetInternal(value ? I::StaticReadOnlyRoot::kTrueValue
495 : I::StaticReadOnlyRoot::kFalseValue);
499 root_index = I::kTrueValueRootIndex;
501 root_index = I::kFalseValueRootIndex;
503 *value_ = I::GetRoot(
GetIsolate(), root_index);
510 if constexpr (std::is_same_v<void, T> || std::is_same_v<v8::Boolean, T>) {
512 }
else if constexpr (std::is_same_v<v8::Integer, T>) {
513 SetInternal(I::IntegralToSmi(0));
515 static_assert(std::is_same_v<v8::Value, T> || std::is_same_v<v8::Array, T>);
516#if V8_STATIC_ROOTS_BOOL
517 SetInternal(I::StaticReadOnlyRoot::kUndefinedValue);
519 *value_ = I::GetRoot(
GetIsolate(), I::kUndefinedValueRootIndex);
526 static_assert(std::is_base_of_v<T, Primitive>,
"type check");
528#if V8_STATIC_ROOTS_BOOL
529#ifdef V8_ENABLE_CHECKS
531 internal::ValueHelper::SlotAsValue<Value, true>(value_));
533 SetInternal(I::StaticReadOnlyRoot::kNullValue);
535 *value_ = I::GetRoot(
GetIsolate(), I::kNullValueRootIndex);
541 static_assert(std::is_base_of_v<T, Primitive>,
"type check");
543#if V8_STATIC_ROOTS_BOOL
544#ifdef V8_ENABLE_CHECKS
546 internal::ValueHelper::SlotAsValue<Value, true>(value_));
548 SetInternal(I::StaticReadOnlyRoot::kUndefinedValue);
550 *value_ = I::GetRoot(
GetIsolate(), I::kUndefinedValueRootIndex);
556 static_assert(std::is_void_v<T> || std::is_base_of_v<T, Boolean>,
559#if V8_STATIC_ROOTS_BOOL
560#ifdef V8_ENABLE_CHECKS
562 internal::ValueHelper::SlotAsValue<Value, true>(value_));
564 SetInternal(I::StaticReadOnlyRoot::kFalseValue);
566 *value_ = I::GetRoot(
GetIsolate(), I::kFalseValueRootIndex);
572 static_assert(std::is_base_of_v<T, String>,
"type check");
574#if V8_STATIC_ROOTS_BOOL
575#ifdef V8_ENABLE_CHECKS
577 internal::ValueHelper::SlotAsValue<Value, true>(value_));
579 SetInternal(I::StaticReadOnlyRoot::kEmptyString);
581 *value_ = I::GetRoot(
GetIsolate(), I::kEmptyStringRootIndex);
587 return *
reinterpret_cast<Isolate**
>(&value_[kIsolateValueIndex]);
593 internal::ValueHelper::SlotAsValue<Value>(value_));
599 static_assert(
sizeof(S) < 0,
"incompilable to prevent inadvertent misuse");
606 : implicit_args_(implicit_args), values_(values), length_(length) {}
611 if (i < 0 || Length() <= i)
return Undefined(GetIsolate());
634 return *
reinterpret_cast<Isolate**
>(&implicit_args_[kIsolateIndex]);
644 return !NewTarget()->IsUndefined();
649 return static_cast<int>(length_);
654 return *
reinterpret_cast<Isolate**
>(&args_[kIsolateIndex]);
667namespace api_internal {
677 if (!I::HasHeapObjectTag(args_[kHolderV2Index])) {
678 args_[kHolderV2Index] =
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:118
ReturnValue< T > GetReturnValue() const
Definition: v8-function-callback.h:638
Local< Object > This() const
Definition: v8-function-callback.h:616
Local< Value > operator[](int i) const
Definition: v8-function-callback.h:609
Isolate * GetIsolate() const
Definition: v8-function-callback.h:633
Local< Value > NewTarget() const
Definition: v8-function-callback.h:622
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:627
bool IsConstructCall() const
Definition: v8-function-callback.h:643
int Length() const
Definition: v8-function-callback.h:648
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:234
Definition: v8-util.h:166
Definition: v8-function-callback.h:187
Local< Value > Data() const
Definition: v8-function-callback.h:658
friend class internal::PropertyCallbackArguments
Definition: v8-function-callback.h:280
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:675
friend void internal::PrintPropertyCallbackInfo(void *)
friend class MacroAssembler
Definition: v8-function-callback.h:279
Local< Object > This() const
Definition: v8-function-callback.h:663
Isolate * GetIsolate() const
Definition: v8-function-callback.h:653
Definition: v8-function-callback.h:41
void SetFalse()
Definition: v8-function-callback.h:555
void SetEmptyString()
Definition: v8-function-callback.h:571
friend class ReturnValue
Definition: v8-function-callback.h:88
void Set(const Global< S > &handle)
Definition: v8-function-callback.h:325
ReturnValue(const ReturnValue< S > &that)
Definition: v8-function-callback.h:44
void SetNonEmpty(const Global< S > &handle)
Definition: v8-function-callback.h:336
Local< Value > Get() const
Definition: v8-function-callback.h:591
void SetNull()
Definition: v8-function-callback.h:525
Isolate * GetIsolate() const
Definition: v8-function-callback.h:586
void SetUndefined()
Definition: v8-function-callback.h:540
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:1148
v8::Local< v8::Value > GetFunctionTemplateData(v8::Isolate *isolate, v8::Local< v8::Data > raw_target)
internal::Address ConvertToJSGlobalProxyIfNecessary(internal::Address holder)
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:1443
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:302
#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