Skip to content

Commit

Permalink
earlyjs: Extend C++ pipeline for non-js errors
Browse files Browse the repository at this point in the history
Summary:
RuntimeExecutor, RuntimeScheduler, etc. can execute arbitrary c++ on the javascript thread.

If that c++ throws a non-jsi::JSError, it will bypass the js error handler (and start tearing down the react instance 😱).

Let's have the js error handler manage all exceptions raised while native is calling into js. This is more sane.

Changelog: [Internal]

Differential Revision: D64626610
  • Loading branch information
RSNara authored and facebook-github-bot committed Nov 8, 2024
1 parent cd9ece0 commit 93eec8b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ void RuntimeScheduler_Legacy::callExpiredTasks(jsi::Runtime& runtime) {
}
} catch (jsi::JSError& error) {
onTaskError_(runtime, error);
} catch (std::exception& ex) {
jsi::JSError error(runtime, std::string("Non-js exception: ") + ex.what());
onTaskError_(runtime, error);
}

currentPriority_ = previousPriority;
Expand Down Expand Up @@ -233,6 +236,9 @@ void RuntimeScheduler_Legacy::startWorkLoop(jsi::Runtime& runtime) {
}
} catch (jsi::JSError& error) {
onTaskError_(runtime, error);
} catch (std::exception& ex) {
jsi::JSError error(runtime, std::string("Non-js exception: ") + ex.what());
onTaskError_(runtime, error);
}

currentPriority_ = previousPriority;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ void RuntimeScheduler_Modern::executeTask(
}
} catch (jsi::JSError& error) {
onTaskError_(runtime, error);
} catch (std::exception& ex) {
jsi::JSError error(runtime, std::string("Non-js exception: ") + ex.what());
onTaskError_(runtime, error);
}
}

Expand Down Expand Up @@ -420,6 +423,10 @@ void RuntimeScheduler_Modern::performMicrotaskCheckpoint(
}
} catch (jsi::JSError& error) {
onTaskError_(runtime, error);
} catch (std::exception& ex) {
jsi::JSError error(
runtime, std::string("Non-js exception: ") + ex.what());
onTaskError_(runtime, error);
}
retries++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ ReactInstance::ReactInstance(
}
} catch (jsi::JSError& originalError) {
jsErrorHandler->handleError(jsiRuntime, originalError, true);
} catch (std::exception& ex) {
jsi::JSError error(
jsiRuntime, std::string("Non-js exception: ") + ex.what());
jsErrorHandler->handleError(jsiRuntime, error, true);
}
});
}
Expand Down

0 comments on commit 93eec8b

Please sign in to comment.