earlyjs: Extend C++ pipeline for non-js errors (#47529)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/47529

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]

Reviewed By: sammy-SC

Differential Revision: D64626610

fbshipit-source-id: 40132f24b4e2737ae3f055fbd09153111404e5bf
This commit is contained in:
Ramanpreet Nara 2024-11-11 13:24:49 -08:00 committed by Facebook GitHub Bot
parent 998ab262ea
commit ca7b9e9509
3 changed files with 17 additions and 0 deletions

View File

@ -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;
@ -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;

View File

@ -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);
}
}
@ -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++;
}

View File

@ -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);
}
});
}