1998-10-19 21:48:55 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
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
|
|
|
|
2013-01-29 04:33:17 +04:00
|
|
|
#include "mozilla/Likely.h"
|
|
|
|
#include "mozilla/TypedEnum.h"
|
|
|
|
|
2013-07-30 18:25:31 +04:00
|
|
|
#include <stdint.h>
|
|
|
|
|
1998-10-19 21:48:55 +04:00
|
|
|
/*
|
|
|
|
* To add error code to your module, you need to do the following:
|
|
|
|
*
|
2009-03-13 17:51:27 +03:00
|
|
|
* 1) Add a module offset code. Add yours to the bottom of the list
|
1998-10-19 21:48:55 +04:00
|
|
|
* right below this comment, adding 1.
|
|
|
|
*
|
|
|
|
* 2) In your module, define a header file which uses one of the
|
|
|
|
* NE_ERROR_GENERATExxxxxx macros. Some examples below:
|
|
|
|
*
|
|
|
|
* #define NS_ERROR_MYMODULE_MYERROR1 NS_ERROR_GENERATE(NS_ERROR_SEVERITY_ERROR,NS_ERROR_MODULE_MYMODULE,1)
|
|
|
|
* #define NS_ERROR_MYMODULE_MYERROR2 NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_MYMODULE,2)
|
|
|
|
* #define NS_ERROR_MYMODULE_MYERROR3 NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_MYMODULE,3)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name Standard Module Offset Code. Each Module should identify a unique number
|
|
|
|
* and then all errors associated with that module become offsets from the
|
|
|
|
* base associated with that module id. There are 16 bits of code bits for
|
|
|
|
* each module.
|
|
|
|
*/
|
|
|
|
|
1998-12-15 09:10:59 +03:00
|
|
|
#define NS_ERROR_MODULE_XPCOM 1
|
|
|
|
#define NS_ERROR_MODULE_BASE 2
|
|
|
|
#define NS_ERROR_MODULE_GFX 3
|
|
|
|
#define NS_ERROR_MODULE_WIDGET 4
|
|
|
|
#define NS_ERROR_MODULE_CALENDAR 5
|
|
|
|
#define NS_ERROR_MODULE_NETWORK 6
|
|
|
|
#define NS_ERROR_MODULE_PLUGINS 7
|
|
|
|
#define NS_ERROR_MODULE_LAYOUT 8
|
1998-12-11 20:02:37 +03:00
|
|
|
#define NS_ERROR_MODULE_HTMLPARSER 9
|
1998-12-22 04:11:18 +03:00
|
|
|
#define NS_ERROR_MODULE_RDF 10
|
1999-01-27 21:00:50 +03:00
|
|
|
#define NS_ERROR_MODULE_UCONV 11
|
1999-02-11 02:27:09 +03:00
|
|
|
#define NS_ERROR_MODULE_REG 12
|
1999-02-18 21:58:25 +03:00
|
|
|
#define NS_ERROR_MODULE_FILES 13
|
1999-09-09 03:11:52 +04:00
|
|
|
#define NS_ERROR_MODULE_DOM 14
|
1999-11-05 01:27:36 +03:00
|
|
|
#define NS_ERROR_MODULE_IMGLIB 15
|
1999-02-09 07:28:17 +03:00
|
|
|
#define NS_ERROR_MODULE_MAILNEWS 16
|
1999-03-03 21:30:09 +03:00
|
|
|
#define NS_ERROR_MODULE_EDITOR 17
|
1999-08-18 06:08:26 +04:00
|
|
|
#define NS_ERROR_MODULE_XPCONNECT 18
|
2000-04-19 07:04:49 +04:00
|
|
|
#define NS_ERROR_MODULE_PROFILE 19
|
2000-06-20 07:33:26 +04:00
|
|
|
#define NS_ERROR_MODULE_LDAP 20
|
2002-01-25 18:17:25 +03:00
|
|
|
#define NS_ERROR_MODULE_SECURITY 21
|
2002-03-14 15:18:04 +03:00
|
|
|
#define NS_ERROR_MODULE_DOM_XPATH 22
|
2012-03-17 02:16:40 +04:00
|
|
|
/* 23 used to be NS_ERROR_MODULE_DOM_RANGE (see bug 711047) */
|
2002-09-24 23:53:43 +04:00
|
|
|
#define NS_ERROR_MODULE_URILOADER 24
|
2002-11-25 14:21:22 +03:00
|
|
|
#define NS_ERROR_MODULE_CONTENT 25
|
|
|
|
#define NS_ERROR_MODULE_PYXPCOM 26
|
2003-03-25 23:28:09 +03:00
|
|
|
#define NS_ERROR_MODULE_XSLT 27
|
2004-05-11 09:04:25 +04:00
|
|
|
#define NS_ERROR_MODULE_IPC 28
|
2004-07-22 22:34:36 +04:00
|
|
|
#define NS_ERROR_MODULE_SVG 29
|
2004-12-09 02:14:13 +03:00
|
|
|
#define NS_ERROR_MODULE_STORAGE 30
|
2004-12-10 18:11:31 +03:00
|
|
|
#define NS_ERROR_MODULE_SCHEMA 31
|
2007-07-25 08:29:47 +04:00
|
|
|
#define NS_ERROR_MODULE_DOM_FILE 32
|
2010-11-11 02:25:44 +03:00
|
|
|
#define NS_ERROR_MODULE_DOM_INDEXEDDB 33
|
2012-06-03 20:33:52 +04:00
|
|
|
#define NS_ERROR_MODULE_DOM_FILEHANDLE 34
|
2012-11-15 03:31:39 +04:00
|
|
|
#define NS_ERROR_MODULE_SIGNED_JAR 35
|
2014-03-05 07:25:40 +04:00
|
|
|
#define NS_ERROR_MODULE_DOM_FILESYSTEM 36
|
2002-09-08 00:07:57 +04:00
|
|
|
|
|
|
|
/* NS_ERROR_MODULE_GENERAL should be used by modules that do not
|
|
|
|
* care if return code values overlap. Callers of methods that
|
|
|
|
* return such codes should be aware that they are not
|
|
|
|
* globally unique. Implementors should be careful about blindly
|
|
|
|
* returning codes from other modules that might also use
|
|
|
|
* the generic base.
|
|
|
|
*/
|
2009-03-13 17:51:27 +03:00
|
|
|
#define NS_ERROR_MODULE_GENERAL 51
|
1999-02-09 07:28:17 +03:00
|
|
|
|
2012-08-07 12:27:45 +04:00
|
|
|
/**
|
|
|
|
* @name Severity Code. This flag identifies the level of warning
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define NS_ERROR_SEVERITY_SUCCESS 0
|
|
|
|
#define NS_ERROR_SEVERITY_ERROR 1
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name Mozilla Code. This flag separates consumers of mozilla code
|
|
|
|
* from the native platform
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define NS_ERROR_MODULE_BASE_OFFSET 0x45
|
|
|
|
|
|
|
|
/* Helpers for defining our enum, to be undef'd later */
|
|
|
|
#define SUCCESS_OR_FAILURE(sev, module, code) \
|
|
|
|
((uint32_t)(sev) << 31) | \
|
|
|
|
((uint32_t)(module + NS_ERROR_MODULE_BASE_OFFSET) << 16) | \
|
|
|
|
(uint32_t)(code)
|
|
|
|
#define SUCCESS(code) \
|
|
|
|
SUCCESS_OR_FAILURE(NS_ERROR_SEVERITY_SUCCESS, MODULE, code)
|
|
|
|
#define FAILURE(code) \
|
|
|
|
SUCCESS_OR_FAILURE(NS_ERROR_SEVERITY_ERROR, MODULE, code)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name Standard return values
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*@{*/
|
|
|
|
|
2012-08-02 12:55:58 +04:00
|
|
|
/* Unfortunately, our workaround for compilers that don't support enum class
|
|
|
|
* doesn't really work for nsresult. We need constants like NS_OK with type
|
|
|
|
* nsresult, but they can't be used in (e.g.) switch cases if they're objects.
|
|
|
|
* But if we define them to be of type nsresult::Enum instead, that causes
|
|
|
|
* return foo ? F() : NS_ERROR_FAILURE;
|
|
|
|
* to fail, because nsresult and nsresult::Enum are two distinct types and
|
|
|
|
* either can be converted to the other, so it's ambiguous. So we have to fall
|
2013-01-05 07:55:22 +04:00
|
|
|
* back to a regular enum.
|
2012-08-02 12:55:58 +04:00
|
|
|
*/
|
2013-01-05 07:55:22 +04:00
|
|
|
#if defined(MOZ_HAVE_CXX11_STRONG_ENUMS)
|
2012-08-02 12:55:58 +04:00
|
|
|
typedef enum class tag_nsresult : uint32_t
|
2013-01-31 03:32:44 +04:00
|
|
|
{
|
|
|
|
#undef ERROR
|
|
|
|
#define ERROR(key, val) key = val
|
|
|
|
#include "ErrorList.h"
|
|
|
|
#undef ERROR
|
|
|
|
} nsresult;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* enum classes don't place their initializers in the global scope, so we need
|
|
|
|
* #define's for compatibility with old code.
|
|
|
|
*/
|
|
|
|
#include "ErrorListCxxDefines.h"
|
2013-01-05 07:55:22 +04:00
|
|
|
#elif defined(MOZ_HAVE_CXX11_ENUM_TYPE)
|
2012-08-02 12:55:58 +04:00
|
|
|
typedef enum tag_nsresult : uint32_t
|
|
|
|
{
|
2012-10-16 13:01:58 +04:00
|
|
|
#undef ERROR
|
2012-08-02 12:55:58 +04:00
|
|
|
#define ERROR(key, val) key = val
|
|
|
|
#include "ErrorList.h"
|
|
|
|
#undef ERROR
|
|
|
|
} nsresult;
|
2013-01-31 03:32:44 +04:00
|
|
|
#elif defined(__cplusplus)
|
|
|
|
/*
|
|
|
|
* We're C++ in an old compiler lacking enum classes *and* typed enums (likely
|
|
|
|
* gcc < 4.5.1 as clang/MSVC have long supported one or both), or compiler
|
|
|
|
* support is unknown. Yet nsresult must have unsigned 32-bit representation.
|
|
|
|
* So just make it a typedef, and implement the constants with global consts.
|
|
|
|
*/
|
|
|
|
typedef uint32_t nsresult;
|
2012-08-02 12:55:58 +04:00
|
|
|
|
2013-01-31 03:32:44 +04:00
|
|
|
const nsresult
|
|
|
|
#undef ERROR
|
|
|
|
#define ERROR(key, val) key = val
|
|
|
|
#include "ErrorList.h"
|
|
|
|
#undef ERROR
|
|
|
|
;
|
|
|
|
#else
|
|
|
|
/*
|
|
|
|
* C doesn't have any way to fix the type underlying an enum, and enum
|
|
|
|
* initializers can't have values outside the range of 'int'. So typedef
|
|
|
|
* nsresult to the correct unsigned type, and fall back to using #defines for
|
|
|
|
* all error constants.
|
|
|
|
*/
|
2013-01-05 07:55:22 +04:00
|
|
|
typedef uint32_t nsresult;
|
|
|
|
#include "ErrorListCDefines.h"
|
2013-01-31 03:32:44 +04:00
|
|
|
#endif
|
2012-08-07 12:27:45 +04:00
|
|
|
|
|
|
|
#undef SUCCESS_OR_FAILURE
|
|
|
|
#undef SUCCESS
|
|
|
|
#undef FAILURE
|
|
|
|
|
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
|
|
|
*/
|
|
|
|
|
2012-06-27 18:54:01 +04:00
|
|
|
#ifdef __cplusplus
|
2012-10-18 04:43:06 +04:00
|
|
|
inline uint32_t NS_FAILED_impl(nsresult _nsresult) {
|
2012-08-02 12:55:58 +04:00
|
|
|
return static_cast<uint32_t>(_nsresult) & 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");
|
2008-05-01 04:47:27 +04:00
|
|
|
#else
|
2012-10-18 04:43:06 +04:00
|
|
|
#define NS_FAILED_impl(_nsresult) ((_nsresult) & 0x80000000)
|
2012-10-26 17:32:10 +04:00
|
|
|
#define NS_FAILED(_nsresult) (MOZ_UNLIKELY(NS_FAILED_impl(_nsresult)))
|
|
|
|
#define NS_SUCCEEDED(_nsresult) (MOZ_LIKELY(!NS_FAILED_impl(_nsresult)))
|
2008-05-01 04:47:27 +04:00
|
|
|
#endif
|
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) \
|
2012-08-22 19:56:38 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
inline uint16_t NS_ERROR_GET_CODE(nsresult err) {
|
|
|
|
return uint32_t(err) & 0xffff;
|
|
|
|
}
|
|
|
|
inline uint16_t NS_ERROR_GET_MODULE(nsresult err) {
|
|
|
|
return ((uint32_t(err) >> 16) - NS_ERROR_MODULE_BASE_OFFSET) & 0x1fff;
|
|
|
|
}
|
|
|
|
inline bool NS_ERROR_GET_SEVERITY(nsresult err) {
|
|
|
|
return uint32_t(err) >> 31;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define NS_ERROR_GET_CODE(err) ((err) & 0xffff)
|
|
|
|
#define NS_ERROR_GET_MODULE(err) ((((err) >> 16) - NS_ERROR_MODULE_BASE_OFFSET) & 0x1fff)
|
|
|
|
#define NS_ERROR_GET_SEVERITY(err) (((err) >> 31) & 0x1)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
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
|