Apply clang-tidy setting: cxxreact (#52730)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/52730

Changelog: [Internal]

Reviewed By: cipolleschi

Differential Revision: D78459248

fbshipit-source-id: 1dcd15c5d0cf56f323cc15248c684c9940abdd19
This commit is contained in:
Christoph Purrer
2025-07-23 09:31:44 -07:00
committed by Facebook GitHub Bot
parent 0f25a354ba
commit 39ded5eb2a
16 changed files with 48 additions and 41 deletions
@@ -94,6 +94,7 @@ std::vector<MethodDescriptor> CxxNativeModule::getMethods() {
lazyInit();
std::vector<MethodDescriptor> descs;
descs.reserve(methods_.size());
for (auto& method : methods_) {
descs.emplace_back(method.name, method.getType());
}
@@ -198,7 +199,7 @@ void CxxNativeModule::invoke(
TraceSection s(
"CxxMethodCallDispatch", "module", moduleName, "method", method.name);
try {
method.func(std::move(params), first, second);
method.func(params, first, second);
} catch (const facebook::xplat::JsArgumentException& ex) {
throw;
} catch (std::exception& e) {
@@ -41,7 +41,7 @@ Instance::~Instance() {
}
void Instance::unregisterFromInspector() {
if (inspectorTarget_) {
if (inspectorTarget_ != nullptr) {
assert(runtimeInspectorTarget_);
inspectorTarget_->unregisterRuntime(*runtimeInspectorTarget_);
assert(parentInspectorTarget_);
@@ -132,24 +132,28 @@ void Instance::initializeBridge(
void Instance::loadBundle(
std::unique_ptr<RAMBundleRegistry> bundleRegistry,
std::unique_ptr<const JSBigString> string,
std::unique_ptr<const JSBigString> startupScript,
std::string sourceURL) {
callback_->incrementPendingJSCalls();
TraceSection s("Instance::loadBundle", "sourceURL", sourceURL);
nativeToJsBridge_->loadBundle(
std::move(bundleRegistry), std::move(string), std::move(sourceURL));
std::move(bundleRegistry),
std::move(startupScript),
std::move(sourceURL));
}
void Instance::loadBundleSync(
std::unique_ptr<RAMBundleRegistry> bundleRegistry,
std::unique_ptr<const JSBigString> string,
std::unique_ptr<const JSBigString> startupScript,
std::string sourceURL) {
std::unique_lock<std::mutex> lock(m_syncMutex);
m_syncCV.wait(lock, [this] { return m_syncReady; });
TraceSection s("Instance::loadBundleSync", "sourceURL", sourceURL);
nativeToJsBridge_->loadBundleSync(
std::move(bundleRegistry), std::move(string), std::move(sourceURL));
std::move(bundleRegistry),
std::move(startupScript),
std::move(sourceURL));
}
void Instance::setSourceURL(std::string sourceURL) {
@@ -277,7 +281,7 @@ std::shared_ptr<CallInvoker> Instance::getJSCallInvoker() {
RuntimeExecutor Instance::getRuntimeExecutor() {
// HACK: RuntimeExecutor is not compatible with non-JSIExecutor, we return
// a null callback, which the caller should handle.
if (!getJavaScriptContext()) {
if (getJavaScriptContext() == nullptr) {
return nullptr;
}
@@ -288,8 +292,8 @@ RuntimeExecutor Instance::getRuntimeExecutor() {
strongNativeToJsBridge->runOnExecutorQueue(
[callback = std::move(callback)](JSExecutor* executor) {
// Assumes the underlying executor is a JSIExecutor
jsi::Runtime* runtime =
(jsi::Runtime*)executor->getJavaScriptContext();
auto* runtime =
static_cast<jsi::Runtime*>(executor->getJavaScriptContext());
try {
react_native_assert(runtime != nullptr);
callback(*runtime);
@@ -315,7 +319,7 @@ void Instance::JSCallInvoker::setNativeToJsBridgeAndFlushCalls(
m_shouldBuffer = false;
m_nativeToJsBridge = nativeToJsBridge;
while (m_workBuffer.size() > 0) {
while (!m_workBuffer.empty()) {
scheduleAsync(std::move(m_workBuffer.front()));
m_workBuffer.pop_front();
}
@@ -129,7 +129,7 @@ class RN_EXPORT Instance : private jsinspector_modern::InstanceTargetDelegate {
* NativeMethodCallInvoker that schedules work on the respective thread.
*/
std::shared_ptr<NativeMethodCallInvoker> getDecoratedNativeMethodCallInvoker(
std::shared_ptr<NativeMethodCallInvoker> nativeInvoker);
std::shared_ptr<NativeMethodCallInvoker> nativeMethodCallInvoker);
/**
* RuntimeExecutor is used by Fabric to access the jsi::Runtime.
@@ -49,7 +49,7 @@ JSBigFileString::JSBigFileString(int fd, size_t size, off_t offset /*= 0*/)
}
JSBigFileString::~JSBigFileString() {
if (m_data) {
if (m_data != nullptr) {
munmap((void*)m_data, m_size);
}
folly::fileops::close(m_fd);
@@ -59,7 +59,7 @@ const char* JSBigFileString::c_str() const {
if (m_size == 0) {
return "";
}
if (!m_data) {
if (m_data == nullptr) {
m_data = (const char*)mmap(
nullptr, m_size, PROT_READ, MAP_PRIVATE, m_fd, m_mapOff);
CHECK(m_data != MAP_FAILED)
@@ -11,6 +11,7 @@
#include <glog/logging.h>
#include <fstream>
#include <memory>
#include <sstream>
#include <folly/lang/Bits.h>
@@ -70,8 +71,7 @@ void JSIndexedRAMBundle::init() {
readBundle(reinterpret_cast<char*>(m_table.data.get()), m_table.byteLength());
// read the startup code
m_startupCode = std::unique_ptr<JSBigBufferString>(
new JSBigBufferString{startupCodeSize - 1});
m_startupCode = std::make_unique<JSBigBufferString>(startupCodeSize - 1);
readBundle(m_startupCode->data(), startupCodeSize - 1);
}
@@ -95,7 +95,7 @@ std::string JSIndexedRAMBundle::getModuleCode(const uint32_t id) const {
// entries without associated code have offset = 0 and length = 0
const uint32_t length =
moduleData ? folly::Endian::little(moduleData->length) : 0;
moduleData != nullptr ? folly::Endian::little(moduleData->length) : 0;
if (length == 0) {
throw std::ios_base::failure(
"Error loading module" + std::to_string(id) + "from RAM Bundle");
@@ -112,7 +112,7 @@ std::string JSIndexedRAMBundle::getModuleCode(const uint32_t id) const {
void JSIndexedRAMBundle::readBundle(char* buffer, const std::streamsize bytes)
const {
if (!m_bundle->read(buffer, bytes)) {
if (m_bundle->rdstate() & std::ios::eofbit) {
if ((m_bundle->rdstate() & std::ios::eofbit) != 0) {
throw std::ios_base::failure("Unexpected end of RAM Bundle file");
}
throw std::ios_base::failure(
@@ -29,7 +29,7 @@ class RN_EXPORT JSIndexedRAMBundle : public JSModulesUnbundle {
buildFactory();
// Throws std::runtime_error on failure.
JSIndexedRAMBundle(const char* sourceURL);
explicit JSIndexedRAMBundle(const char* sourcePath);
JSIndexedRAMBundle(std::unique_ptr<const JSBigString> script);
// Throws std::runtime_error on failure.
@@ -68,7 +68,7 @@ class RN_EXPORT JSIndexedRAMBundle : public JSModulesUnbundle {
mutable std::unique_ptr<std::istream> m_bundle;
ModuleTable m_table;
size_t m_baseOffset;
size_t m_baseOffset{};
std::unique_ptr<JSBigBufferString> m_startupCode;
};
@@ -31,7 +31,7 @@ struct MethodCall {
};
/// \throws std::invalid_argument
std::vector<MethodCall> parseMethodCalls(folly::dynamic&& calls);
std::vector<MethodCall> parseMethodCalls(folly::dynamic&& jsonData);
} // namespace facebook::react
@@ -11,6 +11,7 @@
#include <glog/logging.h>
#include <reactperflogger/BridgeNativeModulePerfLogger.h>
#include <utility>
#include "NativeModule.h"
#include "TraceSection.h"
@@ -37,7 +38,8 @@ std::string normalizeName(std::string name) {
ModuleRegistry::ModuleRegistry(
std::vector<std::unique_ptr<NativeModule>> modules,
ModuleNotFoundCallback callback)
: modules_{std::move(modules)}, moduleNotFoundCallback_{callback} {}
: modules_{std::move(modules)},
moduleNotFoundCallback_{std::move(callback)} {}
void ModuleRegistry::updateModuleNamesFromIndex(size_t index) {
for (; index < modules_.size(); index++) {
@@ -58,12 +58,12 @@ class RN_EXPORT ModuleRegistry {
MethodCallResult callSerializableNativeHook(
unsigned int moduleId,
unsigned int methodId,
folly::dynamic&& args);
folly::dynamic&& params);
std::string getModuleName(unsigned int moduleId);
std::string getModuleSyncMethodName(
unsigned int moduleId,
unsigned int methodName);
unsigned int methodId);
private:
// This is always populated
@@ -71,7 +71,7 @@ class RN_EXPORT ModuleRegistry {
// This is used to extend the population of modulesByName_ if registerModules
// is called after moduleNames
void updateModuleNamesFromIndex(size_t size);
void updateModuleNamesFromIndex(size_t index);
// This is only populated if moduleNames() is called. Values are indices into
// modules_.
@@ -26,6 +26,7 @@
#include "TraceSection.h"
#include <memory>
#include <utility>
#ifdef WITH_FBSYSTRACE
#include <fbsystrace.h>
@@ -41,7 +42,7 @@ class JsToNativeBridge : public react::ExecutorDelegate {
JsToNativeBridge(
std::shared_ptr<ModuleRegistry> registry,
std::shared_ptr<InstanceCallback> callback)
: m_registry(registry), m_callback(callback) {}
: m_registry(std::move(registry)), m_callback(std::move(callback)) {}
std::shared_ptr<ModuleRegistry> getModuleRegistry() override {
return m_registry;
@@ -59,12 +59,12 @@ class NativeToJsBridge {
void callFunction(
std::string&& module,
std::string&& method,
folly::dynamic&& args);
folly::dynamic&& arguments);
/**
* Invokes a callback with the cbID, and optional additional arguments in JS.
*/
void invokeCallback(double callbackId, folly::dynamic&& args);
void invokeCallback(double callbackId, folly::dynamic&& arguments);
/**
* Sets global variables in the JS Context.
@@ -78,11 +78,11 @@ class NativeToJsBridge {
*/
void loadBundle(
std::unique_ptr<RAMBundleRegistry> bundleRegistry,
std::unique_ptr<const JSBigString> startupCode,
std::unique_ptr<const JSBigString> startupScript,
std::string sourceURL);
void loadBundleSync(
std::unique_ptr<RAMBundleRegistry> bundleRegistry,
std::unique_ptr<const JSBigString> startupCode,
std::unique_ptr<const JSBigString> startupScript,
std::string sourceURL);
void registerBundle(uint32_t bundleId, const std::string& bundlePath);
@@ -107,7 +107,7 @@ class NativeToJsBridge {
* NativeModule thread(s).
*/
std::shared_ptr<NativeMethodCallInvoker> getDecoratedNativeMethodCallInvoker(
std::shared_ptr<NativeMethodCallInvoker> nativeInvoker) const;
std::shared_ptr<NativeMethodCallInvoker> nativeMethodCallInvoker) const;
jsinspector_modern::RuntimeTargetDelegate& getInspectorTargetDelegate();
@@ -76,7 +76,7 @@ class RN_EXPORT StartupLogger {
public:
static StartupLogger& getInstance();
void logStartupEvent(const ReactMarkerId markerName, double markerTime);
void logStartupEvent(const ReactMarkerId markerId, double markerTime);
void reset();
double getAppStartupStartTime();
double getInitReactRuntimeStartTime();
@@ -14,7 +14,7 @@
using namespace facebook::react;
namespace {
int tempFileFromString(std::string contents) {
int tempFileFromString(const std::string& contents) {
const char* tmpDir = getenv("TMPDIR");
if (tmpDir == nullptr) {
tmpDir = "/tmp";
@@ -106,8 +106,7 @@ TEST(parseMethodCalls, NullReturn) {
}
TEST(parseMethodCalls, MapReturn) {
auto jsText =
"[[0],[0],[[{\"foo\": \"hello\", \"bar\": 4.0, \"baz\": true}]]]";
auto jsText = R"([[0],[0],[[{"foo": "hello", "bar": 4.0, "baz": true}]]])";
auto returnedCalls = parseMethodCalls(folly::parseJson(jsText));
EXPECT_EQ(1, returnedCalls.size());
auto returnedCall = returnedCalls[0];
@@ -9,7 +9,7 @@
#include "JSRuntimeFactory.h"
void js_runtime_factory_destroy(JSRuntimeFactoryRef factory) {
if (factory) {
if (factory != nullptr) {
delete static_cast<facebook::react::JSRuntimeFactory*>(factory);
}
}
@@ -21,13 +21,13 @@ extern "C" {
#endif // __cplusplus
void set_react_native_logfunc(reactnativelogfunctype newlogfunc);
void react_native_log_info(const char* text);
void react_native_log_warn(const char* text);
void react_native_log_error(const char* text);
void react_native_log_fatal(const char* text);
void react_native_log_info(const char* message);
void react_native_log_warn(const char* message);
void react_native_log_error(const char* message);
void react_native_log_fatal(const char* message);
void _react_native_log(ReactNativeLogLevel level, const char* text);
void _react_native_log_default(ReactNativeLogLevel level, const char* text);
void _react_native_log(ReactNativeLogLevel level, const char* message);
void _react_native_log_default(ReactNativeLogLevel level, const char* message);
#ifdef __cplusplus
}
#endif // __cpusplus