Skip to content

Commit 2797b91

Browse files
committed
fix: Fix JSIConverter<function>::fromJSI (1/2)
1 parent a8b9afc commit 2797b91

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

package/cpp/jsi/JSIConverter.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,9 @@ template <typename ReturnType, typename... Args>
104104
struct JSIConverter<std::function<ReturnType(Args...)>> {
105105
static std::function<ReturnType(Args...)> fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
106106
jsi::Function function = arg.asObject(runtime).asFunction(runtime);
107-
return [&runtime, function = std::move(function)] (Args... args) -> ReturnType {
108-
jsi::Value result = function.call(runtime, JSIConverter<Args>::toJSI(runtime, args)...);
107+
std::shared_ptr<jsi::Function> sharedFunction = std::make_shared<jsi::Function>(std::move(function));
108+
return [&runtime, sharedFunction] (Args... args) -> ReturnType {
109+
jsi::Value result = sharedFunction->call(runtime, JSIConverter<Args>::toJSI(runtime, args)...);
109110
if constexpr (std::is_same_v<ReturnType, void>) {
110111
return;
111112
} else {
@@ -114,19 +115,20 @@ struct JSIConverter<std::function<ReturnType(Args...)>> {
114115
};
115116
}
116117

117-
template<size_t... Is>
118+
/*template<size_t... Is>
118119
static jsi::Value callHybridFunction(const std::function<ReturnType(Args...)>& function, jsi::Runtime& runtime, const jsi::Value* args, std::index_sequence<Is...>) {
119120
ReturnType result = function(JSIConverter<Args>::fromJSI(runtime, args[Is])...);
120121
return JSIConverter<ReturnType>::toJSI(runtime, result);
121-
}
122+
}*/
122123
static jsi::Value toJSI(jsi::Runtime& runtime, std::function<ReturnType(Args...)> function) {
123-
jsi::HostFunctionType jsFunction = [function = std::move(function)] (jsi::Runtime& runtime,
124+
return jsi::Value::undefined();
125+
/*jsi::HostFunctionType jsFunction = [function = std::move(function)] (jsi::Runtime& runtime,
124126
const jsi::Value& thisValue,
125127
const jsi::Value* args,
126128
size_t count) -> jsi::Value {
127129
callHybridFunction(function, runtime, args, std::index_sequence_for<Args...>{});
128130
};
129-
return jsi::Function::createFromHostFunction(runtime, jsi::PropNameID::forUtf8(runtime, "hostFunction"), sizeof...(Args), jsFunction);
131+
return jsi::Function::createFromHostFunction(runtime, jsi::PropNameID::forUtf8(runtime, "hostFunction"), sizeof...(Args), jsFunction);*/
130132
}
131133
};
132134

0 commit comments

Comments
 (0)