Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ HermesExecutor::getRuntimeTargetDelegate() {
if (!targetDelegate_) {
targetDelegate_ =
std::make_unique<jsinspector_modern::HermesRuntimeTargetDelegate>(
hermesRuntime_);
hermesRuntime_, *hermesRuntime_);
}
return *targetDelegate_;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ const uint16_t HERMES_SAMPLING_FREQUENCY_HZ = 10000;
class HermesRuntimeSamplingProfileDelegate {
public:
explicit HermesRuntimeSamplingProfileDelegate(
std::shared_ptr<HermesRuntime> hermesRuntime)
: hermesRuntime_(std::move(hermesRuntime)) {}
std::shared_ptr<jsi::Runtime> runtime,
hermes::HermesRuntime& hermesRuntime)
: runtime_(std::move(runtime)), hermesRuntime_(hermesRuntime) {}

void startSampling() {
auto* hermesAPI = jsi::castInterface<IHermesRootAPI>(makeHermesRootAPI());
Expand All @@ -52,11 +53,12 @@ class HermesRuntimeSamplingProfileDelegate {
tracing::RuntimeSamplingProfile collectSamplingProfile() {
return tracing::HermesRuntimeSamplingProfileSerializer::
serializeToTracingSamplingProfile(
hermesRuntime_->dumpSampledTraceToProfile());
hermesRuntime_.dumpSampledTraceToProfile());
}

private:
std::shared_ptr<HermesRuntime> hermesRuntime_;
std::shared_ptr<jsi::Runtime> runtime_;
HermesRuntime& hermesRuntime_;
};

} // namespace
Expand Down Expand Up @@ -93,13 +95,16 @@ class HermesRuntimeTargetDelegate::Impl final : public RuntimeTargetDelegate {
public:
explicit Impl(
HermesRuntimeTargetDelegate& delegate,
std::shared_ptr<HermesRuntime> hermesRuntime)
std::shared_ptr<jsi::Runtime> runtime,
HermesRuntime& hermesRuntime)
: delegate_(delegate),
runtime_(hermesRuntime),
cdpDebugAPI_(CDPDebugAPI::create(*runtime_)),
runtime_(runtime),
hermesRuntime_(hermesRuntime),
cdpDebugAPI_(CDPDebugAPI::create(hermesRuntime_)),
samplingProfileDelegate_(
std::make_unique<HermesRuntimeSamplingProfileDelegate>(
std::move(hermesRuntime))) {}
std::move(runtime),
hermesRuntime_)) {}

CDPDebugAPI& getCDPDebugAPI() {
return *cdpDebugAPI_;
Expand All @@ -119,7 +124,7 @@ class HermesRuntimeTargetDelegate::Impl final : public RuntimeTargetDelegate {
sessionState,
std::move(previouslyExportedState),
executionContextDescription,
*runtime_,
hermesRuntime_,
delegate_,
std::move(runtimeExecutor)));
}
Expand Down Expand Up @@ -209,7 +214,7 @@ class HermesRuntimeTargetDelegate::Impl final : public RuntimeTargetDelegate {
// properly representing the stack trace in other use cases, where native
// frames aren't stripped on serialisation.
return std::make_unique<HermesStackTraceWrapper>(
runtime_->getDebugger().captureStackTrace());
hermesRuntime_.getDebugger().captureStackTrace());
}

void enableSamplingProfiler() override {
Expand Down Expand Up @@ -267,7 +272,8 @@ class HermesRuntimeTargetDelegate::Impl final : public RuntimeTargetDelegate {

private:
HermesRuntimeTargetDelegate& delegate_;
std::shared_ptr<HermesRuntime> runtime_;
std::shared_ptr<jsi::Runtime> runtime_;
HermesRuntime& hermesRuntime_;
const std::unique_ptr<CDPDebugAPI> cdpDebugAPI_;
std::unique_ptr<HermesRuntimeSamplingProfileDelegate>
samplingProfileDelegate_;
Expand All @@ -284,11 +290,13 @@ class HermesRuntimeTargetDelegate::Impl final
public:
explicit Impl(
HermesRuntimeTargetDelegate&,
std::shared_ptr<HermesRuntime> hermesRuntime)
: FallbackRuntimeTargetDelegate{hermesRuntime->description()},
std::shared_ptr<jsi::Runtime> runtime,
HermesRuntime& hermesRuntime)
: FallbackRuntimeTargetDelegate{hermesRuntime.description()},
samplingProfileDelegate_(
std::make_unique<HermesRuntimeSamplingProfileDelegate>(
std::move(hermesRuntime))) {}
std::move(runtime),
hermesRuntime)) {}

void enableSamplingProfiler() override {
samplingProfileDelegate_->startSampling();
Expand All @@ -310,8 +318,9 @@ class HermesRuntimeTargetDelegate::Impl final
#endif // HERMES_ENABLE_DEBUGGER

HermesRuntimeTargetDelegate::HermesRuntimeTargetDelegate(
std::shared_ptr<HermesRuntime> hermesRuntime)
: impl_(std::make_unique<Impl>(*this, std::move(hermesRuntime))) {}
std::shared_ptr<jsi::Runtime> runtime,
HermesRuntime& hermesRuntime)
: impl_(std::make_unique<Impl>(*this, std::move(runtime), hermesRuntime)) {}

HermesRuntimeTargetDelegate::~HermesRuntimeTargetDelegate() = default;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class HermesRuntimeTargetDelegate : public RuntimeTargetDelegate {
/**
* Creates a HermesRuntimeTargetDelegate for the given runtime.
*/
explicit HermesRuntimeTargetDelegate(std::shared_ptr<hermes::HermesRuntime> hermesRuntime);
explicit HermesRuntimeTargetDelegate(std::shared_ptr<jsi::Runtime> runtime, hermes::HermesRuntime &hermesRuntime);

~HermesRuntimeTargetDelegate() override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ JsiIntegrationTestHermesEngineAdapter::JsiIntegrationTestHermesEngineAdapter(
::hermes::vm::CompilationMode::ForceLazyCompilation)
.build())},
jsExecutor_{jsExecutor},
runtimeTargetDelegate_{runtime_} {
runtimeTargetDelegate_{runtime_, *runtime_} {
// NOTE: In React Native, registerForProfiling is called by
// HermesInstance::unstable_initializeOnJsThread, called from
// ReactInstance::initializeRuntime. Ideally, we should figure out how to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ class DecoratedRuntime : public jsi::RuntimeDecorator<jsi::Runtime> {

class HermesJSRuntime : public JSRuntime {
public:
HermesJSRuntime(std::unique_ptr<HermesRuntime> runtime)
: runtime_(std::move(runtime)) {}
HermesJSRuntime(
std::shared_ptr<jsi::Runtime> runtime,
HermesRuntime& hermesRuntime)
: runtime_(std::move(runtime)), hermesRuntime_(hermesRuntime) {}

jsi::Runtime& getRuntime() noexcept override {
return *runtime_;
Expand All @@ -108,17 +110,18 @@ class HermesJSRuntime : public JSRuntime {
jsinspector_modern::RuntimeTargetDelegate& getRuntimeTargetDelegate()
override {
if (!targetDelegate_) {
targetDelegate_.emplace(runtime_);
targetDelegate_.emplace(runtime_, hermesRuntime_);
}
return *targetDelegate_;
}

void unstable_initializeOnJsThread() override {
runtime_->registerForProfiling();
hermesRuntime_.registerForProfiling();
}

private:
std::shared_ptr<HermesRuntime> runtime_;
std::shared_ptr<jsi::Runtime> runtime_;
HermesRuntime& hermesRuntime_;
std::optional<jsinspector_modern::HermesRuntimeTargetDelegate>
targetDelegate_;
};
Expand Down Expand Up @@ -173,7 +176,9 @@ std::unique_ptr<JSRuntime> HermesInstance::createJSRuntime(
(void)msgQueueThread;
#endif

return std::make_unique<HermesJSRuntime>(std::move(hermesRuntime));
HermesRuntime& hermesRuntimeRef = *hermesRuntime;
return std::make_unique<HermesJSRuntime>(
std::move(hermesRuntime), hermesRuntimeRef);
}

} // namespace facebook::react
Loading