Loading...
Searching...
No Matches
v8-fast-api-calls.h
Go to the documentation of this file.
1// Copyright 2020 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
219#ifndef INCLUDE_V8_FAST_API_CALLS_H_
220#define INCLUDE_V8_FAST_API_CALLS_H_
221
222#include <stddef.h>
223#include <stdint.h>
224
225#include <tuple>
226#include <type_traits>
227
228#include "v8-internal.h" // NOLINT(build/include_directory)
229#include "v8-local-handle.h" // NOLINT(build/include_directory)
230#include "v8-typed-array.h" // NOLINT(build/include_directory)
231#include "v8-value.h" // NOLINT(build/include_directory)
232#include "v8config.h" // NOLINT(build/include_directory)
233
234namespace v8 {
235
236class Isolate;
237
239 public:
240 enum class Type : uint8_t {
241 kVoid,
242 kBool,
243 kUint8,
244 kInt32,
245 kUint32,
246 kInt64,
247 kUint64,
248 kFloat32,
249 kFloat64,
250 kPointer,
251 kV8Value,
253 kApiObject, // This will be deprecated once all users have
254 // migrated from v8::ApiObject to v8::Local<v8::Value>.
255 kAny, // This is added to enable untyped representation of fast
256 // call arguments for test purposes. It can represent any of
257 // the other types stored in the same memory as a union
258 // (see AnyCType declared below). This allows for
259 // uniform passing of arguments w.r.t. their location
260 // (in a register or on the stack), independent of their
261 // actual type. It's currently used by the arm64 simulator
262 // and can be added to the other simulators as well when fast
263 // calls having both GP and FP params need to be supported.
264 };
265
266 // kCallbackOptionsType is not part of the Type enum
267 // because it is only used internally. Use value 255 that is larger
268 // than any valid Type enum.
269 static constexpr Type kCallbackOptionsType = Type(255);
270
271 enum class SequenceType : uint8_t {
272 kScalar,
273 kIsSequence, // sequence<T>
274 kIsTypedArray, // TypedArray of T or any ArrayBufferView if T
275 // is void
276 kIsArrayBuffer // ArrayBuffer
277 };
278
279 enum class Flags : uint8_t {
280 kNone = 0,
281 kAllowSharedBit = 1 << 0, // Must be an ArrayBuffer or TypedArray
282 kEnforceRangeBit = 1 << 1, // T must be integral
283 kClampBit = 1 << 2, // T must be integral
284 kIsRestrictedBit = 1 << 3, // T must be float or double
285 };
286
287 explicit constexpr CTypeInfo(
288 Type type, SequenceType sequence_type = SequenceType::kScalar,
289 Flags flags = Flags::kNone)
290 : type_(type), sequence_type_(sequence_type), flags_(flags) {}
291
292 typedef uint32_t Identifier;
293 explicit constexpr CTypeInfo(Identifier identifier)
294 : CTypeInfo(static_cast<Type>(identifier >> 16),
295 static_cast<SequenceType>((identifier >> 8) & 255),
296 static_cast<Flags>(identifier & 255)) {}
297 constexpr Identifier GetId() const {
298 return static_cast<uint8_t>(type_) << 16 |
299 static_cast<uint8_t>(sequence_type_) << 8 |
300 static_cast<uint8_t>(flags_);
301 }
302
303 constexpr Type GetType() const { return type_; }
304 constexpr SequenceType GetSequenceType() const { return sequence_type_; }
305 constexpr Flags GetFlags() const { return flags_; }
306
307 static constexpr bool IsIntegralType(Type type) {
308 return type == Type::kUint8 || type == Type::kInt32 ||
309 type == Type::kUint32 || type == Type::kInt64 ||
310 type == Type::kUint64;
311 }
312
313 static constexpr bool IsFloatingPointType(Type type) {
314 return type == Type::kFloat32 || type == Type::kFloat64;
315 }
316
317 static constexpr bool IsPrimitive(Type type) {
318 return IsIntegralType(type) || IsFloatingPointType(type) ||
319 type == Type::kBool;
320 }
321
322 private:
323 Type type_;
324 SequenceType sequence_type_;
325 Flags flags_;
326};
327
329 public:
330 // Returns the length in number of elements.
331 size_t V8_EXPORT length() const { return length_; }
332 // Checks whether the given index is within the bounds of the collection.
333 void V8_EXPORT ValidateIndex(size_t index) const;
334
335 protected:
336 size_t length_ = 0;
337};
338
339template <typename T>
341 public:
342 V8_INLINE T get(size_t index) const {
343#ifdef DEBUG
344 ValidateIndex(index);
345#endif // DEBUG
346 T tmp;
347 memcpy(&tmp, static_cast<void*>(reinterpret_cast<T*>(data_) + index),
348 sizeof(T));
349 return tmp;
350 }
351
352 bool getStorageIfAligned(T** elements) const {
353 if (reinterpret_cast<uintptr_t>(data_) % alignof(T) != 0) {
354 return false;
355 }
356 *elements = reinterpret_cast<T*>(data_);
357 return true;
358 }
359
360 private:
361 // This pointer should include the typed array offset applied.
362 // It's not guaranteed that it's aligned to sizeof(T), it's only
363 // guaranteed that it's 4-byte aligned, so for 8-byte types we need to
364 // provide a special implementation for reading from it, which hides
365 // the possibly unaligned read in the `get` method.
366 void* data_;
367};
368
369// Any TypedArray. It uses kTypedArrayBit with base type void
370// Overloaded args of ArrayBufferView and TypedArray are not supported
371// (for now) because the generic “any” ArrayBufferView doesn’t have its
372// own instance type. It could be supported if we specify that
373// TypedArray<T> always has precedence over the generic ArrayBufferView,
374// but this complicates overload resolution.
376 void* data;
378};
379
381 void* data;
383};
384
386 const char* data;
387 uint32_t length;
388};
389
391 public:
392 enum class Int64Representation : uint8_t {
393 kNumber = 0, // Use numbers to represent 64 bit integers.
394 kBigInt = 1, // Use BigInts to represent 64 bit integers.
395 };
396
397 // Construct a struct to hold a CFunction's type information.
398 // |return_info| describes the function's return type.
399 // |arg_info| is an array of |arg_count| CTypeInfos describing the
400 // arguments. Only the last argument may be of the special type
401 // CTypeInfo::kCallbackOptionsType.
402 CFunctionInfo(const CTypeInfo& return_info, unsigned int arg_count,
403 const CTypeInfo* arg_info,
404 Int64Representation repr = Int64Representation::kNumber);
405
406 const CTypeInfo& ReturnInfo() const { return return_info_; }
407
408 // The argument count, not including the v8::FastApiCallbackOptions
409 // if present.
410 unsigned int ArgumentCount() const {
411 return HasOptions() ? arg_count_ - 1 : arg_count_;
412 }
413
415
416 // |index| must be less than ArgumentCount().
417 // Note: if the last argument passed on construction of CFunctionInfo
418 // has type CTypeInfo::kCallbackOptionsType, it is not included in
419 // ArgumentCount().
420 const CTypeInfo& ArgumentInfo(unsigned int index) const;
421
422 bool HasOptions() const {
423 // The options arg is always the last one.
424 return arg_count_ > 0 && arg_info_[arg_count_ - 1].GetType() ==
425 CTypeInfo::kCallbackOptionsType;
426 }
427
428 private:
429 const CTypeInfo return_info_;
430 const Int64Representation repr_;
431 const unsigned int arg_count_;
432 const CTypeInfo* arg_info_;
433};
434
435struct FastApiCallbackOptions;
436
437// Provided for testing.
439 AnyCType() : int64_value(0) {}
440
441#if defined(V8_ENABLE_LOCAL_OFF_STACK_CHECK) && V8_HAS_ATTRIBUTE_TRIVIAL_ABI
442 // In this case, Local<T> is not trivially copyable and the implicit
443 // copy constructor and copy assignment for the union are deleted.
444 AnyCType(const AnyCType& other) : int64_value(other.int64_value) {}
445 AnyCType& operator=(const AnyCType& other) {
446 int64_value = other.int64_value;
447 return *this;
448 }
449#endif
450
452 int32_t int32_value;
453 uint32_t uint32_value;
454 int64_t int64_value;
455 uint64_t uint64_value;
470};
471
472static_assert(
473 sizeof(AnyCType) == 8,
474 "The union AnyCType should have size == 64 bits, as this is assumed "
475 "by EffectControlLinearizer.");
476
478 public:
479 constexpr CFunction() : address_(nullptr), type_info_(nullptr) {}
480
481 const CTypeInfo& ReturnInfo() const { return type_info_->ReturnInfo(); }
482
483 const CTypeInfo& ArgumentInfo(unsigned int index) const {
484 return type_info_->ArgumentInfo(index);
485 }
486
487 unsigned int ArgumentCount() const { return type_info_->ArgumentCount(); }
488
489 const void* GetAddress() const { return address_; }
491 return type_info_->GetInt64Representation();
492 }
493 const CFunctionInfo* GetTypeInfo() const { return type_info_; }
494
495 enum class OverloadResolution { kImpossible, kAtRuntime, kAtCompileTime };
496
497 // Returns whether an overload between this and the given CFunction can
498 // be resolved at runtime by the RTTI available for the arguments or at
499 // compile time for functions with different number of arguments.
501 // Runtime overload resolution can only deal with functions with the
502 // same number of arguments. Functions with different arity are handled
503 // by compile time overload resolution though.
504 if (ArgumentCount() != other->ArgumentCount()) {
505 return OverloadResolution::kAtCompileTime;
506 }
507
508 // The functions can only differ by a single argument position.
509 int diff_index = -1;
510 for (unsigned int i = 0; i < ArgumentCount(); ++i) {
511 if (ArgumentInfo(i).GetSequenceType() !=
512 other->ArgumentInfo(i).GetSequenceType()) {
513 if (diff_index >= 0) {
514 return OverloadResolution::kImpossible;
515 }
516 diff_index = i;
517
518 // We only support overload resolution between sequence types.
519 if (ArgumentInfo(i).GetSequenceType() ==
520 CTypeInfo::SequenceType::kScalar ||
521 other->ArgumentInfo(i).GetSequenceType() ==
522 CTypeInfo::SequenceType::kScalar) {
523 return OverloadResolution::kImpossible;
524 }
525 }
526 }
527
528 return OverloadResolution::kAtRuntime;
529 }
530
531 template <typename F>
532 static CFunction Make(F* func) {
533 return ArgUnwrap<F*>::Make(func);
534 }
535
536 // Provided for testing purposes.
537 template <typename R, typename... Args, typename R_Patch,
538 typename... Args_Patch>
539 static CFunction Make(R (*func)(Args...),
540 R_Patch (*patching_func)(Args_Patch...)) {
541 CFunction c_func = ArgUnwrap<R (*)(Args...)>::Make(func);
542 static_assert(
543 sizeof...(Args_Patch) == sizeof...(Args),
544 "The patching function must have the same number of arguments.");
545 c_func.address_ = reinterpret_cast<void*>(patching_func);
546 return c_func;
547 }
548
549 CFunction(const void* address, const CFunctionInfo* type_info);
550
551 private:
552 const void* address_;
553 const CFunctionInfo* type_info_;
554
555 template <typename F>
556 class ArgUnwrap {
557 static_assert(sizeof(F) != sizeof(F),
558 "CFunction must be created from a function pointer.");
559 };
560
561 template <typename R, typename... Args>
562 class ArgUnwrap<R (*)(Args...)> {
563 public:
564 static CFunction Make(R (*func)(Args...));
565 };
566};
567
580 return {false, {0}, nullptr};
581 }
582
595
600 union {
601 uintptr_t data_ptr;
603 };
604
609};
610
611namespace internal {
612
613// Helper to count the number of occurances of `T` in `List`
614template <typename T, typename... List>
615struct count : std::integral_constant<int, 0> {};
616template <typename T, typename... Args>
617struct count<T, T, Args...>
618 : std::integral_constant<std::size_t, 1 + count<T, Args...>::value> {};
619template <typename T, typename U, typename... Args>
620struct count<T, U, Args...> : count<T, Args...> {};
621
622template <CFunctionInfo::Int64Representation Representation,
623 typename RetBuilder, typename... ArgBuilders>
625 static constexpr int kOptionsArgCount =
626 count<FastApiCallbackOptions&, ArgBuilders...>();
627 static constexpr int kReceiverCount = 1;
628
629 static_assert(kOptionsArgCount == 0 || kOptionsArgCount == 1,
630 "Only one options parameter is supported.");
631
632 static_assert(sizeof...(ArgBuilders) >= kOptionsArgCount + kReceiverCount,
633 "The receiver or the options argument is missing.");
634
635 public:
637 : CFunctionInfo(RetBuilder::Build(), sizeof...(ArgBuilders),
638 arg_info_storage_, Representation),
639 arg_info_storage_{ArgBuilders::Build()...} {
640 constexpr CTypeInfo::Type kReturnType = RetBuilder::Build().GetType();
641 static_assert(kReturnType == CTypeInfo::Type::kVoid ||
642 kReturnType == CTypeInfo::Type::kBool ||
643 kReturnType == CTypeInfo::Type::kInt32 ||
644 kReturnType == CTypeInfo::Type::kUint32 ||
645 kReturnType == CTypeInfo::Type::kInt64 ||
646 kReturnType == CTypeInfo::Type::kUint64 ||
647 kReturnType == CTypeInfo::Type::kFloat32 ||
648 kReturnType == CTypeInfo::Type::kFloat64 ||
649 kReturnType == CTypeInfo::Type::kPointer ||
650 kReturnType == CTypeInfo::Type::kAny,
651 "String and api object values are not currently "
652 "supported return types.");
653 }
654
655 private:
656 const CTypeInfo arg_info_storage_[sizeof...(ArgBuilders)];
657};
658
659template <typename T>
661 static_assert(sizeof(T) != sizeof(T), "This type is not supported");
662};
663
664#define SPECIALIZE_GET_TYPE_INFO_HELPER_FOR(T, Enum) \
665 template <> \
666 struct TypeInfoHelper<T> { \
667 static constexpr CTypeInfo::Flags Flags() { \
668 return CTypeInfo::Flags::kNone; \
669 } \
670 \
671 static constexpr CTypeInfo::Type Type() { return CTypeInfo::Type::Enum; } \
672 static constexpr CTypeInfo::SequenceType SequenceType() { \
673 return CTypeInfo::SequenceType::kScalar; \
674 } \
675 };
676
677template <CTypeInfo::Type type>
679
680#define DEFINE_TYPE_INFO_TRAITS(CType, Enum) \
681 template <> \
682 struct CTypeInfoTraits<CTypeInfo::Type::Enum> { \
683 using ctype = CType; \
684 };
685
686#define PRIMITIVE_C_TYPES(V) \
687 V(bool, kBool) \
688 V(uint8_t, kUint8) \
689 V(int32_t, kInt32) \
690 V(uint32_t, kUint32) \
691 V(int64_t, kInt64) \
692 V(uint64_t, kUint64) \
693 V(float, kFloat32) \
694 V(double, kFloat64) \
695 V(void*, kPointer)
696
697// Same as above, but includes deprecated types for compatibility.
698#define ALL_C_TYPES(V) \
699 PRIMITIVE_C_TYPES(V) \
700 V(void, kVoid) \
701 V(v8::Local<v8::Value>, kV8Value) \
702 V(v8::Local<v8::Object>, kV8Value) \
703 V(AnyCType, kAny)
704
705// ApiObject was a temporary solution to wrap the pointer to the v8::Value.
706// Please use v8::Local<v8::Value> in new code for the arguments and
707// v8::Local<v8::Object> for the receiver, as ApiObject will be deprecated.
708
711
712#undef PRIMITIVE_C_TYPES
713#undef ALL_C_TYPES
714
715#define SPECIALIZE_GET_TYPE_INFO_HELPER_FOR_TA(T, Enum) \
716 template <> \
717 struct TypeInfoHelper<const FastApiTypedArray<T>&> { \
718 static constexpr CTypeInfo::Flags Flags() { \
719 return CTypeInfo::Flags::kNone; \
720 } \
721 \
722 static constexpr CTypeInfo::Type Type() { return CTypeInfo::Type::Enum; } \
723 static constexpr CTypeInfo::SequenceType SequenceType() { \
724 return CTypeInfo::SequenceType::kIsTypedArray; \
725 } \
726 };
727
728#define TYPED_ARRAY_C_TYPES(V) \
729 V(uint8_t, kUint8) \
730 V(int32_t, kInt32) \
731 V(uint32_t, kUint32) \
732 V(int64_t, kInt64) \
733 V(uint64_t, kUint64) \
734 V(float, kFloat32) \
735 V(double, kFloat64)
736
739#undef TYPED_ARRAY_C_TYPES
741template <>
742struct TypeInfoHelper<v8::Local<v8::Array>> {
743 static constexpr CTypeInfo::Flags Flags() { return CTypeInfo::Flags::kNone; }
744
745 static constexpr CTypeInfo::Type Type() { return CTypeInfo::Type::kVoid; }
746 static constexpr CTypeInfo::SequenceType SequenceType() {
749};
751template <>
752struct TypeInfoHelper<v8::Local<v8::Uint32Array>> {
753 static constexpr CTypeInfo::Flags Flags() { return CTypeInfo::Flags::kNone; }
754
755 static constexpr CTypeInfo::Type Type() { return CTypeInfo::Type::kUint32; }
756 static constexpr CTypeInfo::SequenceType SequenceType() {
759};
761template <>
763 static constexpr CTypeInfo::Flags Flags() { return CTypeInfo::Flags::kNone; }
764
765 static constexpr CTypeInfo::Type Type() {
767 }
768 static constexpr CTypeInfo::SequenceType SequenceType() {
771};
773template <>
774struct TypeInfoHelper<const FastOneByteString&> {
775 static constexpr CTypeInfo::Flags Flags() { return CTypeInfo::Flags::kNone; }
776
777 static constexpr CTypeInfo::Type Type() {
779 }
780 static constexpr CTypeInfo::SequenceType SequenceType() {
782 }
783};
784
785#define STATIC_ASSERT_IMPLIES(COND, ASSERTION, MSG) \
786 static_assert(((COND) == 0) || (ASSERTION), MSG)
787
788} // namespace internal
789
790template <typename T, CTypeInfo::Flags... Flags>
792 public:
793 using BaseType = T;
794
795 static constexpr CTypeInfo Build() {
796 constexpr CTypeInfo::Flags kFlags =
797 MergeFlags(internal::TypeInfoHelper<T>::Flags(), Flags...);
799 constexpr CTypeInfo::SequenceType kSequenceType =
801
803 uint8_t(kFlags) & uint8_t(CTypeInfo::Flags::kAllowSharedBit),
804 (kSequenceType == CTypeInfo::SequenceType::kIsTypedArray ||
805 kSequenceType == CTypeInfo::SequenceType::kIsArrayBuffer),
806 "kAllowSharedBit is only allowed for TypedArrays and ArrayBuffers.");
808 uint8_t(kFlags) & uint8_t(CTypeInfo::Flags::kEnforceRangeBit),
809 CTypeInfo::IsIntegralType(kType),
810 "kEnforceRangeBit is only allowed for integral types.");
812 uint8_t(kFlags) & uint8_t(CTypeInfo::Flags::kClampBit),
813 CTypeInfo::IsIntegralType(kType),
814 "kClampBit is only allowed for integral types.");
816 uint8_t(kFlags) & uint8_t(CTypeInfo::Flags::kIsRestrictedBit),
817 CTypeInfo::IsFloatingPointType(kType),
818 "kIsRestrictedBit is only allowed for floating point types.");
819 STATIC_ASSERT_IMPLIES(kSequenceType == CTypeInfo::SequenceType::kIsSequence,
820 kType == CTypeInfo::Type::kVoid,
821 "Sequences are only supported from void type.");
823 kSequenceType == CTypeInfo::SequenceType::kIsTypedArray,
824 CTypeInfo::IsPrimitive(kType) || kType == CTypeInfo::Type::kVoid,
825 "TypedArrays are only supported from primitive types or void.");
826
827 // Return the same type with the merged flags.
830 }
831
832 private:
833 template <typename... Rest>
834 static constexpr CTypeInfo::Flags MergeFlags(CTypeInfo::Flags flags,
835 Rest... rest) {
836 return CTypeInfo::Flags(uint8_t(flags) | uint8_t(MergeFlags(rest...)));
837 }
838 static constexpr CTypeInfo::Flags MergeFlags() { return CTypeInfo::Flags(0); }
839};
841namespace internal {
842template <typename RetBuilder, typename... ArgBuilders>
844 public:
845 explicit constexpr CFunctionBuilderWithFunction(const void* fn) : fn_(fn) {}
846
847 template <CTypeInfo::Flags... Flags>
848 constexpr auto Ret() {
850 CTypeInfoBuilder<typename RetBuilder::BaseType, Flags...>,
851 ArgBuilders...>(fn_);
852 }
853
854 template <unsigned int N, CTypeInfo::Flags... Flags>
855 constexpr auto Arg() {
856 // Return a copy of the builder with the Nth arg builder merged with
857 // template parameter pack Flags.
858 return ArgImpl<N, Flags...>(
859 std::make_index_sequence<sizeof...(ArgBuilders)>());
860 }
861
862 // Provided for testing purposes.
863 template <typename Ret, typename... Args>
864 auto Patch(Ret (*patching_func)(Args...)) {
865 static_assert(
866 sizeof...(Args) == sizeof...(ArgBuilders),
867 "The patching function must have the same number of arguments.");
868 fn_ = reinterpret_cast<void*>(patching_func);
869 return *this;
870 }
871
872 template <CFunctionInfo::Int64Representation Representation =
874 auto Build() {
875 static CFunctionInfoImpl<Representation, RetBuilder, ArgBuilders...>
876 instance;
877 return CFunction(fn_, &instance);
878 }
879
880 private:
881 template <bool Merge, unsigned int N, CTypeInfo::Flags... Flags>
882 struct GetArgBuilder;
883
884 // Returns the same ArgBuilder as the one at index N, including its flags.
885 // Flags in the template parameter pack are ignored.
886 template <unsigned int N, CTypeInfo::Flags... Flags>
887 struct GetArgBuilder<false, N, Flags...> {
888 using type =
889 typename std::tuple_element<N, std::tuple<ArgBuilders...>>::type;
890 };
891
892 // Returns an ArgBuilder with the same base type as the one at index N,
893 // but merges the flags with the flags in the template parameter pack.
894 template <unsigned int N, CTypeInfo::Flags... Flags>
895 struct GetArgBuilder<true, N, Flags...> {
896 using type = CTypeInfoBuilder<
897 typename std::tuple_element<N,
898 std::tuple<ArgBuilders...>>::type::BaseType,
899 std::tuple_element<N, std::tuple<ArgBuilders...>>::type::Build()
900 .GetFlags(),
901 Flags...>;
902 };
903
904 // Return a copy of the CFunctionBuilder, but merges the Flags on
905 // ArgBuilder index N with the new Flags passed in the template parameter
906 // pack.
907 template <unsigned int N, CTypeInfo::Flags... Flags, size_t... I>
908 constexpr auto ArgImpl(std::index_sequence<I...>) {
910 RetBuilder, typename GetArgBuilder<N == I, I, Flags...>::type...>(fn_);
912
913 const void* fn_;
914};
915
917 public:
918 constexpr CFunctionBuilder() {}
919
920 template <typename R, typename... Args>
921 constexpr auto Fn(R (*fn)(Args...)) {
924 reinterpret_cast<const void*>(fn));
925 }
926};
927
928} // namespace internal
929
930// static
931template <typename R, typename... Args>
932CFunction CFunction::ArgUnwrap<R (*)(Args...)>::Make(R (*func)(Args...)) {
933 return internal::CFunctionBuilder().Fn(func).Build();
934}
935
936using CFunctionBuilder = internal::CFunctionBuilder;
937
938static constexpr CTypeInfo kTypeInfoInt32 = CTypeInfo(CTypeInfo::Type::kInt32);
939static constexpr CTypeInfo kTypeInfoFloat64 =
940 CTypeInfo(CTypeInfo::Type::kFloat64);
941
954template <CTypeInfo::Identifier type_info_id, typename T>
956 Local<Array> src, T* dst, uint32_t max_length);
957
958template <>
960TryToCopyAndConvertArrayToCppBuffer<CTypeInfoBuilder<int32_t>::Build().GetId(),
961 int32_t>(Local<Array> src, int32_t* dst,
962 uint32_t max_length);
963
964template <>
966TryToCopyAndConvertArrayToCppBuffer<CTypeInfoBuilder<uint32_t>::Build().GetId(),
967 uint32_t>(Local<Array> src, uint32_t* dst,
968 uint32_t max_length);
969
970template <>
972TryToCopyAndConvertArrayToCppBuffer<CTypeInfoBuilder<float>::Build().GetId(),
973 float>(Local<Array> src, float* dst,
974 uint32_t max_length);
975
976template <>
978TryToCopyAndConvertArrayToCppBuffer<CTypeInfoBuilder<double>::Build().GetId(),
979 double>(Local<Array> src, double* dst,
980 uint32_t max_length);
981
982} // namespace v8
983
984#endif // INCLUDE_V8_FAST_API_CALLS_H_
Definition: v8-fast-api-calls.h:390
Int64Representation GetInt64Representation() const
Definition: v8-fast-api-calls.h:414
Int64Representation
Definition: v8-fast-api-calls.h:392
const CTypeInfo & ReturnInfo() const
Definition: v8-fast-api-calls.h:406
const CTypeInfo & ArgumentInfo(unsigned int index) const
bool HasOptions() const
Definition: v8-fast-api-calls.h:422
unsigned int ArgumentCount() const
Definition: v8-fast-api-calls.h:410
CFunctionInfo(const CTypeInfo &return_info, unsigned int arg_count, const CTypeInfo *arg_info, Int64Representation repr=Int64Representation::kNumber)
Definition: v8-fast-api-calls.h:477
const CTypeInfo & ReturnInfo() const
Definition: v8-fast-api-calls.h:481
constexpr CFunction()
Definition: v8-fast-api-calls.h:479
const CTypeInfo & ArgumentInfo(unsigned int index) const
Definition: v8-fast-api-calls.h:483
unsigned int ArgumentCount() const
Definition: v8-fast-api-calls.h:487
CFunctionInfo::Int64Representation GetInt64Representation() const
Definition: v8-fast-api-calls.h:490
CFunction(const void *address, const CFunctionInfo *type_info)
static CFunction Make(R(*func)(Args...), R_Patch(*patching_func)(Args_Patch...))
Definition: v8-fast-api-calls.h:539
const void * GetAddress() const
Definition: v8-fast-api-calls.h:489
OverloadResolution
Definition: v8-fast-api-calls.h:495
const CFunctionInfo * GetTypeInfo() const
Definition: v8-fast-api-calls.h:493
static CFunction Make(F *func)
Definition: v8-fast-api-calls.h:532
OverloadResolution GetOverloadResolution(const CFunction *other)
Definition: v8-fast-api-calls.h:500
Definition: v8-fast-api-calls.h:786
T BaseType
Definition: v8-fast-api-calls.h:788
Definition: v8-fast-api-calls.h:238
Flags
Definition: v8-fast-api-calls.h:279
constexpr CTypeInfo(Type type, SequenceType sequence_type=SequenceType::kScalar, Flags flags=Flags::kNone)
Definition: v8-fast-api-calls.h:287
static constexpr bool IsFloatingPointType(Type type)
Definition: v8-fast-api-calls.h:313
static constexpr bool IsPrimitive(Type type)
Definition: v8-fast-api-calls.h:317
static constexpr Type kCallbackOptionsType
Definition: v8-fast-api-calls.h:269
static constexpr bool IsIntegralType(Type type)
Definition: v8-fast-api-calls.h:307
SequenceType
Definition: v8-fast-api-calls.h:271
constexpr Identifier GetId() const
Definition: v8-fast-api-calls.h:297
constexpr Type GetType() const
Definition: v8-fast-api-calls.h:303
constexpr Flags GetFlags() const
Definition: v8-fast-api-calls.h:305
Type
Definition: v8-fast-api-calls.h:240
uint32_t Identifier
Definition: v8-fast-api-calls.h:292
constexpr CTypeInfo(Identifier identifier)
Definition: v8-fast-api-calls.h:293
constexpr SequenceType GetSequenceType() const
Definition: v8-fast-api-calls.h:304
Definition: v8-isolate.h:210
Definition: v8-local-handle.h:258
Definition: v8-fast-api-calls.h:838
constexpr CFunctionBuilderWithFunction(const void *fn)
Definition: v8-fast-api-calls.h:840
auto Build()
Definition: v8-fast-api-calls.h:869
constexpr auto Ret()
Definition: v8-fast-api-calls.h:843
constexpr auto Arg()
Definition: v8-fast-api-calls.h:850
auto Patch(Ret(*patching_func)(Args...))
Definition: v8-fast-api-calls.h:859
Definition: v8-fast-api-calls.h:911
constexpr CFunctionBuilder()
Definition: v8-fast-api-calls.h:913
constexpr auto Fn(R(*fn)(Args...))
Definition: v8-fast-api-calls.h:916
Definition: v8-fast-api-calls.h:624
constexpr CFunctionInfoImpl()
Definition: v8-fast-api-calls.h:636
Definition: libplatform.h:15
bool TryToCopyAndConvertArrayToCppBuffer(Local< Array > src, T *dst, uint32_t max_length)
internal::CFunctionBuilder CFunctionBuilder
Definition: v8-fast-api-calls.h:931
Definition: v8-fast-api-calls.h:375
size_t byte_length
Definition: v8-fast-api-calls.h:377
void * data
Definition: v8-fast-api-calls.h:376
Definition: v8-fast-api-calls.h:380
void * data
Definition: v8-fast-api-calls.h:381
size_t byte_length
Definition: v8-fast-api-calls.h:382
Definition: v8-fast-api-calls.h:574
bool fallback
Definition: v8-fast-api-calls.h:594
v8::Local< v8::Value > data
Definition: v8-fast-api-calls.h:602
uintptr_t data_ptr
Definition: v8-fast-api-calls.h:601
FastApiTypedArray< uint8_t > *const wasm_memory
Definition: v8-fast-api-calls.h:608
static FastApiCallbackOptions CreateForTesting(Isolate *isolate)
Definition: v8-fast-api-calls.h:579
Definition: v8-fast-api-calls.h:328
size_t length() const
Definition: v8-fast-api-calls.h:331
size_t length_
Definition: v8-fast-api-calls.h:336
void ValidateIndex(size_t index) const
Definition: v8-fast-api-calls.h:340
bool getStorageIfAligned(T **elements) const
Definition: v8-fast-api-calls.h:352
T get(size_t index) const
Definition: v8-fast-api-calls.h:342
Definition: v8-fast-api-calls.h:385
const char * data
Definition: v8-fast-api-calls.h:386
uint32_t length
Definition: v8-fast-api-calls.h:387
Definition: v8-fast-api-calls.h:678
Definition: v8-fast-api-calls.h:660
Definition: v8-fast-api-calls.h:615
Definition: v8-fast-api-calls.h:438
FastApiCallbackOptions * options_value
Definition: v8-fast-api-calls.h:469
const FastApiTypedArray< int64_t > * int64_ta_value
Definition: v8-fast-api-calls.h:464
AnyCType()
Definition: v8-fast-api-calls.h:439
const FastApiTypedArray< uint64_t > * uint64_ta_value
Definition: v8-fast-api-calls.h:465
const FastOneByteString * string_value
Definition: v8-fast-api-calls.h:468
Local< Array > sequence_value
Definition: v8-fast-api-calls.h:460
Local< Object > object_value
Definition: v8-fast-api-calls.h:459
double double_value
Definition: v8-fast-api-calls.h:457
const FastApiTypedArray< float > * float_ta_value
Definition: v8-fast-api-calls.h:466
void * pointer_value
Definition: v8-fast-api-calls.h:458
uint32_t uint32_value
Definition: v8-fast-api-calls.h:453
bool bool_value
Definition: v8-fast-api-calls.h:451
const FastApiTypedArray< int32_t > * int32_ta_value
Definition: v8-fast-api-calls.h:462
float float_value
Definition: v8-fast-api-calls.h:456
const FastApiTypedArray< uint32_t > * uint32_ta_value
Definition: v8-fast-api-calls.h:463
const FastApiTypedArray< uint8_t > * uint8_ta_value
Definition: v8-fast-api-calls.h:461
const FastApiTypedArray< double > * double_ta_value
Definition: v8-fast-api-calls.h:467
uint64_t uint64_value
Definition: v8-fast-api-calls.h:455
int32_t int32_value
Definition: v8-fast-api-calls.h:452
int64_t int64_value
Definition: v8-fast-api-calls.h:454
#define DEFINE_TYPE_INFO_TRAITS(CType, Enum)
Definition: v8-fast-api-calls.h:680
#define SPECIALIZE_GET_TYPE_INFO_HELPER_FOR_TA(T, Enum)
Definition: v8-fast-api-calls.h:712
#define PRIMITIVE_C_TYPES(V)
Definition: v8-fast-api-calls.h:686
#define TYPED_ARRAY_C_TYPES(V)
Definition: v8-fast-api-calls.h:725
#define SPECIALIZE_GET_TYPE_INFO_HELPER_FOR(T, Enum)
Definition: v8-fast-api-calls.h:664
#define ALL_C_TYPES(V)
Definition: v8-fast-api-calls.h:698
#define STATIC_ASSERT_IMPLIES(COND, ASSERTION, MSG)
Definition: v8-fast-api-calls.h:780
#define V8_EXPORT
Definition: v8config.h:762
#define V8_INLINE
Definition: v8config.h:477
#define V8_WARN_UNUSED_RESULT
Definition: v8config.h:637
#define V8_TRIVIAL_ABI
Definition: v8config.h:712