Skip to content

Commit 44f5989

Browse files
javachefacebook-github-bot
authored andcommitted
Mark AsyncCallback as noexcept (#40745)
Summary: Pull Request resolved: #40745 Changelog: [Internal] Reviewed By: NickGerleman Differential Revision: D49886196 fbshipit-source-id: 6b4fa888f6cffbf7863167396d13c4a00bf485a2
1 parent 5cec1ea commit 44f5989

File tree

21 files changed

+62
-50
lines changed

21 files changed

+62
-50
lines changed

packages/react-native/ReactAndroid/src/main/jni/react/jni/CatalystInstanceImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ CatalystInstanceImpl::getNativeMethodCallInvokerHolder() {
362362
: messageQueueThread_(messageQueueThread) {}
363363
void invokeAsync(
364364
const std::string& methodName,
365-
std::function<void()>&& work) override {
365+
std::function<void()>&& work) noexcept override {
366366
messageQueueThread_->runOnQueue(std::move(work));
367367
}
368368
void invokeSync(

packages/react-native/ReactCommon/callinvoker/ReactCommon/CallInvoker.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ using CallFunc = std::function<void()>;
2222
*/
2323
class CallInvoker {
2424
public:
25-
virtual void invokeAsync(CallFunc&& func) = 0;
26-
virtual void invokeAsync(SchedulerPriority /*priority*/, CallFunc&& func) {
25+
virtual void invokeAsync(CallFunc&& func) noexcept = 0;
26+
virtual void invokeAsync(
27+
SchedulerPriority /*priority*/,
28+
CallFunc&& func) noexcept {
2729
// When call with priority is not implemented, fall back to a regular async
2830
// execution
2931
invokeAsync(std::move(func));
@@ -34,7 +36,9 @@ class CallInvoker {
3436

3537
class NativeMethodCallInvoker {
3638
public:
37-
virtual void invokeAsync(const std::string& methodName, CallFunc&& func) = 0;
39+
virtual void invokeAsync(
40+
const std::string& methodName,
41+
CallFunc&& func) noexcept = 0;
3842
virtual void invokeSync(const std::string& methodName, CallFunc&& func) = 0;
3943
virtual ~NativeMethodCallInvoker() {}
4044
};

packages/react-native/ReactCommon/cxxreact/Instance.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ void Instance::JSCallInvoker::invokeSync(std::function<void()>&& work) {
263263
"Synchronous native -> JS calls are currently not supported.");
264264
}
265265

266-
void Instance::JSCallInvoker::invokeAsync(std::function<void()>&& work) {
266+
void Instance::JSCallInvoker::invokeAsync(
267+
std::function<void()>&& work) noexcept {
267268
std::scoped_lock guard(m_mutex);
268269

269270
/**
@@ -288,7 +289,8 @@ void Instance::JSCallInvoker::invokeAsync(std::function<void()>&& work) {
288289
scheduleAsync(std::move(work));
289290
}
290291

291-
void Instance::JSCallInvoker::scheduleAsync(std::function<void()>&& work) {
292+
void Instance::JSCallInvoker::scheduleAsync(
293+
std::function<void()>&& work) noexcept {
292294
if (auto strongNativeToJsBridge = m_nativeToJsBridge.lock()) {
293295
strongNativeToJsBridge->runOnExecutorQueue(
294296
[work = std::move(work)](JSExecutor* executor) {

packages/react-native/ReactCommon/cxxreact/Instance.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,12 @@ class RN_EXPORT Instance {
158158
bool m_shouldBuffer = true;
159159
std::list<std::function<void()>> m_workBuffer;
160160

161-
void scheduleAsync(std::function<void()>&& work);
161+
void scheduleAsync(std::function<void()>&& work) noexcept;
162162

163163
public:
164164
void setNativeToJsBridgeAndFlushCalls(
165165
std::weak_ptr<NativeToJsBridge> nativeToJsBridge);
166-
void invokeAsync(std::function<void()>&& work) override;
166+
void invokeAsync(std::function<void()>&& work) noexcept override;
167167
void invokeSync(std::function<void()>&& work) override;
168168
};
169169

packages/react-native/ReactCommon/cxxreact/NativeToJsBridge.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class JsToNativeBridge : public react::ExecutorDelegate {
9191
moduleId, methodId, std::move(args));
9292
}
9393

94-
void recordTurboModuleAsyncMethodCall() {
94+
void recordTurboModuleAsyncMethodCall() noexcept {
9595
m_batchHadNativeModuleOrTurboModuleCalls = true;
9696
}
9797

@@ -288,7 +288,7 @@ void NativeToJsBridge::destroy() {
288288
}
289289

290290
void NativeToJsBridge::runOnExecutorQueue(
291-
std::function<void(JSExecutor*)> task) {
291+
std::function<void(JSExecutor*)>&& task) noexcept {
292292
if (*m_destroyed) {
293293
return;
294294
}
@@ -326,7 +326,7 @@ NativeToJsBridge::getDecoratedNativeMethodCallInvoker(
326326

327327
void invokeAsync(
328328
const std::string& methodName,
329-
std::function<void()>&& func) override {
329+
std::function<void()>&& func) noexcept override {
330330
if (auto strongJsToNativeBridge = m_jsToNativeBridge.lock()) {
331331
strongJsToNativeBridge->recordTurboModuleAsyncMethodCall();
332332
}

packages/react-native/ReactCommon/cxxreact/NativeToJsBridge.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class NativeToJsBridge {
9797
*/
9898
void destroy();
9999

100-
void runOnExecutorQueue(std::function<void(JSExecutor*)> task);
100+
void runOnExecutorQueue(std::function<void(JSExecutor*)>&& task) noexcept;
101101

102102
/**
103103
* NativeMethodCallInvoker is used by TurboModules to schedule work on the

packages/react-native/ReactCommon/react/bridging/CallbackWrapper.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,19 @@ class CallbackWrapper : public LongLivedObject {
4545
allowRelease();
4646
}
4747

48-
jsi::Function& callback() {
48+
jsi::Function& callback() noexcept {
4949
return callback_;
5050
}
5151

52-
jsi::Runtime& runtime() {
52+
jsi::Runtime& runtime() noexcept {
5353
return runtime_;
5454
}
5555

56-
CallInvoker& jsInvoker() {
56+
CallInvoker& jsInvoker() noexcept {
5757
return *(jsInvoker_);
5858
}
5959

60-
std::shared_ptr<CallInvoker> jsInvokerPtr() {
60+
std::shared_ptr<CallInvoker> jsInvokerPtr() noexcept {
6161
return jsInvoker_;
6262
}
6363
};

packages/react-native/ReactCommon/react/bridging/Function.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,28 @@ class AsyncCallback {
2929
std::move(function),
3030
std::move(jsInvoker))) {}
3131

32-
void operator()(Args... args) const {
32+
void operator()(Args... args) const noexcept {
3333
call(std::forward<Args>(args)...);
3434
}
3535

36-
void call(Args... args) const {
36+
void call(Args... args) const noexcept {
3737
callWithArgs(std::nullopt, std::forward<Args>(args)...);
3838
}
3939

40-
void callWithPriority(SchedulerPriority priority, Args... args) const {
40+
void callWithPriority(SchedulerPriority priority, Args... args)
41+
const noexcept {
4142
callWithArgs(priority, std::forward<Args>(args)...);
4243
}
4344

44-
void call(
45-
std::function<void(jsi::Runtime&, jsi::Function&)>&& callImpl) const {
45+
void call(std::function<void(jsi::Runtime&, jsi::Function&)>&& callImpl)
46+
const noexcept {
4647
callWithFunction(std::nullopt, std::move(callImpl));
4748
}
4849

4950
void callWithPriority(
5051
SchedulerPriority priority,
51-
std::function<void(jsi::Runtime&, jsi::Function&)>&& callImpl) const {
52+
std::function<void(jsi::Runtime&, jsi::Function&)>&& callImpl)
53+
const noexcept {
5254
callWithFunction(priority, std::move(callImpl));
5355
}
5456

@@ -58,7 +60,7 @@ class AsyncCallback {
5860
std::shared_ptr<SyncCallback<void(Args...)>> callback_;
5961

6062
void callWithArgs(std::optional<SchedulerPriority> priority, Args... args)
61-
const {
63+
const noexcept {
6264
auto wrapper = callback_->wrapper_.lock();
6365
if (wrapper) {
6466
auto& jsInvoker = wrapper->jsInvoker();
@@ -78,7 +80,8 @@ class AsyncCallback {
7880

7981
void callWithFunction(
8082
std::optional<SchedulerPriority> priority,
81-
std::function<void(jsi::Runtime&, jsi::Function&)>&& callImpl) const {
83+
std::function<void(jsi::Runtime&, jsi::Function&)>&& callImpl)
84+
const noexcept {
8285
auto wrapper = callback_->wrapper_.lock();
8386
if (wrapper) {
8487
auto& jsInvoker = wrapper->jsInvoker();

packages/react-native/ReactCommon/react/bridging/tests/BridgingTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace facebook::react {
1717

1818
class TestCallInvoker : public CallInvoker {
1919
public:
20-
void invokeAsync(std::function<void()>&& fn) override {
20+
void invokeAsync(std::function<void()>&& fn) noexcept override {
2121
queue_.push_back(std::move(fn));
2222
}
2323

packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ bool isCreatingModule() const
112112

113113
public:
114114
ModuleNativeMethodCallInvoker(dispatch_queue_t methodQueue) : methodQueue_(methodQueue) {}
115-
void invokeAsync(const std::string &methodName, std::function<void()> &&work) override
115+
void invokeAsync(const std::string &methodName, std::function<void()> &&work) noexcept override
116116
{
117117
if (methodQueue_ == RCTJSThread) {
118118
work();

0 commit comments

Comments
 (0)