Coverage Report

Created: 2018-09-25 14:53

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