mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Mark AsyncCallback as noexcept (#40745)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/40745 Changelog: [Internal] Reviewed By: NickGerleman Differential Revision: D49886196 fbshipit-source-id: 6b4fa888f6cffbf7863167396d13c4a00bf485a2
This commit is contained in:
committed by
Facebook GitHub Bot
parent
5cec1eaabf
commit
44f5989c3b
@@ -362,7 +362,7 @@ CatalystInstanceImpl::getNativeMethodCallInvokerHolder() {
|
||||
: messageQueueThread_(messageQueueThread) {}
|
||||
void invokeAsync(
|
||||
const std::string& methodName,
|
||||
std::function<void()>&& work) override {
|
||||
std::function<void()>&& work) noexcept override {
|
||||
messageQueueThread_->runOnQueue(std::move(work));
|
||||
}
|
||||
void invokeSync(
|
||||
|
||||
@@ -22,8 +22,10 @@ using CallFunc = std::function<void()>;
|
||||
*/
|
||||
class CallInvoker {
|
||||
public:
|
||||
virtual void invokeAsync(CallFunc&& func) = 0;
|
||||
virtual void invokeAsync(SchedulerPriority /*priority*/, CallFunc&& func) {
|
||||
virtual void invokeAsync(CallFunc&& func) noexcept = 0;
|
||||
virtual void invokeAsync(
|
||||
SchedulerPriority /*priority*/,
|
||||
CallFunc&& func) noexcept {
|
||||
// When call with priority is not implemented, fall back to a regular async
|
||||
// execution
|
||||
invokeAsync(std::move(func));
|
||||
@@ -34,7 +36,9 @@ class CallInvoker {
|
||||
|
||||
class NativeMethodCallInvoker {
|
||||
public:
|
||||
virtual void invokeAsync(const std::string& methodName, CallFunc&& func) = 0;
|
||||
virtual void invokeAsync(
|
||||
const std::string& methodName,
|
||||
CallFunc&& func) noexcept = 0;
|
||||
virtual void invokeSync(const std::string& methodName, CallFunc&& func) = 0;
|
||||
virtual ~NativeMethodCallInvoker() {}
|
||||
};
|
||||
|
||||
@@ -263,7 +263,8 @@ void Instance::JSCallInvoker::invokeSync(std::function<void()>&& work) {
|
||||
"Synchronous native -> JS calls are currently not supported.");
|
||||
}
|
||||
|
||||
void Instance::JSCallInvoker::invokeAsync(std::function<void()>&& work) {
|
||||
void Instance::JSCallInvoker::invokeAsync(
|
||||
std::function<void()>&& work) noexcept {
|
||||
std::scoped_lock guard(m_mutex);
|
||||
|
||||
/**
|
||||
@@ -288,7 +289,8 @@ void Instance::JSCallInvoker::invokeAsync(std::function<void()>&& work) {
|
||||
scheduleAsync(std::move(work));
|
||||
}
|
||||
|
||||
void Instance::JSCallInvoker::scheduleAsync(std::function<void()>&& work) {
|
||||
void Instance::JSCallInvoker::scheduleAsync(
|
||||
std::function<void()>&& work) noexcept {
|
||||
if (auto strongNativeToJsBridge = m_nativeToJsBridge.lock()) {
|
||||
strongNativeToJsBridge->runOnExecutorQueue(
|
||||
[work = std::move(work)](JSExecutor* executor) {
|
||||
|
||||
@@ -158,12 +158,12 @@ class RN_EXPORT Instance {
|
||||
bool m_shouldBuffer = true;
|
||||
std::list<std::function<void()>> m_workBuffer;
|
||||
|
||||
void scheduleAsync(std::function<void()>&& work);
|
||||
void scheduleAsync(std::function<void()>&& work) noexcept;
|
||||
|
||||
public:
|
||||
void setNativeToJsBridgeAndFlushCalls(
|
||||
std::weak_ptr<NativeToJsBridge> nativeToJsBridge);
|
||||
void invokeAsync(std::function<void()>&& work) override;
|
||||
void invokeAsync(std::function<void()>&& work) noexcept override;
|
||||
void invokeSync(std::function<void()>&& work) override;
|
||||
};
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ class JsToNativeBridge : public react::ExecutorDelegate {
|
||||
moduleId, methodId, std::move(args));
|
||||
}
|
||||
|
||||
void recordTurboModuleAsyncMethodCall() {
|
||||
void recordTurboModuleAsyncMethodCall() noexcept {
|
||||
m_batchHadNativeModuleOrTurboModuleCalls = true;
|
||||
}
|
||||
|
||||
@@ -288,7 +288,7 @@ void NativeToJsBridge::destroy() {
|
||||
}
|
||||
|
||||
void NativeToJsBridge::runOnExecutorQueue(
|
||||
std::function<void(JSExecutor*)> task) {
|
||||
std::function<void(JSExecutor*)>&& task) noexcept {
|
||||
if (*m_destroyed) {
|
||||
return;
|
||||
}
|
||||
@@ -326,7 +326,7 @@ NativeToJsBridge::getDecoratedNativeMethodCallInvoker(
|
||||
|
||||
void invokeAsync(
|
||||
const std::string& methodName,
|
||||
std::function<void()>&& func) override {
|
||||
std::function<void()>&& func) noexcept override {
|
||||
if (auto strongJsToNativeBridge = m_jsToNativeBridge.lock()) {
|
||||
strongJsToNativeBridge->recordTurboModuleAsyncMethodCall();
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ class NativeToJsBridge {
|
||||
*/
|
||||
void destroy();
|
||||
|
||||
void runOnExecutorQueue(std::function<void(JSExecutor*)> task);
|
||||
void runOnExecutorQueue(std::function<void(JSExecutor*)>&& task) noexcept;
|
||||
|
||||
/**
|
||||
* NativeMethodCallInvoker is used by TurboModules to schedule work on the
|
||||
|
||||
@@ -45,19 +45,19 @@ class CallbackWrapper : public LongLivedObject {
|
||||
allowRelease();
|
||||
}
|
||||
|
||||
jsi::Function& callback() {
|
||||
jsi::Function& callback() noexcept {
|
||||
return callback_;
|
||||
}
|
||||
|
||||
jsi::Runtime& runtime() {
|
||||
jsi::Runtime& runtime() noexcept {
|
||||
return runtime_;
|
||||
}
|
||||
|
||||
CallInvoker& jsInvoker() {
|
||||
CallInvoker& jsInvoker() noexcept {
|
||||
return *(jsInvoker_);
|
||||
}
|
||||
|
||||
std::shared_ptr<CallInvoker> jsInvokerPtr() {
|
||||
std::shared_ptr<CallInvoker> jsInvokerPtr() noexcept {
|
||||
return jsInvoker_;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -29,26 +29,28 @@ class AsyncCallback {
|
||||
std::move(function),
|
||||
std::move(jsInvoker))) {}
|
||||
|
||||
void operator()(Args... args) const {
|
||||
void operator()(Args... args) const noexcept {
|
||||
call(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
void call(Args... args) const {
|
||||
void call(Args... args) const noexcept {
|
||||
callWithArgs(std::nullopt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
void callWithPriority(SchedulerPriority priority, Args... args) const {
|
||||
void callWithPriority(SchedulerPriority priority, Args... args)
|
||||
const noexcept {
|
||||
callWithArgs(priority, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
void call(
|
||||
std::function<void(jsi::Runtime&, jsi::Function&)>&& callImpl) const {
|
||||
void call(std::function<void(jsi::Runtime&, jsi::Function&)>&& callImpl)
|
||||
const noexcept {
|
||||
callWithFunction(std::nullopt, std::move(callImpl));
|
||||
}
|
||||
|
||||
void callWithPriority(
|
||||
SchedulerPriority priority,
|
||||
std::function<void(jsi::Runtime&, jsi::Function&)>&& callImpl) const {
|
||||
std::function<void(jsi::Runtime&, jsi::Function&)>&& callImpl)
|
||||
const noexcept {
|
||||
callWithFunction(priority, std::move(callImpl));
|
||||
}
|
||||
|
||||
@@ -58,7 +60,7 @@ class AsyncCallback {
|
||||
std::shared_ptr<SyncCallback<void(Args...)>> callback_;
|
||||
|
||||
void callWithArgs(std::optional<SchedulerPriority> priority, Args... args)
|
||||
const {
|
||||
const noexcept {
|
||||
auto wrapper = callback_->wrapper_.lock();
|
||||
if (wrapper) {
|
||||
auto& jsInvoker = wrapper->jsInvoker();
|
||||
@@ -78,7 +80,8 @@ class AsyncCallback {
|
||||
|
||||
void callWithFunction(
|
||||
std::optional<SchedulerPriority> priority,
|
||||
std::function<void(jsi::Runtime&, jsi::Function&)>&& callImpl) const {
|
||||
std::function<void(jsi::Runtime&, jsi::Function&)>&& callImpl)
|
||||
const noexcept {
|
||||
auto wrapper = callback_->wrapper_.lock();
|
||||
if (wrapper) {
|
||||
auto& jsInvoker = wrapper->jsInvoker();
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace facebook::react {
|
||||
|
||||
class TestCallInvoker : public CallInvoker {
|
||||
public:
|
||||
void invokeAsync(std::function<void()>&& fn) override {
|
||||
void invokeAsync(std::function<void()>&& fn) noexcept override {
|
||||
queue_.push_back(std::move(fn));
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -112,7 +112,7 @@ class ModuleNativeMethodCallInvoker : public NativeMethodCallInvoker {
|
||||
|
||||
public:
|
||||
ModuleNativeMethodCallInvoker(dispatch_queue_t methodQueue) : methodQueue_(methodQueue) {}
|
||||
void invokeAsync(const std::string &methodName, std::function<void()> &&work) override
|
||||
void invokeAsync(const std::string &methodName, std::function<void()> &&work) noexcept override
|
||||
{
|
||||
if (methodQueue_ == RCTJSThread) {
|
||||
work();
|
||||
|
||||
+5
-5
@@ -21,7 +21,7 @@ RuntimeScheduler::RuntimeScheduler(
|
||||
std::function<RuntimeSchedulerTimePoint()> now)
|
||||
: runtimeExecutor_(std::move(runtimeExecutor)), now_(std::move(now)) {}
|
||||
|
||||
void RuntimeScheduler::scheduleWork(RawCallback callback) const {
|
||||
void RuntimeScheduler::scheduleWork(RawCallback&& callback) const noexcept {
|
||||
SystraceSection s("RuntimeScheduler::scheduleWork");
|
||||
|
||||
runtimeAccessRequests_ += 1;
|
||||
@@ -37,7 +37,7 @@ void RuntimeScheduler::scheduleWork(RawCallback callback) const {
|
||||
|
||||
std::shared_ptr<Task> RuntimeScheduler::scheduleTask(
|
||||
SchedulerPriority priority,
|
||||
jsi::Function callback) {
|
||||
jsi::Function&& callback) noexcept {
|
||||
auto expirationTime = now_() + timeoutForSchedulerPriority(priority);
|
||||
auto task =
|
||||
std::make_shared<Task>(priority, std::move(callback), expirationTime);
|
||||
@@ -50,7 +50,7 @@ std::shared_ptr<Task> RuntimeScheduler::scheduleTask(
|
||||
|
||||
std::shared_ptr<Task> RuntimeScheduler::scheduleTask(
|
||||
SchedulerPriority priority,
|
||||
RawCallback callback) {
|
||||
RawCallback&& callback) noexcept {
|
||||
auto expirationTime = now_() + timeoutForSchedulerPriority(priority);
|
||||
auto task =
|
||||
std::make_shared<Task>(priority, std::move(callback), expirationTime);
|
||||
@@ -81,7 +81,7 @@ RuntimeSchedulerTimePoint RuntimeScheduler::now() const noexcept {
|
||||
return now_();
|
||||
}
|
||||
|
||||
void RuntimeScheduler::executeNowOnTheSameThread(RawCallback callback) {
|
||||
void RuntimeScheduler::executeNowOnTheSameThread(RawCallback&& callback) {
|
||||
SystraceSection s("RuntimeScheduler::executeNowOnTheSameThread");
|
||||
|
||||
runtimeAccessRequests_ += 1;
|
||||
@@ -166,7 +166,7 @@ void RuntimeScheduler::startWorkLoop(jsi::Runtime& runtime) const {
|
||||
|
||||
void RuntimeScheduler::executeTask(
|
||||
jsi::Runtime& runtime,
|
||||
std::shared_ptr<Task> task,
|
||||
const std::shared_ptr<Task>& task,
|
||||
bool didUserCallbackTimeout) const {
|
||||
SystraceSection s(
|
||||
"RuntimeScheduler::executeTask",
|
||||
|
||||
+5
-5
@@ -34,7 +34,7 @@ class RuntimeScheduler final {
|
||||
RuntimeScheduler(RuntimeScheduler&&) = delete;
|
||||
RuntimeScheduler& operator=(RuntimeScheduler&&) = delete;
|
||||
|
||||
void scheduleWork(RawCallback callback) const;
|
||||
void scheduleWork(RawCallback&& callback) const noexcept;
|
||||
|
||||
/*
|
||||
* Grants access to the runtime synchronously on the caller's thread.
|
||||
@@ -43,7 +43,7 @@ class RuntimeScheduler final {
|
||||
* by dispatching a synchronous event via event emitter in your native
|
||||
* component.
|
||||
*/
|
||||
void executeNowOnTheSameThread(RawCallback callback);
|
||||
void executeNowOnTheSameThread(RawCallback&& callback);
|
||||
|
||||
/*
|
||||
* Adds a JavaScript callback to priority queue with given priority.
|
||||
@@ -53,11 +53,11 @@ class RuntimeScheduler final {
|
||||
*/
|
||||
std::shared_ptr<Task> scheduleTask(
|
||||
SchedulerPriority priority,
|
||||
jsi::Function callback);
|
||||
jsi::Function&& callback) noexcept;
|
||||
|
||||
std::shared_ptr<Task> scheduleTask(
|
||||
SchedulerPriority priority,
|
||||
RawCallback callback);
|
||||
RawCallback&& callback) noexcept;
|
||||
|
||||
/*
|
||||
* Cancelled task will never be executed.
|
||||
@@ -135,7 +135,7 @@ class RuntimeScheduler final {
|
||||
|
||||
void executeTask(
|
||||
jsi::Runtime& runtime,
|
||||
std::shared_ptr<Task> task,
|
||||
const std::shared_ptr<Task>& task,
|
||||
bool didUserCallbackTimeout) const;
|
||||
|
||||
/*
|
||||
|
||||
+2
-2
@@ -16,7 +16,7 @@ RuntimeSchedulerCallInvoker::RuntimeSchedulerCallInvoker(
|
||||
std::weak_ptr<RuntimeScheduler> runtimeScheduler)
|
||||
: runtimeScheduler_(std::move(runtimeScheduler)) {}
|
||||
|
||||
void RuntimeSchedulerCallInvoker::invokeAsync(CallFunc&& func) {
|
||||
void RuntimeSchedulerCallInvoker::invokeAsync(CallFunc&& func) noexcept {
|
||||
if (auto runtimeScheduler = runtimeScheduler_.lock()) {
|
||||
runtimeScheduler->scheduleWork(
|
||||
[func = std::move(func)](jsi::Runtime&) { func(); });
|
||||
@@ -32,7 +32,7 @@ void RuntimeSchedulerCallInvoker::invokeSync(CallFunc&& func) {
|
||||
|
||||
void RuntimeSchedulerCallInvoker::invokeAsync(
|
||||
SchedulerPriority priority,
|
||||
CallFunc&& func) {
|
||||
CallFunc&& func) noexcept {
|
||||
if (auto runtimeScheduler = runtimeScheduler_.lock()) {
|
||||
runtimeScheduler->scheduleTask(
|
||||
priority, [func = std::move(func)](jsi::Runtime&) { func(); });
|
||||
|
||||
+3
-2
@@ -20,9 +20,10 @@ class RuntimeSchedulerCallInvoker : public CallInvoker {
|
||||
public:
|
||||
RuntimeSchedulerCallInvoker(std::weak_ptr<RuntimeScheduler> runtimeScheduler);
|
||||
|
||||
void invokeAsync(CallFunc&& func) override;
|
||||
void invokeAsync(CallFunc&& func) noexcept override;
|
||||
void invokeSync(CallFunc&& func) override;
|
||||
void invokeAsync(SchedulerPriority priority, CallFunc&& func) override;
|
||||
void invokeAsync(SchedulerPriority priority, CallFunc&& func) noexcept
|
||||
override;
|
||||
|
||||
private:
|
||||
/*
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ static inline SchedulerPriority fromRawValue(double value) {
|
||||
}
|
||||
|
||||
static inline std::chrono::milliseconds timeoutForSchedulerPriority(
|
||||
SchedulerPriority schedulerPriority) {
|
||||
SchedulerPriority schedulerPriority) noexcept {
|
||||
switch (schedulerPriority) {
|
||||
case SchedulerPriority::ImmediatePriority:
|
||||
return std::chrono::milliseconds(-1);
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace facebook::react {
|
||||
|
||||
Task::Task(
|
||||
SchedulerPriority priority,
|
||||
jsi::Function callback,
|
||||
jsi::Function&& callback,
|
||||
std::chrono::steady_clock::time_point expirationTime)
|
||||
: priority(priority),
|
||||
callback(std::move(callback)),
|
||||
@@ -19,7 +19,7 @@ Task::Task(
|
||||
|
||||
Task::Task(
|
||||
SchedulerPriority priority,
|
||||
RawCallback callback,
|
||||
RawCallback&& callback,
|
||||
std::chrono::steady_clock::time_point expirationTime)
|
||||
: priority(priority),
|
||||
callback(std::move(callback)),
|
||||
|
||||
@@ -24,12 +24,12 @@ using RawCallback = std::function<void(jsi::Runtime&)>;
|
||||
struct Task final : public jsi::NativeState {
|
||||
Task(
|
||||
SchedulerPriority priority,
|
||||
jsi::Function callback,
|
||||
jsi::Function&& callback,
|
||||
std::chrono::steady_clock::time_point expirationTime);
|
||||
|
||||
Task(
|
||||
SchedulerPriority priority,
|
||||
RawCallback callback,
|
||||
RawCallback&& callback,
|
||||
std::chrono::steady_clock::time_point expirationTime);
|
||||
|
||||
private:
|
||||
|
||||
@@ -15,7 +15,8 @@ BridgelessJSCallInvoker::BridgelessJSCallInvoker(
|
||||
RuntimeExecutor runtimeExecutor)
|
||||
: runtimeExecutor_(std::move(runtimeExecutor)) {}
|
||||
|
||||
void BridgelessJSCallInvoker::invokeAsync(std::function<void()>&& func) {
|
||||
void BridgelessJSCallInvoker::invokeAsync(
|
||||
std::function<void()>&& func) noexcept {
|
||||
runtimeExecutor_([func = std::move(func)](jsi::Runtime& runtime) { func(); });
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace facebook::react {
|
||||
class BridgelessJSCallInvoker : public CallInvoker {
|
||||
public:
|
||||
explicit BridgelessJSCallInvoker(RuntimeExecutor runtimeExecutor);
|
||||
void invokeAsync(std::function<void()>&& func) override;
|
||||
void invokeAsync(std::function<void()>&& func) noexcept override;
|
||||
void invokeSync(std::function<void()>&& func) override;
|
||||
|
||||
private:
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ BridgelessNativeMethodCallInvoker::BridgelessNativeMethodCallInvoker(
|
||||
|
||||
void BridgelessNativeMethodCallInvoker::invokeAsync(
|
||||
const std::string& methodName,
|
||||
std::function<void()>&& func) {
|
||||
std::function<void()>&& func) noexcept {
|
||||
messageQueueThread_->runOnQueue(std::move(func));
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,9 @@ class BridgelessNativeMethodCallInvoker : public NativeMethodCallInvoker {
|
||||
public:
|
||||
explicit BridgelessNativeMethodCallInvoker(
|
||||
std::shared_ptr<MessageQueueThread> messageQueueThread);
|
||||
void invokeAsync(const std::string& methodName, std::function<void()>&& func)
|
||||
override;
|
||||
void invokeAsync(
|
||||
const std::string& methodName,
|
||||
std::function<void()>&& func) noexcept override;
|
||||
void invokeSync(const std::string& methodName, std::function<void()>&& func)
|
||||
override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user