Bug 899546 - ENSURE_SUCCESS macro for ErrorResult, r=bz
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 31 Jul 2013 10:12:46 +0200
changeset 148310 42dffbbe9e577d3ec727cc87d93df3afaee2040e
parent 148285 5623c4b04a1e9ccbaacd987ff7c3715d0f822020
child 148311 e8a2344ce2a25929f6155b7c4ee6a64bc1848198
push id4085
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 20:29:25 +0000
treeherdermozilla-aurora@ede8780a15bc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs899546
milestone25.0a1
Bug 899546 - ENSURE_SUCCESS macro for ErrorResult, r=bz
dom/bindings/ErrorResult.h
--- a/dom/bindings/ErrorResult.h
+++ b/dom/bindings/ErrorResult.h
@@ -10,16 +10,17 @@
 
 #ifndef mozilla_ErrorResult_h
 #define mozilla_ErrorResult_h
 
 #include <stdarg.h>
 
 #include "js/Value.h"
 #include "nscore.h"
+#include "nsStringGlue.h"
 #include "mozilla/Assertions.h"
 
 namespace mozilla {
 
 namespace dom {
 
 enum ErrNum {
 #define MSG_DEF(_name, _argc, _str) \
@@ -140,11 +141,37 @@ private:
   bool mMightHaveUnreportedJSException;
 #endif
 
   // Not to be implemented, to make sure people always pass this by
   // reference, not by value.
   ErrorResult(const ErrorResult&) MOZ_DELETE;
 };
 
+/******************************************************************************
+ ** Macros for checking results
+ ******************************************************************************/
+
+#define ENSURE_SUCCESS(res, ret)                                          \
+  do {                                                                    \
+    if (res.Failed()) {                                                   \
+      nsCString msg;                                                      \
+      msg.AppendPrintf("ENSURE_SUCCESS(%s, %s) failed with "              \
+                       "result 0x%X", #res, #ret, res.ErrorCode());       \
+      NS_WARNING(msg.get());                                              \
+      return ret;                                                         \
+    }                                                                     \
+  } while(0)
+
+#define ENSURE_SUCCESS_VOID(res)                                          \
+  do {                                                                    \
+    if (res.Failed()) {                                                   \
+      nsCString msg;                                                      \
+      msg.AppendPrintf("ENSURE_SUCCESS_VOID(%s) failed with "             \
+                       "result 0x%X", #res, res.ErrorCode());             \
+      NS_WARNING(msg.get());                                              \
+      return;                                                             \
+    }                                                                     \
+  } while(0)
+
 } // namespace mozilla
 
 #endif /* mozilla_ErrorResult_h */