219 #ifndef INCLUDE_V8_FAST_API_CALLS_H_
220 #define INCLUDE_V8_FAST_API_CALLS_H_
226 #include <type_traits>
276 : type_(type), sequence_type_(sequence_type), flags_(flags) {}
313 template <
typename T>
318 ValidateIndex(index);
321 memcpy(&tmp,
reinterpret_cast<T*>(data_) + index,
sizeof(T));
376 return arg_count_ > 0 && arg_info_[arg_count_ - 1]
.GetType() ==
382 const unsigned int arg_count_;
388 constexpr CFunction() : address_(
nullptr), type_info_(
nullptr) {}
419 if (diff_index >= 0) {
437 template <
typename F>
439 return ArgUnwrap<F*>::Make(func);
442 template <
typename F>
445 return ArgUnwrap<F*>::Make(func);
451 const void* address_;
454 template <
typename F>
456 static_assert(
sizeof(F) !=
sizeof(F),
457 "CFunction must be created from a function pointer.");
460 template <
typename R,
typename... Args>
461 class ArgUnwrap<R (*)(Args...)> {
463 static CFunction Make(R (*func)(Args...));
512 template <
typename T,
typename... List>
513 struct count : std::integral_constant<
int, 0> {};
514 template <
typename T,
typename... Args>
516 : std::integral_constant<std::size_t, 1 +
count<T, Args...>::value> {};
517 template <
typename T,
typename U,
typename... Args>
520 template <
typename RetBuilder,
typename... ArgBuilders>
522 static constexpr int kOptionsArgCount =
524 static constexpr int kReceiverCount = 1;
526 static_assert(kOptionsArgCount == 0 || kOptionsArgCount == 1,
527 "Only one options parameter is supported.");
529 static_assert(
sizeof...(ArgBuilders) >= kOptionsArgCount + kReceiverCount,
530 "The receiver or the options argument is missing.");
536 arg_info_storage_{ArgBuilders::Build()...} {
537 constexpr CTypeInfo::
Type kReturnType = RetBuilder::Build().GetType();
544 "64-bit int and api object values are not currently "
545 "supported return types.");
549 const CTypeInfo arg_info_storage_[
sizeof...(ArgBuilders)];
552 template <
typename T>
554 static_assert(
sizeof(T) !=
sizeof(T),
"This type is not supported");
557 #define SPECIALIZE_GET_TYPE_INFO_HELPER_FOR(T, Enum)
559 struct TypeInfoHelper<T> {
560 static constexpr CTypeInfo::Flags Flags() {
561 return CTypeInfo::Flags::kNone;
564 static constexpr CTypeInfo::Type Type() { return CTypeInfo::Type::Enum; }
565 static constexpr CTypeInfo::SequenceType SequenceType() {
566 return CTypeInfo::SequenceType::kScalar;
573 #define DEFINE_TYPE_INFO_TRAITS(CType, Enum)
575 struct CTypeInfoTraits<CTypeInfo::Type::Enum> {
579 #define PRIMITIVE_C_TYPES(V)
589 #define ALL_C_TYPES(V)
592 V(v8::Local<v8::Value>, kV8Value)
593 V(v8::Local<v8::Object>, kV8Value)
594 V(ApiObject, kApiObject)
603 #undef PRIMITIVE_C_TYPES
606 #define SPECIALIZE_GET_TYPE_INFO_HELPER_FOR_TA(T, Enum)
608 struct TypeInfoHelper<const FastApiTypedArray<T>&> {
609 static constexpr CTypeInfo::Flags Flags() {
610 return CTypeInfo::Flags::kNone;
613 static constexpr CTypeInfo::Type Type() { return CTypeInfo::Type::Enum; }
614 static constexpr CTypeInfo::SequenceType SequenceType() {
615 return CTypeInfo::SequenceType::kIsTypedArray;
619 #define TYPED_ARRAY_C_TYPES(V)
629 #undef TYPED_ARRAY_C_TYPES
663 #define STATIC_ASSERT_IMPLIES(COND, ASSERTION, MSG)
664 static_assert(((COND) == 0
) || (ASSERTION), MSG)
682 "kAllowSharedBit is only allowed for TypedArrays and ArrayBuffers.");
686 "kEnforceRangeBit is only allowed for integral types.");
690 "kClampBit is only allowed for integral types.");
694 "kIsRestrictedBit is only allowed for floating point types.");
697 "Sequences are only supported from void type.");
701 "TypedArrays are only supported from primitive types or void.");
709 template <
typename... Rest>
712 return CTypeInfo::
Flags(uint8_t(flags) | uint8_t(MergeFlags(rest...)));
717 template <
typename RetBuilder,
typename... ArgBuilders>
726 ArgBuilders...>(fn_);
733 return ArgImpl<N, Flags...>(
734 std::make_index_sequence<
sizeof...(ArgBuilders)>());
744 struct GetArgBuilder;
749 struct GetArgBuilder<
false, N, Flags...> {
751 typename std::tuple_element<N, std::tuple<ArgBuilders...>>::type;
757 struct GetArgBuilder<
true, N, Flags...> {
759 typename std::tuple_element<N,
760 std::tuple<ArgBuilders...>>::type::BaseType,
761 std::tuple_element<N, std::tuple<ArgBuilders...>>::type::Build()
770 constexpr auto ArgImpl(std::index_sequence<I...>) {
772 RetBuilder,
typename GetArgBuilder<N == I, I, Flags...>::type...>(fn_);
782 template <
typename R,
typename... Args>
783 constexpr auto Fn(R (*fn)(Args...)) {
786 reinterpret_cast<
const void*>(fn));
793 template <
typename R,
typename... Args>
801 static constexpr CTypeInfo kTypeInfoFloat64 =
816 template <
const CTypeInfo* type_info,
typename T>
818 Local<
Array> src, T* dst, uint32_t max_length);
823 Local<
Array> src, int32_t* dst, uint32_t max_length) {
830 Local<
Array> src,
double* dst, uint32_t max_length) {