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);
274 template <
typename U>
281 static constexpr int kPropertyKeyIndex = 0;
282 static constexpr int kShouldThrowOnErrorIndex = 1;
284 static constexpr int kHolderIndex = 2;
285 static constexpr int kIsolateIndex = 3;
286 static constexpr int kHolderV2Index = 4;
287 static constexpr int kReturnValueIndex = 5;
288 static constexpr int kDataIndex = 6;
289 static constexpr int kThisIndex = 7;
290 static constexpr int kArgsLength = 8;
307void ReturnValue<T>::SetInternal(internal::Address value) {
308#if V8_STATIC_ROOTS_BOOL
309 using I = internal::Internals;
314 *value_ = I::DecompressTaggedField(*value_, I::CompressTagged(value));
323 static_assert(std::is_base_of_v<T, S>,
"type check");
327 SetInternal(handle.
ptr());
334 static_assert(std::is_base_of_v<T, S>,
"type check");
335#ifdef V8_ENABLE_CHECKS
336 internal::VerifyHandleIsNonEmpty(handle.
IsEmpty());
338 SetInternal(handle.
ptr());
344 static_assert(std::is_base_of_v<T, S>,
"type check");
348 SetInternal(handle.
ptr());
355 static_assert(std::is_base_of_v<T, S>,
"type check");
356#ifdef V8_ENABLE_CHECKS
357 internal::VerifyHandleIsNonEmpty(handle.
IsEmpty());
359 SetInternal(handle.
ptr());
366#ifdef V8_IMMINENT_DEPRECATION_WARNINGS
367 static constexpr bool is_allowed_void =
false;
368 static_assert(!std::is_void_v<T>,
369 "ReturnValue<void>::Set(const Local<S>) is deprecated. "
370 "Do nothing to indicate that the operation succeeded or use "
371 "SetFalse() to indicate that the operation failed (don't "
372 "forget to handle info.ShouldThrowOnError()). "
373 "See http://crbug.com/348660658 for details.");
375 static constexpr bool is_allowed_void = std::is_void_v<T>;
377 static_assert(is_allowed_void || std::is_base_of_v<T, S>,
"type check");
380 }
else if constexpr (is_allowed_void) {
383 Set(handle->BooleanValue(GetIsolate()));
385 SetInternal(handle.
ptr());
393#ifdef V8_IMMINENT_DEPRECATION_WARNINGS
394 static constexpr bool is_allowed_void =
false;
395 static_assert(!std::is_void_v<T>,
396 "ReturnValue<void>::SetNonEmpty(const Local<S>) is deprecated. "
397 "Do nothing to indicate that the operation succeeded or use "
398 "SetFalse() to indicate that the operation failed (don't "
399 "forget to handle info.ShouldThrowOnError()). "
400 "See http://crbug.com/348660658 for details.");
402 static constexpr bool is_allowed_void = std::is_void_v<T>;
404 static_assert(is_allowed_void || std::is_base_of_v<T, S>,
"type check");
405#ifdef V8_ENABLE_CHECKS
406 internal::VerifyHandleIsNonEmpty(handle.
IsEmpty());
408 if constexpr (is_allowed_void) {
411 Set(handle->BooleanValue(GetIsolate()));
413 SetInternal(handle.
ptr());
419 static_assert(std::is_base_of_v<T, Number>,
"type check");
420 SetNonEmpty(Number::New(GetIsolate(), i));
425 static_assert(std::is_base_of_v<T, Integer>,
"type check");
427 static_assert(I::IsValidSmi(std::numeric_limits<int16_t>::min()));
428 static_assert(I::IsValidSmi(std::numeric_limits<int16_t>::max()));
429 SetInternal(I::IntegralToSmi(i));
434 static_assert(std::is_base_of_v<T, Integer>,
"type check");
435 if (
const auto result = internal::Internals::TryIntegralToSmi(i)) {
436 SetInternal(*result);
439 SetNonEmpty(Integer::New(GetIsolate(), i));
444 static_assert(std::is_base_of_v<T, Integer>,
"type check");
445 if (
const auto result = internal::Internals::TryIntegralToSmi(i)) {
446 SetInternal(*result);
449 SetNonEmpty(Number::New(GetIsolate(),
static_cast<double>(i)));
454 static_assert(std::is_base_of_v<T, Integer>,
"type check");
456 static_assert(I::IsValidSmi(std::numeric_limits<uint16_t>::min()));
457 static_assert(I::IsValidSmi(std::numeric_limits<uint16_t>::max()));
458 SetInternal(I::IntegralToSmi(i));
463 static_assert(std::is_base_of_v<T, Integer>,
"type check");
464 if (
const auto result = internal::Internals::TryIntegralToSmi(i)) {
465 SetInternal(*result);
468 SetNonEmpty(Integer::NewFromUnsigned(GetIsolate(), i));
473 static_assert(std::is_base_of_v<T, Integer>,
"type check");
474 if (
const auto result = internal::Internals::TryIntegralToSmi(i)) {
475 SetInternal(*result);
478 SetNonEmpty(Number::New(GetIsolate(),
static_cast<double>(i)));
483 static_assert(std::is_void_v<T> || std::is_base_of_v<T, Boolean>,
486#if V8_STATIC_ROOTS_BOOL
487#ifdef V8_ENABLE_CHECKS
488 internal::PerformCastCheck(
489 internal::ValueHelper::SlotAsValue<Value, true>(value_));
491 SetInternal(value ? I::StaticReadOnlyRoot::kTrueValue
492 : I::StaticReadOnlyRoot::kFalseValue);
496 root_index = I::kTrueValueRootIndex;
498 root_index = I::kFalseValueRootIndex;
500 *value_ = I::GetRoot(GetIsolate(), root_index);
507 if constexpr (std::is_same_v<void, T> || std::is_same_v<v8::Boolean, T>) {
509 }
else if constexpr (std::is_same_v<v8::Integer, T>) {
510 SetInternal(I::IntegralToSmi(0));
512 static_assert(std::is_same_v<v8::Value, T> || std::is_same_v<v8::Array, T>);
513#if V8_STATIC_ROOTS_BOOL
514 SetInternal(I::StaticReadOnlyRoot::kUndefinedValue);
516 *value_ = I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex);
523 static_assert(std::is_base_of_v<T, Primitive>,
"type check");
525#if V8_STATIC_ROOTS_BOOL
526#ifdef V8_ENABLE_CHECKS
527 internal::PerformCastCheck(
528 internal::ValueHelper::SlotAsValue<Value, true>(value_));
530 SetInternal(I::StaticReadOnlyRoot::kNullValue);
532 *value_ = I::GetRoot(GetIsolate(), I::kNullValueRootIndex);
538 static_assert(std::is_base_of_v<T, Primitive>,
"type check");
540#if V8_STATIC_ROOTS_BOOL
541#ifdef V8_ENABLE_CHECKS
542 internal::PerformCastCheck(
543 internal::ValueHelper::SlotAsValue<Value, true>(value_));
545 SetInternal(I::StaticReadOnlyRoot::kUndefinedValue);
547 *value_ = I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex);
553 static_assert(std::is_void_v<T> || std::is_base_of_v<T, Boolean>,
556#if V8_STATIC_ROOTS_BOOL
557#ifdef V8_ENABLE_CHECKS
558 internal::PerformCastCheck(
559 internal::ValueHelper::SlotAsValue<Value, true>(value_));
561 SetInternal(I::StaticReadOnlyRoot::kFalseValue);
563 *value_ = I::GetRoot(GetIsolate(), I::kFalseValueRootIndex);
569 static_assert(std::is_base_of_v<T, String>,
"type check");
571#if V8_STATIC_ROOTS_BOOL
572#ifdef V8_ENABLE_CHECKS
573 internal::PerformCastCheck(
574 internal::ValueHelper::SlotAsValue<Value, true>(value_));
576 SetInternal(I::StaticReadOnlyRoot::kEmptyString);
578 *value_ = I::GetRoot(GetIsolate(), I::kEmptyStringRootIndex);
584 return *
reinterpret_cast<Isolate**
>(&value_[kIsolateValueIndex]);
590 internal::ValueHelper::SlotAsValue<Value>(value_));
596 static_assert(
sizeof(S) < 0,
"incompilable to prevent inadvertent misuse");
603 : implicit_args_(implicit_args), values_(values), length_(length) {}
608 if (i < 0 || Length() <= i)
return Undefined(GetIsolate());
631 return *
reinterpret_cast<Isolate**
>(&implicit_args_[kIsolateIndex]);
641 return !NewTarget()->IsUndefined();
646 return static_cast<int>(length_);
651 return *
reinterpret_cast<Isolate**
>(&args_[kIsolateIndex]);
664namespace api_internal {
674 if (!I::HasHeapObjectTag(args_[kHolderV2Index])) {
675 args_[kHolderV2Index] =
689 if (args_[kShouldThrowOnErrorIndex] !=
690 I::IntegralToSmi(I::kInferShouldThrowMode)) {
691 return args_[kShouldThrowOnErrorIndex] != I::IntegralToSmi(I::kDontThrow);
694 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:635
Local< Object > This() const
Definition: v8-function-callback.h:613
Local< Value > operator[](int i) const
Definition: v8-function-callback.h:606
Isolate * GetIsolate() const
Definition: v8-function-callback.h:630
Local< Value > NewTarget() const
Definition: v8-function-callback.h:619
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:624
bool IsConstructCall() const
Definition: v8-function-callback.h:640
int Length() const
Definition: v8-function-callback.h:645
Definition: v8-persistent-handle.h:349
Definition: v8-isolate.h:291
Definition: v8-local-handle.h:366
Definition: v8-util.h:166
Definition: v8-function-callback.h:187
Local< Value > Data() const
Definition: v8-function-callback.h:655
friend class internal::PropertyCallbackArguments
Definition: v8-function-callback.h:277
friend class PropertyCallbackInfo
Definition: v8-function-callback.h:275
bool ShouldThrowOnError() const
Definition: v8-function-callback.h:687
ReturnValue< T > GetReturnValue() const
Definition: v8-function-callback.h:682
Local< Object > HolderV2() const
Definition: v8-function-callback.h:672
friend class MacroAssembler
Definition: v8-function-callback.h:276
Local< Object > This() const
Definition: v8-function-callback.h:660
Isolate * GetIsolate() const
Definition: v8-function-callback.h:650
Definition: v8-function-callback.h:41
void SetFalse()
Definition: v8-function-callback.h:552
void SetEmptyString()
Definition: v8-function-callback.h:568
friend class ReturnValue
Definition: v8-function-callback.h:88
ReturnValue(const ReturnValue< S > &that)
Definition: v8-function-callback.h:44
void SetNonEmpty(const Global< S > &handle)
Definition: v8-function-callback.h:333
Local< Value > Get() const
Definition: v8-function-callback.h:588
void SetNull()
Definition: v8-function-callback.h:522
Isolate * GetIsolate() const
Definition: v8-function-callback.h:583
void SetUndefined()
Definition: v8-function-callback.h:537
Definition: v8-container.h:148
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
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 PrintPropertyCallbackInfo(void *property_callback_info)
bool ShouldThrowOnError(internal::Isolate *isolate)
uintptr_t Address
Definition: v8-internal.h:38
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:299
#define V8_EXPORT
Definition: v8config.h:855
#define V8_INLINE
Definition: v8config.h:508
#define V8_UNLIKELY(condition)
Definition: v8config.h:668