@@ -19,32 +19,43 @@ template <typename Model> class ModelHostObject : public JsiHostObject {
1919 }
2020
2121 JSI_HOST_FUNCTION (forward) {
22-
2322 auto promise = promiseVendor.createPromise (
2423 [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+ }
3331
32+ // Do the asynchronous work
33+ std::thread ([this , promise = std::move (promise), args, &runtime]() {
3434 try {
3535 auto argsConverted = jsiconversion::createArgsTupleFromJsi (
3636 &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);
4443 });
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 ;
4553 } catch (const std::exception &e) {
4654 promise->reject (e.what ());
4755 return ;
56+ } catch (...) {
57+ promise->reject (" Unknown error" );
58+ return ;
4859 }
4960 }).detach ();
5061 });
0 commit comments