@@ -19,32 +19,43 @@ template <typename Model> class ModelHostObject : public JsiHostObject {
19
19
}
20
20
21
21
JSI_HOST_FUNCTION (forward) {
22
-
23
22
auto promise = promiseVendor.createPromise (
24
23
[this , count, args, &runtime](std::shared_ptr<Promise> promise) {
25
- std::thread ([this , promise = std::move (promise), count, args,
26
- &runtime]() {
27
- constexpr std::size_t forwardArgCount =
28
- jsiconversion::getArgumentCount (&Model::forward);
29
- if (forwardArgCount != count) {
30
- promise->reject (" Argument count mismatch" );
31
- return ;
32
- }
24
+ // Check if the function call matches the expected number of arguments
25
+ constexpr std::size_t forwardArgCount =
26
+ jsiconversion::getArgumentCount (&Model::forward);
27
+ if (forwardArgCount != count) {
28
+ promise->reject (" Argument count mismatch" );
29
+ return ;
30
+ }
33
31
32
+ // Do the asynchronous work
33
+ std::thread ([this , promise = std::move (promise), args, &runtime]() {
34
34
try {
35
35
auto argsConverted = jsiconversion::createArgsTupleFromJsi (
36
36
&Model::forward, args, runtime);
37
- promise->resolve ([this , argsConverted = std::move (argsConverted)](
38
- jsi::Runtime &runtime) {
39
- auto result = std::apply (
40
- std::bind_front (&Model::forward, model), argsConverted);
41
- auto resultValue =
42
- jsiconversion::getJsiValue (std::move (result), runtime);
43
- return resultValue;
37
+ auto result = std::apply (std::bind_front (&Model::forward, model),
38
+ argsConverted);
39
+
40
+ promise->resolve ([result =
41
+ std::move (result)](jsi::Runtime &runtime) {
42
+ return jsiconversion::getJsiValue (std::move (result), runtime);
44
43
});
44
+ } catch (const std::runtime_error &e) {
45
+ // This catch should be merged with the next one
46
+ // (std::runtime_error inherits from std::exception) HOWEVER react
47
+ // native has broken RTTI which breaks proper exception type
48
+ // checking. Remove when the following change is present in our
49
+ // version:
50
+ // https://github.com/facebook/react-native/commit/3132cc88dd46f95898a756456bebeeb6c248f20e
51
+ promise->reject (e.what ());
52
+ return ;
45
53
} catch (const std::exception &e) {
46
54
promise->reject (e.what ());
47
55
return ;
56
+ } catch (...) {
57
+ promise->reject (" Unknown error" );
58
+ return ;
48
59
}
49
60
}).detach ();
50
61
});
0 commit comments