162 #ifndef INCLUDE_V8_FAST_API_CALLS_H_
163 #define INCLUDE_V8_FAST_API_CALLS_H_
193 uintptr_t wrapper_type_info_ptr =
194 reinterpret_cast<uintptr_t
>(wrapper_type_info);
197 wrapper_type_info_ptr & ~(
static_cast<uintptr_t
>(~0)
198 <<
static_cast<uintptr_t
>(kIsWrapperTypeBit)),
202 return CTypeInfo(wrapper_type_info_ptr |
static_cast<int>(flags) |
210 ((
static_cast<uintptr_t
>(ctype) << kTypeOffset) & kTypeMask) |
211 static_cast<int>(flags));
217 if (payload_ & kIsWrapperTypeBit) {
220 return static_cast<Type>((payload_ & kTypeMask) >> kTypeOffset);
228 explicit constexpr
CTypeInfo(uintptr_t payload) : payload_(payload) {}
231 static constexpr uintptr_t kIsWrapperTypeBit = 1 << 1;
232 static constexpr uintptr_t kWrapperTypeInfoMask =
static_cast<uintptr_t
>(~0)
235 static constexpr
unsigned int kTypeOffset = kIsWrapperTypeBit;
236 static constexpr
unsigned int kTypeSize = 8 - kTypeOffset;
237 static constexpr uintptr_t kTypeMask =
238 (~(
static_cast<uintptr_t
>(~0) << kTypeSize)) << kTypeOffset;
240 const uintptr_t payload_;
250 template <
typename T>
254 static_assert(
sizeof(T) !=
sizeof(T),
255 "WrapperTraits must be specialized for this type.");
262 template <
typename T>
264 static_assert(
sizeof(T) !=
sizeof(T),
"Unsupported CType");
267 #define SPECIALIZE_GET_C_TYPE_FOR(ctype, ctypeinfo) \
269 struct GetCType<ctype> { \
270 static constexpr CTypeInfo Get() { \
271 return CTypeInfo::FromCType(CTypeInfo::Type::ctypeinfo); \
275 #define SUPPORTED_C_TYPES(V) \
279 V(uint32_t, kUint32) \
281 V(uint64_t, kUint64) \
287 template <
typename T,
typename =
void>
290 template <
typename T>
297 template <
typename T,
typename =
void>
306 template <
typename T>
314 template <
typename T,
typename =
void>
316 static_assert(
sizeof(T**) !=
sizeof(T**),
"Unsupported type");
320 template <
typename T>
329 template <
typename T>
332 template <
typename T>
335 template <
typename R,
typename... Args>
339 : return_info_(internal::
GetCType<R>::Get()),
340 arg_count_(sizeof...(Args)),
344 "Only void return types are currently supported.");
351 return arg_info_[index];
356 const unsigned int arg_count_;
364 constexpr
CFunction() : address_(nullptr), type_info_(nullptr) {}
369 return type_info_->ArgumentInfo(index);
377 template <
typename F>
379 return ArgUnwrap<F*>::Make(func);
383 const void* address_;
388 template <
typename R,
typename... Args>
394 template <
typename F>
396 static_assert(
sizeof(F) !=
sizeof(F),
397 "CFunction must be created from a function pointer.");
400 template <
typename R,
typename... Args>
401 class ArgUnwrap<R (*)(Args...)> {
403 static CFunction Make(R (*func)(Args...)) {
404 return CFunction(
reinterpret_cast<const void*
>(func),
405 GetCFunctionInfo<R, Args...>());
412 #endif // INCLUDE_V8_FAST_API_CALLS_H_