From dc9c5a7756e494894c5585cee4d5f43c6d146c80 Mon Sep 17 00:00:00 2001 From: Chi Tsai Date: Thu, 5 Feb 2026 12:04:55 -0800 Subject: [PATCH] Add `IEventLoopControl` APIs to hermes-interface Summary: Adds `ISetEventLoopControl` to the Hermes-specific JSI. This interface specifies an user-defined, thread-safe function to schedule some task provided by the Hermes VM. The Hermes VM may use this function to "ask" the integrator to run some arbitrary task when the integrator has exclusive control of the runtime. Notably, this is useful for the Hermes implementation of Workers, where the Worker thread may ask the integrator to process an event. Differential Revision: D91905969 --- .../ReactCommon/jsi/jsi/hermes-interfaces.h | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/packages/react-native/ReactCommon/jsi/jsi/hermes-interfaces.h b/packages/react-native/ReactCommon/jsi/jsi/hermes-interfaces.h index 364a645a97941a..342343329e5c30 100644 --- a/packages/react-native/ReactCommon/jsi/jsi/hermes-interfaces.h +++ b/packages/react-native/ReactCommon/jsi/jsi/hermes-interfaces.h @@ -26,6 +26,34 @@ namespace debugger { class Debugger; } +#ifdef JSI_UNSTABLE +struct IEventLoopControl { + /// `scheduleCallback` is an integrator-provided function for the VM to + /// schedule a callback task \p callback. This API must be thread-safe and run + /// the callback when it is the exclusive user of the Runtime. + virtual void scheduleCallback(const std::function callback) = 0; + + protected: + ~IEventLoopControl() = default; +}; + +struct JSI_EXPORT ISetEventLoopControl : public jsi::ICast { + public: + static constexpr jsi::UUID uuid{ + 0x7b6902e6, + 0xfd38, + 0x11f0, + 0x8de9, + 0x0242ac120002}; + + /// Configures the eventloop control mechanism using \p eventLoopControl. + virtual void setEventLoopControl(IEventLoopControl* eventLoopControl) = 0; + + protected: + ~ISetEventLoopControl() = default; +}; +#endif + /// Interface for Hermes-specific runtime methods.The actual implementations of /// the pure virtual methods are provided by Hermes API. class JSI_EXPORT IHermes : public jsi::ICast {