mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
e6995583d3
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43098 Changelog: [Internal] Wraps Hermes's `CDPHandler::getState()` API in an engine-agnostic abstraction (`RuntimeAgentDelegate::getExportedState`). An Agent's lifetime ends when its Target is destroyed, but it can occasionally be useful to persist some state for the "next" Target+Agent of the same type (in the same session) to read. `RuntimeAgentDelegate` is polymorphic and can't just write arbitrary data to SessionState. Instead, it can now *export* a state object that we'll store and pass to the next `RuntimeTargetDelegate::createAgentDelegate` call. Reviewed By: huntie Differential Revision: D53919696 fbshipit-source-id: a8e9b921bc8fc2d195c5dddea9537e6ead3d0358
51 lines
1.5 KiB
C++
51 lines
1.5 KiB
C++
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#include "JSExecutor.h"
|
|
|
|
#include "RAMBundleRegistry.h"
|
|
|
|
#include <folly/Conv.h>
|
|
#include <jsinspector-modern/ReactCdp.h>
|
|
|
|
#include <chrono>
|
|
|
|
namespace facebook::react {
|
|
|
|
std::string JSExecutor::getSyntheticBundlePath(
|
|
uint32_t bundleId,
|
|
const std::string& bundlePath) {
|
|
if (bundleId == RAMBundleRegistry::MAIN_BUNDLE_ID) {
|
|
return bundlePath;
|
|
}
|
|
return folly::to<std::string>("seg-", bundleId, ".js");
|
|
}
|
|
|
|
double JSExecutor::performanceNow() {
|
|
auto time = std::chrono::steady_clock::now();
|
|
auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(
|
|
time.time_since_epoch())
|
|
.count();
|
|
|
|
constexpr double NANOSECONDS_IN_MILLISECOND = 1000000.0;
|
|
return duration / NANOSECONDS_IN_MILLISECOND;
|
|
}
|
|
|
|
std::unique_ptr<jsinspector_modern::RuntimeAgentDelegate>
|
|
JSExecutor::createAgentDelegate(
|
|
jsinspector_modern::FrontendChannel frontendChannel,
|
|
jsinspector_modern::SessionState& sessionState,
|
|
std::unique_ptr<jsinspector_modern::RuntimeAgentDelegate::ExportedState>,
|
|
const jsinspector_modern::ExecutionContextDescription&
|
|
executionContextDescription) {
|
|
(void)executionContextDescription;
|
|
return std::make_unique<jsinspector_modern::FallbackRuntimeAgentDelegate>(
|
|
std::move(frontendChannel), sessionState, getDescription());
|
|
}
|
|
|
|
} // namespace facebook::react
|