5#ifndef INCLUDE_V8_FUNCTION_CALLBACK_H_
6#define INCLUDE_V8_FUNCTION_CALLBACK_H_
26class FunctionCallbackArguments;
27class PropertyCallbackArguments;
32class ConsoleCallArguments;
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;
118class FunctionCallbackInfo {
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;
168 static_assert(ReturnValue<Value>::kIsolateValueIndex ==
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
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);
520void ReturnValue<T>::SetDefaultValue() {
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
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
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
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
591 SetInternal(I::StaticReadOnlyRoot::kEmptyString);
593 *value_ = I::GetRoot(
GetIsolate(), I::kEmptyStringRootIndex);
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) {}
624 return Local<Value>::FromSlot(values_ + i);
630 return Local<Object>::FromSlot(values_ + kThisValuesIndex);
635 return Local<Value>::FromSlot(&implicit_args_[kNewTargetIndex]);
640 auto target = Local<v8::Data>::FromSlot(&implicit_args_[kTargetIndex]);
646 return *
reinterpret_cast<Isolate**
>(&implicit_args_[kIsolateIndex]);
661 return static_cast<int>(length_);
666 return *
reinterpret_cast<Isolate**
>(&args_[kIsolateIndex]);
671 return Local<Value>::FromSlot(&args_[kDataIndex]);
676 return Local<Object>::FromSlot(&args_[kThisIndex]);
681 return Local<Object>::FromSlot(&args_[kHolderIndex]);
684namespace api_internal {
694 if (!I::HasHeapObjectTag(args_[kHolderV2Index])) {
695 args_[kHolderV2Index] =
698 return Local<Object>::FromSlot(&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()));
V8_INLINE ReturnValue< T > GetReturnValue() const
V8_INLINE bool IsConstructCall() const
V8_INLINE Local< Object > This() const
V8_INLINE Isolate * GetIsolate() const
V8_INLINE Local< Value > Data() const
V8_INLINE int Length() const
friend class debug::ConsoleCallArguments
V8_INLINE Local< Value > NewTarget() const
friend class internal::FunctionCallbackArguments
V8_INLINE Local< Value > operator[](int i) 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 Local< Number > New(Isolate *isolate, double value)
V8_INLINE ReturnValue< Value > GetReturnValue() const
friend class internal::PropertyCallbackArguments
V8_INLINE Local< Object > This() const
V8_INLINE Isolate * GetIsolate() const
V8_INLINE Local< Value > Data() const
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
friend class PropertyCallbackInfo
V8_INLINE bool ShouldThrowOnError() const
friend void internal::PrintPropertyCallbackInfo(void *)
V8_INLINE Local< Object > HolderV2() const
friend class MacroAssembler
friend class PersistentValueMapBase
V8_INLINE ReturnValue(const ReturnValue< S > &that)
V8_INLINE Isolate * GetIsolate() const
V8_INLINE void SetFalse()
friend class PropertyCallbackInfo
V8_INLINE void SetNonEmpty(const Local< S > handle)
V8_INLINE void Set(const BasicTracedReference< S > &handle)
friend class FunctionCallbackInfo
V8_INLINE void SetUndefined()
V8_INLINE void SetNonEmpty(const Global< S > &handle)
V8_INLINE void Set(const Global< S > &handle)
V8_INLINE void SetEmptyString()
V8_INLINE void SetNonEmpty(const BasicTracedReference< S > &handle)
V8_INLINE void Set(const Local< S > handle)
V8_INLINE void Set(S *whatever)
V8_INLINE Local< Value > Get() const
V8_INLINE internal::Address ptr() const
V8_INLINE bool IsEmpty() const
static constexpr std::optional< Address > TryIntegralToSmi(T value)
static V8_INLINE T * SlotAsValue(S *slot)
V8_EXPORT v8::Local< v8::Value > GetFunctionTemplateData(v8::Isolate *isolate, v8::Local< v8::Data > raw_target)
V8_EXPORT internal::Address ConvertToJSGlobalProxyIfNecessary(internal::Address holder)
const int kApiSystemPointerSize
V8_EXPORT void VerifyHandleIsNonEmpty(bool is_empty)
void PrintFunctionCallbackInfo(void *function_callback_info)
V8_INLINE void PerformCastCheck(T *data)
V8_EXPORT bool ShouldThrowOnError(internal::Isolate *isolate)
void(*)(const FunctionCallbackInfo< Value > &info) FunctionCallback
V8_INLINE Local< Primitive > Undefined(Isolate *isolate)
#define V8_UNLIKELY(condition)