Skip to content

feat: add a runtime config for debugger options #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions common/JSCRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1582,5 +1595,9 @@ std::unique_ptr<jsi::Runtime> makeJSCRuntime() {
return std::make_unique<JSCRuntime>();
}

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

} // namespace jsc
} // namespace facebook
7 changes: 7 additions & 0 deletions common/JSCRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,15 @@
namespace facebook {
namespace jsc {

struct RuntimeConfig {
bool enableDebugger;
std::string debuggerName;
};

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

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

} // namespace jsc
} // namespace facebook

Expand Down
12 changes: 12 additions & 0 deletions ios/RCTJscInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,22 @@ class RCTJscInstance : public JSRuntimeFactory {
public:
RCTJscInstance();

void setEnableDebugger(bool enableDebugger);

void setDebuggerName(const std::string &debuggerName);

std::unique_ptr<JSRuntime> createJSRuntime(
std::shared_ptr<MessageQueueThread> 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
Expand Down
14 changes: 13 additions & 1 deletion ios/RCTJscInstance.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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<JSRuntime> RCTJscInstance::createJSRuntime(std::shared_ptr<MessageQueueThread> msgQueueThread) noexcept
{
return std::make_unique<JSIRuntimeHolder>(jsc::makeJSCRuntime());
jsc::RuntimeConfig rc = {
.enableDebugger = enableDebugger_,
.debuggerName = debuggerName_,
};
return std::make_unique<JSIRuntimeHolder>(jsc::makeJSCRuntime(std::move(rc)));
}

} // namespace react
Expand Down
Loading