5#ifndef INCLUDE_V8_FAST_API_CALLS_H_
6#define INCLUDE_V8_FAST_API_CALLS_H_
226#include <type_traits>
270 static constexpr Type kCallbackOptionsType =
Type(255);
273 "There is no special support in V8 anymore, there is no need to"
274 "use a SequenceType") SequenceType : uint8_t {
282 kAllowSharedBit = 1 << 0,
283 kEnforceRangeBit = 1 << 1,
285 kIsRestrictedBit = 1 << 3,
289 :
type_(type), sequence_type_(SequenceType::kScalar),
flags_(flags) {}
294 :
type_(type), sequence_type_(sequence_type),
flags_(flags) {}
299 static_cast<SequenceType>((
identifier >> 8) & 255),
302 return static_cast<uint8_t
>(
type_) << 16 |
303 static_cast<uint8_t
>(sequence_type_) << 8 |
304 static_cast<uint8_t
>(
flags_);
309 constexpr SequenceType GetSequenceType()
const {
return sequence_type_; }
313 return type == Type::kUint8 || type == Type::kInt32 ||
314 type == Type::kUint32 || type == Type::kInt64 ||
315 type == Type::kUint64;
319 return type == Type::kFloat32 || type == Type::kFloat64;
323 return IsIntegralType(type) || IsFloatingPointType(type) ||
353 Int64Representation repr = Int64Representation::kNumber);
360 return HasOptions() ? arg_count_ - 1 : arg_count_;
369 const CTypeInfo& ArgumentInfo(
unsigned int index)
const;
373 return arg_count_ > 0 && arg_info_[arg_count_ - 1].GetType() ==
374 CTypeInfo::kCallbackOptionsType;
390#if defined(V8_ENABLE_LOCAL_OFF_STACK_CHECK) && V8_HAS_ATTRIBUTE_TRIVIAL_ABI
394 AnyCType& operator=(
const AnyCType& other) {
395 int64_value = other.int64_value;
416 "The union AnyCType should have size == 64 bits, as this is assumed "
417 "by EffectControlLinearizer.");
421 constexpr CFunction() : address_(nullptr), type_info_(nullptr) {}
426 return type_info_->ArgumentInfo(index);
433 return type_info_->GetInt64Representation();
439 template <
typename F>
442 CFunctionInfo::Int64Representation::kNumber) {
444 result.GetInt64Representation();
449 template <
typename R,
typename... Args,
typename R_Patch,
450 typename... Args_Patch>
452 R_Patch (*patching_func)(Args_Patch...),
454 CFunctionInfo::Int64Representation::kNumber) {
457 sizeof...(Args_Patch) ==
sizeof...(Args),
458 "The patching function must have the same number of arguments.");
459 c_func.
address_ =
reinterpret_cast<void*
>(patching_func);
469 template <
typename F>
471 static_assert(
sizeof(
F) !=
sizeof(
F),
472 "CFunction must be created from a function pointer.");
475 template <
typename R,
typename... Args>
478 static CFunction Make(R (*func)(Args...),
480 CFunctionInfo::Int64Representation::kNumber);
510template <
typename T,
typename... List>
511struct count : std::integral_constant<int, 0> {};
512template <
typename T,
typename... Args>
514 : std::integral_constant<std::size_t, 1 + count<T, Args...>::value> {};
515template <
typename T,
typename U,
typename... Args>
519 typename RetBuilder,
typename... ArgBuilders>
526 "Only one options parameter is supported.");
529 "The receiver or the options argument is missing.");
547 "String and api object values are not currently "
548 "supported return types.");
557 static_assert(
sizeof(
T) !=
sizeof(
T),
"This type is not supported");
560#define SPECIALIZE_GET_TYPE_INFO_HELPER_FOR(T, Enum) \
562 struct TypeInfoHelper<T> { \
563 static constexpr CTypeInfo::Flags Flags() { \
564 return CTypeInfo::Flags::kNone; \
567 static constexpr CTypeInfo::Type Type() { return CTypeInfo::Type::Enum; } \
570template <CTypeInfo::Type type>
573#define DEFINE_TYPE_INFO_TRAITS(CType, Enum) \
575 struct CTypeInfoTraits<CTypeInfo::Type::Enum> { \
576 using ctype = CType; \
579#define PRIMITIVE_C_TYPES(V) \
583 V(uint32_t, kUint32) \
585 V(uint64_t, kUint64) \
587 V(double, kFloat64) \
591#define ALL_C_TYPES(V) \
592 PRIMITIVE_C_TYPES(V) \
594 V(v8::Local<v8::Value>, kV8Value) \
595 V(v8::Local<v8::Object>, kV8Value) \
596 V(v8::Local<v8::Array>, kV8Value) \
606#undef PRIMITIVE_C_TYPES
609#undef TYPED_ARRAY_C_TYPES
629#define STATIC_ASSERT_IMPLIES(COND, ASSERTION, MSG) \
630 static_assert(((COND) == 0) || (ASSERTION), MSG)
645 uint8_t(kFlags) & uint8_t(CTypeInfo::Flags::kEnforceRangeBit),
646 CTypeInfo::IsIntegralType(kType),
647 "kEnforceRangeBit is only allowed for integral types.");
649 uint8_t(kFlags) & uint8_t(CTypeInfo::Flags::kClampBit),
650 CTypeInfo::IsIntegralType(kType),
651 "kClampBit is only allowed for integral types.");
653 uint8_t(kFlags) & uint8_t(CTypeInfo::Flags::kIsRestrictedBit),
654 CTypeInfo::IsFloatingPointType(kType),
655 "kIsRestrictedBit is only allowed for floating point types.");
662 template <
typename... Rest>
671template <
typename RetBuilder,
typename... ArgBuilders>
680 ArgBuilders...>(
fn_);
688 std::make_index_sequence<
sizeof...(ArgBuilders)>());
692 template <
typename Ret,
typename... Args>
695 sizeof...(Args) ==
sizeof...(ArgBuilders),
696 "The patching function must have the same number of arguments.");
697 fn_ =
reinterpret_cast<void*
>(patching_func);
718 typename std::tuple_element<
N, std::tuple<ArgBuilders...>>
::type;
726 typename std::tuple_element<
N,
727 std::tuple<ArgBuilders...>>::type::BaseType,
728 std::tuple_element<
N, std::tuple<ArgBuilders...>>::type::Build()
737 constexpr auto ArgImpl(std::index_sequence<I...>) {
749 template <
typename R,
typename... Args>
750 constexpr auto Fn(R (*
fn)(Args...)) {
753 reinterpret_cast<const void*
>(
fn));
760template <
typename R,
typename... Args>
768 .template Build<CFunctionInfo::Int64Representation::kBigInt>();
789template <CTypeInfo::Identifier type_info_
id,
typename T>
795TryToCopyAndConvertArrayToCppBuffer<CTypeInfoBuilder<int32_t>::Build().GetId(),
797 uint32_t max_length);
801TryToCopyAndConvertArrayToCppBuffer<CTypeInfoBuilder<uint32_t>::Build().GetId(),
803 uint32_t max_length);
807TryToCopyAndConvertArrayToCppBuffer<CTypeInfoBuilder<float>::Build().GetId(),
809 uint32_t max_length);
813TryToCopyAndConvertArrayToCppBuffer<CTypeInfoBuilder<double>::Build().GetId(),
815 uint32_t max_length);
Int64Representation GetInt64Representation() const
const CTypeInfo * arg_info_
const CTypeInfo & ReturnInfo() const
const Int64Representation repr_
const CTypeInfo return_info_
const unsigned int arg_count_
unsigned int ArgumentCount() const
const CTypeInfo & ReturnInfo() const
const CTypeInfo & ArgumentInfo(unsigned int index) const
unsigned int ArgumentCount() const
CFunctionInfo::Int64Representation GetInt64Representation() const
static CFunction Make(R(*func)(Args...), R_Patch(*patching_func)(Args_Patch...), CFunctionInfo::Int64Representation int64_rep=CFunctionInfo::Int64Representation::kNumber)
const void * GetAddress() const
const CFunctionInfo * GetTypeInfo() const
static CFunction Make(F *func, CFunctionInfo::Int64Representation int64_rep=CFunctionInfo::Int64Representation::kNumber)
const CFunctionInfo * type_info_
static constexpr CTypeInfo Build()
static constexpr CTypeInfo::Flags MergeFlags(CTypeInfo::Flags flags, Rest... rest)
static constexpr CTypeInfo::Flags MergeFlags()
SequenceType sequence_type_
constexpr CTypeInfo(Type type, Flags flags=Flags::kNone)
static constexpr bool IsFloatingPointType(Type type)
static constexpr bool IsPrimitive(Type type)
static constexpr Type kCallbackOptionsType
static constexpr bool IsIntegralType(Type type)
constexpr Identifier GetId() const
constexpr Type GetType() const
constexpr Flags GetFlags() const
constexpr CTypeInfo(Identifier identifier)
constexpr CFunctionBuilderWithFunction(const void *fn)
constexpr auto ArgImpl(std::index_sequence< I... >)
auto Patch(Ret(*patching_func)(Args...))
constexpr CFunctionBuilder()
constexpr auto Fn(R(*fn)(Args...))
constexpr CFunctionInfoImpl()
static constexpr int kReceiverCount
const CTypeInfo arg_info_storage_[sizeof...(ArgBuilders)]
static constexpr int kOptionsArgCount
ZoneVector< RpoNumber > & result
V8_EXPORT_PRIVATE base::Vector< Flag > Flags()
static constexpr CTypeInfo kTypeInfoFloat64
static constexpr CTypeInfo kTypeInfoInt32
bool V8_EXPORT TryToCopyAndConvertArrayToCppBuffer(Local< Array > src, T *dst, uint32_t max_length)
v8::Local< v8::Value > data
static FastApiCallbackOptions CreateForTesting(Isolate *isolate)
typename std::tuple_element< N, std::tuple< ArgBuilders... > >::type type
static constexpr CTypeInfo::Type Type()
static constexpr CTypeInfo::Flags Flags()
static constexpr CTypeInfo::Flags Flags()
static constexpr CTypeInfo::Type Type()
FastApiCallbackOptions * options_value
const FastOneByteString * string_value
Local< Array > sequence_value
Local< Object > object_value
#define DEFINE_TYPE_INFO_TRAITS(CType, Enum)
#define PRIMITIVE_C_TYPES(V)
#define SPECIALIZE_GET_TYPE_INFO_HELPER_FOR(T, Enum)
#define STATIC_ASSERT_IMPLIES(COND, ASSERTION, MSG)
#define V8_DEPRECATE_SOON(message)
#define END_ALLOW_USE_DEPRECATED()
#define V8_WARN_UNUSED_RESULT
#define START_ALLOW_USE_DEPRECATED()