/src/mozilla-central/xpcom/reflect/xptinfo/xptinfo.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 https://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "xptinfo.h" |
8 | | #include "nsISupports.h" |
9 | | #include "mozilla/dom/DOMJSClass.h" |
10 | | #include "mozilla/ArrayUtils.h" |
11 | | |
12 | | #include "jsfriendapi.h" |
13 | | |
14 | | using namespace mozilla; |
15 | | using namespace mozilla::dom; |
16 | | using namespace xpt::detail; |
17 | | |
18 | | |
19 | | //////////////////////////////////// |
20 | | // Constant Lookup Helper Methods // |
21 | | //////////////////////////////////// |
22 | | |
23 | | |
24 | | bool |
25 | | nsXPTInterfaceInfo::HasAncestor(const nsIID& aIID) const |
26 | 30 | { |
27 | 64 | for (const auto* info = this; info; info = info->GetParent()) { |
28 | 64 | if (info->IID() == aIID) { |
29 | 30 | return true; |
30 | 30 | } |
31 | 64 | } |
32 | 30 | return false; |
33 | 30 | } |
34 | | |
35 | | const nsXPTConstantInfo& |
36 | | nsXPTInterfaceInfo::Constant(uint16_t aIndex) const |
37 | 50 | { |
38 | 50 | MOZ_ASSERT(aIndex < ConstantCount()); |
39 | 50 | |
40 | 50 | if (const nsXPTInterfaceInfo* pi = GetParent()) { |
41 | 50 | if (aIndex < pi->ConstantCount()) { |
42 | 0 | return pi->Constant(aIndex); |
43 | 0 | } |
44 | 50 | aIndex -= pi->ConstantCount(); |
45 | 50 | } |
46 | 50 | |
47 | 50 | return xpt::detail::GetConstant(mConsts + aIndex); |
48 | 50 | } |
49 | | |
50 | | const nsXPTMethodInfo& |
51 | | nsXPTInterfaceInfo::Method(uint16_t aIndex) const |
52 | 17.8M | { |
53 | 17.8M | MOZ_ASSERT(aIndex < MethodCount()); |
54 | 17.8M | |
55 | 17.8M | if (const nsXPTInterfaceInfo* pi = GetParent()) { |
56 | 17.8M | if (aIndex < pi->MethodCount()) { |
57 | 6.49M | return pi->Method(aIndex); |
58 | 6.49M | } |
59 | 11.3M | aIndex -= pi->MethodCount(); |
60 | 11.3M | } |
61 | 17.8M | |
62 | 17.8M | return xpt::detail::GetMethod(mMethods + aIndex); |
63 | 17.8M | } |
64 | | |
65 | | |
66 | | //////////////////////////////////////////////// |
67 | | // nsIInterfaceInfo backcompat implementation // |
68 | | //////////////////////////////////////////////// |
69 | | |
70 | | nsresult |
71 | | nsXPTInterfaceInfo::GetName(char** aName) const |
72 | 0 | { |
73 | 0 | *aName = moz_xstrdup(Name()); |
74 | 0 | return NS_OK; |
75 | 0 | } |
76 | | |
77 | | nsresult |
78 | | nsXPTInterfaceInfo::IsScriptable(bool* aRes) const |
79 | 30 | { |
80 | 30 | *aRes = IsScriptable(); |
81 | 30 | return NS_OK; |
82 | 30 | } |
83 | | |
84 | | nsresult |
85 | | nsXPTInterfaceInfo::IsBuiltinClass(bool* aRes) const |
86 | 3 | { |
87 | 3 | *aRes = IsBuiltinClass(); |
88 | 3 | return NS_OK; |
89 | 3 | } |
90 | | |
91 | | nsresult |
92 | | nsXPTInterfaceInfo::GetParent(const nsXPTInterfaceInfo** aParent) const |
93 | 0 | { |
94 | 0 | *aParent = GetParent(); |
95 | 0 | return NS_OK; |
96 | 0 | } |
97 | | |
98 | | nsresult |
99 | | nsXPTInterfaceInfo::GetMethodCount(uint16_t* aMethodCount) const |
100 | 30 | { |
101 | 30 | *aMethodCount = MethodCount(); |
102 | 30 | return NS_OK; |
103 | 30 | } |
104 | | |
105 | | nsresult |
106 | | nsXPTInterfaceInfo::GetConstantCount(uint16_t* aConstantCount) const |
107 | 27 | { |
108 | 27 | *aConstantCount = ConstantCount(); |
109 | 27 | return NS_OK; |
110 | 27 | } |
111 | | |
112 | | nsresult |
113 | | nsXPTInterfaceInfo::GetMethodInfo(uint16_t aIndex, const nsXPTMethodInfo** aInfo) const |
114 | 11.3M | { |
115 | 11.3M | *aInfo = aIndex < MethodCount() ? &Method(aIndex) : nullptr; |
116 | 11.3M | return *aInfo ? NS_OK : NS_ERROR_FAILURE; |
117 | 11.3M | } |
118 | | |
119 | | nsresult |
120 | | nsXPTInterfaceInfo::GetConstant(uint16_t aIndex, |
121 | | JS::MutableHandleValue aConstant, |
122 | | char** aName) const |
123 | 25 | { |
124 | 25 | if (aIndex < ConstantCount()) { |
125 | 25 | aConstant.set(Constant(aIndex).JSValue()); |
126 | 25 | *aName = moz_xstrdup(Constant(aIndex).Name()); |
127 | 25 | return NS_OK; |
128 | 25 | } |
129 | 0 | return NS_ERROR_FAILURE; |
130 | 0 | } |
131 | | |
132 | | nsresult |
133 | | nsXPTInterfaceInfo::IsIID(const nsIID* aIID, bool* aIs) const |
134 | 0 | { |
135 | 0 | *aIs = mIID == *aIID; |
136 | 0 | return NS_OK; |
137 | 0 | } |
138 | | |
139 | | nsresult |
140 | | nsXPTInterfaceInfo::GetNameShared(const char** aName) const |
141 | 27 | { |
142 | 27 | *aName = Name(); |
143 | 27 | return NS_OK; |
144 | 27 | } |
145 | | |
146 | | nsresult |
147 | | nsXPTInterfaceInfo::GetIIDShared(const nsIID** aIID) const |
148 | 8.11M | { |
149 | 8.11M | *aIID = &IID(); |
150 | 8.11M | return NS_OK; |
151 | 8.11M | } |
152 | | |
153 | | nsresult |
154 | | nsXPTInterfaceInfo::IsFunction(bool* aRetval) const |
155 | 1.62M | { |
156 | 1.62M | *aRetval = IsFunction(); |
157 | 1.62M | return NS_OK; |
158 | 1.62M | } |
159 | | |
160 | | nsresult |
161 | | nsXPTInterfaceInfo::HasAncestor(const nsIID* aIID, bool* aRetval) const |
162 | 0 | { |
163 | 0 | *aRetval = HasAncestor(*aIID); |
164 | 0 | return NS_OK; |
165 | 0 | } |
166 | | |
167 | | nsresult |
168 | | nsXPTInterfaceInfo::IsMainProcessScriptableOnly(bool* aRetval) const |
169 | 27 | { |
170 | 27 | *aRetval = IsMainProcessScriptableOnly(); |
171 | 27 | return NS_OK; |
172 | 27 | } |
173 | | |
174 | | //////////////////////////////////// |
175 | | // nsXPTMethodInfo symbol helpers // |
176 | | //////////////////////////////////// |
177 | | |
178 | | void |
179 | | nsXPTMethodInfo::GetSymbolDescription(JSContext* aCx, nsACString& aID) const |
180 | 0 | { |
181 | 0 | JS::RootedSymbol symbol(aCx, GetSymbol(aCx)); |
182 | 0 | JSString* desc = JS::GetSymbolDescription(symbol); |
183 | 0 | MOZ_ASSERT(JS_StringHasLatin1Chars(desc)); |
184 | 0 |
|
185 | 0 | JS::AutoAssertNoGC nogc(aCx); |
186 | 0 | size_t length; |
187 | 0 | const JS::Latin1Char* chars = JS_GetLatin1StringCharsAndLength( |
188 | 0 | aCx, nogc, desc, &length); |
189 | 0 |
|
190 | 0 | aID.AssignASCII(reinterpret_cast<const char*>(chars), length); |
191 | 0 | } |