Skip to content

Commit 43122d4

Browse files
authored
[JSCRuntime] Add runtimeConfig to set debugger options (#1957)
1 parent 1aa1700 commit 43122d4

File tree

4 files changed

+68
-4
lines changed

4 files changed

+68
-4
lines changed

packages/react-native/React/CxxBridge/JSCExecutorFactory.h

+11
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,23 @@ class JSCExecutorFactory : public JSExecutorFactory {
1616
explicit JSCExecutorFactory(JSIExecutor::RuntimeInstaller runtimeInstaller)
1717
: runtimeInstaller_(std::move(runtimeInstaller)) {}
1818

19+
// [macOS
20+
void setEnableDebugger(bool enableDebugger);
21+
22+
void setDebuggerName(const std::string &debuggerName);
23+
// macOS]
24+
1925
std::unique_ptr<JSExecutor> createJSExecutor(
2026
std::shared_ptr<ExecutorDelegate> delegate,
2127
std::shared_ptr<MessageQueueThread> jsQueue) override;
2228

2329
private:
2430
JSIExecutor::RuntimeInstaller runtimeInstaller_;
31+
32+
// [macOS
33+
bool enableDebugger_ = true;
34+
std::string debuggerName_ = "JSC React Native";
35+
// macOS]
2536
};
2637

2738
} // namespace facebook::react

packages/react-native/React/CxxBridge/JSCExecutorFactory.mm

+17-3
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,26 @@
1313

1414
namespace facebook::react {
1515

16+
// [macOS
17+
void JSCExecutorFactory::setEnableDebugger(bool enableDebugger) {
18+
enableDebugger_ = enableDebugger;
19+
}
20+
21+
void JSCExecutorFactory::setDebuggerName(const std::string &debuggerName) {
22+
debuggerName_ = debuggerName;
23+
}
24+
// macOS]
25+
1626
std::unique_ptr<JSExecutor> JSCExecutorFactory::createJSExecutor(
1727
std::shared_ptr<ExecutorDelegate> delegate,
1828
std::shared_ptr<MessageQueueThread> __unused jsQueue)
1929
{
20-
return std::make_unique<JSIExecutor>(
21-
facebook::jsc::makeJSCRuntime(), delegate, JSIExecutor::defaultTimeoutInvoker, runtimeInstaller_);
30+
// [macOS
31+
facebook::jsc::RuntimeConfig rc = {
32+
.enableDebugger = enableDebugger_,
33+
.debuggerName = debuggerName_,
34+
};
35+
return std::make_unique<JSIExecutor>(facebook::jsc::makeJSCRuntime(std::move(rc)), delegate, JSIExecutor::defaultTimeoutInvoker, runtimeInstaller_);
36+
// macOS]
2237
}
23-
2438
} // namespace facebook::react

packages/react-native/ReactCommon/jsc/JSCRuntime.cpp

+31-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ class JSCRuntime : public jsi::Runtime {
3636
public:
3737
// Creates new context in new context group
3838
JSCRuntime();
39+
// [macOS
40+
// Creates new context in new context group with config
41+
JSCRuntime(const facebook::jsc::RuntimeConfig& rc);
42+
// macOS]
3943
// Retains ctx
4044
JSCRuntime(JSGlobalContextRef ctx);
4145
~JSCRuntime();
@@ -293,11 +297,18 @@ class JSCRuntime : public jsi::Runtime {
293297
} \
294298
} while (0)
295299

296-
#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
300+
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) // [macOS]
297301
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 160400
298302
#define _JSC_HAS_INSPECTABLE
299303
#endif
300304
#endif
305+
// [macOS
306+
#if defined(__MAC_OS_X_VERSION_MAX_ALLOWED)
307+
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 130300
308+
#define _JSC_HAS_INSPECTABLE
309+
#endif
310+
#endif
311+
// macOS]
301312

302313
// JSStringRef utilities
303314
namespace {
@@ -361,6 +372,19 @@ JSCRuntime::JSCRuntime()
361372
JSGlobalContextRelease(ctx_);
362373
}
363374

375+
// [macOS
376+
JSCRuntime::JSCRuntime(const facebook::jsc::RuntimeConfig& rc)
377+
: JSCRuntime() {
378+
#ifdef _JSC_HAS_INSPECTABLE
379+
if (__builtin_available(macOS 13.3, iOS 16.4, tvOS 16.4, *)) {
380+
JSGlobalContextSetInspectable(ctx_, rc.enableDebugger);
381+
}
382+
#endif
383+
JSGlobalContextSetName(ctx_, JSStringCreateWithUTF8CString(rc.debuggerName.c_str()));
384+
385+
}
386+
// macOS]
387+
364388
JSCRuntime::JSCRuntime(JSGlobalContextRef ctx)
365389
: ctx_(JSGlobalContextRetain(ctx)),
366390
ctxInvalid_(false)
@@ -1565,5 +1589,11 @@ std::unique_ptr<jsi::Runtime> makeJSCRuntime() {
15651589
return std::make_unique<JSCRuntime>();
15661590
}
15671591

1592+
// [macOS
1593+
std::unique_ptr<jsi::Runtime> makeJSCRuntime(const facebook::jsc::RuntimeConfig& rc) {
1594+
return std::make_unique<JSCRuntime>(rc);
1595+
}
1596+
// macOS]
1597+
15681598
} // namespace jsc
15691599
} // namespace facebook

packages/react-native/ReactCommon/jsc/JSCRuntime.h

+9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,16 @@
1313
namespace facebook {
1414
namespace jsc {
1515

16+
// [macOS
17+
struct RuntimeConfig {
18+
bool enableDebugger;
19+
std::string debuggerName;
20+
};
21+
// macOS]
22+
1623
std::unique_ptr<jsi::Runtime> makeJSCRuntime();
1724

25+
std::unique_ptr<jsi::Runtime> makeJSCRuntime(const facebook::jsc::RuntimeConfig& rc); // [macOS]
26+
1827
} // namespace jsc
1928
} // namespace facebook

0 commit comments

Comments
 (0)