@@ -26,14 +26,12 @@ class JsiDispatcher {
26
26
* @return A new dispatch function for running the provided function with
27
27
* error handling
28
28
*/
29
- static std::function<void ()> createDispatcher (
30
- jsi::Runtime &runtime, std::shared_ptr<JsiWrapper> thisValuePtr,
31
- const jsi::HostFunctionType &functionPtr,
32
- const std::function<void (std::shared_ptr<JsiWrapper>)> onSuccess,
33
- const std::function<void(const char *)> onError) {
29
+ static std::function<void ()> createDispatcher (jsi::Runtime& runtime, std::shared_ptr<JsiWrapper> thisValuePtr,
30
+ const jsi::HostFunctionType& functionPtr,
31
+ const std::function<void (std::shared_ptr<JsiWrapper>)> onSuccess,
32
+ const std::function<void(const char *)> onError) {
34
33
std::vector<std::shared_ptr<JsiWrapper>> emptyArgs;
35
- return createDispatcher (runtime, thisValuePtr, functionPtr, emptyArgs,
36
- onSuccess, onError);
34
+ return createDispatcher (runtime, thisValuePtr, functionPtr, emptyArgs, onSuccess, onError);
37
35
}
38
36
39
37
/* *
@@ -48,38 +46,31 @@ class JsiDispatcher {
48
46
* @return A new dispatch function for running the provided function with
49
47
* error handling
50
48
*/
51
- static std::function<void ()> createDispatcher (
52
- jsi::Runtime &runtime, std::shared_ptr<JsiWrapper> thisValuePtr,
53
- const jsi::HostFunctionType &functionPtr,
54
- const std::vector<std::shared_ptr<JsiWrapper>> &arguments,
55
- const std::function<void (std::shared_ptr<JsiWrapper>)> onSuccess,
56
- const std::function<void(const char *)> onError) {
49
+ static std::function<void ()> createDispatcher (jsi::Runtime& runtime, std::shared_ptr<JsiWrapper> thisValuePtr,
50
+ const jsi::HostFunctionType& functionPtr,
51
+ const std::vector<std::shared_ptr<JsiWrapper>>& arguments,
52
+ const std::function<void (std::shared_ptr<JsiWrapper>)> onSuccess,
53
+ const std::function<void(const char *)> onError) {
57
54
58
55
// Set up the callback to run on the correct runtime thread
59
- return [&runtime, arguments, thisValuePtr, functionPtr, onSuccess,
60
- onError]() {
56
+ return [&runtime, arguments, thisValuePtr, functionPtr, onSuccess, onError]() {
61
57
try {
62
58
// Define return value
63
59
jsi::Value retVal = jsi::Value::undefined ();
64
60
65
61
// Arguments
66
- jsi::Value * args = new jsi::Value[arguments.size ()];
62
+ jsi::Value* args = new jsi::Value[arguments.size ()];
67
63
for (int i = 0 ; i < arguments.size (); ++i) {
68
64
args[i] = JsiWrapper::unwrap (runtime, arguments[i]);
69
65
}
70
66
71
67
// Call with this or not?
72
- if (thisValuePtr != nullptr &&
73
- thisValuePtr->getType () != JsiWrapperType::Null &&
68
+ if (thisValuePtr != nullptr && thisValuePtr->getType () != JsiWrapperType::Null &&
74
69
thisValuePtr->getType () != JsiWrapperType::Undefined) {
75
- retVal = functionPtr (
76
- runtime,
77
- JsiWrapper::unwrap (runtime, thisValuePtr).asObject (runtime),
78
- static_cast <const jsi::Value *>(args), arguments.size ());
79
- } else {
80
- retVal = functionPtr (runtime, nullptr ,
81
- static_cast <const jsi::Value *>(args),
70
+ retVal = functionPtr (runtime, JsiWrapper::unwrap (runtime, thisValuePtr).asObject (runtime), static_cast <const jsi::Value*>(args),
82
71
arguments.size ());
72
+ } else {
73
+ retVal = functionPtr (runtime, nullptr , static_cast <const jsi::Value*>(args), arguments.size ());
83
74
}
84
75
85
76
delete[] args;
@@ -88,13 +79,13 @@ class JsiDispatcher {
88
79
if (onSuccess != nullptr ) {
89
80
onSuccess (JsiWrapper::wrap (runtime, retVal));
90
81
}
91
- } catch (const jsi::JSError & err) {
82
+ } catch (const jsi::JSError& err) {
92
83
if (onError != nullptr )
93
84
onError (err.getMessage ().c_str ());
94
- } catch (const std::exception & err) {
85
+ } catch (const std::exception & err) {
95
86
if (onError != nullptr )
96
87
onError (err.what ());
97
- } catch (const std::runtime_error & err) {
88
+ } catch (const std::runtime_error& err) {
98
89
if (onError != nullptr )
99
90
onError (err.what ());
100
91
} catch (...) {
0 commit comments