Skip to content

Commit

Permalink
[JSCRuntime] Add runtimeConfig to set debugger options
Browse files Browse the repository at this point in the history
  • Loading branch information
Saadnajmi committed Oct 21, 2023
1 parent 5727c99 commit 123c61e
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 4 deletions.
7 changes: 7 additions & 0 deletions packages/react-native/React/CxxBridge/JSCExecutorFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@ 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_;

bool enableDebugger_ = true;
std::string debuggerName_ = "JSC React Native";
};

} // namespace react
Expand Down
15 changes: 13 additions & 2 deletions packages/react-native/React/CxxBridge/JSCExecutorFactory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,23 @@
namespace facebook {
namespace 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 react
Expand Down
3 changes: 1 addition & 2 deletions packages/react-native/ReactCommon/cxxreact/JSExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ class RN_EXPORT JSExecutor {
}

/**
* Returns whether or not the underlying executor supports debugging via the
* Chrome remote debugging protocol.
* Returns whether or not the underlying executor supports debugging.
*/
virtual bool isInspectable() {
return false;
Expand Down
21 changes: 21 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(facebook::jsc::runtimeConfig &rc);
// Retains ctx
JSCRuntime(JSGlobalContextRef ctx);
~JSCRuntime();
Expand Down Expand Up @@ -392,6 +394,17 @@ JSCRuntime::JSCRuntime()
JSGlobalContextRelease(ctx_);
}

JSCRuntime::JSCRuntime(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 @@ -481,7 +494,11 @@ std::string JSCRuntime::description() {
}

bool JSCRuntime::isInspectable() {
#ifdef _JSC_HAS_INSPECTABLE
return JSGlobalContextIsInspectable(ctx_);
#else
return false;
#endif
}

namespace {
Expand Down Expand Up @@ -1567,5 +1584,9 @@ std::unique_ptr<jsi::Runtime> makeJSCRuntime() {
return std::make_unique<JSCRuntime>();
}

std::unique_ptr<jsi::Runtime> makeJSCRuntime(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(facebook::jsc::runtimeConfig rc);

} // namespace jsc
} // namespace facebook

0 comments on commit 123c61e

Please sign in to comment.