Skip to content
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

[JSCRuntime] Add runtimeConfig to set debugger options #38942

Closed
wants to merge 2 commits into from
Closed
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
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)) {}

void setEnableDebugger(bool enableDebugger);

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

std::unique_ptr<JSExecutor> createJSExecutor(
std::shared_ptr<ExecutorDelegate> delegate,
std::shared_ptr<MessageQueueThread> jsQueue) override;

private:
JSIExecutor::RuntimeInstaller runtimeInstaller_;

#if DEBUG
bool enableDebugger_ = true;
#else
bool enableDebugger_ = false;
#endif
Comment on lines +30 to +34
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oversight caught internally: Initially this was always true so release builds would have the debugger enabled. I changed it so the default is true only for debug. This way, one could still enable debugging for a ship/release build if they wished.

I considered copying what Hermes does and putting all debugging code behind a custom preprocessor variable (#37723), but that seemed overkill and would prevent us from enable debugging on ship.
For reference, equivalent PRs in React Native macOS:
microsoft#1976
microsoft#1977
microsoft#1978
microsoft#1979

std::string debuggerName_ = "JSC React Native";
};

} // namespace facebook::react
16 changes: 13 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,22 @@

namespace facebook::react {

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

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

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_);
facebook::jsc::RuntimeConfig rc = {
.enableDebugger = enableDebugger_,
.debuggerName = debuggerName_,
};
return std::make_unique<JSIExecutor>(facebook::jsc::makeJSCRuntime(std::move(rc)), delegate, JSIExecutor::defaultTimeoutInvoker, runtimeInstaller_);
}

} // namespace facebook::react
17 changes: 17 additions & 0 deletions packages/react-native/ReactCommon/jsc/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 @@ -361,6 +363,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 @@ -1565,5 +1578,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 packages/react-native/ReactCommon/jsc/JSCRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@
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