/work/obj-fuzz/dom/bindings/WidevineCDMManifestBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM WidevineCDMManifest.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "AtomList.h" |
4 | | #include "WidevineCDMManifestBinding.h" |
5 | | #include "mozilla/OwningNonNull.h" |
6 | | #include "mozilla/dom/BindingUtils.h" |
7 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
8 | | #include "mozilla/dom/ScriptSettings.h" |
9 | | #include "mozilla/dom/SimpleGlobalObject.h" |
10 | | |
11 | | namespace mozilla { |
12 | | namespace dom { |
13 | | |
14 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
15 | | using namespace mozilla::dom::binding_detail; |
16 | | |
17 | | |
18 | | |
19 | | WidevineCDMManifest::WidevineCDMManifest() |
20 | 0 | { |
21 | 0 | // Safe to pass a null context if we pass a null value |
22 | 0 | Init(nullptr, JS::NullHandleValue); |
23 | 0 | } |
24 | | |
25 | | |
26 | | |
27 | | bool |
28 | | WidevineCDMManifest::InitIds(JSContext* cx, WidevineCDMManifestAtoms* atomsCache) |
29 | 0 | { |
30 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
31 | 0 |
|
32 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
33 | 0 | // uninitialized. |
34 | 0 | if (!atomsCache->x_cdm_module_versions_id.init(cx, "x-cdm-module-versions") || |
35 | 0 | !atomsCache->x_cdm_interface_versions_id.init(cx, "x-cdm-interface-versions") || |
36 | 0 | !atomsCache->x_cdm_host_versions_id.init(cx, "x-cdm-host-versions") || |
37 | 0 | !atomsCache->x_cdm_codecs_id.init(cx, "x-cdm-codecs") || |
38 | 0 | !atomsCache->version_id.init(cx, "version") || |
39 | 0 | !atomsCache->name_id.init(cx, "name") || |
40 | 0 | !atomsCache->description_id.init(cx, "description")) { |
41 | 0 | return false; |
42 | 0 | } |
43 | 0 | return true; |
44 | 0 | } |
45 | | |
46 | | bool |
47 | | WidevineCDMManifest::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
48 | 0 | { |
49 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
50 | 0 | // Since in that case we will not have to do any property gets |
51 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
52 | 0 | // checkers by static analysis tools |
53 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
54 | 0 | WidevineCDMManifestAtoms* atomsCache = nullptr; |
55 | 0 | if (cx) { |
56 | 0 | atomsCache = GetAtomCache<WidevineCDMManifestAtoms>(cx); |
57 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
58 | 0 | return false; |
59 | 0 | } |
60 | 0 | } |
61 | 0 | |
62 | 0 | if (!IsConvertibleToDictionary(val)) { |
63 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
64 | 0 | } |
65 | 0 | |
66 | 0 | bool isNull = val.isNullOrUndefined(); |
67 | 0 | // We only need these if !isNull, in which case we have |cx|. |
68 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
69 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
70 | 0 | if (!isNull) { |
71 | 0 | MOZ_ASSERT(cx); |
72 | 0 | object.emplace(cx, &val.toObject()); |
73 | 0 | temp.emplace(cx); |
74 | 0 | } |
75 | 0 | if (!isNull) { |
76 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->description_id, temp.ptr())) { |
77 | 0 | return false; |
78 | 0 | } |
79 | 0 | } |
80 | 0 | if (!isNull && !temp->isUndefined()) { |
81 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mDescription)) { |
82 | 0 | return false; |
83 | 0 | } |
84 | 0 | mIsAnyMemberPresent = true; |
85 | 0 | } else if (cx) { |
86 | 0 | // Don't error out if we have no cx. In that |
87 | 0 | // situation the caller is default-constructing us and we'll |
88 | 0 | // just assume they know what they're doing. |
89 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
90 | 0 | "'description' member of WidevineCDMManifest"); |
91 | 0 | } |
92 | 0 | |
93 | 0 | if (!isNull) { |
94 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->name_id, temp.ptr())) { |
95 | 0 | return false; |
96 | 0 | } |
97 | 0 | } |
98 | 0 | if (!isNull && !temp->isUndefined()) { |
99 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mName)) { |
100 | 0 | return false; |
101 | 0 | } |
102 | 0 | mIsAnyMemberPresent = true; |
103 | 0 | } else if (cx) { |
104 | 0 | // Don't error out if we have no cx. In that |
105 | 0 | // situation the caller is default-constructing us and we'll |
106 | 0 | // just assume they know what they're doing. |
107 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
108 | 0 | "'name' member of WidevineCDMManifest"); |
109 | 0 | } |
110 | 0 | |
111 | 0 | if (!isNull) { |
112 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->version_id, temp.ptr())) { |
113 | 0 | return false; |
114 | 0 | } |
115 | 0 | } |
116 | 0 | if (!isNull && !temp->isUndefined()) { |
117 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mVersion)) { |
118 | 0 | return false; |
119 | 0 | } |
120 | 0 | mIsAnyMemberPresent = true; |
121 | 0 | } else if (cx) { |
122 | 0 | // Don't error out if we have no cx. In that |
123 | 0 | // situation the caller is default-constructing us and we'll |
124 | 0 | // just assume they know what they're doing. |
125 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
126 | 0 | "'version' member of WidevineCDMManifest"); |
127 | 0 | } |
128 | 0 | |
129 | 0 | if (!isNull) { |
130 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->x_cdm_codecs_id, temp.ptr())) { |
131 | 0 | return false; |
132 | 0 | } |
133 | 0 | } |
134 | 0 | if (!isNull && !temp->isUndefined()) { |
135 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mX_cdm_codecs)) { |
136 | 0 | return false; |
137 | 0 | } |
138 | 0 | mIsAnyMemberPresent = true; |
139 | 0 | } else if (cx) { |
140 | 0 | // Don't error out if we have no cx. In that |
141 | 0 | // situation the caller is default-constructing us and we'll |
142 | 0 | // just assume they know what they're doing. |
143 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
144 | 0 | "'x-cdm-codecs' member of WidevineCDMManifest"); |
145 | 0 | } |
146 | 0 | |
147 | 0 | if (!isNull) { |
148 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->x_cdm_host_versions_id, temp.ptr())) { |
149 | 0 | return false; |
150 | 0 | } |
151 | 0 | } |
152 | 0 | if (!isNull && !temp->isUndefined()) { |
153 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mX_cdm_host_versions)) { |
154 | 0 | return false; |
155 | 0 | } |
156 | 0 | mIsAnyMemberPresent = true; |
157 | 0 | } else if (cx) { |
158 | 0 | // Don't error out if we have no cx. In that |
159 | 0 | // situation the caller is default-constructing us and we'll |
160 | 0 | // just assume they know what they're doing. |
161 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
162 | 0 | "'x-cdm-host-versions' member of WidevineCDMManifest"); |
163 | 0 | } |
164 | 0 | |
165 | 0 | if (!isNull) { |
166 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->x_cdm_interface_versions_id, temp.ptr())) { |
167 | 0 | return false; |
168 | 0 | } |
169 | 0 | } |
170 | 0 | if (!isNull && !temp->isUndefined()) { |
171 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mX_cdm_interface_versions)) { |
172 | 0 | return false; |
173 | 0 | } |
174 | 0 | mIsAnyMemberPresent = true; |
175 | 0 | } else if (cx) { |
176 | 0 | // Don't error out if we have no cx. In that |
177 | 0 | // situation the caller is default-constructing us and we'll |
178 | 0 | // just assume they know what they're doing. |
179 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
180 | 0 | "'x-cdm-interface-versions' member of WidevineCDMManifest"); |
181 | 0 | } |
182 | 0 | |
183 | 0 | if (!isNull) { |
184 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->x_cdm_module_versions_id, temp.ptr())) { |
185 | 0 | return false; |
186 | 0 | } |
187 | 0 | } |
188 | 0 | if (!isNull && !temp->isUndefined()) { |
189 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mX_cdm_module_versions)) { |
190 | 0 | return false; |
191 | 0 | } |
192 | 0 | mIsAnyMemberPresent = true; |
193 | 0 | } else if (cx) { |
194 | 0 | // Don't error out if we have no cx. In that |
195 | 0 | // situation the caller is default-constructing us and we'll |
196 | 0 | // just assume they know what they're doing. |
197 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
198 | 0 | "'x-cdm-module-versions' member of WidevineCDMManifest"); |
199 | 0 | } |
200 | 0 | return true; |
201 | 0 | } |
202 | | |
203 | | bool |
204 | | WidevineCDMManifest::Init(const nsAString& aJSON) |
205 | 0 | { |
206 | 0 | AutoJSAPI jsapi; |
207 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
208 | 0 | if (!cleanGlobal) { |
209 | 0 | return false; |
210 | 0 | } |
211 | 0 | if (!jsapi.Init(cleanGlobal)) { |
212 | 0 | return false; |
213 | 0 | } |
214 | 0 | JSContext* cx = jsapi.cx(); |
215 | 0 | JS::Rooted<JS::Value> json(cx); |
216 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
217 | 0 | NS_ENSURE_TRUE(ok, false); |
218 | 0 | return Init(cx, json); |
219 | 0 | } |
220 | | |
221 | | bool |
222 | | WidevineCDMManifest::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
223 | 0 | { |
224 | 0 | WidevineCDMManifestAtoms* atomsCache = GetAtomCache<WidevineCDMManifestAtoms>(cx); |
225 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
226 | 0 | return false; |
227 | 0 | } |
228 | 0 | |
229 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
230 | 0 | if (!obj) { |
231 | 0 | return false; |
232 | 0 | } |
233 | 0 | rval.set(JS::ObjectValue(*obj)); |
234 | 0 |
|
235 | 0 | do { |
236 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
237 | 0 | JS::Rooted<JS::Value> temp(cx); |
238 | 0 | nsString const & currentValue = mDescription; |
239 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
240 | 0 | return false; |
241 | 0 | } |
242 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->description_id, temp, JSPROP_ENUMERATE)) { |
243 | 0 | return false; |
244 | 0 | } |
245 | 0 | break; |
246 | 0 | } while(false); |
247 | 0 |
|
248 | 0 | do { |
249 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
250 | 0 | JS::Rooted<JS::Value> temp(cx); |
251 | 0 | nsString const & currentValue = mName; |
252 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
253 | 0 | return false; |
254 | 0 | } |
255 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->name_id, temp, JSPROP_ENUMERATE)) { |
256 | 0 | return false; |
257 | 0 | } |
258 | 0 | break; |
259 | 0 | } while(false); |
260 | 0 |
|
261 | 0 | do { |
262 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
263 | 0 | JS::Rooted<JS::Value> temp(cx); |
264 | 0 | nsString const & currentValue = mVersion; |
265 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
266 | 0 | return false; |
267 | 0 | } |
268 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->version_id, temp, JSPROP_ENUMERATE)) { |
269 | 0 | return false; |
270 | 0 | } |
271 | 0 | break; |
272 | 0 | } while(false); |
273 | 0 |
|
274 | 0 | do { |
275 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
276 | 0 | JS::Rooted<JS::Value> temp(cx); |
277 | 0 | nsString const & currentValue = mX_cdm_codecs; |
278 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
279 | 0 | return false; |
280 | 0 | } |
281 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->x_cdm_codecs_id, temp, JSPROP_ENUMERATE)) { |
282 | 0 | return false; |
283 | 0 | } |
284 | 0 | break; |
285 | 0 | } while(false); |
286 | 0 |
|
287 | 0 | do { |
288 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
289 | 0 | JS::Rooted<JS::Value> temp(cx); |
290 | 0 | nsString const & currentValue = mX_cdm_host_versions; |
291 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
292 | 0 | return false; |
293 | 0 | } |
294 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->x_cdm_host_versions_id, temp, JSPROP_ENUMERATE)) { |
295 | 0 | return false; |
296 | 0 | } |
297 | 0 | break; |
298 | 0 | } while(false); |
299 | 0 |
|
300 | 0 | do { |
301 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
302 | 0 | JS::Rooted<JS::Value> temp(cx); |
303 | 0 | nsString const & currentValue = mX_cdm_interface_versions; |
304 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
305 | 0 | return false; |
306 | 0 | } |
307 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->x_cdm_interface_versions_id, temp, JSPROP_ENUMERATE)) { |
308 | 0 | return false; |
309 | 0 | } |
310 | 0 | break; |
311 | 0 | } while(false); |
312 | 0 |
|
313 | 0 | do { |
314 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
315 | 0 | JS::Rooted<JS::Value> temp(cx); |
316 | 0 | nsString const & currentValue = mX_cdm_module_versions; |
317 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
318 | 0 | return false; |
319 | 0 | } |
320 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->x_cdm_module_versions_id, temp, JSPROP_ENUMERATE)) { |
321 | 0 | return false; |
322 | 0 | } |
323 | 0 | break; |
324 | 0 | } while(false); |
325 | 0 |
|
326 | 0 | return true; |
327 | 0 | } |
328 | | |
329 | | bool |
330 | | WidevineCDMManifest::ToJSON(nsAString& aJSON) const |
331 | 0 | { |
332 | 0 | AutoJSAPI jsapi; |
333 | 0 | jsapi.Init(); |
334 | 0 | JSContext *cx = jsapi.cx(); |
335 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
336 | 0 | // because we'll only be creating objects, in ways that have no |
337 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
338 | 0 | // which likewise guarantees no side-effects for the sorts of |
339 | 0 | // things we will pass it. |
340 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
341 | 0 | JS::Rooted<JS::Value> val(cx); |
342 | 0 | if (!ToObjectInternal(cx, &val)) { |
343 | 0 | return false; |
344 | 0 | } |
345 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
346 | 0 | return StringifyToJSON(cx, obj, aJSON); |
347 | 0 | } |
348 | | |
349 | | void |
350 | | WidevineCDMManifest::TraceDictionary(JSTracer* trc) |
351 | 0 | { |
352 | 0 | } |
353 | | |
354 | | WidevineCDMManifest& |
355 | | WidevineCDMManifest::operator=(const WidevineCDMManifest& aOther) |
356 | 0 | { |
357 | 0 | DictionaryBase::operator=(aOther); |
358 | 0 | mDescription = aOther.mDescription; |
359 | 0 | mName = aOther.mName; |
360 | 0 | mVersion = aOther.mVersion; |
361 | 0 | mX_cdm_codecs = aOther.mX_cdm_codecs; |
362 | 0 | mX_cdm_host_versions = aOther.mX_cdm_host_versions; |
363 | 0 | mX_cdm_interface_versions = aOther.mX_cdm_interface_versions; |
364 | 0 | mX_cdm_module_versions = aOther.mX_cdm_module_versions; |
365 | 0 | return *this; |
366 | 0 | } |
367 | | |
368 | | namespace binding_detail { |
369 | | } // namespace binding_detail |
370 | | |
371 | | |
372 | | } // namespace dom |
373 | | } // namespace mozilla |