Bug 899546 - ENSURE_SUCCESS macro for ErrorResult, r=bz

This commit is contained in:
Andrea Marchesini 2013-07-31 10:12:46 +02:00
parent 1903f4c376
commit 0fc4510b29

View File

@ -15,6 +15,7 @@
#include "js/Value.h"
#include "nscore.h"
#include "nsStringGlue.h"
#include "mozilla/Assertions.h"
namespace mozilla {
@ -145,6 +146,32 @@ private:
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 */