Skip to content

Commit 1d1e5e6

Browse files
authored
feat: add a runtime config for debugger options (#17)
* feat: add a runtime config for debugger options * Update ios/RCTJscInstance.mm
1 parent 9b0a749 commit 1d1e5e6

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

Diff for: common/JSCRuntime.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class JSCRuntime : public jsi::Runtime {
3636
public:
3737
// Creates new context in new context group
3838
JSCRuntime();
39+
// Creates new context in new context group with config
40+
JSCRuntime(const facebook::jsc::RuntimeConfig& rc);
3941
// Retains ctx
4042
JSCRuntime(JSGlobalContextRef ctx);
4143
~JSCRuntime();
@@ -366,6 +368,17 @@ JSCRuntime::JSCRuntime()
366368
JSGlobalContextRelease(ctx_);
367369
}
368370

371+
JSCRuntime::JSCRuntime(const facebook::jsc::RuntimeConfig& rc)
372+
: JSCRuntime() {
373+
#ifdef _JSC_HAS_INSPECTABLE
374+
if (__builtin_available(macOS 13.3, iOS 16.4, tvOS 16.4, *)) {
375+
JSGlobalContextSetInspectable(ctx_, rc.enableDebugger);
376+
}
377+
#endif
378+
JSGlobalContextSetName(ctx_, JSStringCreateWithUTF8CString(rc.debuggerName.c_str()));
379+
380+
}
381+
369382
JSCRuntime::JSCRuntime(JSGlobalContextRef ctx)
370383
: ctx_(JSGlobalContextRetain(ctx)),
371384
ctxInvalid_(false)
@@ -1582,5 +1595,9 @@ std::unique_ptr<jsi::Runtime> makeJSCRuntime() {
15821595
return std::make_unique<JSCRuntime>();
15831596
}
15841597

1598+
std::unique_ptr<jsi::Runtime> makeJSCRuntime(const facebook::jsc::RuntimeConfig& rc) {
1599+
return std::make_unique<JSCRuntime>(rc);
1600+
}
1601+
15851602
} // namespace jsc
15861603
} // namespace facebook

Diff for: common/JSCRuntime.h

+7
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,15 @@
1515
namespace facebook {
1616
namespace jsc {
1717

18+
struct RuntimeConfig {
19+
bool enableDebugger;
20+
std::string debuggerName;
21+
};
22+
1823
std::unique_ptr<jsi::Runtime> makeJSCRuntime();
1924

25+
std::unique_ptr<jsi::Runtime> makeJSCRuntime(const facebook::jsc::RuntimeConfig& rc);
26+
2027
} // namespace jsc
2128
} // namespace facebook
2229

Diff for: ios/RCTJscInstance.h

+12
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,22 @@ class RCTJscInstance : public JSRuntimeFactory {
1818
public:
1919
RCTJscInstance();
2020

21+
void setEnableDebugger(bool enableDebugger);
22+
23+
void setDebuggerName(const std::string &debuggerName);
24+
2125
std::unique_ptr<JSRuntime> createJSRuntime(
2226
std::shared_ptr<MessageQueueThread> msgQueueThread) noexcept override;
2327

2428
~RCTJscInstance(){};
29+
30+
private:
31+
#if DEBUG
32+
bool enableDebugger_ = true;
33+
#else
34+
bool enableDebugger_ = false;
35+
#endif
36+
std::string debuggerName_ = "JSC React Native";
2537
};
2638
} // namespace react
2739
} // namespace facebook

Diff for: ios/RCTJscInstance.mm

+13-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,21 @@
1313

1414
RCTJscInstance::RCTJscInstance() {}
1515

16+
void RCTJscInstance::setEnableDebugger(bool enableDebugger) {
17+
enableDebugger_ = enableDebugger;
18+
}
19+
20+
void RCTJscInstance::setDebuggerName(const std::string &debuggerName) {
21+
debuggerName_ = debuggerName;
22+
}
23+
1624
std::unique_ptr<JSRuntime> RCTJscInstance::createJSRuntime(std::shared_ptr<MessageQueueThread> msgQueueThread) noexcept
1725
{
18-
return std::make_unique<JSIRuntimeHolder>(jsc::makeJSCRuntime());
26+
jsc::RuntimeConfig rc = {
27+
.enableDebugger = enableDebugger_,
28+
.debuggerName = debuggerName_,
29+
};
30+
return std::make_unique<JSIRuntimeHolder>(jsc::makeJSCRuntime(std::move(rc)));
1931
}
2032

2133
} // namespace react

0 commit comments

Comments
 (0)