Skip to content
Closed
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 @@ -14,9 +14,10 @@

#include <jsinspector-modern/InspectorInterfaces.h>

#include <utility>

namespace facebook::hermes::inspector_modern::chrome {

using ::facebook::react::jsinspector_modern::IInspector;
using ::facebook::react::jsinspector_modern::ILocalConnection;
using ::facebook::react::jsinspector_modern::IRemoteConnection;

Expand All @@ -27,7 +28,7 @@ class LocalConnection : public ILocalConnection {
LocalConnection(
std::shared_ptr<hermes::inspector_modern::chrome::CDPHandler> conn,
std::shared_ptr<std::unordered_set<std::string>> inspectedContexts);
~LocalConnection();
~LocalConnection() override;

void sendMessage(std::string message) override;
void disconnect() override;
Expand All @@ -40,14 +41,14 @@ class LocalConnection : public ILocalConnection {
LocalConnection::LocalConnection(
std::shared_ptr<hermes::inspector_modern::chrome::CDPHandler> conn,
std::shared_ptr<std::unordered_set<std::string>> inspectedContexts)
: conn_(conn), inspectedContexts_(inspectedContexts) {
: conn_(conn), inspectedContexts_(std::move(inspectedContexts)) {
inspectedContexts_->insert(conn->getTitle());
}

LocalConnection::~LocalConnection() = default;

void LocalConnection::sendMessage(std::string str) {
conn_->handle(std::move(str));
void LocalConnection::sendMessage(std::string message) {
conn_->handle(std::move(message));
}

void LocalConnection::disconnect() {
Expand Down Expand Up @@ -76,9 +77,9 @@ DebugSessionToken ConnectionDemux::enableDebugging(
// register the new CS VM instance, check for any previous CS VM (via strcmp
// of title) and remove them.
std::vector<int> pagesToDelete;
for (auto it = conns_.begin(); it != conns_.end(); ++it) {
if (it->second->getTitle() == title) {
pagesToDelete.push_back(it->first);
for (auto& conn : conns_) {
if (conn.second->getTitle() == title) {
pagesToDelete.push_back(conn.first);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <hermes/hermes.h>
#include <jsinspector-modern/ReactCdp.h>

#include <utility>

using namespace facebook::hermes;

namespace facebook::react::jsinspector_modern {
Expand All @@ -25,7 +27,7 @@ class HermesRuntimeAgentDelegate::Impl final : public RuntimeAgentDelegate {
explicit HermesStateWrapper(HermesState state) : state_(std::move(state)) {}

static HermesState unwrapDestructively(ExportedState* wrapper) {
if (!wrapper) {
if (wrapper == nullptr) {
return {};
}
if (auto* typedWrapper = dynamic_cast<HermesStateWrapper*>(wrapper)) {
Expand Down Expand Up @@ -58,7 +60,7 @@ class HermesRuntimeAgentDelegate::Impl final : public RuntimeAgentDelegate {
runtimeExecutor(
[&runtime, fn = std::move(fn)](auto&) { fn(runtime); });
},
frontendChannel,
std::move(frontendChannel),
HermesStateWrapper::unwrapDestructively(
previouslyExportedState.get()))) {
if (sessionState.isRuntimeDomainEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <chrono>
#include <string>
#include <utility>

using namespace std::chrono;
using namespace std::literals::string_view_literals;
Expand All @@ -26,7 +27,8 @@ FallbackRuntimeAgentDelegate::FallbackRuntimeAgentDelegate(
FrontendChannel frontendChannel,
const SessionState& sessionState,
std::string engineDescription)
: frontendChannel_(frontendChannel), engineDescription_(engineDescription) {
: frontendChannel_(std::move(frontendChannel)),
engineDescription_(std::move(engineDescription)) {
if (sessionState.isLogDomainEnabled) {
sendFallbackRuntimeWarning();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <folly/json.h>

#include <memory>
#include <utility>

namespace facebook::react::jsinspector_modern {

Expand Down Expand Up @@ -180,7 +181,7 @@ HostTarget::~HostTarget() {
"HostTargetSession objects must be destroyed before their HostTarget. Did you call getInspectorInstance().removePage()?");
}

HostTargetDelegate::~HostTargetDelegate() {}
HostTargetDelegate::~HostTargetDelegate() = default;

InstanceTarget& HostTarget::registerInstance(InstanceTargetDelegate& delegate) {
assert(!currentInstance_ && "Only one instance allowed");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@
#include <cassert>
#include <list>
#include <mutex>
#include <utility>

namespace facebook::react::jsinspector_modern {

// pure destructors in C++ are odd. You would think they don't want an
// implementation, but in fact the linker requires one. Define them to be
// empty so that people don't count on them for any particular behaviour.
IDestructible::~IDestructible() {}
ILocalConnection::~ILocalConnection() {}
IRemoteConnection::~IRemoteConnection() {}
IInspector::~IInspector() {}
IPageStatusListener::~IPageStatusListener() {}
IDestructible::~IDestructible() = default;
ILocalConnection::~ILocalConnection() = default;
IRemoteConnection::~IRemoteConnection() = default;
IInspector::~IInspector() = default;
IPageStatusListener::~IPageStatusListener() = default;

folly::dynamic targetCapabilitiesToDynamic(
const InspectorTargetCapabilities& capabilities) {
Expand Down Expand Up @@ -54,8 +55,8 @@ class InspectorImpl : public IInspector {
public:
Page(
int id,
const std::string& description,
const std::string& vm,
std::string description,
std::string vm,
ConnectFunc connectFunc,
InspectorTargetCapabilities capabilities);
operator InspectorPageDescription() const;
Expand All @@ -77,13 +78,13 @@ class InspectorImpl : public IInspector {

InspectorImpl::Page::Page(
int id,
const std::string& description,
const std::string& vm,
std::string description,
std::string vm,
ConnectFunc connectFunc,
InspectorTargetCapabilities capabilities)
: id_(id),
description_(description),
vm_(vm),
description_(std::move(description)),
vm_(std::move(vm)),
connectFunc_(std::move(connectFunc)),
capabilities_(capabilities) {}

Expand Down Expand Up @@ -122,7 +123,7 @@ void InspectorImpl::removePage(int pageId) {
std::scoped_lock lock(mutex_);

if (pages_.erase(pageId) != 0) {
for (auto& listenerWeak : listeners_) {
for (const auto& listenerWeak : listeners_) {
if (auto listener = listenerWeak.lock()) {
listener->onPageRemoved(pageId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <glog/logging.h>
#include <cerrno>
#include <chrono>
#include <utility>

using namespace std::literals;

Expand All @@ -34,7 +35,10 @@ InspectorPackagerConnection::Impl::create(
// No make_shared because the constructor is private
std::shared_ptr<InspectorPackagerConnection::Impl> impl(
new InspectorPackagerConnection::Impl(
url, deviceName, appName, std::move(delegate)));
std::move(url),
std::move(deviceName),
std::move(appName),
std::move(delegate)));
getInspectorInstance().registerPageStatusListener(impl);
return impl;
}
Expand All @@ -50,7 +54,7 @@ InspectorPackagerConnection::Impl::Impl(
delegate_(std::move(delegate)) {}

void InspectorPackagerConnection::Impl::handleProxyMessage(
folly::const_dynamic_view message) {
const folly::const_dynamic_view& message) {
std::string event = message.descend("event").string_or(INVALID);
if (event == "getPages") {
sendToPackager(
Expand All @@ -67,7 +71,7 @@ void InspectorPackagerConnection::Impl::handleProxyMessage(
}

void InspectorPackagerConnection::Impl::sendEventToAllConnections(
std::string event) {
const std::string& event) {
for (auto& connection : inspectorSessions_) {
connection.second.localConnection->sendMessage(event);
}
Expand All @@ -81,7 +85,7 @@ void InspectorPackagerConnection::Impl::closeAllConnections() {
}

void InspectorPackagerConnection::Impl::handleConnect(
folly::const_dynamic_view payload) {
const folly::const_dynamic_view& payload) {
std::string pageId = payload.descend("pageId").string_or(INVALID);
auto existingConnectionIt = inspectorSessions_.find(pageId);
if (existingConnectionIt != inspectorSessions_.end()) {
Expand All @@ -91,7 +95,7 @@ void InspectorPackagerConnection::Impl::handleConnect(
LOG(WARNING) << "Already connected: " << pageId;
return;
}
int pageIdInt;
int pageIdInt = 0;
try {
pageIdInt = std::stoi(pageId);
} catch (...) {
Expand Down Expand Up @@ -123,7 +127,7 @@ void InspectorPackagerConnection::Impl::handleConnect(
}

void InspectorPackagerConnection::Impl::handleDisconnect(
folly::const_dynamic_view payload) {
const folly::const_dynamic_view& payload) {
std::string pageId = payload.descend("pageId").string_or(INVALID);
auto inspectorConnection = removeConnectionForPage(pageId);
if (inspectorConnection) {
Expand All @@ -132,7 +136,8 @@ void InspectorPackagerConnection::Impl::handleDisconnect(
}

std::unique_ptr<ILocalConnection>
InspectorPackagerConnection::Impl::removeConnectionForPage(std::string pageId) {
InspectorPackagerConnection::Impl::removeConnectionForPage(
const std::string& pageId) {
auto it = inspectorSessions_.find(pageId);
if (it != inspectorSessions_.end()) {
auto connection = std::move(it->second);
Expand All @@ -143,7 +148,7 @@ InspectorPackagerConnection::Impl::removeConnectionForPage(std::string pageId) {
}

void InspectorPackagerConnection::Impl::handleWrappedEvent(
folly::const_dynamic_view payload) {
const folly::const_dynamic_view& payload) {
std::string pageId = payload.descend("pageId").string_or(INVALID);
std::string wrappedEvent = payload.descend("wrappedEvent").string_or(INVALID);
auto connectionIt = inspectorSessions_.find(pageId);
Expand Down Expand Up @@ -195,7 +200,7 @@ void InspectorPackagerConnection::Impl::didReceiveMessage(
<< e.what();
return;
}
handleProxyMessage(std::move(parsedJSON));
handleProxyMessage(parsedJSON);
}

void InspectorPackagerConnection::Impl::didOpen() {
Expand Down Expand Up @@ -277,7 +282,8 @@ void InspectorPackagerConnection::Impl::closeQuietly() {
disposeWebSocket();
}

void InspectorPackagerConnection::Impl::sendToPackager(folly::dynamic message) {
void InspectorPackagerConnection::Impl::sendToPackager(
const folly::dynamic& message) {
if (!webSocket_) {
return;
}
Expand All @@ -288,7 +294,7 @@ void InspectorPackagerConnection::Impl::sendToPackager(folly::dynamic message) {
void InspectorPackagerConnection::Impl::scheduleSendToPackager(
folly::dynamic message,
SessionId sourceSessionId,
std::string sourcePageId) {
const std::string& sourcePageId) {
delegate_->scheduleCallback(
[weakSelf = weak_from_this(),
message = std::move(message),
Expand Down Expand Up @@ -331,7 +337,7 @@ InspectorPackagerConnection::Impl::RemoteConnection::RemoteConnection(
std::weak_ptr<InspectorPackagerConnection::Impl> owningPackagerConnection,
std::string pageId,
SessionId sessionId)
: owningPackagerConnection_(owningPackagerConnection),
: owningPackagerConnection_(std::move(owningPackagerConnection)),
pageId_(std::move(pageId)),
sessionId_(sessionId) {}

Expand Down Expand Up @@ -367,7 +373,11 @@ InspectorPackagerConnection::InspectorPackagerConnection(
std::string deviceName,
std::string appName,
std::unique_ptr<InspectorPackagerConnectionDelegate> delegate)
: impl_(Impl::create(url, deviceName, appName, std::move(delegate))) {}
: impl_(Impl::create(
std::move(url),
std::move(deviceName),
std::move(appName),
std::move(delegate))) {}

bool InspectorPackagerConnection::isConnected() const {
return impl_->isConnected();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ class InspectorPackagerConnection::Impl
bool isConnected() const;
void connect();
void closeQuietly();
void sendEventToAllConnections(std::string event);
std::unique_ptr<ILocalConnection> removeConnectionForPage(std::string pageId);
void sendEventToAllConnections(const std::string& event);
std::unique_ptr<ILocalConnection> removeConnectionForPage(
const std::string& pageId);

/**
* Send a message to the packager as soon as possible. This method is safe
Expand All @@ -51,7 +52,7 @@ class InspectorPackagerConnection::Impl
void scheduleSendToPackager(
folly::dynamic message,
SessionId sourceSessionId,
std::string sourcePageId);
const std::string& sourcePageId);

private:
struct Session {
Expand All @@ -68,15 +69,15 @@ class InspectorPackagerConnection::Impl
Impl(const Impl&) = delete;
Impl& operator=(const Impl&) = delete;

void handleDisconnect(folly::const_dynamic_view payload);
void handleConnect(folly::const_dynamic_view payload);
void handleWrappedEvent(folly::const_dynamic_view wrappedEvent);
void handleProxyMessage(folly::const_dynamic_view message);
void handleDisconnect(const folly::const_dynamic_view& payload);
void handleConnect(const folly::const_dynamic_view& payload);
void handleWrappedEvent(const folly::const_dynamic_view& payload);
void handleProxyMessage(const folly::const_dynamic_view& message);
folly::dynamic pages();
void reconnect();
void closeAllConnections();
void disposeWebSocket();
void sendToPackager(folly::dynamic message);
void sendToPackager(const folly::dynamic& message);

void abort(
std::optional<int> posixCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#include <jsinspector-modern/cdp/CdpJson.h>

#include <utility>

namespace facebook::react::jsinspector_modern {

InstanceAgent::InstanceAgent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#include <jsinspector-modern/InstanceTarget.h>

#include <utility>

namespace facebook::react::jsinspector_modern {

std::shared_ptr<InstanceTarget> InstanceTarget::create(
Expand All @@ -30,10 +32,10 @@ InstanceTarget::InstanceTarget(
(void)delegate_;
}

InstanceTargetDelegate::~InstanceTargetDelegate() {}
InstanceTargetDelegate::~InstanceTargetDelegate() = default;

std::shared_ptr<InstanceAgent> InstanceTarget::createAgent(
FrontendChannel channel,
const FrontendChannel& channel,
SessionState& sessionState) {
auto instanceAgent =
std::make_shared<InstanceAgent>(channel, *this, sessionState);
Expand Down Expand Up @@ -61,7 +63,7 @@ RuntimeTarget& InstanceTarget::registerRuntime(
.name = "main",
.uniqueId = std::nullopt},
delegate,
jsExecutor,
std::move(jsExecutor),
makeVoidExecutor(executorFromThis()));

agents_.forEach([currentRuntime = &*currentRuntime_](InstanceAgent& agent) {
Expand Down
Loading
Loading