[fastcall] Expose CTypeInfoBuilder publicly

This CL exposes the helper class publicly to facilitate sequences
implementation, as discussed in
https://chromium-review.googlesource.com/c/chromium/src/+/3111815.

Bug: chromium:1052746
Change-Id: I3f3c24412c022014fc15b563201a63ee0691f6bc
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3236549
Auto-Submit: Maya Lekova <mslekova@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77568}
This commit is contained in:
Maya Lekova 2021-10-21 14:46:55 +02:00 committed by V8 LUCI CQ
parent 1ca9a77095
commit dff140dd25
3 changed files with 42 additions and 32 deletions

View File

@ -678,17 +678,19 @@ struct TypeInfoHelper<FastApiCallbackOptions&> {
#define STATIC_ASSERT_IMPLIES(COND, ASSERTION, MSG) \
static_assert(((COND) == 0) || (ASSERTION), MSG)
} // namespace internal
template <typename T, CTypeInfo::Flags... Flags>
class CTypeInfoBuilder {
class V8_EXPORT CTypeInfoBuilder {
public:
using BaseType = T;
static constexpr CTypeInfo Build() {
constexpr CTypeInfo::Flags kFlags =
MergeFlags(TypeInfoHelper<T>::Flags(), Flags...);
constexpr CTypeInfo::Type kType = TypeInfoHelper<T>::Type();
MergeFlags(internal::TypeInfoHelper<T>::Flags(), Flags...);
constexpr CTypeInfo::Type kType = internal::TypeInfoHelper<T>::Type();
constexpr CTypeInfo::SequenceType kSequenceType =
TypeInfoHelper<T>::SequenceType();
internal::TypeInfoHelper<T>::SequenceType();
STATIC_ASSERT_IMPLIES(
uint8_t(kFlags) & uint8_t(CTypeInfo::Flags::kAllowSharedBit),
@ -716,8 +718,8 @@ class CTypeInfoBuilder {
"TypedArrays are only supported from primitive types or void.");
// Return the same type with the merged flags.
return CTypeInfo(TypeInfoHelper<T>::Type(),
TypeInfoHelper<T>::SequenceType(), kFlags);
return CTypeInfo(internal::TypeInfoHelper<T>::Type(),
internal::TypeInfoHelper<T>::SequenceType(), kFlags);
}
private:
@ -729,6 +731,7 @@ class CTypeInfoBuilder {
static constexpr CTypeInfo::Flags MergeFlags() { return CTypeInfo::Flags(0); }
};
namespace internal {
template <typename RetBuilder, typename... ArgBuilders>
class CFunctionBuilderWithFunction {
public:
@ -858,24 +861,28 @@ bool V8_EXPORT V8_WARN_UNUSED_RESULT TryToCopyAndConvertArrayToCppBuffer(
Local<Array> src, T* dst, uint32_t max_length);
template <>
bool V8_EXPORT V8_WARN_UNUSED_RESULT TryToCopyAndConvertArrayToCppBuffer<
internal::CTypeInfoBuilder<int32_t>::Build().GetId(), int32_t>(
Local<Array> src, int32_t* dst, uint32_t max_length);
bool V8_EXPORT V8_WARN_UNUSED_RESULT
TryToCopyAndConvertArrayToCppBuffer<CTypeInfoBuilder<int32_t>::Build().GetId(),
int32_t>(Local<Array> src, int32_t* dst,
uint32_t max_length);
template <>
bool V8_EXPORT V8_WARN_UNUSED_RESULT TryToCopyAndConvertArrayToCppBuffer<
internal::CTypeInfoBuilder<uint32_t>::Build().GetId(), uint32_t>(
Local<Array> src, uint32_t* dst, uint32_t max_length);
bool V8_EXPORT V8_WARN_UNUSED_RESULT
TryToCopyAndConvertArrayToCppBuffer<CTypeInfoBuilder<uint32_t>::Build().GetId(),
uint32_t>(Local<Array> src, uint32_t* dst,
uint32_t max_length);
template <>
bool V8_EXPORT V8_WARN_UNUSED_RESULT TryToCopyAndConvertArrayToCppBuffer<
internal::CTypeInfoBuilder<float>::Build().GetId(), float>(
Local<Array> src, float* dst, uint32_t max_length);
bool V8_EXPORT V8_WARN_UNUSED_RESULT
TryToCopyAndConvertArrayToCppBuffer<CTypeInfoBuilder<float>::Build().GetId(),
float>(Local<Array> src, float* dst,
uint32_t max_length);
template <>
bool V8_EXPORT V8_WARN_UNUSED_RESULT TryToCopyAndConvertArrayToCppBuffer<
internal::CTypeInfoBuilder<double>::Build().GetId(), double>(
Local<Array> src, double* dst, uint32_t max_length);
bool V8_EXPORT V8_WARN_UNUSED_RESULT
TryToCopyAndConvertArrayToCppBuffer<CTypeInfoBuilder<double>::Build().GetId(),
double>(Local<Array> src, double* dst,
uint32_t max_length);
} // namespace v8

View File

@ -10531,9 +10531,10 @@ bool ConvertDouble(double d) {
} // namespace internal
template <>
bool V8_EXPORT V8_WARN_UNUSED_RESULT TryToCopyAndConvertArrayToCppBuffer<
internal::CTypeInfoBuilder<int32_t>::Build().GetId(), int32_t>(
Local<Array> src, int32_t* dst, uint32_t max_length) {
bool V8_EXPORT V8_WARN_UNUSED_RESULT
TryToCopyAndConvertArrayToCppBuffer<CTypeInfoBuilder<int32_t>::Build().GetId(),
int32_t>(Local<Array> src, int32_t* dst,
uint32_t max_length) {
return CopyAndConvertArrayToCppBuffer<
CTypeInfo(CTypeInfo::Type::kInt32, CTypeInfo::SequenceType::kIsSequence)
.GetId(),
@ -10541,9 +10542,10 @@ bool V8_EXPORT V8_WARN_UNUSED_RESULT TryToCopyAndConvertArrayToCppBuffer<
}
template <>
bool V8_EXPORT V8_WARN_UNUSED_RESULT TryToCopyAndConvertArrayToCppBuffer<
internal::CTypeInfoBuilder<uint32_t>::Build().GetId(), uint32_t>(
Local<Array> src, uint32_t* dst, uint32_t max_length) {
bool V8_EXPORT V8_WARN_UNUSED_RESULT
TryToCopyAndConvertArrayToCppBuffer<CTypeInfoBuilder<uint32_t>::Build().GetId(),
uint32_t>(Local<Array> src, uint32_t* dst,
uint32_t max_length) {
return CopyAndConvertArrayToCppBuffer<
CTypeInfo(CTypeInfo::Type::kUint32, CTypeInfo::SequenceType::kIsSequence)
.GetId(),
@ -10551,9 +10553,10 @@ bool V8_EXPORT V8_WARN_UNUSED_RESULT TryToCopyAndConvertArrayToCppBuffer<
}
template <>
bool V8_EXPORT V8_WARN_UNUSED_RESULT TryToCopyAndConvertArrayToCppBuffer<
internal::CTypeInfoBuilder<float>::Build().GetId(), float>(
Local<Array> src, float* dst, uint32_t max_length) {
bool V8_EXPORT V8_WARN_UNUSED_RESULT
TryToCopyAndConvertArrayToCppBuffer<CTypeInfoBuilder<float>::Build().GetId(),
float>(Local<Array> src, float* dst,
uint32_t max_length) {
return CopyAndConvertArrayToCppBuffer<
CTypeInfo(CTypeInfo::Type::kFloat32, CTypeInfo::SequenceType::kIsSequence)
.GetId(),
@ -10561,9 +10564,10 @@ bool V8_EXPORT V8_WARN_UNUSED_RESULT TryToCopyAndConvertArrayToCppBuffer<
}
template <>
bool V8_EXPORT V8_WARN_UNUSED_RESULT TryToCopyAndConvertArrayToCppBuffer<
internal::CTypeInfoBuilder<double>::Build().GetId(), double>(
Local<Array> src, double* dst, uint32_t max_length) {
bool V8_EXPORT V8_WARN_UNUSED_RESULT
TryToCopyAndConvertArrayToCppBuffer<CTypeInfoBuilder<double>::Build().GetId(),
double>(Local<Array> src, double* dst,
uint32_t max_length) {
return CopyAndConvertArrayToCppBuffer<
CTypeInfo(CTypeInfo::Type::kFloat64, CTypeInfo::SequenceType::kIsSequence)
.GetId(),

View File

@ -120,8 +120,7 @@ class FastCApiObject {
Type buffer[1024];
bool result = TryToCopyAndConvertArrayToCppBuffer<
i::CTypeInfoBuilder<Type>::Build().GetId(), Type>(seq_arg, buffer,
1024);
CTypeInfoBuilder<Type>::Build().GetId(), Type>(seq_arg, buffer, 1024);
if (!result) {
options.fallback = 1;
return 0;