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>
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>
323#if V8_STATIC_ROOTS_BOOL
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");
459 static_assert(std::is_base_of<T, Integer>::value,
"type check");
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");
488 static_assert(std::is_base_of<T, Integer>::value,
"type check");
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
506 SetInternal(value ? I::StaticReadOnlyRoot::kTrueValue
507 : I::StaticReadOnlyRoot::kFalseValue);
511 root_index = I::kTrueValueRootIndex;
513 root_index = I::kFalseValueRootIndex;
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);
538 static_assert(std::is_base_of<T, Primitive>::value,
"type check");
540#if V8_STATIC_ROOTS_BOOL
541#ifdef V8_ENABLE_CHECKS
545 SetInternal(I::StaticReadOnlyRoot::kNullValue);
553 static_assert(std::is_base_of<T, Primitive>::value,
"type check");
555#if V8_STATIC_ROOTS_BOOL
556#ifdef V8_ENABLE_CHECKS
560 SetInternal(I::StaticReadOnlyRoot::kUndefinedValue);
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
576 SetInternal(I::StaticReadOnlyRoot::kFalseValue);
584 static_assert(std::is_base_of<T, String>::value,
"type check");
586#if V8_STATIC_ROOTS_BOOL
587#ifdef V8_ENABLE_CHECKS
591 SetInternal(I::StaticReadOnlyRoot::kEmptyString);
599 return *
reinterpret_cast<Isolate**
>(&
value_[kIsolateValueIndex]);
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);
static constexpr int kReturnValueIndex
static constexpr int kArgsLength
internal::Address length_
internal::Address * implicit_args_
V8_INLINE ReturnValue< T > GetReturnValue() const
V8_INLINE FunctionCallbackInfo(internal::Address *implicit_args, internal::Address *values, int length)
static constexpr int kContextIndex
static constexpr int kTargetIndex
static constexpr int kUnusedIndex
internal::Address * values_
V8_INLINE Local< Object > This() const
static constexpr int kIsolateIndex
static constexpr int kThisValuesIndex
V8_INLINE Local< Value > operator[](int i) const
V8_INLINE Isolate * GetIsolate() const
static constexpr int kSize
static constexpr int kLengthOffset
V8_INLINE Local< Value > NewTarget() const
static constexpr int kValuesOffset
V8_INLINE Local< Value > Data() const
static constexpr int kNewTargetIndex
V8_INLINE bool IsConstructCall() const
static constexpr int kArgsLengthWithReceiver
static constexpr int kImplicitArgsOffset
V8_INLINE int Length() const
static Local< Integer > New(Isolate *isolate, int32_t value)
static Local< Integer > NewFromUnsigned(Isolate *isolate, uint32_t value)
static V8_INLINE Local< T > New(Isolate *isolate, Local< T > that)
static V8_INLINE Local< T > FromSlot(internal::Address *slot)
static Local< Number > New(Isolate *isolate, double value)
V8_INLINE Local< Value > Data() const
static constexpr int kReturnValueIndex
friend class internal::PropertyCallbackArguments
static constexpr int kIsolateIndex
static constexpr int kDataIndex
static constexpr int kArgsLength
static constexpr int kShouldThrowOnErrorIndex
static constexpr int kHolderV2Index
V8_INLINE bool ShouldThrowOnError() const
static constexpr int kThisIndex
static constexpr int kHolderIndex
static constexpr int kPropertyKeyIndex
V8_DEPRECATE_SOON("V8 will stop providing access to hidden prototype (i.e. " "JSGlobalObject). Use HolderV2() instead. \n" "DO NOT try to workaround this by accessing JSGlobalObject via " "v8::Object::GetPrototype() - it'll be deprecated soon too. \n" "See http://crbug.com/333672197. ") V8_INLINE Local< Object > Holder() const
V8_INLINE ReturnValue< T > GetReturnValue() const
static constexpr int kSize
V8_INLINE Local< Object > HolderV2() const
internal::Address args_[kArgsLength]
friend void internal::PrintPropertyCallbackInfo(void *)
friend class MacroAssembler
V8_INLINE Local< Object > This() const
V8_INLINE Isolate * GetIsolate() const
V8_INLINE void Set(const BasicTracedReference< S > &handle)
V8_INLINE void SetNonEmpty(const Global< S > &handle)
V8_INLINE void SetDefaultValue()
V8_INLINE void SetFalse()
V8_INLINE void SetEmptyString()
V8_INLINE void SetNonEmpty(const Local< S > handle)
V8_INLINE void SetInternal(internal::Address value)
static constexpr int kIsolateValueIndex
V8_INLINE void Set(const Global< S > &handle)
V8_INLINE Local< Value > Get() const
V8_INLINE void Set(const Local< S > handle)
internal::Address * value_
V8_INLINE void SetNonEmpty(const BasicTracedReference< S > &handle)
V8_INLINE Isolate * GetIsolate() const
V8_INLINE ReturnValue(const ReturnValue< S > &that)
V8_INLINE void Set(S *whatever)
V8_INLINE void SetUndefined()
static constexpr std::optional< Address > TryIntegralToSmi(T value)
static V8_INLINE T * SlotAsValue(S *slot)
ZoneVector< RpoNumber > & result
i::Address ConvertToJSGlobalProxyIfNecessary(i::Address holder_ptr)
V8_EXPORT v8::Local< v8::Value > GetFunctionTemplateData(v8::Isolate *isolate, v8::Local< v8::Data > raw_target)
const int kApiSystemPointerSize
void VerifyHandleIsNonEmpty(bool is_empty)
V8_INLINE void PerformCastCheck(T *data)
void PrintFunctionCallbackInfo(void *function_callback_info)
V8_EXPORT bool ShouldThrowOnError(internal::Isolate *isolate)
V8_INLINE Local< Primitive > Undefined(Isolate *isolate)
void(*)(const FunctionCallbackInfo< Value > &info) FunctionCallback
#define I(name, number_of_args, result_size)
#define V8_UNLIKELY(condition)
std::unique_ptr< ValueMirror > value