219 #ifndef INCLUDE_V8_FAST_API_CALLS_H_
220 #define INCLUDE_V8_FAST_API_CALLS_H_
226 #include <type_traits>
287 : type_(type), sequence_type_(sequence_type), flags_(flags) {}
293 static_cast<
Flags>(identifier & 255)
) {}
295 return static_cast<uint8_t>(type_) << 16 |
296 static_cast<uint8_t>(sequence_type_) << 8 |
297 static_cast<uint8_t>(flags_);
335 template <
typename T>
340 ValidateIndex(index);
343 memcpy(&tmp,
reinterpret_cast<T*>(data_) + index,
sizeof(T));
348 if (
reinterpret_cast<uintptr_t>(data_) %
alignof(T) != 0) {
351 *elements =
reinterpret_cast<T*>(data_);
406 return arg_count_ > 0 && arg_info_[arg_count_ - 1]
.GetType() ==
412 const unsigned int arg_count_;
444 "The AnyCType struct should have size == 64 bits, as this is assumed "
445 "by EffectControlLinearizer.");
449 constexpr CFunction() : address_(
nullptr), type_info_(
nullptr) {}
480 if (diff_index >= 0) {
498 template <
typename F>
500 return ArgUnwrap<F*>::Make(func);
504 template <
typename R,
typename... Args,
typename R_Patch,
505 typename... Args_Patch>
507 R_Patch (*patching_func)(Args_Patch...)) {
508 CFunction c_func = ArgUnwrap<R (*)(Args...)>::Make(func);
510 sizeof...(Args_Patch) ==
sizeof...(Args),
511 "The patching function must have the same number of arguments.");
512 c_func.address_ =
reinterpret_cast<
void*>(patching_func);
519 const void* address_;
522 template <
typename F>
524 static_assert(
sizeof(F) !=
sizeof(F),
525 "CFunction must be created from a function pointer.");
528 template <
typename R,
typename... Args>
529 class ArgUnwrap<R (*)(Args...)> {
531 static CFunction Make(R (*func)(Args...));
576 template <
typename T,
typename... List>
577 struct count : std::integral_constant<
int, 0> {};
578 template <
typename T,
typename... Args>
580 : std::integral_constant<std::size_t, 1 +
count<T, Args...>::value> {};
581 template <
typename T,
typename U,
typename... Args>
584 template <
typename RetBuilder,
typename... ArgBuilders>
586 static constexpr int kOptionsArgCount =
588 static constexpr int kReceiverCount = 1;
590 static_assert(kOptionsArgCount == 0 || kOptionsArgCount == 1,
591 "Only one options parameter is supported.");
593 static_assert(
sizeof...(ArgBuilders) >= kOptionsArgCount + kReceiverCount,
594 "The receiver or the options argument is missing.");
600 arg_info_storage_{ArgBuilders::Build()...} {
601 constexpr CTypeInfo::
Type kReturnType = RetBuilder::Build().GetType();
609 "64-bit int and api object values are not currently "
610 "supported return types.");
614 const CTypeInfo arg_info_storage_[
sizeof...(ArgBuilders)];
617 template <
typename T>
619 static_assert(
sizeof(T) !=
sizeof(T),
"This type is not supported");
622 #define SPECIALIZE_GET_TYPE_INFO_HELPER_FOR(T, Enum)
624 struct TypeInfoHelper<T> {
625 static constexpr CTypeInfo::Flags Flags() {
626 return CTypeInfo::Flags::kNone;
629 static constexpr CTypeInfo::Type Type() { return CTypeInfo::Type::Enum; }
630 static constexpr CTypeInfo::SequenceType SequenceType() {
631 return CTypeInfo::SequenceType::kScalar;
638 #define DEFINE_TYPE_INFO_TRAITS(CType, Enum)
640 struct CTypeInfoTraits<CTypeInfo::Type::Enum> {
644 #define PRIMITIVE_C_TYPES(V)
654 #define ALL_C_TYPES(V)
657 V(v8::Local<v8::Value>, kV8Value)
658 V(v8::Local<v8::Object>, kV8Value)
668 #undef PRIMITIVE_C_TYPES
671 #define SPECIALIZE_GET_TYPE_INFO_HELPER_FOR_TA(T, Enum)
673 struct TypeInfoHelper<const FastApiTypedArray<T>&> {
674 static constexpr CTypeInfo::Flags Flags() {
675 return CTypeInfo::Flags::kNone;
678 static constexpr CTypeInfo::Type Type() { return CTypeInfo::Type::Enum; }
679 static constexpr CTypeInfo::SequenceType SequenceType() {
680 return CTypeInfo::SequenceType::kIsTypedArray;
684 #define TYPED_ARRAY_C_TYPES(V)
694 #undef TYPED_ARRAY_C_TYPES
728 #define STATIC_ASSERT_IMPLIES(COND, ASSERTION, MSG)
729 static_assert(((COND) == 0
) || (ASSERTION), MSG)
749 "kAllowSharedBit is only allowed for TypedArrays and ArrayBuffers.");
753 "kEnforceRangeBit is only allowed for integral types.");
757 "kClampBit is only allowed for integral types.");
761 "kIsRestrictedBit is only allowed for floating point types.");
764 "Sequences are only supported from void type.");
768 "TypedArrays are only supported from primitive types or void.");
776 template <
typename... Rest>
779 return CTypeInfo::
Flags(uint8_t(flags) | uint8_t(MergeFlags(rest...)));
785 template <
typename RetBuilder,
typename... ArgBuilders>
794 ArgBuilders...>(fn_);
801 return ArgImpl<N, Flags...>(
802 std::make_index_sequence<
sizeof...(ArgBuilders)>());
812 struct GetArgBuilder;
817 struct GetArgBuilder<
false, N, Flags...> {
819 typename std::tuple_element<N, std::tuple<ArgBuilders...>>::type;
825 struct GetArgBuilder<
true, N, Flags...> {
827 typename std::tuple_element<N,
828 std::tuple<ArgBuilders...>>::type::BaseType,
829 std::tuple_element<N, std::tuple<ArgBuilders...>>::type::Build()
838 constexpr auto ArgImpl(std::index_sequence<I...>) {
840 RetBuilder,
typename GetArgBuilder<N == I, I, Flags...>::type...>(fn_);
850 template <
typename R,
typename... Args>
851 constexpr auto Fn(R (*fn)(Args...)) {
854 reinterpret_cast<
const void*>(fn));
861 template <
typename R,
typename... Args>
869 static constexpr CTypeInfo kTypeInfoFloat64 =
884 template <
const CTypeInfo* type_info,
typename T>
886 "Use TryToCopyAndConvertArrayToCppBuffer<CTypeInfo::Identifier, T>()")
893 "Use TryToCopyAndConvertArrayToCppBuffer<CTypeInfo::Identifier, T>()")
895 TryCopyAndConvertArrayToCppBuffer<&kTypeInfoInt32, int32_t>(
896 Local<
Array> src, int32_t* dst, uint32_t max_length) {
902 "Use TryToCopyAndConvertArrayToCppBuffer<CTypeInfo::Identifier, T>()")
904 TryCopyAndConvertArrayToCppBuffer<&kTypeInfoFloat64,
double>(
905 Local<
Array> src,
double* dst, uint32_t max_length) {
911 Local<
Array> src, T* dst, uint32_t max_length);
917 uint32_t max_length);
923 uint32_t max_length);
929 uint32_t max_length);
935 uint32_t max_length);