diff --git a/packages/react-native/ReactCommon/jsinspector-modern/InstanceTarget.h b/packages/react-native/ReactCommon/jsinspector-modern/InstanceTarget.h index 101433c8b27..e9ec51b12db 100644 --- a/packages/react-native/ReactCommon/jsinspector-modern/InstanceTarget.h +++ b/packages/react-native/ReactCommon/jsinspector-modern/InstanceTarget.h @@ -70,9 +70,22 @@ class InstanceTarget : public EnableExecutorFromThis { FrontendChannel channel, SessionState& sessionState); + /** + * Registers a JS runtime with this InstanceTarget. \returns a reference to + * the created RuntimeTarget, which is owned by the \c InstanceTarget. All the + * requirements of \c RuntimeTarget::create must be met. + */ RuntimeTarget& registerRuntime( RuntimeTargetDelegate& delegate, RuntimeExecutor executor); + + /** + * Unregisters a JS runtime from this InstanceTarget. This destroys the \c + * RuntimeTarget, and it is no longer valid to use. Note that the \c + * RuntimeTargetDelegate& initially provided to \c registerRuntime may + * continue to be used as long as JavaScript execution continues in the + * runtime. + */ void unregisterRuntime(RuntimeTarget& runtime); private: diff --git a/packages/react-native/ReactCommon/jsinspector-modern/RuntimeTarget.h b/packages/react-native/ReactCommon/jsinspector-modern/RuntimeTarget.h index 0e1160a7109..9960c170f03 100644 --- a/packages/react-native/ReactCommon/jsinspector-modern/RuntimeTarget.h +++ b/packages/react-native/ReactCommon/jsinspector-modern/RuntimeTarget.h @@ -77,15 +77,15 @@ class JSINSPECTOR_EXPORT RuntimeTarget : public EnableExecutorFromThis { public: /** - * Constructs a new RuntimeTarget. The caller must call setExecutor - * immediately afterwards. * \param executionContextDescription A description of the execution context * represented by this runtime. This is used for disambiguating the * source/destination of CDP messages when there are multiple runtimes * (concurrently or over the life of a Host). * \param delegate The object that will receive events from this target. The - * caller is responsible for - * ensuring that the delegate outlives this object. + * caller is responsible for ensuring that the delegate outlives this object + * AND that it remains valid for as long as the JS runtime is executing any + * code, even if the \c RuntimeTarget itself is destroyed. The delegate SHOULD + * be the object that owns the underlying jsi::Runtime, if any. * \param jsExecutor A RuntimeExecutor that can be used to schedule work on * the JS runtime's thread. The executor's queue should be empty when * RuntimeTarget is constructed (i.e. anything scheduled during the @@ -127,9 +127,11 @@ class JSINSPECTOR_EXPORT RuntimeTarget * represented by this runtime. This is used for disambiguating the * source/destination of CDP messages when there are multiple runtimes * (concurrently or over the life of a Host). - * \param delegate The object that will receive events from this target. - * The caller is responsible for ensuring that the delegate outlives this - * object. + * \param delegate The object that will receive events from this target. The + * caller is responsible for ensuring that the delegate outlives this object + * AND that it remains valid for as long as the JS runtime is executing any + * code, even if the \c RuntimeTarget itself is destroyed. The delegate SHOULD + * be the object that owns the underlying jsi::Runtime, if any. * \param jsExecutor A RuntimeExecutor that can be used to schedule work on * the JS runtime's thread. The executor's queue should be empty when * RuntimeTarget is constructed (i.e. anything scheduled during the