138 #ifndef INCLUDE_V8_FAST_API_CALLS_H_
139 #define INCLUDE_V8_FAST_API_CALLS_H_
168 return CTypeInfo(
static_cast<
int>(flags) | kIsWrapperTypeBit);
177 ((
static_cast<uintptr_t>(ctype) << kTypeOffset) & kTypeMask) |
178 static_cast<
int>(flags));
184 if (payload_ & kIsWrapperTypeBit) {
187 return static_cast<
Type>((payload_ & kTypeMask) >> kTypeOffset);
200 explicit constexpr CTypeInfo(uintptr_t payload) : payload_(payload) {}
203 static constexpr uintptr_t kIsWrapperTypeBit = 1 << 1;
204 static constexpr uintptr_t kWrapperTypeInfoMask =
static_cast<uintptr_t>(~0)
207 static constexpr unsigned int kTypeOffset = kIsWrapperTypeBit;
208 static constexpr unsigned int kTypeSize = 8 - kTypeOffset;
209 static constexpr uintptr_t kTypeMask =
210 (~(
static_cast<uintptr_t>(~0) << kTypeSize)) << kTypeOffset;
212 const uintptr_t payload_;
228 template <
typename T>
235 #define SPECIALIZE_GET_C_TYPE_FOR(ctype, ctypeinfo)
237 struct GetCType<ctype> {
238 static constexpr CTypeInfo Get() {
239 return CTypeInfo::FromCType(CTypeInfo::Type::ctypeinfo);
243 #define SUPPORTED_C_TYPES(V)
252 V(ApiObject, kV8Value)
257 template <
typename T,
typename =
void>
266 template <
typename T>
272 template <
typename T,
typename =
void>
274 static_assert(
sizeof(T**) !=
sizeof(T**),
"Unsupported type");
278 template <
typename T>
285 template <
typename T>
288 template <
typename T>
291 template <
typename R,
bool RaisesException,
typename... Args>
301 "The receiver or the has_error argument is missing.");
304 "Only void return types are currently supported.");
313 return arg_info_[index];
318 const unsigned int arg_count_;
319 const CTypeInfo arg_info_[
sizeof...(Args)];
326 constexpr CFunction() : address_(
nullptr), type_info_(
nullptr) {}
339 template <
typename F>
341 return ArgUnwrap<F*>::Make(func);
344 template <
typename F>
346 return ArgUnwrap<F*>::MakeWithErrorSupport(func);
349 template <
typename F>
351 return CFunction(
reinterpret_cast<
const void*>(func), type_info);
355 const void* address_;
358 CFunction(
const void* address,
const CFunctionInfo* type_info);
360 template <
typename R,
bool RaisesException,
typename... Args>
366 template <
typename F>
368 static_assert(
sizeof(F) !=
sizeof(F),
369 "CFunction must be created from a function pointer.");
372 template <
typename R,
typename... Args>
373 class ArgUnwrap<R (*)(Args...)> {
375 static CFunction Make(R (*func)(Args...)) {
376 return CFunction(
reinterpret_cast<
const void*>(func),
377 GetCFunctionInfo<R,
false, Args...>());
379 static CFunction MakeWithErrorSupport(R (*func)(Args...)) {
380 return CFunction(
reinterpret_cast<
const void*>(func),
381 GetCFunctionInfo<R,
true, Args...>());