diff --git a/packages/react-native/ReactCommon/cxxreact/CxxNativeModule.cpp b/packages/react-native/ReactCommon/cxxreact/CxxNativeModule.cpp index 3ca3d4bbdf9..d1450570488 100644 --- a/packages/react-native/ReactCommon/cxxreact/CxxNativeModule.cpp +++ b/packages/react-native/ReactCommon/cxxreact/CxxNativeModule.cpp @@ -94,6 +94,7 @@ std::vector CxxNativeModule::getMethods() { lazyInit(); std::vector 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) { diff --git a/packages/react-native/ReactCommon/cxxreact/Instance.cpp b/packages/react-native/ReactCommon/cxxreact/Instance.cpp index 3fda838887a..4e21dd70565 100644 --- a/packages/react-native/ReactCommon/cxxreact/Instance.cpp +++ b/packages/react-native/ReactCommon/cxxreact/Instance.cpp @@ -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 bundleRegistry, - std::unique_ptr string, + std::unique_ptr 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 bundleRegistry, - std::unique_ptr string, + std::unique_ptr startupScript, std::string sourceURL) { std::unique_lock 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 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(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(); } diff --git a/packages/react-native/ReactCommon/cxxreact/Instance.h b/packages/react-native/ReactCommon/cxxreact/Instance.h index 9fe147c495e..145c2b63767 100644 --- a/packages/react-native/ReactCommon/cxxreact/Instance.h +++ b/packages/react-native/ReactCommon/cxxreact/Instance.h @@ -129,7 +129,7 @@ class RN_EXPORT Instance : private jsinspector_modern::InstanceTargetDelegate { * NativeMethodCallInvoker that schedules work on the respective thread. */ std::shared_ptr getDecoratedNativeMethodCallInvoker( - std::shared_ptr nativeInvoker); + std::shared_ptr nativeMethodCallInvoker); /** * RuntimeExecutor is used by Fabric to access the jsi::Runtime. diff --git a/packages/react-native/ReactCommon/cxxreact/JSBigString.cpp b/packages/react-native/ReactCommon/cxxreact/JSBigString.cpp index 7883c1e7e2e..ea4116d0fdf 100644 --- a/packages/react-native/ReactCommon/cxxreact/JSBigString.cpp +++ b/packages/react-native/ReactCommon/cxxreact/JSBigString.cpp @@ -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) diff --git a/packages/react-native/ReactCommon/cxxreact/JSIndexedRAMBundle.cpp b/packages/react-native/ReactCommon/cxxreact/JSIndexedRAMBundle.cpp index 7b89fae0511..02b69c39fd5 100644 --- a/packages/react-native/ReactCommon/cxxreact/JSIndexedRAMBundle.cpp +++ b/packages/react-native/ReactCommon/cxxreact/JSIndexedRAMBundle.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -70,8 +71,7 @@ void JSIndexedRAMBundle::init() { readBundle(reinterpret_cast(m_table.data.get()), m_table.byteLength()); // read the startup code - m_startupCode = std::unique_ptr( - new JSBigBufferString{startupCodeSize - 1}); + m_startupCode = std::make_unique(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( diff --git a/packages/react-native/ReactCommon/cxxreact/JSIndexedRAMBundle.h b/packages/react-native/ReactCommon/cxxreact/JSIndexedRAMBundle.h index 9a377b50d01..0bcb352c19c 100644 --- a/packages/react-native/ReactCommon/cxxreact/JSIndexedRAMBundle.h +++ b/packages/react-native/ReactCommon/cxxreact/JSIndexedRAMBundle.h @@ -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 script); // Throws std::runtime_error on failure. @@ -68,7 +68,7 @@ class RN_EXPORT JSIndexedRAMBundle : public JSModulesUnbundle { mutable std::unique_ptr m_bundle; ModuleTable m_table; - size_t m_baseOffset; + size_t m_baseOffset{}; std::unique_ptr m_startupCode; }; diff --git a/packages/react-native/ReactCommon/cxxreact/MethodCall.h b/packages/react-native/ReactCommon/cxxreact/MethodCall.h index f774463a069..b12fdde24c3 100644 --- a/packages/react-native/ReactCommon/cxxreact/MethodCall.h +++ b/packages/react-native/ReactCommon/cxxreact/MethodCall.h @@ -31,7 +31,7 @@ struct MethodCall { }; /// \throws std::invalid_argument -std::vector parseMethodCalls(folly::dynamic&& calls); +std::vector parseMethodCalls(folly::dynamic&& jsonData); } // namespace facebook::react diff --git a/packages/react-native/ReactCommon/cxxreact/ModuleRegistry.cpp b/packages/react-native/ReactCommon/cxxreact/ModuleRegistry.cpp index 51a884321f7..15db7bad3cb 100644 --- a/packages/react-native/ReactCommon/cxxreact/ModuleRegistry.cpp +++ b/packages/react-native/ReactCommon/cxxreact/ModuleRegistry.cpp @@ -11,6 +11,7 @@ #include #include +#include #include "NativeModule.h" #include "TraceSection.h" @@ -37,7 +38,8 @@ std::string normalizeName(std::string name) { ModuleRegistry::ModuleRegistry( std::vector> 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++) { diff --git a/packages/react-native/ReactCommon/cxxreact/ModuleRegistry.h b/packages/react-native/ReactCommon/cxxreact/ModuleRegistry.h index bed262bc82e..e5146000b0d 100644 --- a/packages/react-native/ReactCommon/cxxreact/ModuleRegistry.h +++ b/packages/react-native/ReactCommon/cxxreact/ModuleRegistry.h @@ -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_. diff --git a/packages/react-native/ReactCommon/cxxreact/NativeToJsBridge.cpp b/packages/react-native/ReactCommon/cxxreact/NativeToJsBridge.cpp index 8afed017083..64539ee9274 100644 --- a/packages/react-native/ReactCommon/cxxreact/NativeToJsBridge.cpp +++ b/packages/react-native/ReactCommon/cxxreact/NativeToJsBridge.cpp @@ -26,6 +26,7 @@ #include "TraceSection.h" #include +#include #ifdef WITH_FBSYSTRACE #include @@ -41,7 +42,7 @@ class JsToNativeBridge : public react::ExecutorDelegate { JsToNativeBridge( std::shared_ptr registry, std::shared_ptr callback) - : m_registry(registry), m_callback(callback) {} + : m_registry(std::move(registry)), m_callback(std::move(callback)) {} std::shared_ptr getModuleRegistry() override { return m_registry; diff --git a/packages/react-native/ReactCommon/cxxreact/NativeToJsBridge.h b/packages/react-native/ReactCommon/cxxreact/NativeToJsBridge.h index f7b48ab61da..1e1de9bb56c 100644 --- a/packages/react-native/ReactCommon/cxxreact/NativeToJsBridge.h +++ b/packages/react-native/ReactCommon/cxxreact/NativeToJsBridge.h @@ -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 bundleRegistry, - std::unique_ptr startupCode, + std::unique_ptr startupScript, std::string sourceURL); void loadBundleSync( std::unique_ptr bundleRegistry, - std::unique_ptr startupCode, + std::unique_ptr 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 getDecoratedNativeMethodCallInvoker( - std::shared_ptr nativeInvoker) const; + std::shared_ptr nativeMethodCallInvoker) const; jsinspector_modern::RuntimeTargetDelegate& getInspectorTargetDelegate(); diff --git a/packages/react-native/ReactCommon/cxxreact/ReactMarker.h b/packages/react-native/ReactCommon/cxxreact/ReactMarker.h index c6729dd54bf..8b4a95234dc 100644 --- a/packages/react-native/ReactCommon/cxxreact/ReactMarker.h +++ b/packages/react-native/ReactCommon/cxxreact/ReactMarker.h @@ -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(); diff --git a/packages/react-native/ReactCommon/cxxreact/tests/jsbigstring.cpp b/packages/react-native/ReactCommon/cxxreact/tests/jsbigstring.cpp index 02890b11190..ac412042135 100644 --- a/packages/react-native/ReactCommon/cxxreact/tests/jsbigstring.cpp +++ b/packages/react-native/ReactCommon/cxxreact/tests/jsbigstring.cpp @@ -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"; diff --git a/packages/react-native/ReactCommon/cxxreact/tests/methodcall.cpp b/packages/react-native/ReactCommon/cxxreact/tests/methodcall.cpp index f124a2430c7..e418b384bce 100644 --- a/packages/react-native/ReactCommon/cxxreact/tests/methodcall.cpp +++ b/packages/react-native/ReactCommon/cxxreact/tests/methodcall.cpp @@ -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]; diff --git a/packages/react-native/ReactCommon/jsitooling/react/runtime/JSRuntimeFactoryCAPI.cpp b/packages/react-native/ReactCommon/jsitooling/react/runtime/JSRuntimeFactoryCAPI.cpp index 7f7d2e6d320..f362ac78d9f 100644 --- a/packages/react-native/ReactCommon/jsitooling/react/runtime/JSRuntimeFactoryCAPI.cpp +++ b/packages/react-native/ReactCommon/jsitooling/react/runtime/JSRuntimeFactoryCAPI.cpp @@ -9,7 +9,7 @@ #include "JSRuntimeFactory.h" void js_runtime_factory_destroy(JSRuntimeFactoryRef factory) { - if (factory) { + if (factory != nullptr) { delete static_cast(factory); } } diff --git a/packages/react-native/ReactCommon/logger/react_native_log.h b/packages/react-native/ReactCommon/logger/react_native_log.h index a05b4c6e6a3..3d26ea6b77f 100644 --- a/packages/react-native/ReactCommon/logger/react_native_log.h +++ b/packages/react-native/ReactCommon/logger/react_native_log.h @@ -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