diff --git a/common/JSCRuntime.cpp b/common/JSCRuntime.cpp index 9e188fa..0d6b7d6 100644 --- a/common/JSCRuntime.cpp +++ b/common/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(const facebook::jsc::RuntimeConfig& rc); // Retains ctx JSCRuntime(JSGlobalContextRef ctx); ~JSCRuntime(); @@ -366,6 +368,17 @@ JSCRuntime::JSCRuntime() JSGlobalContextRelease(ctx_); } +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())); + +} + JSCRuntime::JSCRuntime(JSGlobalContextRef ctx) : ctx_(JSGlobalContextRetain(ctx)), ctxInvalid_(false) @@ -1582,5 +1595,9 @@ std::unique_ptr makeJSCRuntime() { return std::make_unique(); } +std::unique_ptr makeJSCRuntime(const facebook::jsc::RuntimeConfig& rc) { + return std::make_unique(rc); +} + } // namespace jsc } // namespace facebook diff --git a/common/JSCRuntime.h b/common/JSCRuntime.h index 4023d26..c8b3e3e 100644 --- a/common/JSCRuntime.h +++ b/common/JSCRuntime.h @@ -15,8 +15,15 @@ namespace facebook { namespace jsc { +struct RuntimeConfig { + bool enableDebugger; + std::string debuggerName; +}; + std::unique_ptr makeJSCRuntime(); +std::unique_ptr makeJSCRuntime(const facebook::jsc::RuntimeConfig& rc); + } // namespace jsc } // namespace facebook diff --git a/ios/RCTJscInstance.h b/ios/RCTJscInstance.h index 51f7c9e..9d9ab1d 100644 --- a/ios/RCTJscInstance.h +++ b/ios/RCTJscInstance.h @@ -18,10 +18,22 @@ class RCTJscInstance : public JSRuntimeFactory { public: RCTJscInstance(); + void setEnableDebugger(bool enableDebugger); + + void setDebuggerName(const std::string &debuggerName); + std::unique_ptr createJSRuntime( std::shared_ptr msgQueueThread) noexcept override; ~RCTJscInstance(){}; + + private: +#if DEBUG + bool enableDebugger_ = true; +#else + bool enableDebugger_ = false; +#endif + std::string debuggerName_ = "JSC React Native"; }; } // namespace react } // namespace facebook diff --git a/ios/RCTJscInstance.mm b/ios/RCTJscInstance.mm index 50bf9cc..3cc4f01 100644 --- a/ios/RCTJscInstance.mm +++ b/ios/RCTJscInstance.mm @@ -13,9 +13,21 @@ RCTJscInstance::RCTJscInstance() {} +void RCTJscInstance::setEnableDebugger(bool enableDebugger) { + enableDebugger_ = enableDebugger; +} + +void RCTJscInstance::setDebuggerName(const std::string &debuggerName) { + debuggerName_ = debuggerName; +} + std::unique_ptr RCTJscInstance::createJSRuntime(std::shared_ptr msgQueueThread) noexcept { - return std::make_unique(jsc::makeJSCRuntime()); + jsc::RuntimeConfig rc = { + .enableDebugger = enableDebugger_, + .debuggerName = debuggerName_, + }; + return std::make_unique(jsc::makeJSCRuntime(std::move(rc))); } } // namespace react