Skip to content

Commit 3535293

Browse files
authored
fix: remove a dangling reference exception handling (#357)
## Description Remove a dangling reference when handling exceptions in forward method in native C++. ### Type of change - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Documentation update (improves or adds clarity to existing documentation) ### Tested on - [x] iOS - [x] Android ### Checklist - [x] I have performed a self-review of my code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have updated the documentation accordingly - [x] My changes generate no new warnings
1 parent 7ec4592 commit 3535293

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

packages/react-native-executorch/common/rnexecutorch/host_objects/ModelHostObject.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,19 @@ template <typename Model> class ModelHostObject : public JsiHostObject {
6969
// breaks proper exception type checking. Remove when the
7070
// following change is present in our version:
7171
// https://github.com/facebook/react-native/commit/3132cc88dd46f95898a756456bebeeb6c248f20e
72-
callInvoker->invokeAsync(
73-
[&e, promise]() { promise->reject(e.what()); });
72+
callInvoker->invokeAsync([e = std::move(e), promise]() {
73+
promise->reject(e.what());
74+
});
7475
return;
7576
} catch (const jsi::JSError &e) {
76-
callInvoker->invokeAsync(
77-
[&e, promise]() { promise->reject(e.what()); });
77+
callInvoker->invokeAsync([e = std::move(e), promise]() {
78+
promise->reject(e.what());
79+
});
7880
return;
7981
} catch (const std::exception &e) {
80-
callInvoker->invokeAsync(
81-
[&e, promise]() { promise->reject(e.what()); });
82+
callInvoker->invokeAsync([e = std::move(e), promise]() {
83+
promise->reject(e.what());
84+
});
8285
return;
8386
} catch (...) {
8487
callInvoker->invokeAsync(

0 commit comments

Comments
 (0)