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