/work/obj-fuzz/dist/include/nsInterfaceHashtable.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 nsInterfaceHashtable_h__ |
8 | | #define nsInterfaceHashtable_h__ |
9 | | |
10 | | #include "nsBaseHashtable.h" |
11 | | #include "nsHashKeys.h" |
12 | | #include "nsCOMPtr.h" |
13 | | |
14 | | /** |
15 | | * templated hashtable class maps keys to interface pointers. |
16 | | * See nsBaseHashtable for complete declaration. |
17 | | * @param KeyClass a wrapper-class for the hashtable key, see nsHashKeys.h |
18 | | * for a complete specification. |
19 | | * @param Interface the interface-type being wrapped |
20 | | * @see nsDataHashtable, nsClassHashtable |
21 | | */ |
22 | | template<class KeyClass, class Interface> |
23 | | class nsInterfaceHashtable |
24 | | : public nsBaseHashtable<KeyClass, nsCOMPtr<Interface>, Interface*> |
25 | | { |
26 | | public: |
27 | | typedef typename KeyClass::KeyType KeyType; |
28 | | typedef Interface* UserDataType; |
29 | | typedef nsBaseHashtable<KeyClass, nsCOMPtr<Interface>, Interface*> base_type; |
30 | | |
31 | 9 | nsInterfaceHashtable() {} Unexecuted instantiation: nsInterfaceHashtable<nsCStringHashKey, nsISupports>::nsInterfaceHashtable() nsInterfaceHashtable<nsCStringHashKey, mozilla::ModuleLoader>::nsInterfaceHashtable() Line | Count | Source | 31 | 3 | nsInterfaceHashtable() {} |
nsInterfaceHashtable<nsURIHashKey, nsIURI>::nsInterfaceHashtable() Line | Count | Source | 31 | 3 | nsInterfaceHashtable() {} |
Unexecuted instantiation: nsInterfaceHashtable<nsRefPtrHashKey<nsAtom>, nsIURI>::nsInterfaceHashtable() nsInterfaceHashtable<nsUint64HashKey, nsIRequestContext>::nsInterfaceHashtable() Line | Count | Source | 31 | 3 | nsInterfaceHashtable() {} |
Unexecuted instantiation: nsInterfaceHashtable<nsCStringHashKey, nsIWeakReference>::nsInterfaceHashtable() Unexecuted instantiation: nsInterfaceHashtable<nsCStringHashKey, nsIVariant>::nsInterfaceHashtable() Unexecuted instantiation: nsInterfaceHashtable<nsCharPtrHashKey, nsISupports>::nsInterfaceHashtable() Unexecuted instantiation: nsInterfaceHashtable<nsCStringHashKey, mozIStorageStatement>::nsInterfaceHashtable() Unexecuted instantiation: nsInterfaceHashtable<nsISupportsHashKey, nsIXPConnectWrappedJS>::nsInterfaceHashtable() Unexecuted instantiation: nsInterfaceHashtable<nsURIHashKey, nsIStreamListener>::nsInterfaceHashtable() Unexecuted instantiation: nsInterfaceHashtable<nsXBLPrototypeBinding::IIDHashKey, nsIContent>::nsInterfaceHashtable() Unexecuted instantiation: nsInterfaceHashtable<nsURIHashKey, nsIStorageStream>::nsInterfaceHashtable() Unexecuted instantiation: nsInterfaceHashtable<nsURIHashKey, nsIObjectInputStream>::nsInterfaceHashtable() Unexecuted instantiation: nsInterfaceHashtable<nsCStringHashKey, nsITimer>::nsInterfaceHashtable() Unexecuted instantiation: nsInterfaceHashtable<nsRefPtrHashKey<mozilla::URLAndReferrerInfo>, nsIMutationObserver>::nsInterfaceHashtable() Unexecuted instantiation: nsInterfaceHashtable<nsStringHashKey, nsIURI>::nsInterfaceHashtable() Unexecuted instantiation: nsInterfaceHashtable<nsPtrHashKey<_GtkWidget>, nsIWeakReference>::nsInterfaceHashtable() Unexecuted instantiation: nsInterfaceHashtable<nsStringHashKey, mozIDOMWindowProxy>::nsInterfaceHashtable() Unexecuted instantiation: nsInterfaceHashtable<nsPtrHashKey<nsAtom const>, nsITabParent>::nsInterfaceHashtable() Unexecuted instantiation: nsInterfaceHashtable<nsCStringHashKey, mozIStorageAsyncStatement>::nsInterfaceHashtable() Unexecuted instantiation: nsInterfaceHashtable<nsCStringHashKey, nsIUrlClassifierHashCompleter>::nsInterfaceHashtable() |
32 | | explicit nsInterfaceHashtable(uint32_t aInitLength) |
33 | | : nsBaseHashtable<KeyClass, nsCOMPtr<Interface>, Interface*>(aInitLength) |
34 | 3 | { |
35 | 3 | } nsInterfaceHashtable<nsCStringHashKey, nsIFile>::nsInterfaceHashtable(unsigned int) Line | Count | Source | 34 | 3 | { | 35 | 3 | } |
Unexecuted instantiation: nsInterfaceHashtable<nsUint32HashKey, nsIChannel>::nsInterfaceHashtable(unsigned int) Unexecuted instantiation: nsInterfaceHashtable<nsUint32HashKey, nsIParentChannel>::nsInterfaceHashtable(unsigned int) Unexecuted instantiation: nsInterfaceHashtable<nsCStringHashKey, nsIControllerCommand>::nsInterfaceHashtable(unsigned int) Unexecuted instantiation: nsInterfaceHashtable<nsStringHashKey, nsISupports>::nsInterfaceHashtable(unsigned int) Unexecuted instantiation: nsInterfaceHashtable<nsCStringHashKey, nsIGSettingsCollection>::nsInterfaceHashtable(unsigned int) Unexecuted instantiation: nsInterfaceHashtable<nsUint32HashKey, TestHashtables::IFoo>::nsInterfaceHashtable(unsigned int) |
36 | | |
37 | | /** |
38 | | * @copydoc nsBaseHashtable::Get |
39 | | * @param aData This is an XPCOM getter, so aData is already_addrefed. |
40 | | * If the key doesn't exist, aData will be set to nullptr. |
41 | | */ |
42 | | bool Get(KeyType aKey, UserDataType* aData) const; |
43 | | |
44 | | /** |
45 | | * @copydoc nsBaseHashtable::Get |
46 | | */ |
47 | | already_AddRefed<Interface> Get(KeyType aKey) const; |
48 | | |
49 | | /** |
50 | | * Gets a weak reference to the hashtable entry. |
51 | | * @param aFound If not nullptr, will be set to true if the entry is found, |
52 | | * to false otherwise. |
53 | | * @return The entry, or nullptr if not found. Do not release this pointer! |
54 | | */ |
55 | | Interface* GetWeak(KeyType aKey, bool* aFound = nullptr) const; |
56 | | |
57 | | /** |
58 | | * Allows inserting a value into the hashtable, moving its owning reference |
59 | | * count into the hashtable, avoiding an AddRef. |
60 | | */ |
61 | | void Put(KeyType aKey, already_AddRefed<Interface>&& aData) |
62 | | { |
63 | | if (!Put(aKey, std::move(aData), mozilla::fallible)) { |
64 | | NS_ABORT_OOM(this->mTable.EntrySize() * this->mTable.EntryCount()); |
65 | | } |
66 | | } |
67 | | |
68 | | MOZ_MUST_USE bool Put(KeyType aKey, already_AddRefed<Interface>&& aData, |
69 | | const mozilla::fallible_t&); |
70 | | using base_type::Put; |
71 | | |
72 | | /** |
73 | | * Remove the entry associated with aKey (if any), optionally _moving_ its |
74 | | * current value into *aData, thereby avoiding calls to AddRef and Release. |
75 | | * Return true if found. |
76 | | * @param aKey the key to remove from the hashtable |
77 | | * @param aData where to move the value (if non-null). If an entry is not |
78 | | * found it will be set to nullptr. |
79 | | * @return true if an entry for aKey was found (and removed) |
80 | | */ |
81 | | inline bool Remove(KeyType aKey, Interface** aData = nullptr); |
82 | | }; |
83 | | |
84 | | template<typename K, typename T> |
85 | | inline void |
86 | | ImplCycleCollectionUnlink(nsInterfaceHashtable<K, T>& aField) |
87 | | { |
88 | | aField.Clear(); |
89 | | } |
90 | | |
91 | | template<typename K, typename T> |
92 | | inline void |
93 | | ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, |
94 | | const nsInterfaceHashtable<K, T>& aField, |
95 | | const char* aName, |
96 | | uint32_t aFlags = 0) |
97 | 0 | { |
98 | 0 | for (auto iter = aField.ConstIter(); !iter.Done(); iter.Next()) { |
99 | 0 | CycleCollectionNoteChild(aCallback, iter.UserData(), aName, aFlags); |
100 | 0 | } |
101 | 0 | } Unexecuted instantiation: void ImplCycleCollectionTraverse<nsStringHashKey, nsISupports>(nsCycleCollectionTraversalCallback&, nsInterfaceHashtable<nsStringHashKey, nsISupports> const&, char const*, unsigned int) Unexecuted instantiation: void ImplCycleCollectionTraverse<nsXBLPrototypeBinding::IIDHashKey, nsIContent>(nsCycleCollectionTraversalCallback&, nsInterfaceHashtable<nsXBLPrototypeBinding::IIDHashKey, nsIContent> const&, char const*, unsigned int) |
102 | | |
103 | | // |
104 | | // nsInterfaceHashtable definitions |
105 | | // |
106 | | |
107 | | template<class KeyClass, class Interface> |
108 | | bool |
109 | | nsInterfaceHashtable<KeyClass, Interface>::Get(KeyType aKey, |
110 | | UserDataType* aInterface) const |
111 | 0 | { |
112 | 0 | typename base_type::EntryType* ent = this->GetEntry(aKey); |
113 | 0 |
|
114 | 0 | if (ent) { |
115 | 0 | if (aInterface) { |
116 | 0 | *aInterface = ent->mData; |
117 | 0 |
|
118 | 0 | NS_IF_ADDREF(*aInterface); |
119 | 0 | } |
120 | 0 |
|
121 | 0 | return true; |
122 | 0 | } |
123 | 0 |
|
124 | 0 | // if the key doesn't exist, set *aInterface to null |
125 | 0 | // so that it is a valid XPCOM getter |
126 | 0 | if (aInterface) { |
127 | 0 | *aInterface = nullptr; |
128 | 0 | } |
129 | 0 |
|
130 | 0 | return false; |
131 | 0 | } Unexecuted instantiation: nsInterfaceHashtable<nsURIHashKey, nsIURI>::Get(nsIURI*, nsIURI**) const Unexecuted instantiation: nsInterfaceHashtable<nsUint32HashKey, nsIChannel>::Get(unsigned int const&, nsIChannel**) const Unexecuted instantiation: nsInterfaceHashtable<nsUint32HashKey, nsIParentChannel>::Get(unsigned int const&, nsIParentChannel**) const Unexecuted instantiation: nsInterfaceHashtable<nsUint64HashKey, nsIRequestContext>::Get(unsigned long const&, nsIRequestContext**) const Unexecuted instantiation: nsInterfaceHashtable<nsCStringHashKey, nsIWeakReference>::Get(nsTSubstring<char> const&, nsIWeakReference**) const Unexecuted instantiation: nsInterfaceHashtable<nsCStringHashKey, nsIControllerCommand>::Get(nsTSubstring<char> const&, nsIControllerCommand**) const Unexecuted instantiation: nsInterfaceHashtable<nsCStringHashKey, mozIStorageStatement>::Get(nsTSubstring<char> const&, mozIStorageStatement**) const Unexecuted instantiation: nsInterfaceHashtable<nsURIHashKey, nsIStorageStream>::Get(nsIURI*, nsIStorageStream**) const Unexecuted instantiation: nsInterfaceHashtable<nsStringHashKey, nsISupports>::Get(nsTSubstring<char16_t> const&, nsISupports**) const Unexecuted instantiation: nsInterfaceHashtable<nsPtrHashKey<nsAtom const>, nsITabParent>::Get(nsAtom const*, nsITabParent**) const Unexecuted instantiation: nsInterfaceHashtable<nsCStringHashKey, mozIStorageAsyncStatement>::Get(nsTSubstring<char> const&, mozIStorageAsyncStatement**) const Unexecuted instantiation: nsInterfaceHashtable<nsCStringHashKey, nsIUrlClassifierHashCompleter>::Get(nsTSubstring<char> const&, nsIUrlClassifierHashCompleter**) const Unexecuted instantiation: nsInterfaceHashtable<nsUint32HashKey, TestHashtables::IFoo>::Get(unsigned int const&, TestHashtables::IFoo**) const |
132 | | |
133 | | template<class KeyClass, class Interface> |
134 | | already_AddRefed<Interface> |
135 | | nsInterfaceHashtable<KeyClass, Interface>::Get(KeyType aKey) const |
136 | 61 | { |
137 | 61 | typename base_type::EntryType* ent = this->GetEntry(aKey); |
138 | 61 | if (!ent) { |
139 | 40 | return nullptr; |
140 | 40 | } |
141 | 21 | |
142 | 21 | nsCOMPtr<Interface> copy = ent->mData; |
143 | 21 | return copy.forget(); |
144 | 21 | } nsInterfaceHashtable<nsCStringHashKey, nsIFile>::Get(nsTSubstring<char> const&) const Line | Count | Source | 136 | 60 | { | 137 | 60 | typename base_type::EntryType* ent = this->GetEntry(aKey); | 138 | 60 | if (!ent) { | 139 | 39 | return nullptr; | 140 | 39 | } | 141 | 21 | | 142 | 21 | nsCOMPtr<Interface> copy = ent->mData; | 143 | 21 | return copy.forget(); | 144 | 21 | } |
nsInterfaceHashtable<nsCStringHashKey, mozilla::ModuleLoader>::Get(nsTSubstring<char> const&) const Line | Count | Source | 136 | 1 | { | 137 | 1 | typename base_type::EntryType* ent = this->GetEntry(aKey); | 138 | 1 | if (!ent) { | 139 | 1 | return nullptr; | 140 | 1 | } | 141 | 0 | | 142 | 0 | nsCOMPtr<Interface> copy = ent->mData; | 143 | 0 | return copy.forget(); | 144 | 0 | } |
Unexecuted instantiation: nsInterfaceHashtable<nsRefPtrHashKey<nsAtom>, nsIURI>::Get(nsAtom*) const Unexecuted instantiation: nsInterfaceHashtable<nsStringHashKey, nsIURI>::Get(nsTSubstring<char16_t> const&) const Unexecuted instantiation: nsInterfaceHashtable<nsCStringHashKey, nsIGSettingsCollection>::Get(nsTSubstring<char> const&) const |
145 | | |
146 | | template<class KeyClass, class Interface> |
147 | | Interface* |
148 | | nsInterfaceHashtable<KeyClass, Interface>::GetWeak(KeyType aKey, |
149 | | bool* aFound) const |
150 | 0 | { |
151 | 0 | typename base_type::EntryType* ent = this->GetEntry(aKey); |
152 | 0 |
|
153 | 0 | if (ent) { |
154 | 0 | if (aFound) { |
155 | 0 | *aFound = true; |
156 | 0 | } |
157 | 0 |
|
158 | 0 | return ent->mData; |
159 | 0 | } |
160 | 0 |
|
161 | 0 | // Key does not exist, return nullptr and set aFound to false |
162 | 0 | if (aFound) { |
163 | 0 | *aFound = false; |
164 | 0 | } |
165 | 0 | return nullptr; |
166 | 0 | } Unexecuted instantiation: nsInterfaceHashtable<nsCStringHashKey, nsISupports>::GetWeak(nsTSubstring<char> const&, bool*) const Unexecuted instantiation: nsInterfaceHashtable<nsStringHashKey, nsISupports>::GetWeak(nsTSubstring<char16_t> const&, bool*) const Unexecuted instantiation: nsInterfaceHashtable<nsISupportsHashKey, nsIXPConnectWrappedJS>::GetWeak(nsISupports*, bool*) const Unexecuted instantiation: nsInterfaceHashtable<nsURIHashKey, nsIStreamListener>::GetWeak(nsIURI*, bool*) const Unexecuted instantiation: nsInterfaceHashtable<nsXBLPrototypeBinding::IIDHashKey, nsIContent>::GetWeak(nsID const&, bool*) const Unexecuted instantiation: nsInterfaceHashtable<nsRefPtrHashKey<mozilla::URLAndReferrerInfo>, nsIMutationObserver>::GetWeak(mozilla::URLAndReferrerInfo*, bool*) const Unexecuted instantiation: nsInterfaceHashtable<nsStringHashKey, nsIURI>::GetWeak(nsTSubstring<char16_t> const&, bool*) const Unexecuted instantiation: nsInterfaceHashtable<nsStringHashKey, mozIDOMWindowProxy>::GetWeak(nsTSubstring<char16_t> const&, bool*) const |
167 | | |
168 | | template<class KeyClass, class Interface> |
169 | | bool |
170 | | nsInterfaceHashtable<KeyClass, Interface>::Put(KeyType aKey, |
171 | | already_AddRefed<Interface>&& aValue, |
172 | | const mozilla::fallible_t&) |
173 | | { |
174 | | typename base_type::EntryType* ent = this->PutEntry(aKey); |
175 | | if (!ent) { |
176 | | return false; |
177 | | } |
178 | | |
179 | | ent->mData = aValue; |
180 | | return true; |
181 | | } |
182 | | |
183 | | template<class KeyClass, class Interface> |
184 | | bool |
185 | | nsInterfaceHashtable<KeyClass, Interface>::Remove(KeyType aKey, |
186 | | Interface** aData) |
187 | 0 | { |
188 | 0 | typename base_type::EntryType* ent = this->GetEntry(aKey); |
189 | 0 |
|
190 | 0 | if (ent) { |
191 | 0 | if (aData) { |
192 | 0 | ent->mData.forget(aData); |
193 | 0 | } |
194 | 0 | this->RemoveEntry(ent); |
195 | 0 | return true; |
196 | 0 | } |
197 | 0 |
|
198 | 0 | if (aData) { |
199 | 0 | *aData = nullptr; |
200 | 0 | } |
201 | 0 | return false; |
202 | 0 | } Unexecuted instantiation: nsInterfaceHashtable<nsCStringHashKey, nsIFile>::Remove(nsTSubstring<char> const&, nsIFile**) Unexecuted instantiation: nsInterfaceHashtable<nsCStringHashKey, nsISupports>::Remove(nsTSubstring<char> const&, nsISupports**) Unexecuted instantiation: nsInterfaceHashtable<nsRefPtrHashKey<nsAtom>, nsIURI>::Remove(nsAtom*, nsIURI**) Unexecuted instantiation: nsInterfaceHashtable<nsUint32HashKey, nsIChannel>::Remove(unsigned int const&, nsIChannel**) Unexecuted instantiation: nsInterfaceHashtable<nsUint32HashKey, nsIParentChannel>::Remove(unsigned int const&, nsIParentChannel**) Unexecuted instantiation: nsInterfaceHashtable<nsUint64HashKey, nsIRequestContext>::Remove(unsigned long const&, nsIRequestContext**) Unexecuted instantiation: nsInterfaceHashtable<nsCStringHashKey, nsIWeakReference>::Remove(nsTSubstring<char> const&, nsIWeakReference**) Unexecuted instantiation: nsInterfaceHashtable<nsCStringHashKey, nsIControllerCommand>::Remove(nsTSubstring<char> const&, nsIControllerCommand**) Unexecuted instantiation: nsInterfaceHashtable<nsISupportsHashKey, nsIXPConnectWrappedJS>::Remove(nsISupports*, nsIXPConnectWrappedJS**) Unexecuted instantiation: nsInterfaceHashtable<nsURIHashKey, nsIStreamListener>::Remove(nsIURI*, nsIStreamListener**) Unexecuted instantiation: nsInterfaceHashtable<nsURIHashKey, nsIObjectInputStream>::Remove(nsIURI*, nsIObjectInputStream**) Unexecuted instantiation: nsInterfaceHashtable<nsURIHashKey, nsIStorageStream>::Remove(nsIURI*, nsIStorageStream**) Unexecuted instantiation: nsInterfaceHashtable<nsCStringHashKey, nsITimer>::Remove(nsTSubstring<char> const&, nsITimer**) Unexecuted instantiation: nsInterfaceHashtable<nsStringHashKey, nsISupports>::Remove(nsTSubstring<char16_t> const&, nsISupports**) Unexecuted instantiation: nsInterfaceHashtable<nsStringHashKey, nsIURI>::Remove(nsTSubstring<char16_t> const&, nsIURI**) Unexecuted instantiation: nsInterfaceHashtable<nsStringHashKey, mozIDOMWindowProxy>::Remove(nsTSubstring<char16_t> const&, mozIDOMWindowProxy**) Unexecuted instantiation: nsInterfaceHashtable<nsCStringHashKey, nsIUrlClassifierHashCompleter>::Remove(nsTSubstring<char> const&, nsIUrlClassifierHashCompleter**) |
203 | | |
204 | | #endif // nsInterfaceHashtable_h__ |