@@ -40,7 +40,8 @@ namespace margelo::nitro {
4040using namespace facebook ;
4141
4242// Unknown type (error)
43- template <typename ArgType, typename Enable = void > struct JSIConverter final {
43+ template <typename ArgType, typename Enable = void >
44+ struct JSIConverter final {
4445 JSIConverter () = delete ;
4546
4647 static inline ArgType fromJSI (jsi::Runtime&, const jsi::Value&) {
@@ -53,11 +54,13 @@ template <typename ArgType, typename Enable = void> struct JSIConverter final {
5354 }
5455
5556private:
56- template <typename > struct always_false : std::false_type {};
57+ template <typename >
58+ struct always_false : std::false_type {};
5759};
5860
5961// int <> number
60- template <> struct JSIConverter <int > {
62+ template <>
63+ struct JSIConverter <int > {
6164 static inline int fromJSI (jsi::Runtime&, const jsi::Value& arg) {
6265 return static_cast <int >(arg.asNumber ());
6366 }
@@ -67,7 +70,8 @@ template <> struct JSIConverter<int> {
6770};
6871
6972// std::monostate <> null
70- template <> struct JSIConverter <std::monostate> {
73+ template <>
74+ struct JSIConverter <std::monostate> {
7175 static inline std::monostate fromJSI (jsi::Runtime&, const jsi::Value& arg) {
7276 return std::monostate ();
7377 }
@@ -77,7 +81,8 @@ template <> struct JSIConverter<std::monostate> {
7781};
7882
7983// double <> number
80- template <> struct JSIConverter <double > {
84+ template <>
85+ struct JSIConverter <double > {
8186 static inline double fromJSI (jsi::Runtime&, const jsi::Value& arg) {
8287 return arg.asNumber ();
8388 }
@@ -87,7 +92,8 @@ template <> struct JSIConverter<double> {
8792};
8893
8994// float <> number
90- template <> struct JSIConverter <float > {
95+ template <>
96+ struct JSIConverter <float > {
9197 static inline float fromJSI (jsi::Runtime&, const jsi::Value& arg) {
9298 return static_cast <float >(arg.asNumber ());
9399 }
@@ -97,7 +103,8 @@ template <> struct JSIConverter<float> {
97103};
98104
99105// int64_t <> BigInt
100- template <> struct JSIConverter <int64_t > {
106+ template <>
107+ struct JSIConverter <int64_t > {
101108 static inline double fromJSI (jsi::Runtime& runtime, const jsi::Value& arg) {
102109 return arg.asBigInt (runtime).asInt64 (runtime);
103110 }
@@ -107,7 +114,8 @@ template <> struct JSIConverter<int64_t> {
107114};
108115
109116// uint64_t <> BigInt
110- template <> struct JSIConverter <uint64_t > {
117+ template <>
118+ struct JSIConverter <uint64_t > {
111119 static inline double fromJSI (jsi::Runtime& runtime, const jsi::Value& arg) {
112120 return arg.asBigInt (runtime).asUint64 (runtime);
113121 }
@@ -117,7 +125,8 @@ template <> struct JSIConverter<uint64_t> {
117125};
118126
119127// bool <> boolean
120- template <> struct JSIConverter <bool > {
128+ template <>
129+ struct JSIConverter <bool > {
121130 static inline bool fromJSI (jsi::Runtime&, const jsi::Value& arg) {
122131 return arg.asBool ();
123132 }
@@ -127,7 +136,8 @@ template <> struct JSIConverter<bool> {
127136};
128137
129138// std::string <> string
130- template <> struct JSIConverter <std::string> {
139+ template <>
140+ struct JSIConverter <std::string> {
131141 static inline std::string fromJSI (jsi::Runtime& runtime, const jsi::Value& arg) {
132142 return arg.asString (runtime).utf8 (runtime);
133143 }
@@ -137,7 +147,8 @@ template <> struct JSIConverter<std::string> {
137147};
138148
139149// std::optional<T> <> T | undefined
140- template <typename TInner> struct JSIConverter <std::optional<TInner>> {
150+ template <typename TInner>
151+ struct JSIConverter <std::optional<TInner>> {
141152 static inline std::optional<TInner> fromJSI (jsi::Runtime& runtime, const jsi::Value& arg) {
142153 if (arg.isUndefined () || arg.isNull ()) {
143154 return std::nullopt ;
@@ -155,7 +166,8 @@ template <typename TInner> struct JSIConverter<std::optional<TInner>> {
155166};
156167
157168// std::future<T> <> Promise<T>
158- template <typename TResult> struct JSIConverter <std::future<TResult>> {
169+ template <typename TResult>
170+ struct JSIConverter <std::future<TResult>> {
159171 static inline std::future<TResult> fromJSI (jsi::Runtime&, const jsi::Value&) {
160172 throw std::runtime_error (" Promise cannot be converted to a native type - it needs to be awaited first!" );
161173 }
@@ -210,16 +222,20 @@ template <typename TResult> struct JSIConverter<std::future<TResult>> {
210222 }
211223};
212224
213- template <typename T> struct future_traits {
225+ template <typename T>
226+ struct future_traits {
214227 using type = void ;
215228};
216- template <typename T> struct future_traits <std::future<T>> {
229+ template <typename T>
230+ struct future_traits <std::future<T>> {
217231 using type = T;
218232};
219- template <typename T> using future_traits_t = typename future_traits<std::remove_reference_t <T>>::type;
233+ template <typename T>
234+ using future_traits_t = typename future_traits<std::remove_reference_t <T>>::type;
220235
221236// [](Args...) -> T {} <> (Args...) => T
222- template <typename ReturnType, typename ... Args> struct JSIConverter <std::function<ReturnType(Args...)>> {
237+ template <typename ReturnType, typename ... Args>
238+ struct JSIConverter <std::function<ReturnType(Args...)>> {
223239 // std::future<T> -> T
224240 using ResultingType = future_traits_t <ReturnType>;
225241
@@ -311,7 +327,8 @@ template <typename ReturnType, typename... Args> struct JSIConverter<std::functi
311327};
312328
313329// std::vector<T> <> T[]
314- template <typename ElementType> struct JSIConverter <std::vector<ElementType>> {
330+ template <typename ElementType>
331+ struct JSIConverter <std::vector<ElementType>> {
315332 static inline std::vector<ElementType> fromJSI (jsi::Runtime& runtime, const jsi::Value& arg) {
316333 jsi::Array array = arg.asObject (runtime).asArray (runtime);
317334 size_t length = array.size (runtime);
@@ -335,7 +352,8 @@ template <typename ElementType> struct JSIConverter<std::vector<ElementType>> {
335352};
336353
337354// std::unordered_map<std::string, T> <> Record<string, T>
338- template <typename ValueType> struct JSIConverter <std::unordered_map<std::string, ValueType>> {
355+ template <typename ValueType>
356+ struct JSIConverter <std::unordered_map<std::string, ValueType>> {
339357 static inline std::unordered_map<std::string, ValueType> fromJSI (jsi::Runtime& runtime, const jsi::Value& arg) {
340358 jsi::Object object = arg.asObject (runtime);
341359 jsi::Array propertyNames = object.getPropertyNames (runtime);
@@ -361,7 +379,8 @@ template <typename ValueType> struct JSIConverter<std::unordered_map<std::string
361379};
362380
363381// std::tuple<A, B, C> <> [A, B, C]
364- template <typename ... Types> struct JSIConverter <std::tuple<Types...>> {
382+ template <typename ... Types>
383+ struct JSIConverter <std::tuple<Types...>> {
365384 static inline std::tuple<Types...> fromJSI (jsi::Runtime& runtime, const jsi::Value& value) {
366385 jsi::Object object = value.asObject (runtime);
367386 jsi::Array array = object.asArray (runtime);
@@ -396,11 +415,14 @@ template <typename... Types> struct JSIConverter<std::tuple<Types...>> {
396415};
397416
398417// Helper struct to check if a type is present in a parameter pack
399- template <typename T, typename ... Types> struct is_in_pack : std::disjunction<std::is_same<T, Types>...> {};
400- template <typename T, typename ... Types> inline constexpr bool is_in_pack_v = is_in_pack<T, Types...>::value;
418+ template <typename T, typename ... Types>
419+ struct is_in_pack : std::disjunction<std::is_same<T, Types>...> {};
420+ template <typename T, typename ... Types>
421+ inline constexpr bool is_in_pack_v = is_in_pack<T, Types...>::value;
401422
402423// std::variant<A, B, C> <> A | B | C
403- template <typename ... Types> struct JSIConverter <std::variant<Types...>> {
424+ template <typename ... Types>
425+ struct JSIConverter <std::variant<Types...>> {
404426 static inline std::variant<Types...> fromJSI (jsi::Runtime& runtime, const jsi::Value& value) {
405427 if (value.isNull ()) {
406428 if constexpr (is_in_pack_v<std::monostate, Types...>) {
@@ -465,7 +487,8 @@ template <typename... Types> struct JSIConverter<std::variant<Types...>> {
465487};
466488
467489// AnyValue <> Record<K, V>
468- template <> struct JSIConverter <AnyValue> {
490+ template <>
491+ struct JSIConverter <AnyValue> {
469492 static inline AnyValue fromJSI (jsi::Runtime& runtime, const jsi::Value& arg) {
470493 return JSIConverter<AnyValue::variant>::fromJSI (runtime, arg);
471494 }
@@ -475,7 +498,8 @@ template <> struct JSIConverter<AnyValue> {
475498};
476499
477500// AnyMap <> Record<K, V>
478- template <> struct JSIConverter <std::shared_ptr<AnyMap>> {
501+ template <>
502+ struct JSIConverter <std::shared_ptr<AnyMap>> {
479503 static inline std::shared_ptr<AnyMap> fromJSI (jsi::Runtime& runtime, const jsi::Value& arg) {
480504 jsi::Object object = arg.asObject (runtime);
481505 jsi::Array propNames = object.getPropertyNames (runtime);
@@ -500,7 +524,8 @@ template <> struct JSIConverter<std::shared_ptr<AnyMap>> {
500524};
501525
502526// MutableBuffer <> ArrayBuffer
503- template <> struct JSIConverter <std::shared_ptr<jsi::MutableBuffer>> {
527+ template <>
528+ struct JSIConverter <std::shared_ptr<jsi::MutableBuffer>> {
504529 static inline std::shared_ptr<ArrayBuffer> fromJSI (jsi::Runtime& runtime, const jsi::Value& arg) {
505530 jsi::Object object = arg.asObject (runtime);
506531 if (!object.isArrayBuffer (runtime)) [[unlikely]] {
@@ -515,9 +540,12 @@ template <> struct JSIConverter<std::shared_ptr<jsi::MutableBuffer>> {
515540};
516541
517542// HybridObject <> {}
518- template <typename T> struct is_shared_ptr_to_host_object : std::false_type {};
519- template <typename T> struct is_shared_ptr_to_host_object <std::shared_ptr<T>> : std::is_base_of<jsi::HostObject, T> {};
520- template <typename T> struct JSIConverter <T, std::enable_if_t <is_shared_ptr_to_host_object<T>::value>> {
543+ template <typename T>
544+ struct is_shared_ptr_to_host_object : std::false_type {};
545+ template <typename T>
546+ struct is_shared_ptr_to_host_object <std::shared_ptr<T>> : std::is_base_of<jsi::HostObject, T> {};
547+ template <typename T>
548+ struct JSIConverter <T, std::enable_if_t <is_shared_ptr_to_host_object<T>::value>> {
521549 using TPointee = typename T::element_type;
522550
523551 static inline T fromJSI (jsi::Runtime& runtime, const jsi::Value& arg) {
@@ -564,9 +592,12 @@ template <typename T> struct JSIConverter<T, std::enable_if_t<is_shared_ptr_to_h
564592};
565593
566594// NativeState <> {}
567- template <typename T> struct is_shared_ptr_to_native_state : std::false_type {};
568- template <typename T> struct is_shared_ptr_to_native_state <std::shared_ptr<T>> : std::is_base_of<jsi::NativeState, T> {};
569- template <typename T> struct JSIConverter <T, std::enable_if_t <is_shared_ptr_to_native_state<T>::value>> {
595+ template <typename T>
596+ struct is_shared_ptr_to_native_state : std::false_type {};
597+ template <typename T>
598+ struct is_shared_ptr_to_native_state <std::shared_ptr<T>> : std::is_base_of<jsi::NativeState, T> {};
599+ template <typename T>
600+ struct JSIConverter <T, std::enable_if_t <is_shared_ptr_to_native_state<T>::value>> {
570601 using TPointee = typename T::element_type;
571602
572603 static inline T fromJSI (jsi::Runtime& runtime, const jsi::Value& arg) {
0 commit comments