Skip to content

Commit 4af3dc8

Browse files
authored
[0.73][JSCRuntime] Add runtimeConfig to set debugger options (#1958)
* Refactor _JSC_HAS_INSPECTABLE to support macOS * [JSCRuntime] Add runtimeConfig to set debugger options * Add macOS tags to RuntimeConfig changes
1 parent 074ca1e commit 4af3dc8

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();
@@ -290,11 +294,18 @@ class JSCRuntime : public jsi::Runtime {
290294
} \
291295
} while (0)
292296

293-
#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
297+
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) // [macOS]
294298
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 160400
295299
#define _JSC_HAS_INSPECTABLE
296300
#endif
297301
#endif
302+
// [macOS
303+
#if defined(__MAC_OS_X_VERSION_MAX_ALLOWED)
304+
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 130300
305+
#define _JSC_HAS_INSPECTABLE
306+
#endif
307+
#endif
308+
// macOS]
298309

299310
// JSStringRef utilities
300311
namespace {
@@ -358,6 +369,19 @@ JSCRuntime::JSCRuntime()
358369
JSGlobalContextRelease(ctx_);
359370
}
360371

372+
// [macOS
373+
JSCRuntime::JSCRuntime(const facebook::jsc::RuntimeConfig& rc)
374+
: JSCRuntime() {
375+
#ifdef _JSC_HAS_INSPECTABLE
376+
if (__builtin_available(macOS 13.3, iOS 16.4, tvOS 16.4, *)) {
377+
JSGlobalContextSetInspectable(ctx_, rc.enableDebugger);
378+
}
379+
#endif
380+
JSGlobalContextSetName(ctx_, JSStringCreateWithUTF8CString(rc.debuggerName.c_str()));
381+
382+
}
383+
// macOS]
384+
361385
JSCRuntime::JSCRuntime(JSGlobalContextRef ctx)
362386
: ctx_(JSGlobalContextRetain(ctx)),
363387
ctxInvalid_(false)
@@ -1504,5 +1528,11 @@ std::unique_ptr<jsi::Runtime> makeJSCRuntime() {
15041528
return std::make_unique<JSCRuntime>();
15051529
}
15061530

1531+
// [macOS
1532+
std::unique_ptr<jsi::Runtime> makeJSCRuntime(const facebook::jsc::RuntimeConfig& rc) {
1533+
return std::make_unique<JSCRuntime>(rc);
1534+
}
1535+
// macOS]
1536+
15071537
} // namespace jsc
15081538
} // 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)