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<T, S>::value,
"type check");
93 template <
class F,
class G,
class H>
106 static constexpr int kIsolateValueIndex = -2;
140 "V8 will stop providing access to hidden prototype (i.e. "
141 "JSGlobalObject). Use This() instead. \n"
142 "DO NOT try to workaround this by accessing JSGlobalObject via "
143 "v8::Object::GetPrototype() - it'll be deprecated soon too. \n"
144 "See http://crbug.com/333672197. ")
168 static constexpr int kHolderIndex = 0;
169 static constexpr int kIsolateIndex = 1;
170 static constexpr int kContextIndex = 2;
171 static constexpr int kReturnValueIndex = 3;
172 static constexpr int kTargetIndex = 4;
173 static constexpr int kNewTargetIndex = 5;
174 static constexpr int kArgsLength = 6;
176 static constexpr int kArgsLengthWithReceiver = kArgsLength + 1;
180 static constexpr int kImplicitArgsOffset = 0;
181 static constexpr int kValuesOffset =
183 static constexpr int kLengthOffset =
186 static constexpr int kThisValuesIndex = -1;
188 kIsolateIndex - kReturnValueIndex);
273 "V8 will stop providing access to hidden prototype (i.e. "
274 "JSGlobalObject). Use HolderV2() instead. \n"
275 "DO NOT try to workaround this by accessing JSGlobalObject via "
276 "v8::Object::GetPrototype() - it'll be deprecated soon too. \n"
277 "See http://crbug.com/333672197. ")
309 template <typename U>
316 static constexpr
int kPropertyKeyIndex = 0;
317 static constexpr
int kShouldThrowOnErrorIndex = 1;
318 static constexpr
int kHolderIndex = 2;
319 static constexpr
int kIsolateIndex = 3;
320 static constexpr
int kHolderV2Index = 4;
321 static constexpr
int kReturnValueIndex = 5;
322 static constexpr
int kDataIndex = 6;
323 static constexpr
int kThisIndex = 7;
324 static constexpr
int kArgsLength = 8;
326 static constexpr
int kSize = kArgsLength * internal::kApiSystemPointerSize;
330 mutable internal::Address args_[kArgsLength];
342#if V8_STATIC_ROOTS_BOOL
343 using I = internal::Internals;
348 *value_ = I::DecompressTaggedField(*value_, I::CompressTagged(value));
357 static_assert(std::is_base_of<T, S>::value,
"type check");
361 SetInternal(handle.
ptr());
368 static_assert(std::is_base_of<T, S>::value,
"type check");
369#ifdef V8_ENABLE_CHECKS
372 SetInternal(handle.
ptr());
378 static_assert(std::is_base_of<T, S>::value,
"type check");
382 SetInternal(handle.
ptr());
389 static_assert(std::is_base_of<T, S>::value,
"type check");
390#ifdef V8_ENABLE_CHECKS
393 SetInternal(handle.
ptr());
400#ifdef V8_IMMINENT_DEPRECATION_WARNINGS
401 static constexpr bool is_allowed_void =
false;
402 static_assert(!std::is_void<T>::value,
403 "ReturnValue<void>::Set(const Local<S>) is deprecated. "
404 "Do nothing to indicate that the operation succeeded or use "
405 "SetFalse() to indicate that the operation failed (don't "
406 "forget to handle info.ShouldThrowOnError()). "
407 "See http://crbug.com/348660658 for details.");
409 static constexpr bool is_allowed_void = std::is_void<T>::value;
411 static_assert(is_allowed_void || std::is_base_of<T, S>::value,
"type check");
414 }
else if constexpr (is_allowed_void) {
419 SetInternal(handle.
ptr());
427#ifdef V8_IMMINENT_DEPRECATION_WARNINGS
428 static constexpr bool is_allowed_void =
false;
429 static_assert(!std::is_void<T>::value,
430 "ReturnValue<void>::SetNonEmpty(const Local<S>) is deprecated. "
431 "Do nothing to indicate that the operation succeeded or use "
432 "SetFalse() to indicate that the operation failed (don't "
433 "forget to handle info.ShouldThrowOnError()). "
434 "See http://crbug.com/348660658 for details.");
436 static constexpr bool is_allowed_void = std::is_void<T>::value;
438 static_assert(is_allowed_void || std::is_base_of<T, S>::value,
"type check");
439#ifdef V8_ENABLE_CHECKS
442 if constexpr (is_allowed_void) {
447 SetInternal(handle.
ptr());
453 static_assert(std::is_base_of<T, Number>::value,
"type check");
459 static_assert(std::is_base_of<T, Integer>::value,
"type check");
461 static_assert(I::IsValidSmi(std::numeric_limits<int16_t>::min()));
462 static_assert(I::IsValidSmi(std::numeric_limits<int16_t>::max()));
463 SetInternal(I::IntegralToSmi(i));
468 static_assert(std::is_base_of<T, Integer>::value,
"type check");
470 SetInternal(*result);
478 static_assert(std::is_base_of<T, Integer>::value,
"type check");
480 SetInternal(*result);
488 static_assert(std::is_base_of<T, Integer>::value,
"type check");
490 static_assert(I::IsValidSmi(std::numeric_limits<uint16_t>::min()));
491 static_assert(I::IsValidSmi(std::numeric_limits<uint16_t>::max()));
492 SetInternal(I::IntegralToSmi(i));
497 static_assert(std::is_base_of<T, Integer>::value,
"type check");
499 SetInternal(*result);
507 static_assert(std::is_base_of<T, Integer>::value,
"type check");
509 SetInternal(*result);
517 static_assert(std::is_void<T>::value || std::is_base_of<T, Boolean>::value,
520#if V8_STATIC_ROOTS_BOOL
521#ifdef V8_ENABLE_CHECKS
523 internal::ValueHelper::SlotAsValue<Value, true>(value_));
525 SetInternal(value ? I::StaticReadOnlyRoot::kTrueValue
526 : I::StaticReadOnlyRoot::kFalseValue);
530 root_index = I::kTrueValueRootIndex;
532 root_index = I::kFalseValueRootIndex;
534 *value_ = I::GetRoot(
GetIsolate(), root_index);
541 if constexpr (std::is_same_v<void, T> || std::is_same_v<v8::Boolean, T>) {
543 }
else if constexpr (std::is_same_v<v8::Integer, T>) {
544 SetInternal(I::IntegralToSmi(0));
546 static_assert(std::is_same_v<v8::Value, T> || std::is_same_v<v8::Array, T>);
547#if V8_STATIC_ROOTS_BOOL
548 SetInternal(I::StaticReadOnlyRoot::kUndefinedValue);
550 *value_ = I::GetRoot(
GetIsolate(), I::kUndefinedValueRootIndex);
557 static_assert(std::is_base_of<T, Primitive>::value,
"type check");
559#if V8_STATIC_ROOTS_BOOL
560#ifdef V8_ENABLE_CHECKS
562 internal::ValueHelper::SlotAsValue<Value, true>(value_));
564 SetInternal(I::StaticReadOnlyRoot::kNullValue);
566 *value_ = I::GetRoot(
GetIsolate(), I::kNullValueRootIndex);
572 static_assert(std::is_base_of<T, Primitive>::value,
"type check");
574#if V8_STATIC_ROOTS_BOOL
575#ifdef V8_ENABLE_CHECKS
577 internal::ValueHelper::SlotAsValue<Value, true>(value_));
579 SetInternal(I::StaticReadOnlyRoot::kUndefinedValue);
581 *value_ = I::GetRoot(
GetIsolate(), I::kUndefinedValueRootIndex);
587 static_assert(std::is_void<T>::value || std::is_base_of<T, Boolean>::value,
590#if V8_STATIC_ROOTS_BOOL
591#ifdef V8_ENABLE_CHECKS
593 internal::ValueHelper::SlotAsValue<Value, true>(value_));
595 SetInternal(I::StaticReadOnlyRoot::kFalseValue);
597 *value_ = I::GetRoot(
GetIsolate(), I::kFalseValueRootIndex);
603 static_assert(std::is_base_of<T, String>::value,
"type check");
605#if V8_STATIC_ROOTS_BOOL
606#ifdef V8_ENABLE_CHECKS
608 internal::ValueHelper::SlotAsValue<Value, true>(value_));
610 SetInternal(I::StaticReadOnlyRoot::kEmptyString);
612 *value_ = I::GetRoot(
GetIsolate(), I::kEmptyStringRootIndex);
618 return *
reinterpret_cast<Isolate**
>(&value_[kIsolateValueIndex]);
624 internal::ValueHelper::SlotAsValue<Value>(value_));
630 static_assert(
sizeof(S) < 0,
"incompilable to prevent inadvertent misuse");
637 : implicit_args_(implicit_args), values_(values), length_(length) {}
642 if (i < 0 || Length() <= i)
return Undefined(GetIsolate());
659 return HolderSoonToBeDeprecated();
675 return *
reinterpret_cast<Isolate**
>(&implicit_args_[kIsolateIndex]);
685 return !NewTarget()->IsUndefined();
690 return static_cast<int>(length_);
695 return *
reinterpret_cast<Isolate**
>(&args_[kIsolateIndex]);
713namespace api_internal {
723 if (!I::HasHeapObjectTag(args_[kHolderV2Index])) {
724 args_[kHolderV2Index] =
738 if (args_[kShouldThrowOnErrorIndex] !=
739 I::IntegralToSmi(I::kInferShouldThrowMode)) {
740 return args_[kShouldThrowOnErrorIndex] != I::IntegralToSmi(I::kDontThrow);
743 reinterpret_cast<v8::internal::Isolate*
>(GetIsolate()));
Definition: v8-traced-handle.h:124
Definition: v8-function-callback.h:118
Local< Object > HolderSoonToBeDeprecated() const
Definition: v8-function-callback.h:653
ReturnValue< T > GetReturnValue() const
Definition: v8-function-callback.h:679
Local< Object > This() const
Definition: v8-function-callback.h:647
Local< Object > Holder() const
Definition: v8-function-callback.h:658
Local< Value > operator[](int i) const
Definition: v8-function-callback.h:640
Isolate * GetIsolate() const
Definition: v8-function-callback.h:674
Local< Value > NewTarget() const
Definition: v8-function-callback.h:663
friend class debug::ConsoleCallArguments
Definition: v8-function-callback.h:165
friend class internal::FunctionCallbackArguments
Definition: v8-function-callback.h:163
Local< Value > Data() const
Definition: v8-function-callback.h:668
bool IsConstructCall() const
Definition: v8-function-callback.h:684
int Length() const
Definition: v8-function-callback.h:689
Definition: v8-persistent-handle.h:347
static Local< Integer > New(Isolate *isolate, int32_t value)
static Local< Integer > NewFromUnsigned(Isolate *isolate, uint32_t value)
Definition: v8-isolate.h:212
Definition: v8-local-handle.h:266
static Local< T > New(Isolate *isolate, Local< T > that)
Definition: v8-local-handle.h:346
static Local< Number > New(Isolate *isolate, double value)
Definition: v8-object.h:233
Definition: v8-util.h:166
Definition: v8-function-callback.h:206
Local< Value > Data() const
Definition: v8-function-callback.h:699
friend class internal::PropertyCallbackArguments
Definition: v8-function-callback.h:312
Local< Object > Holder() const
Definition: v8-function-callback.h:709
bool ShouldThrowOnError() const
Definition: v8-function-callback.h:736
ReturnValue< T > GetReturnValue() const
Definition: v8-function-callback.h:731
Local< Object > HolderV2() const
Definition: v8-function-callback.h:721
friend void internal::PrintPropertyCallbackInfo(void *)
friend class MacroAssembler
Definition: v8-function-callback.h:311
Local< Object > This() const
Definition: v8-function-callback.h:704
Isolate * GetIsolate() const
Definition: v8-function-callback.h:694
Definition: v8-function-callback.h:41
void SetFalse()
Definition: v8-function-callback.h:586
void SetEmptyString()
Definition: v8-function-callback.h:602
friend class ReturnValue
Definition: v8-function-callback.h:88
void Set(const Global< S > &handle)
Definition: v8-function-callback.h:356
ReturnValue(const ReturnValue< S > &that)
Definition: v8-function-callback.h:44
void SetNonEmpty(const Global< S > &handle)
Definition: v8-function-callback.h:367
Local< Value > Get() const
Definition: v8-function-callback.h:622
void SetNull()
Definition: v8-function-callback.h:556
Isolate * GetIsolate() const
Definition: v8-function-callback.h:617
void SetUndefined()
Definition: v8-function-callback.h:571
Definition: v8-container.h:148
Definition: v8-value.h:32
internal::Address ptr() const
Definition: v8-handle-base.h:76
bool IsEmpty() const
Definition: v8-handle-base.h:56
Definition: v8-local-handle.h:72
Definition: v8-internal.h:855
static constexpr std::optional< Address > TryIntegralToSmi(T value)
Definition: v8-internal.h:1101
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:64
void VerifyHandleIsNonEmpty(bool is_empty)
bool ShouldThrowOnError(internal::Isolate *isolate)
uintptr_t Address
Definition: v8-internal.h:51
void PerformCastCheck(T *data)
Definition: v8-internal.h:1352
void PrintFunctionCallbackInfo(void *function_callback_info)
Definition: libplatform.h:15
Local< Primitive > Undefined(Isolate *isolate)
Definition: v8-primitive.h:1021
void(*)(const FunctionCallbackInfo< Value > &info) FunctionCallback
Definition: v8-function-callback.h:333
#define V8_EXPORT
Definition: v8config.h:793
#define V8_INLINE
Definition: v8config.h:499
#define V8_DEPRECATE_SOON(message)
Definition: v8config.h:603
#define V8_DEPRECATED(message)
Definition: v8config.h:595
#define V8_UNLIKELY(condition)
Definition: v8config.h:649