Skip to content

Commit 546e276

Browse files
Apply clang-tidy setting: jsinspectormodern (#52741)
Summary: Pull Request resolved: #52741 Changelog: [Internal] Reviewed By: cipolleschi Differential Revision: D78634934 fbshipit-source-id: 03c4c8f5287452fb19fdce69e93686a04525eba5
1 parent 70f7a50 commit 546e276

21 files changed

+105
-83
lines changed

packages/react-native/ReactCommon/hermes/inspector-modern/chrome/ConnectionDemux.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414

1515
#include <jsinspector-modern/InspectorInterfaces.h>
1616

17+
#include <utility>
18+
1719
namespace facebook::hermes::inspector_modern::chrome {
1820

19-
using ::facebook::react::jsinspector_modern::IInspector;
2021
using ::facebook::react::jsinspector_modern::ILocalConnection;
2122
using ::facebook::react::jsinspector_modern::IRemoteConnection;
2223

@@ -27,7 +28,7 @@ class LocalConnection : public ILocalConnection {
2728
LocalConnection(
2829
std::shared_ptr<hermes::inspector_modern::chrome::CDPHandler> conn,
2930
std::shared_ptr<std::unordered_set<std::string>> inspectedContexts);
30-
~LocalConnection();
31+
~LocalConnection() override;
3132

3233
void sendMessage(std::string message) override;
3334
void disconnect() override;
@@ -40,14 +41,14 @@ class LocalConnection : public ILocalConnection {
4041
LocalConnection::LocalConnection(
4142
std::shared_ptr<hermes::inspector_modern::chrome::CDPHandler> conn,
4243
std::shared_ptr<std::unordered_set<std::string>> inspectedContexts)
43-
: conn_(conn), inspectedContexts_(inspectedContexts) {
44+
: conn_(conn), inspectedContexts_(std::move(inspectedContexts)) {
4445
inspectedContexts_->insert(conn->getTitle());
4546
}
4647

4748
LocalConnection::~LocalConnection() = default;
4849

49-
void LocalConnection::sendMessage(std::string str) {
50-
conn_->handle(std::move(str));
50+
void LocalConnection::sendMessage(std::string message) {
51+
conn_->handle(std::move(message));
5152
}
5253

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

packages/react-native/ReactCommon/hermes/inspector-modern/chrome/HermesRuntimeAgentDelegate.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <hermes/hermes.h>
1515
#include <jsinspector-modern/ReactCdp.h>
1616

17+
#include <utility>
18+
1719
using namespace facebook::hermes;
1820

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

2729
static HermesState unwrapDestructively(ExportedState* wrapper) {
28-
if (!wrapper) {
30+
if (wrapper == nullptr) {
2931
return {};
3032
}
3133
if (auto* typedWrapper = dynamic_cast<HermesStateWrapper*>(wrapper)) {
@@ -58,7 +60,7 @@ class HermesRuntimeAgentDelegate::Impl final : public RuntimeAgentDelegate {
5860
runtimeExecutor(
5961
[&runtime, fn = std::move(fn)](auto&) { fn(runtime); });
6062
},
61-
frontendChannel,
63+
std::move(frontendChannel),
6264
HermesStateWrapper::unwrapDestructively(
6365
previouslyExportedState.get()))) {
6466
if (sessionState.isRuntimeDomainEnabled) {

packages/react-native/ReactCommon/jsinspector-modern/FallbackRuntimeAgentDelegate.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <chrono>
1111
#include <string>
12+
#include <utility>
1213

1314
using namespace std::chrono;
1415
using namespace std::literals::string_view_literals;
@@ -26,7 +27,8 @@ FallbackRuntimeAgentDelegate::FallbackRuntimeAgentDelegate(
2627
FrontendChannel frontendChannel,
2728
const SessionState& sessionState,
2829
std::string engineDescription)
29-
: frontendChannel_(frontendChannel), engineDescription_(engineDescription) {
30+
: frontendChannel_(std::move(frontendChannel)),
31+
engineDescription_(std::move(engineDescription)) {
3032
if (sessionState.isLogDomainEnabled) {
3133
sendFallbackRuntimeWarning();
3234
}

packages/react-native/ReactCommon/jsinspector-modern/HostTarget.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <folly/json.h>
2020

2121
#include <memory>
22+
#include <utility>
2223

2324
namespace facebook::react::jsinspector_modern {
2425

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

183-
HostTargetDelegate::~HostTargetDelegate() {}
184+
HostTargetDelegate::~HostTargetDelegate() = default;
184185

185186
InstanceTarget& HostTarget::registerInstance(InstanceTargetDelegate& delegate) {
186187
assert(!currentInstance_ && "Only one instance allowed");

packages/react-native/ReactCommon/jsinspector-modern/InspectorInterfaces.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@
1010
#include <cassert>
1111
#include <list>
1212
#include <mutex>
13+
#include <utility>
1314

1415
namespace facebook::react::jsinspector_modern {
1516

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

2526
folly::dynamic targetCapabilitiesToDynamic(
2627
const InspectorTargetCapabilities& capabilities) {
@@ -54,8 +55,8 @@ class InspectorImpl : public IInspector {
5455
public:
5556
Page(
5657
int id,
57-
const std::string& description,
58-
const std::string& vm,
58+
std::string description,
59+
std::string vm,
5960
ConnectFunc connectFunc,
6061
InspectorTargetCapabilities capabilities);
6162
operator InspectorPageDescription() const;
@@ -77,13 +78,13 @@ class InspectorImpl : public IInspector {
7778

7879
InspectorImpl::Page::Page(
7980
int id,
80-
const std::string& description,
81-
const std::string& vm,
81+
std::string description,
82+
std::string vm,
8283
ConnectFunc connectFunc,
8384
InspectorTargetCapabilities capabilities)
8485
: id_(id),
85-
description_(description),
86-
vm_(vm),
86+
description_(std::move(description)),
87+
vm_(std::move(vm)),
8788
connectFunc_(std::move(connectFunc)),
8889
capabilities_(capabilities) {}
8990

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

124125
if (pages_.erase(pageId) != 0) {
125-
for (auto& listenerWeak : listeners_) {
126+
for (const auto& listenerWeak : listeners_) {
126127
if (auto listener = listenerWeak.lock()) {
127128
listener->onPageRemoved(pageId);
128129
}

packages/react-native/ReactCommon/jsinspector-modern/InspectorPackagerConnection.cpp

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <glog/logging.h>
1515
#include <cerrno>
1616
#include <chrono>
17+
#include <utility>
1718

1819
using namespace std::literals;
1920

@@ -34,7 +35,10 @@ InspectorPackagerConnection::Impl::create(
3435
// No make_shared because the constructor is private
3536
std::shared_ptr<InspectorPackagerConnection::Impl> impl(
3637
new InspectorPackagerConnection::Impl(
37-
url, deviceName, appName, std::move(delegate)));
38+
std::move(url),
39+
std::move(deviceName),
40+
std::move(appName),
41+
std::move(delegate)));
3842
getInspectorInstance().registerPageStatusListener(impl);
3943
return impl;
4044
}
@@ -50,7 +54,7 @@ InspectorPackagerConnection::Impl::Impl(
5054
delegate_(std::move(delegate)) {}
5155

5256
void InspectorPackagerConnection::Impl::handleProxyMessage(
53-
folly::const_dynamic_view message) {
57+
const folly::const_dynamic_view& message) {
5458
std::string event = message.descend("event").string_or(INVALID);
5559
if (event == "getPages") {
5660
sendToPackager(
@@ -67,7 +71,7 @@ void InspectorPackagerConnection::Impl::handleProxyMessage(
6771
}
6872

6973
void InspectorPackagerConnection::Impl::sendEventToAllConnections(
70-
std::string event) {
74+
const std::string& event) {
7175
for (auto& connection : inspectorSessions_) {
7276
connection.second.localConnection->sendMessage(event);
7377
}
@@ -81,7 +85,7 @@ void InspectorPackagerConnection::Impl::closeAllConnections() {
8185
}
8286

8387
void InspectorPackagerConnection::Impl::handleConnect(
84-
folly::const_dynamic_view payload) {
88+
const folly::const_dynamic_view& payload) {
8589
std::string pageId = payload.descend("pageId").string_or(INVALID);
8690
auto existingConnectionIt = inspectorSessions_.find(pageId);
8791
if (existingConnectionIt != inspectorSessions_.end()) {
@@ -91,7 +95,7 @@ void InspectorPackagerConnection::Impl::handleConnect(
9195
LOG(WARNING) << "Already connected: " << pageId;
9296
return;
9397
}
94-
int pageIdInt;
98+
int pageIdInt = 0;
9599
try {
96100
pageIdInt = std::stoi(pageId);
97101
} catch (...) {
@@ -123,7 +127,7 @@ void InspectorPackagerConnection::Impl::handleConnect(
123127
}
124128

125129
void InspectorPackagerConnection::Impl::handleDisconnect(
126-
folly::const_dynamic_view payload) {
130+
const folly::const_dynamic_view& payload) {
127131
std::string pageId = payload.descend("pageId").string_or(INVALID);
128132
auto inspectorConnection = removeConnectionForPage(pageId);
129133
if (inspectorConnection) {
@@ -132,7 +136,8 @@ void InspectorPackagerConnection::Impl::handleDisconnect(
132136
}
133137

134138
std::unique_ptr<ILocalConnection>
135-
InspectorPackagerConnection::Impl::removeConnectionForPage(std::string pageId) {
139+
InspectorPackagerConnection::Impl::removeConnectionForPage(
140+
const std::string& pageId) {
136141
auto it = inspectorSessions_.find(pageId);
137142
if (it != inspectorSessions_.end()) {
138143
auto connection = std::move(it->second);
@@ -143,7 +148,7 @@ InspectorPackagerConnection::Impl::removeConnectionForPage(std::string pageId) {
143148
}
144149

145150
void InspectorPackagerConnection::Impl::handleWrappedEvent(
146-
folly::const_dynamic_view payload) {
151+
const folly::const_dynamic_view& payload) {
147152
std::string pageId = payload.descend("pageId").string_or(INVALID);
148153
std::string wrappedEvent = payload.descend("wrappedEvent").string_or(INVALID);
149154
auto connectionIt = inspectorSessions_.find(pageId);
@@ -195,7 +200,7 @@ void InspectorPackagerConnection::Impl::didReceiveMessage(
195200
<< e.what();
196201
return;
197202
}
198-
handleProxyMessage(std::move(parsedJSON));
203+
handleProxyMessage(parsedJSON);
199204
}
200205

201206
void InspectorPackagerConnection::Impl::didOpen() {
@@ -277,7 +282,8 @@ void InspectorPackagerConnection::Impl::closeQuietly() {
277282
disposeWebSocket();
278283
}
279284

280-
void InspectorPackagerConnection::Impl::sendToPackager(folly::dynamic message) {
285+
void InspectorPackagerConnection::Impl::sendToPackager(
286+
const folly::dynamic& message) {
281287
if (!webSocket_) {
282288
return;
283289
}
@@ -288,7 +294,7 @@ void InspectorPackagerConnection::Impl::sendToPackager(folly::dynamic message) {
288294
void InspectorPackagerConnection::Impl::scheduleSendToPackager(
289295
folly::dynamic message,
290296
SessionId sourceSessionId,
291-
std::string sourcePageId) {
297+
const std::string& sourcePageId) {
292298
delegate_->scheduleCallback(
293299
[weakSelf = weak_from_this(),
294300
message = std::move(message),
@@ -331,7 +337,7 @@ InspectorPackagerConnection::Impl::RemoteConnection::RemoteConnection(
331337
std::weak_ptr<InspectorPackagerConnection::Impl> owningPackagerConnection,
332338
std::string pageId,
333339
SessionId sessionId)
334-
: owningPackagerConnection_(owningPackagerConnection),
340+
: owningPackagerConnection_(std::move(owningPackagerConnection)),
335341
pageId_(std::move(pageId)),
336342
sessionId_(sessionId) {}
337343

@@ -367,7 +373,11 @@ InspectorPackagerConnection::InspectorPackagerConnection(
367373
std::string deviceName,
368374
std::string appName,
369375
std::unique_ptr<InspectorPackagerConnectionDelegate> delegate)
370-
: impl_(Impl::create(url, deviceName, appName, std::move(delegate))) {}
376+
: impl_(Impl::create(
377+
std::move(url),
378+
std::move(deviceName),
379+
std::move(appName),
380+
std::move(delegate))) {}
371381

372382
bool InspectorPackagerConnection::isConnected() const {
373383
return impl_->isConnected();

packages/react-native/ReactCommon/jsinspector-modern/InspectorPackagerConnectionImpl.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ class InspectorPackagerConnection::Impl
3939
bool isConnected() const;
4040
void connect();
4141
void closeQuietly();
42-
void sendEventToAllConnections(std::string event);
43-
std::unique_ptr<ILocalConnection> removeConnectionForPage(std::string pageId);
42+
void sendEventToAllConnections(const std::string& event);
43+
std::unique_ptr<ILocalConnection> removeConnectionForPage(
44+
const std::string& pageId);
4445

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

5657
private:
5758
struct Session {
@@ -68,15 +69,15 @@ class InspectorPackagerConnection::Impl
6869
Impl(const Impl&) = delete;
6970
Impl& operator=(const Impl&) = delete;
7071

71-
void handleDisconnect(folly::const_dynamic_view payload);
72-
void handleConnect(folly::const_dynamic_view payload);
73-
void handleWrappedEvent(folly::const_dynamic_view wrappedEvent);
74-
void handleProxyMessage(folly::const_dynamic_view message);
72+
void handleDisconnect(const folly::const_dynamic_view& payload);
73+
void handleConnect(const folly::const_dynamic_view& payload);
74+
void handleWrappedEvent(const folly::const_dynamic_view& payload);
75+
void handleProxyMessage(const folly::const_dynamic_view& message);
7576
folly::dynamic pages();
7677
void reconnect();
7778
void closeAllConnections();
7879
void disposeWebSocket();
79-
void sendToPackager(folly::dynamic message);
80+
void sendToPackager(const folly::dynamic& message);
8081

8182
void abort(
8283
std::optional<int> posixCode,

packages/react-native/ReactCommon/jsinspector-modern/InstanceAgent.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

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

13+
#include <utility>
14+
1315
namespace facebook::react::jsinspector_modern {
1416

1517
InstanceAgent::InstanceAgent(

packages/react-native/ReactCommon/jsinspector-modern/InstanceTarget.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
#include <jsinspector-modern/InstanceTarget.h>
1212

13+
#include <utility>
14+
1315
namespace facebook::react::jsinspector_modern {
1416

1517
std::shared_ptr<InstanceTarget> InstanceTarget::create(
@@ -30,10 +32,10 @@ InstanceTarget::InstanceTarget(
3032
(void)delegate_;
3133
}
3234

33-
InstanceTargetDelegate::~InstanceTargetDelegate() {}
35+
InstanceTargetDelegate::~InstanceTargetDelegate() = default;
3436

3537
std::shared_ptr<InstanceAgent> InstanceTarget::createAgent(
36-
FrontendChannel channel,
38+
const FrontendChannel& channel,
3739
SessionState& sessionState) {
3840
auto instanceAgent =
3941
std::make_shared<InstanceAgent>(channel, *this, sessionState);
@@ -61,7 +63,7 @@ RuntimeTarget& InstanceTarget::registerRuntime(
6163
.name = "main",
6264
.uniqueId = std::nullopt},
6365
delegate,
64-
jsExecutor,
66+
std::move(jsExecutor),
6567
makeVoidExecutor(executorFromThis()));
6668

6769
agents_.forEach([currentRuntime = &*currentRuntime_](InstanceAgent& agent) {

0 commit comments

Comments
 (0)