diff --git a/packages/react-native/React/CxxBridge/JSCExecutorFactory.h b/packages/react-native/React/CxxBridge/JSCExecutorFactory.h index 17b64037c72ef5..4a83139aa563d9 100644 --- a/packages/react-native/React/CxxBridge/JSCExecutorFactory.h +++ b/packages/react-native/React/CxxBridge/JSCExecutorFactory.h @@ -17,12 +17,23 @@ class JSCExecutorFactory : public JSExecutorFactory { explicit JSCExecutorFactory(JSIExecutor::RuntimeInstaller runtimeInstaller) : runtimeInstaller_(std::move(runtimeInstaller)) {} + // [macOS + void setEnableDebugger(bool enableDebugger); + + void setDebuggerName(const std::string &debuggerName); + // macOS] + std::unique_ptr createJSExecutor( std::shared_ptr delegate, std::shared_ptr jsQueue) override; private: JSIExecutor::RuntimeInstaller runtimeInstaller_; + + // [macOS + bool enableDebugger_ = true; + std::string debuggerName_ = "JSC React Native"; + // macOS] }; } // namespace react diff --git a/packages/react-native/React/CxxBridge/JSCExecutorFactory.mm b/packages/react-native/React/CxxBridge/JSCExecutorFactory.mm index 78584cd4e6c121..e9b2d779b94986 100644 --- a/packages/react-native/React/CxxBridge/JSCExecutorFactory.mm +++ b/packages/react-native/React/CxxBridge/JSCExecutorFactory.mm @@ -14,12 +14,27 @@ namespace facebook { namespace react { +// [macOS +void JSCExecutorFactory::setEnableDebugger(bool enableDebugger) { + enableDebugger_ = enableDebugger; +} + +void JSCExecutorFactory::setDebuggerName(const std::string &debuggerName) { + debuggerName_ = debuggerName; +} +// macOS] + 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_); + // [macOS + facebook::jsc::RuntimeConfig rc = { + .enableDebugger = enableDebugger_, + .debuggerName = debuggerName_, + }; + return std::make_unique(facebook::jsc::makeJSCRuntime(std::move(rc)), delegate, JSIExecutor::defaultTimeoutInvoker, runtimeInstaller_); + // macOS] } } // namespace react diff --git a/packages/react-native/ReactCommon/jsc/JSCRuntime.cpp b/packages/react-native/ReactCommon/jsc/JSCRuntime.cpp index 523b1be36937ee..2baf233af8418a 100644 --- a/packages/react-native/ReactCommon/jsc/JSCRuntime.cpp +++ b/packages/react-native/ReactCommon/jsc/JSCRuntime.cpp @@ -36,6 +36,10 @@ class JSCRuntime : public jsi::Runtime { public: // Creates new context in new context group JSCRuntime(); + // [macOS + // Creates new context in new context group with config + JSCRuntime(const facebook::jsc::RuntimeConfig& rc); + // macOS] // Retains ctx JSCRuntime(JSGlobalContextRef ctx); ~JSCRuntime(); @@ -293,7 +297,7 @@ class JSCRuntime : public jsi::Runtime { } \ } while (0) -#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) +#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) // [macOS] // This takes care of watch and tvos (due to backwards compatibility in // Availability.h #if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_9_0 @@ -316,6 +320,11 @@ class JSCRuntime : public jsi::Runtime { #if __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_12 #define _JSC_NO_ARRAY_BUFFERS #endif +// [macOS +#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 130300 +#define _JSC_HAS_INSPECTABLE +#endif +// macOS] #endif // JSStringRef utilities @@ -392,6 +401,19 @@ JSCRuntime::JSCRuntime() JSGlobalContextRelease(ctx_); } +// [macOS +JSCRuntime::JSCRuntime(const 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())); + +} +// macOS] + JSCRuntime::JSCRuntime(JSGlobalContextRef ctx) : ctx_(JSGlobalContextRetain(ctx)), ctxInvalid_(false) @@ -1567,5 +1589,11 @@ std::unique_ptr makeJSCRuntime() { return std::make_unique(); } +// [macOS +std::unique_ptr makeJSCRuntime(const facebook::jsc::RuntimeConfig& rc) { + return std::make_unique(rc); +} +// macOS] + } // namespace jsc } // namespace facebook diff --git a/packages/react-native/ReactCommon/jsc/JSCRuntime.h b/packages/react-native/ReactCommon/jsc/JSCRuntime.h index 1d6b2259fcdbe2..f32908db87b541 100644 --- a/packages/react-native/ReactCommon/jsc/JSCRuntime.h +++ b/packages/react-native/ReactCommon/jsc/JSCRuntime.h @@ -13,7 +13,16 @@ namespace facebook { namespace jsc { +// [macOS +struct RuntimeConfig { + bool enableDebugger; + std::string debuggerName; +}; +// macOS] + std::unique_ptr makeJSCRuntime(); +std::unique_ptr makeJSCRuntime(const facebook::jsc::RuntimeConfig& rc); // [macOS] + } // namespace jsc } // namespace facebook