diff --git a/packages/react-native-nitro-modules/android/src/main/cpp/platform/NitroLogger.cpp b/packages/react-native-nitro-modules/android/src/main/cpp/platform/NitroLogger.cpp index a87d5f8c3..1f47ad17c 100644 --- a/packages/react-native-nitro-modules/android/src/main/cpp/platform/NitroLogger.cpp +++ b/packages/react-native-nitro-modules/android/src/main/cpp/platform/NitroLogger.cpp @@ -27,11 +27,9 @@ int levelToAndroidLevel(LogLevel level) { } void Logger::nativeLog(LogLevel level, const char* tag, const std::string& message) { -#ifdef NITRO_DEBUG int logLevel = levelToAndroidLevel(level); std::string combinedTag = "Nitro." + std::string(tag); __android_log_print(logLevel, combinedTag.c_str(), "%s", message.c_str()); -#endif } } // namespace margelo::nitro diff --git a/packages/react-native-nitro-modules/android/src/main/cpp/registry/DefaultConstructableObject.hpp b/packages/react-native-nitro-modules/android/src/main/cpp/registry/DefaultConstructableObject.hpp index 959bd8148..4f93698fa 100644 --- a/packages/react-native-nitro-modules/android/src/main/cpp/registry/DefaultConstructableObject.hpp +++ b/packages/react-native-nitro-modules/android/src/main/cpp/registry/DefaultConstructableObject.hpp @@ -57,11 +57,9 @@ class DefaultConstructableObject { jni::local_ref create() const { // Calls the class's default constructor auto instance = _javaClass->newObject(_defaultConstructor); -#ifdef NITRO_DEBUG if (instance == nullptr) [[unlikely]] { throw std::runtime_error("Failed to create an instance of \"JHybridTestObjectSwiftKotlinSpec\" - the constructor returned null!"); } -#endif return instance; } diff --git a/packages/react-native-nitro-modules/android/src/main/cpp/registry/JHybridObjectRegistry.cpp b/packages/react-native-nitro-modules/android/src/main/cpp/registry/JHybridObjectRegistry.cpp index 2757d6769..e7211bd43 100644 --- a/packages/react-native-nitro-modules/android/src/main/cpp/registry/JHybridObjectRegistry.cpp +++ b/packages/react-native-nitro-modules/android/src/main/cpp/registry/JHybridObjectRegistry.cpp @@ -18,11 +18,9 @@ void JHybridObjectRegistry::registerHybridObjectConstructor(jni::alias_ref std::shared_ptr { // 1. Call the Java initializer function jni::local_ref hybridObject = sharedInitializer->call(); -#ifdef NITRO_DEBUG if (hybridObject == nullptr) [[unlikely]] { throw std::runtime_error("Failed to create HybridObject \"" + hybridObjectName + "\" - the constructor returned null!"); } -#endif // 2. Make the resulting HybridObject a global (shared) reference jni::global_ref globalHybridObject = jni::make_global(hybridObject); diff --git a/packages/react-native-nitro-modules/cpp/core/HybridFunction.hpp b/packages/react-native-nitro-modules/cpp/core/HybridFunction.hpp index 1f6a36461..87d8e493f 100644 --- a/packages/react-native-nitro-modules/cpp/core/HybridFunction.hpp +++ b/packages/react-native-nitro-modules/cpp/core/HybridFunction.hpp @@ -171,7 +171,6 @@ class HybridFunction final { static inline std::shared_ptr getHybridObjectNativeState(jsi::Runtime& runtime, const jsi::Value& value, FunctionKind funcKind, const std::string& funcName) { // 1. Convert jsi::Value to jsi::Object -#ifdef NITRO_DEBUG if (!value.isObject()) [[unlikely]] { throw jsi::JSError(runtime, "Cannot " + getHybridFuncDebugInfo(funcKind, funcName) + " - `this` is not bound! Suggestions:\n" @@ -182,7 +181,6 @@ class HybridFunction final { "- Did you accidentally call `" + funcName + "` on the prototype directly?"); } -#endif jsi::Object object = value.getObject(runtime); // 2. Check if it even has any kind of `NativeState` diff --git a/packages/react-native-nitro-modules/cpp/jsi/JSICache.cpp b/packages/react-native-nitro-modules/cpp/jsi/JSICache.cpp index 45958d06d..70148f370 100644 --- a/packages/react-native-nitro-modules/cpp/jsi/JSICache.cpp +++ b/packages/react-native-nitro-modules/cpp/jsi/JSICache.cpp @@ -47,11 +47,9 @@ JSICacheReference JSICache::getOrCreateCache(jsi::Runtime& runtime) { Logger::log(LogLevel::Warning, TAG, "JSICache was created, but it is no longer strong!"); } -#ifdef NITRO_DEBUG if (runtime.global().hasProperty(runtime, CACHE_PROP_NAME)) [[unlikely]] { throw std::runtime_error("The Runtime \"" + getRuntimeId(runtime) + "\" already has a global cache! (\"" + CACHE_PROP_NAME + "\")"); } -#endif // Cache doesn't exist yet. Logger::log(LogLevel::Info, TAG, "Creating new JSICache for runtime %s..", getRuntimeId(runtime).c_str()); diff --git a/packages/react-native-nitro-modules/cpp/jsi/JSIConverter+ArrayBuffer.hpp b/packages/react-native-nitro-modules/cpp/jsi/JSIConverter+ArrayBuffer.hpp index 121a06104..ecb4c1815 100644 --- a/packages/react-native-nitro-modules/cpp/jsi/JSIConverter+ArrayBuffer.hpp +++ b/packages/react-native-nitro-modules/cpp/jsi/JSIConverter+ArrayBuffer.hpp @@ -31,22 +31,18 @@ using namespace facebook; template struct JSIConverter>> final { static inline std::shared_ptr fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) { -#ifdef NITRO_DEBUG if (!arg.isObject()) [[unlikely]] { throw std::invalid_argument("Value \"" + arg.toString(runtime).utf8(runtime) + "\" is not an ArrayBuffer - " "in fact, it's not even an object!"); } -#endif jsi::Object object = arg.asObject(runtime); -#ifdef NITRO_DEBUG if (!object.isArrayBuffer(runtime)) [[unlikely]] { throw std::invalid_argument("Object \"" + arg.toString(runtime).utf8(runtime) + "\" is not an ArrayBuffer! " "Are you maybe passing a TypedArray (e.g. Uint8Array)? Try to pass it's `.buffer` value."); } -#endif JSICacheReference cache = JSICache::getOrCreateCache(runtime); auto borrowingArrayBuffer = cache.makeShared(object.getArrayBuffer(runtime)); diff --git a/packages/react-native-nitro-modules/cpp/jsi/JSIConverter+HostObject.hpp b/packages/react-native-nitro-modules/cpp/jsi/JSIConverter+HostObject.hpp index 22cb8a392..1098e6a6e 100644 --- a/packages/react-native-nitro-modules/cpp/jsi/JSIConverter+HostObject.hpp +++ b/packages/react-native-nitro-modules/cpp/jsi/JSIConverter+HostObject.hpp @@ -20,7 +20,6 @@ struct JSIConverter>> using TPointee = typename T::element_type; static inline T fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) { -#ifdef NITRO_DEBUG if (!arg.isObject()) [[unlikely]] { if (arg.isUndefined()) [[unlikely]] { throw jsi::JSError(runtime, invalidTypeErrorMessage("undefined", "It is undefined!")); @@ -29,10 +28,8 @@ struct JSIConverter>> throw jsi::JSError(runtime, invalidTypeErrorMessage(stringRepresentation, "It is not an object!")); } } -#endif jsi::Object object = arg.asObject(runtime); -#ifdef NITRO_DEBUG if (!object.isHostObject(runtime)) [[unlikely]] { if (!object.isHostObject(runtime)) [[unlikely]] { std::string stringRepresentation = arg.toString(runtime).utf8(runtime); @@ -42,7 +39,6 @@ struct JSIConverter>> throw jsi::JSError(runtime, invalidTypeErrorMessage(stringRepresentation, "It is a different HostObject!")); } } -#endif return object.getHostObject(runtime); } diff --git a/packages/react-native-nitro-modules/cpp/jsi/JSIConverter+HybridObject.hpp b/packages/react-native-nitro-modules/cpp/jsi/JSIConverter+HybridObject.hpp index b5c190db2..8720f7d43 100644 --- a/packages/react-native-nitro-modules/cpp/jsi/JSIConverter+HybridObject.hpp +++ b/packages/react-native-nitro-modules/cpp/jsi/JSIConverter+HybridObject.hpp @@ -25,7 +25,6 @@ struct JSIConverter> using TPointee = typename T::element_type; static inline T fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) { -#ifdef NITRO_DEBUG if (!arg.isObject()) [[unlikely]] { if (arg.isUndefined()) [[unlikely]] { throw jsi::JSError(runtime, invalidTypeErrorMessage("undefined", "It is undefined!")); @@ -34,10 +33,8 @@ struct JSIConverter> throw jsi::JSError(runtime, invalidTypeErrorMessage(stringRepresentation, "It is not an object!")); } } -#endif jsi::Object object = arg.asObject(runtime); -#ifdef NITRO_DEBUG if (!object.hasNativeState(runtime)) [[unlikely]] { if (!object.hasNativeState(runtime)) [[unlikely]] { std::string stringRepresentation = arg.toString(runtime).utf8(runtime); @@ -47,7 +44,6 @@ struct JSIConverter> throw jsi::JSError(runtime, invalidTypeErrorMessage(stringRepresentation, "It has a different NativeState!")); } } -#endif std::shared_ptr nativeState = object.getNativeState(runtime); return std::dynamic_pointer_cast(nativeState); } diff --git a/packages/react-native-nitro-modules/cpp/registry/HybridObjectRegistry.cpp b/packages/react-native-nitro-modules/cpp/registry/HybridObjectRegistry.cpp index fc9397e81..bd783f36e 100644 --- a/packages/react-native-nitro-modules/cpp/registry/HybridObjectRegistry.cpp +++ b/packages/react-native-nitro-modules/cpp/registry/HybridObjectRegistry.cpp @@ -32,7 +32,6 @@ std::vector HybridObjectRegistry::getAllHybridObjectNames() { void HybridObjectRegistry::registerHybridObjectConstructor(const std::string& hybridObjectName, HybridObjectConstructorFn&& constructorFn) { Logger::log(LogLevel::Info, TAG, "Registering HybridObject \"%s\"...", hybridObjectName.c_str()); auto& map = HybridObjectRegistry::getRegistry(); -#ifdef NITRO_DEBUG if (map.contains(hybridObjectName)) [[unlikely]] { auto message = "HybridObject \"" + std::string(hybridObjectName) + @@ -42,7 +41,6 @@ void HybridObjectRegistry::registerHybridObjectConstructor(const std::string& hy "- If you just registered your own HybridObject, maybe you accidentally called `registerHybridObjectConstructor(...)` twice?"; throw std::runtime_error(message); } -#endif map.insert({hybridObjectName, std::move(constructorFn)}); Logger::log(LogLevel::Info, TAG, "Successfully registered HybridObject \"%s\"!", hybridObjectName.c_str()); }