1717
1818#include < hermes/inspector-modern/chrome/HermesRuntimeTargetDelegate.h>
1919
20- #if defined(HERMES_ENABLE_DEBUGGER) && !defined(HERMES_V1_ENABLED)
21- #include < hermes/inspector-modern/chrome/Registration.h>
22- #include < hermes/inspector/RuntimeAdapter.h>
23- #endif
24-
2520using namespace facebook ::hermes;
2621using namespace facebook ::jsi;
2722
2823namespace facebook ::react {
2924
3025namespace {
3126
32- #if defined(HERMES_ENABLE_DEBUGGER) && !defined(HERMES_V1_ENABLED)
33-
34- class HermesExecutorRuntimeAdapter
35- : public facebook::hermes::inspector_modern::RuntimeAdapter {
36- public:
37- HermesExecutorRuntimeAdapter (
38- std::shared_ptr<HermesRuntime> runtime,
39- std::shared_ptr<MessageQueueThread> thread)
40- : runtime_(runtime), thread_(std::move(thread)) {}
41-
42- virtual ~HermesExecutorRuntimeAdapter () = default ;
43-
44- HermesRuntime& getRuntime () override {
45- return *runtime_;
46- }
47-
48- void tickleJs () override {
49- thread_->runOnQueue (
50- [weakRuntime = std::weak_ptr<HermesRuntime>(runtime_)]() {
51- auto runtime = weakRuntime.lock ();
52- if (!runtime) {
53- return ;
54- }
55- jsi::Function func =
56- runtime->global ().getPropertyAsFunction (*runtime, " __tickleJs" );
57- func.call (*runtime);
58- });
59- }
60-
61- private:
62- std::shared_ptr<HermesRuntime> runtime_;
63-
64- std::shared_ptr<MessageQueueThread> thread_;
65- };
66-
67- #endif // defined(HERMES_ENABLE_DEBUGGER) && !defined(HERMES_V1_ENABLED)
68-
6927struct ReentrancyCheck {
7028// This is effectively a very subtle and complex assert, so only
7129// include it in builds which would include asserts.
@@ -133,14 +91,11 @@ struct ReentrancyCheck {
13391#endif
13492};
13593
136- // This adds ReentrancyCheck and debugger enable/teardown to the given
137- // Runtime.
94+ // This adds ReentrancyCheck to the given Runtime.
13895class DecoratedRuntime : public jsi ::WithRuntimeDecorator<ReentrancyCheck> {
13996 public:
14097 // The first argument may be another decorater which itself
14198 // decorates the real HermesRuntime, depending on the build config.
142- // The second argument is the real HermesRuntime as well to
143- // manage the debugger registration.
14499 DecoratedRuntime (
145100 std::unique_ptr<Runtime> runtime,
146101 HermesRuntime& hermesRuntime,
@@ -149,42 +104,17 @@ class DecoratedRuntime : public jsi::WithRuntimeDecorator<ReentrancyCheck> {
149104 const std::string& debuggerName)
150105 : jsi::WithRuntimeDecorator<ReentrancyCheck>(*runtime, reentrancyCheck_),
151106 runtime_ (std::move(runtime)) {
152- #if defined(HERMES_ENABLE_DEBUGGER) && !defined(HERMES_V1_ENABLED)
153- enableDebugger_ = enableDebugger;
154- if (enableDebugger_) {
155- std::shared_ptr<HermesRuntime> rt (runtime_, &hermesRuntime);
156- auto adapter =
157- std::make_unique<HermesExecutorRuntimeAdapter>(rt, jsQueue);
158- debugToken_ = facebook::hermes::inspector_modern::chrome::enableDebugging (
159- std::move (adapter), debuggerName);
160- }
161- #else
107+ (void )hermesRuntime;
162108 (void )jsQueue;
163- #endif // HERMES_ENABLE_DEBUGGER
109+ (void )enableDebugger;
110+ (void )debuggerName;
164111 }
165112
166- ~DecoratedRuntime () {
167- #if defined(HERMES_ENABLE_DEBUGGER) && !defined(HERMES_V1_ENABLED)
168- if (enableDebugger_) {
169- facebook::hermes::inspector_modern::chrome::disableDebugging (debugToken_);
170- }
171- #endif // HERMES_ENABLE_DEBUGGER
172- }
113+ ~DecoratedRuntime () {}
173114
174115 private:
175- // runtime_ is a potentially decorated Runtime.
176- // hermesRuntime is a reference to a HermesRuntime managed by runtime_.
177- //
178- // HermesExecutorRuntimeAdapter requirements are kept, because the
179- // dtor will disable debugging on the HermesRuntime before the
180- // member managing it is destroyed.
181-
182116 std::shared_ptr<Runtime> runtime_;
183117 ReentrancyCheck reentrancyCheck_;
184- #if defined(HERMES_ENABLE_DEBUGGER) && !defined(HERMES_V1_ENABLED)
185- bool enableDebugger_;
186- facebook::hermes::inspector_modern::chrome::DebugSessionToken debugToken_;
187- #endif // HERMES_ENABLE_DEBUGGER
188118};
189119
190120} // namespace
@@ -221,10 +151,7 @@ std::unique_ptr<JSExecutor> HermesExecutorFactory::createJSExecutor(
221151 //
222152 // DecoratedRuntime is held by JSIExecutor. When it gets used, it
223153 // will check that it's on the right thread, do any necessary trace
224- // logging, then call the real HermesRuntime. When it is destroyed,
225- // it will shut down the debugger before the HermesRuntime is. In
226- // the normal case where debugging is not compiled in,
227- // all that's left is the thread checking.
154+ // logging, then call the real HermesRuntime.
228155
229156 // Add js engine information to Error.prototype so in error reporting we
230157 // can send this information.
0 commit comments