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_<unit_name>" (where
<unit_name> 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
This commit is contained in:
Gang Zhao
2025-09-04 03:06:33 -07:00
committed by Facebook GitHub Bot
parent 48998b4c11
commit 89d9533a97
@@ -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