Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/RTCConfigurationBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM RTCConfiguration.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "AtomList.h"
4
#include "RTCConfigurationBinding.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/ScriptSettings.h"
10
#include "mozilla/dom/SimpleGlobalObject.h"
11
#include "mozilla/dom/UnionConversions.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 RTCIceCredentialTypeValues {
21
extern const EnumEntry strings[3] = {
22
  {"password", 8},
23
  {"token", 5},
24
  { nullptr, 0 }
25
};
26
} // namespace RTCIceCredentialTypeValues
27
28
bool
29
ToJSValue(JSContext* aCx, RTCIceCredentialType aArgument, JS::MutableHandle<JS::Value> aValue)
30
0
{
31
0
  MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(RTCIceCredentialTypeValues::strings));
32
0
  JSString* resultStr =
33
0
    JS_NewStringCopyN(aCx, RTCIceCredentialTypeValues::strings[uint32_t(aArgument)].value,
34
0
                      RTCIceCredentialTypeValues::strings[uint32_t(aArgument)].length);
35
0
  if (!resultStr) {
36
0
    return false;
37
0
  }
38
0
  aValue.setString(resultStr);
39
0
  return true;
40
0
}
41
42
43
namespace RTCIceTransportPolicyValues {
44
extern const EnumEntry strings[3] = {
45
  {"relay", 5},
46
  {"all", 3},
47
  { nullptr, 0 }
48
};
49
} // namespace RTCIceTransportPolicyValues
50
51
bool
52
ToJSValue(JSContext* aCx, RTCIceTransportPolicy aArgument, JS::MutableHandle<JS::Value> aValue)
53
0
{
54
0
  MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(RTCIceTransportPolicyValues::strings));
55
0
  JSString* resultStr =
56
0
    JS_NewStringCopyN(aCx, RTCIceTransportPolicyValues::strings[uint32_t(aArgument)].value,
57
0
                      RTCIceTransportPolicyValues::strings[uint32_t(aArgument)].length);
58
0
  if (!resultStr) {
59
0
    return false;
60
0
  }
61
0
  aValue.setString(resultStr);
62
0
  return true;
63
0
}
64
65
66
namespace RTCBundlePolicyValues {
67
extern const EnumEntry strings[4] = {
68
  {"balanced", 8},
69
  {"max-compat", 10},
70
  {"max-bundle", 10},
71
  { nullptr, 0 }
72
};
73
} // namespace RTCBundlePolicyValues
74
75
bool
76
ToJSValue(JSContext* aCx, RTCBundlePolicy aArgument, JS::MutableHandle<JS::Value> aValue)
77
0
{
78
0
  MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(RTCBundlePolicyValues::strings));
79
0
  JSString* resultStr =
80
0
    JS_NewStringCopyN(aCx, RTCBundlePolicyValues::strings[uint32_t(aArgument)].value,
81
0
                      RTCBundlePolicyValues::strings[uint32_t(aArgument)].length);
82
0
  if (!resultStr) {
83
0
    return false;
84
0
  }
85
0
  aValue.setString(resultStr);
86
0
  return true;
87
0
}
88
89
90
91
RTCIceServer::RTCIceServer()
92
0
{
93
0
  // Safe to pass a null context if we pass a null value
94
0
  Init(nullptr, JS::NullHandleValue);
95
0
}
96
97
98
99
bool
100
RTCIceServer::InitIds(JSContext* cx, RTCIceServerAtoms* atomsCache)
101
0
{
102
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
103
0
104
0
  // Initialize these in reverse order so that any failure leaves the first one
105
0
  // uninitialized.
106
0
  if (!atomsCache->username_id.init(cx, "username") ||
107
0
      !atomsCache->urls_id.init(cx, "urls") ||
108
0
      !atomsCache->url_id.init(cx, "url") ||
109
0
      !atomsCache->credentialType_id.init(cx, "credentialType") ||
110
0
      !atomsCache->credential_id.init(cx, "credential")) {
111
0
    return false;
112
0
  }
113
0
  return true;
114
0
}
115
116
bool
117
RTCIceServer::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
118
0
{
119
0
  // Passing a null JSContext is OK only if we're initing from null,
120
0
  // Since in that case we will not have to do any property gets
121
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
122
0
  // checkers by static analysis tools
123
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
124
0
  RTCIceServerAtoms* atomsCache = nullptr;
125
0
  if (cx) {
126
0
    atomsCache = GetAtomCache<RTCIceServerAtoms>(cx);
127
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
128
0
      return false;
129
0
    }
130
0
  }
131
0
132
0
  if (!IsConvertibleToDictionary(val)) {
133
0
    return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
134
0
  }
135
0
136
0
  bool isNull = val.isNullOrUndefined();
137
0
  // We only need these if !isNull, in which case we have |cx|.
138
0
  Maybe<JS::Rooted<JSObject *> > object;
139
0
  Maybe<JS::Rooted<JS::Value> > temp;
140
0
  if (!isNull) {
141
0
    MOZ_ASSERT(cx);
142
0
    object.emplace(cx, &val.toObject());
143
0
    temp.emplace(cx);
144
0
  }
145
0
  if (!isNull) {
146
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->credential_id, temp.ptr())) {
147
0
      return false;
148
0
    }
149
0
  }
150
0
  if (!isNull && !temp->isUndefined()) {
151
0
    mCredential.Construct();
152
0
    if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mCredential.Value()))) {
153
0
      return false;
154
0
    }
155
0
    mIsAnyMemberPresent = true;
156
0
  }
157
0
158
0
  if (!isNull) {
159
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->credentialType_id, temp.ptr())) {
160
0
      return false;
161
0
    }
162
0
  }
163
0
  if (!isNull && !temp->isUndefined()) {
164
0
    {
165
0
      int index;
166
0
      if (!FindEnumStringIndex<true>(cx, temp.ref(), RTCIceCredentialTypeValues::strings, "RTCIceCredentialType", "'credentialType' member of RTCIceServer", &index)) {
167
0
        return false;
168
0
      }
169
0
      MOZ_ASSERT(index >= 0);
170
0
      mCredentialType = static_cast<RTCIceCredentialType>(index);
171
0
    }
172
0
  } else {
173
0
    mCredentialType = RTCIceCredentialType::Password;
174
0
  }
175
0
  mIsAnyMemberPresent = true;
176
0
177
0
  if (!isNull) {
178
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->url_id, temp.ptr())) {
179
0
      return false;
180
0
    }
181
0
  }
182
0
  if (!isNull && !temp->isUndefined()) {
183
0
    mUrl.Construct();
184
0
    if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mUrl.Value()))) {
185
0
      return false;
186
0
    }
187
0
    mIsAnyMemberPresent = true;
188
0
  }
189
0
190
0
  if (!isNull) {
191
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->urls_id, temp.ptr())) {
192
0
      return false;
193
0
    }
194
0
  }
195
0
  if (!isNull && !temp->isUndefined()) {
196
0
    mUrls.Construct();
197
0
    {
198
0
      bool done = false, failed = false, tryNext;
199
0
      if (temp.ref().isObject()) {
200
0
        done = (failed = !(mUrls.Value()).TrySetToStringSequence(cx, temp.ref(), tryNext, passedToJSImpl)) || !tryNext;
201
0
      }
202
0
      if (!done) {
203
0
        do {
204
0
          done = (failed = !(mUrls.Value()).TrySetToString(cx, temp.ref(), tryNext)) || !tryNext;
205
0
          break;
206
0
        } while (false);
207
0
      }
208
0
      if (failed) {
209
0
        return false;
210
0
      }
211
0
      if (!done) {
212
0
        ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "'urls' member of RTCIceServer", "StringSequence");
213
0
        return false;
214
0
      }
215
0
    }
216
0
    mIsAnyMemberPresent = true;
217
0
  }
218
0
219
0
  if (!isNull) {
220
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->username_id, temp.ptr())) {
221
0
      return false;
222
0
    }
223
0
  }
224
0
  if (!isNull && !temp->isUndefined()) {
225
0
    mUsername.Construct();
226
0
    if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mUsername.Value()))) {
227
0
      return false;
228
0
    }
229
0
    mIsAnyMemberPresent = true;
230
0
  }
231
0
  return true;
232
0
}
233
234
bool
235
RTCIceServer::Init(const nsAString& aJSON)
236
0
{
237
0
  AutoJSAPI jsapi;
238
0
  JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
239
0
  if (!cleanGlobal) {
240
0
    return false;
241
0
  }
242
0
  if (!jsapi.Init(cleanGlobal)) {
243
0
    return false;
244
0
  }
245
0
  JSContext* cx = jsapi.cx();
246
0
  JS::Rooted<JS::Value> json(cx);
247
0
  bool ok = ParseJSON(cx, aJSON, &json);
248
0
  NS_ENSURE_TRUE(ok, false);
249
0
  return Init(cx, json);
250
0
}
251
252
bool
253
RTCIceServer::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
254
0
{
255
0
  RTCIceServerAtoms* atomsCache = GetAtomCache<RTCIceServerAtoms>(cx);
256
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
257
0
    return false;
258
0
  }
259
0
260
0
  JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
261
0
  if (!obj) {
262
0
    return false;
263
0
  }
264
0
  rval.set(JS::ObjectValue(*obj));
265
0
266
0
  if (mCredential.WasPassed()) {
267
0
    do {
268
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
269
0
      JS::Rooted<JS::Value> temp(cx);
270
0
      nsString const & currentValue = mCredential.InternalValue();
271
0
      if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
272
0
        return false;
273
0
      }
274
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->credential_id, temp, JSPROP_ENUMERATE)) {
275
0
        return false;
276
0
      }
277
0
      break;
278
0
    } while(false);
279
0
  }
280
0
281
0
  do {
282
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
283
0
    JS::Rooted<JS::Value> temp(cx);
284
0
    RTCIceCredentialType const & currentValue = mCredentialType;
285
0
    if (!ToJSValue(cx, currentValue, &temp)) {
286
0
      return false;
287
0
    }
288
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->credentialType_id, temp, JSPROP_ENUMERATE)) {
289
0
      return false;
290
0
    }
291
0
    break;
292
0
  } while(false);
293
0
294
0
  if (mUrl.WasPassed()) {
295
0
    do {
296
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
297
0
      JS::Rooted<JS::Value> temp(cx);
298
0
      nsString const & currentValue = mUrl.InternalValue();
299
0
      if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
300
0
        return false;
301
0
      }
302
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->url_id, temp, JSPROP_ENUMERATE)) {
303
0
        return false;
304
0
      }
305
0
      break;
306
0
    } while(false);
307
0
  }
308
0
309
0
  if (mUrls.WasPassed()) {
310
0
    do {
311
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
312
0
      JS::Rooted<JS::Value> temp(cx);
313
0
      OwningStringOrStringSequence const & currentValue = mUrls.InternalValue();
314
0
      if (!currentValue.ToJSVal(cx, obj, &temp)) {
315
0
        return false;
316
0
      }
317
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->urls_id, temp, JSPROP_ENUMERATE)) {
318
0
        return false;
319
0
      }
320
0
      break;
321
0
    } while(false);
322
0
  }
323
0
324
0
  if (mUsername.WasPassed()) {
325
0
    do {
326
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
327
0
      JS::Rooted<JS::Value> temp(cx);
328
0
      nsString const & currentValue = mUsername.InternalValue();
329
0
      if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
330
0
        return false;
331
0
      }
332
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->username_id, temp, JSPROP_ENUMERATE)) {
333
0
        return false;
334
0
      }
335
0
      break;
336
0
    } while(false);
337
0
  }
338
0
339
0
  return true;
340
0
}
341
342
bool
343
RTCIceServer::ToJSON(nsAString& aJSON) const
344
0
{
345
0
  AutoJSAPI jsapi;
346
0
  jsapi.Init();
347
0
  JSContext *cx = jsapi.cx();
348
0
  // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
349
0
  // because we'll only be creating objects, in ways that have no
350
0
  // side-effects, followed by a call to JS::ToJSONMaybeSafely,
351
0
  // which likewise guarantees no side-effects for the sorts of
352
0
  // things we will pass it.
353
0
  JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal());
354
0
  JS::Rooted<JS::Value> val(cx);
355
0
  if (!ToObjectInternal(cx, &val)) {
356
0
    return false;
357
0
  }
358
0
  JS::Rooted<JSObject*> obj(cx, &val.toObject());
359
0
  return StringifyToJSON(cx, obj, aJSON);
360
0
}
361
362
void
363
RTCIceServer::TraceDictionary(JSTracer* trc)
364
0
{
365
0
}
366
367
RTCIceServer&
368
RTCIceServer::operator=(const RTCIceServer& aOther)
369
0
{
370
0
  DictionaryBase::operator=(aOther);
371
0
  mCredential.Reset();
372
0
  if (aOther.mCredential.WasPassed()) {
373
0
    mCredential.Construct(aOther.mCredential.Value());
374
0
  }
375
0
  mCredentialType = aOther.mCredentialType;
376
0
  mUrl.Reset();
377
0
  if (aOther.mUrl.WasPassed()) {
378
0
    mUrl.Construct(aOther.mUrl.Value());
379
0
  }
380
0
  mUrls.Reset();
381
0
  if (aOther.mUrls.WasPassed()) {
382
0
    mUrls.Construct(aOther.mUrls.Value());
383
0
  }
384
0
  mUsername.Reset();
385
0
  if (aOther.mUsername.WasPassed()) {
386
0
    mUsername.Construct(aOther.mUsername.Value());
387
0
  }
388
0
  return *this;
389
0
}
390
391
namespace binding_detail {
392
} // namespace binding_detail
393
394
395
396
RTCConfiguration::RTCConfiguration()
397
0
{
398
0
  // Safe to pass a null context if we pass a null value
399
0
  Init(nullptr, JS::NullHandleValue);
400
0
}
401
402
403
404
bool
405
RTCConfiguration::InitIds(JSContext* cx, RTCConfigurationAtoms* atomsCache)
406
0
{
407
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
408
0
409
0
  // Initialize these in reverse order so that any failure leaves the first one
410
0
  // uninitialized.
411
0
  if (!atomsCache->peerIdentity_id.init(cx, "peerIdentity") ||
412
0
      !atomsCache->iceTransportPolicy_id.init(cx, "iceTransportPolicy") ||
413
0
      !atomsCache->iceServers_id.init(cx, "iceServers") ||
414
0
      !atomsCache->certificates_id.init(cx, "certificates") ||
415
0
      !atomsCache->bundlePolicy_id.init(cx, "bundlePolicy")) {
416
0
    return false;
417
0
  }
418
0
  return true;
419
0
}
420
421
bool
422
RTCConfiguration::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
423
0
{
424
0
  // Passing a null JSContext is OK only if we're initing from null,
425
0
  // Since in that case we will not have to do any property gets
426
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
427
0
  // checkers by static analysis tools
428
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
429
0
  RTCConfigurationAtoms* atomsCache = nullptr;
430
0
  if (cx) {
431
0
    atomsCache = GetAtomCache<RTCConfigurationAtoms>(cx);
432
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
433
0
      return false;
434
0
    }
435
0
  }
436
0
437
0
  if (!IsConvertibleToDictionary(val)) {
438
0
    return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
439
0
  }
440
0
441
0
  bool isNull = val.isNullOrUndefined();
442
0
  // We only need these if !isNull, in which case we have |cx|.
443
0
  Maybe<JS::Rooted<JSObject *> > object;
444
0
  Maybe<JS::Rooted<JS::Value> > temp;
445
0
  if (!isNull) {
446
0
    MOZ_ASSERT(cx);
447
0
    object.emplace(cx, &val.toObject());
448
0
    temp.emplace(cx);
449
0
  }
450
0
  if (!isNull) {
451
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->bundlePolicy_id, temp.ptr())) {
452
0
      return false;
453
0
    }
454
0
  }
455
0
  if (!isNull && !temp->isUndefined()) {
456
0
    {
457
0
      int index;
458
0
      if (!FindEnumStringIndex<true>(cx, temp.ref(), RTCBundlePolicyValues::strings, "RTCBundlePolicy", "'bundlePolicy' member of RTCConfiguration", &index)) {
459
0
        return false;
460
0
      }
461
0
      MOZ_ASSERT(index >= 0);
462
0
      mBundlePolicy = static_cast<RTCBundlePolicy>(index);
463
0
    }
464
0
  } else {
465
0
    mBundlePolicy = RTCBundlePolicy::Balanced;
466
0
  }
467
0
  mIsAnyMemberPresent = true;
468
0
469
0
  if (!isNull) {
470
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->certificates_id, temp.ptr())) {
471
0
      return false;
472
0
    }
473
0
  }
474
0
  if (!isNull && !temp->isUndefined()) {
475
0
    mCertificates.Construct();
476
0
    if (temp.ref().isObject()) {
477
0
      JS::ForOfIterator iter(cx);
478
0
      if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
479
0
        return false;
480
0
      }
481
0
      if (!iter.valueIsIterable()) {
482
0
        ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'certificates' member of RTCConfiguration");
483
0
        return false;
484
0
      }
485
0
      Sequence<OwningNonNull<mozilla::dom::RTCCertificate>> &arr = (mCertificates.Value());
486
0
      JS::Rooted<JS::Value> temp(cx);
487
0
      while (true) {
488
0
        bool done;
489
0
        if (!iter.next(&temp, &done)) {
490
0
          return false;
491
0
        }
492
0
        if (done) {
493
0
          break;
494
0
        }
495
0
        OwningNonNull<mozilla::dom::RTCCertificate>* slotPtr = arr.AppendElement(mozilla::fallible);
496
0
        if (!slotPtr) {
497
0
          JS_ReportOutOfMemory(cx);
498
0
          return false;
499
0
        }
500
0
        OwningNonNull<mozilla::dom::RTCCertificate>& slot = *slotPtr;
501
0
        if (temp.isObject()) {
502
0
          static_assert(IsRefcounted<mozilla::dom::RTCCertificate>::value, "We can only store refcounted classes.");{
503
0
            nsresult rv = UnwrapObject<prototypes::id::RTCCertificate, mozilla::dom::RTCCertificate>(&temp, slot);
504
0
            if (NS_FAILED(rv)) {
505
0
              ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Element of 'certificates' member of RTCConfiguration", "RTCCertificate");
506
0
              return false;
507
0
            }
508
0
          }
509
0
        } else {
510
0
          ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of 'certificates' member of RTCConfiguration");
511
0
          return false;
512
0
        }
513
0
      }
514
0
    } else {
515
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'certificates' member of RTCConfiguration");
516
0
      return false;
517
0
    }
518
0
    mIsAnyMemberPresent = true;
519
0
  }
520
0
521
0
  if (!isNull) {
522
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->iceServers_id, temp.ptr())) {
523
0
      return false;
524
0
    }
525
0
  }
526
0
  if (!isNull && !temp->isUndefined()) {
527
0
    mIceServers.Construct();
528
0
    if (temp.ref().isObject()) {
529
0
      JS::ForOfIterator iter(cx);
530
0
      if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
531
0
        return false;
532
0
      }
533
0
      if (!iter.valueIsIterable()) {
534
0
        ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'iceServers' member of RTCConfiguration");
535
0
        return false;
536
0
      }
537
0
      Sequence<RTCIceServer> &arr = (mIceServers.Value());
538
0
      JS::Rooted<JS::Value> temp(cx);
539
0
      while (true) {
540
0
        bool done;
541
0
        if (!iter.next(&temp, &done)) {
542
0
          return false;
543
0
        }
544
0
        if (done) {
545
0
          break;
546
0
        }
547
0
        RTCIceServer* slotPtr = arr.AppendElement(mozilla::fallible);
548
0
        if (!slotPtr) {
549
0
          JS_ReportOutOfMemory(cx);
550
0
          return false;
551
0
        }
552
0
        RTCIceServer& slot = *slotPtr;
553
0
        if (!slot.Init(cx, temp,  "Element of 'iceServers' member of RTCConfiguration", passedToJSImpl)) {
554
0
          return false;
555
0
        }
556
0
      }
557
0
    } else {
558
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'iceServers' member of RTCConfiguration");
559
0
      return false;
560
0
    }
561
0
    mIsAnyMemberPresent = true;
562
0
  }
563
0
564
0
  if (!isNull) {
565
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->iceTransportPolicy_id, temp.ptr())) {
566
0
      return false;
567
0
    }
568
0
  }
569
0
  if (!isNull && !temp->isUndefined()) {
570
0
    {
571
0
      int index;
572
0
      if (!FindEnumStringIndex<true>(cx, temp.ref(), RTCIceTransportPolicyValues::strings, "RTCIceTransportPolicy", "'iceTransportPolicy' member of RTCConfiguration", &index)) {
573
0
        return false;
574
0
      }
575
0
      MOZ_ASSERT(index >= 0);
576
0
      mIceTransportPolicy = static_cast<RTCIceTransportPolicy>(index);
577
0
    }
578
0
  } else {
579
0
    mIceTransportPolicy = RTCIceTransportPolicy::All;
580
0
  }
581
0
  mIsAnyMemberPresent = true;
582
0
583
0
  if (!isNull) {
584
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->peerIdentity_id, temp.ptr())) {
585
0
      return false;
586
0
    }
587
0
  }
588
0
  if (!isNull && !temp->isUndefined()) {
589
0
    if (!ConvertJSValueToString(cx, temp.ref(), eNull, eNull, mPeerIdentity)) {
590
0
      return false;
591
0
    }
592
0
  } else {
593
0
    mPeerIdentity.SetIsVoid(true);
594
0
  }
595
0
  mIsAnyMemberPresent = true;
596
0
  return true;
597
0
}
598
599
bool
600
RTCConfiguration::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
601
0
{
602
0
  RTCConfigurationAtoms* atomsCache = GetAtomCache<RTCConfigurationAtoms>(cx);
603
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
604
0
    return false;
605
0
  }
606
0
607
0
  JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
608
0
  if (!obj) {
609
0
    return false;
610
0
  }
611
0
  rval.set(JS::ObjectValue(*obj));
612
0
613
0
  do {
614
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
615
0
    JS::Rooted<JS::Value> temp(cx);
616
0
    RTCBundlePolicy const & currentValue = mBundlePolicy;
617
0
    if (!ToJSValue(cx, currentValue, &temp)) {
618
0
      return false;
619
0
    }
620
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->bundlePolicy_id, temp, JSPROP_ENUMERATE)) {
621
0
      return false;
622
0
    }
623
0
    break;
624
0
  } while(false);
625
0
626
0
  if (mCertificates.WasPassed()) {
627
0
    do {
628
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
629
0
      JS::Rooted<JS::Value> temp(cx);
630
0
      Sequence<OwningNonNull<mozilla::dom::RTCCertificate>> const & currentValue = mCertificates.InternalValue();
631
0
632
0
      uint32_t length = currentValue.Length();
633
0
      JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
634
0
      if (!returnArray) {
635
0
        return false;
636
0
      }
637
0
      // Scope for 'tmp'
638
0
      {
639
0
        JS::Rooted<JS::Value> tmp(cx);
640
0
        for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
641
0
          // Control block to let us common up the JS_DefineElement calls when there
642
0
          // are different ways to succeed at wrapping the object.
643
0
          do {
644
0
            if (!GetOrCreateDOMReflector(cx, currentValue[sequenceIdx0], &tmp)) {
645
0
              MOZ_ASSERT(JS_IsExceptionPending(cx));
646
0
              return false;
647
0
            }
648
0
            break;
649
0
          } while (false);
650
0
          if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
651
0
                                JSPROP_ENUMERATE)) {
652
0
            return false;
653
0
          }
654
0
        }
655
0
      }
656
0
      temp.setObject(*returnArray);
657
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->certificates_id, temp, JSPROP_ENUMERATE)) {
658
0
        return false;
659
0
      }
660
0
      break;
661
0
    } while(false);
662
0
  }
663
0
664
0
  if (mIceServers.WasPassed()) {
665
0
    do {
666
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
667
0
      JS::Rooted<JS::Value> temp(cx);
668
0
      Sequence<RTCIceServer> const & currentValue = mIceServers.InternalValue();
669
0
670
0
      uint32_t length = currentValue.Length();
671
0
      JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
672
0
      if (!returnArray) {
673
0
        return false;
674
0
      }
675
0
      // Scope for 'tmp'
676
0
      {
677
0
        JS::Rooted<JS::Value> tmp(cx);
678
0
        for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
679
0
          // Control block to let us common up the JS_DefineElement calls when there
680
0
          // are different ways to succeed at wrapping the object.
681
0
          do {
682
0
            if (!currentValue[sequenceIdx0].ToObjectInternal(cx, &tmp)) {
683
0
              return false;
684
0
            }
685
0
            break;
686
0
          } while (false);
687
0
          if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
688
0
                                JSPROP_ENUMERATE)) {
689
0
            return false;
690
0
          }
691
0
        }
692
0
      }
693
0
      temp.setObject(*returnArray);
694
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->iceServers_id, temp, JSPROP_ENUMERATE)) {
695
0
        return false;
696
0
      }
697
0
      break;
698
0
    } while(false);
699
0
  }
700
0
701
0
  do {
702
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
703
0
    JS::Rooted<JS::Value> temp(cx);
704
0
    RTCIceTransportPolicy const & currentValue = mIceTransportPolicy;
705
0
    if (!ToJSValue(cx, currentValue, &temp)) {
706
0
      return false;
707
0
    }
708
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->iceTransportPolicy_id, temp, JSPROP_ENUMERATE)) {
709
0
      return false;
710
0
    }
711
0
    break;
712
0
  } while(false);
713
0
714
0
  do {
715
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
716
0
    JS::Rooted<JS::Value> temp(cx);
717
0
    nsString const & currentValue = mPeerIdentity;
718
0
    if (!xpc::StringToJsval(cx, currentValue, &temp)) {
719
0
      return false;
720
0
    }
721
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->peerIdentity_id, temp, JSPROP_ENUMERATE)) {
722
0
      return false;
723
0
    }
724
0
    break;
725
0
  } while(false);
726
0
727
0
  return true;
728
0
}
729
730
void
731
RTCConfiguration::TraceDictionary(JSTracer* trc)
732
0
{
733
0
}
734
735
736
737
RTCConfiguration&
738
RTCConfiguration::operator=(const RTCConfiguration& aOther)
739
0
{
740
0
  DictionaryBase::operator=(aOther);
741
0
  mBundlePolicy = aOther.mBundlePolicy;
742
0
  mCertificates.Reset();
743
0
  if (aOther.mCertificates.WasPassed()) {
744
0
    mCertificates.Construct(aOther.mCertificates.Value());
745
0
  }
746
0
  mIceServers.Reset();
747
0
  if (aOther.mIceServers.WasPassed()) {
748
0
    mIceServers.Construct(aOther.mIceServers.Value());
749
0
  }
750
0
  mIceTransportPolicy = aOther.mIceTransportPolicy;
751
0
  mPeerIdentity = aOther.mPeerIdentity;
752
0
  return *this;
753
0
}
754
755
namespace binding_detail {
756
} // namespace binding_detail
757
758
759
} // namespace dom
760
} // namespace mozilla