Skip to content

Commit 4310158

Browse files
Apply clang-tidy setting: react/nativemodule
Differential Revision: D78634926
1 parent 4273904 commit 4310158

File tree

20 files changed

+117
-86
lines changed

20 files changed

+117
-86
lines changed

packages/react-native/ReactCommon/react/bridging/tests/ClassTest.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,40 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
#include <utility>
9+
810
#include "BridgingTest.h"
911

1012
namespace facebook::react {
1113

1214
using namespace std::literals;
1315

1416
struct TestClass {
15-
TestClass(std::shared_ptr<CallInvoker> invoker) : invoker_(invoker) {}
17+
explicit TestClass(std::shared_ptr<CallInvoker> invoker)
18+
: invoker_(std::move(invoker)) {}
1619

17-
double add(jsi::Runtime&, int a, float b) {
20+
double add(jsi::Runtime& /*unused*/, int a, float b) {
1821
return a + b;
1922
}
2023

21-
jsi::Object getObject(jsi::Runtime&, jsi::Object obj) {
24+
jsi::Object getObject(jsi::Runtime& /*unused*/, jsi::Object obj) {
2225
return obj;
2326
}
2427

2528
AsyncPromise<std::string> getPromise(jsi::Runtime& rt, std::string result) {
2629
auto promise = AsyncPromise<std::string>(rt, invoker_);
27-
promise.resolve(result);
30+
promise.resolve(std::move(result));
2831
return promise;
2932
}
3033

31-
std::string
32-
callFunc(jsi::Runtime&, SyncCallback<std::string(int)> func, int num) {
34+
std::string callFunc(
35+
jsi::Runtime& /*unused*/,
36+
SyncCallback<std::string(int)> func,
37+
int num) {
3338
return func(num);
3439
}
3540

36-
void callAsync(jsi::Runtime&, AsyncCallback<> callback) {
41+
void callAsync(jsi::Runtime& /*unused*/, const AsyncCallback<>& callback) {
3742
callback();
3843
}
3944

@@ -69,7 +74,8 @@ TEST_F(BridgingTest, callFromJsTest) {
6974
then.callWithThis(
7075
rt,
7176
promise,
72-
bridging::toJs(rt, [&](std::string res) { result = res; }, invoker));
77+
bridging::toJs(
78+
rt, [&](std::string res) { result = std::move(res); }, invoker));
7379

7480
flushQueue();
7581
EXPECT_EQ("hi"s, result);

packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/CxxTurboModuleUtils.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#include "CxxTurboModuleUtils.h"
99

10+
#include <utility>
11+
1012
namespace facebook::react {
1113

1214
std::unordered_map<
@@ -23,10 +25,10 @@ globalExportedCxxTurboModuleMap() {
2325
}
2426

2527
void registerCxxModuleToGlobalModuleMap(
26-
std::string name,
28+
const std::string& name,
2729
std::function<std::shared_ptr<TurboModule>(
2830
std::shared_ptr<CallInvoker> jsInvoker)> moduleProviderFunc) {
29-
globalExportedCxxTurboModuleMap()[name] = moduleProviderFunc;
31+
globalExportedCxxTurboModuleMap()[name] = std::move(moduleProviderFunc);
3032
}
3133

3234
} // namespace facebook::react

packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/CxxTurboModuleUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ globalExportedCxxTurboModuleMap();
2828
* for example in a `+ load`, your AppDelegate's start, or from Java init.
2929
*/
3030
void registerCxxModuleToGlobalModuleMap(
31-
std::string name,
31+
const std::string& name,
3232
std::function<std::shared_ptr<TurboModule>(
3333
std::shared_ptr<CallInvoker> jsInvoker)> moduleProviderFunc);
3434

packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboCxxModule.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ namespace facebook::react {
2020

2121
namespace {
2222
CxxModule::Callback makeTurboCxxModuleCallback(
23-
jsi::Runtime& runtime,
2423
std::weak_ptr<CallbackWrapper> weakWrapper) {
25-
return [weakWrapper,
26-
wrapperWasCalled = false](std::vector<folly::dynamic> args) mutable {
24+
return [weakWrapper, wrapperWasCalled = false](
25+
const std::vector<folly::dynamic>& args) mutable {
2726
if (wrapperWasCalled) {
2827
LOG(FATAL) << "callback arg cannot be called more than once";
2928
}
@@ -77,9 +76,9 @@ jsi::Value TurboCxxModule::create(
7776
0,
7877
[this](
7978
jsi::Runtime& rt,
80-
const jsi::Value& thisVal,
81-
const jsi::Value* args,
82-
size_t count) {
79+
const jsi::Value& /*thisVal*/,
80+
const jsi::Value* /*args*/,
81+
size_t /*count*/) {
8382
jsi::Object result(rt);
8483
auto constants = cxxModule_->getConstants();
8584
for (auto& pair : constants) {
@@ -97,7 +96,7 @@ jsi::Value TurboCxxModule::create(
9796
0,
9897
[this, propNameUtf8](
9998
jsi::Runtime& rt,
100-
const jsi::Value& thisVal,
99+
const jsi::Value& /*thisVal*/,
101100
const jsi::Value* args,
102101
size_t count) {
103102
return invokeMethod(rt, propNameUtf8, args, count);
@@ -114,8 +113,8 @@ std::vector<jsi::PropNameID> TurboCxxModule::getPropertyNames(
114113
std::vector<jsi::PropNameID> result;
115114
result.reserve(cxxMethods_.size() + 1);
116115
result.push_back(jsi::PropNameID::forUtf8(runtime, "getConstants"));
117-
for (auto it = cxxMethods_.begin(); it != cxxMethods_.end(); it++) {
118-
result.push_back(jsi::PropNameID::forUtf8(runtime, it->name));
116+
for (auto& cxxMethod : cxxMethods_) {
117+
result.push_back(jsi::PropNameID::forUtf8(runtime, cxxMethod.name));
119118
}
120119
return result;
121120
}
@@ -164,7 +163,7 @@ jsi::Value TurboCxxModule::invokeMethod(
164163
args[count - 1].getObject(runtime).getFunction(runtime),
165164
runtime,
166165
jsInvoker_);
167-
first = makeTurboCxxModuleCallback(runtime, wrapper);
166+
first = makeTurboCxxModuleCallback(wrapper);
168167
} else if (method.callbacks == 2) {
169168
auto wrapper1 = CallbackWrapper::createWeak(
170169
args[count - 2].getObject(runtime).getFunction(runtime),
@@ -174,8 +173,8 @@ jsi::Value TurboCxxModule::invokeMethod(
174173
args[count - 1].getObject(runtime).getFunction(runtime),
175174
runtime,
176175
jsInvoker_);
177-
first = makeTurboCxxModuleCallback(runtime, wrapper1);
178-
second = makeTurboCxxModuleCallback(runtime, wrapper2);
176+
first = makeTurboCxxModuleCallback(wrapper1);
177+
second = makeTurboCxxModuleCallback(wrapper2);
179178
}
180179

181180
auto innerArgs = folly::dynamic::array();
@@ -194,9 +193,9 @@ jsi::Value TurboCxxModule::invokeMethod(
194193
auto rejectWrapper = CallbackWrapper::createWeak(
195194
promise->reject_.getFunction(rt), rt, jsInvoker_);
196195
CxxModule::Callback resolve =
197-
makeTurboCxxModuleCallback(rt, resolveWrapper);
196+
makeTurboCxxModuleCallback(resolveWrapper);
198197
CxxModule::Callback reject =
199-
makeTurboCxxModuleCallback(rt, rejectWrapper);
198+
makeTurboCxxModuleCallback(rejectWrapper);
200199

201200
auto innerArgs = folly::dynamic::array();
202201
for (size_t i = 0; i < count; i++) {

packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModule.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace facebook::react {
1313
TurboModuleMethodValueKind getTurboModuleMethodValueKind(
1414
jsi::Runtime& rt,
1515
const jsi::Value* value) {
16-
if (!value || value->isUndefined() || value->isNull()) {
16+
if ((value == nullptr) || value->isUndefined() || value->isNull()) {
1717
return VoidKind;
1818
} else if (value->isBool()) {
1919
return BooleanKind;
@@ -41,7 +41,7 @@ TurboModule::TurboModule(
4141

4242
void TurboModule::emitDeviceEvent(
4343
const std::string& eventName,
44-
ArgFactory argFactory) {
44+
const ArgFactory& argFactory) {
4545
jsInvoker_->invokeAsync([eventName, argFactory](jsi::Runtime& rt) {
4646
jsi::Value emitter = rt.global().getProperty(rt, "__rctDeviceEventEmitter");
4747
if (!emitter.isUndefined()) {

packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class JSI_EXPORT TurboModule : public jsi::HostObject {
111111
*/
112112
void emitDeviceEvent(
113113
const std::string& eventName,
114-
ArgFactory argFactory = nullptr);
114+
const ArgFactory& argFactory = nullptr);
115115

116116
// Backwards compatibility version
117117
void emitDeviceEvent(

packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleBinding.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class BridgelessNativeModuleProxy : public jsi::HostObject {
5454
*/
5555
std::string moduleName = name.utf8(runtime);
5656
if (moduleName == "__esModule") {
57-
return jsi::Value(false);
57+
return {false};
5858
}
5959

6060
auto turboModule = turboBinding_.getModule(runtime, moduleName);

packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleUtils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ jsi::Value createPromiseAsJSIValue(
3535
2,
3636
[func = std::move(func)](
3737
jsi::Runtime& rt2,
38-
const jsi::Value& thisVal,
38+
const jsi::Value& /*thisVal*/,
3939
const jsi::Value* args,
40-
size_t count) {
40+
size_t /*count*/) {
4141
jsi::Function resolve = args[0].getObject(rt2).getFunction(rt2);
4242
jsi::Function reject = args[1].getObject(rt2).getFunction(rt2);
4343
auto wrapper = std::make_shared<Promise>(

packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct Promise : public LongLivedObject {
1919
Promise(jsi::Runtime& rt, jsi::Function resolve, jsi::Function reject);
2020

2121
void resolve(const jsi::Value& result);
22-
void reject(const std::string& error);
22+
void reject(const std::string& message);
2323

2424
jsi::Function resolve_;
2525
jsi::Function reject_;

packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaInteropTurboModule.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,15 @@ std::string getType(jsi::Runtime& rt, const jsi::Value& v) {
3737

3838
JavaInteropTurboModule::JavaInteropTurboModule(
3939
const JavaTurboModule::InitParams& params,
40-
std::vector<MethodDescriptor> methodDescriptors)
40+
const std::vector<MethodDescriptor>& methodDescriptors)
4141
: JavaTurboModule(params),
4242
methodDescriptors_(methodDescriptors),
4343
methodIDs_(methodDescriptors.size()),
4444
constantsCache_(jsi::Value::undefined()) {
4545
for (const auto& methodDescriptor : methodDescriptors) {
4646
methodMap_[methodDescriptor.methodName] = MethodMetadata{
47-
static_cast<size_t>(methodDescriptor.jsArgCount), nullptr};
47+
.argCount = static_cast<size_t>(methodDescriptor.jsArgCount),
48+
.invoker = nullptr};
4849
}
4950
}
5051

@@ -60,7 +61,7 @@ jsi::Value JavaInteropTurboModule::create(
6061
static_cast<unsigned int>(methodDescriptors_[i].jsArgCount),
6162
[this, i](
6263
jsi::Runtime& rt,
63-
const jsi::Value& thisVal,
64+
const jsi::Value& /*thisVal*/,
6465
const jsi::Value* args,
6566
size_t count) mutable {
6667
if (!this->constantsCache_.isUndefined()) {
@@ -103,7 +104,7 @@ jsi::Value JavaInteropTurboModule::create(
103104
static_cast<unsigned int>(methodDescriptors_[i].jsArgCount),
104105
[this, i](
105106
jsi::Runtime& rt,
106-
const jsi::Value& thisVal,
107+
const jsi::Value& /*thisVal*/,
107108
const jsi::Value* args,
108109
size_t count) {
109110
return this->invokeJavaMethod(

0 commit comments

Comments
 (0)