ReportInternalError.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef mozilla_dom_indexeddb_reportinternalerror_h__
  6. #define mozilla_dom_indexeddb_reportinternalerror_h__
  7. #include "nsDebug.h"
  8. #include "IndexedDatabase.h"
  9. #define IDB_WARNING(...) \
  10. do { \
  11. nsPrintfCString s(__VA_ARGS__); \
  12. mozilla::dom::indexedDB::ReportInternalError(__FILE__, __LINE__, s.get()); \
  13. NS_WARNING(s.get()); \
  14. } while (0)
  15. #define IDB_REPORT_INTERNAL_ERR() \
  16. mozilla::dom::indexedDB::ReportInternalError(__FILE__, __LINE__, \
  17. "UnknownErr")
  18. // Based on NS_ENSURE_TRUE
  19. #define IDB_ENSURE_TRUE(x, ret) \
  20. do { \
  21. if (MOZ_UNLIKELY(!(x))) { \
  22. IDB_REPORT_INTERNAL_ERR(); \
  23. NS_WARNING("IDB_ENSURE_TRUE(" #x ") failed"); \
  24. return ret; \
  25. } \
  26. } while(0)
  27. // Based on NS_ENSURE_SUCCESS
  28. #define IDB_ENSURE_SUCCESS(res, ret) \
  29. do { \
  30. nsresult __rv = res; /* Don't evaluate |res| more than once */ \
  31. if (NS_FAILED(__rv)) { \
  32. IDB_REPORT_INTERNAL_ERR(); \
  33. NS_ENSURE_SUCCESS_BODY(res, ret) \
  34. return ret; \
  35. } \
  36. } while(0)
  37. namespace mozilla {
  38. namespace dom {
  39. namespace indexedDB {
  40. void
  41. ReportInternalError(const char* aFile, uint32_t aLine, const char* aStr);
  42. } // namespace indexedDB
  43. } // namespace dom
  44. } // namespace mozilla
  45. #endif // mozilla_dom_indexeddb_reportinternalerror_h__