diff --git a/packages/react-native/React/CxxBridge/JSCExecutorFactory.h b/packages/react-native/React/CxxBridge/JSCExecutorFactory.h index 17b64037c72ef5..3adb9934196cde 100644 --- a/packages/react-native/React/CxxBridge/JSCExecutorFactory.h +++ b/packages/react-native/React/CxxBridge/JSCExecutorFactory.h @@ -17,12 +17,19 @@ class JSCExecutorFactory : public JSExecutorFactory { explicit JSCExecutorFactory(JSIExecutor::RuntimeInstaller runtimeInstaller) : runtimeInstaller_(std::move(runtimeInstaller)) {} + void setEnableDebugger(bool enableDebugger); + + void setDebuggerName(const std::string &debuggerName); + std::unique_ptr createJSExecutor( std::shared_ptr delegate, std::shared_ptr jsQueue) override; private: JSIExecutor::RuntimeInstaller runtimeInstaller_; + + bool enableDebugger_ = true; + std::string debuggerName_ = "JSC React Native"; }; } // namespace react diff --git a/packages/react-native/React/CxxBridge/JSCExecutorFactory.mm b/packages/react-native/React/CxxBridge/JSCExecutorFactory.mm index 78584cd4e6c121..075e1fc4953599 100644 --- a/packages/react-native/React/CxxBridge/JSCExecutorFactory.mm +++ b/packages/react-native/React/CxxBridge/JSCExecutorFactory.mm @@ -14,12 +14,23 @@ namespace facebook { namespace react { +void JSCExecutorFactory::setEnableDebugger(bool enableDebugger) { + enableDebugger_ = enableDebugger; +} + +void JSCExecutorFactory::setDebuggerName(const std::string &debuggerName) { + debuggerName_ = debuggerName; +} + std::unique_ptr JSCExecutorFactory::createJSExecutor( std::shared_ptr delegate, std::shared_ptr __unused jsQueue) { - return std::make_unique( - facebook::jsc::makeJSCRuntime(), delegate, JSIExecutor::defaultTimeoutInvoker, runtimeInstaller_); + facebook::jsc::runtimeConfig rc = { + .enableDebugger = enableDebugger_, + .debuggerName = debuggerName_, + }; + return std::make_unique(facebook::jsc::makeJSCRuntime(std::move(rc)), delegate, JSIExecutor::defaultTimeoutInvoker, runtimeInstaller_); } } // namespace react diff --git a/packages/react-native/ReactCommon/cxxreact/JSExecutor.h b/packages/react-native/ReactCommon/cxxreact/JSExecutor.h index 112426a1da4144..093da01e1284a3 100644 --- a/packages/react-native/ReactCommon/cxxreact/JSExecutor.h +++ b/packages/react-native/ReactCommon/cxxreact/JSExecutor.h @@ -114,8 +114,7 @@ class RN_EXPORT JSExecutor { } /** - * Returns whether or not the underlying executor supports debugging via the - * Chrome remote debugging protocol. + * Returns whether or not the underlying executor supports debugging. */ virtual bool isInspectable() { return false; diff --git a/packages/react-native/ReactCommon/jsc/JSCRuntime.cpp b/packages/react-native/ReactCommon/jsc/JSCRuntime.cpp index 523b1be36937ee..9505a202aafc2c 100644 --- a/packages/react-native/ReactCommon/jsc/JSCRuntime.cpp +++ b/packages/react-native/ReactCommon/jsc/JSCRuntime.cpp @@ -36,6 +36,8 @@ class JSCRuntime : public jsi::Runtime { public: // Creates new context in new context group JSCRuntime(); + // Creates new context in new context group with config + JSCRuntime(facebook::jsc::runtimeConfig &rc); // Retains ctx JSCRuntime(JSGlobalContextRef ctx); ~JSCRuntime(); @@ -392,6 +394,17 @@ JSCRuntime::JSCRuntime() JSGlobalContextRelease(ctx_); } +JSCRuntime::JSCRuntime(facebook::jsc::runtimeConfig &rc) + : JSCRuntime() { +#ifdef _JSC_HAS_INSPECTABLE + if (__builtin_available(macOS 13.3, iOS 16.4, tvOS 16.4, *)) { + JSGlobalContextSetInspectable(ctx_, rc.enableDebugger); + } +#endif + JSGlobalContextSetName(ctx_, JSStringCreateWithUTF8CString(rc.debuggerName.c_str())); + +} + JSCRuntime::JSCRuntime(JSGlobalContextRef ctx) : ctx_(JSGlobalContextRetain(ctx)), ctxInvalid_(false) @@ -481,7 +494,11 @@ std::string JSCRuntime::description() { } bool JSCRuntime::isInspectable() { +#ifdef _JSC_HAS_INSPECTABLE + return JSGlobalContextIsInspectable(ctx_); +#else return false; +#endif } namespace { @@ -1567,5 +1584,9 @@ std::unique_ptr makeJSCRuntime() { return std::make_unique(); } +std::unique_ptr makeJSCRuntime(facebook::jsc::runtimeConfig rc) { + return std::make_unique(rc); +} + } // namespace jsc } // namespace facebook diff --git a/packages/react-native/ReactCommon/jsc/JSCRuntime.h b/packages/react-native/ReactCommon/jsc/JSCRuntime.h index 1d6b2259fcdbe2..894358e5018b0d 100644 --- a/packages/react-native/ReactCommon/jsc/JSCRuntime.h +++ b/packages/react-native/ReactCommon/jsc/JSCRuntime.h @@ -13,7 +13,14 @@ namespace facebook { namespace jsc { +struct runtimeConfig { + bool enableDebugger; + std::string debuggerName; +}; + std::unique_ptr makeJSCRuntime(); +std::unique_ptr makeJSCRuntime(facebook::jsc::runtimeConfig rc); + } // namespace jsc } // namespace facebook