diff --git a/ReactCommon/jsi/jsi/jsi-inl.h b/ReactCommon/jsi/jsi/jsi-inl.h index c30b78a16a1df7..34d7e90a0b67d5 100644 --- a/ReactCommon/jsi/jsi/jsi-inl.h +++ b/ReactCommon/jsi/jsi/jsi-inl.h @@ -56,7 +56,12 @@ inline PropNameID&& toPropNameID(Runtime&, PropNameID&& name) { return std::move(name); } -void throwJSError(Runtime&, const char* msg); +/// Helper to throw while still compiling with exceptions turned off. +template +[[noreturn]] inline void throwOrDie(Args&&... args) { + std::rethrow_exception( + std::make_exception_ptr(E{std::forward(args)...})); +} } // namespace detail @@ -184,7 +189,8 @@ inline std::shared_ptr Object::getHostObject(Runtime& runtime) const { template inline std::shared_ptr Object::asHostObject(Runtime& runtime) const { if (!isHostObject(runtime)) { - detail::throwJSError(runtime, "Object is not a HostObject of desired type"); + detail::throwOrDie( + runtime, "Object is not a HostObject of desired type"); } return std::static_pointer_cast(runtime.getHostObject(*this)); } diff --git a/ReactCommon/jsi/jsi/jsi.cpp b/ReactCommon/jsi/jsi/jsi.cpp index 4dfb1a04af2f76..a081eb34f97d9c 100644 --- a/ReactCommon/jsi/jsi/jsi.cpp +++ b/ReactCommon/jsi/jsi/jsi.cpp @@ -62,14 +62,6 @@ Value callGlobalFunction(Runtime& runtime, const char* name, const Value& arg) { } // namespace -namespace detail { - -void throwJSError(Runtime& rt, const char* msg) { - throw JSError(rt, msg); -} - -} // namespace detail - Buffer::~Buffer() = default; PreparedJavaScript::~PreparedJavaScript() = default; diff --git a/ReactCommon/react/renderer/runtimescheduler/tests/RuntimeSchedulerTest.cpp b/ReactCommon/react/renderer/runtimescheduler/tests/RuntimeSchedulerTest.cpp index d5561e04749ae8..7c274bcf39358a 100644 --- a/ReactCommon/react/renderer/runtimescheduler/tests/RuntimeSchedulerTest.cpp +++ b/ReactCommon/react/renderer/runtimescheduler/tests/RuntimeSchedulerTest.cpp @@ -453,7 +453,7 @@ TEST_F(RuntimeSchedulerTest, handlingError) { bool didRunTask = false; auto firstCallback = createHostFunctionFromLambda([this, &didRunTask](bool) { didRunTask = true; - jsi::detail::throwJSError(*runtime_, "Test error"); + throw jsi::JSError(*runtime_, "Test error"); return jsi::Value::undefined(); });