Skip to content

Commit

Permalink
[JSCRuntime] Add runtimeConfig to set debugger options (#1957)
Browse files Browse the repository at this point in the history
  • Loading branch information
Saadnajmi authored Oct 28, 2023
1 parent 1aa1700 commit 43122d4
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 4 deletions.
11 changes: 11 additions & 0 deletions packages/react-native/React/CxxBridge/JSCExecutorFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,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<JSExecutor> createJSExecutor(
std::shared_ptr<ExecutorDelegate> delegate,
std::shared_ptr<MessageQueueThread> jsQueue) override;

private:
JSIExecutor::RuntimeInstaller runtimeInstaller_;

// [macOS
bool enableDebugger_ = true;
std::string debuggerName_ = "JSC React Native";
// macOS]
};

} // namespace facebook::react
20 changes: 17 additions & 3 deletions packages/react-native/React/CxxBridge/JSCExecutorFactory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,26 @@

namespace facebook::react {

// [macOS
void JSCExecutorFactory::setEnableDebugger(bool enableDebugger) {
enableDebugger_ = enableDebugger;
}

void JSCExecutorFactory::setDebuggerName(const std::string &debuggerName) {
debuggerName_ = debuggerName;
}
// macOS]

std::unique_ptr<JSExecutor> JSCExecutorFactory::createJSExecutor(
std::shared_ptr<ExecutorDelegate> delegate,
std::shared_ptr<MessageQueueThread> __unused jsQueue)
{
return std::make_unique<JSIExecutor>(
facebook::jsc::makeJSCRuntime(), delegate, JSIExecutor::defaultTimeoutInvoker, runtimeInstaller_);
// [macOS
facebook::jsc::RuntimeConfig rc = {
.enableDebugger = enableDebugger_,
.debuggerName = debuggerName_,
};
return std::make_unique<JSIExecutor>(facebook::jsc::makeJSCRuntime(std::move(rc)), delegate, JSIExecutor::defaultTimeoutInvoker, runtimeInstaller_);
// macOS]
}

} // namespace facebook::react
32 changes: 31 additions & 1 deletion packages/react-native/ReactCommon/jsc/JSCRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -293,11 +297,18 @@ class JSCRuntime : public jsi::Runtime {
} \
} while (0)

#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) // [macOS]
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 160400
#define _JSC_HAS_INSPECTABLE
#endif
#endif
// [macOS
#if defined(__MAC_OS_X_VERSION_MAX_ALLOWED)
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 130300
#define _JSC_HAS_INSPECTABLE
#endif
#endif
// macOS]

// JSStringRef utilities
namespace {
Expand Down Expand Up @@ -361,6 +372,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)
Expand Down Expand Up @@ -1565,5 +1589,11 @@ std::unique_ptr<jsi::Runtime> makeJSCRuntime() {
return std::make_unique<JSCRuntime>();
}

// [macOS
std::unique_ptr<jsi::Runtime> makeJSCRuntime(const facebook::jsc::RuntimeConfig& rc) {
return std::make_unique<JSCRuntime>(rc);
}
// macOS]

} // namespace jsc
} // namespace facebook
9 changes: 9 additions & 0 deletions packages/react-native/ReactCommon/jsc/JSCRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@
namespace facebook {
namespace jsc {

// [macOS
struct RuntimeConfig {
bool enableDebugger;
std::string debuggerName;
};
// macOS]

std::unique_ptr<jsi::Runtime> makeJSCRuntime();

std::unique_ptr<jsi::Runtime> makeJSCRuntime(const facebook::jsc::RuntimeConfig& rc); // [macOS]

} // namespace jsc
} // namespace facebook

0 comments on commit 43122d4

Please sign in to comment.