diff --git a/ReactCommon/fabric/debug/DebugStringConvertible.cpp b/ReactCommon/fabric/debug/DebugStringConvertible.cpp index 951d5c27fe..b8a2e30eea 100644 --- a/ReactCommon/fabric/debug/DebugStringConvertible.cpp +++ b/ReactCommon/fabric/debug/DebugStringConvertible.cpp @@ -142,6 +142,9 @@ std::string toString(double const &value) { return folly::to(value); } std::string toString(void const *value) { + if (value == nullptr) { + return "null"; + } return folly::sformat("0x{0:016x}", reinterpret_cast(value)); } diff --git a/ReactCommon/fabric/debug/DebugStringConvertible.h b/ReactCommon/fabric/debug/DebugStringConvertible.h index 0337896116..2767f92d2e 100644 --- a/ReactCommon/fabric/debug/DebugStringConvertible.h +++ b/ReactCommon/fabric/debug/DebugStringConvertible.h @@ -272,7 +272,7 @@ inline std::string getDebugDescription( // `void *` inline std::string getDebugDescription( - void const *pointer, + void *pointer, DebugStringConvertibleOptions options = {}) { return toString(pointer); } @@ -295,6 +295,30 @@ std::vector getDebugChildren(std::vector const &vector) { return vector; } +// `std::shared_ptr` +template +inline std::string getDebugDescription( + std::shared_ptr const &pointer, + DebugStringConvertibleOptions options = {}) { + return getDebugDescription((void *)pointer.get()) + "(shared)"; +} + +// `std::weak_ptr` +template +inline std::string getDebugDescription( + std::weak_ptr const &pointer, + DebugStringConvertibleOptions options = {}) { + return getDebugDescription((void *)pointer.lock().get()) + "(weak)"; +} + +// `std::unique_ptr` +template +inline std::string getDebugDescription( + std::unique_ptr const &pointer, + DebugStringConvertibleOptions options = {}) { + return getDebugDescription((void *)pointer.get()) + "(unique)"; +} + /* * Trivial container for `name` and `value` pair that supports * static `DebugStringConvertible` informal interface.