/work/obj-fuzz/dist/include/xpcObjectHelper.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* vim: set ts=8 sts=4 et sw=4 tw=99: */ |
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 xpcObjectHelper_h |
8 | | #define xpcObjectHelper_h |
9 | | |
10 | | // Including 'windows.h' will #define GetClassInfo to something else. |
11 | | #ifdef XP_WIN |
12 | | #ifdef GetClassInfo |
13 | | #undef GetClassInfo |
14 | | #endif |
15 | | #endif |
16 | | |
17 | | #include "mozilla/Attributes.h" |
18 | | #include <stdint.h> |
19 | | #include "nsCOMPtr.h" |
20 | | #include "nsIClassInfo.h" |
21 | | #include "nsISupports.h" |
22 | | #include "nsIXPCScriptable.h" |
23 | | #include "nsWrapperCache.h" |
24 | | |
25 | | class xpcObjectHelper |
26 | | { |
27 | | public: |
28 | | explicit xpcObjectHelper(nsISupports* aObject, nsWrapperCache* aCache = nullptr) |
29 | | : mObject(aObject) |
30 | | , mCache(aCache) |
31 | | { |
32 | | if (!mCache && aObject) { |
33 | | CallQueryInterface(aObject, &mCache); |
34 | | } |
35 | | } |
36 | | |
37 | | nsISupports* Object() |
38 | | { |
39 | | return mObject; |
40 | | } |
41 | | |
42 | | nsIClassInfo* GetClassInfo() |
43 | | { |
44 | | if (!mClassInfo) { |
45 | | mClassInfo = do_QueryInterface(mObject); |
46 | | } |
47 | | return mClassInfo; |
48 | | } |
49 | | |
50 | | // We assert that we can reach an nsIXPCScriptable somehow. |
51 | | uint32_t GetScriptableFlags() |
52 | 0 | { |
53 | 0 | nsCOMPtr<nsIXPCScriptable> sinfo = do_QueryInterface(mObject); |
54 | 0 |
|
55 | 0 | // We should have something by now. |
56 | 0 | MOZ_ASSERT(sinfo); |
57 | 0 |
|
58 | 0 | // Grab the flags. |
59 | 0 | return sinfo->GetScriptableFlags(); |
60 | 0 | } |
61 | | |
62 | | nsWrapperCache* GetWrapperCache() |
63 | | { |
64 | | return mCache; |
65 | | } |
66 | | |
67 | | private: |
68 | | xpcObjectHelper(xpcObjectHelper& aOther) = delete; |
69 | | |
70 | | nsISupports* MOZ_UNSAFE_REF("xpcObjectHelper has been specifically optimized " |
71 | | "to avoid unnecessary AddRefs and Releases. " |
72 | | "(see bug 565742)") mObject; |
73 | | nsWrapperCache* mCache; |
74 | | nsCOMPtr<nsIClassInfo> mClassInfo; |
75 | | }; |
76 | | |
77 | | #endif |