Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef nsError_h__ |
michael@0 | 7 | #define nsError_h__ |
michael@0 | 8 | |
michael@0 | 9 | #include "mozilla/Likely.h" |
michael@0 | 10 | #include "mozilla/TypedEnum.h" |
michael@0 | 11 | |
michael@0 | 12 | #include <stdint.h> |
michael@0 | 13 | |
michael@0 | 14 | /* |
michael@0 | 15 | * To add error code to your module, you need to do the following: |
michael@0 | 16 | * |
michael@0 | 17 | * 1) Add a module offset code. Add yours to the bottom of the list |
michael@0 | 18 | * right below this comment, adding 1. |
michael@0 | 19 | * |
michael@0 | 20 | * 2) In your module, define a header file which uses one of the |
michael@0 | 21 | * NE_ERROR_GENERATExxxxxx macros. Some examples below: |
michael@0 | 22 | * |
michael@0 | 23 | * #define NS_ERROR_MYMODULE_MYERROR1 NS_ERROR_GENERATE(NS_ERROR_SEVERITY_ERROR,NS_ERROR_MODULE_MYMODULE,1) |
michael@0 | 24 | * #define NS_ERROR_MYMODULE_MYERROR2 NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_MYMODULE,2) |
michael@0 | 25 | * #define NS_ERROR_MYMODULE_MYERROR3 NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_MYMODULE,3) |
michael@0 | 26 | * |
michael@0 | 27 | */ |
michael@0 | 28 | |
michael@0 | 29 | |
michael@0 | 30 | /** |
michael@0 | 31 | * @name Standard Module Offset Code. Each Module should identify a unique number |
michael@0 | 32 | * and then all errors associated with that module become offsets from the |
michael@0 | 33 | * base associated with that module id. There are 16 bits of code bits for |
michael@0 | 34 | * each module. |
michael@0 | 35 | */ |
michael@0 | 36 | |
michael@0 | 37 | #define NS_ERROR_MODULE_XPCOM 1 |
michael@0 | 38 | #define NS_ERROR_MODULE_BASE 2 |
michael@0 | 39 | #define NS_ERROR_MODULE_GFX 3 |
michael@0 | 40 | #define NS_ERROR_MODULE_WIDGET 4 |
michael@0 | 41 | #define NS_ERROR_MODULE_CALENDAR 5 |
michael@0 | 42 | #define NS_ERROR_MODULE_NETWORK 6 |
michael@0 | 43 | #define NS_ERROR_MODULE_PLUGINS 7 |
michael@0 | 44 | #define NS_ERROR_MODULE_LAYOUT 8 |
michael@0 | 45 | #define NS_ERROR_MODULE_HTMLPARSER 9 |
michael@0 | 46 | #define NS_ERROR_MODULE_RDF 10 |
michael@0 | 47 | #define NS_ERROR_MODULE_UCONV 11 |
michael@0 | 48 | #define NS_ERROR_MODULE_REG 12 |
michael@0 | 49 | #define NS_ERROR_MODULE_FILES 13 |
michael@0 | 50 | #define NS_ERROR_MODULE_DOM 14 |
michael@0 | 51 | #define NS_ERROR_MODULE_IMGLIB 15 |
michael@0 | 52 | #define NS_ERROR_MODULE_MAILNEWS 16 |
michael@0 | 53 | #define NS_ERROR_MODULE_EDITOR 17 |
michael@0 | 54 | #define NS_ERROR_MODULE_XPCONNECT 18 |
michael@0 | 55 | #define NS_ERROR_MODULE_PROFILE 19 |
michael@0 | 56 | #define NS_ERROR_MODULE_LDAP 20 |
michael@0 | 57 | #define NS_ERROR_MODULE_SECURITY 21 |
michael@0 | 58 | #define NS_ERROR_MODULE_DOM_XPATH 22 |
michael@0 | 59 | /* 23 used to be NS_ERROR_MODULE_DOM_RANGE (see bug 711047) */ |
michael@0 | 60 | #define NS_ERROR_MODULE_URILOADER 24 |
michael@0 | 61 | #define NS_ERROR_MODULE_CONTENT 25 |
michael@0 | 62 | #define NS_ERROR_MODULE_PYXPCOM 26 |
michael@0 | 63 | #define NS_ERROR_MODULE_XSLT 27 |
michael@0 | 64 | #define NS_ERROR_MODULE_IPC 28 |
michael@0 | 65 | #define NS_ERROR_MODULE_SVG 29 |
michael@0 | 66 | #define NS_ERROR_MODULE_STORAGE 30 |
michael@0 | 67 | #define NS_ERROR_MODULE_SCHEMA 31 |
michael@0 | 68 | #define NS_ERROR_MODULE_DOM_FILE 32 |
michael@0 | 69 | #define NS_ERROR_MODULE_DOM_INDEXEDDB 33 |
michael@0 | 70 | #define NS_ERROR_MODULE_DOM_FILEHANDLE 34 |
michael@0 | 71 | #define NS_ERROR_MODULE_SIGNED_JAR 35 |
michael@0 | 72 | #define NS_ERROR_MODULE_DOM_FILESYSTEM 36 |
michael@0 | 73 | |
michael@0 | 74 | /* NS_ERROR_MODULE_GENERAL should be used by modules that do not |
michael@0 | 75 | * care if return code values overlap. Callers of methods that |
michael@0 | 76 | * return such codes should be aware that they are not |
michael@0 | 77 | * globally unique. Implementors should be careful about blindly |
michael@0 | 78 | * returning codes from other modules that might also use |
michael@0 | 79 | * the generic base. |
michael@0 | 80 | */ |
michael@0 | 81 | #define NS_ERROR_MODULE_GENERAL 51 |
michael@0 | 82 | |
michael@0 | 83 | /** |
michael@0 | 84 | * @name Severity Code. This flag identifies the level of warning |
michael@0 | 85 | */ |
michael@0 | 86 | |
michael@0 | 87 | #define NS_ERROR_SEVERITY_SUCCESS 0 |
michael@0 | 88 | #define NS_ERROR_SEVERITY_ERROR 1 |
michael@0 | 89 | |
michael@0 | 90 | /** |
michael@0 | 91 | * @name Mozilla Code. This flag separates consumers of mozilla code |
michael@0 | 92 | * from the native platform |
michael@0 | 93 | */ |
michael@0 | 94 | |
michael@0 | 95 | #define NS_ERROR_MODULE_BASE_OFFSET 0x45 |
michael@0 | 96 | |
michael@0 | 97 | /* Helpers for defining our enum, to be undef'd later */ |
michael@0 | 98 | #define SUCCESS_OR_FAILURE(sev, module, code) \ |
michael@0 | 99 | ((uint32_t)(sev) << 31) | \ |
michael@0 | 100 | ((uint32_t)(module + NS_ERROR_MODULE_BASE_OFFSET) << 16) | \ |
michael@0 | 101 | (uint32_t)(code) |
michael@0 | 102 | #define SUCCESS(code) \ |
michael@0 | 103 | SUCCESS_OR_FAILURE(NS_ERROR_SEVERITY_SUCCESS, MODULE, code) |
michael@0 | 104 | #define FAILURE(code) \ |
michael@0 | 105 | SUCCESS_OR_FAILURE(NS_ERROR_SEVERITY_ERROR, MODULE, code) |
michael@0 | 106 | |
michael@0 | 107 | /** |
michael@0 | 108 | * @name Standard return values |
michael@0 | 109 | */ |
michael@0 | 110 | |
michael@0 | 111 | /*@{*/ |
michael@0 | 112 | |
michael@0 | 113 | /* Unfortunately, our workaround for compilers that don't support enum class |
michael@0 | 114 | * doesn't really work for nsresult. We need constants like NS_OK with type |
michael@0 | 115 | * nsresult, but they can't be used in (e.g.) switch cases if they're objects. |
michael@0 | 116 | * But if we define them to be of type nsresult::Enum instead, that causes |
michael@0 | 117 | * return foo ? F() : NS_ERROR_FAILURE; |
michael@0 | 118 | * to fail, because nsresult and nsresult::Enum are two distinct types and |
michael@0 | 119 | * either can be converted to the other, so it's ambiguous. So we have to fall |
michael@0 | 120 | * back to a regular enum. |
michael@0 | 121 | */ |
michael@0 | 122 | #if defined(MOZ_HAVE_CXX11_STRONG_ENUMS) |
michael@0 | 123 | typedef enum class tag_nsresult : uint32_t |
michael@0 | 124 | { |
michael@0 | 125 | #undef ERROR |
michael@0 | 126 | #define ERROR(key, val) key = val |
michael@0 | 127 | #include "ErrorList.h" |
michael@0 | 128 | #undef ERROR |
michael@0 | 129 | } nsresult; |
michael@0 | 130 | |
michael@0 | 131 | /* |
michael@0 | 132 | * enum classes don't place their initializers in the global scope, so we need |
michael@0 | 133 | * #define's for compatibility with old code. |
michael@0 | 134 | */ |
michael@0 | 135 | #include "ErrorListCxxDefines.h" |
michael@0 | 136 | #elif defined(MOZ_HAVE_CXX11_ENUM_TYPE) |
michael@0 | 137 | typedef enum tag_nsresult : uint32_t |
michael@0 | 138 | { |
michael@0 | 139 | #undef ERROR |
michael@0 | 140 | #define ERROR(key, val) key = val |
michael@0 | 141 | #include "ErrorList.h" |
michael@0 | 142 | #undef ERROR |
michael@0 | 143 | } nsresult; |
michael@0 | 144 | #elif defined(__cplusplus) |
michael@0 | 145 | /* |
michael@0 | 146 | * We're C++ in an old compiler lacking enum classes *and* typed enums (likely |
michael@0 | 147 | * gcc < 4.5.1 as clang/MSVC have long supported one or both), or compiler |
michael@0 | 148 | * support is unknown. Yet nsresult must have unsigned 32-bit representation. |
michael@0 | 149 | * So just make it a typedef, and implement the constants with global consts. |
michael@0 | 150 | */ |
michael@0 | 151 | typedef uint32_t nsresult; |
michael@0 | 152 | |
michael@0 | 153 | const nsresult |
michael@0 | 154 | #undef ERROR |
michael@0 | 155 | #define ERROR(key, val) key = val |
michael@0 | 156 | #include "ErrorList.h" |
michael@0 | 157 | #undef ERROR |
michael@0 | 158 | ; |
michael@0 | 159 | #else |
michael@0 | 160 | /* |
michael@0 | 161 | * C doesn't have any way to fix the type underlying an enum, and enum |
michael@0 | 162 | * initializers can't have values outside the range of 'int'. So typedef |
michael@0 | 163 | * nsresult to the correct unsigned type, and fall back to using #defines for |
michael@0 | 164 | * all error constants. |
michael@0 | 165 | */ |
michael@0 | 166 | typedef uint32_t nsresult; |
michael@0 | 167 | #include "ErrorListCDefines.h" |
michael@0 | 168 | #endif |
michael@0 | 169 | |
michael@0 | 170 | #undef SUCCESS_OR_FAILURE |
michael@0 | 171 | #undef SUCCESS |
michael@0 | 172 | #undef FAILURE |
michael@0 | 173 | |
michael@0 | 174 | /** |
michael@0 | 175 | * @name Standard Error Handling Macros |
michael@0 | 176 | * @return 0 or 1 (false/true with bool type for C++) |
michael@0 | 177 | */ |
michael@0 | 178 | |
michael@0 | 179 | #ifdef __cplusplus |
michael@0 | 180 | inline uint32_t NS_FAILED_impl(nsresult _nsresult) { |
michael@0 | 181 | return static_cast<uint32_t>(_nsresult) & 0x80000000; |
michael@0 | 182 | } |
michael@0 | 183 | #define NS_FAILED(_nsresult) ((bool)MOZ_UNLIKELY(NS_FAILED_impl(_nsresult))) |
michael@0 | 184 | #define NS_SUCCEEDED(_nsresult) ((bool)MOZ_LIKELY(!NS_FAILED_impl(_nsresult))) |
michael@0 | 185 | |
michael@0 | 186 | /* Check that our enum type is actually uint32_t as expected */ |
michael@0 | 187 | static_assert(((nsresult)0) < ((nsresult)-1), |
michael@0 | 188 | "nsresult must be an unsigned type"); |
michael@0 | 189 | static_assert(sizeof(nsresult) == sizeof(uint32_t), |
michael@0 | 190 | "nsresult must be 32 bits"); |
michael@0 | 191 | #else |
michael@0 | 192 | #define NS_FAILED_impl(_nsresult) ((_nsresult) & 0x80000000) |
michael@0 | 193 | #define NS_FAILED(_nsresult) (MOZ_UNLIKELY(NS_FAILED_impl(_nsresult))) |
michael@0 | 194 | #define NS_SUCCEEDED(_nsresult) (MOZ_LIKELY(!NS_FAILED_impl(_nsresult))) |
michael@0 | 195 | #endif |
michael@0 | 196 | |
michael@0 | 197 | /** |
michael@0 | 198 | * @name Standard Error Generating Macros |
michael@0 | 199 | */ |
michael@0 | 200 | |
michael@0 | 201 | #define NS_ERROR_GENERATE(sev, module, code) \ |
michael@0 | 202 | (nsresult)(((uint32_t)(sev) << 31) | \ |
michael@0 | 203 | ((uint32_t)(module + NS_ERROR_MODULE_BASE_OFFSET) << 16) | \ |
michael@0 | 204 | ((uint32_t)(code))) |
michael@0 | 205 | |
michael@0 | 206 | #define NS_ERROR_GENERATE_SUCCESS(module, code) \ |
michael@0 | 207 | NS_ERROR_GENERATE(NS_ERROR_SEVERITY_SUCCESS, module, code) |
michael@0 | 208 | |
michael@0 | 209 | #define NS_ERROR_GENERATE_FAILURE(module, code) \ |
michael@0 | 210 | NS_ERROR_GENERATE(NS_ERROR_SEVERITY_ERROR, module, code) |
michael@0 | 211 | |
michael@0 | 212 | /* |
michael@0 | 213 | * This will return the nsresult corresponding to the most recent NSPR failure |
michael@0 | 214 | * returned by PR_GetError. |
michael@0 | 215 | * |
michael@0 | 216 | *********************************************************************** |
michael@0 | 217 | * Do not depend on this function. It will be going away! |
michael@0 | 218 | *********************************************************************** |
michael@0 | 219 | */ |
michael@0 | 220 | extern nsresult |
michael@0 | 221 | NS_ErrorAccordingToNSPR(); |
michael@0 | 222 | |
michael@0 | 223 | |
michael@0 | 224 | /** |
michael@0 | 225 | * @name Standard Macros for retrieving error bits |
michael@0 | 226 | */ |
michael@0 | 227 | |
michael@0 | 228 | #ifdef __cplusplus |
michael@0 | 229 | inline uint16_t NS_ERROR_GET_CODE(nsresult err) { |
michael@0 | 230 | return uint32_t(err) & 0xffff; |
michael@0 | 231 | } |
michael@0 | 232 | inline uint16_t NS_ERROR_GET_MODULE(nsresult err) { |
michael@0 | 233 | return ((uint32_t(err) >> 16) - NS_ERROR_MODULE_BASE_OFFSET) & 0x1fff; |
michael@0 | 234 | } |
michael@0 | 235 | inline bool NS_ERROR_GET_SEVERITY(nsresult err) { |
michael@0 | 236 | return uint32_t(err) >> 31; |
michael@0 | 237 | } |
michael@0 | 238 | #else |
michael@0 | 239 | #define NS_ERROR_GET_CODE(err) ((err) & 0xffff) |
michael@0 | 240 | #define NS_ERROR_GET_MODULE(err) ((((err) >> 16) - NS_ERROR_MODULE_BASE_OFFSET) & 0x1fff) |
michael@0 | 241 | #define NS_ERROR_GET_SEVERITY(err) (((err) >> 31) & 0x1) |
michael@0 | 242 | #endif |
michael@0 | 243 | |
michael@0 | 244 | |
michael@0 | 245 | #ifdef _MSC_VER |
michael@0 | 246 | #pragma warning(disable: 4251) /* 'nsCOMPtr<class nsIInputStream>' needs to have dll-interface to be used by clients of class 'nsInputStream' */ |
michael@0 | 247 | #pragma warning(disable: 4275) /* non dll-interface class 'nsISupports' used as base for dll-interface class 'nsIRDFNode' */ |
michael@0 | 248 | #endif |
michael@0 | 249 | |
michael@0 | 250 | #endif |