Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/nsError.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef nsError_h__
8
#define nsError_h__
9
10
#ifndef __cplusplus
11
#error nsError.h no longer supports C sources
12
#endif
13
14
#include "mozilla/Attributes.h"
15
#include "mozilla/Likely.h"
16
17
#include <stdint.h>
18
19
#define NS_ERROR_SEVERITY_SUCCESS       0
20
0
#define NS_ERROR_SEVERITY_ERROR         1
21
22
#include "ErrorList.h"
23
24
/**
25
 * @name Standard Error Handling Macros
26
 * @return 0 or 1 (false/true with bool type for C++)
27
 */
28
29
inline uint32_t
30
NS_FAILED_impl(nsresult aErr)
31
155M
{
32
155M
  return static_cast<uint32_t>(aErr) & 0x80000000;
33
155M
}
34
121M
#define NS_FAILED(_nsresult)    ((bool)MOZ_UNLIKELY(NS_FAILED_impl(_nsresult)))
35
29.6M
#define NS_SUCCEEDED(_nsresult) ((bool)MOZ_LIKELY(!NS_FAILED_impl(_nsresult)))
36
37
/* Check that our enum type is actually uint32_t as expected */
38
static_assert(((nsresult)0) < ((nsresult)-1),
39
              "nsresult must be an unsigned type");
40
static_assert(sizeof(nsresult) == sizeof(uint32_t),
41
              "nsresult must be 32 bits");
42
43
40
#define MOZ_ALWAYS_SUCCEEDS(expr) MOZ_ALWAYS_TRUE(NS_SUCCEEDED(expr))
44
45
/**
46
 * @name Standard Error Generating Macros
47
 */
48
49
#define NS_ERROR_GENERATE(sev, module, code) \
50
0
  (nsresult)(((uint32_t)(sev) << 31) | \
51
0
             ((uint32_t)(module + NS_ERROR_MODULE_BASE_OFFSET) << 16) | \
52
0
             ((uint32_t)(code)))
53
54
#define NS_ERROR_GENERATE_SUCCESS(module, code) \
55
  NS_ERROR_GENERATE(NS_ERROR_SEVERITY_SUCCESS, module, code)
56
57
#define NS_ERROR_GENERATE_FAILURE(module, code) \
58
0
  NS_ERROR_GENERATE(NS_ERROR_SEVERITY_ERROR, module, code)
59
60
 /*
61
  * This will return the nsresult corresponding to the most recent NSPR failure
62
  * returned by PR_GetError.
63
  *
64
  ***********************************************************************
65
  *      Do not depend on this function. It will be going away!
66
  ***********************************************************************
67
  */
68
extern nsresult
69
NS_ErrorAccordingToNSPR();
70
71
72
/**
73
 * @name Standard Macros for retrieving error bits
74
 */
75
76
inline constexpr uint16_t
77
NS_ERROR_GET_CODE(nsresult aErr)
78
0
{
79
0
  return uint32_t(aErr) & 0xffff;
80
0
}
81
inline constexpr uint16_t
82
NS_ERROR_GET_MODULE(nsresult aErr)
83
0
{
84
0
  return ((uint32_t(aErr) >> 16) - NS_ERROR_MODULE_BASE_OFFSET) & 0x1fff;
85
0
}
86
inline bool
87
NS_ERROR_GET_SEVERITY(nsresult aErr)
88
0
{
89
0
  return uint32_t(aErr) >> 31;
90
0
}
91
92
93
#ifdef _MSC_VER
94
#pragma warning(disable: 4251) /* 'nsCOMPtr<class nsIInputStream>' needs to have dll-interface to be used by clients of class 'nsInputStream' */
95
#pragma warning(disable: 4275) /* non dll-interface class 'nsISupports' used as base for dll-interface class 'nsIRDFNode' */
96
#endif
97
98
#endif