Skip to content

Commit f72bf86

Browse files
authored
[0.72][JSCRuntime] Add runtimeConfig to set debugger options (#1959)
* Refactor _JSC_HAS_INSPECTABLE to support macOS * [JSCRuntime] Add runtimeConfig to set debugger options * Add macOS tags to RuntimeConfig changes
1 parent 5727c99 commit f72bf86

File tree

4 files changed

+66
-3
lines changed

4 files changed

+66
-3
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,23 @@ class JSCExecutorFactory : public JSExecutorFactory {
1717
explicit JSCExecutorFactory(JSIExecutor::RuntimeInstaller runtimeInstaller)
1818
: runtimeInstaller_(std::move(runtimeInstaller)) {}
1919

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

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

2839
} // namespace react

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,27 @@
1414
namespace facebook {
1515
namespace react {
1616

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

2540
} // namespace react

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

Lines changed: 29 additions & 1 deletion
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,7 +297,7 @@ 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
// This takes care of watch and tvos (due to backwards compatibility in
298302
// Availability.h
299303
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_9_0
@@ -316,6 +320,11 @@ class JSCRuntime : public jsi::Runtime {
316320
#if __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_12
317321
#define _JSC_NO_ARRAY_BUFFERS
318322
#endif
323+
// [macOS
324+
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 130300
325+
#define _JSC_HAS_INSPECTABLE
326+
#endif
327+
// macOS]
319328
#endif
320329

321330
// JSStringRef utilities
@@ -392,6 +401,19 @@ JSCRuntime::JSCRuntime()
392401
JSGlobalContextRelease(ctx_);
393402
}
394403

404+
// [macOS
405+
JSCRuntime::JSCRuntime(const facebook::jsc::RuntimeConfig& rc)
406+
: JSCRuntime() {
407+
#ifdef _JSC_HAS_INSPECTABLE
408+
if (__builtin_available(macOS 13.3, iOS 16.4, tvOS 16.4, *)) {
409+
JSGlobalContextSetInspectable(ctx_, rc.enableDebugger);
410+
}
411+
#endif
412+
JSGlobalContextSetName(ctx_, JSStringCreateWithUTF8CString(rc.debuggerName.c_str()));
413+
414+
}
415+
// macOS]
416+
395417
JSCRuntime::JSCRuntime(JSGlobalContextRef ctx)
396418
: ctx_(JSGlobalContextRetain(ctx)),
397419
ctxInvalid_(false)
@@ -1567,5 +1589,11 @@ std::unique_ptr<jsi::Runtime> makeJSCRuntime() {
15671589
return std::make_unique<JSCRuntime>();
15681590
}
15691591

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+
15701598
} // namespace jsc
15711599
} // namespace facebook

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

Lines changed: 9 additions & 0 deletions
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)