5#ifndef INCLUDE_V8_FUNCTION_CALLBACK_H_
6#define INCLUDE_V8_FUNCTION_CALLBACK_H_
18class BasicTracedReference;
25class FunctionCallbackArguments;
26class PropertyCallbackArguments;
31class ConsoleCallArguments;
39 static_assert(std::is_base_of<T, S>::value,
"type check");
83 template <
class F,
class G,
class H>
97 static constexpr int kIsolateValueIndex = -2;
147 static constexpr int kHolderIndex = 0;
148 static constexpr int kIsolateIndex = 1;
149 static constexpr int kUnusedIndex = 2;
150 static constexpr int kReturnValueIndex = 3;
151 static constexpr int kDataIndex = 4;
152 static constexpr int kNewTargetIndex = 5;
153 static constexpr int kArgsLength = 6;
155 static constexpr int kArgsLengthWithReceiver = kArgsLength + 1;
159 static constexpr int kImplicitArgsOffset = 0;
160 static constexpr int kValuesOffset =
162 static constexpr int kLengthOffset =
165 static constexpr int kThisValuesIndex = -1;
167 kIsolateIndex - kReturnValueIndex);
272 static constexpr int kShouldThrowOnErrorIndex = 0;
273 static constexpr int kHolderIndex = 1;
274 static constexpr int kIsolateIndex = 2;
275 static constexpr int kUnusedIndex = 3;
276 static constexpr int kReturnValueIndex = 4;
277 static constexpr int kDataIndex = 5;
278 static constexpr int kThisIndex = 6;
279 static constexpr int kArgsLength = 7;
297void ReturnValue<T>::SetInternal(internal::Address value) {
298#if V8_STATIC_ROOTS_BOOL
299 using I = internal::Internals;
304 *value_ = I::DecompressTaggedField(*value_, I::CompressTagged(value));
313 static_assert(std::is_base_of<T, S>::value,
"type check");
317 SetInternal(handle.
ptr());
324 static_assert(std::is_base_of<T, S>::value,
"type check");
325#ifdef V8_ENABLE_CHECKS
326 internal::VerifyHandleIsNonEmpty(handle.
IsEmpty());
328 SetInternal(handle.
ptr());
334 static_assert(std::is_base_of<T, S>::value,
"type check");
338 SetInternal(handle.
ptr());
345 static_assert(std::is_base_of<T, S>::value,
"type check");
346#ifdef V8_ENABLE_CHECKS
347 internal::VerifyHandleIsNonEmpty(handle.
IsEmpty());
349 SetInternal(handle.
ptr());
355 static_assert(std::is_void<T>::value || std::is_base_of<T, S>::value,
360 SetInternal(handle.
ptr());
367 static_assert(std::is_void<T>::value || std::is_base_of<T, S>::value,
369#ifdef V8_ENABLE_CHECKS
370 internal::VerifyHandleIsNonEmpty(handle.
IsEmpty());
372 SetInternal(handle.
ptr());
377 static_assert(std::is_base_of<T, Number>::value,
"type check");
378 SetNonEmpty(Number::New(GetIsolate(), i));
383 static_assert(std::is_base_of<T, Integer>::value,
"type check");
386 SetInternal(I::IntToSmi(i));
389 SetNonEmpty(Integer::New(GetIsolate(), i));
394 static_assert(std::is_base_of<T, Integer>::value,
"type check");
396 bool fits_into_int32_t = (i & (1U << 31)) == 0;
398 Set(
static_cast<int32_t
>(i));
401 SetNonEmpty(Integer::NewFromUnsigned(GetIsolate(), i));
406 static_assert(std::is_base_of<T, Integer>::value,
"type check");
408 static_assert(I::IsValidSmi(std::numeric_limits<uint16_t>::min()));
409 static_assert(I::IsValidSmi(std::numeric_limits<uint16_t>::max()));
410 SetInternal(I::IntToSmi(i));
415 static_assert(std::is_base_of<T, Boolean>::value,
"type check");
417#if V8_STATIC_ROOTS_BOOL
418#ifdef V8_ENABLE_CHECKS
419 internal::PerformCastCheck(
420 internal::ValueHelper::SlotAsValue<Value, true>(value_));
422 SetInternal(value ? I::StaticReadOnlyRoot::kTrueValue
423 : I::StaticReadOnlyRoot::kFalseValue);
427 root_index = I::kTrueValueRootIndex;
429 root_index = I::kFalseValueRootIndex;
431 *value_ = I::GetRoot(GetIsolate(), root_index);
438#if V8_STATIC_ROOTS_BOOL
439 SetInternal(I::StaticReadOnlyRoot::kTheHoleValue);
441 *value_ = I::GetRoot(GetIsolate(), I::kTheHoleValueRootIndex);
447 static_assert(std::is_base_of<T, Primitive>::value,
"type check");
449#if V8_STATIC_ROOTS_BOOL
450#ifdef V8_ENABLE_CHECKS
451 internal::PerformCastCheck(
452 internal::ValueHelper::SlotAsValue<Value, true>(value_));
454 SetInternal(I::StaticReadOnlyRoot::kNullValue);
456 *value_ = I::GetRoot(GetIsolate(), I::kNullValueRootIndex);
462 static_assert(std::is_base_of<T, Primitive>::value,
"type check");
464#if V8_STATIC_ROOTS_BOOL
465#ifdef V8_ENABLE_CHECKS
466 internal::PerformCastCheck(
467 internal::ValueHelper::SlotAsValue<Value, true>(value_));
469 SetInternal(I::StaticReadOnlyRoot::kUndefinedValue);
471 *value_ = I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex);
477 static_assert(std::is_base_of<T, String>::value,
"type check");
479#if V8_STATIC_ROOTS_BOOL
480#ifdef V8_ENABLE_CHECKS
481 internal::PerformCastCheck(
482 internal::ValueHelper::SlotAsValue<Value, true>(value_));
484 SetInternal(I::StaticReadOnlyRoot::kEmptyString);
486 *value_ = I::GetRoot(GetIsolate(), I::kEmptyStringRootIndex);
492 return *
reinterpret_cast<Isolate**
>(&value_[kIsolateValueIndex]);
498#if V8_STATIC_ROOTS_BOOL
499 if (I::is_identical(*value_, I::StaticReadOnlyRoot::kTheHoleValue)) {
501 if (*value_ == I::GetRoot(GetIsolate(), I::kTheHoleValueRootIndex)) {
506 internal::ValueHelper::SlotAsValue<Value>(value_));
512 static_assert(
sizeof(S) < 0,
"incompilable to prevent inadvertent misuse");
519 : implicit_args_(implicit_args), values_(values), length_(length) {}
524 if (i < 0 || length_ <= i)
return Undefined(GetIsolate());
551 return *
reinterpret_cast<Isolate**
>(&implicit_args_[kIsolateIndex]);
561 return !NewTarget()->IsUndefined();
571 return *
reinterpret_cast<Isolate**
>(&args_[kIsolateIndex]);
597 if (args_[kShouldThrowOnErrorIndex] !=
598 I::IntToSmi(I::kInferShouldThrowMode)) {
599 return args_[kShouldThrowOnErrorIndex] != I::IntToSmi(I::kDontThrow);
602 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 Local< Object > Holder() 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
V8_INLINE ReturnValue< T > GetReturnValue() const
friend class internal::PropertyCallbackArguments
V8_INLINE Local< Object > This() const
V8_INLINE Local< Object > Holder() const
V8_INLINE Isolate * GetIsolate() const
V8_INLINE Local< Value > Data() const
V8_INLINE bool ShouldThrowOnError() const
friend class MacroAssembler
V8_INLINE ReturnValue(const ReturnValue< S > &that)
V8_INLINE Isolate * GetIsolate() const
V8_INLINE void SetNonEmpty(const Local< S > handle)
V8_INLINE void Set(const BasicTracedReference< S > &handle)
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
const int kApiSystemPointerSize
V8_EXPORT bool ShouldThrowOnError(internal::Isolate *isolate)
void(*)(const FunctionCallbackInfo< Value > &info) FunctionCallback
V8_INLINE Local< Primitive > Undefined(Isolate *isolate)
#define V8_LIKELY(condition)
#define V8_UNLIKELY(condition)