Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/xpcom/base/nsCOMPtr.cpp
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
#include "nsCOMPtr.h"
8
9
nsresult
10
nsQueryInterface::operator()(const nsIID& aIID, void** aAnswer) const
11
27.6M
{
12
27.6M
  nsresult status;
13
27.6M
  if (mRawPtr) {
14
27.6M
    status = mRawPtr->QueryInterface(aIID, aAnswer);
15
27.6M
  } else {
16
23
    status = NS_ERROR_NULL_POINTER;
17
23
  }
18
27.6M
19
27.6M
  return status;
20
27.6M
}
21
22
nsresult
23
nsQueryInterfaceWithError::operator()(const nsIID& aIID, void** aAnswer) const
24
1.13M
{
25
1.13M
  nsresult status;
26
1.13M
  if (mRawPtr) {
27
1.13M
    status = mRawPtr->QueryInterface(aIID, aAnswer);
28
1.13M
  } else {
29
0
    status = NS_ERROR_NULL_POINTER;
30
0
  }
31
1.13M
32
1.13M
  if (mErrorPtr) {
33
1.13M
    *mErrorPtr = status;
34
1.13M
  }
35
1.13M
  return status;
36
1.13M
}
37
38
void
39
nsCOMPtr_base::assign_with_AddRef(nsISupports* aRawPtr)
40
41.4M
{
41
41.4M
  if (aRawPtr) {
42
10.5M
    NSCAP_ADDREF(this, aRawPtr);
43
10.5M
  }
44
41.4M
  assign_assuming_AddRef(aRawPtr);
45
41.4M
}
46
47
void
48
nsCOMPtr_base::assign_from_qi(const nsQueryInterface aQI, const nsIID& aIID)
49
27.6M
{
50
27.6M
  void* newRawPtr;
51
27.6M
  if (NS_FAILED(aQI(aIID, &newRawPtr))) {
52
16.2M
    newRawPtr = nullptr;
53
16.2M
  }
54
27.6M
  assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
55
27.6M
}
56
57
void
58
nsCOMPtr_base::assign_from_qi_with_error(const nsQueryInterfaceWithError& aQI,
59
                                         const nsIID& aIID)
60
1.13M
{
61
1.13M
  void* newRawPtr;
62
1.13M
  if (NS_FAILED(aQI(aIID, &newRawPtr))) {
63
14
    newRawPtr = nullptr;
64
14
  }
65
1.13M
  assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
66
1.13M
}
67
68
void
69
nsCOMPtr_base::assign_from_gs_cid(const nsGetServiceByCID aGS,
70
                                  const nsIID& aIID)
71
6
{
72
6
  void* newRawPtr;
73
6
  if (NS_FAILED(aGS(aIID, &newRawPtr))) {
74
0
    newRawPtr = nullptr;
75
0
  }
76
6
  assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
77
6
}
78
79
void
80
nsCOMPtr_base::assign_from_gs_cid_with_error(
81
    const nsGetServiceByCIDWithError& aGS, const nsIID& aIID)
82
0
{
83
0
  void* newRawPtr;
84
0
  if (NS_FAILED(aGS(aIID, &newRawPtr))) {
85
0
    newRawPtr = nullptr;
86
0
  }
87
0
  assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
88
0
}
89
90
void
91
nsCOMPtr_base::assign_from_gs_contractid(const nsGetServiceByContractID aGS,
92
                                         const nsIID& aIID)
93
9.59k
{
94
9.59k
  void* newRawPtr;
95
9.59k
  if (NS_FAILED(aGS(aIID, &newRawPtr))) {
96
0
    newRawPtr = nullptr;
97
0
  }
98
9.59k
  assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
99
9.59k
}
100
101
void
102
nsCOMPtr_base::assign_from_gs_contractid_with_error(
103
    const nsGetServiceByContractIDWithError& aGS, const nsIID& aIID)
104
55
{
105
55
  void* newRawPtr;
106
55
  if (NS_FAILED(aGS(aIID, &newRawPtr))) {
107
0
    newRawPtr = nullptr;
108
0
  }
109
55
  assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
110
55
}
111
112
void
113
nsCOMPtr_base::assign_from_query_referent(
114
    const nsQueryReferent& aQueryReferent, const nsIID& aIID)
115
585
{
116
585
  void* newRawPtr;
117
585
  if (NS_FAILED(aQueryReferent(aIID, &newRawPtr))) {
118
585
    newRawPtr = nullptr;
119
585
  }
120
585
  assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
121
585
}
122
123
void
124
nsCOMPtr_base::assign_from_helper(const nsCOMPtr_helper& aHelper,
125
                                  const nsIID& aIID)
126
296k
{
127
296k
  void* newRawPtr;
128
296k
  if (NS_FAILED(aHelper(aIID, &newRawPtr))) {
129
0
    newRawPtr = nullptr;
130
0
  }
131
296k
  assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
132
296k
}
133
134
void**
135
nsCOMPtr_base::begin_assignment()
136
20.8M
{
137
20.8M
  assign_assuming_AddRef(nullptr);
138
20.8M
  return reinterpret_cast<void**>(&mRawPtr);
139
20.8M
}