Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/MediaCapabilitiesBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM MediaCapabilities.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "AtomList.h"
4
#include "MediaCapabilitiesBinding.h"
5
#include "WrapperFactory.h"
6
#include "jsapi.h"
7
#include "mozilla/OwningNonNull.h"
8
#include "mozilla/dom/BindingUtils.h"
9
#include "mozilla/dom/DOMJSClass.h"
10
#include "mozilla/dom/MediaCapabilities.h"
11
#include "mozilla/dom/NonRefcountedDOMObject.h"
12
#include "mozilla/dom/PrimitiveConversions.h"
13
#include "mozilla/dom/Promise.h"
14
#include "mozilla/dom/ScriptSettings.h"
15
#include "mozilla/dom/SimpleGlobalObject.h"
16
#include "mozilla/dom/ToJSValue.h"
17
#include "mozilla/dom/XrayExpandoClass.h"
18
19
namespace mozilla {
20
namespace dom {
21
22
namespace binding_detail {}; // Just to make sure it's known as a namespace
23
using namespace mozilla::dom::binding_detail;
24
25
26
namespace MediaDecodingTypeValues {
27
extern const EnumEntry strings[3] = {
28
  {"file", 4},
29
  {"media-source", 12},
30
  { nullptr, 0 }
31
};
32
} // namespace MediaDecodingTypeValues
33
34
bool
35
ToJSValue(JSContext* aCx, MediaDecodingType aArgument, JS::MutableHandle<JS::Value> aValue)
36
0
{
37
0
  MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(MediaDecodingTypeValues::strings));
38
0
  JSString* resultStr =
39
0
    JS_NewStringCopyN(aCx, MediaDecodingTypeValues::strings[uint32_t(aArgument)].value,
40
0
                      MediaDecodingTypeValues::strings[uint32_t(aArgument)].length);
41
0
  if (!resultStr) {
42
0
    return false;
43
0
  }
44
0
  aValue.setString(resultStr);
45
0
  return true;
46
0
}
47
48
49
namespace MediaEncodingTypeValues {
50
extern const EnumEntry strings[3] = {
51
  {"record", 6},
52
  {"transmission", 12},
53
  { nullptr, 0 }
54
};
55
} // namespace MediaEncodingTypeValues
56
57
bool
58
ToJSValue(JSContext* aCx, MediaEncodingType aArgument, JS::MutableHandle<JS::Value> aValue)
59
0
{
60
0
  MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(MediaEncodingTypeValues::strings));
61
0
  JSString* resultStr =
62
0
    JS_NewStringCopyN(aCx, MediaEncodingTypeValues::strings[uint32_t(aArgument)].value,
63
0
                      MediaEncodingTypeValues::strings[uint32_t(aArgument)].length);
64
0
  if (!resultStr) {
65
0
    return false;
66
0
  }
67
0
  aValue.setString(resultStr);
68
0
  return true;
69
0
}
70
71
72
73
AudioConfiguration::AudioConfiguration()
74
0
{
75
0
  // Safe to pass a null context if we pass a null value
76
0
  Init(nullptr, JS::NullHandleValue);
77
0
}
78
79
80
81
bool
82
AudioConfiguration::InitIds(JSContext* cx, AudioConfigurationAtoms* atomsCache)
83
0
{
84
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
85
0
86
0
  // Initialize these in reverse order so that any failure leaves the first one
87
0
  // uninitialized.
88
0
  if (!atomsCache->samplerate_id.init(cx, "samplerate") ||
89
0
      !atomsCache->contentType_id.init(cx, "contentType") ||
90
0
      !atomsCache->channels_id.init(cx, "channels") ||
91
0
      !atomsCache->bitrate_id.init(cx, "bitrate")) {
92
0
    return false;
93
0
  }
94
0
  return true;
95
0
}
96
97
bool
98
AudioConfiguration::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
99
0
{
100
0
  // Passing a null JSContext is OK only if we're initing from null,
101
0
  // Since in that case we will not have to do any property gets
102
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
103
0
  // checkers by static analysis tools
104
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
105
0
  AudioConfigurationAtoms* atomsCache = nullptr;
106
0
  if (cx) {
107
0
    atomsCache = GetAtomCache<AudioConfigurationAtoms>(cx);
108
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
109
0
      return false;
110
0
    }
111
0
  }
112
0
113
0
  if (!IsConvertibleToDictionary(val)) {
114
0
    return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
115
0
  }
116
0
117
0
  bool isNull = val.isNullOrUndefined();
118
0
  // We only need these if !isNull, in which case we have |cx|.
119
0
  Maybe<JS::Rooted<JSObject *> > object;
120
0
  Maybe<JS::Rooted<JS::Value> > temp;
121
0
  if (!isNull) {
122
0
    MOZ_ASSERT(cx);
123
0
    object.emplace(cx, &val.toObject());
124
0
    temp.emplace(cx);
125
0
  }
126
0
  if (!isNull) {
127
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->bitrate_id, temp.ptr())) {
128
0
      return false;
129
0
    }
130
0
  }
131
0
  if (!isNull && !temp->isUndefined()) {
132
0
    mBitrate.Construct();
133
0
    if (!ValueToPrimitive<uint64_t, eDefault>(cx, temp.ref(), &(mBitrate.Value()))) {
134
0
      return false;
135
0
    }
136
0
    mIsAnyMemberPresent = true;
137
0
  }
138
0
139
0
  if (!isNull) {
140
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->channels_id, temp.ptr())) {
141
0
      return false;
142
0
    }
143
0
  }
144
0
  if (!isNull && !temp->isUndefined()) {
145
0
    mChannels.Construct();
146
0
    if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mChannels.Value()))) {
147
0
      return false;
148
0
    }
149
0
    mIsAnyMemberPresent = true;
150
0
  }
151
0
152
0
  if (!isNull) {
153
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->contentType_id, temp.ptr())) {
154
0
      return false;
155
0
    }
156
0
  }
157
0
  if (!isNull && !temp->isUndefined()) {
158
0
    mContentType.Construct();
159
0
    if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mContentType.Value()))) {
160
0
      return false;
161
0
    }
162
0
    mIsAnyMemberPresent = true;
163
0
  }
164
0
165
0
  if (!isNull) {
166
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->samplerate_id, temp.ptr())) {
167
0
      return false;
168
0
    }
169
0
  }
170
0
  if (!isNull && !temp->isUndefined()) {
171
0
    mSamplerate.Construct();
172
0
    if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mSamplerate.Value()))) {
173
0
      return false;
174
0
    }
175
0
    mIsAnyMemberPresent = true;
176
0
  }
177
0
  return true;
178
0
}
179
180
bool
181
AudioConfiguration::Init(const nsAString& aJSON)
182
0
{
183
0
  AutoJSAPI jsapi;
184
0
  JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
185
0
  if (!cleanGlobal) {
186
0
    return false;
187
0
  }
188
0
  if (!jsapi.Init(cleanGlobal)) {
189
0
    return false;
190
0
  }
191
0
  JSContext* cx = jsapi.cx();
192
0
  JS::Rooted<JS::Value> json(cx);
193
0
  bool ok = ParseJSON(cx, aJSON, &json);
194
0
  NS_ENSURE_TRUE(ok, false);
195
0
  return Init(cx, json);
196
0
}
197
198
bool
199
AudioConfiguration::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
200
0
{
201
0
  AudioConfigurationAtoms* atomsCache = GetAtomCache<AudioConfigurationAtoms>(cx);
202
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
203
0
    return false;
204
0
  }
205
0
206
0
  JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
207
0
  if (!obj) {
208
0
    return false;
209
0
  }
210
0
  rval.set(JS::ObjectValue(*obj));
211
0
212
0
  if (mBitrate.WasPassed()) {
213
0
    do {
214
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
215
0
      JS::Rooted<JS::Value> temp(cx);
216
0
      uint64_t const & currentValue = mBitrate.InternalValue();
217
0
      temp.set(JS_NumberValue(double(currentValue)));
218
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->bitrate_id, temp, JSPROP_ENUMERATE)) {
219
0
        return false;
220
0
      }
221
0
      break;
222
0
    } while(false);
223
0
  }
224
0
225
0
  if (mChannels.WasPassed()) {
226
0
    do {
227
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
228
0
      JS::Rooted<JS::Value> temp(cx);
229
0
      nsString const & currentValue = mChannels.InternalValue();
230
0
      if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
231
0
        return false;
232
0
      }
233
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->channels_id, temp, JSPROP_ENUMERATE)) {
234
0
        return false;
235
0
      }
236
0
      break;
237
0
    } while(false);
238
0
  }
239
0
240
0
  if (mContentType.WasPassed()) {
241
0
    do {
242
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
243
0
      JS::Rooted<JS::Value> temp(cx);
244
0
      nsString const & currentValue = mContentType.InternalValue();
245
0
      if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
246
0
        return false;
247
0
      }
248
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->contentType_id, temp, JSPROP_ENUMERATE)) {
249
0
        return false;
250
0
      }
251
0
      break;
252
0
    } while(false);
253
0
  }
254
0
255
0
  if (mSamplerate.WasPassed()) {
256
0
    do {
257
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
258
0
      JS::Rooted<JS::Value> temp(cx);
259
0
      uint32_t const & currentValue = mSamplerate.InternalValue();
260
0
      temp.setNumber(currentValue);
261
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->samplerate_id, temp, JSPROP_ENUMERATE)) {
262
0
        return false;
263
0
      }
264
0
      break;
265
0
    } while(false);
266
0
  }
267
0
268
0
  return true;
269
0
}
270
271
bool
272
AudioConfiguration::ToJSON(nsAString& aJSON) const
273
0
{
274
0
  AutoJSAPI jsapi;
275
0
  jsapi.Init();
276
0
  JSContext *cx = jsapi.cx();
277
0
  // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
278
0
  // because we'll only be creating objects, in ways that have no
279
0
  // side-effects, followed by a call to JS::ToJSONMaybeSafely,
280
0
  // which likewise guarantees no side-effects for the sorts of
281
0
  // things we will pass it.
282
0
  JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal());
283
0
  JS::Rooted<JS::Value> val(cx);
284
0
  if (!ToObjectInternal(cx, &val)) {
285
0
    return false;
286
0
  }
287
0
  JS::Rooted<JSObject*> obj(cx, &val.toObject());
288
0
  return StringifyToJSON(cx, obj, aJSON);
289
0
}
290
291
void
292
AudioConfiguration::TraceDictionary(JSTracer* trc)
293
0
{
294
0
}
295
296
AudioConfiguration&
297
AudioConfiguration::operator=(const AudioConfiguration& aOther)
298
0
{
299
0
  DictionaryBase::operator=(aOther);
300
0
  mBitrate.Reset();
301
0
  if (aOther.mBitrate.WasPassed()) {
302
0
    mBitrate.Construct(aOther.mBitrate.Value());
303
0
  }
304
0
  mChannels.Reset();
305
0
  if (aOther.mChannels.WasPassed()) {
306
0
    mChannels.Construct(aOther.mChannels.Value());
307
0
  }
308
0
  mContentType.Reset();
309
0
  if (aOther.mContentType.WasPassed()) {
310
0
    mContentType.Construct(aOther.mContentType.Value());
311
0
  }
312
0
  mSamplerate.Reset();
313
0
  if (aOther.mSamplerate.WasPassed()) {
314
0
    mSamplerate.Construct(aOther.mSamplerate.Value());
315
0
  }
316
0
  return *this;
317
0
}
318
319
namespace binding_detail {
320
} // namespace binding_detail
321
322
323
324
VideoConfiguration::VideoConfiguration()
325
0
{
326
0
  // Safe to pass a null context if we pass a null value
327
0
  Init(nullptr, JS::NullHandleValue);
328
0
}
329
330
331
332
bool
333
VideoConfiguration::InitIds(JSContext* cx, VideoConfigurationAtoms* atomsCache)
334
0
{
335
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
336
0
337
0
  // Initialize these in reverse order so that any failure leaves the first one
338
0
  // uninitialized.
339
0
  if (!atomsCache->width_id.init(cx, "width") ||
340
0
      !atomsCache->height_id.init(cx, "height") ||
341
0
      !atomsCache->framerate_id.init(cx, "framerate") ||
342
0
      !atomsCache->contentType_id.init(cx, "contentType") ||
343
0
      !atomsCache->bitrate_id.init(cx, "bitrate")) {
344
0
    return false;
345
0
  }
346
0
  return true;
347
0
}
348
349
bool
350
VideoConfiguration::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
351
0
{
352
0
  // Passing a null JSContext is OK only if we're initing from null,
353
0
  // Since in that case we will not have to do any property gets
354
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
355
0
  // checkers by static analysis tools
356
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
357
0
  VideoConfigurationAtoms* atomsCache = nullptr;
358
0
  if (cx) {
359
0
    atomsCache = GetAtomCache<VideoConfigurationAtoms>(cx);
360
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
361
0
      return false;
362
0
    }
363
0
  }
364
0
365
0
  if (!IsConvertibleToDictionary(val)) {
366
0
    return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
367
0
  }
368
0
369
0
  bool isNull = val.isNullOrUndefined();
370
0
  // We only need these if !isNull, in which case we have |cx|.
371
0
  Maybe<JS::Rooted<JSObject *> > object;
372
0
  Maybe<JS::Rooted<JS::Value> > temp;
373
0
  if (!isNull) {
374
0
    MOZ_ASSERT(cx);
375
0
    object.emplace(cx, &val.toObject());
376
0
    temp.emplace(cx);
377
0
  }
378
0
  if (!isNull) {
379
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->bitrate_id, temp.ptr())) {
380
0
      return false;
381
0
    }
382
0
  }
383
0
  if (!isNull && !temp->isUndefined()) {
384
0
    mBitrate.Construct();
385
0
    if (!ValueToPrimitive<uint64_t, eDefault>(cx, temp.ref(), &(mBitrate.Value()))) {
386
0
      return false;
387
0
    }
388
0
    mIsAnyMemberPresent = true;
389
0
  }
390
0
391
0
  if (!isNull) {
392
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->contentType_id, temp.ptr())) {
393
0
      return false;
394
0
    }
395
0
  }
396
0
  if (!isNull && !temp->isUndefined()) {
397
0
    mContentType.Construct();
398
0
    if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mContentType.Value()))) {
399
0
      return false;
400
0
    }
401
0
    mIsAnyMemberPresent = true;
402
0
  }
403
0
404
0
  if (!isNull) {
405
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->framerate_id, temp.ptr())) {
406
0
      return false;
407
0
    }
408
0
  }
409
0
  if (!isNull && !temp->isUndefined()) {
410
0
    mFramerate.Construct();
411
0
    if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mFramerate.Value()))) {
412
0
      return false;
413
0
    }
414
0
    mIsAnyMemberPresent = true;
415
0
  }
416
0
417
0
  if (!isNull) {
418
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->height_id, temp.ptr())) {
419
0
      return false;
420
0
    }
421
0
  }
422
0
  if (!isNull && !temp->isUndefined()) {
423
0
    mHeight.Construct();
424
0
    if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mHeight.Value()))) {
425
0
      return false;
426
0
    }
427
0
    mIsAnyMemberPresent = true;
428
0
  }
429
0
430
0
  if (!isNull) {
431
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->width_id, temp.ptr())) {
432
0
      return false;
433
0
    }
434
0
  }
435
0
  if (!isNull && !temp->isUndefined()) {
436
0
    mWidth.Construct();
437
0
    if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mWidth.Value()))) {
438
0
      return false;
439
0
    }
440
0
    mIsAnyMemberPresent = true;
441
0
  }
442
0
  return true;
443
0
}
444
445
bool
446
VideoConfiguration::Init(const nsAString& aJSON)
447
0
{
448
0
  AutoJSAPI jsapi;
449
0
  JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
450
0
  if (!cleanGlobal) {
451
0
    return false;
452
0
  }
453
0
  if (!jsapi.Init(cleanGlobal)) {
454
0
    return false;
455
0
  }
456
0
  JSContext* cx = jsapi.cx();
457
0
  JS::Rooted<JS::Value> json(cx);
458
0
  bool ok = ParseJSON(cx, aJSON, &json);
459
0
  NS_ENSURE_TRUE(ok, false);
460
0
  return Init(cx, json);
461
0
}
462
463
bool
464
VideoConfiguration::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
465
0
{
466
0
  VideoConfigurationAtoms* atomsCache = GetAtomCache<VideoConfigurationAtoms>(cx);
467
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
468
0
    return false;
469
0
  }
470
0
471
0
  JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
472
0
  if (!obj) {
473
0
    return false;
474
0
  }
475
0
  rval.set(JS::ObjectValue(*obj));
476
0
477
0
  if (mBitrate.WasPassed()) {
478
0
    do {
479
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
480
0
      JS::Rooted<JS::Value> temp(cx);
481
0
      uint64_t const & currentValue = mBitrate.InternalValue();
482
0
      temp.set(JS_NumberValue(double(currentValue)));
483
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->bitrate_id, temp, JSPROP_ENUMERATE)) {
484
0
        return false;
485
0
      }
486
0
      break;
487
0
    } while(false);
488
0
  }
489
0
490
0
  if (mContentType.WasPassed()) {
491
0
    do {
492
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
493
0
      JS::Rooted<JS::Value> temp(cx);
494
0
      nsString const & currentValue = mContentType.InternalValue();
495
0
      if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
496
0
        return false;
497
0
      }
498
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->contentType_id, temp, JSPROP_ENUMERATE)) {
499
0
        return false;
500
0
      }
501
0
      break;
502
0
    } while(false);
503
0
  }
504
0
505
0
  if (mFramerate.WasPassed()) {
506
0
    do {
507
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
508
0
      JS::Rooted<JS::Value> temp(cx);
509
0
      nsString const & currentValue = mFramerate.InternalValue();
510
0
      if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
511
0
        return false;
512
0
      }
513
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->framerate_id, temp, JSPROP_ENUMERATE)) {
514
0
        return false;
515
0
      }
516
0
      break;
517
0
    } while(false);
518
0
  }
519
0
520
0
  if (mHeight.WasPassed()) {
521
0
    do {
522
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
523
0
      JS::Rooted<JS::Value> temp(cx);
524
0
      uint32_t const & currentValue = mHeight.InternalValue();
525
0
      temp.setNumber(currentValue);
526
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->height_id, temp, JSPROP_ENUMERATE)) {
527
0
        return false;
528
0
      }
529
0
      break;
530
0
    } while(false);
531
0
  }
532
0
533
0
  if (mWidth.WasPassed()) {
534
0
    do {
535
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
536
0
      JS::Rooted<JS::Value> temp(cx);
537
0
      uint32_t const & currentValue = mWidth.InternalValue();
538
0
      temp.setNumber(currentValue);
539
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->width_id, temp, JSPROP_ENUMERATE)) {
540
0
        return false;
541
0
      }
542
0
      break;
543
0
    } while(false);
544
0
  }
545
0
546
0
  return true;
547
0
}
548
549
bool
550
VideoConfiguration::ToJSON(nsAString& aJSON) const
551
0
{
552
0
  AutoJSAPI jsapi;
553
0
  jsapi.Init();
554
0
  JSContext *cx = jsapi.cx();
555
0
  // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
556
0
  // because we'll only be creating objects, in ways that have no
557
0
  // side-effects, followed by a call to JS::ToJSONMaybeSafely,
558
0
  // which likewise guarantees no side-effects for the sorts of
559
0
  // things we will pass it.
560
0
  JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal());
561
0
  JS::Rooted<JS::Value> val(cx);
562
0
  if (!ToObjectInternal(cx, &val)) {
563
0
    return false;
564
0
  }
565
0
  JS::Rooted<JSObject*> obj(cx, &val.toObject());
566
0
  return StringifyToJSON(cx, obj, aJSON);
567
0
}
568
569
void
570
VideoConfiguration::TraceDictionary(JSTracer* trc)
571
0
{
572
0
}
573
574
VideoConfiguration&
575
VideoConfiguration::operator=(const VideoConfiguration& aOther)
576
0
{
577
0
  DictionaryBase::operator=(aOther);
578
0
  mBitrate.Reset();
579
0
  if (aOther.mBitrate.WasPassed()) {
580
0
    mBitrate.Construct(aOther.mBitrate.Value());
581
0
  }
582
0
  mContentType.Reset();
583
0
  if (aOther.mContentType.WasPassed()) {
584
0
    mContentType.Construct(aOther.mContentType.Value());
585
0
  }
586
0
  mFramerate.Reset();
587
0
  if (aOther.mFramerate.WasPassed()) {
588
0
    mFramerate.Construct(aOther.mFramerate.Value());
589
0
  }
590
0
  mHeight.Reset();
591
0
  if (aOther.mHeight.WasPassed()) {
592
0
    mHeight.Construct(aOther.mHeight.Value());
593
0
  }
594
0
  mWidth.Reset();
595
0
  if (aOther.mWidth.WasPassed()) {
596
0
    mWidth.Construct(aOther.mWidth.Value());
597
0
  }
598
0
  return *this;
599
0
}
600
601
namespace binding_detail {
602
} // namespace binding_detail
603
604
605
606
MediaConfiguration::MediaConfiguration()
607
  : mAudio(FastDictionaryInitializer()),
608
    mVideo(FastDictionaryInitializer())
609
0
{
610
0
  // Safe to pass a null context if we pass a null value
611
0
  Init(nullptr, JS::NullHandleValue);
612
0
}
613
614
615
616
bool
617
MediaConfiguration::InitIds(JSContext* cx, MediaConfigurationAtoms* atomsCache)
618
0
{
619
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
620
0
621
0
  // Initialize these in reverse order so that any failure leaves the first one
622
0
  // uninitialized.
623
0
  if (!atomsCache->video_id.init(cx, "video") ||
624
0
      !atomsCache->audio_id.init(cx, "audio")) {
625
0
    return false;
626
0
  }
627
0
  return true;
628
0
}
629
630
bool
631
MediaConfiguration::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
632
0
{
633
0
  // Passing a null JSContext is OK only if we're initing from null,
634
0
  // Since in that case we will not have to do any property gets
635
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
636
0
  // checkers by static analysis tools
637
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
638
0
  MediaConfigurationAtoms* atomsCache = nullptr;
639
0
  if (cx) {
640
0
    atomsCache = GetAtomCache<MediaConfigurationAtoms>(cx);
641
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
642
0
      return false;
643
0
    }
644
0
  }
645
0
646
0
  if (!IsConvertibleToDictionary(val)) {
647
0
    return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
648
0
  }
649
0
650
0
  bool isNull = val.isNullOrUndefined();
651
0
  // We only need these if !isNull, in which case we have |cx|.
652
0
  Maybe<JS::Rooted<JSObject *> > object;
653
0
  Maybe<JS::Rooted<JS::Value> > temp;
654
0
  if (!isNull) {
655
0
    MOZ_ASSERT(cx);
656
0
    object.emplace(cx, &val.toObject());
657
0
    temp.emplace(cx);
658
0
  }
659
0
  if (!isNull) {
660
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->audio_id, temp.ptr())) {
661
0
      return false;
662
0
    }
663
0
  }
664
0
  if (!mAudio.Init(cx, (!isNull && !temp->isUndefined()) ? temp.ref() : JS::NullHandleValue,  "'audio' member of MediaConfiguration", passedToJSImpl)) {
665
0
    return false;
666
0
  }
667
0
  mIsAnyMemberPresent = true;
668
0
669
0
  if (!isNull) {
670
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->video_id, temp.ptr())) {
671
0
      return false;
672
0
    }
673
0
  }
674
0
  if (!mVideo.Init(cx, (!isNull && !temp->isUndefined()) ? temp.ref() : JS::NullHandleValue,  "'video' member of MediaConfiguration", passedToJSImpl)) {
675
0
    return false;
676
0
  }
677
0
  mIsAnyMemberPresent = true;
678
0
  return true;
679
0
}
680
681
bool
682
MediaConfiguration::Init(const nsAString& aJSON)
683
0
{
684
0
  AutoJSAPI jsapi;
685
0
  JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
686
0
  if (!cleanGlobal) {
687
0
    return false;
688
0
  }
689
0
  if (!jsapi.Init(cleanGlobal)) {
690
0
    return false;
691
0
  }
692
0
  JSContext* cx = jsapi.cx();
693
0
  JS::Rooted<JS::Value> json(cx);
694
0
  bool ok = ParseJSON(cx, aJSON, &json);
695
0
  NS_ENSURE_TRUE(ok, false);
696
0
  return Init(cx, json);
697
0
}
698
699
bool
700
MediaConfiguration::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
701
0
{
702
0
  MediaConfigurationAtoms* atomsCache = GetAtomCache<MediaConfigurationAtoms>(cx);
703
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
704
0
    return false;
705
0
  }
706
0
707
0
  JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
708
0
  if (!obj) {
709
0
    return false;
710
0
  }
711
0
  rval.set(JS::ObjectValue(*obj));
712
0
713
0
  do {
714
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
715
0
    JS::Rooted<JS::Value> temp(cx);
716
0
    AudioConfiguration const & currentValue = mAudio;
717
0
    if (!currentValue.ToObjectInternal(cx, &temp)) {
718
0
      return false;
719
0
    }
720
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->audio_id, temp, JSPROP_ENUMERATE)) {
721
0
      return false;
722
0
    }
723
0
    break;
724
0
  } while(false);
725
0
726
0
  do {
727
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
728
0
    JS::Rooted<JS::Value> temp(cx);
729
0
    VideoConfiguration const & currentValue = mVideo;
730
0
    if (!currentValue.ToObjectInternal(cx, &temp)) {
731
0
      return false;
732
0
    }
733
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->video_id, temp, JSPROP_ENUMERATE)) {
734
0
      return false;
735
0
    }
736
0
    break;
737
0
  } while(false);
738
0
739
0
  return true;
740
0
}
741
742
bool
743
MediaConfiguration::ToJSON(nsAString& aJSON) const
744
0
{
745
0
  AutoJSAPI jsapi;
746
0
  jsapi.Init();
747
0
  JSContext *cx = jsapi.cx();
748
0
  // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
749
0
  // because we'll only be creating objects, in ways that have no
750
0
  // side-effects, followed by a call to JS::ToJSONMaybeSafely,
751
0
  // which likewise guarantees no side-effects for the sorts of
752
0
  // things we will pass it.
753
0
  JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal());
754
0
  JS::Rooted<JS::Value> val(cx);
755
0
  if (!ToObjectInternal(cx, &val)) {
756
0
    return false;
757
0
  }
758
0
  JS::Rooted<JSObject*> obj(cx, &val.toObject());
759
0
  return StringifyToJSON(cx, obj, aJSON);
760
0
}
761
762
void
763
MediaConfiguration::TraceDictionary(JSTracer* trc)
764
0
{
765
0
}
766
767
MediaConfiguration&
768
MediaConfiguration::operator=(const MediaConfiguration& aOther)
769
0
{
770
0
  DictionaryBase::operator=(aOther);
771
0
  mAudio = aOther.mAudio;
772
0
  mVideo = aOther.mVideo;
773
0
  return *this;
774
0
}
775
776
namespace binding_detail {
777
} // namespace binding_detail
778
779
780
781
MediaDecodingConfiguration::MediaDecodingConfiguration()
782
  : MediaConfiguration(FastDictionaryInitializer())
783
0
{
784
0
  // Safe to pass a null context if we pass a null value
785
0
  Init(nullptr, JS::NullHandleValue);
786
0
}
787
788
789
790
bool
791
MediaDecodingConfiguration::InitIds(JSContext* cx, MediaDecodingConfigurationAtoms* atomsCache)
792
0
{
793
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
794
0
795
0
  // Initialize these in reverse order so that any failure leaves the first one
796
0
  // uninitialized.
797
0
  if (!atomsCache->type_id.init(cx, "type")) {
798
0
    return false;
799
0
  }
800
0
  return true;
801
0
}
802
803
bool
804
MediaDecodingConfiguration::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
805
0
{
806
0
  // Passing a null JSContext is OK only if we're initing from null,
807
0
  // Since in that case we will not have to do any property gets
808
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
809
0
  // checkers by static analysis tools
810
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
811
0
  MediaDecodingConfigurationAtoms* atomsCache = nullptr;
812
0
  if (cx) {
813
0
    atomsCache = GetAtomCache<MediaDecodingConfigurationAtoms>(cx);
814
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
815
0
      return false;
816
0
    }
817
0
  }
818
0
819
0
  // Per spec, we init the parent's members first
820
0
  if (!MediaConfiguration::Init(cx, val)) {
821
0
    return false;
822
0
  }
823
0
824
0
  bool isNull = val.isNullOrUndefined();
825
0
  // We only need these if !isNull, in which case we have |cx|.
826
0
  Maybe<JS::Rooted<JSObject *> > object;
827
0
  Maybe<JS::Rooted<JS::Value> > temp;
828
0
  if (!isNull) {
829
0
    MOZ_ASSERT(cx);
830
0
    object.emplace(cx, &val.toObject());
831
0
    temp.emplace(cx);
832
0
  }
833
0
  if (!isNull) {
834
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->type_id, temp.ptr())) {
835
0
      return false;
836
0
    }
837
0
  }
838
0
  if (!isNull && !temp->isUndefined()) {
839
0
    {
840
0
      int index;
841
0
      if (!FindEnumStringIndex<true>(cx, temp.ref(), MediaDecodingTypeValues::strings, "MediaDecodingType", "'type' member of MediaDecodingConfiguration", &index)) {
842
0
        return false;
843
0
      }
844
0
      MOZ_ASSERT(index >= 0);
845
0
      mType = static_cast<MediaDecodingType>(index);
846
0
    }
847
0
    mIsAnyMemberPresent = true;
848
0
  } else if (cx) {
849
0
    // Don't error out if we have no cx.  In that
850
0
    // situation the caller is default-constructing us and we'll
851
0
    // just assume they know what they're doing.
852
0
    return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER,
853
0
                             "'type' member of MediaDecodingConfiguration");
854
0
  }
855
0
  return true;
856
0
}
857
858
bool
859
MediaDecodingConfiguration::Init(const nsAString& aJSON)
860
0
{
861
0
  AutoJSAPI jsapi;
862
0
  JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
863
0
  if (!cleanGlobal) {
864
0
    return false;
865
0
  }
866
0
  if (!jsapi.Init(cleanGlobal)) {
867
0
    return false;
868
0
  }
869
0
  JSContext* cx = jsapi.cx();
870
0
  JS::Rooted<JS::Value> json(cx);
871
0
  bool ok = ParseJSON(cx, aJSON, &json);
872
0
  NS_ENSURE_TRUE(ok, false);
873
0
  return Init(cx, json);
874
0
}
875
876
bool
877
MediaDecodingConfiguration::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
878
0
{
879
0
  MediaDecodingConfigurationAtoms* atomsCache = GetAtomCache<MediaDecodingConfigurationAtoms>(cx);
880
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
881
0
    return false;
882
0
  }
883
0
884
0
  // Per spec, we define the parent's members first
885
0
  if (!MediaConfiguration::ToObjectInternal(cx, rval)) {
886
0
    return false;
887
0
  }
888
0
  JS::Rooted<JSObject*> obj(cx, &rval.toObject());
889
0
890
0
  do {
891
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
892
0
    JS::Rooted<JS::Value> temp(cx);
893
0
    MediaDecodingType const & currentValue = mType;
894
0
    if (!ToJSValue(cx, currentValue, &temp)) {
895
0
      return false;
896
0
    }
897
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->type_id, temp, JSPROP_ENUMERATE)) {
898
0
      return false;
899
0
    }
900
0
    break;
901
0
  } while(false);
902
0
903
0
  return true;
904
0
}
905
906
bool
907
MediaDecodingConfiguration::ToJSON(nsAString& aJSON) const
908
0
{
909
0
  AutoJSAPI jsapi;
910
0
  jsapi.Init();
911
0
  JSContext *cx = jsapi.cx();
912
0
  // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
913
0
  // because we'll only be creating objects, in ways that have no
914
0
  // side-effects, followed by a call to JS::ToJSONMaybeSafely,
915
0
  // which likewise guarantees no side-effects for the sorts of
916
0
  // things we will pass it.
917
0
  JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal());
918
0
  JS::Rooted<JS::Value> val(cx);
919
0
  if (!ToObjectInternal(cx, &val)) {
920
0
    return false;
921
0
  }
922
0
  JS::Rooted<JSObject*> obj(cx, &val.toObject());
923
0
  return StringifyToJSON(cx, obj, aJSON);
924
0
}
925
926
void
927
MediaDecodingConfiguration::TraceDictionary(JSTracer* trc)
928
0
{
929
0
  MediaConfiguration::TraceDictionary(trc);
930
0
}
931
932
MediaDecodingConfiguration&
933
MediaDecodingConfiguration::operator=(const MediaDecodingConfiguration& aOther)
934
0
{
935
0
  MediaConfiguration::operator=(aOther);
936
0
  mType = aOther.mType;
937
0
  return *this;
938
0
}
939
940
namespace binding_detail {
941
} // namespace binding_detail
942
943
944
945
MediaEncodingConfiguration::MediaEncodingConfiguration()
946
  : MediaConfiguration(FastDictionaryInitializer())
947
0
{
948
0
  // Safe to pass a null context if we pass a null value
949
0
  Init(nullptr, JS::NullHandleValue);
950
0
}
951
952
953
954
bool
955
MediaEncodingConfiguration::InitIds(JSContext* cx, MediaEncodingConfigurationAtoms* atomsCache)
956
0
{
957
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
958
0
959
0
  // Initialize these in reverse order so that any failure leaves the first one
960
0
  // uninitialized.
961
0
  if (!atomsCache->type_id.init(cx, "type")) {
962
0
    return false;
963
0
  }
964
0
  return true;
965
0
}
966
967
bool
968
MediaEncodingConfiguration::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
969
0
{
970
0
  // Passing a null JSContext is OK only if we're initing from null,
971
0
  // Since in that case we will not have to do any property gets
972
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
973
0
  // checkers by static analysis tools
974
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
975
0
  MediaEncodingConfigurationAtoms* atomsCache = nullptr;
976
0
  if (cx) {
977
0
    atomsCache = GetAtomCache<MediaEncodingConfigurationAtoms>(cx);
978
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
979
0
      return false;
980
0
    }
981
0
  }
982
0
983
0
  // Per spec, we init the parent's members first
984
0
  if (!MediaConfiguration::Init(cx, val)) {
985
0
    return false;
986
0
  }
987
0
988
0
  bool isNull = val.isNullOrUndefined();
989
0
  // We only need these if !isNull, in which case we have |cx|.
990
0
  Maybe<JS::Rooted<JSObject *> > object;
991
0
  Maybe<JS::Rooted<JS::Value> > temp;
992
0
  if (!isNull) {
993
0
    MOZ_ASSERT(cx);
994
0
    object.emplace(cx, &val.toObject());
995
0
    temp.emplace(cx);
996
0
  }
997
0
  if (!isNull) {
998
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->type_id, temp.ptr())) {
999
0
      return false;
1000
0
    }
1001
0
  }
1002
0
  if (!isNull && !temp->isUndefined()) {
1003
0
    {
1004
0
      int index;
1005
0
      if (!FindEnumStringIndex<true>(cx, temp.ref(), MediaEncodingTypeValues::strings, "MediaEncodingType", "'type' member of MediaEncodingConfiguration", &index)) {
1006
0
        return false;
1007
0
      }
1008
0
      MOZ_ASSERT(index >= 0);
1009
0
      mType = static_cast<MediaEncodingType>(index);
1010
0
    }
1011
0
    mIsAnyMemberPresent = true;
1012
0
  } else if (cx) {
1013
0
    // Don't error out if we have no cx.  In that
1014
0
    // situation the caller is default-constructing us and we'll
1015
0
    // just assume they know what they're doing.
1016
0
    return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER,
1017
0
                             "'type' member of MediaEncodingConfiguration");
1018
0
  }
1019
0
  return true;
1020
0
}
1021
1022
bool
1023
MediaEncodingConfiguration::Init(const nsAString& aJSON)
1024
0
{
1025
0
  AutoJSAPI jsapi;
1026
0
  JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
1027
0
  if (!cleanGlobal) {
1028
0
    return false;
1029
0
  }
1030
0
  if (!jsapi.Init(cleanGlobal)) {
1031
0
    return false;
1032
0
  }
1033
0
  JSContext* cx = jsapi.cx();
1034
0
  JS::Rooted<JS::Value> json(cx);
1035
0
  bool ok = ParseJSON(cx, aJSON, &json);
1036
0
  NS_ENSURE_TRUE(ok, false);
1037
0
  return Init(cx, json);
1038
0
}
1039
1040
bool
1041
MediaEncodingConfiguration::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
1042
0
{
1043
0
  MediaEncodingConfigurationAtoms* atomsCache = GetAtomCache<MediaEncodingConfigurationAtoms>(cx);
1044
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
1045
0
    return false;
1046
0
  }
1047
0
1048
0
  // Per spec, we define the parent's members first
1049
0
  if (!MediaConfiguration::ToObjectInternal(cx, rval)) {
1050
0
    return false;
1051
0
  }
1052
0
  JS::Rooted<JSObject*> obj(cx, &rval.toObject());
1053
0
1054
0
  do {
1055
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
1056
0
    JS::Rooted<JS::Value> temp(cx);
1057
0
    MediaEncodingType const & currentValue = mType;
1058
0
    if (!ToJSValue(cx, currentValue, &temp)) {
1059
0
      return false;
1060
0
    }
1061
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->type_id, temp, JSPROP_ENUMERATE)) {
1062
0
      return false;
1063
0
    }
1064
0
    break;
1065
0
  } while(false);
1066
0
1067
0
  return true;
1068
0
}
1069
1070
bool
1071
MediaEncodingConfiguration::ToJSON(nsAString& aJSON) const
1072
0
{
1073
0
  AutoJSAPI jsapi;
1074
0
  jsapi.Init();
1075
0
  JSContext *cx = jsapi.cx();
1076
0
  // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
1077
0
  // because we'll only be creating objects, in ways that have no
1078
0
  // side-effects, followed by a call to JS::ToJSONMaybeSafely,
1079
0
  // which likewise guarantees no side-effects for the sorts of
1080
0
  // things we will pass it.
1081
0
  JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal());
1082
0
  JS::Rooted<JS::Value> val(cx);
1083
0
  if (!ToObjectInternal(cx, &val)) {
1084
0
    return false;
1085
0
  }
1086
0
  JS::Rooted<JSObject*> obj(cx, &val.toObject());
1087
0
  return StringifyToJSON(cx, obj, aJSON);
1088
0
}
1089
1090
void
1091
MediaEncodingConfiguration::TraceDictionary(JSTracer* trc)
1092
0
{
1093
0
  MediaConfiguration::TraceDictionary(trc);
1094
0
}
1095
1096
MediaEncodingConfiguration&
1097
MediaEncodingConfiguration::operator=(const MediaEncodingConfiguration& aOther)
1098
0
{
1099
0
  MediaConfiguration::operator=(aOther);
1100
0
  mType = aOther.mType;
1101
0
  return *this;
1102
0
}
1103
1104
namespace binding_detail {
1105
} // namespace binding_detail
1106
1107
1108
namespace MediaCapabilities_Binding {
1109
1110
MOZ_CAN_RUN_SCRIPT static bool
1111
decodingInfo(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaCapabilities* self, const JSJitMethodCallArgs& args)
1112
0
{
1113
0
  AUTO_PROFILER_LABEL_FAST("MediaCapabilities.decodingInfo", DOM, cx);
1114
0
1115
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
1116
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "MediaCapabilities.decodingInfo");
1117
0
  }
1118
0
  binding_detail::FastMediaDecodingConfiguration arg0;
1119
0
  if (!arg0.Init(cx, args[0],  "Argument 1 of MediaCapabilities.decodingInfo", false)) {
1120
0
    return false;
1121
0
  }
1122
0
  FastErrorResult rv;
1123
0
  auto result(StrongOrRawPtr<Promise>(self->DecodingInfo(Constify(arg0), rv)));
1124
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1125
0
    return false;
1126
0
  }
1127
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1128
0
  static_assert(!IsPointer<decltype(result)>::value,
1129
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
1130
0
  if (!ToJSValue(cx, result, args.rval())) {
1131
0
    return false;
1132
0
  }
1133
0
  return true;
1134
0
}
1135
1136
MOZ_CAN_RUN_SCRIPT static bool
1137
decodingInfo_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaCapabilities* self, const JSJitMethodCallArgs& args)
1138
0
{
1139
0
  bool ok = decodingInfo(cx, obj, self, args);
1140
0
  if (ok) {
1141
0
    return true;
1142
0
  }
1143
0
  return ConvertExceptionToPromise(cx, args.rval());
1144
0
}
1145
1146
static const JSJitInfo decodingInfo_methodinfo = {
1147
  { (JSJitGetterOp)decodingInfo_promiseWrapper },
1148
  { prototypes::id::MediaCapabilities },
1149
  { PrototypeTraits<prototypes::id::MediaCapabilities>::Depth },
1150
  JSJitInfo::Method,
1151
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1152
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
1153
  false,  /* isInfallible. False in setters. */
1154
  false,  /* isMovable.  Not relevant for setters. */
1155
  false, /* isEliminatable.  Not relevant for setters. */
1156
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1157
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1158
  false,  /* isTypedMethod.  Only relevant for methods. */
1159
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1160
};
1161
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1162
static_assert(0 < 1, "There is no slot for us");
1163
1164
MOZ_CAN_RUN_SCRIPT static bool
1165
encodingInfo(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaCapabilities* self, const JSJitMethodCallArgs& args)
1166
0
{
1167
0
  AUTO_PROFILER_LABEL_FAST("MediaCapabilities.encodingInfo", DOM, cx);
1168
0
1169
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
1170
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "MediaCapabilities.encodingInfo");
1171
0
  }
1172
0
  binding_detail::FastMediaEncodingConfiguration arg0;
1173
0
  if (!arg0.Init(cx, args[0],  "Argument 1 of MediaCapabilities.encodingInfo", false)) {
1174
0
    return false;
1175
0
  }
1176
0
  FastErrorResult rv;
1177
0
  auto result(StrongOrRawPtr<Promise>(self->EncodingInfo(Constify(arg0), rv)));
1178
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1179
0
    return false;
1180
0
  }
1181
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1182
0
  static_assert(!IsPointer<decltype(result)>::value,
1183
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
1184
0
  if (!ToJSValue(cx, result, args.rval())) {
1185
0
    return false;
1186
0
  }
1187
0
  return true;
1188
0
}
1189
1190
MOZ_CAN_RUN_SCRIPT static bool
1191
encodingInfo_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaCapabilities* self, const JSJitMethodCallArgs& args)
1192
0
{
1193
0
  bool ok = encodingInfo(cx, obj, self, args);
1194
0
  if (ok) {
1195
0
    return true;
1196
0
  }
1197
0
  return ConvertExceptionToPromise(cx, args.rval());
1198
0
}
1199
1200
static const JSJitInfo encodingInfo_methodinfo = {
1201
  { (JSJitGetterOp)encodingInfo_promiseWrapper },
1202
  { prototypes::id::MediaCapabilities },
1203
  { PrototypeTraits<prototypes::id::MediaCapabilities>::Depth },
1204
  JSJitInfo::Method,
1205
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1206
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
1207
  false,  /* isInfallible. False in setters. */
1208
  false,  /* isMovable.  Not relevant for setters. */
1209
  false, /* isEliminatable.  Not relevant for setters. */
1210
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1211
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1212
  false,  /* isTypedMethod.  Only relevant for methods. */
1213
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1214
};
1215
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1216
static_assert(0 < 1, "There is no slot for us");
1217
1218
static bool
1219
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
1220
0
{
1221
0
  mozilla::dom::MediaCapabilities* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MediaCapabilities>(obj);
1222
0
  // We don't want to preserve if we don't have a wrapper, and we
1223
0
  // obviously can't preserve if we're not initialized.
1224
0
  if (self && self->GetWrapperPreserveColor()) {
1225
0
    PreserveWrapper(self);
1226
0
  }
1227
0
  return true;
1228
0
}
1229
1230
static void
1231
_finalize(js::FreeOp* fop, JSObject* obj)
1232
0
{
1233
0
  mozilla::dom::MediaCapabilities* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MediaCapabilities>(obj);
1234
0
  if (self) {
1235
0
    ClearWrapper(self, self, obj);
1236
0
    AddForDeferredFinalization<mozilla::dom::MediaCapabilities>(self);
1237
0
  }
1238
0
}
1239
1240
static size_t
1241
_objectMoved(JSObject* obj, JSObject* old)
1242
0
{
1243
0
  mozilla::dom::MediaCapabilities* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MediaCapabilities>(obj);
1244
0
  if (self) {
1245
0
    UpdateWrapper(self, self, obj, old);
1246
0
  }
1247
0
1248
0
  return 0;
1249
0
}
1250
1251
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
1252
#if defined(__clang__)
1253
#pragma clang diagnostic push
1254
#pragma clang diagnostic ignored "-Wmissing-braces"
1255
#endif
1256
static const JSFunctionSpec sMethods_specs[] = {
1257
  JS_FNSPEC("decodingInfo", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&decodingInfo_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
1258
  JS_FNSPEC("encodingInfo", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&encodingInfo_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
1259
  JS_FS_END
1260
};
1261
#if defined(__clang__)
1262
#pragma clang diagnostic pop
1263
#endif
1264
1265
1266
static const Prefable<const JSFunctionSpec> sMethods[] = {
1267
  { nullptr, &sMethods_specs[0] },
1268
  { nullptr, nullptr }
1269
};
1270
1271
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
1272
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
1273
static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
1274
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
1275
1276
1277
static uint16_t sNativeProperties_sortedPropertyIndices[2];
1278
static PropertyInfo sNativeProperties_propertyInfos[2];
1279
1280
static const NativePropertiesN<1> sNativeProperties = {
1281
  false, 0,
1282
  false, 0,
1283
  true,  0 /* sMethods */,
1284
  false, 0,
1285
  false, 0,
1286
  false, 0,
1287
  false, 0,
1288
  -1,
1289
  2,
1290
  sNativeProperties_sortedPropertyIndices,
1291
  {
1292
    { sMethods, &sNativeProperties_propertyInfos[0] }
1293
  }
1294
};
1295
static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
1296
    "We have a property info count that is oversized");
1297
1298
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
1299
  {
1300
    "Function",
1301
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
1302
    &sBoringInterfaceObjectClassClassOps,
1303
    JS_NULL_CLASS_SPEC,
1304
    JS_NULL_CLASS_EXT,
1305
    &sInterfaceObjectClassObjectOps
1306
  },
1307
  eInterface,
1308
  true,
1309
  prototypes::id::MediaCapabilities,
1310
  PrototypeTraits<prototypes::id::MediaCapabilities>::Depth,
1311
  sNativePropertyHooks,
1312
  "function MediaCapabilities() {\n    [native code]\n}",
1313
  JS::GetRealmFunctionPrototype
1314
};
1315
1316
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
1317
  {
1318
    "MediaCapabilitiesPrototype",
1319
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
1320
    JS_NULL_CLASS_OPS,
1321
    JS_NULL_CLASS_SPEC,
1322
    JS_NULL_CLASS_EXT,
1323
    JS_NULL_OBJECT_OPS
1324
  },
1325
  eInterfacePrototype,
1326
  false,
1327
  prototypes::id::MediaCapabilities,
1328
  PrototypeTraits<prototypes::id::MediaCapabilities>::Depth,
1329
  sNativePropertyHooks,
1330
  "[object MediaCapabilitiesPrototype]",
1331
  JS::GetRealmObjectPrototype
1332
};
1333
1334
bool
1335
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
1336
0
{
1337
0
  return mozilla::dom::MediaCapabilities::Enabled(aCx, aObj);
1338
0
}
1339
1340
static const js::ClassOps sClassOps = {
1341
  _addProperty, /* addProperty */
1342
  nullptr,               /* delProperty */
1343
  nullptr,               /* enumerate */
1344
  nullptr, /* newEnumerate */
1345
  nullptr, /* resolve */
1346
  nullptr, /* mayResolve */
1347
  _finalize, /* finalize */
1348
  nullptr, /* call */
1349
  nullptr,               /* hasInstance */
1350
  nullptr,               /* construct */
1351
  nullptr, /* trace */
1352
};
1353
1354
static const js::ClassExtension sClassExtension = {
1355
  nullptr, /* weakmapKeyDelegateOp */
1356
  _objectMoved /* objectMovedOp */
1357
};
1358
1359
static const DOMJSClass sClass = {
1360
  { "MediaCapabilities",
1361
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
1362
    &sClassOps,
1363
    JS_NULL_CLASS_SPEC,
1364
    &sClassExtension,
1365
    JS_NULL_OBJECT_OPS
1366
  },
1367
  { prototypes::id::MediaCapabilities, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
1368
  IsBaseOf<nsISupports, mozilla::dom::MediaCapabilities >::value,
1369
  sNativePropertyHooks,
1370
  FindAssociatedGlobalForNative<mozilla::dom::MediaCapabilities>::Get,
1371
  GetProtoObjectHandle,
1372
  GetCCParticipant<mozilla::dom::MediaCapabilities>::Get()
1373
};
1374
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
1375
              "Must have the right minimal number of reserved slots.");
1376
static_assert(1 >= 1,
1377
              "Must have enough reserved slots.");
1378
1379
const JSClass*
1380
GetJSClass()
1381
0
{
1382
0
  return sClass.ToJSClass();
1383
0
}
1384
1385
bool
1386
Wrap(JSContext* aCx, mozilla::dom::MediaCapabilities* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
1387
0
{
1388
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::MediaCapabilities>::value,
1389
0
                "Shouldn't have wrappercached things that are not refcounted.");
1390
0
  MOZ_ASSERT(static_cast<mozilla::dom::MediaCapabilities*>(aObject) ==
1391
0
             reinterpret_cast<mozilla::dom::MediaCapabilities*>(aObject),
1392
0
             "Multiple inheritance for mozilla::dom::MediaCapabilities is broken.");
1393
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
1394
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
1395
0
  MOZ_ASSERT(!aCache->GetWrapper(),
1396
0
             "You should probably not be using Wrap() directly; use "
1397
0
             "GetOrCreateDOMReflector instead");
1398
0
1399
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
1400
0
             "nsISupports must be on our primary inheritance chain");
1401
0
1402
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
1403
0
  if (!global) {
1404
0
    return false;
1405
0
  }
1406
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
1407
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
1408
0
1409
0
  // That might have ended up wrapping us already, due to the wonders
1410
0
  // of XBL.  Check for that, and bail out as needed.
1411
0
  aReflector.set(aCache->GetWrapper());
1412
0
  if (aReflector) {
1413
#ifdef DEBUG
1414
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
1415
#endif // DEBUG
1416
    return true;
1417
0
  }
1418
0
1419
0
  JSAutoRealm ar(aCx, global);
1420
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
1421
0
  if (!canonicalProto) {
1422
0
    return false;
1423
0
  }
1424
0
  JS::Rooted<JSObject*> proto(aCx);
1425
0
  if (aGivenProto) {
1426
0
    proto = aGivenProto;
1427
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
1428
0
    // coming in, we changed compartments to that of "parent" so may need
1429
0
    // to wrap the proto here.
1430
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
1431
0
      if (!JS_WrapObject(aCx, &proto)) {
1432
0
        return false;
1433
0
      }
1434
0
    }
1435
0
  } else {
1436
0
    proto = canonicalProto;
1437
0
  }
1438
0
1439
0
  BindingJSObjectCreator<mozilla::dom::MediaCapabilities> creator(aCx);
1440
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
1441
0
  if (!aReflector) {
1442
0
    return false;
1443
0
  }
1444
0
1445
0
  aCache->SetWrapper(aReflector);
1446
0
  creator.InitializationSucceeded();
1447
0
1448
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
1449
0
             aCache->GetWrapperPreserveColor() == aReflector);
1450
0
  // If proto != canonicalProto, we have to preserve our wrapper;
1451
0
  // otherwise we won't be able to properly recreate it later, since
1452
0
  // we won't know what proto to use.  Note that we don't check
1453
0
  // aGivenProto here, since it's entirely possible (and even
1454
0
  // somewhat common) to have a non-null aGivenProto which is the
1455
0
  // same as canonicalProto.
1456
0
  if (proto != canonicalProto) {
1457
0
    PreserveWrapper(aObject);
1458
0
  }
1459
0
1460
0
  return true;
1461
0
}
1462
1463
const NativePropertyHooks sNativePropertyHooks[] = { {
1464
  nullptr,
1465
  nullptr,
1466
  nullptr,
1467
  { sNativeProperties.Upcast(), nullptr },
1468
  prototypes::id::MediaCapabilities,
1469
  constructors::id::MediaCapabilities,
1470
  nullptr,
1471
  &DefaultXrayExpandoObjectClass
1472
} };
1473
1474
void
1475
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
1476
0
{
1477
0
  JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
1478
0
  if (!parentProto) {
1479
0
    return;
1480
0
  }
1481
0
1482
0
  JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
1483
0
  if (!constructorProto) {
1484
0
    return;
1485
0
  }
1486
0
1487
0
  static bool sIdsInited = false;
1488
0
  if (!sIdsInited && NS_IsMainThread()) {
1489
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
1490
0
      return;
1491
0
    }
1492
0
    sIdsInited = true;
1493
0
  }
1494
0
1495
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::MediaCapabilities);
1496
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::MediaCapabilities);
1497
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
1498
0
                              &sPrototypeClass.mBase, protoCache,
1499
0
                              nullptr,
1500
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
1501
0
                              interfaceCache,
1502
0
                              sNativeProperties.Upcast(),
1503
0
                              nullptr,
1504
0
                              "MediaCapabilities", aDefineOnGlobal,
1505
0
                              nullptr,
1506
0
                              false);
1507
0
}
1508
1509
JSObject*
1510
GetConstructorObject(JSContext* aCx)
1511
0
{
1512
0
  return GetConstructorObjectHandle(aCx);
1513
0
}
1514
1515
} // namespace MediaCapabilities_Binding
1516
1517
1518
1519
namespace MediaCapabilitiesInfo_Binding {
1520
1521
MOZ_CAN_RUN_SCRIPT static bool
1522
get_supported(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaCapabilitiesInfo* self, JSJitGetterCallArgs args)
1523
0
{
1524
0
  AUTO_PROFILER_LABEL_FAST("get MediaCapabilitiesInfo.supported", DOM, cx);
1525
0
1526
0
  bool result(self->Supported());
1527
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1528
0
  args.rval().setBoolean(result);
1529
0
  return true;
1530
0
}
1531
1532
static const JSJitInfo supported_getterinfo = {
1533
  { (JSJitGetterOp)get_supported },
1534
  { prototypes::id::MediaCapabilitiesInfo },
1535
  { PrototypeTraits<prototypes::id::MediaCapabilitiesInfo>::Depth },
1536
  JSJitInfo::Getter,
1537
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1538
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
1539
  true,  /* isInfallible. False in setters. */
1540
  false,  /* isMovable.  Not relevant for setters. */
1541
  false, /* isEliminatable.  Not relevant for setters. */
1542
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1543
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1544
  false,  /* isTypedMethod.  Only relevant for methods. */
1545
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1546
};
1547
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1548
static_assert(0 < 1, "There is no slot for us");
1549
1550
MOZ_CAN_RUN_SCRIPT static bool
1551
get_smooth(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaCapabilitiesInfo* self, JSJitGetterCallArgs args)
1552
0
{
1553
0
  AUTO_PROFILER_LABEL_FAST("get MediaCapabilitiesInfo.smooth", DOM, cx);
1554
0
1555
0
  bool result(self->Smooth());
1556
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1557
0
  args.rval().setBoolean(result);
1558
0
  return true;
1559
0
}
1560
1561
static const JSJitInfo smooth_getterinfo = {
1562
  { (JSJitGetterOp)get_smooth },
1563
  { prototypes::id::MediaCapabilitiesInfo },
1564
  { PrototypeTraits<prototypes::id::MediaCapabilitiesInfo>::Depth },
1565
  JSJitInfo::Getter,
1566
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1567
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
1568
  true,  /* isInfallible. False in setters. */
1569
  false,  /* isMovable.  Not relevant for setters. */
1570
  false, /* isEliminatable.  Not relevant for setters. */
1571
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1572
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1573
  false,  /* isTypedMethod.  Only relevant for methods. */
1574
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1575
};
1576
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1577
static_assert(0 < 1, "There is no slot for us");
1578
1579
MOZ_CAN_RUN_SCRIPT static bool
1580
get_powerEfficient(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaCapabilitiesInfo* self, JSJitGetterCallArgs args)
1581
0
{
1582
0
  AUTO_PROFILER_LABEL_FAST("get MediaCapabilitiesInfo.powerEfficient", DOM, cx);
1583
0
1584
0
  bool result(self->PowerEfficient());
1585
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1586
0
  args.rval().setBoolean(result);
1587
0
  return true;
1588
0
}
1589
1590
static const JSJitInfo powerEfficient_getterinfo = {
1591
  { (JSJitGetterOp)get_powerEfficient },
1592
  { prototypes::id::MediaCapabilitiesInfo },
1593
  { PrototypeTraits<prototypes::id::MediaCapabilitiesInfo>::Depth },
1594
  JSJitInfo::Getter,
1595
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1596
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
1597
  true,  /* isInfallible. False in setters. */
1598
  false,  /* isMovable.  Not relevant for setters. */
1599
  false, /* isEliminatable.  Not relevant for setters. */
1600
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1601
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1602
  false,  /* isTypedMethod.  Only relevant for methods. */
1603
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1604
};
1605
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1606
static_assert(0 < 1, "There is no slot for us");
1607
1608
static void
1609
_finalize(js::FreeOp* fop, JSObject* obj)
1610
0
{
1611
0
  mozilla::dom::MediaCapabilitiesInfo* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MediaCapabilitiesInfo>(obj);
1612
0
  if (self) {
1613
0
    AddForDeferredFinalization<mozilla::dom::MediaCapabilitiesInfo>(self);
1614
0
  }
1615
0
}
1616
1617
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
1618
#if defined(__clang__)
1619
#pragma clang diagnostic push
1620
#pragma clang diagnostic ignored "-Wmissing-braces"
1621
#endif
1622
static const JSPropertySpec sAttributes_specs[] = {
1623
  { "supported", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &supported_getterinfo, nullptr, nullptr },
1624
  { "smooth", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &smooth_getterinfo, nullptr, nullptr },
1625
  { "powerEfficient", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &powerEfficient_getterinfo, nullptr, nullptr },
1626
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
1627
};
1628
#if defined(__clang__)
1629
#pragma clang diagnostic pop
1630
#endif
1631
1632
1633
static const Prefable<const JSPropertySpec> sAttributes[] = {
1634
  { nullptr, &sAttributes_specs[0] },
1635
  { nullptr, nullptr }
1636
};
1637
1638
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
1639
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
1640
static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
1641
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
1642
1643
1644
static uint16_t sNativeProperties_sortedPropertyIndices[3];
1645
static PropertyInfo sNativeProperties_propertyInfos[3];
1646
1647
static const NativePropertiesN<1> sNativeProperties = {
1648
  false, 0,
1649
  false, 0,
1650
  false, 0,
1651
  true,  0 /* sAttributes */,
1652
  false, 0,
1653
  false, 0,
1654
  false, 0,
1655
  -1,
1656
  3,
1657
  sNativeProperties_sortedPropertyIndices,
1658
  {
1659
    { sAttributes, &sNativeProperties_propertyInfos[0] }
1660
  }
1661
};
1662
static_assert(3 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
1663
    "We have a property info count that is oversized");
1664
1665
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
1666
  {
1667
    "Function",
1668
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
1669
    &sBoringInterfaceObjectClassClassOps,
1670
    JS_NULL_CLASS_SPEC,
1671
    JS_NULL_CLASS_EXT,
1672
    &sInterfaceObjectClassObjectOps
1673
  },
1674
  eInterface,
1675
  true,
1676
  prototypes::id::MediaCapabilitiesInfo,
1677
  PrototypeTraits<prototypes::id::MediaCapabilitiesInfo>::Depth,
1678
  sNativePropertyHooks,
1679
  "function MediaCapabilitiesInfo() {\n    [native code]\n}",
1680
  JS::GetRealmFunctionPrototype
1681
};
1682
1683
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
1684
  {
1685
    "MediaCapabilitiesInfoPrototype",
1686
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
1687
    JS_NULL_CLASS_OPS,
1688
    JS_NULL_CLASS_SPEC,
1689
    JS_NULL_CLASS_EXT,
1690
    JS_NULL_OBJECT_OPS
1691
  },
1692
  eInterfacePrototype,
1693
  false,
1694
  prototypes::id::MediaCapabilitiesInfo,
1695
  PrototypeTraits<prototypes::id::MediaCapabilitiesInfo>::Depth,
1696
  sNativePropertyHooks,
1697
  "[object MediaCapabilitiesInfoPrototype]",
1698
  JS::GetRealmObjectPrototype
1699
};
1700
1701
bool
1702
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
1703
0
{
1704
0
  return mozilla::dom::MediaCapabilities::Enabled(aCx, aObj);
1705
0
}
1706
1707
static const js::ClassOps sClassOps = {
1708
  nullptr, /* addProperty */
1709
  nullptr,               /* delProperty */
1710
  nullptr,               /* enumerate */
1711
  nullptr, /* newEnumerate */
1712
  nullptr, /* resolve */
1713
  nullptr, /* mayResolve */
1714
  _finalize, /* finalize */
1715
  nullptr, /* call */
1716
  nullptr,               /* hasInstance */
1717
  nullptr,               /* construct */
1718
  nullptr, /* trace */
1719
};
1720
1721
static const js::ClassExtension sClassExtension = {
1722
  nullptr, /* weakmapKeyDelegateOp */
1723
  nullptr /* objectMovedOp */
1724
};
1725
1726
static const DOMJSClass sClass = {
1727
  { "MediaCapabilitiesInfo",
1728
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
1729
    &sClassOps,
1730
    JS_NULL_CLASS_SPEC,
1731
    &sClassExtension,
1732
    JS_NULL_OBJECT_OPS
1733
  },
1734
  { prototypes::id::MediaCapabilitiesInfo, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
1735
  IsBaseOf<nsISupports, mozilla::dom::MediaCapabilitiesInfo >::value,
1736
  sNativePropertyHooks,
1737
  FindAssociatedGlobalForNative<mozilla::dom::MediaCapabilitiesInfo>::Get,
1738
  GetProtoObjectHandle,
1739
  GetCCParticipant<mozilla::dom::MediaCapabilitiesInfo>::Get()
1740
};
1741
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
1742
              "Must have the right minimal number of reserved slots.");
1743
static_assert(1 >= 1,
1744
              "Must have enough reserved slots.");
1745
1746
const JSClass*
1747
GetJSClass()
1748
0
{
1749
0
  return sClass.ToJSClass();
1750
0
}
1751
1752
bool
1753
Wrap(JSContext* aCx, mozilla::dom::MediaCapabilitiesInfo* aObject, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
1754
0
{
1755
0
  MOZ_ASSERT(static_cast<mozilla::dom::MediaCapabilitiesInfo*>(aObject) ==
1756
0
             reinterpret_cast<mozilla::dom::MediaCapabilitiesInfo*>(aObject),
1757
0
             "Multiple inheritance for mozilla::dom::MediaCapabilitiesInfo is broken.");
1758
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
1759
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
1760
0
1761
0
  JS::Rooted<JSObject*> global(aCx, JS::CurrentGlobalOrNull(aCx));
1762
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
1763
0
  if (!canonicalProto) {
1764
0
    return false;
1765
0
  }
1766
0
  JS::Rooted<JSObject*> proto(aCx);
1767
0
  if (aGivenProto) {
1768
0
    proto = aGivenProto;
1769
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
1770
0
    // coming in, we changed compartments to that of "parent" so may need
1771
0
    // to wrap the proto here.
1772
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
1773
0
      if (!JS_WrapObject(aCx, &proto)) {
1774
0
        return false;
1775
0
      }
1776
0
    }
1777
0
  } else {
1778
0
    proto = canonicalProto;
1779
0
  }
1780
0
1781
0
  BindingJSObjectCreator<mozilla::dom::MediaCapabilitiesInfo> creator(aCx);
1782
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
1783
0
  if (!aReflector) {
1784
0
    return false;
1785
0
  }
1786
0
1787
0
1788
0
1789
0
  creator.InitializationSucceeded();
1790
0
  return true;
1791
0
}
1792
1793
const NativePropertyHooks sNativePropertyHooks[] = { {
1794
  nullptr,
1795
  nullptr,
1796
  nullptr,
1797
  { sNativeProperties.Upcast(), nullptr },
1798
  prototypes::id::MediaCapabilitiesInfo,
1799
  constructors::id::MediaCapabilitiesInfo,
1800
  nullptr,
1801
  &DefaultXrayExpandoObjectClass
1802
} };
1803
1804
void
1805
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
1806
0
{
1807
0
  JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
1808
0
  if (!parentProto) {
1809
0
    return;
1810
0
  }
1811
0
1812
0
  JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
1813
0
  if (!constructorProto) {
1814
0
    return;
1815
0
  }
1816
0
1817
0
  static bool sIdsInited = false;
1818
0
  if (!sIdsInited && NS_IsMainThread()) {
1819
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
1820
0
      return;
1821
0
    }
1822
0
    sIdsInited = true;
1823
0
  }
1824
0
1825
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::MediaCapabilitiesInfo);
1826
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::MediaCapabilitiesInfo);
1827
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
1828
0
                              &sPrototypeClass.mBase, protoCache,
1829
0
                              nullptr,
1830
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
1831
0
                              interfaceCache,
1832
0
                              sNativeProperties.Upcast(),
1833
0
                              nullptr,
1834
0
                              "MediaCapabilitiesInfo", aDefineOnGlobal,
1835
0
                              nullptr,
1836
0
                              false);
1837
0
}
1838
1839
JSObject*
1840
GetConstructorObject(JSContext* aCx)
1841
0
{
1842
0
  return GetConstructorObjectHandle(aCx);
1843
0
}
1844
1845
} // namespace MediaCapabilitiesInfo_Binding
1846
1847
1848
1849
} // namespace dom
1850
} // namespace mozilla