2014-05-05 21:30:39 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1998-10-19 21:48:55 +04:00
|
|
|
|
2001-09-27 07:43:00 +04:00
|
|
|
#ifndef nsError_h__
|
|
|
|
#define nsError_h__
|
1998-10-19 21:48:55 +04:00
|
|
|
|
2015-01-30 02:53:47 +03:00
|
|
|
#ifndef __cplusplus
|
|
|
|
#error nsError.h no longer supports C sources
|
|
|
|
#endif
|
|
|
|
|
2016-02-29 18:43:56 +03:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-01-29 04:33:17 +04:00
|
|
|
#include "mozilla/Likely.h"
|
|
|
|
|
2013-07-30 18:25:31 +04:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2012-08-07 12:27:45 +04:00
|
|
|
#define NS_ERROR_SEVERITY_SUCCESS 0
|
|
|
|
#define NS_ERROR_SEVERITY_ERROR 1
|
|
|
|
|
2017-03-30 21:13:01 +03:00
|
|
|
#include "ErrorList.h"
|
2012-08-07 12:27:45 +04:00
|
|
|
|
1998-10-19 21:48:55 +04:00
|
|
|
/**
|
|
|
|
* @name Standard Error Handling Macros
|
2012-10-18 04:43:06 +04:00
|
|
|
* @return 0 or 1 (false/true with bool type for C++)
|
1998-10-19 21:48:55 +04:00
|
|
|
*/
|
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
inline uint32_t
|
|
|
|
NS_FAILED_impl(nsresult aErr)
|
|
|
|
{
|
|
|
|
return static_cast<uint32_t>(aErr) & 0x80000000;
|
2008-05-01 04:47:27 +04:00
|
|
|
}
|
2012-10-26 17:32:10 +04:00
|
|
|
#define NS_FAILED(_nsresult) ((bool)MOZ_UNLIKELY(NS_FAILED_impl(_nsresult)))
|
|
|
|
#define NS_SUCCEEDED(_nsresult) ((bool)MOZ_LIKELY(!NS_FAILED_impl(_nsresult)))
|
2013-09-17 15:05:12 +04:00
|
|
|
|
|
|
|
/* Check that our enum type is actually uint32_t as expected */
|
|
|
|
static_assert(((nsresult)0) < ((nsresult)-1),
|
|
|
|
"nsresult must be an unsigned type");
|
|
|
|
static_assert(sizeof(nsresult) == sizeof(uint32_t),
|
|
|
|
"nsresult must be 32 bits");
|
1998-10-19 21:48:55 +04:00
|
|
|
|
2016-03-28 20:28:14 +03:00
|
|
|
#define MOZ_ALWAYS_SUCCEEDS(expr) MOZ_ALWAYS_TRUE(NS_SUCCEEDED(expr))
|
|
|
|
|
1998-10-19 21:48:55 +04:00
|
|
|
/**
|
|
|
|
* @name Standard Error Generating Macros
|
|
|
|
*/
|
|
|
|
|
2012-07-27 18:03:27 +04:00
|
|
|
#define NS_ERROR_GENERATE(sev, module, code) \
|
2014-05-05 21:30:39 +04:00
|
|
|
(nsresult)(((uint32_t)(sev) << 31) | \
|
|
|
|
((uint32_t)(module + NS_ERROR_MODULE_BASE_OFFSET) << 16) | \
|
|
|
|
((uint32_t)(code)))
|
1998-10-19 21:48:55 +04:00
|
|
|
|
2012-07-27 18:03:27 +04:00
|
|
|
#define NS_ERROR_GENERATE_SUCCESS(module, code) \
|
|
|
|
NS_ERROR_GENERATE(NS_ERROR_SEVERITY_SUCCESS, module, code)
|
1998-10-19 21:48:55 +04:00
|
|
|
|
2012-07-27 18:03:27 +04:00
|
|
|
#define NS_ERROR_GENERATE_FAILURE(module, code) \
|
|
|
|
NS_ERROR_GENERATE(NS_ERROR_SEVERITY_ERROR, module, code)
|
1998-10-19 21:48:55 +04:00
|
|
|
|
2002-09-08 00:07:57 +04:00
|
|
|
/*
|
|
|
|
* This will return the nsresult corresponding to the most recent NSPR failure
|
|
|
|
* returned by PR_GetError.
|
|
|
|
*
|
|
|
|
***********************************************************************
|
|
|
|
* Do not depend on this function. It will be going away!
|
|
|
|
***********************************************************************
|
|
|
|
*/
|
2011-08-18 17:46:39 +04:00
|
|
|
extern nsresult
|
2000-01-25 00:28:28 +03:00
|
|
|
NS_ErrorAccordingToNSPR();
|
|
|
|
|
1999-03-25 10:29:29 +03:00
|
|
|
|
2012-08-02 12:55:58 +04:00
|
|
|
/**
|
|
|
|
* @name Standard Macros for retrieving error bits
|
|
|
|
*/
|
|
|
|
|
2016-07-09 00:39:53 +03:00
|
|
|
inline constexpr uint16_t
|
2014-05-13 21:41:38 +04:00
|
|
|
NS_ERROR_GET_CODE(nsresult aErr)
|
|
|
|
{
|
|
|
|
return uint32_t(aErr) & 0xffff;
|
2012-08-02 12:55:58 +04:00
|
|
|
}
|
2016-07-09 00:39:53 +03:00
|
|
|
inline constexpr uint16_t
|
2014-05-13 21:41:38 +04:00
|
|
|
NS_ERROR_GET_MODULE(nsresult aErr)
|
|
|
|
{
|
|
|
|
return ((uint32_t(aErr) >> 16) - NS_ERROR_MODULE_BASE_OFFSET) & 0x1fff;
|
2012-08-02 12:55:58 +04:00
|
|
|
}
|
2014-05-13 21:41:38 +04:00
|
|
|
inline bool
|
|
|
|
NS_ERROR_GET_SEVERITY(nsresult aErr)
|
|
|
|
{
|
|
|
|
return uint32_t(aErr) >> 31;
|
2012-08-02 12:55:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-07 09:07:56 +03:00
|
|
|
#ifdef _MSC_VER
|
2002-09-08 00:07:57 +04:00
|
|
|
#pragma warning(disable: 4251) /* 'nsCOMPtr<class nsIInputStream>' needs to have dll-interface to be used by clients of class 'nsInputStream' */
|
|
|
|
#pragma warning(disable: 4275) /* non dll-interface class 'nsISupports' used as base for dll-interface class 'nsIRDFNode' */
|
1999-03-25 10:29:29 +03:00
|
|
|
#endif
|
|
|
|
|
2000-01-25 00:28:28 +03:00
|
|
|
#endif
|