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;
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);
254 "V8 will stop providing access to hidden prototype (i.e. "
255 "JSGlobalObject). Use HolderV2() instead. \n"
256 "DO NOT try to workaround this by accessing JSGlobalObject via "
257 "v8::Object::GetPrototype() - it'll be deprecated soon too. \n"
258 "See http://crbug.com/333672197. ")
290 template <typename U>
297 static constexpr
int kPropertyKeyIndex = 0;
298 static constexpr
int kShouldThrowOnErrorIndex = 1;
299 static constexpr
int kHolderIndex = 2;
300 static constexpr
int kIsolateIndex = 3;
301 static constexpr
int kHolderV2Index = 4;
302 static constexpr
int kReturnValueIndex = 5;
303 static constexpr
int kDataIndex = 6;
304 static constexpr
int kThisIndex = 7;
305 static constexpr
int kArgsLength = 8;
307 static constexpr
int kSize = kArgsLength * internal::kApiSystemPointerSize;
311 mutable internal::Address args_[kArgsLength];
323#if V8_STATIC_ROOTS_BOOL
324 using I = internal::Internals;
329 *value_ = I::DecompressTaggedField(*value_, I::CompressTagged(value));
338 static_assert(std::is_base_of<T, S>::value,
"type check");
342 SetInternal(handle.
ptr());
349 static_assert(std::is_base_of<T, S>::value,
"type check");
350#ifdef V8_ENABLE_CHECKS
353 SetInternal(handle.
ptr());
359 static_assert(std::is_base_of<T, S>::value,
"type check");
363 SetInternal(handle.
ptr());
370 static_assert(std::is_base_of<T, S>::value,
"type check");
371#ifdef V8_ENABLE_CHECKS
374 SetInternal(handle.
ptr());
381#ifdef V8_IMMINENT_DEPRECATION_WARNINGS
382 static constexpr bool is_allowed_void =
false;
383 static_assert(!std::is_void<T>::value,
384 "ReturnValue<void>::Set(const Local<S>) is deprecated. "
385 "Do nothing to indicate that the operation succeeded or use "
386 "SetFalse() to indicate that the operation failed (don't "
387 "forget to handle info.ShouldThrowOnError()). "
388 "See http://crbug.com/348660658 for details.");
390 static constexpr bool is_allowed_void = std::is_void<T>::value;
392 static_assert(is_allowed_void || std::is_base_of<T, S>::value,
"type check");
395 }
else if constexpr (is_allowed_void) {
400 SetInternal(handle.
ptr());
408#ifdef V8_IMMINENT_DEPRECATION_WARNINGS
409 static constexpr bool is_allowed_void =
false;
410 static_assert(!std::is_void<T>::value,
411 "ReturnValue<void>::SetNonEmpty(const Local<S>) is deprecated. "
412 "Do nothing to indicate that the operation succeeded or use "
413 "SetFalse() to indicate that the operation failed (don't "
414 "forget to handle info.ShouldThrowOnError()). "
415 "See http://crbug.com/348660658 for details.");
417 static constexpr bool is_allowed_void = std::is_void<T>::value;
419 static_assert(is_allowed_void || std::is_base_of<T, S>::value,
"type check");
420#ifdef V8_ENABLE_CHECKS
423 if constexpr (is_allowed_void) {
428 SetInternal(handle.
ptr());
434 static_assert(std::is_base_of<T, Number>::value,
"type check");
440 static_assert(std::is_base_of<T, Integer>::value,
"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<T, Integer>::value,
"type check");
451 SetInternal(*result);
459 static_assert(std::is_base_of<T, Integer>::value,
"type check");
461 SetInternal(*result);
469 static_assert(std::is_base_of<T, Integer>::value,
"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<T, Integer>::value,
"type check");
480 SetInternal(*result);
488 static_assert(std::is_base_of<T, Integer>::value,
"type check");
490 SetInternal(*result);
498 static_assert(std::is_void<T>::value || std::is_base_of<T, Boolean>::value,
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<T, Primitive>::value,
"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<T, Primitive>::value,
"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<T>::value || std::is_base_of<T, Boolean>::value,
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<T, String>::value,
"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);
599 return *
reinterpret_cast<Isolate**
>(&value_[kIsolateValueIndex]);
605 internal::ValueHelper::SlotAsValue<Value>(value_));
611 static_assert(
sizeof(S) < 0,
"incompilable to prevent inadvertent misuse");
618 : implicit_args_(implicit_args), values_(values), length_(length) {}
623 if (i < 0 || Length() <= i)
return Undefined(GetIsolate());
646 return *
reinterpret_cast<Isolate**
>(&implicit_args_[kIsolateIndex]);
656 return !NewTarget()->IsUndefined();
661 return static_cast<int>(length_);
666 return *
reinterpret_cast<Isolate**
>(&args_[kIsolateIndex]);
684namespace api_internal {
694 if (!I::HasHeapObjectTag(args_[kHolderV2Index])) {
695 args_[kHolderV2Index] =
709 if (args_[kShouldThrowOnErrorIndex] !=
710 I::IntegralToSmi(I::kInferShouldThrowMode)) {
711 return args_[kShouldThrowOnErrorIndex] != I::IntegralToSmi(I::kDontThrow);
714 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:650
Local< Object > This() const
Definition: v8-function-callback.h:628
Local< Value > operator[](int i) const
Definition: v8-function-callback.h:621
Isolate * GetIsolate() const
Definition: v8-function-callback.h:645
Local< Value > NewTarget() const
Definition: v8-function-callback.h:634
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:639
bool IsConstructCall() const
Definition: v8-function-callback.h:655
int Length() const
Definition: v8-function-callback.h:660
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:274
Definition: v8-local-handle.h:267
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:187
Local< Value > Data() const
Definition: v8-function-callback.h:670
friend class internal::PropertyCallbackArguments
Definition: v8-function-callback.h:293
Local< Object > Holder() const
Definition: v8-function-callback.h:680
bool ShouldThrowOnError() const
Definition: v8-function-callback.h:707
ReturnValue< T > GetReturnValue() const
Definition: v8-function-callback.h:702
Local< Object > HolderV2() const
Definition: v8-function-callback.h:692
friend void internal::PrintPropertyCallbackInfo(void *)
friend class MacroAssembler
Definition: v8-function-callback.h:292
Local< Object > This() const
Definition: v8-function-callback.h:675
Isolate * GetIsolate() const
Definition: v8-function-callback.h:665
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:337
ReturnValue(const ReturnValue< S > &that)
Definition: v8-function-callback.h:44
void SetNonEmpty(const Global< S > &handle)
Definition: v8-function-callback.h:348
Local< Value > Get() const
Definition: v8-function-callback.h:603
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:72
Definition: v8-internal.h:830
static constexpr std::optional< Address > TryIntegralToSmi(T value)
Definition: v8-internal.h:1079
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:65
void VerifyHandleIsNonEmpty(bool is_empty)
bool ShouldThrowOnError(internal::Isolate *isolate)
uintptr_t Address
Definition: v8-internal.h:52
void PerformCastCheck(T *data)
Definition: v8-internal.h:1337
void PrintFunctionCallbackInfo(void *function_callback_info)
Definition: libplatform.h:15
Local< Primitive > Undefined(Isolate *isolate)
Definition: v8-primitive.h:1055
void(*)(const FunctionCallbackInfo< Value > &info) FunctionCallback
Definition: v8-function-callback.h:314
#define V8_EXPORT
Definition: v8config.h:803
#define V8_INLINE
Definition: v8config.h:499
#define V8_DEPRECATE_SOON(message)
Definition: v8config.h:613
#define V8_UNLIKELY(condition)
Definition: v8config.h:659