Skip to content

Commit e93afbd

Browse files
Mark ReactHost functions noexcept (#52574)
Summary: Pull Request resolved: #52574 Changelog: [Internal] The main change here is to catch *all* exceptions in: - loadScriptFromDevServer - loadScriptFromBundlePath so that we can make the `loadScript(...` method `noexcept` Other methods which only call into `noexcept` methods have been marked with `noexcept` as well Reviewed By: lenaic Differential Revision: D78222989 fbshipit-source-id: 174ac2420e88c913662f857c875fef996959c564
1 parent a5d6156 commit e93afbd

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

packages/react-native/ReactCxxPlatform/react/runtime/ReactHost.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ void ReactHost::reloadReactInstance() {
417417

418418
bool ReactHost::loadScript(
419419
const std::string& bundlePath,
420-
const std::string& sourcePath) {
420+
const std::string& sourcePath) noexcept {
421421
bool isLoaded = false;
422422
if (devServerHelper_) {
423423
devServerHelper_->setSourcePath(sourcePath);
@@ -458,7 +458,7 @@ bool ReactHost::loadScriptFromDevServer() {
458458
}
459459
devServerHelper_->setupHMRClient();
460460
return true;
461-
} catch (const std::exception& /*e*/) {
461+
} catch (...) {
462462
devServerHelper_->setSourcePath("");
463463
LOG(WARNING)
464464
<< "Unable to download JS bundle from Metro, falling back to prebuilt JS bundle. "
@@ -475,7 +475,7 @@ bool ReactHost::loadScriptFromBundlePath(const std::string& bundlePath) {
475475
reactInstance_->loadScript(std::move(script), bundlePath);
476476
LOG(INFO) << "Loaded JS bundle from bundle path: " << bundlePath;
477477
return true;
478-
} catch (const std::exception& /*e*/) {
478+
} catch (...) {
479479
LOG(WARNING) << "Unable to read bundle from bundle path" << bundlePath;
480480
return false;
481481
}
@@ -486,24 +486,24 @@ void ReactHost::startSurface(
486486
const std::string& moduleName,
487487
const folly::dynamic& initialProps,
488488
const LayoutConstraints& layoutConstraints,
489-
const LayoutContext& layoutContext) {
489+
const LayoutContext& layoutContext) noexcept {
490490
surfaceManager_->startSurface(
491491
surfaceId, moduleName, initialProps, layoutConstraints, layoutContext);
492492
}
493493

494494
void ReactHost::setSurfaceConstraints(
495495
SurfaceId surfaceId,
496496
const LayoutConstraints& layoutConstraints,
497-
const LayoutContext& layoutContext) {
497+
const LayoutContext& layoutContext) noexcept {
498498
surfaceManager_->constraintSurfaceLayout(
499499
surfaceId, layoutConstraints, layoutContext);
500500
}
501501

502-
void ReactHost::stopSurface(SurfaceId surfaceId) {
502+
void ReactHost::stopSurface(SurfaceId surfaceId) noexcept {
503503
surfaceManager_->stopSurface(surfaceId);
504504
}
505505

506-
void ReactHost::stopAllSurfaces() {
506+
void ReactHost::stopAllSurfaces() noexcept {
507507
surfaceManager_->stopAllSurfaces();
508508
}
509509

@@ -522,7 +522,7 @@ void ReactHost::runOnScheduler(
522522

523523
void ReactHost::runOnRuntimeScheduler(
524524
std::function<void(jsi::Runtime& runtime)>&& task,
525-
SchedulerPriority priority) const {
525+
SchedulerPriority priority) const noexcept {
526526
if (!isReloadingReactInstance_) {
527527
reactInstance_->getRuntimeScheduler()->scheduleTask(
528528
priority, std::move(task));

packages/react-native/ReactCxxPlatform/react/runtime/ReactHost.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,25 @@ class ReactHost {
6060
ReactHost& operator=(ReactHost&&) noexcept = delete;
6161
~ReactHost() noexcept;
6262

63-
bool loadScript(const std::string& bundlePath, const std::string& sourcePath);
63+
bool loadScript(
64+
const std::string& bundlePath,
65+
const std::string& sourcePath) noexcept;
6466

6567
void startSurface(
6668
SurfaceId surfaceId,
6769
const std::string& moduleName /* can be empty */,
6870
const folly::dynamic& initialProps,
6971
const LayoutConstraints& layoutConstraints,
70-
const LayoutContext& layoutContext = {});
72+
const LayoutContext& layoutContext = {}) noexcept;
7173

7274
void setSurfaceConstraints(
7375
SurfaceId surfaceId,
7476
const LayoutConstraints& layoutConstraints,
75-
const LayoutContext& layoutContext);
77+
const LayoutContext& layoutContext) noexcept;
7678

77-
void stopSurface(SurfaceId surfaceId);
79+
void stopSurface(SurfaceId surfaceId) noexcept;
7880

79-
void stopAllSurfaces();
81+
void stopAllSurfaces() noexcept;
8082

8183
bool isSurfaceRunning(SurfaceId surfaceId) const noexcept;
8284

@@ -86,7 +88,8 @@ class ReactHost {
8688

8789
void runOnRuntimeScheduler(
8890
std::function<void(jsi::Runtime& runtime)>&& task,
89-
SchedulerPriority priority = SchedulerPriority::NormalPriority) const;
91+
SchedulerPriority priority =
92+
SchedulerPriority::NormalPriority) const noexcept;
9093

9194
void emitDeviceEvent(folly::dynamic&& args);
9295

0 commit comments

Comments
 (0)