From 89d9533a97ef011ff9793da8d2d3cf32f0ed1e5e Mon Sep 17 00:00:00 2001 From: Gang Zhao Date: Thu, 4 Sep 2025 03:06:33 -0700 Subject: [PATCH] getSHUnitCreator() to IHermes (#53419) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/53419 By default, this function returns nullptr. User can pass a preprocessor definition "-DHERMES_SH_UNIT_FN=sh_export_" (where is the name passed to shermesc when compiling the JS input), so that this function returns the function pointer, which can be passed to `evaluateSHUnit` for evaluation. Changelog: [Internal] Reviewed By: avp Differential Revision: D80747463 fbshipit-source-id: a798a7a572679444fca111c34674fd7ced9311f3 --- .../react-native/ReactCommon/jsi/jsi/hermes.h | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/react-native/ReactCommon/jsi/jsi/hermes.h b/packages/react-native/ReactCommon/jsi/jsi/hermes.h index 04a7d924a7f..640e51494a5 100644 --- a/packages/react-native/ReactCommon/jsi/jsi/hermes.h +++ b/packages/react-native/ReactCommon/jsi/jsi/hermes.h @@ -11,6 +11,7 @@ struct SHUnit; struct SHRuntime; +using SHUnitCreator = SHUnit* (*)(); namespace hermes::vm { class GCExecTrace; } @@ -131,7 +132,7 @@ class JSI_EXPORT IHermes : public jsi::ICast { /// Associate the SHUnit returned by \p shUnitCreator with this runtime and /// run its initialization code. The unit will be freed when the runtime is /// destroyed. - virtual jsi::Value evaluateSHUnit(SHUnit* (*shUnitCreator)()) = 0; + virtual jsi::Value evaluateSHUnit(SHUnitCreator shUnitCreator) = 0; /// Retrieve the underlying SHRuntime. virtual SHRuntime* getSHRuntime() noexcept = 0; @@ -145,4 +146,23 @@ class JSI_EXPORT IHermes : public jsi::ICast { protected: ~IHermes() = default; }; + +/// Interface for provide Hermes backend specific methods. +class IHermesSHUnit : public jsi::ICast { + public: + static constexpr jsi::UUID uuid{ + 0x52a2d522, + 0xcbc6, + 0x4236, + 0x8d5d, + 0x2636c320ed65, + }; + + /// Get the unit creating function pointer which can be passed to + /// evaluateSHUnit() for evaluation. + virtual SHUnitCreator getSHUnitCreator() const = 0; + + protected: + ~IHermesSHUnit() = default; +}; } // namespace facebook::hermes