Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/RTCPeerConnectionBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM RTCPeerConnection.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "AtomList.h"
4
#include "DOMMediaStream.h"
5
#include "EventHandlerBinding.h"
6
#include "EventTargetBinding.h"
7
#include "FunctionBinding.h"
8
#include "RTCConfigurationBinding.h"
9
#include "RTCIceCandidateBinding.h"
10
#include "RTCIdentityProviderBinding.h"
11
#include "RTCPeerConnectionBinding.h"
12
#include "RTCRtpReceiverBinding.h"
13
#include "RTCRtpSenderBinding.h"
14
#include "RTCRtpTransceiverBinding.h"
15
#include "RTCSessionDescriptionBinding.h"
16
#include "RTCStatsReportBinding.h"
17
#include "SubtleCryptoBinding.h"
18
#include "WrapperFactory.h"
19
#include "jsapi.h"
20
#include "jsfriendapi.h"
21
#include "mozilla/FloatingPoint.h"
22
#include "mozilla/OwningNonNull.h"
23
#include "mozilla/Preferences.h"
24
#include "mozilla/dom/BindingUtils.h"
25
#include "mozilla/dom/DOMException.h"
26
#include "mozilla/dom/DOMJSClass.h"
27
#include "mozilla/dom/MediaStreamTrack.h"
28
#include "mozilla/dom/NonRefcountedDOMObject.h"
29
#include "mozilla/dom/Nullable.h"
30
#include "mozilla/dom/PrimitiveConversions.h"
31
#include "mozilla/dom/Promise.h"
32
#include "mozilla/dom/RTCCertificate.h"
33
#include "mozilla/dom/ScriptSettings.h"
34
#include "mozilla/dom/SimpleGlobalObject.h"
35
#include "mozilla/dom/ToJSValue.h"
36
#include "mozilla/dom/UnionConversions.h"
37
#include "mozilla/dom/XrayExpandoClass.h"
38
#include "nsContentUtils.h"
39
#include "nsDOMDataChannel.h"
40
#include "nsIDocument.h"
41
#include "nsIGlobalObject.h"
42
43
namespace mozilla {
44
namespace dom {
45
46
namespace binding_detail {}; // Just to make sure it's known as a namespace
47
using namespace mozilla::dom::binding_detail;
48
49
50
namespace RTCSignalingStateValues {
51
extern const EnumEntry strings[7] = {
52
  {"stable", 6},
53
  {"have-local-offer", 16},
54
  {"have-remote-offer", 17},
55
  {"have-local-pranswer", 19},
56
  {"have-remote-pranswer", 20},
57
  {"closed", 6},
58
  { nullptr, 0 }
59
};
60
} // namespace RTCSignalingStateValues
61
62
bool
63
ToJSValue(JSContext* aCx, RTCSignalingState aArgument, JS::MutableHandle<JS::Value> aValue)
64
0
{
65
0
  MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(RTCSignalingStateValues::strings));
66
0
  JSString* resultStr =
67
0
    JS_NewStringCopyN(aCx, RTCSignalingStateValues::strings[uint32_t(aArgument)].value,
68
0
                      RTCSignalingStateValues::strings[uint32_t(aArgument)].length);
69
0
  if (!resultStr) {
70
0
    return false;
71
0
  }
72
0
  aValue.setString(resultStr);
73
0
  return true;
74
0
}
75
76
77
namespace RTCIceGatheringStateValues {
78
extern const EnumEntry strings[4] = {
79
  {"new", 3},
80
  {"gathering", 9},
81
  {"complete", 8},
82
  { nullptr, 0 }
83
};
84
} // namespace RTCIceGatheringStateValues
85
86
bool
87
ToJSValue(JSContext* aCx, RTCIceGatheringState aArgument, JS::MutableHandle<JS::Value> aValue)
88
0
{
89
0
  MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(RTCIceGatheringStateValues::strings));
90
0
  JSString* resultStr =
91
0
    JS_NewStringCopyN(aCx, RTCIceGatheringStateValues::strings[uint32_t(aArgument)].value,
92
0
                      RTCIceGatheringStateValues::strings[uint32_t(aArgument)].length);
93
0
  if (!resultStr) {
94
0
    return false;
95
0
  }
96
0
  aValue.setString(resultStr);
97
0
  return true;
98
0
}
99
100
101
namespace RTCIceConnectionStateValues {
102
extern const EnumEntry strings[8] = {
103
  {"new", 3},
104
  {"checking", 8},
105
  {"connected", 9},
106
  {"completed", 9},
107
  {"failed", 6},
108
  {"disconnected", 12},
109
  {"closed", 6},
110
  { nullptr, 0 }
111
};
112
} // namespace RTCIceConnectionStateValues
113
114
bool
115
ToJSValue(JSContext* aCx, RTCIceConnectionState aArgument, JS::MutableHandle<JS::Value> aValue)
116
0
{
117
0
  MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(RTCIceConnectionStateValues::strings));
118
0
  JSString* resultStr =
119
0
    JS_NewStringCopyN(aCx, RTCIceConnectionStateValues::strings[uint32_t(aArgument)].value,
120
0
                      RTCIceConnectionStateValues::strings[uint32_t(aArgument)].length);
121
0
  if (!resultStr) {
122
0
    return false;
123
0
  }
124
0
  aValue.setString(resultStr);
125
0
  return true;
126
0
}
127
128
129
namespace mozPacketDumpTypeValues {
130
extern const EnumEntry strings[5] = {
131
  {"rtp", 3},
132
  {"srtp", 4},
133
  {"rtcp", 4},
134
  {"srtcp", 5},
135
  { nullptr, 0 }
136
};
137
} // namespace mozPacketDumpTypeValues
138
139
bool
140
ToJSValue(JSContext* aCx, mozPacketDumpType aArgument, JS::MutableHandle<JS::Value> aValue)
141
0
{
142
0
  MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(mozPacketDumpTypeValues::strings));
143
0
  JSString* resultStr =
144
0
    JS_NewStringCopyN(aCx, mozPacketDumpTypeValues::strings[uint32_t(aArgument)].value,
145
0
                      mozPacketDumpTypeValues::strings[uint32_t(aArgument)].length);
146
0
  if (!resultStr) {
147
0
    return false;
148
0
  }
149
0
  aValue.setString(resultStr);
150
0
  return true;
151
0
}
152
153
154
void
155
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningMediaStreamTrackOrString& aUnion, const char* aName, uint32_t aFlags)
156
0
{
157
0
  if (aUnion.IsMediaStreamTrack()) {
158
0
    ImplCycleCollectionTraverse(aCallback, aUnion.GetAsMediaStreamTrack(), "mMediaStreamTrack", aFlags);
159
0
  }
160
0
}
161
162
163
void
164
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningRTCIceCandidateInitOrRTCIceCandidate& aUnion, const char* aName, uint32_t aFlags)
165
0
{
166
0
  if (aUnion.IsRTCIceCandidate()) {
167
0
    ImplCycleCollectionTraverse(aCallback, aUnion.GetAsRTCIceCandidate(), "mRTCIceCandidate", aFlags);
168
0
  }
169
0
}
170
171
172
void
173
ImplCycleCollectionUnlink(OwningMediaStreamTrackOrString& aUnion)
174
0
{
175
0
  aUnion.Uninit();
176
0
}
177
178
179
void
180
ImplCycleCollectionUnlink(OwningRTCIceCandidateInitOrRTCIceCandidate& aUnion)
181
0
{
182
0
  aUnion.Uninit();
183
0
}
184
185
186
bool
187
MediaStreamTrackOrString::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
188
0
{
189
0
  switch (mType) {
190
0
    case eUninitialized: {
191
0
      return false;
192
0
      break;
193
0
    }
194
0
    case eMediaStreamTrack: {
195
0
      if (!GetOrCreateDOMReflector(cx, mValue.mMediaStreamTrack.Value(), rval)) {
196
0
        MOZ_ASSERT(JS_IsExceptionPending(cx));
197
0
        return false;
198
0
      }
199
0
      return true;
200
0
      break;
201
0
    }
202
0
    case eString: {
203
0
      if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) {
204
0
        return false;
205
0
      }
206
0
      return true;
207
0
      break;
208
0
    }
209
0
    default: {
210
0
      return false;
211
0
      break;
212
0
    }
213
0
  }
214
0
215
0
  return false;
216
0
}
217
218
219
OwningNonNull<mozilla::dom::MediaStreamTrack>&
220
OwningMediaStreamTrackOrString::RawSetAsMediaStreamTrack()
221
0
{
222
0
  if (mType == eMediaStreamTrack) {
223
0
    return mValue.mMediaStreamTrack.Value();
224
0
  }
225
0
  MOZ_ASSERT(mType == eUninitialized);
226
0
  mType = eMediaStreamTrack;
227
0
  return mValue.mMediaStreamTrack.SetValue();
228
0
}
229
230
OwningNonNull<mozilla::dom::MediaStreamTrack>&
231
OwningMediaStreamTrackOrString::SetAsMediaStreamTrack()
232
0
{
233
0
  if (mType == eMediaStreamTrack) {
234
0
    return mValue.mMediaStreamTrack.Value();
235
0
  }
236
0
  Uninit();
237
0
  mType = eMediaStreamTrack;
238
0
  return mValue.mMediaStreamTrack.SetValue();
239
0
}
240
241
bool
242
OwningMediaStreamTrackOrString::TrySetToMediaStreamTrack(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
243
0
{
244
0
  tryNext = false;
245
0
  { // scope for memberSlot
246
0
    OwningNonNull<mozilla::dom::MediaStreamTrack>& memberSlot = RawSetAsMediaStreamTrack();
247
0
    static_assert(IsRefcounted<mozilla::dom::MediaStreamTrack>::value, "We can only store refcounted classes.");{
248
0
      nsresult rv = UnwrapObject<prototypes::id::MediaStreamTrack, mozilla::dom::MediaStreamTrack>(value, memberSlot);
249
0
      if (NS_FAILED(rv)) {
250
0
        DestroyMediaStreamTrack();
251
0
        tryNext = true;
252
0
        return true;
253
0
      }
254
0
    }
255
0
  }
256
0
  return true;
257
0
}
258
259
void
260
OwningMediaStreamTrackOrString::DestroyMediaStreamTrack()
261
0
{
262
0
  MOZ_ASSERT(IsMediaStreamTrack(), "Wrong type!");
263
0
  mValue.mMediaStreamTrack.Destroy();
264
0
  mType = eUninitialized;
265
0
}
266
267
268
269
270
nsString&
271
OwningMediaStreamTrackOrString::RawSetAsString()
272
0
{
273
0
  if (mType == eString) {
274
0
    return mValue.mString.Value();
275
0
  }
276
0
  MOZ_ASSERT(mType == eUninitialized);
277
0
  mType = eString;
278
0
  return mValue.mString.SetValue();
279
0
}
280
281
nsString&
282
OwningMediaStreamTrackOrString::SetAsString()
283
0
{
284
0
  if (mType == eString) {
285
0
    return mValue.mString.Value();
286
0
  }
287
0
  Uninit();
288
0
  mType = eString;
289
0
  return mValue.mString.SetValue();
290
0
}
291
292
bool
293
OwningMediaStreamTrackOrString::TrySetToString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
294
0
{
295
0
  tryNext = false;
296
0
  { // scope for memberSlot
297
0
    nsString& memberSlot = RawSetAsString();
298
0
    if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
299
0
      return false;
300
0
    }
301
0
  }
302
0
  return true;
303
0
}
304
305
306
void
307
OwningMediaStreamTrackOrString::DestroyString()
308
0
{
309
0
  MOZ_ASSERT(IsString(), "Wrong type!");
310
0
  mValue.mString.Destroy();
311
0
  mType = eUninitialized;
312
0
}
313
314
315
316
317
void
318
OwningMediaStreamTrackOrString::Uninit()
319
{
320
  switch (mType) {
321
    case eUninitialized: {
322
      break;
323
    }
324
    case eMediaStreamTrack: {
325
      DestroyMediaStreamTrack();
326
      break;
327
    }
328
    case eString: {
329
      DestroyString();
330
      break;
331
    }
332
  }
333
}
334
335
bool
336
OwningMediaStreamTrackOrString::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
337
0
{
338
0
  switch (mType) {
339
0
    case eUninitialized: {
340
0
      return false;
341
0
      break;
342
0
    }
343
0
    case eMediaStreamTrack: {
344
0
      if (!GetOrCreateDOMReflector(cx, mValue.mMediaStreamTrack.Value(), rval)) {
345
0
        MOZ_ASSERT(JS_IsExceptionPending(cx));
346
0
        return false;
347
0
      }
348
0
      return true;
349
0
      break;
350
0
    }
351
0
    case eString: {
352
0
      if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) {
353
0
        return false;
354
0
      }
355
0
      return true;
356
0
      break;
357
0
    }
358
0
    default: {
359
0
      return false;
360
0
      break;
361
0
    }
362
0
  }
363
0
364
0
  return false;
365
0
}
366
367
void
368
OwningMediaStreamTrackOrString::TraceUnion(JSTracer* trc)
369
0
{
370
0
}
371
372
OwningMediaStreamTrackOrString&
373
OwningMediaStreamTrackOrString::operator=(const OwningMediaStreamTrackOrString& aOther)
374
0
{
375
0
  switch (aOther.mType) {
376
0
    case eUninitialized: {
377
0
      MOZ_ASSERT(mType == eUninitialized,
378
0
                 "We need to destroy ourselves?");
379
0
      break;
380
0
    }
381
0
    case eMediaStreamTrack: {
382
0
      SetAsMediaStreamTrack() = aOther.GetAsMediaStreamTrack();
383
0
      break;
384
0
    }
385
0
    case eString: {
386
0
      SetAsString() = aOther.GetAsString();
387
0
      break;
388
0
    }
389
0
  }
390
0
  return *this;
391
0
}
392
393
394
395
RTCDataChannelInit::RTCDataChannelInit()
396
0
{
397
0
  // Safe to pass a null context if we pass a null value
398
0
  Init(nullptr, JS::NullHandleValue);
399
0
}
400
401
402
403
bool
404
RTCDataChannelInit::InitIds(JSContext* cx, RTCDataChannelInitAtoms* atomsCache)
405
0
{
406
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
407
0
408
0
  // Initialize these in reverse order so that any failure leaves the first one
409
0
  // uninitialized.
410
0
  if (!atomsCache->protocol_id.init(cx, "protocol") ||
411
0
      !atomsCache->ordered_id.init(cx, "ordered") ||
412
0
      !atomsCache->negotiated_id.init(cx, "negotiated") ||
413
0
      !atomsCache->maxRetransmits_id.init(cx, "maxRetransmits") ||
414
0
      !atomsCache->maxRetransmitTime_id.init(cx, "maxRetransmitTime") ||
415
0
      !atomsCache->maxPacketLifeTime_id.init(cx, "maxPacketLifeTime") ||
416
0
      !atomsCache->id_id.init(cx, "id")) {
417
0
    return false;
418
0
  }
419
0
  return true;
420
0
}
421
422
bool
423
RTCDataChannelInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
424
0
{
425
0
  // Passing a null JSContext is OK only if we're initing from null,
426
0
  // Since in that case we will not have to do any property gets
427
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
428
0
  // checkers by static analysis tools
429
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
430
0
  RTCDataChannelInitAtoms* atomsCache = nullptr;
431
0
  if (cx) {
432
0
    atomsCache = GetAtomCache<RTCDataChannelInitAtoms>(cx);
433
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
434
0
      return false;
435
0
    }
436
0
  }
437
0
438
0
  if (!IsConvertibleToDictionary(val)) {
439
0
    return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
440
0
  }
441
0
442
0
  bool isNull = val.isNullOrUndefined();
443
0
  // We only need these if !isNull, in which case we have |cx|.
444
0
  Maybe<JS::Rooted<JSObject *> > object;
445
0
  Maybe<JS::Rooted<JS::Value> > temp;
446
0
  if (!isNull) {
447
0
    MOZ_ASSERT(cx);
448
0
    object.emplace(cx, &val.toObject());
449
0
    temp.emplace(cx);
450
0
  }
451
0
  if (!isNull) {
452
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->id_id, temp.ptr())) {
453
0
      return false;
454
0
    }
455
0
  }
456
0
  if (!isNull && !temp->isUndefined()) {
457
0
    mId.Construct();
458
0
    if (!ValueToPrimitive<uint16_t, eDefault>(cx, temp.ref(), &(mId.Value()))) {
459
0
      return false;
460
0
    }
461
0
    mIsAnyMemberPresent = true;
462
0
  }
463
0
464
0
  if (!isNull) {
465
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->maxPacketLifeTime_id, temp.ptr())) {
466
0
      return false;
467
0
    }
468
0
  }
469
0
  if (!isNull && !temp->isUndefined()) {
470
0
    mMaxPacketLifeTime.Construct();
471
0
    if (!ValueToPrimitive<uint16_t, eDefault>(cx, temp.ref(), &(mMaxPacketLifeTime.Value()))) {
472
0
      return false;
473
0
    }
474
0
    mIsAnyMemberPresent = true;
475
0
  }
476
0
477
0
  if (!isNull) {
478
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->maxRetransmitTime_id, temp.ptr())) {
479
0
      return false;
480
0
    }
481
0
  }
482
0
  if (!isNull && !temp->isUndefined()) {
483
0
    mMaxRetransmitTime.Construct();
484
0
    if (!ValueToPrimitive<uint16_t, eDefault>(cx, temp.ref(), &(mMaxRetransmitTime.Value()))) {
485
0
      return false;
486
0
    }
487
0
    mIsAnyMemberPresent = true;
488
0
  }
489
0
490
0
  if (!isNull) {
491
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->maxRetransmits_id, temp.ptr())) {
492
0
      return false;
493
0
    }
494
0
  }
495
0
  if (!isNull && !temp->isUndefined()) {
496
0
    mMaxRetransmits.Construct();
497
0
    if (!ValueToPrimitive<uint16_t, eDefault>(cx, temp.ref(), &(mMaxRetransmits.Value()))) {
498
0
      return false;
499
0
    }
500
0
    mIsAnyMemberPresent = true;
501
0
  }
502
0
503
0
  if (!isNull) {
504
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->negotiated_id, temp.ptr())) {
505
0
      return false;
506
0
    }
507
0
  }
508
0
  if (!isNull && !temp->isUndefined()) {
509
0
    if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mNegotiated)) {
510
0
      return false;
511
0
    }
512
0
  } else {
513
0
    mNegotiated = false;
514
0
  }
515
0
  mIsAnyMemberPresent = true;
516
0
517
0
  if (!isNull) {
518
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->ordered_id, temp.ptr())) {
519
0
      return false;
520
0
    }
521
0
  }
522
0
  if (!isNull && !temp->isUndefined()) {
523
0
    if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mOrdered)) {
524
0
      return false;
525
0
    }
526
0
  } else {
527
0
    mOrdered = true;
528
0
  }
529
0
  mIsAnyMemberPresent = true;
530
0
531
0
  if (!isNull) {
532
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->protocol_id, temp.ptr())) {
533
0
      return false;
534
0
    }
535
0
  }
536
0
  if (!isNull && !temp->isUndefined()) {
537
0
    if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mProtocol)) {
538
0
      return false;
539
0
    }
540
0
  } else {
541
0
    static const char16_t data[] = { 0 };
542
0
    mProtocol.Rebind(data, ArrayLength(data) - 1);
543
0
  }
544
0
  mIsAnyMemberPresent = true;
545
0
  return true;
546
0
}
547
548
bool
549
RTCDataChannelInit::Init(const nsAString& aJSON)
550
0
{
551
0
  AutoJSAPI jsapi;
552
0
  JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
553
0
  if (!cleanGlobal) {
554
0
    return false;
555
0
  }
556
0
  if (!jsapi.Init(cleanGlobal)) {
557
0
    return false;
558
0
  }
559
0
  JSContext* cx = jsapi.cx();
560
0
  JS::Rooted<JS::Value> json(cx);
561
0
  bool ok = ParseJSON(cx, aJSON, &json);
562
0
  NS_ENSURE_TRUE(ok, false);
563
0
  return Init(cx, json);
564
0
}
565
566
bool
567
RTCDataChannelInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
568
0
{
569
0
  RTCDataChannelInitAtoms* atomsCache = GetAtomCache<RTCDataChannelInitAtoms>(cx);
570
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
571
0
    return false;
572
0
  }
573
0
574
0
  JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
575
0
  if (!obj) {
576
0
    return false;
577
0
  }
578
0
  rval.set(JS::ObjectValue(*obj));
579
0
580
0
  if (mId.WasPassed()) {
581
0
    do {
582
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
583
0
      JS::Rooted<JS::Value> temp(cx);
584
0
      uint16_t const & currentValue = mId.InternalValue();
585
0
      temp.setInt32(int32_t(currentValue));
586
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->id_id, temp, JSPROP_ENUMERATE)) {
587
0
        return false;
588
0
      }
589
0
      break;
590
0
    } while(false);
591
0
  }
592
0
593
0
  if (mMaxPacketLifeTime.WasPassed()) {
594
0
    do {
595
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
596
0
      JS::Rooted<JS::Value> temp(cx);
597
0
      uint16_t const & currentValue = mMaxPacketLifeTime.InternalValue();
598
0
      temp.setInt32(int32_t(currentValue));
599
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->maxPacketLifeTime_id, temp, JSPROP_ENUMERATE)) {
600
0
        return false;
601
0
      }
602
0
      break;
603
0
    } while(false);
604
0
  }
605
0
606
0
  if (mMaxRetransmitTime.WasPassed()) {
607
0
    do {
608
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
609
0
      JS::Rooted<JS::Value> temp(cx);
610
0
      uint16_t const & currentValue = mMaxRetransmitTime.InternalValue();
611
0
      temp.setInt32(int32_t(currentValue));
612
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->maxRetransmitTime_id, temp, JSPROP_ENUMERATE)) {
613
0
        return false;
614
0
      }
615
0
      break;
616
0
    } while(false);
617
0
  }
618
0
619
0
  if (mMaxRetransmits.WasPassed()) {
620
0
    do {
621
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
622
0
      JS::Rooted<JS::Value> temp(cx);
623
0
      uint16_t const & currentValue = mMaxRetransmits.InternalValue();
624
0
      temp.setInt32(int32_t(currentValue));
625
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->maxRetransmits_id, temp, JSPROP_ENUMERATE)) {
626
0
        return false;
627
0
      }
628
0
      break;
629
0
    } while(false);
630
0
  }
631
0
632
0
  do {
633
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
634
0
    JS::Rooted<JS::Value> temp(cx);
635
0
    bool const & currentValue = mNegotiated;
636
0
    temp.setBoolean(currentValue);
637
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->negotiated_id, temp, JSPROP_ENUMERATE)) {
638
0
      return false;
639
0
    }
640
0
    break;
641
0
  } while(false);
642
0
643
0
  do {
644
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
645
0
    JS::Rooted<JS::Value> temp(cx);
646
0
    bool const & currentValue = mOrdered;
647
0
    temp.setBoolean(currentValue);
648
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->ordered_id, temp, JSPROP_ENUMERATE)) {
649
0
      return false;
650
0
    }
651
0
    break;
652
0
  } while(false);
653
0
654
0
  do {
655
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
656
0
    JS::Rooted<JS::Value> temp(cx);
657
0
    nsString const & currentValue = mProtocol;
658
0
    if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
659
0
      return false;
660
0
    }
661
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->protocol_id, temp, JSPROP_ENUMERATE)) {
662
0
      return false;
663
0
    }
664
0
    break;
665
0
  } while(false);
666
0
667
0
  return true;
668
0
}
669
670
bool
671
RTCDataChannelInit::ToJSON(nsAString& aJSON) const
672
0
{
673
0
  AutoJSAPI jsapi;
674
0
  jsapi.Init();
675
0
  JSContext *cx = jsapi.cx();
676
0
  // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
677
0
  // because we'll only be creating objects, in ways that have no
678
0
  // side-effects, followed by a call to JS::ToJSONMaybeSafely,
679
0
  // which likewise guarantees no side-effects for the sorts of
680
0
  // things we will pass it.
681
0
  JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal());
682
0
  JS::Rooted<JS::Value> val(cx);
683
0
  if (!ToObjectInternal(cx, &val)) {
684
0
    return false;
685
0
  }
686
0
  JS::Rooted<JSObject*> obj(cx, &val.toObject());
687
0
  return StringifyToJSON(cx, obj, aJSON);
688
0
}
689
690
void
691
RTCDataChannelInit::TraceDictionary(JSTracer* trc)
692
0
{
693
0
}
694
695
RTCDataChannelInit&
696
RTCDataChannelInit::operator=(const RTCDataChannelInit& aOther)
697
0
{
698
0
  DictionaryBase::operator=(aOther);
699
0
  mId.Reset();
700
0
  if (aOther.mId.WasPassed()) {
701
0
    mId.Construct(aOther.mId.Value());
702
0
  }
703
0
  mMaxPacketLifeTime.Reset();
704
0
  if (aOther.mMaxPacketLifeTime.WasPassed()) {
705
0
    mMaxPacketLifeTime.Construct(aOther.mMaxPacketLifeTime.Value());
706
0
  }
707
0
  mMaxRetransmitTime.Reset();
708
0
  if (aOther.mMaxRetransmitTime.WasPassed()) {
709
0
    mMaxRetransmitTime.Construct(aOther.mMaxRetransmitTime.Value());
710
0
  }
711
0
  mMaxRetransmits.Reset();
712
0
  if (aOther.mMaxRetransmits.WasPassed()) {
713
0
    mMaxRetransmits.Construct(aOther.mMaxRetransmits.Value());
714
0
  }
715
0
  mNegotiated = aOther.mNegotiated;
716
0
  mOrdered = aOther.mOrdered;
717
0
  mProtocol = aOther.mProtocol;
718
0
  return *this;
719
0
}
720
721
namespace binding_detail {
722
} // namespace binding_detail
723
724
725
bool
726
RTCIceCandidateInitOrRTCIceCandidate::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
727
0
{
728
0
  switch (mType) {
729
0
    case eUninitialized: {
730
0
      return false;
731
0
      break;
732
0
    }
733
0
    case eRTCIceCandidateInit: {
734
0
      if (!mValue.mRTCIceCandidateInit.Value().ToObjectInternal(cx, rval)) {
735
0
        return false;
736
0
      }
737
0
      return true;
738
0
      break;
739
0
    }
740
0
    case eRTCIceCandidate: {
741
0
      if (!GetOrCreateDOMReflector(cx, mValue.mRTCIceCandidate.Value(), rval)) {
742
0
        MOZ_ASSERT(JS_IsExceptionPending(cx));
743
0
        return false;
744
0
      }
745
0
      return true;
746
0
      break;
747
0
    }
748
0
    default: {
749
0
      return false;
750
0
      break;
751
0
    }
752
0
  }
753
0
754
0
  return false;
755
0
}
756
757
758
RTCIceCandidateInit&
759
OwningRTCIceCandidateInitOrRTCIceCandidate::RawSetAsRTCIceCandidateInit()
760
0
{
761
0
  if (mType == eRTCIceCandidateInit) {
762
0
    return mValue.mRTCIceCandidateInit.Value();
763
0
  }
764
0
  MOZ_ASSERT(mType == eUninitialized);
765
0
  mType = eRTCIceCandidateInit;
766
0
  return mValue.mRTCIceCandidateInit.SetValue();
767
0
}
768
769
RTCIceCandidateInit&
770
OwningRTCIceCandidateInitOrRTCIceCandidate::SetAsRTCIceCandidateInit()
771
0
{
772
0
  if (mType == eRTCIceCandidateInit) {
773
0
    return mValue.mRTCIceCandidateInit.Value();
774
0
  }
775
0
  Uninit();
776
0
  mType = eRTCIceCandidateInit;
777
0
  return mValue.mRTCIceCandidateInit.SetValue();
778
0
}
779
780
bool
781
OwningRTCIceCandidateInitOrRTCIceCandidate::TrySetToRTCIceCandidateInit(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
782
0
{
783
0
  tryNext = false;
784
0
  { // scope for memberSlot
785
0
    RTCIceCandidateInit& memberSlot = RawSetAsRTCIceCandidateInit();
786
0
    if (!IsConvertibleToDictionary(value)) {
787
0
      DestroyRTCIceCandidateInit();
788
0
      tryNext = true;
789
0
      return true;
790
0
    }
791
0
    if (!memberSlot.Init(cx, value,  "Member of RTCIceCandidateInitOrRTCIceCandidate", passedToJSImpl)) {
792
0
      return false;
793
0
    }
794
0
  }
795
0
  return true;
796
0
}
797
798
void
799
OwningRTCIceCandidateInitOrRTCIceCandidate::DestroyRTCIceCandidateInit()
800
0
{
801
0
  MOZ_ASSERT(IsRTCIceCandidateInit(), "Wrong type!");
802
0
  mValue.mRTCIceCandidateInit.Destroy();
803
0
  mType = eUninitialized;
804
0
}
805
806
807
808
809
OwningNonNull<mozilla::dom::RTCIceCandidate>&
810
OwningRTCIceCandidateInitOrRTCIceCandidate::RawSetAsRTCIceCandidate()
811
0
{
812
0
  if (mType == eRTCIceCandidate) {
813
0
    return mValue.mRTCIceCandidate.Value();
814
0
  }
815
0
  MOZ_ASSERT(mType == eUninitialized);
816
0
  mType = eRTCIceCandidate;
817
0
  return mValue.mRTCIceCandidate.SetValue();
818
0
}
819
820
OwningNonNull<mozilla::dom::RTCIceCandidate>&
821
OwningRTCIceCandidateInitOrRTCIceCandidate::SetAsRTCIceCandidate()
822
0
{
823
0
  if (mType == eRTCIceCandidate) {
824
0
    return mValue.mRTCIceCandidate.Value();
825
0
  }
826
0
  Uninit();
827
0
  mType = eRTCIceCandidate;
828
0
  return mValue.mRTCIceCandidate.SetValue();
829
0
}
830
831
bool
832
OwningRTCIceCandidateInitOrRTCIceCandidate::TrySetToRTCIceCandidate(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
833
0
{
834
0
  tryNext = false;
835
0
  { // scope for memberSlot
836
0
    OwningNonNull<mozilla::dom::RTCIceCandidate>& memberSlot = RawSetAsRTCIceCandidate();
837
0
    static_assert(IsRefcounted<mozilla::dom::RTCIceCandidate>::value, "We can only store refcounted classes.");{
838
0
      nsresult rv = UnwrapObject<prototypes::id::RTCIceCandidate, mozilla::dom::RTCIceCandidate>(value, memberSlot);
839
0
      if (NS_FAILED(rv)) {
840
0
        DestroyRTCIceCandidate();
841
0
        tryNext = true;
842
0
        return true;
843
0
      }
844
0
    }
845
0
  }
846
0
  return true;
847
0
}
848
849
void
850
OwningRTCIceCandidateInitOrRTCIceCandidate::DestroyRTCIceCandidate()
851
0
{
852
0
  MOZ_ASSERT(IsRTCIceCandidate(), "Wrong type!");
853
0
  mValue.mRTCIceCandidate.Destroy();
854
0
  mType = eUninitialized;
855
0
}
856
857
858
859
860
void
861
OwningRTCIceCandidateInitOrRTCIceCandidate::Uninit()
862
{
863
  switch (mType) {
864
    case eUninitialized: {
865
      break;
866
    }
867
    case eRTCIceCandidateInit: {
868
      DestroyRTCIceCandidateInit();
869
      break;
870
    }
871
    case eRTCIceCandidate: {
872
      DestroyRTCIceCandidate();
873
      break;
874
    }
875
  }
876
}
877
878
bool
879
OwningRTCIceCandidateInitOrRTCIceCandidate::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
880
0
{
881
0
  switch (mType) {
882
0
    case eUninitialized: {
883
0
      return false;
884
0
      break;
885
0
    }
886
0
    case eRTCIceCandidateInit: {
887
0
      if (!mValue.mRTCIceCandidateInit.Value().ToObjectInternal(cx, rval)) {
888
0
        return false;
889
0
      }
890
0
      return true;
891
0
      break;
892
0
    }
893
0
    case eRTCIceCandidate: {
894
0
      if (!GetOrCreateDOMReflector(cx, mValue.mRTCIceCandidate.Value(), rval)) {
895
0
        MOZ_ASSERT(JS_IsExceptionPending(cx));
896
0
        return false;
897
0
      }
898
0
      return true;
899
0
      break;
900
0
    }
901
0
    default: {
902
0
      return false;
903
0
      break;
904
0
    }
905
0
  }
906
0
907
0
  return false;
908
0
}
909
910
void
911
OwningRTCIceCandidateInitOrRTCIceCandidate::TraceUnion(JSTracer* trc)
912
0
{
913
0
}
914
915
OwningRTCIceCandidateInitOrRTCIceCandidate&
916
OwningRTCIceCandidateInitOrRTCIceCandidate::operator=(const OwningRTCIceCandidateInitOrRTCIceCandidate& aOther)
917
0
{
918
0
  switch (aOther.mType) {
919
0
    case eUninitialized: {
920
0
      MOZ_ASSERT(mType == eUninitialized,
921
0
                 "We need to destroy ourselves?");
922
0
      break;
923
0
    }
924
0
    case eRTCIceCandidateInit: {
925
0
      SetAsRTCIceCandidateInit() = aOther.GetAsRTCIceCandidateInit();
926
0
      break;
927
0
    }
928
0
    case eRTCIceCandidate: {
929
0
      SetAsRTCIceCandidate() = aOther.GetAsRTCIceCandidate();
930
0
      break;
931
0
    }
932
0
  }
933
0
  return *this;
934
0
}
935
936
937
938
RTCOfferAnswerOptions::RTCOfferAnswerOptions()
939
0
{
940
0
  // Safe to pass a null context if we pass a null value
941
0
  Init(nullptr, JS::NullHandleValue);
942
0
}
943
944
945
946
bool
947
RTCOfferAnswerOptions::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
948
0
{
949
0
  // Passing a null JSContext is OK only if we're initing from null,
950
0
  // Since in that case we will not have to do any property gets
951
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
952
0
  // checkers by static analysis tools
953
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
954
0
  if (!IsConvertibleToDictionary(val)) {
955
0
    return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
956
0
  }
957
0
958
0
  return true;
959
0
}
960
961
bool
962
RTCOfferAnswerOptions::Init(const nsAString& aJSON)
963
0
{
964
0
  AutoJSAPI jsapi;
965
0
  JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
966
0
  if (!cleanGlobal) {
967
0
    return false;
968
0
  }
969
0
  if (!jsapi.Init(cleanGlobal)) {
970
0
    return false;
971
0
  }
972
0
  JSContext* cx = jsapi.cx();
973
0
  JS::Rooted<JS::Value> json(cx);
974
0
  bool ok = ParseJSON(cx, aJSON, &json);
975
0
  NS_ENSURE_TRUE(ok, false);
976
0
  return Init(cx, json);
977
0
}
978
979
bool
980
RTCOfferAnswerOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
981
0
{
982
0
  JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
983
0
  if (!obj) {
984
0
    return false;
985
0
  }
986
0
  rval.set(JS::ObjectValue(*obj));
987
0
988
0
989
0
  return true;
990
0
}
991
992
bool
993
RTCOfferAnswerOptions::ToJSON(nsAString& aJSON) const
994
0
{
995
0
  AutoJSAPI jsapi;
996
0
  jsapi.Init();
997
0
  JSContext *cx = jsapi.cx();
998
0
  // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
999
0
  // because we'll only be creating objects, in ways that have no
1000
0
  // side-effects, followed by a call to JS::ToJSONMaybeSafely,
1001
0
  // which likewise guarantees no side-effects for the sorts of
1002
0
  // things we will pass it.
1003
0
  JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal());
1004
0
  JS::Rooted<JS::Value> val(cx);
1005
0
  if (!ToObjectInternal(cx, &val)) {
1006
0
    return false;
1007
0
  }
1008
0
  JS::Rooted<JSObject*> obj(cx, &val.toObject());
1009
0
  return StringifyToJSON(cx, obj, aJSON);
1010
0
}
1011
1012
void
1013
RTCOfferAnswerOptions::TraceDictionary(JSTracer* trc)
1014
0
{
1015
0
}
1016
1017
RTCOfferAnswerOptions&
1018
RTCOfferAnswerOptions::operator=(const RTCOfferAnswerOptions& aOther)
1019
0
{
1020
0
  DictionaryBase::operator=(aOther);
1021
0
  return *this;
1022
0
}
1023
1024
namespace binding_detail {
1025
} // namespace binding_detail
1026
1027
1028
1029
RTCAnswerOptions::RTCAnswerOptions()
1030
  : RTCOfferAnswerOptions(FastDictionaryInitializer())
1031
0
{
1032
0
  // Safe to pass a null context if we pass a null value
1033
0
  Init(nullptr, JS::NullHandleValue);
1034
0
}
1035
1036
1037
1038
bool
1039
RTCAnswerOptions::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
1040
0
{
1041
0
  // Passing a null JSContext is OK only if we're initing from null,
1042
0
  // Since in that case we will not have to do any property gets
1043
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
1044
0
  // checkers by static analysis tools
1045
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
1046
0
  // Per spec, we init the parent's members first
1047
0
  if (!RTCOfferAnswerOptions::Init(cx, val)) {
1048
0
    return false;
1049
0
  }
1050
0
1051
0
  return true;
1052
0
}
1053
1054
bool
1055
RTCAnswerOptions::Init(const nsAString& aJSON)
1056
0
{
1057
0
  AutoJSAPI jsapi;
1058
0
  JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
1059
0
  if (!cleanGlobal) {
1060
0
    return false;
1061
0
  }
1062
0
  if (!jsapi.Init(cleanGlobal)) {
1063
0
    return false;
1064
0
  }
1065
0
  JSContext* cx = jsapi.cx();
1066
0
  JS::Rooted<JS::Value> json(cx);
1067
0
  bool ok = ParseJSON(cx, aJSON, &json);
1068
0
  NS_ENSURE_TRUE(ok, false);
1069
0
  return Init(cx, json);
1070
0
}
1071
1072
bool
1073
RTCAnswerOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
1074
0
{
1075
0
  // Per spec, we define the parent's members first
1076
0
  if (!RTCOfferAnswerOptions::ToObjectInternal(cx, rval)) {
1077
0
    return false;
1078
0
  }
1079
0
  JS::Rooted<JSObject*> obj(cx, &rval.toObject());
1080
0
1081
0
1082
0
  return true;
1083
0
}
1084
1085
bool
1086
RTCAnswerOptions::ToJSON(nsAString& aJSON) const
1087
0
{
1088
0
  AutoJSAPI jsapi;
1089
0
  jsapi.Init();
1090
0
  JSContext *cx = jsapi.cx();
1091
0
  // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
1092
0
  // because we'll only be creating objects, in ways that have no
1093
0
  // side-effects, followed by a call to JS::ToJSONMaybeSafely,
1094
0
  // which likewise guarantees no side-effects for the sorts of
1095
0
  // things we will pass it.
1096
0
  JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal());
1097
0
  JS::Rooted<JS::Value> val(cx);
1098
0
  if (!ToObjectInternal(cx, &val)) {
1099
0
    return false;
1100
0
  }
1101
0
  JS::Rooted<JSObject*> obj(cx, &val.toObject());
1102
0
  return StringifyToJSON(cx, obj, aJSON);
1103
0
}
1104
1105
void
1106
RTCAnswerOptions::TraceDictionary(JSTracer* trc)
1107
0
{
1108
0
  RTCOfferAnswerOptions::TraceDictionary(trc);
1109
0
}
1110
1111
RTCAnswerOptions&
1112
RTCAnswerOptions::operator=(const RTCAnswerOptions& aOther)
1113
0
{
1114
0
  RTCOfferAnswerOptions::operator=(aOther);
1115
0
  return *this;
1116
0
}
1117
1118
namespace binding_detail {
1119
} // namespace binding_detail
1120
1121
1122
1123
RTCOfferOptions::RTCOfferOptions()
1124
  : RTCOfferAnswerOptions(FastDictionaryInitializer())
1125
0
{
1126
0
  // Safe to pass a null context if we pass a null value
1127
0
  Init(nullptr, JS::NullHandleValue);
1128
0
}
1129
1130
1131
1132
bool
1133
RTCOfferOptions::InitIds(JSContext* cx, RTCOfferOptionsAtoms* atomsCache)
1134
0
{
1135
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
1136
0
1137
0
  // Initialize these in reverse order so that any failure leaves the first one
1138
0
  // uninitialized.
1139
0
  if (!atomsCache->offerToReceiveVideo_id.init(cx, "offerToReceiveVideo") ||
1140
0
      !atomsCache->offerToReceiveAudio_id.init(cx, "offerToReceiveAudio") ||
1141
0
      !atomsCache->iceRestart_id.init(cx, "iceRestart")) {
1142
0
    return false;
1143
0
  }
1144
0
  return true;
1145
0
}
1146
1147
bool
1148
RTCOfferOptions::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
1149
0
{
1150
0
  // Passing a null JSContext is OK only if we're initing from null,
1151
0
  // Since in that case we will not have to do any property gets
1152
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
1153
0
  // checkers by static analysis tools
1154
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
1155
0
  RTCOfferOptionsAtoms* atomsCache = nullptr;
1156
0
  if (cx) {
1157
0
    atomsCache = GetAtomCache<RTCOfferOptionsAtoms>(cx);
1158
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
1159
0
      return false;
1160
0
    }
1161
0
  }
1162
0
1163
0
  // Per spec, we init the parent's members first
1164
0
  if (!RTCOfferAnswerOptions::Init(cx, val)) {
1165
0
    return false;
1166
0
  }
1167
0
1168
0
  bool isNull = val.isNullOrUndefined();
1169
0
  // We only need these if !isNull, in which case we have |cx|.
1170
0
  Maybe<JS::Rooted<JSObject *> > object;
1171
0
  Maybe<JS::Rooted<JS::Value> > temp;
1172
0
  if (!isNull) {
1173
0
    MOZ_ASSERT(cx);
1174
0
    object.emplace(cx, &val.toObject());
1175
0
    temp.emplace(cx);
1176
0
  }
1177
0
  if (!isNull) {
1178
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->iceRestart_id, temp.ptr())) {
1179
0
      return false;
1180
0
    }
1181
0
  }
1182
0
  if (!isNull && !temp->isUndefined()) {
1183
0
    if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mIceRestart)) {
1184
0
      return false;
1185
0
    }
1186
0
  } else {
1187
0
    mIceRestart = false;
1188
0
  }
1189
0
  mIsAnyMemberPresent = true;
1190
0
1191
0
  if (!isNull) {
1192
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->offerToReceiveAudio_id, temp.ptr())) {
1193
0
      return false;
1194
0
    }
1195
0
  }
1196
0
  if (!isNull && !temp->isUndefined()) {
1197
0
    mOfferToReceiveAudio.Construct();
1198
0
    if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &(mOfferToReceiveAudio.Value()))) {
1199
0
      return false;
1200
0
    }
1201
0
    mIsAnyMemberPresent = true;
1202
0
  }
1203
0
1204
0
  if (!isNull) {
1205
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->offerToReceiveVideo_id, temp.ptr())) {
1206
0
      return false;
1207
0
    }
1208
0
  }
1209
0
  if (!isNull && !temp->isUndefined()) {
1210
0
    mOfferToReceiveVideo.Construct();
1211
0
    if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &(mOfferToReceiveVideo.Value()))) {
1212
0
      return false;
1213
0
    }
1214
0
    mIsAnyMemberPresent = true;
1215
0
  }
1216
0
  return true;
1217
0
}
1218
1219
bool
1220
RTCOfferOptions::Init(const nsAString& aJSON)
1221
0
{
1222
0
  AutoJSAPI jsapi;
1223
0
  JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
1224
0
  if (!cleanGlobal) {
1225
0
    return false;
1226
0
  }
1227
0
  if (!jsapi.Init(cleanGlobal)) {
1228
0
    return false;
1229
0
  }
1230
0
  JSContext* cx = jsapi.cx();
1231
0
  JS::Rooted<JS::Value> json(cx);
1232
0
  bool ok = ParseJSON(cx, aJSON, &json);
1233
0
  NS_ENSURE_TRUE(ok, false);
1234
0
  return Init(cx, json);
1235
0
}
1236
1237
bool
1238
RTCOfferOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
1239
0
{
1240
0
  RTCOfferOptionsAtoms* atomsCache = GetAtomCache<RTCOfferOptionsAtoms>(cx);
1241
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
1242
0
    return false;
1243
0
  }
1244
0
1245
0
  // Per spec, we define the parent's members first
1246
0
  if (!RTCOfferAnswerOptions::ToObjectInternal(cx, rval)) {
1247
0
    return false;
1248
0
  }
1249
0
  JS::Rooted<JSObject*> obj(cx, &rval.toObject());
1250
0
1251
0
  do {
1252
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
1253
0
    JS::Rooted<JS::Value> temp(cx);
1254
0
    bool const & currentValue = mIceRestart;
1255
0
    temp.setBoolean(currentValue);
1256
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->iceRestart_id, temp, JSPROP_ENUMERATE)) {
1257
0
      return false;
1258
0
    }
1259
0
    break;
1260
0
  } while(false);
1261
0
1262
0
  if (mOfferToReceiveAudio.WasPassed()) {
1263
0
    do {
1264
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
1265
0
      JS::Rooted<JS::Value> temp(cx);
1266
0
      bool const & currentValue = mOfferToReceiveAudio.InternalValue();
1267
0
      temp.setBoolean(currentValue);
1268
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->offerToReceiveAudio_id, temp, JSPROP_ENUMERATE)) {
1269
0
        return false;
1270
0
      }
1271
0
      break;
1272
0
    } while(false);
1273
0
  }
1274
0
1275
0
  if (mOfferToReceiveVideo.WasPassed()) {
1276
0
    do {
1277
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
1278
0
      JS::Rooted<JS::Value> temp(cx);
1279
0
      bool const & currentValue = mOfferToReceiveVideo.InternalValue();
1280
0
      temp.setBoolean(currentValue);
1281
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->offerToReceiveVideo_id, temp, JSPROP_ENUMERATE)) {
1282
0
        return false;
1283
0
      }
1284
0
      break;
1285
0
    } while(false);
1286
0
  }
1287
0
1288
0
  return true;
1289
0
}
1290
1291
bool
1292
RTCOfferOptions::ToJSON(nsAString& aJSON) const
1293
0
{
1294
0
  AutoJSAPI jsapi;
1295
0
  jsapi.Init();
1296
0
  JSContext *cx = jsapi.cx();
1297
0
  // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
1298
0
  // because we'll only be creating objects, in ways that have no
1299
0
  // side-effects, followed by a call to JS::ToJSONMaybeSafely,
1300
0
  // which likewise guarantees no side-effects for the sorts of
1301
0
  // things we will pass it.
1302
0
  JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal());
1303
0
  JS::Rooted<JS::Value> val(cx);
1304
0
  if (!ToObjectInternal(cx, &val)) {
1305
0
    return false;
1306
0
  }
1307
0
  JS::Rooted<JSObject*> obj(cx, &val.toObject());
1308
0
  return StringifyToJSON(cx, obj, aJSON);
1309
0
}
1310
1311
void
1312
RTCOfferOptions::TraceDictionary(JSTracer* trc)
1313
0
{
1314
0
  RTCOfferAnswerOptions::TraceDictionary(trc);
1315
0
}
1316
1317
RTCOfferOptions&
1318
RTCOfferOptions::operator=(const RTCOfferOptions& aOther)
1319
0
{
1320
0
  RTCOfferAnswerOptions::operator=(aOther);
1321
0
  mIceRestart = aOther.mIceRestart;
1322
0
  mOfferToReceiveAudio.Reset();
1323
0
  if (aOther.mOfferToReceiveAudio.WasPassed()) {
1324
0
    mOfferToReceiveAudio.Construct(aOther.mOfferToReceiveAudio.Value());
1325
0
  }
1326
0
  mOfferToReceiveVideo.Reset();
1327
0
  if (aOther.mOfferToReceiveVideo.WasPassed()) {
1328
0
    mOfferToReceiveVideo.Construct(aOther.mOfferToReceiveVideo.Value());
1329
0
  }
1330
0
  return *this;
1331
0
}
1332
1333
namespace binding_detail {
1334
} // namespace binding_detail
1335
1336
1337
void
1338
RTCSessionDescriptionCallback::Call(JSContext* cx, JS::Handle<JS::Value> aThisVal, const RTCSessionDescriptionInit& description, ErrorResult& aRv)
1339
0
{
1340
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
1341
0
  JS::AutoValueVector argv(cx);
1342
0
  if (!argv.resize(1)) {
1343
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
1344
0
    return;
1345
0
  }
1346
0
  unsigned argc = 1;
1347
0
1348
0
  do {
1349
0
    if (!description.ToObjectInternal(cx, argv[0])) {
1350
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
1351
0
      return;
1352
0
    }
1353
0
    break;
1354
0
  } while (false);
1355
0
1356
0
  JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback));
1357
0
  if (!JS::Call(cx, aThisVal, callable,
1358
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
1359
0
    aRv.NoteJSContextException(cx);
1360
0
    return;
1361
0
  }
1362
0
}
1363
1364
1365
1366
void
1367
RTCPeerConnectionErrorCallback::Call(JSContext* cx, JS::Handle<JS::Value> aThisVal, DOMException& error, ErrorResult& aRv)
1368
0
{
1369
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
1370
0
  JS::AutoValueVector argv(cx);
1371
0
  if (!argv.resize(1)) {
1372
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
1373
0
    return;
1374
0
  }
1375
0
  unsigned argc = 1;
1376
0
1377
0
  do {
1378
0
    if (!GetOrCreateDOMReflector(cx, error, argv[0])) {
1379
0
      MOZ_ASSERT(JS_IsExceptionPending(cx));
1380
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
1381
0
      return;
1382
0
    }
1383
0
    break;
1384
0
  } while (false);
1385
0
1386
0
  JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback));
1387
0
  if (!JS::Call(cx, aThisVal, callable,
1388
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
1389
0
    aRv.NoteJSContextException(cx);
1390
0
    return;
1391
0
  }
1392
0
}
1393
1394
1395
1396
void
1397
RTCStatsCallback::Call(JSContext* cx, JS::Handle<JS::Value> aThisVal, RTCStatsReport& report, ErrorResult& aRv)
1398
0
{
1399
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
1400
0
  JS::AutoValueVector argv(cx);
1401
0
  if (!argv.resize(1)) {
1402
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
1403
0
    return;
1404
0
  }
1405
0
  unsigned argc = 1;
1406
0
1407
0
  do {
1408
0
    if (!GetOrCreateDOMReflector(cx, report, argv[0])) {
1409
0
      MOZ_ASSERT(JS_IsExceptionPending(cx));
1410
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
1411
0
      return;
1412
0
    }
1413
0
    break;
1414
0
  } while (false);
1415
0
1416
0
  JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback));
1417
0
  if (!JS::Call(cx, aThisVal, callable,
1418
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
1419
0
    aRv.NoteJSContextException(cx);
1420
0
    return;
1421
0
  }
1422
0
}
1423
1424
1425
1426
void
1427
mozPacketCallback::Call(JSContext* cx, JS::Handle<JS::Value> aThisVal, uint32_t level, mozPacketDumpType type, bool sending, JS::Handle<JSObject*> packet, ErrorResult& aRv)
1428
0
{
1429
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
1430
0
  JS::AutoValueVector argv(cx);
1431
0
  if (!argv.resize(4)) {
1432
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
1433
0
    return;
1434
0
  }
1435
0
  unsigned argc = 4;
1436
0
1437
0
  do {
1438
0
    JS::ExposeObjectToActiveJS(packet);
1439
0
    argv[3].setObject(*packet);
1440
0
    if (!MaybeWrapNonDOMObjectValue(cx, argv[3])) {
1441
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
1442
0
      return;
1443
0
    }
1444
0
    break;
1445
0
  } while (false);
1446
0
1447
0
  do {
1448
0
    argv[2].setBoolean(sending);
1449
0
    break;
1450
0
  } while (false);
1451
0
1452
0
  do {
1453
0
    if (!ToJSValue(cx, type, argv[1])) {
1454
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
1455
0
      return;
1456
0
    }
1457
0
    break;
1458
0
  } while (false);
1459
0
1460
0
  do {
1461
0
    argv[0].setNumber(level);
1462
0
    break;
1463
0
  } while (false);
1464
0
1465
0
  JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback));
1466
0
  if (!JS::Call(cx, aThisVal, callable,
1467
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
1468
0
    aRv.NoteJSContextException(cx);
1469
0
    return;
1470
0
  }
1471
0
}
1472
1473
1474
1475
namespace binding_detail {
1476
} // namespace binding_detail
1477
1478
1479
namespace binding_detail {
1480
} // namespace binding_detail
1481
1482
1483
namespace binding_detail {
1484
} // namespace binding_detail
1485
1486
1487
namespace binding_detail {
1488
} // namespace binding_detail
1489
1490
1491
namespace RTCPeerConnection_Binding {
1492
1493
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventTarget_Binding::NativeType>::value,
1494
              "Can't inherit from an interface with a different ownership model.");
1495
1496
static bool
1497
generateCertificate(JSContext* cx, unsigned argc, JS::Value* vp)
1498
0
{
1499
0
  AUTO_PROFILER_LABEL_FAST("RTCPeerConnection.generateCertificate", DOM, cx);
1500
0
1501
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
1502
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
1503
0
1504
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
1505
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCPeerConnection.generateCertificate");
1506
0
  }
1507
0
  GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
1508
0
  if (global.Failed()) {
1509
0
    return false;
1510
0
  }
1511
0
1512
0
  ObjectOrString arg0;
1513
0
  ObjectOrStringArgument arg0_holder(arg0);
1514
0
  {
1515
0
    bool done = false, failed = false, tryNext;
1516
0
    if (args[0].isObject()) {
1517
0
      if (!arg0_holder.SetToObject(cx, &args[0].toObject(), true)) {
1518
0
        return false;
1519
0
      }
1520
0
      done = true;
1521
0
    } else {
1522
0
      do {
1523
0
        done = (failed = !arg0_holder.TrySetToString(cx, args[0], tryNext)) || !tryNext;
1524
0
        break;
1525
0
      } while (false);
1526
0
    }
1527
0
    if (failed) {
1528
0
      return false;
1529
0
    }
1530
0
    if (!done) {
1531
0
      ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "Argument 1 of RTCPeerConnection.generateCertificate", "Object");
1532
0
      return false;
1533
0
    }
1534
0
  }
1535
0
  FastErrorResult rv;
1536
0
  auto result(StrongOrRawPtr<Promise>(mozilla::dom::RTCCertificate::GenerateCertificate(global, Constify(arg0), rv)));
1537
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1538
0
    return false;
1539
0
  }
1540
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1541
0
  if (!ToJSValue(cx, result, args.rval())) {
1542
0
    return false;
1543
0
  }
1544
0
  return true;
1545
0
}
1546
1547
1548
static const JSJitInfo generateCertificate_methodinfo = {
1549
  { (JSJitGetterOp)generateCertificate },
1550
  { prototypes::id::_ID_Count }, { 0 }, JSJitInfo::StaticMethod,
1551
  JSJitInfo::AliasEverything, JSVAL_TYPE_MISSING, false, false,
1552
  false, false, 0
1553
};
1554
1555
MOZ_CAN_RUN_SCRIPT static bool
1556
setIdentityProvider(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
1557
0
{
1558
0
  AUTO_PROFILER_LABEL_FAST("RTCPeerConnection.setIdentityProvider", DOM, cx);
1559
0
1560
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
1561
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCPeerConnection.setIdentityProvider");
1562
0
  }
1563
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
1564
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
1565
0
  if (objIsXray) {
1566
0
    unwrappedObj.emplace(cx, obj);
1567
0
  }
1568
0
  binding_detail::FakeString arg0;
1569
0
  if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
1570
0
    return false;
1571
0
  }
1572
0
  binding_detail::FastRTCIdentityProviderOptions arg1;
1573
0
  if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue,  "Argument 2 of RTCPeerConnection.setIdentityProvider", true)) {
1574
0
    return false;
1575
0
  }
1576
0
  if (objIsXray) {
1577
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
1578
0
    if (!unwrappedObj.ref()) {
1579
0
      return false;
1580
0
    }
1581
0
  }
1582
0
  FastErrorResult rv;
1583
0
  self->SetIdentityProvider(NonNullHelper(Constify(arg0)), Constify(arg1), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
1584
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1585
0
    return false;
1586
0
  }
1587
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1588
0
  args.rval().setUndefined();
1589
0
  return true;
1590
0
}
1591
1592
static const JSJitInfo setIdentityProvider_methodinfo = {
1593
  { (JSJitGetterOp)setIdentityProvider },
1594
  { prototypes::id::RTCPeerConnection },
1595
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
1596
  JSJitInfo::Method,
1597
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1598
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
1599
  false,  /* isInfallible. False in setters. */
1600
  false,  /* isMovable.  Not relevant for setters. */
1601
  false, /* isEliminatable.  Not relevant for setters. */
1602
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1603
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1604
  false,  /* isTypedMethod.  Only relevant for methods. */
1605
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1606
};
1607
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1608
static_assert(0 < 1, "There is no slot for us");
1609
1610
MOZ_CAN_RUN_SCRIPT static bool
1611
getIdentityAssertion(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
1612
0
{
1613
0
  AUTO_PROFILER_LABEL_FAST("RTCPeerConnection.getIdentityAssertion", DOM, cx);
1614
0
1615
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
1616
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
1617
0
  if (objIsXray) {
1618
0
    unwrappedObj.emplace(cx, obj);
1619
0
  }
1620
0
  if (objIsXray) {
1621
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
1622
0
    if (!unwrappedObj.ref()) {
1623
0
      return false;
1624
0
    }
1625
0
  }
1626
0
  FastErrorResult rv;
1627
0
  auto result(StrongOrRawPtr<Promise>(self->GetIdentityAssertion(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)))));
1628
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1629
0
    return false;
1630
0
  }
1631
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1632
0
  if (!ToJSValue(cx, result, args.rval())) {
1633
0
    return false;
1634
0
  }
1635
0
  return true;
1636
0
}
1637
1638
MOZ_CAN_RUN_SCRIPT static bool
1639
getIdentityAssertion_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
1640
0
{
1641
0
  bool ok = getIdentityAssertion(cx, obj, self, args);
1642
0
  if (ok) {
1643
0
    return true;
1644
0
  }
1645
0
  return ConvertExceptionToPromise(cx, args.rval());
1646
0
}
1647
1648
static const JSJitInfo getIdentityAssertion_methodinfo = {
1649
  { (JSJitGetterOp)getIdentityAssertion_promiseWrapper },
1650
  { prototypes::id::RTCPeerConnection },
1651
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
1652
  JSJitInfo::Method,
1653
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1654
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
1655
  false,  /* isInfallible. False in setters. */
1656
  false,  /* isMovable.  Not relevant for setters. */
1657
  false, /* isEliminatable.  Not relevant for setters. */
1658
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1659
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1660
  false,  /* isTypedMethod.  Only relevant for methods. */
1661
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1662
};
1663
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1664
static_assert(0 < 1, "There is no slot for us");
1665
1666
MOZ_CAN_RUN_SCRIPT static bool
1667
createOffer(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
1668
0
{
1669
0
  AUTO_PROFILER_LABEL_FAST("RTCPeerConnection.createOffer", DOM, cx);
1670
0
1671
0
  unsigned argcount = std::min(args.length(), 3u);
1672
0
  switch (argcount) {
1673
0
    case 0: {
1674
0
      MOZ_FALLTHROUGH;
1675
0
    }
1676
0
    case 1: {
1677
0
      Maybe<JS::Rooted<JSObject*> > unwrappedObj;
1678
0
      bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
1679
0
      if (objIsXray) {
1680
0
        unwrappedObj.emplace(cx, obj);
1681
0
      }
1682
0
      binding_detail::FastRTCOfferOptions arg0;
1683
0
      if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue,  "Argument 1 of RTCPeerConnection.createOffer", true)) {
1684
0
        return false;
1685
0
      }
1686
0
      if (objIsXray) {
1687
0
        unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
1688
0
        if (!unwrappedObj.ref()) {
1689
0
          return false;
1690
0
        }
1691
0
      }
1692
0
      FastErrorResult rv;
1693
0
      auto result(StrongOrRawPtr<Promise>(self->CreateOffer(Constify(arg0), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)))));
1694
0
      if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1695
0
        return false;
1696
0
      }
1697
0
      MOZ_ASSERT(!JS_IsExceptionPending(cx));
1698
0
      if (!ToJSValue(cx, result, args.rval())) {
1699
0
        return false;
1700
0
      }
1701
0
      return true;
1702
0
      break;
1703
0
    }
1704
0
    case 2: {
1705
0
      MOZ_FALLTHROUGH;
1706
0
    }
1707
0
    case 3: {
1708
0
      Maybe<JS::Rooted<JSObject*> > unwrappedObj;
1709
0
      bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
1710
0
      if (objIsXray) {
1711
0
        unwrappedObj.emplace(cx, obj);
1712
0
      }
1713
0
      RootedCallback<OwningNonNull<binding_detail::FastRTCSessionDescriptionCallback>> arg0(cx);
1714
0
      if (args[0].isObject()) {
1715
0
        if (JS::IsCallable(&args[0].toObject())) {
1716
0
        { // scope for tempRoot and tempGlobalRoot if needed
1717
0
          arg0 = new binding_detail::FastRTCSessionDescriptionCallback(&args[0].toObject(), JS::CurrentGlobalOrNull(cx));
1718
0
        }
1719
0
        } else {
1720
0
          ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 1 of RTCPeerConnection.createOffer");
1721
0
          return false;
1722
0
        }
1723
0
      } else {
1724
0
        ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of RTCPeerConnection.createOffer");
1725
0
        return false;
1726
0
      }
1727
0
      RootedCallback<OwningNonNull<binding_detail::FastRTCPeerConnectionErrorCallback>> arg1(cx);
1728
0
      if (args[1].isObject()) {
1729
0
        if (JS::IsCallable(&args[1].toObject())) {
1730
0
        { // scope for tempRoot and tempGlobalRoot if needed
1731
0
          arg1 = new binding_detail::FastRTCPeerConnectionErrorCallback(&args[1].toObject(), JS::CurrentGlobalOrNull(cx));
1732
0
        }
1733
0
        } else {
1734
0
          ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 2 of RTCPeerConnection.createOffer");
1735
0
          return false;
1736
0
        }
1737
0
      } else {
1738
0
        ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of RTCPeerConnection.createOffer");
1739
0
        return false;
1740
0
      }
1741
0
      binding_detail::FastRTCOfferOptions arg2;
1742
0
      if (!arg2.Init(cx, (args.hasDefined(2)) ? args[2] : JS::NullHandleValue,  "Argument 3 of RTCPeerConnection.createOffer", true)) {
1743
0
        return false;
1744
0
      }
1745
0
      if (objIsXray) {
1746
0
        unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
1747
0
        if (!unwrappedObj.ref()) {
1748
0
          return false;
1749
0
        }
1750
0
      }
1751
0
      FastErrorResult rv;
1752
0
      auto result(StrongOrRawPtr<Promise>(self->CreateOffer(NonNullHelper(arg0), NonNullHelper(arg1), Constify(arg2), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)))));
1753
0
      if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1754
0
        return false;
1755
0
      }
1756
0
      MOZ_ASSERT(!JS_IsExceptionPending(cx));
1757
0
      if (!ToJSValue(cx, result, args.rval())) {
1758
0
        return false;
1759
0
      }
1760
0
      return true;
1761
0
      break;
1762
0
    }
1763
0
    default: {
1764
0
      return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCPeerConnection.createOffer");
1765
0
      break;
1766
0
    }
1767
0
  }
1768
0
  MOZ_CRASH("We have an always-returning default case");
1769
0
  return false;
1770
0
}
1771
1772
MOZ_CAN_RUN_SCRIPT static bool
1773
createOffer_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
1774
0
{
1775
0
  bool ok = createOffer(cx, obj, self, args);
1776
0
  if (ok) {
1777
0
    return true;
1778
0
  }
1779
0
  return ConvertExceptionToPromise(cx, args.rval());
1780
0
}
1781
1782
static const JSJitInfo createOffer_methodinfo = {
1783
  { (JSJitGetterOp)createOffer_promiseWrapper },
1784
  { prototypes::id::RTCPeerConnection },
1785
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
1786
  JSJitInfo::Method,
1787
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1788
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
1789
  false,  /* isInfallible. False in setters. */
1790
  false,  /* isMovable.  Not relevant for setters. */
1791
  false, /* isEliminatable.  Not relevant for setters. */
1792
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1793
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1794
  false,  /* isTypedMethod.  Only relevant for methods. */
1795
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1796
};
1797
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1798
static_assert(0 < 1, "There is no slot for us");
1799
1800
MOZ_CAN_RUN_SCRIPT static bool
1801
createAnswer(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
1802
0
{
1803
0
  AUTO_PROFILER_LABEL_FAST("RTCPeerConnection.createAnswer", DOM, cx);
1804
0
1805
0
  unsigned argcount = std::min(args.length(), 2u);
1806
0
  switch (argcount) {
1807
0
    case 0: {
1808
0
      MOZ_FALLTHROUGH;
1809
0
    }
1810
0
    case 1: {
1811
0
      Maybe<JS::Rooted<JSObject*> > unwrappedObj;
1812
0
      bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
1813
0
      if (objIsXray) {
1814
0
        unwrappedObj.emplace(cx, obj);
1815
0
      }
1816
0
      binding_detail::FastRTCAnswerOptions arg0;
1817
0
      if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue,  "Argument 1 of RTCPeerConnection.createAnswer", true)) {
1818
0
        return false;
1819
0
      }
1820
0
      if (objIsXray) {
1821
0
        unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
1822
0
        if (!unwrappedObj.ref()) {
1823
0
          return false;
1824
0
        }
1825
0
      }
1826
0
      FastErrorResult rv;
1827
0
      auto result(StrongOrRawPtr<Promise>(self->CreateAnswer(Constify(arg0), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)))));
1828
0
      if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1829
0
        return false;
1830
0
      }
1831
0
      MOZ_ASSERT(!JS_IsExceptionPending(cx));
1832
0
      if (!ToJSValue(cx, result, args.rval())) {
1833
0
        return false;
1834
0
      }
1835
0
      return true;
1836
0
      break;
1837
0
    }
1838
0
    case 2: {
1839
0
      Maybe<JS::Rooted<JSObject*> > unwrappedObj;
1840
0
      bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
1841
0
      if (objIsXray) {
1842
0
        unwrappedObj.emplace(cx, obj);
1843
0
      }
1844
0
      RootedCallback<OwningNonNull<binding_detail::FastRTCSessionDescriptionCallback>> arg0(cx);
1845
0
      if (args[0].isObject()) {
1846
0
        if (JS::IsCallable(&args[0].toObject())) {
1847
0
        { // scope for tempRoot and tempGlobalRoot if needed
1848
0
          arg0 = new binding_detail::FastRTCSessionDescriptionCallback(&args[0].toObject(), JS::CurrentGlobalOrNull(cx));
1849
0
        }
1850
0
        } else {
1851
0
          ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 1 of RTCPeerConnection.createAnswer");
1852
0
          return false;
1853
0
        }
1854
0
      } else {
1855
0
        ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of RTCPeerConnection.createAnswer");
1856
0
        return false;
1857
0
      }
1858
0
      RootedCallback<OwningNonNull<binding_detail::FastRTCPeerConnectionErrorCallback>> arg1(cx);
1859
0
      if (args[1].isObject()) {
1860
0
        if (JS::IsCallable(&args[1].toObject())) {
1861
0
        { // scope for tempRoot and tempGlobalRoot if needed
1862
0
          arg1 = new binding_detail::FastRTCPeerConnectionErrorCallback(&args[1].toObject(), JS::CurrentGlobalOrNull(cx));
1863
0
        }
1864
0
        } else {
1865
0
          ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 2 of RTCPeerConnection.createAnswer");
1866
0
          return false;
1867
0
        }
1868
0
      } else {
1869
0
        ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of RTCPeerConnection.createAnswer");
1870
0
        return false;
1871
0
      }
1872
0
      if (objIsXray) {
1873
0
        unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
1874
0
        if (!unwrappedObj.ref()) {
1875
0
          return false;
1876
0
        }
1877
0
      }
1878
0
      FastErrorResult rv;
1879
0
      auto result(StrongOrRawPtr<Promise>(self->CreateAnswer(NonNullHelper(arg0), NonNullHelper(arg1), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)))));
1880
0
      if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1881
0
        return false;
1882
0
      }
1883
0
      MOZ_ASSERT(!JS_IsExceptionPending(cx));
1884
0
      if (!ToJSValue(cx, result, args.rval())) {
1885
0
        return false;
1886
0
      }
1887
0
      return true;
1888
0
      break;
1889
0
    }
1890
0
    default: {
1891
0
      return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCPeerConnection.createAnswer");
1892
0
      break;
1893
0
    }
1894
0
  }
1895
0
  MOZ_CRASH("We have an always-returning default case");
1896
0
  return false;
1897
0
}
1898
1899
MOZ_CAN_RUN_SCRIPT static bool
1900
createAnswer_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
1901
0
{
1902
0
  bool ok = createAnswer(cx, obj, self, args);
1903
0
  if (ok) {
1904
0
    return true;
1905
0
  }
1906
0
  return ConvertExceptionToPromise(cx, args.rval());
1907
0
}
1908
1909
static const JSJitInfo createAnswer_methodinfo = {
1910
  { (JSJitGetterOp)createAnswer_promiseWrapper },
1911
  { prototypes::id::RTCPeerConnection },
1912
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
1913
  JSJitInfo::Method,
1914
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1915
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
1916
  false,  /* isInfallible. False in setters. */
1917
  false,  /* isMovable.  Not relevant for setters. */
1918
  false, /* isEliminatable.  Not relevant for setters. */
1919
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1920
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1921
  false,  /* isTypedMethod.  Only relevant for methods. */
1922
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1923
};
1924
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1925
static_assert(0 < 1, "There is no slot for us");
1926
1927
MOZ_CAN_RUN_SCRIPT static bool
1928
setLocalDescription(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
1929
0
{
1930
0
  AUTO_PROFILER_LABEL_FAST("RTCPeerConnection.setLocalDescription", DOM, cx);
1931
0
1932
0
  unsigned argcount = std::min(args.length(), 3u);
1933
0
  switch (argcount) {
1934
0
    case 1: {
1935
0
      Maybe<JS::Rooted<JSObject*> > unwrappedObj;
1936
0
      bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
1937
0
      if (objIsXray) {
1938
0
        unwrappedObj.emplace(cx, obj);
1939
0
      }
1940
0
      binding_detail::FastRTCSessionDescriptionInit arg0;
1941
0
      if (!arg0.Init(cx, args[0],  "Argument 1 of RTCPeerConnection.setLocalDescription", true)) {
1942
0
        return false;
1943
0
      }
1944
0
      if (objIsXray) {
1945
0
        unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
1946
0
        if (!unwrappedObj.ref()) {
1947
0
          return false;
1948
0
        }
1949
0
      }
1950
0
      FastErrorResult rv;
1951
0
      auto result(StrongOrRawPtr<Promise>(self->SetLocalDescription(Constify(arg0), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)))));
1952
0
      if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1953
0
        return false;
1954
0
      }
1955
0
      MOZ_ASSERT(!JS_IsExceptionPending(cx));
1956
0
      if (!ToJSValue(cx, result, args.rval())) {
1957
0
        return false;
1958
0
      }
1959
0
      return true;
1960
0
      break;
1961
0
    }
1962
0
    case 3: {
1963
0
      Maybe<JS::Rooted<JSObject*> > unwrappedObj;
1964
0
      bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
1965
0
      if (objIsXray) {
1966
0
        unwrappedObj.emplace(cx, obj);
1967
0
      }
1968
0
      binding_detail::FastRTCSessionDescriptionInit arg0;
1969
0
      if (!arg0.Init(cx, args[0],  "Argument 1 of RTCPeerConnection.setLocalDescription", true)) {
1970
0
        return false;
1971
0
      }
1972
0
      RootedCallback<OwningNonNull<binding_detail::FastVoidFunction>> arg1(cx);
1973
0
      if (args[1].isObject()) {
1974
0
        if (JS::IsCallable(&args[1].toObject())) {
1975
0
        { // scope for tempRoot and tempGlobalRoot if needed
1976
0
          arg1 = new binding_detail::FastVoidFunction(&args[1].toObject(), JS::CurrentGlobalOrNull(cx));
1977
0
        }
1978
0
        } else {
1979
0
          ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 2 of RTCPeerConnection.setLocalDescription");
1980
0
          return false;
1981
0
        }
1982
0
      } else {
1983
0
        ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of RTCPeerConnection.setLocalDescription");
1984
0
        return false;
1985
0
      }
1986
0
      RootedCallback<OwningNonNull<binding_detail::FastRTCPeerConnectionErrorCallback>> arg2(cx);
1987
0
      if (args[2].isObject()) {
1988
0
        if (JS::IsCallable(&args[2].toObject())) {
1989
0
        { // scope for tempRoot and tempGlobalRoot if needed
1990
0
          arg2 = new binding_detail::FastRTCPeerConnectionErrorCallback(&args[2].toObject(), JS::CurrentGlobalOrNull(cx));
1991
0
        }
1992
0
        } else {
1993
0
          ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 3 of RTCPeerConnection.setLocalDescription");
1994
0
          return false;
1995
0
        }
1996
0
      } else {
1997
0
        ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 3 of RTCPeerConnection.setLocalDescription");
1998
0
        return false;
1999
0
      }
2000
0
      if (objIsXray) {
2001
0
        unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
2002
0
        if (!unwrappedObj.ref()) {
2003
0
          return false;
2004
0
        }
2005
0
      }
2006
0
      FastErrorResult rv;
2007
0
      auto result(StrongOrRawPtr<Promise>(self->SetLocalDescription(Constify(arg0), NonNullHelper(arg1), NonNullHelper(arg2), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)))));
2008
0
      if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2009
0
        return false;
2010
0
      }
2011
0
      MOZ_ASSERT(!JS_IsExceptionPending(cx));
2012
0
      if (!ToJSValue(cx, result, args.rval())) {
2013
0
        return false;
2014
0
      }
2015
0
      return true;
2016
0
      break;
2017
0
    }
2018
0
    default: {
2019
0
      return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCPeerConnection.setLocalDescription");
2020
0
      break;
2021
0
    }
2022
0
  }
2023
0
  MOZ_CRASH("We have an always-returning default case");
2024
0
  return false;
2025
0
}
2026
2027
MOZ_CAN_RUN_SCRIPT static bool
2028
setLocalDescription_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
2029
0
{
2030
0
  bool ok = setLocalDescription(cx, obj, self, args);
2031
0
  if (ok) {
2032
0
    return true;
2033
0
  }
2034
0
  return ConvertExceptionToPromise(cx, args.rval());
2035
0
}
2036
2037
static const JSJitInfo setLocalDescription_methodinfo = {
2038
  { (JSJitGetterOp)setLocalDescription_promiseWrapper },
2039
  { prototypes::id::RTCPeerConnection },
2040
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
2041
  JSJitInfo::Method,
2042
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
2043
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
2044
  false,  /* isInfallible. False in setters. */
2045
  false,  /* isMovable.  Not relevant for setters. */
2046
  false, /* isEliminatable.  Not relevant for setters. */
2047
  false, /* isAlwaysInSlot.  Only relevant for getters. */
2048
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
2049
  false,  /* isTypedMethod.  Only relevant for methods. */
2050
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
2051
};
2052
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
2053
static_assert(0 < 1, "There is no slot for us");
2054
2055
MOZ_CAN_RUN_SCRIPT static bool
2056
setRemoteDescription(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
2057
0
{
2058
0
  AUTO_PROFILER_LABEL_FAST("RTCPeerConnection.setRemoteDescription", DOM, cx);
2059
0
2060
0
  unsigned argcount = std::min(args.length(), 3u);
2061
0
  switch (argcount) {
2062
0
    case 1: {
2063
0
      Maybe<JS::Rooted<JSObject*> > unwrappedObj;
2064
0
      bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2065
0
      if (objIsXray) {
2066
0
        unwrappedObj.emplace(cx, obj);
2067
0
      }
2068
0
      binding_detail::FastRTCSessionDescriptionInit arg0;
2069
0
      if (!arg0.Init(cx, args[0],  "Argument 1 of RTCPeerConnection.setRemoteDescription", true)) {
2070
0
        return false;
2071
0
      }
2072
0
      if (objIsXray) {
2073
0
        unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
2074
0
        if (!unwrappedObj.ref()) {
2075
0
          return false;
2076
0
        }
2077
0
      }
2078
0
      FastErrorResult rv;
2079
0
      auto result(StrongOrRawPtr<Promise>(self->SetRemoteDescription(Constify(arg0), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)))));
2080
0
      if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2081
0
        return false;
2082
0
      }
2083
0
      MOZ_ASSERT(!JS_IsExceptionPending(cx));
2084
0
      if (!ToJSValue(cx, result, args.rval())) {
2085
0
        return false;
2086
0
      }
2087
0
      return true;
2088
0
      break;
2089
0
    }
2090
0
    case 3: {
2091
0
      Maybe<JS::Rooted<JSObject*> > unwrappedObj;
2092
0
      bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2093
0
      if (objIsXray) {
2094
0
        unwrappedObj.emplace(cx, obj);
2095
0
      }
2096
0
      binding_detail::FastRTCSessionDescriptionInit arg0;
2097
0
      if (!arg0.Init(cx, args[0],  "Argument 1 of RTCPeerConnection.setRemoteDescription", true)) {
2098
0
        return false;
2099
0
      }
2100
0
      RootedCallback<OwningNonNull<binding_detail::FastVoidFunction>> arg1(cx);
2101
0
      if (args[1].isObject()) {
2102
0
        if (JS::IsCallable(&args[1].toObject())) {
2103
0
        { // scope for tempRoot and tempGlobalRoot if needed
2104
0
          arg1 = new binding_detail::FastVoidFunction(&args[1].toObject(), JS::CurrentGlobalOrNull(cx));
2105
0
        }
2106
0
        } else {
2107
0
          ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 2 of RTCPeerConnection.setRemoteDescription");
2108
0
          return false;
2109
0
        }
2110
0
      } else {
2111
0
        ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of RTCPeerConnection.setRemoteDescription");
2112
0
        return false;
2113
0
      }
2114
0
      RootedCallback<OwningNonNull<binding_detail::FastRTCPeerConnectionErrorCallback>> arg2(cx);
2115
0
      if (args[2].isObject()) {
2116
0
        if (JS::IsCallable(&args[2].toObject())) {
2117
0
        { // scope for tempRoot and tempGlobalRoot if needed
2118
0
          arg2 = new binding_detail::FastRTCPeerConnectionErrorCallback(&args[2].toObject(), JS::CurrentGlobalOrNull(cx));
2119
0
        }
2120
0
        } else {
2121
0
          ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 3 of RTCPeerConnection.setRemoteDescription");
2122
0
          return false;
2123
0
        }
2124
0
      } else {
2125
0
        ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 3 of RTCPeerConnection.setRemoteDescription");
2126
0
        return false;
2127
0
      }
2128
0
      if (objIsXray) {
2129
0
        unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
2130
0
        if (!unwrappedObj.ref()) {
2131
0
          return false;
2132
0
        }
2133
0
      }
2134
0
      FastErrorResult rv;
2135
0
      auto result(StrongOrRawPtr<Promise>(self->SetRemoteDescription(Constify(arg0), NonNullHelper(arg1), NonNullHelper(arg2), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)))));
2136
0
      if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2137
0
        return false;
2138
0
      }
2139
0
      MOZ_ASSERT(!JS_IsExceptionPending(cx));
2140
0
      if (!ToJSValue(cx, result, args.rval())) {
2141
0
        return false;
2142
0
      }
2143
0
      return true;
2144
0
      break;
2145
0
    }
2146
0
    default: {
2147
0
      return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCPeerConnection.setRemoteDescription");
2148
0
      break;
2149
0
    }
2150
0
  }
2151
0
  MOZ_CRASH("We have an always-returning default case");
2152
0
  return false;
2153
0
}
2154
2155
MOZ_CAN_RUN_SCRIPT static bool
2156
setRemoteDescription_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
2157
0
{
2158
0
  bool ok = setRemoteDescription(cx, obj, self, args);
2159
0
  if (ok) {
2160
0
    return true;
2161
0
  }
2162
0
  return ConvertExceptionToPromise(cx, args.rval());
2163
0
}
2164
2165
static const JSJitInfo setRemoteDescription_methodinfo = {
2166
  { (JSJitGetterOp)setRemoteDescription_promiseWrapper },
2167
  { prototypes::id::RTCPeerConnection },
2168
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
2169
  JSJitInfo::Method,
2170
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
2171
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
2172
  false,  /* isInfallible. False in setters. */
2173
  false,  /* isMovable.  Not relevant for setters. */
2174
  false, /* isEliminatable.  Not relevant for setters. */
2175
  false, /* isAlwaysInSlot.  Only relevant for getters. */
2176
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
2177
  false,  /* isTypedMethod.  Only relevant for methods. */
2178
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
2179
};
2180
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
2181
static_assert(0 < 1, "There is no slot for us");
2182
2183
MOZ_CAN_RUN_SCRIPT static bool
2184
get_localDescription(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
2185
0
{
2186
0
  AUTO_PROFILER_LABEL_FAST("get RTCPeerConnection.localDescription", DOM, cx);
2187
0
2188
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
2189
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2190
0
  if (objIsXray) {
2191
0
    unwrappedObj.emplace(cx, obj);
2192
0
  }
2193
0
  if (objIsXray) {
2194
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
2195
0
    if (!unwrappedObj.ref()) {
2196
0
      return false;
2197
0
    }
2198
0
  }
2199
0
  FastErrorResult rv;
2200
0
  auto result(StrongOrRawPtr<mozilla::dom::RTCSessionDescription>(self->GetLocalDescription(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)))));
2201
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2202
0
    return false;
2203
0
  }
2204
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
2205
0
  if (!result) {
2206
0
    args.rval().setNull();
2207
0
    return true;
2208
0
  }
2209
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
2210
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
2211
0
    return false;
2212
0
  }
2213
0
  return true;
2214
0
}
2215
2216
static const JSJitInfo localDescription_getterinfo = {
2217
  { (JSJitGetterOp)get_localDescription },
2218
  { prototypes::id::RTCPeerConnection },
2219
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
2220
  JSJitInfo::Getter,
2221
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
2222
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
2223
  false,  /* isInfallible. False in setters. */
2224
  false,  /* isMovable.  Not relevant for setters. */
2225
  false, /* isEliminatable.  Not relevant for setters. */
2226
  false, /* isAlwaysInSlot.  Only relevant for getters. */
2227
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
2228
  false,  /* isTypedMethod.  Only relevant for methods. */
2229
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
2230
};
2231
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
2232
static_assert(0 < 1, "There is no slot for us");
2233
2234
MOZ_CAN_RUN_SCRIPT static bool
2235
get_currentLocalDescription(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
2236
0
{
2237
0
  AUTO_PROFILER_LABEL_FAST("get RTCPeerConnection.currentLocalDescription", DOM, cx);
2238
0
2239
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
2240
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2241
0
  if (objIsXray) {
2242
0
    unwrappedObj.emplace(cx, obj);
2243
0
  }
2244
0
  if (objIsXray) {
2245
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
2246
0
    if (!unwrappedObj.ref()) {
2247
0
      return false;
2248
0
    }
2249
0
  }
2250
0
  FastErrorResult rv;
2251
0
  auto result(StrongOrRawPtr<mozilla::dom::RTCSessionDescription>(self->GetCurrentLocalDescription(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)))));
2252
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2253
0
    return false;
2254
0
  }
2255
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
2256
0
  if (!result) {
2257
0
    args.rval().setNull();
2258
0
    return true;
2259
0
  }
2260
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
2261
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
2262
0
    return false;
2263
0
  }
2264
0
  return true;
2265
0
}
2266
2267
static const JSJitInfo currentLocalDescription_getterinfo = {
2268
  { (JSJitGetterOp)get_currentLocalDescription },
2269
  { prototypes::id::RTCPeerConnection },
2270
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
2271
  JSJitInfo::Getter,
2272
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
2273
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
2274
  false,  /* isInfallible. False in setters. */
2275
  false,  /* isMovable.  Not relevant for setters. */
2276
  false, /* isEliminatable.  Not relevant for setters. */
2277
  false, /* isAlwaysInSlot.  Only relevant for getters. */
2278
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
2279
  false,  /* isTypedMethod.  Only relevant for methods. */
2280
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
2281
};
2282
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
2283
static_assert(0 < 1, "There is no slot for us");
2284
2285
MOZ_CAN_RUN_SCRIPT static bool
2286
get_pendingLocalDescription(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
2287
0
{
2288
0
  AUTO_PROFILER_LABEL_FAST("get RTCPeerConnection.pendingLocalDescription", DOM, cx);
2289
0
2290
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
2291
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2292
0
  if (objIsXray) {
2293
0
    unwrappedObj.emplace(cx, obj);
2294
0
  }
2295
0
  if (objIsXray) {
2296
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
2297
0
    if (!unwrappedObj.ref()) {
2298
0
      return false;
2299
0
    }
2300
0
  }
2301
0
  FastErrorResult rv;
2302
0
  auto result(StrongOrRawPtr<mozilla::dom::RTCSessionDescription>(self->GetPendingLocalDescription(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)))));
2303
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2304
0
    return false;
2305
0
  }
2306
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
2307
0
  if (!result) {
2308
0
    args.rval().setNull();
2309
0
    return true;
2310
0
  }
2311
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
2312
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
2313
0
    return false;
2314
0
  }
2315
0
  return true;
2316
0
}
2317
2318
static const JSJitInfo pendingLocalDescription_getterinfo = {
2319
  { (JSJitGetterOp)get_pendingLocalDescription },
2320
  { prototypes::id::RTCPeerConnection },
2321
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
2322
  JSJitInfo::Getter,
2323
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
2324
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
2325
  false,  /* isInfallible. False in setters. */
2326
  false,  /* isMovable.  Not relevant for setters. */
2327
  false, /* isEliminatable.  Not relevant for setters. */
2328
  false, /* isAlwaysInSlot.  Only relevant for getters. */
2329
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
2330
  false,  /* isTypedMethod.  Only relevant for methods. */
2331
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
2332
};
2333
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
2334
static_assert(0 < 1, "There is no slot for us");
2335
2336
MOZ_CAN_RUN_SCRIPT static bool
2337
get_remoteDescription(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
2338
0
{
2339
0
  AUTO_PROFILER_LABEL_FAST("get RTCPeerConnection.remoteDescription", DOM, cx);
2340
0
2341
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
2342
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2343
0
  if (objIsXray) {
2344
0
    unwrappedObj.emplace(cx, obj);
2345
0
  }
2346
0
  if (objIsXray) {
2347
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
2348
0
    if (!unwrappedObj.ref()) {
2349
0
      return false;
2350
0
    }
2351
0
  }
2352
0
  FastErrorResult rv;
2353
0
  auto result(StrongOrRawPtr<mozilla::dom::RTCSessionDescription>(self->GetRemoteDescription(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)))));
2354
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2355
0
    return false;
2356
0
  }
2357
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
2358
0
  if (!result) {
2359
0
    args.rval().setNull();
2360
0
    return true;
2361
0
  }
2362
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
2363
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
2364
0
    return false;
2365
0
  }
2366
0
  return true;
2367
0
}
2368
2369
static const JSJitInfo remoteDescription_getterinfo = {
2370
  { (JSJitGetterOp)get_remoteDescription },
2371
  { prototypes::id::RTCPeerConnection },
2372
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
2373
  JSJitInfo::Getter,
2374
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
2375
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
2376
  false,  /* isInfallible. False in setters. */
2377
  false,  /* isMovable.  Not relevant for setters. */
2378
  false, /* isEliminatable.  Not relevant for setters. */
2379
  false, /* isAlwaysInSlot.  Only relevant for getters. */
2380
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
2381
  false,  /* isTypedMethod.  Only relevant for methods. */
2382
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
2383
};
2384
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
2385
static_assert(0 < 1, "There is no slot for us");
2386
2387
MOZ_CAN_RUN_SCRIPT static bool
2388
get_currentRemoteDescription(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
2389
0
{
2390
0
  AUTO_PROFILER_LABEL_FAST("get RTCPeerConnection.currentRemoteDescription", DOM, cx);
2391
0
2392
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
2393
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2394
0
  if (objIsXray) {
2395
0
    unwrappedObj.emplace(cx, obj);
2396
0
  }
2397
0
  if (objIsXray) {
2398
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
2399
0
    if (!unwrappedObj.ref()) {
2400
0
      return false;
2401
0
    }
2402
0
  }
2403
0
  FastErrorResult rv;
2404
0
  auto result(StrongOrRawPtr<mozilla::dom::RTCSessionDescription>(self->GetCurrentRemoteDescription(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)))));
2405
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2406
0
    return false;
2407
0
  }
2408
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
2409
0
  if (!result) {
2410
0
    args.rval().setNull();
2411
0
    return true;
2412
0
  }
2413
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
2414
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
2415
0
    return false;
2416
0
  }
2417
0
  return true;
2418
0
}
2419
2420
static const JSJitInfo currentRemoteDescription_getterinfo = {
2421
  { (JSJitGetterOp)get_currentRemoteDescription },
2422
  { prototypes::id::RTCPeerConnection },
2423
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
2424
  JSJitInfo::Getter,
2425
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
2426
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
2427
  false,  /* isInfallible. False in setters. */
2428
  false,  /* isMovable.  Not relevant for setters. */
2429
  false, /* isEliminatable.  Not relevant for setters. */
2430
  false, /* isAlwaysInSlot.  Only relevant for getters. */
2431
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
2432
  false,  /* isTypedMethod.  Only relevant for methods. */
2433
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
2434
};
2435
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
2436
static_assert(0 < 1, "There is no slot for us");
2437
2438
MOZ_CAN_RUN_SCRIPT static bool
2439
get_pendingRemoteDescription(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
2440
0
{
2441
0
  AUTO_PROFILER_LABEL_FAST("get RTCPeerConnection.pendingRemoteDescription", DOM, cx);
2442
0
2443
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
2444
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2445
0
  if (objIsXray) {
2446
0
    unwrappedObj.emplace(cx, obj);
2447
0
  }
2448
0
  if (objIsXray) {
2449
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
2450
0
    if (!unwrappedObj.ref()) {
2451
0
      return false;
2452
0
    }
2453
0
  }
2454
0
  FastErrorResult rv;
2455
0
  auto result(StrongOrRawPtr<mozilla::dom::RTCSessionDescription>(self->GetPendingRemoteDescription(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)))));
2456
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2457
0
    return false;
2458
0
  }
2459
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
2460
0
  if (!result) {
2461
0
    args.rval().setNull();
2462
0
    return true;
2463
0
  }
2464
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
2465
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
2466
0
    return false;
2467
0
  }
2468
0
  return true;
2469
0
}
2470
2471
static const JSJitInfo pendingRemoteDescription_getterinfo = {
2472
  { (JSJitGetterOp)get_pendingRemoteDescription },
2473
  { prototypes::id::RTCPeerConnection },
2474
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
2475
  JSJitInfo::Getter,
2476
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
2477
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
2478
  false,  /* isInfallible. False in setters. */
2479
  false,  /* isMovable.  Not relevant for setters. */
2480
  false, /* isEliminatable.  Not relevant for setters. */
2481
  false, /* isAlwaysInSlot.  Only relevant for getters. */
2482
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
2483
  false,  /* isTypedMethod.  Only relevant for methods. */
2484
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
2485
};
2486
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
2487
static_assert(0 < 1, "There is no slot for us");
2488
2489
MOZ_CAN_RUN_SCRIPT static bool
2490
get_signalingState(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
2491
0
{
2492
0
  AUTO_PROFILER_LABEL_FAST("get RTCPeerConnection.signalingState", DOM, cx);
2493
0
2494
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
2495
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2496
0
  if (objIsXray) {
2497
0
    unwrappedObj.emplace(cx, obj);
2498
0
  }
2499
0
  if (objIsXray) {
2500
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
2501
0
    if (!unwrappedObj.ref()) {
2502
0
      return false;
2503
0
    }
2504
0
  }
2505
0
  FastErrorResult rv;
2506
0
  RTCSignalingState result(self->GetSignalingState(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))));
2507
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2508
0
    return false;
2509
0
  }
2510
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
2511
0
  if (!ToJSValue(cx, result, args.rval())) {
2512
0
    return false;
2513
0
  }
2514
0
  return true;
2515
0
}
2516
2517
static const JSJitInfo signalingState_getterinfo = {
2518
  { (JSJitGetterOp)get_signalingState },
2519
  { prototypes::id::RTCPeerConnection },
2520
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
2521
  JSJitInfo::Getter,
2522
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
2523
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
2524
  false,  /* isInfallible. False in setters. */
2525
  false,  /* isMovable.  Not relevant for setters. */
2526
  false, /* isEliminatable.  Not relevant for setters. */
2527
  false, /* isAlwaysInSlot.  Only relevant for getters. */
2528
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
2529
  false,  /* isTypedMethod.  Only relevant for methods. */
2530
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
2531
};
2532
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
2533
static_assert(0 < 1, "There is no slot for us");
2534
2535
MOZ_CAN_RUN_SCRIPT static bool
2536
addIceCandidate(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
2537
0
{
2538
0
  AUTO_PROFILER_LABEL_FAST("RTCPeerConnection.addIceCandidate", DOM, cx);
2539
0
2540
0
  unsigned argcount = std::min(args.length(), 3u);
2541
0
  switch (argcount) {
2542
0
    case 1: {
2543
0
      Maybe<JS::Rooted<JSObject*> > unwrappedObj;
2544
0
      bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2545
0
      if (objIsXray) {
2546
0
        unwrappedObj.emplace(cx, obj);
2547
0
      }
2548
0
      Nullable<RTCIceCandidateInitOrRTCIceCandidate > arg0;
2549
0
      Maybe<RTCIceCandidateInitOrRTCIceCandidateArgument> arg0_holder;
2550
0
      if (args[0].isNullOrUndefined()) {
2551
0
        arg0.SetNull();
2552
0
      } else {
2553
0
        arg0_holder.emplace(arg0.SetValue());
2554
0
        {
2555
0
          bool done = false, failed = false, tryNext;
2556
0
          if (args[0].isObject()) {
2557
0
            done = (failed = !arg0_holder.ref().TrySetToRTCIceCandidate(cx, args[0], tryNext, true)) || !tryNext;
2558
0
2559
0
          }
2560
0
          if (!done) {
2561
0
            done = (failed = !arg0_holder.ref().TrySetToRTCIceCandidateInit(cx, args[0], tryNext, true)) || !tryNext;
2562
0
          }
2563
0
          if (failed) {
2564
0
            return false;
2565
0
          }
2566
0
          if (!done) {
2567
0
            ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "Argument 1 of RTCPeerConnection.addIceCandidate", "RTCIceCandidate, RTCIceCandidateInit");
2568
0
            return false;
2569
0
          }
2570
0
        }
2571
0
      }
2572
0
      if (objIsXray) {
2573
0
        unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
2574
0
        if (!unwrappedObj.ref()) {
2575
0
          return false;
2576
0
        }
2577
0
      }
2578
0
      FastErrorResult rv;
2579
0
      auto result(StrongOrRawPtr<Promise>(self->AddIceCandidate(Constify(arg0), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)))));
2580
0
      if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2581
0
        return false;
2582
0
      }
2583
0
      MOZ_ASSERT(!JS_IsExceptionPending(cx));
2584
0
      if (!ToJSValue(cx, result, args.rval())) {
2585
0
        return false;
2586
0
      }
2587
0
      return true;
2588
0
      break;
2589
0
    }
2590
0
    case 3: {
2591
0
      Maybe<JS::Rooted<JSObject*> > unwrappedObj;
2592
0
      bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2593
0
      if (objIsXray) {
2594
0
        unwrappedObj.emplace(cx, obj);
2595
0
      }
2596
0
      NonNull<mozilla::dom::RTCIceCandidate> arg0;
2597
0
      if (args[0].isObject()) {
2598
0
        {
2599
0
          nsresult rv = UnwrapObject<prototypes::id::RTCIceCandidate, mozilla::dom::RTCIceCandidate>(args[0], arg0);
2600
0
          if (NS_FAILED(rv)) {
2601
0
            ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of RTCPeerConnection.addIceCandidate", "RTCIceCandidate");
2602
0
            return false;
2603
0
          }
2604
0
        }
2605
0
      } else {
2606
0
        ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of RTCPeerConnection.addIceCandidate");
2607
0
        return false;
2608
0
      }
2609
0
      RootedCallback<OwningNonNull<binding_detail::FastVoidFunction>> arg1(cx);
2610
0
      if (args[1].isObject()) {
2611
0
        if (JS::IsCallable(&args[1].toObject())) {
2612
0
        { // scope for tempRoot and tempGlobalRoot if needed
2613
0
          arg1 = new binding_detail::FastVoidFunction(&args[1].toObject(), JS::CurrentGlobalOrNull(cx));
2614
0
        }
2615
0
        } else {
2616
0
          ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 2 of RTCPeerConnection.addIceCandidate");
2617
0
          return false;
2618
0
        }
2619
0
      } else {
2620
0
        ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of RTCPeerConnection.addIceCandidate");
2621
0
        return false;
2622
0
      }
2623
0
      RootedCallback<OwningNonNull<binding_detail::FastRTCPeerConnectionErrorCallback>> arg2(cx);
2624
0
      if (args[2].isObject()) {
2625
0
        if (JS::IsCallable(&args[2].toObject())) {
2626
0
        { // scope for tempRoot and tempGlobalRoot if needed
2627
0
          arg2 = new binding_detail::FastRTCPeerConnectionErrorCallback(&args[2].toObject(), JS::CurrentGlobalOrNull(cx));
2628
0
        }
2629
0
        } else {
2630
0
          ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 3 of RTCPeerConnection.addIceCandidate");
2631
0
          return false;
2632
0
        }
2633
0
      } else {
2634
0
        ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 3 of RTCPeerConnection.addIceCandidate");
2635
0
        return false;
2636
0
      }
2637
0
      if (objIsXray) {
2638
0
        unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
2639
0
        if (!unwrappedObj.ref()) {
2640
0
          return false;
2641
0
        }
2642
0
      }
2643
0
      FastErrorResult rv;
2644
0
      auto result(StrongOrRawPtr<Promise>(self->AddIceCandidate(MOZ_KnownLive(NonNullHelper(arg0)), NonNullHelper(arg1), NonNullHelper(arg2), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)))));
2645
0
      if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2646
0
        return false;
2647
0
      }
2648
0
      MOZ_ASSERT(!JS_IsExceptionPending(cx));
2649
0
      if (!ToJSValue(cx, result, args.rval())) {
2650
0
        return false;
2651
0
      }
2652
0
      return true;
2653
0
      break;
2654
0
    }
2655
0
    default: {
2656
0
      return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCPeerConnection.addIceCandidate");
2657
0
      break;
2658
0
    }
2659
0
  }
2660
0
  MOZ_CRASH("We have an always-returning default case");
2661
0
  return false;
2662
0
}
2663
2664
MOZ_CAN_RUN_SCRIPT static bool
2665
addIceCandidate_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
2666
0
{
2667
0
  bool ok = addIceCandidate(cx, obj, self, args);
2668
0
  if (ok) {
2669
0
    return true;
2670
0
  }
2671
0
  return ConvertExceptionToPromise(cx, args.rval());
2672
0
}
2673
2674
static const JSJitInfo addIceCandidate_methodinfo = {
2675
  { (JSJitGetterOp)addIceCandidate_promiseWrapper },
2676
  { prototypes::id::RTCPeerConnection },
2677
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
2678
  JSJitInfo::Method,
2679
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
2680
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
2681
  false,  /* isInfallible. False in setters. */
2682
  false,  /* isMovable.  Not relevant for setters. */
2683
  false, /* isEliminatable.  Not relevant for setters. */
2684
  false, /* isAlwaysInSlot.  Only relevant for getters. */
2685
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
2686
  false,  /* isTypedMethod.  Only relevant for methods. */
2687
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
2688
};
2689
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
2690
static_assert(0 < 1, "There is no slot for us");
2691
2692
MOZ_CAN_RUN_SCRIPT static bool
2693
get_canTrickleIceCandidates(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
2694
0
{
2695
0
  AUTO_PROFILER_LABEL_FAST("get RTCPeerConnection.canTrickleIceCandidates", DOM, cx);
2696
0
2697
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
2698
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2699
0
  if (objIsXray) {
2700
0
    unwrappedObj.emplace(cx, obj);
2701
0
  }
2702
0
  if (objIsXray) {
2703
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
2704
0
    if (!unwrappedObj.ref()) {
2705
0
      return false;
2706
0
    }
2707
0
  }
2708
0
  FastErrorResult rv;
2709
0
  Nullable<bool> result(self->GetCanTrickleIceCandidates(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))));
2710
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2711
0
    return false;
2712
0
  }
2713
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
2714
0
  if (result.IsNull()) {
2715
0
    args.rval().setNull();
2716
0
    return true;
2717
0
  }
2718
0
  args.rval().setBoolean(result.Value());
2719
0
  return true;
2720
0
}
2721
2722
static const JSJitInfo canTrickleIceCandidates_getterinfo = {
2723
  { (JSJitGetterOp)get_canTrickleIceCandidates },
2724
  { prototypes::id::RTCPeerConnection },
2725
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
2726
  JSJitInfo::Getter,
2727
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
2728
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
2729
  false,  /* isInfallible. False in setters. */
2730
  false,  /* isMovable.  Not relevant for setters. */
2731
  false, /* isEliminatable.  Not relevant for setters. */
2732
  false, /* isAlwaysInSlot.  Only relevant for getters. */
2733
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
2734
  false,  /* isTypedMethod.  Only relevant for methods. */
2735
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
2736
};
2737
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
2738
static_assert(0 < 1, "There is no slot for us");
2739
2740
MOZ_CAN_RUN_SCRIPT static bool
2741
get_iceGatheringState(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
2742
0
{
2743
0
  AUTO_PROFILER_LABEL_FAST("get RTCPeerConnection.iceGatheringState", DOM, cx);
2744
0
2745
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
2746
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2747
0
  if (objIsXray) {
2748
0
    unwrappedObj.emplace(cx, obj);
2749
0
  }
2750
0
  if (objIsXray) {
2751
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
2752
0
    if (!unwrappedObj.ref()) {
2753
0
      return false;
2754
0
    }
2755
0
  }
2756
0
  FastErrorResult rv;
2757
0
  RTCIceGatheringState result(self->GetIceGatheringState(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))));
2758
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2759
0
    return false;
2760
0
  }
2761
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
2762
0
  if (!ToJSValue(cx, result, args.rval())) {
2763
0
    return false;
2764
0
  }
2765
0
  return true;
2766
0
}
2767
2768
static const JSJitInfo iceGatheringState_getterinfo = {
2769
  { (JSJitGetterOp)get_iceGatheringState },
2770
  { prototypes::id::RTCPeerConnection },
2771
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
2772
  JSJitInfo::Getter,
2773
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
2774
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
2775
  false,  /* isInfallible. False in setters. */
2776
  false,  /* isMovable.  Not relevant for setters. */
2777
  false, /* isEliminatable.  Not relevant for setters. */
2778
  false, /* isAlwaysInSlot.  Only relevant for getters. */
2779
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
2780
  false,  /* isTypedMethod.  Only relevant for methods. */
2781
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
2782
};
2783
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
2784
static_assert(0 < 1, "There is no slot for us");
2785
2786
MOZ_CAN_RUN_SCRIPT static bool
2787
get_iceConnectionState(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
2788
0
{
2789
0
  AUTO_PROFILER_LABEL_FAST("get RTCPeerConnection.iceConnectionState", DOM, cx);
2790
0
2791
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
2792
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2793
0
  if (objIsXray) {
2794
0
    unwrappedObj.emplace(cx, obj);
2795
0
  }
2796
0
  if (objIsXray) {
2797
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
2798
0
    if (!unwrappedObj.ref()) {
2799
0
      return false;
2800
0
    }
2801
0
  }
2802
0
  FastErrorResult rv;
2803
0
  RTCIceConnectionState result(self->GetIceConnectionState(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))));
2804
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2805
0
    return false;
2806
0
  }
2807
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
2808
0
  if (!ToJSValue(cx, result, args.rval())) {
2809
0
    return false;
2810
0
  }
2811
0
  return true;
2812
0
}
2813
2814
static const JSJitInfo iceConnectionState_getterinfo = {
2815
  { (JSJitGetterOp)get_iceConnectionState },
2816
  { prototypes::id::RTCPeerConnection },
2817
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
2818
  JSJitInfo::Getter,
2819
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
2820
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
2821
  false,  /* isInfallible. False in setters. */
2822
  false,  /* isMovable.  Not relevant for setters. */
2823
  false, /* isEliminatable.  Not relevant for setters. */
2824
  false, /* isAlwaysInSlot.  Only relevant for getters. */
2825
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
2826
  false,  /* isTypedMethod.  Only relevant for methods. */
2827
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
2828
};
2829
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
2830
static_assert(0 < 1, "There is no slot for us");
2831
2832
MOZ_CAN_RUN_SCRIPT static bool
2833
get_peerIdentity(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
2834
0
{
2835
0
  AUTO_PROFILER_LABEL_FAST("get RTCPeerConnection.peerIdentity", DOM, cx);
2836
0
2837
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
2838
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2839
0
  if (objIsXray) {
2840
0
    unwrappedObj.emplace(cx, obj);
2841
0
  }
2842
0
  if (objIsXray) {
2843
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
2844
0
    if (!unwrappedObj.ref()) {
2845
0
      return false;
2846
0
    }
2847
0
  }
2848
0
  FastErrorResult rv;
2849
0
  auto result(StrongOrRawPtr<Promise>(self->GetPeerIdentity(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)))));
2850
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2851
0
    return false;
2852
0
  }
2853
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
2854
0
  if (!ToJSValue(cx, result, args.rval())) {
2855
0
    return false;
2856
0
  }
2857
0
  return true;
2858
0
}
2859
2860
MOZ_CAN_RUN_SCRIPT static bool
2861
get_peerIdentity_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
2862
0
{
2863
0
  bool ok = get_peerIdentity(cx, obj, self, args);
2864
0
  if (ok) {
2865
0
    return true;
2866
0
  }
2867
0
  return ConvertExceptionToPromise(cx, args.rval());
2868
0
}
2869
2870
static const JSJitInfo peerIdentity_getterinfo = {
2871
  { (JSJitGetterOp)get_peerIdentity_promiseWrapper },
2872
  { prototypes::id::RTCPeerConnection },
2873
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
2874
  JSJitInfo::Getter,
2875
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
2876
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
2877
  false,  /* isInfallible. False in setters. */
2878
  false,  /* isMovable.  Not relevant for setters. */
2879
  false, /* isEliminatable.  Not relevant for setters. */
2880
  false, /* isAlwaysInSlot.  Only relevant for getters. */
2881
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
2882
  false,  /* isTypedMethod.  Only relevant for methods. */
2883
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
2884
};
2885
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
2886
static_assert(0 < 1, "There is no slot for us");
2887
2888
MOZ_CAN_RUN_SCRIPT static bool
2889
get_idpLoginUrl(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
2890
0
{
2891
0
  AUTO_PROFILER_LABEL_FAST("get RTCPeerConnection.idpLoginUrl", DOM, cx);
2892
0
2893
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
2894
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2895
0
  if (objIsXray) {
2896
0
    unwrappedObj.emplace(cx, obj);
2897
0
  }
2898
0
  if (objIsXray) {
2899
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
2900
0
    if (!unwrappedObj.ref()) {
2901
0
      return false;
2902
0
    }
2903
0
  }
2904
0
  FastErrorResult rv;
2905
0
  DOMString result;
2906
0
  self->GetIdpLoginUrl(result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
2907
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2908
0
    return false;
2909
0
  }
2910
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
2911
0
  if (!xpc::StringToJsval(cx, result, args.rval())) {
2912
0
    return false;
2913
0
  }
2914
0
  return true;
2915
0
}
2916
2917
static const JSJitInfo idpLoginUrl_getterinfo = {
2918
  { (JSJitGetterOp)get_idpLoginUrl },
2919
  { prototypes::id::RTCPeerConnection },
2920
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
2921
  JSJitInfo::Getter,
2922
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
2923
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
2924
  false,  /* isInfallible. False in setters. */
2925
  false,  /* isMovable.  Not relevant for setters. */
2926
  false, /* isEliminatable.  Not relevant for setters. */
2927
  false, /* isAlwaysInSlot.  Only relevant for getters. */
2928
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
2929
  false,  /* isTypedMethod.  Only relevant for methods. */
2930
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
2931
};
2932
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
2933
static_assert(0 < 1, "There is no slot for us");
2934
2935
MOZ_CAN_RUN_SCRIPT static bool
2936
get_id(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
2937
0
{
2938
0
  AUTO_PROFILER_LABEL_FAST("get RTCPeerConnection.id", DOM, cx);
2939
0
2940
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
2941
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2942
0
  if (objIsXray) {
2943
0
    unwrappedObj.emplace(cx, obj);
2944
0
  }
2945
0
  if (objIsXray) {
2946
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
2947
0
    if (!unwrappedObj.ref()) {
2948
0
      return false;
2949
0
    }
2950
0
  }
2951
0
  FastErrorResult rv;
2952
0
  DOMString result;
2953
0
  self->GetId(result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
2954
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2955
0
    return false;
2956
0
  }
2957
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
2958
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
2959
0
    return false;
2960
0
  }
2961
0
  return true;
2962
0
}
2963
2964
MOZ_CAN_RUN_SCRIPT static bool
2965
set_id(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitSetterCallArgs args)
2966
0
{
2967
0
  AUTO_PROFILER_LABEL_FAST("set RTCPeerConnection.id", DOM, cx);
2968
0
2969
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
2970
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2971
0
  if (objIsXray) {
2972
0
    unwrappedObj.emplace(cx, obj);
2973
0
  }
2974
0
  binding_detail::FakeString arg0;
2975
0
  if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
2976
0
    return false;
2977
0
  }
2978
0
  if (objIsXray) {
2979
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
2980
0
    if (!unwrappedObj.ref()) {
2981
0
      return false;
2982
0
    }
2983
0
  }
2984
0
  FastErrorResult rv;
2985
0
  self->SetId(NonNullHelper(Constify(arg0)), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
2986
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2987
0
    return false;
2988
0
  }
2989
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
2990
0
2991
0
  return true;
2992
0
}
2993
2994
static const JSJitInfo id_getterinfo = {
2995
  { (JSJitGetterOp)get_id },
2996
  { prototypes::id::RTCPeerConnection },
2997
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
2998
  JSJitInfo::Getter,
2999
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
3000
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
3001
  false,  /* isInfallible. False in setters. */
3002
  false,  /* isMovable.  Not relevant for setters. */
3003
  false, /* isEliminatable.  Not relevant for setters. */
3004
  false, /* isAlwaysInSlot.  Only relevant for getters. */
3005
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
3006
  false,  /* isTypedMethod.  Only relevant for methods. */
3007
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
3008
};
3009
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
3010
static_assert(0 < 1, "There is no slot for us");
3011
static const JSJitInfo id_setterinfo = {
3012
  { (JSJitGetterOp)set_id },
3013
  { prototypes::id::RTCPeerConnection },
3014
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
3015
  JSJitInfo::Setter,
3016
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
3017
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
3018
  false,  /* isInfallible. False in setters. */
3019
  false,  /* isMovable.  Not relevant for setters. */
3020
  false, /* isEliminatable.  Not relevant for setters. */
3021
  false, /* isAlwaysInSlot.  Only relevant for getters. */
3022
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
3023
  false,  /* isTypedMethod.  Only relevant for methods. */
3024
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
3025
};
3026
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
3027
static_assert(0 < 1, "There is no slot for us");
3028
3029
MOZ_CAN_RUN_SCRIPT static bool
3030
getConfiguration(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
3031
0
{
3032
0
  AUTO_PROFILER_LABEL_FAST("RTCPeerConnection.getConfiguration", DOM, cx);
3033
0
3034
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
3035
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
3036
0
  if (objIsXray) {
3037
0
    unwrappedObj.emplace(cx, obj);
3038
0
  }
3039
0
  if (objIsXray) {
3040
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
3041
0
    if (!unwrappedObj.ref()) {
3042
0
      return false;
3043
0
    }
3044
0
  }
3045
0
  FastErrorResult rv;
3046
0
  RTCConfiguration result;
3047
0
  self->GetConfiguration(result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
3048
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
3049
0
    return false;
3050
0
  }
3051
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
3052
0
  if (!result.ToObjectInternal(cx, args.rval())) {
3053
0
    return false;
3054
0
  }
3055
0
  return true;
3056
0
}
3057
3058
static const JSJitInfo getConfiguration_methodinfo = {
3059
  { (JSJitGetterOp)getConfiguration },
3060
  { prototypes::id::RTCPeerConnection },
3061
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
3062
  JSJitInfo::Method,
3063
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
3064
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
3065
  false,  /* isInfallible. False in setters. */
3066
  false,  /* isMovable.  Not relevant for setters. */
3067
  false, /* isEliminatable.  Not relevant for setters. */
3068
  false, /* isAlwaysInSlot.  Only relevant for getters. */
3069
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
3070
  false,  /* isTypedMethod.  Only relevant for methods. */
3071
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
3072
};
3073
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
3074
static_assert(0 < 1, "There is no slot for us");
3075
3076
MOZ_CAN_RUN_SCRIPT static bool
3077
getLocalStreams(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
3078
0
{
3079
0
  AUTO_PROFILER_LABEL_FAST("RTCPeerConnection.getLocalStreams", DOM, cx);
3080
0
3081
0
  DeprecationWarning(cx, obj, nsIDocument::eRTCPeerConnectionGetStreams);
3082
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
3083
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
3084
0
  if (objIsXray) {
3085
0
    unwrappedObj.emplace(cx, obj);
3086
0
  }
3087
0
  if (objIsXray) {
3088
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
3089
0
    if (!unwrappedObj.ref()) {
3090
0
      return false;
3091
0
    }
3092
0
  }
3093
0
  FastErrorResult rv;
3094
0
  nsTArray<StrongPtrForMember<mozilla::DOMMediaStream>::Type> result;
3095
0
  self->GetLocalStreams(result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
3096
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
3097
0
    return false;
3098
0
  }
3099
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
3100
0
3101
0
  uint32_t length = result.Length();
3102
0
  JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
3103
0
  if (!returnArray) {
3104
0
    return false;
3105
0
  }
3106
0
  // Scope for 'tmp'
3107
0
  {
3108
0
    JS::Rooted<JS::Value> tmp(cx);
3109
0
    for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
3110
0
      // Control block to let us common up the JS_DefineElement calls when there
3111
0
      // are different ways to succeed at wrapping the object.
3112
0
      do {
3113
0
        if (!GetOrCreateDOMReflector(cx, result[sequenceIdx0], &tmp)) {
3114
0
          MOZ_ASSERT(JS_IsExceptionPending(cx));
3115
0
          return false;
3116
0
        }
3117
0
        break;
3118
0
      } while (false);
3119
0
      if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
3120
0
                            JSPROP_ENUMERATE)) {
3121
0
        return false;
3122
0
      }
3123
0
    }
3124
0
  }
3125
0
  args.rval().setObject(*returnArray);
3126
0
  return true;
3127
0
}
3128
3129
static const JSJitInfo getLocalStreams_methodinfo = {
3130
  { (JSJitGetterOp)getLocalStreams },
3131
  { prototypes::id::RTCPeerConnection },
3132
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
3133
  JSJitInfo::Method,
3134
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
3135
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
3136
  false,  /* isInfallible. False in setters. */
3137
  false,  /* isMovable.  Not relevant for setters. */
3138
  false, /* isEliminatable.  Not relevant for setters. */
3139
  false, /* isAlwaysInSlot.  Only relevant for getters. */
3140
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
3141
  false,  /* isTypedMethod.  Only relevant for methods. */
3142
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
3143
};
3144
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
3145
static_assert(0 < 1, "There is no slot for us");
3146
3147
MOZ_CAN_RUN_SCRIPT static bool
3148
getRemoteStreams(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
3149
0
{
3150
0
  AUTO_PROFILER_LABEL_FAST("RTCPeerConnection.getRemoteStreams", DOM, cx);
3151
0
3152
0
  DeprecationWarning(cx, obj, nsIDocument::eRTCPeerConnectionGetStreams);
3153
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
3154
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
3155
0
  if (objIsXray) {
3156
0
    unwrappedObj.emplace(cx, obj);
3157
0
  }
3158
0
  if (objIsXray) {
3159
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
3160
0
    if (!unwrappedObj.ref()) {
3161
0
      return false;
3162
0
    }
3163
0
  }
3164
0
  FastErrorResult rv;
3165
0
  nsTArray<StrongPtrForMember<mozilla::DOMMediaStream>::Type> result;
3166
0
  self->GetRemoteStreams(result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
3167
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
3168
0
    return false;
3169
0
  }
3170
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
3171
0
3172
0
  uint32_t length = result.Length();
3173
0
  JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
3174
0
  if (!returnArray) {
3175
0
    return false;
3176
0
  }
3177
0
  // Scope for 'tmp'
3178
0
  {
3179
0
    JS::Rooted<JS::Value> tmp(cx);
3180
0
    for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
3181
0
      // Control block to let us common up the JS_DefineElement calls when there
3182
0
      // are different ways to succeed at wrapping the object.
3183
0
      do {
3184
0
        if (!GetOrCreateDOMReflector(cx, result[sequenceIdx0], &tmp)) {
3185
0
          MOZ_ASSERT(JS_IsExceptionPending(cx));
3186
0
          return false;
3187
0
        }
3188
0
        break;
3189
0
      } while (false);
3190
0
      if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
3191
0
                            JSPROP_ENUMERATE)) {
3192
0
        return false;
3193
0
      }
3194
0
    }
3195
0
  }
3196
0
  args.rval().setObject(*returnArray);
3197
0
  return true;
3198
0
}
3199
3200
static const JSJitInfo getRemoteStreams_methodinfo = {
3201
  { (JSJitGetterOp)getRemoteStreams },
3202
  { prototypes::id::RTCPeerConnection },
3203
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
3204
  JSJitInfo::Method,
3205
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
3206
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
3207
  false,  /* isInfallible. False in setters. */
3208
  false,  /* isMovable.  Not relevant for setters. */
3209
  false, /* isEliminatable.  Not relevant for setters. */
3210
  false, /* isAlwaysInSlot.  Only relevant for getters. */
3211
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
3212
  false,  /* isTypedMethod.  Only relevant for methods. */
3213
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
3214
};
3215
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
3216
static_assert(0 < 1, "There is no slot for us");
3217
3218
MOZ_CAN_RUN_SCRIPT static bool
3219
addStream(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
3220
0
{
3221
0
  AUTO_PROFILER_LABEL_FAST("RTCPeerConnection.addStream", DOM, cx);
3222
0
3223
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
3224
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCPeerConnection.addStream");
3225
0
  }
3226
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
3227
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
3228
0
  if (objIsXray) {
3229
0
    unwrappedObj.emplace(cx, obj);
3230
0
  }
3231
0
  NonNull<mozilla::DOMMediaStream> arg0;
3232
0
  if (args[0].isObject()) {
3233
0
    {
3234
0
      nsresult rv = UnwrapObject<prototypes::id::MediaStream, mozilla::DOMMediaStream>(args[0], arg0);
3235
0
      if (NS_FAILED(rv)) {
3236
0
        ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of RTCPeerConnection.addStream", "MediaStream");
3237
0
        return false;
3238
0
      }
3239
0
    }
3240
0
  } else {
3241
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of RTCPeerConnection.addStream");
3242
0
    return false;
3243
0
  }
3244
0
  if (objIsXray) {
3245
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
3246
0
    if (!unwrappedObj.ref()) {
3247
0
      return false;
3248
0
    }
3249
0
  }
3250
0
  FastErrorResult rv;
3251
0
  self->AddStream(MOZ_KnownLive(NonNullHelper(arg0)), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
3252
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
3253
0
    return false;
3254
0
  }
3255
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
3256
0
  args.rval().setUndefined();
3257
0
  return true;
3258
0
}
3259
3260
static const JSJitInfo addStream_methodinfo = {
3261
  { (JSJitGetterOp)addStream },
3262
  { prototypes::id::RTCPeerConnection },
3263
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
3264
  JSJitInfo::Method,
3265
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
3266
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
3267
  false,  /* isInfallible. False in setters. */
3268
  false,  /* isMovable.  Not relevant for setters. */
3269
  false, /* isEliminatable.  Not relevant for setters. */
3270
  false, /* isAlwaysInSlot.  Only relevant for getters. */
3271
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
3272
  false,  /* isTypedMethod.  Only relevant for methods. */
3273
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
3274
};
3275
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
3276
static_assert(0 < 1, "There is no slot for us");
3277
3278
MOZ_CAN_RUN_SCRIPT static bool
3279
addTrack(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
3280
0
{
3281
0
  AUTO_PROFILER_LABEL_FAST("RTCPeerConnection.addTrack", DOM, cx);
3282
0
3283
0
  if (MOZ_UNLIKELY(args.length() < 2)) {
3284
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCPeerConnection.addTrack");
3285
0
  }
3286
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
3287
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
3288
0
  if (objIsXray) {
3289
0
    unwrappedObj.emplace(cx, obj);
3290
0
  }
3291
0
  NonNull<mozilla::dom::MediaStreamTrack> arg0;
3292
0
  if (args[0].isObject()) {
3293
0
    {
3294
0
      nsresult rv = UnwrapObject<prototypes::id::MediaStreamTrack, mozilla::dom::MediaStreamTrack>(args[0], arg0);
3295
0
      if (NS_FAILED(rv)) {
3296
0
        ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of RTCPeerConnection.addTrack", "MediaStreamTrack");
3297
0
        return false;
3298
0
      }
3299
0
    }
3300
0
  } else {
3301
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of RTCPeerConnection.addTrack");
3302
0
    return false;
3303
0
  }
3304
0
  NonNull<mozilla::DOMMediaStream> arg1;
3305
0
  if (args[1].isObject()) {
3306
0
    {
3307
0
      nsresult rv = UnwrapObject<prototypes::id::MediaStream, mozilla::DOMMediaStream>(args[1], arg1);
3308
0
      if (NS_FAILED(rv)) {
3309
0
        ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 2 of RTCPeerConnection.addTrack", "MediaStream");
3310
0
        return false;
3311
0
      }
3312
0
    }
3313
0
  } else {
3314
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of RTCPeerConnection.addTrack");
3315
0
    return false;
3316
0
  }
3317
0
  AutoSequence<OwningNonNull<mozilla::DOMMediaStream>> arg2;
3318
0
  if (args.length() > 2) {
3319
0
    if (!arg2.SetCapacity(args.length() - 2, mozilla::fallible)) {
3320
0
      JS_ReportOutOfMemory(cx);
3321
0
      return false;
3322
0
    }
3323
0
    for (uint32_t variadicArg = 2; variadicArg < args.length(); ++variadicArg) {
3324
0
      OwningNonNull<mozilla::DOMMediaStream>& slot = *arg2.AppendElement(mozilla::fallible);
3325
0
      if (args[variadicArg].isObject()) {
3326
0
        static_assert(IsRefcounted<mozilla::DOMMediaStream>::value, "We can only store refcounted classes.");{
3327
0
          nsresult rv = UnwrapObject<prototypes::id::MediaStream, mozilla::DOMMediaStream>(args[variadicArg], slot);
3328
0
          if (NS_FAILED(rv)) {
3329
0
            ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 3 of RTCPeerConnection.addTrack", "MediaStream");
3330
0
            return false;
3331
0
          }
3332
0
        }
3333
0
      } else {
3334
0
        ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 3 of RTCPeerConnection.addTrack");
3335
0
        return false;
3336
0
      }
3337
0
    }
3338
0
  }
3339
0
  if (objIsXray) {
3340
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
3341
0
    if (!unwrappedObj.ref()) {
3342
0
      return false;
3343
0
    }
3344
0
  }
3345
0
  FastErrorResult rv;
3346
0
  auto result(StrongOrRawPtr<mozilla::dom::RTCRtpSender>(self->AddTrack(MOZ_KnownLive(NonNullHelper(arg0)), MOZ_KnownLive(NonNullHelper(arg1)), MOZ_KnownLive(NonNullHelper(Constify(arg2))), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)))));
3347
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
3348
0
    return false;
3349
0
  }
3350
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
3351
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
3352
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
3353
0
    return false;
3354
0
  }
3355
0
  return true;
3356
0
}
3357
3358
static const JSJitInfo addTrack_methodinfo = {
3359
  { (JSJitGetterOp)addTrack },
3360
  { prototypes::id::RTCPeerConnection },
3361
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
3362
  JSJitInfo::Method,
3363
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
3364
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
3365
  false,  /* isInfallible. False in setters. */
3366
  false,  /* isMovable.  Not relevant for setters. */
3367
  false, /* isEliminatable.  Not relevant for setters. */
3368
  false, /* isAlwaysInSlot.  Only relevant for getters. */
3369
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
3370
  false,  /* isTypedMethod.  Only relevant for methods. */
3371
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
3372
};
3373
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
3374
static_assert(0 < 1, "There is no slot for us");
3375
3376
MOZ_CAN_RUN_SCRIPT static bool
3377
removeTrack(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
3378
0
{
3379
0
  AUTO_PROFILER_LABEL_FAST("RTCPeerConnection.removeTrack", DOM, cx);
3380
0
3381
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
3382
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCPeerConnection.removeTrack");
3383
0
  }
3384
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
3385
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
3386
0
  if (objIsXray) {
3387
0
    unwrappedObj.emplace(cx, obj);
3388
0
  }
3389
0
  NonNull<mozilla::dom::RTCRtpSender> arg0;
3390
0
  if (args[0].isObject()) {
3391
0
    {
3392
0
      nsresult rv = UnwrapObject<prototypes::id::RTCRtpSender, mozilla::dom::RTCRtpSender>(args[0], arg0);
3393
0
      if (NS_FAILED(rv)) {
3394
0
        ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of RTCPeerConnection.removeTrack", "RTCRtpSender");
3395
0
        return false;
3396
0
      }
3397
0
    }
3398
0
  } else {
3399
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of RTCPeerConnection.removeTrack");
3400
0
    return false;
3401
0
  }
3402
0
  if (objIsXray) {
3403
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
3404
0
    if (!unwrappedObj.ref()) {
3405
0
      return false;
3406
0
    }
3407
0
  }
3408
0
  FastErrorResult rv;
3409
0
  self->RemoveTrack(MOZ_KnownLive(NonNullHelper(arg0)), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
3410
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
3411
0
    return false;
3412
0
  }
3413
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
3414
0
  args.rval().setUndefined();
3415
0
  return true;
3416
0
}
3417
3418
static const JSJitInfo removeTrack_methodinfo = {
3419
  { (JSJitGetterOp)removeTrack },
3420
  { prototypes::id::RTCPeerConnection },
3421
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
3422
  JSJitInfo::Method,
3423
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
3424
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
3425
  false,  /* isInfallible. False in setters. */
3426
  false,  /* isMovable.  Not relevant for setters. */
3427
  false, /* isEliminatable.  Not relevant for setters. */
3428
  false, /* isAlwaysInSlot.  Only relevant for getters. */
3429
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
3430
  false,  /* isTypedMethod.  Only relevant for methods. */
3431
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
3432
};
3433
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
3434
static_assert(0 < 1, "There is no slot for us");
3435
3436
MOZ_CAN_RUN_SCRIPT static bool
3437
addTransceiver(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
3438
0
{
3439
0
  AUTO_PROFILER_LABEL_FAST("RTCPeerConnection.addTransceiver", DOM, cx);
3440
0
3441
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
3442
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCPeerConnection.addTransceiver");
3443
0
  }
3444
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
3445
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
3446
0
  if (objIsXray) {
3447
0
    unwrappedObj.emplace(cx, obj);
3448
0
  }
3449
0
  MediaStreamTrackOrString arg0;
3450
0
  MediaStreamTrackOrStringArgument arg0_holder(arg0);
3451
0
  {
3452
0
    bool done = false, failed = false, tryNext;
3453
0
    if (args[0].isObject()) {
3454
0
      done = (failed = !arg0_holder.TrySetToMediaStreamTrack(cx, args[0], tryNext, true)) || !tryNext;
3455
0
3456
0
    }
3457
0
    if (!done) {
3458
0
      do {
3459
0
        done = (failed = !arg0_holder.TrySetToString(cx, args[0], tryNext)) || !tryNext;
3460
0
        break;
3461
0
      } while (false);
3462
0
    }
3463
0
    if (failed) {
3464
0
      return false;
3465
0
    }
3466
0
    if (!done) {
3467
0
      ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "Argument 1 of RTCPeerConnection.addTransceiver", "MediaStreamTrack");
3468
0
      return false;
3469
0
    }
3470
0
  }
3471
0
  binding_detail::FastRTCRtpTransceiverInit arg1;
3472
0
  if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue,  "Argument 2 of RTCPeerConnection.addTransceiver", true)) {
3473
0
    return false;
3474
0
  }
3475
0
  if (objIsXray) {
3476
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
3477
0
    if (!unwrappedObj.ref()) {
3478
0
      return false;
3479
0
    }
3480
0
  }
3481
0
  FastErrorResult rv;
3482
0
  auto result(StrongOrRawPtr<mozilla::dom::RTCRtpTransceiver>(self->AddTransceiver(Constify(arg0), Constify(arg1), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)))));
3483
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
3484
0
    return false;
3485
0
  }
3486
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
3487
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
3488
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
3489
0
    return false;
3490
0
  }
3491
0
  return true;
3492
0
}
3493
3494
static const JSJitInfo addTransceiver_methodinfo = {
3495
  { (JSJitGetterOp)addTransceiver },
3496
  { prototypes::id::RTCPeerConnection },
3497
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
3498
  JSJitInfo::Method,
3499
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
3500
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
3501
  false,  /* isInfallible. False in setters. */
3502
  false,  /* isMovable.  Not relevant for setters. */
3503
  false, /* isEliminatable.  Not relevant for setters. */
3504
  false, /* isAlwaysInSlot.  Only relevant for getters. */
3505
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
3506
  false,  /* isTypedMethod.  Only relevant for methods. */
3507
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
3508
};
3509
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
3510
static_assert(0 < 1, "There is no slot for us");
3511
3512
MOZ_CAN_RUN_SCRIPT static bool
3513
getSenders(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
3514
0
{
3515
0
  AUTO_PROFILER_LABEL_FAST("RTCPeerConnection.getSenders", DOM, cx);
3516
0
3517
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
3518
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
3519
0
  if (objIsXray) {
3520
0
    unwrappedObj.emplace(cx, obj);
3521
0
  }
3522
0
  if (objIsXray) {
3523
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
3524
0
    if (!unwrappedObj.ref()) {
3525
0
      return false;
3526
0
    }
3527
0
  }
3528
0
  FastErrorResult rv;
3529
0
  nsTArray<StrongPtrForMember<mozilla::dom::RTCRtpSender>::Type> result;
3530
0
  self->GetSenders(result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
3531
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
3532
0
    return false;
3533
0
  }
3534
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
3535
0
3536
0
  uint32_t length = result.Length();
3537
0
  JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
3538
0
  if (!returnArray) {
3539
0
    return false;
3540
0
  }
3541
0
  // Scope for 'tmp'
3542
0
  {
3543
0
    JS::Rooted<JS::Value> tmp(cx);
3544
0
    for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
3545
0
      // Control block to let us common up the JS_DefineElement calls when there
3546
0
      // are different ways to succeed at wrapping the object.
3547
0
      do {
3548
0
        if (!GetOrCreateDOMReflector(cx, result[sequenceIdx0], &tmp)) {
3549
0
          MOZ_ASSERT(JS_IsExceptionPending(cx));
3550
0
          return false;
3551
0
        }
3552
0
        break;
3553
0
      } while (false);
3554
0
      if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
3555
0
                            JSPROP_ENUMERATE)) {
3556
0
        return false;
3557
0
      }
3558
0
    }
3559
0
  }
3560
0
  args.rval().setObject(*returnArray);
3561
0
  return true;
3562
0
}
3563
3564
static const JSJitInfo getSenders_methodinfo = {
3565
  { (JSJitGetterOp)getSenders },
3566
  { prototypes::id::RTCPeerConnection },
3567
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
3568
  JSJitInfo::Method,
3569
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
3570
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
3571
  false,  /* isInfallible. False in setters. */
3572
  false,  /* isMovable.  Not relevant for setters. */
3573
  false, /* isEliminatable.  Not relevant for setters. */
3574
  false, /* isAlwaysInSlot.  Only relevant for getters. */
3575
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
3576
  false,  /* isTypedMethod.  Only relevant for methods. */
3577
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
3578
};
3579
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
3580
static_assert(0 < 1, "There is no slot for us");
3581
3582
MOZ_CAN_RUN_SCRIPT static bool
3583
getReceivers(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
3584
0
{
3585
0
  AUTO_PROFILER_LABEL_FAST("RTCPeerConnection.getReceivers", DOM, cx);
3586
0
3587
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
3588
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
3589
0
  if (objIsXray) {
3590
0
    unwrappedObj.emplace(cx, obj);
3591
0
  }
3592
0
  if (objIsXray) {
3593
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
3594
0
    if (!unwrappedObj.ref()) {
3595
0
      return false;
3596
0
    }
3597
0
  }
3598
0
  FastErrorResult rv;
3599
0
  nsTArray<StrongPtrForMember<mozilla::dom::RTCRtpReceiver>::Type> result;
3600
0
  self->GetReceivers(result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
3601
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
3602
0
    return false;
3603
0
  }
3604
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
3605
0
3606
0
  uint32_t length = result.Length();
3607
0
  JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
3608
0
  if (!returnArray) {
3609
0
    return false;
3610
0
  }
3611
0
  // Scope for 'tmp'
3612
0
  {
3613
0
    JS::Rooted<JS::Value> tmp(cx);
3614
0
    for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
3615
0
      // Control block to let us common up the JS_DefineElement calls when there
3616
0
      // are different ways to succeed at wrapping the object.
3617
0
      do {
3618
0
        if (!GetOrCreateDOMReflector(cx, result[sequenceIdx0], &tmp)) {
3619
0
          MOZ_ASSERT(JS_IsExceptionPending(cx));
3620
0
          return false;
3621
0
        }
3622
0
        break;
3623
0
      } while (false);
3624
0
      if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
3625
0
                            JSPROP_ENUMERATE)) {
3626
0
        return false;
3627
0
      }
3628
0
    }
3629
0
  }
3630
0
  args.rval().setObject(*returnArray);
3631
0
  return true;
3632
0
}
3633
3634
static const JSJitInfo getReceivers_methodinfo = {
3635
  { (JSJitGetterOp)getReceivers },
3636
  { prototypes::id::RTCPeerConnection },
3637
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
3638
  JSJitInfo::Method,
3639
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
3640
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
3641
  false,  /* isInfallible. False in setters. */
3642
  false,  /* isMovable.  Not relevant for setters. */
3643
  false, /* isEliminatable.  Not relevant for setters. */
3644
  false, /* isAlwaysInSlot.  Only relevant for getters. */
3645
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
3646
  false,  /* isTypedMethod.  Only relevant for methods. */
3647
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
3648
};
3649
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
3650
static_assert(0 < 1, "There is no slot for us");
3651
3652
MOZ_CAN_RUN_SCRIPT static bool
3653
getTransceivers(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
3654
0
{
3655
0
  AUTO_PROFILER_LABEL_FAST("RTCPeerConnection.getTransceivers", DOM, cx);
3656
0
3657
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
3658
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
3659
0
  if (objIsXray) {
3660
0
    unwrappedObj.emplace(cx, obj);
3661
0
  }
3662
0
  if (objIsXray) {
3663
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
3664
0
    if (!unwrappedObj.ref()) {
3665
0
      return false;
3666
0
    }
3667
0
  }
3668
0
  FastErrorResult rv;
3669
0
  nsTArray<StrongPtrForMember<mozilla::dom::RTCRtpTransceiver>::Type> result;
3670
0
  self->GetTransceivers(result, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
3671
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
3672
0
    return false;
3673
0
  }
3674
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
3675
0
3676
0
  uint32_t length = result.Length();
3677
0
  JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
3678
0
  if (!returnArray) {
3679
0
    return false;
3680
0
  }
3681
0
  // Scope for 'tmp'
3682
0
  {
3683
0
    JS::Rooted<JS::Value> tmp(cx);
3684
0
    for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
3685
0
      // Control block to let us common up the JS_DefineElement calls when there
3686
0
      // are different ways to succeed at wrapping the object.
3687
0
      do {
3688
0
        if (!GetOrCreateDOMReflector(cx, result[sequenceIdx0], &tmp)) {
3689
0
          MOZ_ASSERT(JS_IsExceptionPending(cx));
3690
0
          return false;
3691
0
        }
3692
0
        break;
3693
0
      } while (false);
3694
0
      if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
3695
0
                            JSPROP_ENUMERATE)) {
3696
0
        return false;
3697
0
      }
3698
0
    }
3699
0
  }
3700
0
  args.rval().setObject(*returnArray);
3701
0
  return true;
3702
0
}
3703
3704
static const JSJitInfo getTransceivers_methodinfo = {
3705
  { (JSJitGetterOp)getTransceivers },
3706
  { prototypes::id::RTCPeerConnection },
3707
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
3708
  JSJitInfo::Method,
3709
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
3710
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
3711
  false,  /* isInfallible. False in setters. */
3712
  false,  /* isMovable.  Not relevant for setters. */
3713
  false, /* isEliminatable.  Not relevant for setters. */
3714
  false, /* isAlwaysInSlot.  Only relevant for getters. */
3715
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
3716
  false,  /* isTypedMethod.  Only relevant for methods. */
3717
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
3718
};
3719
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
3720
static_assert(0 < 1, "There is no slot for us");
3721
3722
MOZ_CAN_RUN_SCRIPT static bool
3723
mozGetNowInRtpSourceReferenceTime(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
3724
0
{
3725
0
  AUTO_PROFILER_LABEL_FAST("RTCPeerConnection.mozGetNowInRtpSourceReferenceTime", DOM, cx);
3726
0
3727
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
3728
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
3729
0
  if (objIsXray) {
3730
0
    unwrappedObj.emplace(cx, obj);
3731
0
  }
3732
0
  if (objIsXray) {
3733
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
3734
0
    if (!unwrappedObj.ref()) {
3735
0
      return false;
3736
0
    }
3737
0
  }
3738
0
  FastErrorResult rv;
3739
0
  double result(self->MozGetNowInRtpSourceReferenceTime(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))));
3740
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
3741
0
    return false;
3742
0
  }
3743
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
3744
0
  args.rval().set(JS_NumberValue(double(result)));
3745
0
  return true;
3746
0
}
3747
3748
static const JSJitInfo mozGetNowInRtpSourceReferenceTime_methodinfo = {
3749
  { (JSJitGetterOp)mozGetNowInRtpSourceReferenceTime },
3750
  { prototypes::id::RTCPeerConnection },
3751
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
3752
  JSJitInfo::Method,
3753
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
3754
  JSVAL_TYPE_DOUBLE,  /* returnType.  Not relevant for setters. */
3755
  false,  /* isInfallible. False in setters. */
3756
  false,  /* isMovable.  Not relevant for setters. */
3757
  false, /* isEliminatable.  Not relevant for setters. */
3758
  false, /* isAlwaysInSlot.  Only relevant for getters. */
3759
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
3760
  false,  /* isTypedMethod.  Only relevant for methods. */
3761
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
3762
};
3763
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
3764
static_assert(0 < 1, "There is no slot for us");
3765
3766
MOZ_CAN_RUN_SCRIPT static bool
3767
mozInsertAudioLevelForContributingSource(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
3768
0
{
3769
0
  AUTO_PROFILER_LABEL_FAST("RTCPeerConnection.mozInsertAudioLevelForContributingSource", DOM, cx);
3770
0
3771
0
  if (MOZ_UNLIKELY(args.length() < 5)) {
3772
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCPeerConnection.mozInsertAudioLevelForContributingSource");
3773
0
  }
3774
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
3775
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
3776
0
  if (objIsXray) {
3777
0
    unwrappedObj.emplace(cx, obj);
3778
0
  }
3779
0
  NonNull<mozilla::dom::RTCRtpReceiver> arg0;
3780
0
  if (args[0].isObject()) {
3781
0
    {
3782
0
      nsresult rv = UnwrapObject<prototypes::id::RTCRtpReceiver, mozilla::dom::RTCRtpReceiver>(args[0], arg0);
3783
0
      if (NS_FAILED(rv)) {
3784
0
        ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of RTCPeerConnection.mozInsertAudioLevelForContributingSource", "RTCRtpReceiver");
3785
0
        return false;
3786
0
      }
3787
0
    }
3788
0
  } else {
3789
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of RTCPeerConnection.mozInsertAudioLevelForContributingSource");
3790
0
    return false;
3791
0
  }
3792
0
  uint32_t arg1;
3793
0
  if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[1], &arg1)) {
3794
0
    return false;
3795
0
  }
3796
0
  double arg2;
3797
0
  if (!ValueToPrimitive<double, eDefault>(cx, args[2], &arg2)) {
3798
0
    return false;
3799
0
  } else if (!mozilla::IsFinite(arg2)) {
3800
0
    ThrowErrorMessage(cx, MSG_NOT_FINITE, "Argument 3 of RTCPeerConnection.mozInsertAudioLevelForContributingSource");
3801
0
    return false;
3802
0
  }
3803
0
  bool arg3;
3804
0
  if (!ValueToPrimitive<bool, eDefault>(cx, args[3], &arg3)) {
3805
0
    return false;
3806
0
  }
3807
0
  int8_t arg4;
3808
0
  if (!ValueToPrimitive<int8_t, eDefault>(cx, args[4], &arg4)) {
3809
0
    return false;
3810
0
  }
3811
0
  if (objIsXray) {
3812
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
3813
0
    if (!unwrappedObj.ref()) {
3814
0
      return false;
3815
0
    }
3816
0
  }
3817
0
  FastErrorResult rv;
3818
0
  self->MozInsertAudioLevelForContributingSource(MOZ_KnownLive(NonNullHelper(arg0)), arg1, arg2, arg3, arg4, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
3819
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
3820
0
    return false;
3821
0
  }
3822
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
3823
0
  args.rval().setUndefined();
3824
0
  return true;
3825
0
}
3826
3827
static const JSJitInfo mozInsertAudioLevelForContributingSource_methodinfo = {
3828
  { (JSJitGetterOp)mozInsertAudioLevelForContributingSource },
3829
  { prototypes::id::RTCPeerConnection },
3830
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
3831
  JSJitInfo::Method,
3832
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
3833
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
3834
  false,  /* isInfallible. False in setters. */
3835
  false,  /* isMovable.  Not relevant for setters. */
3836
  false, /* isEliminatable.  Not relevant for setters. */
3837
  false, /* isAlwaysInSlot.  Only relevant for getters. */
3838
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
3839
  false,  /* isTypedMethod.  Only relevant for methods. */
3840
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
3841
};
3842
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
3843
static_assert(0 < 1, "There is no slot for us");
3844
3845
MOZ_CAN_RUN_SCRIPT static bool
3846
mozAddRIDExtension(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
3847
0
{
3848
0
  AUTO_PROFILER_LABEL_FAST("RTCPeerConnection.mozAddRIDExtension", DOM, cx);
3849
0
3850
0
  if (MOZ_UNLIKELY(args.length() < 2)) {
3851
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCPeerConnection.mozAddRIDExtension");
3852
0
  }
3853
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
3854
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
3855
0
  if (objIsXray) {
3856
0
    unwrappedObj.emplace(cx, obj);
3857
0
  }
3858
0
  NonNull<mozilla::dom::RTCRtpReceiver> arg0;
3859
0
  if (args[0].isObject()) {
3860
0
    {
3861
0
      nsresult rv = UnwrapObject<prototypes::id::RTCRtpReceiver, mozilla::dom::RTCRtpReceiver>(args[0], arg0);
3862
0
      if (NS_FAILED(rv)) {
3863
0
        ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of RTCPeerConnection.mozAddRIDExtension", "RTCRtpReceiver");
3864
0
        return false;
3865
0
      }
3866
0
    }
3867
0
  } else {
3868
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of RTCPeerConnection.mozAddRIDExtension");
3869
0
    return false;
3870
0
  }
3871
0
  uint16_t arg1;
3872
0
  if (!ValueToPrimitive<uint16_t, eDefault>(cx, args[1], &arg1)) {
3873
0
    return false;
3874
0
  }
3875
0
  if (objIsXray) {
3876
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
3877
0
    if (!unwrappedObj.ref()) {
3878
0
      return false;
3879
0
    }
3880
0
  }
3881
0
  FastErrorResult rv;
3882
0
  self->MozAddRIDExtension(MOZ_KnownLive(NonNullHelper(arg0)), arg1, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
3883
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
3884
0
    return false;
3885
0
  }
3886
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
3887
0
  args.rval().setUndefined();
3888
0
  return true;
3889
0
}
3890
3891
static const JSJitInfo mozAddRIDExtension_methodinfo = {
3892
  { (JSJitGetterOp)mozAddRIDExtension },
3893
  { prototypes::id::RTCPeerConnection },
3894
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
3895
  JSJitInfo::Method,
3896
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
3897
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
3898
  false,  /* isInfallible. False in setters. */
3899
  false,  /* isMovable.  Not relevant for setters. */
3900
  false, /* isEliminatable.  Not relevant for setters. */
3901
  false, /* isAlwaysInSlot.  Only relevant for getters. */
3902
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
3903
  false,  /* isTypedMethod.  Only relevant for methods. */
3904
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
3905
};
3906
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
3907
static_assert(0 < 1, "There is no slot for us");
3908
3909
MOZ_CAN_RUN_SCRIPT static bool
3910
mozAddRIDFilter(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
3911
0
{
3912
0
  AUTO_PROFILER_LABEL_FAST("RTCPeerConnection.mozAddRIDFilter", DOM, cx);
3913
0
3914
0
  if (MOZ_UNLIKELY(args.length() < 2)) {
3915
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCPeerConnection.mozAddRIDFilter");
3916
0
  }
3917
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
3918
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
3919
0
  if (objIsXray) {
3920
0
    unwrappedObj.emplace(cx, obj);
3921
0
  }
3922
0
  NonNull<mozilla::dom::RTCRtpReceiver> arg0;
3923
0
  if (args[0].isObject()) {
3924
0
    {
3925
0
      nsresult rv = UnwrapObject<prototypes::id::RTCRtpReceiver, mozilla::dom::RTCRtpReceiver>(args[0], arg0);
3926
0
      if (NS_FAILED(rv)) {
3927
0
        ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of RTCPeerConnection.mozAddRIDFilter", "RTCRtpReceiver");
3928
0
        return false;
3929
0
      }
3930
0
    }
3931
0
  } else {
3932
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of RTCPeerConnection.mozAddRIDFilter");
3933
0
    return false;
3934
0
  }
3935
0
  binding_detail::FakeString arg1;
3936
0
  if (!ConvertJSValueToString(cx, args[1], eStringify, eStringify, arg1)) {
3937
0
    return false;
3938
0
  }
3939
0
  if (objIsXray) {
3940
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
3941
0
    if (!unwrappedObj.ref()) {
3942
0
      return false;
3943
0
    }
3944
0
  }
3945
0
  FastErrorResult rv;
3946
0
  self->MozAddRIDFilter(MOZ_KnownLive(NonNullHelper(arg0)), NonNullHelper(Constify(arg1)), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
3947
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
3948
0
    return false;
3949
0
  }
3950
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
3951
0
  args.rval().setUndefined();
3952
0
  return true;
3953
0
}
3954
3955
static const JSJitInfo mozAddRIDFilter_methodinfo = {
3956
  { (JSJitGetterOp)mozAddRIDFilter },
3957
  { prototypes::id::RTCPeerConnection },
3958
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
3959
  JSJitInfo::Method,
3960
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
3961
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
3962
  false,  /* isInfallible. False in setters. */
3963
  false,  /* isMovable.  Not relevant for setters. */
3964
  false, /* isEliminatable.  Not relevant for setters. */
3965
  false, /* isAlwaysInSlot.  Only relevant for getters. */
3966
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
3967
  false,  /* isTypedMethod.  Only relevant for methods. */
3968
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
3969
};
3970
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
3971
static_assert(0 < 1, "There is no slot for us");
3972
3973
MOZ_CAN_RUN_SCRIPT static bool
3974
mozSetPacketCallback(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
3975
0
{
3976
0
  AUTO_PROFILER_LABEL_FAST("RTCPeerConnection.mozSetPacketCallback", DOM, cx);
3977
0
3978
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
3979
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCPeerConnection.mozSetPacketCallback");
3980
0
  }
3981
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
3982
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
3983
0
  if (objIsXray) {
3984
0
    unwrappedObj.emplace(cx, obj);
3985
0
  }
3986
0
  RootedCallback<OwningNonNull<binding_detail::FastmozPacketCallback>> arg0(cx);
3987
0
  if (args[0].isObject()) {
3988
0
    if (JS::IsCallable(&args[0].toObject())) {
3989
0
    { // scope for tempRoot and tempGlobalRoot if needed
3990
0
      arg0 = new binding_detail::FastmozPacketCallback(&args[0].toObject(), JS::CurrentGlobalOrNull(cx));
3991
0
    }
3992
0
    } else {
3993
0
      ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 1 of RTCPeerConnection.mozSetPacketCallback");
3994
0
      return false;
3995
0
    }
3996
0
  } else {
3997
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of RTCPeerConnection.mozSetPacketCallback");
3998
0
    return false;
3999
0
  }
4000
0
  if (objIsXray) {
4001
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
4002
0
    if (!unwrappedObj.ref()) {
4003
0
      return false;
4004
0
    }
4005
0
  }
4006
0
  FastErrorResult rv;
4007
0
  self->MozSetPacketCallback(NonNullHelper(arg0), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
4008
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
4009
0
    return false;
4010
0
  }
4011
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
4012
0
  args.rval().setUndefined();
4013
0
  return true;
4014
0
}
4015
4016
static const JSJitInfo mozSetPacketCallback_methodinfo = {
4017
  { (JSJitGetterOp)mozSetPacketCallback },
4018
  { prototypes::id::RTCPeerConnection },
4019
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
4020
  JSJitInfo::Method,
4021
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
4022
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
4023
  false,  /* isInfallible. False in setters. */
4024
  false,  /* isMovable.  Not relevant for setters. */
4025
  false, /* isEliminatable.  Not relevant for setters. */
4026
  false, /* isAlwaysInSlot.  Only relevant for getters. */
4027
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
4028
  false,  /* isTypedMethod.  Only relevant for methods. */
4029
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
4030
};
4031
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
4032
static_assert(0 < 1, "There is no slot for us");
4033
4034
MOZ_CAN_RUN_SCRIPT static bool
4035
mozEnablePacketDump(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
4036
0
{
4037
0
  AUTO_PROFILER_LABEL_FAST("RTCPeerConnection.mozEnablePacketDump", DOM, cx);
4038
0
4039
0
  if (MOZ_UNLIKELY(args.length() < 3)) {
4040
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCPeerConnection.mozEnablePacketDump");
4041
0
  }
4042
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
4043
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
4044
0
  if (objIsXray) {
4045
0
    unwrappedObj.emplace(cx, obj);
4046
0
  }
4047
0
  uint32_t arg0;
4048
0
  if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], &arg0)) {
4049
0
    return false;
4050
0
  }
4051
0
  mozPacketDumpType arg1;
4052
0
  {
4053
0
    int index;
4054
0
    if (!FindEnumStringIndex<true>(cx, args[1], mozPacketDumpTypeValues::strings, "mozPacketDumpType", "Argument 2 of RTCPeerConnection.mozEnablePacketDump", &index)) {
4055
0
      return false;
4056
0
    }
4057
0
    MOZ_ASSERT(index >= 0);
4058
0
    arg1 = static_cast<mozPacketDumpType>(index);
4059
0
  }
4060
0
  bool arg2;
4061
0
  if (!ValueToPrimitive<bool, eDefault>(cx, args[2], &arg2)) {
4062
0
    return false;
4063
0
  }
4064
0
  if (objIsXray) {
4065
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
4066
0
    if (!unwrappedObj.ref()) {
4067
0
      return false;
4068
0
    }
4069
0
  }
4070
0
  FastErrorResult rv;
4071
0
  self->MozEnablePacketDump(arg0, arg1, arg2, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
4072
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
4073
0
    return false;
4074
0
  }
4075
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
4076
0
  args.rval().setUndefined();
4077
0
  return true;
4078
0
}
4079
4080
static const JSJitInfo mozEnablePacketDump_methodinfo = {
4081
  { (JSJitGetterOp)mozEnablePacketDump },
4082
  { prototypes::id::RTCPeerConnection },
4083
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
4084
  JSJitInfo::Method,
4085
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
4086
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
4087
  false,  /* isInfallible. False in setters. */
4088
  false,  /* isMovable.  Not relevant for setters. */
4089
  false, /* isEliminatable.  Not relevant for setters. */
4090
  false, /* isAlwaysInSlot.  Only relevant for getters. */
4091
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
4092
  false,  /* isTypedMethod.  Only relevant for methods. */
4093
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
4094
};
4095
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
4096
static_assert(0 < 1, "There is no slot for us");
4097
4098
MOZ_CAN_RUN_SCRIPT static bool
4099
mozDisablePacketDump(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
4100
0
{
4101
0
  AUTO_PROFILER_LABEL_FAST("RTCPeerConnection.mozDisablePacketDump", DOM, cx);
4102
0
4103
0
  if (MOZ_UNLIKELY(args.length() < 3)) {
4104
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCPeerConnection.mozDisablePacketDump");
4105
0
  }
4106
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
4107
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
4108
0
  if (objIsXray) {
4109
0
    unwrappedObj.emplace(cx, obj);
4110
0
  }
4111
0
  uint32_t arg0;
4112
0
  if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], &arg0)) {
4113
0
    return false;
4114
0
  }
4115
0
  mozPacketDumpType arg1;
4116
0
  {
4117
0
    int index;
4118
0
    if (!FindEnumStringIndex<true>(cx, args[1], mozPacketDumpTypeValues::strings, "mozPacketDumpType", "Argument 2 of RTCPeerConnection.mozDisablePacketDump", &index)) {
4119
0
      return false;
4120
0
    }
4121
0
    MOZ_ASSERT(index >= 0);
4122
0
    arg1 = static_cast<mozPacketDumpType>(index);
4123
0
  }
4124
0
  bool arg2;
4125
0
  if (!ValueToPrimitive<bool, eDefault>(cx, args[2], &arg2)) {
4126
0
    return false;
4127
0
  }
4128
0
  if (objIsXray) {
4129
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
4130
0
    if (!unwrappedObj.ref()) {
4131
0
      return false;
4132
0
    }
4133
0
  }
4134
0
  FastErrorResult rv;
4135
0
  self->MozDisablePacketDump(arg0, arg1, arg2, rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
4136
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
4137
0
    return false;
4138
0
  }
4139
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
4140
0
  args.rval().setUndefined();
4141
0
  return true;
4142
0
}
4143
4144
static const JSJitInfo mozDisablePacketDump_methodinfo = {
4145
  { (JSJitGetterOp)mozDisablePacketDump },
4146
  { prototypes::id::RTCPeerConnection },
4147
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
4148
  JSJitInfo::Method,
4149
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
4150
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
4151
  false,  /* isInfallible. False in setters. */
4152
  false,  /* isMovable.  Not relevant for setters. */
4153
  false, /* isEliminatable.  Not relevant for setters. */
4154
  false, /* isAlwaysInSlot.  Only relevant for getters. */
4155
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
4156
  false,  /* isTypedMethod.  Only relevant for methods. */
4157
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
4158
};
4159
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
4160
static_assert(0 < 1, "There is no slot for us");
4161
4162
MOZ_CAN_RUN_SCRIPT static bool
4163
close(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
4164
0
{
4165
0
  AUTO_PROFILER_LABEL_FAST("RTCPeerConnection.close", DOM, cx);
4166
0
4167
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
4168
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
4169
0
  if (objIsXray) {
4170
0
    unwrappedObj.emplace(cx, obj);
4171
0
  }
4172
0
  if (objIsXray) {
4173
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
4174
0
    if (!unwrappedObj.ref()) {
4175
0
      return false;
4176
0
    }
4177
0
  }
4178
0
  FastErrorResult rv;
4179
0
  self->Close(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
4180
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
4181
0
    return false;
4182
0
  }
4183
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
4184
0
  args.rval().setUndefined();
4185
0
  return true;
4186
0
}
4187
4188
static const JSJitInfo close_methodinfo = {
4189
  { (JSJitGetterOp)close },
4190
  { prototypes::id::RTCPeerConnection },
4191
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
4192
  JSJitInfo::Method,
4193
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
4194
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
4195
  false,  /* isInfallible. False in setters. */
4196
  false,  /* isMovable.  Not relevant for setters. */
4197
  false, /* isEliminatable.  Not relevant for setters. */
4198
  false, /* isAlwaysInSlot.  Only relevant for getters. */
4199
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
4200
  false,  /* isTypedMethod.  Only relevant for methods. */
4201
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
4202
};
4203
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
4204
static_assert(0 < 1, "There is no slot for us");
4205
4206
MOZ_CAN_RUN_SCRIPT static bool
4207
get_onnegotiationneeded(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
4208
0
{
4209
0
  AUTO_PROFILER_LABEL_FAST("get RTCPeerConnection.onnegotiationneeded", DOM, cx);
4210
0
4211
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
4212
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
4213
0
  if (objIsXray) {
4214
0
    unwrappedObj.emplace(cx, obj);
4215
0
  }
4216
0
  if (objIsXray) {
4217
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
4218
0
    if (!unwrappedObj.ref()) {
4219
0
      return false;
4220
0
    }
4221
0
  }
4222
0
  FastErrorResult rv;
4223
0
  RefPtr<EventHandlerNonNull> result(self->GetOnnegotiationneeded(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))));
4224
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
4225
0
    return false;
4226
0
  }
4227
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
4228
0
  if (result) {
4229
0
    args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result));
4230
0
    if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
4231
0
      return false;
4232
0
    }
4233
0
    return true;
4234
0
  } else {
4235
0
    args.rval().setNull();
4236
0
    return true;
4237
0
  }
4238
0
}
4239
4240
MOZ_CAN_RUN_SCRIPT static bool
4241
set_onnegotiationneeded(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitSetterCallArgs args)
4242
0
{
4243
0
  AUTO_PROFILER_LABEL_FAST("set RTCPeerConnection.onnegotiationneeded", DOM, cx);
4244
0
4245
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
4246
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
4247
0
  if (objIsXray) {
4248
0
    unwrappedObj.emplace(cx, obj);
4249
0
  }
4250
0
  RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
4251
0
  if (args[0].isObject()) {
4252
0
    { // scope for tempRoot and tempGlobalRoot if needed
4253
0
      arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx));
4254
0
    }
4255
0
  } else {
4256
0
    arg0 = nullptr;
4257
0
  }
4258
0
  if (objIsXray) {
4259
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
4260
0
    if (!unwrappedObj.ref()) {
4261
0
      return false;
4262
0
    }
4263
0
  }
4264
0
  FastErrorResult rv;
4265
0
  self->SetOnnegotiationneeded(Constify(arg0), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
4266
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
4267
0
    return false;
4268
0
  }
4269
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
4270
0
4271
0
  return true;
4272
0
}
4273
4274
static const JSJitInfo onnegotiationneeded_getterinfo = {
4275
  { (JSJitGetterOp)get_onnegotiationneeded },
4276
  { prototypes::id::RTCPeerConnection },
4277
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
4278
  JSJitInfo::Getter,
4279
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
4280
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
4281
  false,  /* isInfallible. False in setters. */
4282
  false,  /* isMovable.  Not relevant for setters. */
4283
  false, /* isEliminatable.  Not relevant for setters. */
4284
  false, /* isAlwaysInSlot.  Only relevant for getters. */
4285
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
4286
  false,  /* isTypedMethod.  Only relevant for methods. */
4287
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
4288
};
4289
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
4290
static_assert(0 < 1, "There is no slot for us");
4291
static const JSJitInfo onnegotiationneeded_setterinfo = {
4292
  { (JSJitGetterOp)set_onnegotiationneeded },
4293
  { prototypes::id::RTCPeerConnection },
4294
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
4295
  JSJitInfo::Setter,
4296
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
4297
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
4298
  false,  /* isInfallible. False in setters. */
4299
  false,  /* isMovable.  Not relevant for setters. */
4300
  false, /* isEliminatable.  Not relevant for setters. */
4301
  false, /* isAlwaysInSlot.  Only relevant for getters. */
4302
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
4303
  false,  /* isTypedMethod.  Only relevant for methods. */
4304
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
4305
};
4306
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
4307
static_assert(0 < 1, "There is no slot for us");
4308
4309
MOZ_CAN_RUN_SCRIPT static bool
4310
get_onicecandidate(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
4311
0
{
4312
0
  AUTO_PROFILER_LABEL_FAST("get RTCPeerConnection.onicecandidate", DOM, cx);
4313
0
4314
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
4315
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
4316
0
  if (objIsXray) {
4317
0
    unwrappedObj.emplace(cx, obj);
4318
0
  }
4319
0
  if (objIsXray) {
4320
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
4321
0
    if (!unwrappedObj.ref()) {
4322
0
      return false;
4323
0
    }
4324
0
  }
4325
0
  FastErrorResult rv;
4326
0
  RefPtr<EventHandlerNonNull> result(self->GetOnicecandidate(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))));
4327
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
4328
0
    return false;
4329
0
  }
4330
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
4331
0
  if (result) {
4332
0
    args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result));
4333
0
    if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
4334
0
      return false;
4335
0
    }
4336
0
    return true;
4337
0
  } else {
4338
0
    args.rval().setNull();
4339
0
    return true;
4340
0
  }
4341
0
}
4342
4343
MOZ_CAN_RUN_SCRIPT static bool
4344
set_onicecandidate(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitSetterCallArgs args)
4345
0
{
4346
0
  AUTO_PROFILER_LABEL_FAST("set RTCPeerConnection.onicecandidate", DOM, cx);
4347
0
4348
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
4349
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
4350
0
  if (objIsXray) {
4351
0
    unwrappedObj.emplace(cx, obj);
4352
0
  }
4353
0
  RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
4354
0
  if (args[0].isObject()) {
4355
0
    { // scope for tempRoot and tempGlobalRoot if needed
4356
0
      arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx));
4357
0
    }
4358
0
  } else {
4359
0
    arg0 = nullptr;
4360
0
  }
4361
0
  if (objIsXray) {
4362
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
4363
0
    if (!unwrappedObj.ref()) {
4364
0
      return false;
4365
0
    }
4366
0
  }
4367
0
  FastErrorResult rv;
4368
0
  self->SetOnicecandidate(Constify(arg0), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
4369
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
4370
0
    return false;
4371
0
  }
4372
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
4373
0
4374
0
  return true;
4375
0
}
4376
4377
static const JSJitInfo onicecandidate_getterinfo = {
4378
  { (JSJitGetterOp)get_onicecandidate },
4379
  { prototypes::id::RTCPeerConnection },
4380
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
4381
  JSJitInfo::Getter,
4382
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
4383
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
4384
  false,  /* isInfallible. False in setters. */
4385
  false,  /* isMovable.  Not relevant for setters. */
4386
  false, /* isEliminatable.  Not relevant for setters. */
4387
  false, /* isAlwaysInSlot.  Only relevant for getters. */
4388
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
4389
  false,  /* isTypedMethod.  Only relevant for methods. */
4390
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
4391
};
4392
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
4393
static_assert(0 < 1, "There is no slot for us");
4394
static const JSJitInfo onicecandidate_setterinfo = {
4395
  { (JSJitGetterOp)set_onicecandidate },
4396
  { prototypes::id::RTCPeerConnection },
4397
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
4398
  JSJitInfo::Setter,
4399
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
4400
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
4401
  false,  /* isInfallible. False in setters. */
4402
  false,  /* isMovable.  Not relevant for setters. */
4403
  false, /* isEliminatable.  Not relevant for setters. */
4404
  false, /* isAlwaysInSlot.  Only relevant for getters. */
4405
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
4406
  false,  /* isTypedMethod.  Only relevant for methods. */
4407
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
4408
};
4409
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
4410
static_assert(0 < 1, "There is no slot for us");
4411
4412
MOZ_CAN_RUN_SCRIPT static bool
4413
get_onsignalingstatechange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
4414
0
{
4415
0
  AUTO_PROFILER_LABEL_FAST("get RTCPeerConnection.onsignalingstatechange", DOM, cx);
4416
0
4417
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
4418
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
4419
0
  if (objIsXray) {
4420
0
    unwrappedObj.emplace(cx, obj);
4421
0
  }
4422
0
  if (objIsXray) {
4423
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
4424
0
    if (!unwrappedObj.ref()) {
4425
0
      return false;
4426
0
    }
4427
0
  }
4428
0
  FastErrorResult rv;
4429
0
  RefPtr<EventHandlerNonNull> result(self->GetOnsignalingstatechange(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))));
4430
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
4431
0
    return false;
4432
0
  }
4433
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
4434
0
  if (result) {
4435
0
    args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result));
4436
0
    if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
4437
0
      return false;
4438
0
    }
4439
0
    return true;
4440
0
  } else {
4441
0
    args.rval().setNull();
4442
0
    return true;
4443
0
  }
4444
0
}
4445
4446
MOZ_CAN_RUN_SCRIPT static bool
4447
set_onsignalingstatechange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitSetterCallArgs args)
4448
0
{
4449
0
  AUTO_PROFILER_LABEL_FAST("set RTCPeerConnection.onsignalingstatechange", DOM, cx);
4450
0
4451
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
4452
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
4453
0
  if (objIsXray) {
4454
0
    unwrappedObj.emplace(cx, obj);
4455
0
  }
4456
0
  RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
4457
0
  if (args[0].isObject()) {
4458
0
    { // scope for tempRoot and tempGlobalRoot if needed
4459
0
      arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx));
4460
0
    }
4461
0
  } else {
4462
0
    arg0 = nullptr;
4463
0
  }
4464
0
  if (objIsXray) {
4465
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
4466
0
    if (!unwrappedObj.ref()) {
4467
0
      return false;
4468
0
    }
4469
0
  }
4470
0
  FastErrorResult rv;
4471
0
  self->SetOnsignalingstatechange(Constify(arg0), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
4472
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
4473
0
    return false;
4474
0
  }
4475
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
4476
0
4477
0
  return true;
4478
0
}
4479
4480
static const JSJitInfo onsignalingstatechange_getterinfo = {
4481
  { (JSJitGetterOp)get_onsignalingstatechange },
4482
  { prototypes::id::RTCPeerConnection },
4483
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
4484
  JSJitInfo::Getter,
4485
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
4486
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
4487
  false,  /* isInfallible. False in setters. */
4488
  false,  /* isMovable.  Not relevant for setters. */
4489
  false, /* isEliminatable.  Not relevant for setters. */
4490
  false, /* isAlwaysInSlot.  Only relevant for getters. */
4491
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
4492
  false,  /* isTypedMethod.  Only relevant for methods. */
4493
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
4494
};
4495
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
4496
static_assert(0 < 1, "There is no slot for us");
4497
static const JSJitInfo onsignalingstatechange_setterinfo = {
4498
  { (JSJitGetterOp)set_onsignalingstatechange },
4499
  { prototypes::id::RTCPeerConnection },
4500
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
4501
  JSJitInfo::Setter,
4502
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
4503
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
4504
  false,  /* isInfallible. False in setters. */
4505
  false,  /* isMovable.  Not relevant for setters. */
4506
  false, /* isEliminatable.  Not relevant for setters. */
4507
  false, /* isAlwaysInSlot.  Only relevant for getters. */
4508
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
4509
  false,  /* isTypedMethod.  Only relevant for methods. */
4510
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
4511
};
4512
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
4513
static_assert(0 < 1, "There is no slot for us");
4514
4515
MOZ_CAN_RUN_SCRIPT static bool
4516
get_onaddstream(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
4517
0
{
4518
0
  AUTO_PROFILER_LABEL_FAST("get RTCPeerConnection.onaddstream", DOM, cx);
4519
0
4520
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
4521
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
4522
0
  if (objIsXray) {
4523
0
    unwrappedObj.emplace(cx, obj);
4524
0
  }
4525
0
  if (objIsXray) {
4526
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
4527
0
    if (!unwrappedObj.ref()) {
4528
0
      return false;
4529
0
    }
4530
0
  }
4531
0
  FastErrorResult rv;
4532
0
  RefPtr<EventHandlerNonNull> result(self->GetOnaddstream(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))));
4533
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
4534
0
    return false;
4535
0
  }
4536
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
4537
0
  if (result) {
4538
0
    args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result));
4539
0
    if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
4540
0
      return false;
4541
0
    }
4542
0
    return true;
4543
0
  } else {
4544
0
    args.rval().setNull();
4545
0
    return true;
4546
0
  }
4547
0
}
4548
4549
MOZ_CAN_RUN_SCRIPT static bool
4550
set_onaddstream(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitSetterCallArgs args)
4551
0
{
4552
0
  AUTO_PROFILER_LABEL_FAST("set RTCPeerConnection.onaddstream", DOM, cx);
4553
0
4554
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
4555
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
4556
0
  if (objIsXray) {
4557
0
    unwrappedObj.emplace(cx, obj);
4558
0
  }
4559
0
  RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
4560
0
  if (args[0].isObject()) {
4561
0
    { // scope for tempRoot and tempGlobalRoot if needed
4562
0
      arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx));
4563
0
    }
4564
0
  } else {
4565
0
    arg0 = nullptr;
4566
0
  }
4567
0
  if (objIsXray) {
4568
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
4569
0
    if (!unwrappedObj.ref()) {
4570
0
      return false;
4571
0
    }
4572
0
  }
4573
0
  FastErrorResult rv;
4574
0
  self->SetOnaddstream(Constify(arg0), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
4575
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
4576
0
    return false;
4577
0
  }
4578
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
4579
0
4580
0
  return true;
4581
0
}
4582
4583
static const JSJitInfo onaddstream_getterinfo = {
4584
  { (JSJitGetterOp)get_onaddstream },
4585
  { prototypes::id::RTCPeerConnection },
4586
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
4587
  JSJitInfo::Getter,
4588
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
4589
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
4590
  false,  /* isInfallible. False in setters. */
4591
  false,  /* isMovable.  Not relevant for setters. */
4592
  false, /* isEliminatable.  Not relevant for setters. */
4593
  false, /* isAlwaysInSlot.  Only relevant for getters. */
4594
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
4595
  false,  /* isTypedMethod.  Only relevant for methods. */
4596
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
4597
};
4598
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
4599
static_assert(0 < 1, "There is no slot for us");
4600
static const JSJitInfo onaddstream_setterinfo = {
4601
  { (JSJitGetterOp)set_onaddstream },
4602
  { prototypes::id::RTCPeerConnection },
4603
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
4604
  JSJitInfo::Setter,
4605
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
4606
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
4607
  false,  /* isInfallible. False in setters. */
4608
  false,  /* isMovable.  Not relevant for setters. */
4609
  false, /* isEliminatable.  Not relevant for setters. */
4610
  false, /* isAlwaysInSlot.  Only relevant for getters. */
4611
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
4612
  false,  /* isTypedMethod.  Only relevant for methods. */
4613
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
4614
};
4615
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
4616
static_assert(0 < 1, "There is no slot for us");
4617
4618
MOZ_CAN_RUN_SCRIPT static bool
4619
get_onaddtrack(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
4620
0
{
4621
0
  AUTO_PROFILER_LABEL_FAST("get RTCPeerConnection.onaddtrack", DOM, cx);
4622
0
4623
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
4624
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
4625
0
  if (objIsXray) {
4626
0
    unwrappedObj.emplace(cx, obj);
4627
0
  }
4628
0
  if (objIsXray) {
4629
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
4630
0
    if (!unwrappedObj.ref()) {
4631
0
      return false;
4632
0
    }
4633
0
  }
4634
0
  FastErrorResult rv;
4635
0
  RefPtr<EventHandlerNonNull> result(self->GetOnaddtrack(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))));
4636
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
4637
0
    return false;
4638
0
  }
4639
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
4640
0
  if (result) {
4641
0
    args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result));
4642
0
    if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
4643
0
      return false;
4644
0
    }
4645
0
    return true;
4646
0
  } else {
4647
0
    args.rval().setNull();
4648
0
    return true;
4649
0
  }
4650
0
}
4651
4652
MOZ_CAN_RUN_SCRIPT static bool
4653
set_onaddtrack(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitSetterCallArgs args)
4654
0
{
4655
0
  AUTO_PROFILER_LABEL_FAST("set RTCPeerConnection.onaddtrack", DOM, cx);
4656
0
4657
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
4658
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
4659
0
  if (objIsXray) {
4660
0
    unwrappedObj.emplace(cx, obj);
4661
0
  }
4662
0
  RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
4663
0
  if (args[0].isObject()) {
4664
0
    { // scope for tempRoot and tempGlobalRoot if needed
4665
0
      arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx));
4666
0
    }
4667
0
  } else {
4668
0
    arg0 = nullptr;
4669
0
  }
4670
0
  if (objIsXray) {
4671
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
4672
0
    if (!unwrappedObj.ref()) {
4673
0
      return false;
4674
0
    }
4675
0
  }
4676
0
  FastErrorResult rv;
4677
0
  self->SetOnaddtrack(Constify(arg0), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
4678
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
4679
0
    return false;
4680
0
  }
4681
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
4682
0
4683
0
  return true;
4684
0
}
4685
4686
static const JSJitInfo onaddtrack_getterinfo = {
4687
  { (JSJitGetterOp)get_onaddtrack },
4688
  { prototypes::id::RTCPeerConnection },
4689
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
4690
  JSJitInfo::Getter,
4691
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
4692
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
4693
  false,  /* isInfallible. False in setters. */
4694
  false,  /* isMovable.  Not relevant for setters. */
4695
  false, /* isEliminatable.  Not relevant for setters. */
4696
  false, /* isAlwaysInSlot.  Only relevant for getters. */
4697
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
4698
  false,  /* isTypedMethod.  Only relevant for methods. */
4699
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
4700
};
4701
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
4702
static_assert(0 < 1, "There is no slot for us");
4703
static const JSJitInfo onaddtrack_setterinfo = {
4704
  { (JSJitGetterOp)set_onaddtrack },
4705
  { prototypes::id::RTCPeerConnection },
4706
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
4707
  JSJitInfo::Setter,
4708
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
4709
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
4710
  false,  /* isInfallible. False in setters. */
4711
  false,  /* isMovable.  Not relevant for setters. */
4712
  false, /* isEliminatable.  Not relevant for setters. */
4713
  false, /* isAlwaysInSlot.  Only relevant for getters. */
4714
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
4715
  false,  /* isTypedMethod.  Only relevant for methods. */
4716
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
4717
};
4718
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
4719
static_assert(0 < 1, "There is no slot for us");
4720
4721
MOZ_CAN_RUN_SCRIPT static bool
4722
get_ontrack(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
4723
0
{
4724
0
  AUTO_PROFILER_LABEL_FAST("get RTCPeerConnection.ontrack", DOM, cx);
4725
0
4726
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
4727
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
4728
0
  if (objIsXray) {
4729
0
    unwrappedObj.emplace(cx, obj);
4730
0
  }
4731
0
  if (objIsXray) {
4732
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
4733
0
    if (!unwrappedObj.ref()) {
4734
0
      return false;
4735
0
    }
4736
0
  }
4737
0
  FastErrorResult rv;
4738
0
  RefPtr<EventHandlerNonNull> result(self->GetOntrack(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))));
4739
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
4740
0
    return false;
4741
0
  }
4742
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
4743
0
  if (result) {
4744
0
    args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result));
4745
0
    if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
4746
0
      return false;
4747
0
    }
4748
0
    return true;
4749
0
  } else {
4750
0
    args.rval().setNull();
4751
0
    return true;
4752
0
  }
4753
0
}
4754
4755
MOZ_CAN_RUN_SCRIPT static bool
4756
set_ontrack(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitSetterCallArgs args)
4757
0
{
4758
0
  AUTO_PROFILER_LABEL_FAST("set RTCPeerConnection.ontrack", DOM, cx);
4759
0
4760
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
4761
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
4762
0
  if (objIsXray) {
4763
0
    unwrappedObj.emplace(cx, obj);
4764
0
  }
4765
0
  RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
4766
0
  if (args[0].isObject()) {
4767
0
    { // scope for tempRoot and tempGlobalRoot if needed
4768
0
      arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx));
4769
0
    }
4770
0
  } else {
4771
0
    arg0 = nullptr;
4772
0
  }
4773
0
  if (objIsXray) {
4774
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
4775
0
    if (!unwrappedObj.ref()) {
4776
0
      return false;
4777
0
    }
4778
0
  }
4779
0
  FastErrorResult rv;
4780
0
  self->SetOntrack(Constify(arg0), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
4781
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
4782
0
    return false;
4783
0
  }
4784
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
4785
0
4786
0
  return true;
4787
0
}
4788
4789
static const JSJitInfo ontrack_getterinfo = {
4790
  { (JSJitGetterOp)get_ontrack },
4791
  { prototypes::id::RTCPeerConnection },
4792
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
4793
  JSJitInfo::Getter,
4794
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
4795
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
4796
  false,  /* isInfallible. False in setters. */
4797
  false,  /* isMovable.  Not relevant for setters. */
4798
  false, /* isEliminatable.  Not relevant for setters. */
4799
  false, /* isAlwaysInSlot.  Only relevant for getters. */
4800
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
4801
  false,  /* isTypedMethod.  Only relevant for methods. */
4802
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
4803
};
4804
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
4805
static_assert(0 < 1, "There is no slot for us");
4806
static const JSJitInfo ontrack_setterinfo = {
4807
  { (JSJitGetterOp)set_ontrack },
4808
  { prototypes::id::RTCPeerConnection },
4809
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
4810
  JSJitInfo::Setter,
4811
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
4812
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
4813
  false,  /* isInfallible. False in setters. */
4814
  false,  /* isMovable.  Not relevant for setters. */
4815
  false, /* isEliminatable.  Not relevant for setters. */
4816
  false, /* isAlwaysInSlot.  Only relevant for getters. */
4817
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
4818
  false,  /* isTypedMethod.  Only relevant for methods. */
4819
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
4820
};
4821
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
4822
static_assert(0 < 1, "There is no slot for us");
4823
4824
MOZ_CAN_RUN_SCRIPT static bool
4825
get_onremovestream(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
4826
0
{
4827
0
  AUTO_PROFILER_LABEL_FAST("get RTCPeerConnection.onremovestream", DOM, cx);
4828
0
4829
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
4830
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
4831
0
  if (objIsXray) {
4832
0
    unwrappedObj.emplace(cx, obj);
4833
0
  }
4834
0
  if (objIsXray) {
4835
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
4836
0
    if (!unwrappedObj.ref()) {
4837
0
      return false;
4838
0
    }
4839
0
  }
4840
0
  FastErrorResult rv;
4841
0
  RefPtr<EventHandlerNonNull> result(self->GetOnremovestream(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))));
4842
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
4843
0
    return false;
4844
0
  }
4845
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
4846
0
  if (result) {
4847
0
    args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result));
4848
0
    if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
4849
0
      return false;
4850
0
    }
4851
0
    return true;
4852
0
  } else {
4853
0
    args.rval().setNull();
4854
0
    return true;
4855
0
  }
4856
0
}
4857
4858
MOZ_CAN_RUN_SCRIPT static bool
4859
set_onremovestream(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitSetterCallArgs args)
4860
0
{
4861
0
  AUTO_PROFILER_LABEL_FAST("set RTCPeerConnection.onremovestream", DOM, cx);
4862
0
4863
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
4864
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
4865
0
  if (objIsXray) {
4866
0
    unwrappedObj.emplace(cx, obj);
4867
0
  }
4868
0
  RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
4869
0
  if (args[0].isObject()) {
4870
0
    { // scope for tempRoot and tempGlobalRoot if needed
4871
0
      arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx));
4872
0
    }
4873
0
  } else {
4874
0
    arg0 = nullptr;
4875
0
  }
4876
0
  if (objIsXray) {
4877
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
4878
0
    if (!unwrappedObj.ref()) {
4879
0
      return false;
4880
0
    }
4881
0
  }
4882
0
  FastErrorResult rv;
4883
0
  self->SetOnremovestream(Constify(arg0), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
4884
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
4885
0
    return false;
4886
0
  }
4887
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
4888
0
4889
0
  return true;
4890
0
}
4891
4892
static const JSJitInfo onremovestream_getterinfo = {
4893
  { (JSJitGetterOp)get_onremovestream },
4894
  { prototypes::id::RTCPeerConnection },
4895
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
4896
  JSJitInfo::Getter,
4897
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
4898
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
4899
  false,  /* isInfallible. False in setters. */
4900
  false,  /* isMovable.  Not relevant for setters. */
4901
  false, /* isEliminatable.  Not relevant for setters. */
4902
  false, /* isAlwaysInSlot.  Only relevant for getters. */
4903
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
4904
  false,  /* isTypedMethod.  Only relevant for methods. */
4905
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
4906
};
4907
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
4908
static_assert(0 < 1, "There is no slot for us");
4909
static const JSJitInfo onremovestream_setterinfo = {
4910
  { (JSJitGetterOp)set_onremovestream },
4911
  { prototypes::id::RTCPeerConnection },
4912
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
4913
  JSJitInfo::Setter,
4914
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
4915
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
4916
  false,  /* isInfallible. False in setters. */
4917
  false,  /* isMovable.  Not relevant for setters. */
4918
  false, /* isEliminatable.  Not relevant for setters. */
4919
  false, /* isAlwaysInSlot.  Only relevant for getters. */
4920
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
4921
  false,  /* isTypedMethod.  Only relevant for methods. */
4922
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
4923
};
4924
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
4925
static_assert(0 < 1, "There is no slot for us");
4926
4927
MOZ_CAN_RUN_SCRIPT static bool
4928
get_oniceconnectionstatechange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
4929
0
{
4930
0
  AUTO_PROFILER_LABEL_FAST("get RTCPeerConnection.oniceconnectionstatechange", DOM, cx);
4931
0
4932
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
4933
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
4934
0
  if (objIsXray) {
4935
0
    unwrappedObj.emplace(cx, obj);
4936
0
  }
4937
0
  if (objIsXray) {
4938
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
4939
0
    if (!unwrappedObj.ref()) {
4940
0
      return false;
4941
0
    }
4942
0
  }
4943
0
  FastErrorResult rv;
4944
0
  RefPtr<EventHandlerNonNull> result(self->GetOniceconnectionstatechange(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))));
4945
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
4946
0
    return false;
4947
0
  }
4948
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
4949
0
  if (result) {
4950
0
    args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result));
4951
0
    if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
4952
0
      return false;
4953
0
    }
4954
0
    return true;
4955
0
  } else {
4956
0
    args.rval().setNull();
4957
0
    return true;
4958
0
  }
4959
0
}
4960
4961
MOZ_CAN_RUN_SCRIPT static bool
4962
set_oniceconnectionstatechange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitSetterCallArgs args)
4963
0
{
4964
0
  AUTO_PROFILER_LABEL_FAST("set RTCPeerConnection.oniceconnectionstatechange", DOM, cx);
4965
0
4966
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
4967
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
4968
0
  if (objIsXray) {
4969
0
    unwrappedObj.emplace(cx, obj);
4970
0
  }
4971
0
  RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
4972
0
  if (args[0].isObject()) {
4973
0
    { // scope for tempRoot and tempGlobalRoot if needed
4974
0
      arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx));
4975
0
    }
4976
0
  } else {
4977
0
    arg0 = nullptr;
4978
0
  }
4979
0
  if (objIsXray) {
4980
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
4981
0
    if (!unwrappedObj.ref()) {
4982
0
      return false;
4983
0
    }
4984
0
  }
4985
0
  FastErrorResult rv;
4986
0
  self->SetOniceconnectionstatechange(Constify(arg0), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
4987
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
4988
0
    return false;
4989
0
  }
4990
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
4991
0
4992
0
  return true;
4993
0
}
4994
4995
static const JSJitInfo oniceconnectionstatechange_getterinfo = {
4996
  { (JSJitGetterOp)get_oniceconnectionstatechange },
4997
  { prototypes::id::RTCPeerConnection },
4998
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
4999
  JSJitInfo::Getter,
5000
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
5001
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
5002
  false,  /* isInfallible. False in setters. */
5003
  false,  /* isMovable.  Not relevant for setters. */
5004
  false, /* isEliminatable.  Not relevant for setters. */
5005
  false, /* isAlwaysInSlot.  Only relevant for getters. */
5006
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
5007
  false,  /* isTypedMethod.  Only relevant for methods. */
5008
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
5009
};
5010
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
5011
static_assert(0 < 1, "There is no slot for us");
5012
static const JSJitInfo oniceconnectionstatechange_setterinfo = {
5013
  { (JSJitGetterOp)set_oniceconnectionstatechange },
5014
  { prototypes::id::RTCPeerConnection },
5015
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
5016
  JSJitInfo::Setter,
5017
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
5018
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
5019
  false,  /* isInfallible. False in setters. */
5020
  false,  /* isMovable.  Not relevant for setters. */
5021
  false, /* isEliminatable.  Not relevant for setters. */
5022
  false, /* isAlwaysInSlot.  Only relevant for getters. */
5023
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
5024
  false,  /* isTypedMethod.  Only relevant for methods. */
5025
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
5026
};
5027
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
5028
static_assert(0 < 1, "There is no slot for us");
5029
5030
MOZ_CAN_RUN_SCRIPT static bool
5031
get_onicegatheringstatechange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
5032
0
{
5033
0
  AUTO_PROFILER_LABEL_FAST("get RTCPeerConnection.onicegatheringstatechange", DOM, cx);
5034
0
5035
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
5036
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
5037
0
  if (objIsXray) {
5038
0
    unwrappedObj.emplace(cx, obj);
5039
0
  }
5040
0
  if (objIsXray) {
5041
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
5042
0
    if (!unwrappedObj.ref()) {
5043
0
      return false;
5044
0
    }
5045
0
  }
5046
0
  FastErrorResult rv;
5047
0
  RefPtr<EventHandlerNonNull> result(self->GetOnicegatheringstatechange(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))));
5048
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
5049
0
    return false;
5050
0
  }
5051
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
5052
0
  if (result) {
5053
0
    args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result));
5054
0
    if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
5055
0
      return false;
5056
0
    }
5057
0
    return true;
5058
0
  } else {
5059
0
    args.rval().setNull();
5060
0
    return true;
5061
0
  }
5062
0
}
5063
5064
MOZ_CAN_RUN_SCRIPT static bool
5065
set_onicegatheringstatechange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitSetterCallArgs args)
5066
0
{
5067
0
  AUTO_PROFILER_LABEL_FAST("set RTCPeerConnection.onicegatheringstatechange", DOM, cx);
5068
0
5069
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
5070
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
5071
0
  if (objIsXray) {
5072
0
    unwrappedObj.emplace(cx, obj);
5073
0
  }
5074
0
  RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
5075
0
  if (args[0].isObject()) {
5076
0
    { // scope for tempRoot and tempGlobalRoot if needed
5077
0
      arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx));
5078
0
    }
5079
0
  } else {
5080
0
    arg0 = nullptr;
5081
0
  }
5082
0
  if (objIsXray) {
5083
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
5084
0
    if (!unwrappedObj.ref()) {
5085
0
      return false;
5086
0
    }
5087
0
  }
5088
0
  FastErrorResult rv;
5089
0
  self->SetOnicegatheringstatechange(Constify(arg0), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
5090
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
5091
0
    return false;
5092
0
  }
5093
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
5094
0
5095
0
  return true;
5096
0
}
5097
5098
static const JSJitInfo onicegatheringstatechange_getterinfo = {
5099
  { (JSJitGetterOp)get_onicegatheringstatechange },
5100
  { prototypes::id::RTCPeerConnection },
5101
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
5102
  JSJitInfo::Getter,
5103
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
5104
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
5105
  false,  /* isInfallible. False in setters. */
5106
  false,  /* isMovable.  Not relevant for setters. */
5107
  false, /* isEliminatable.  Not relevant for setters. */
5108
  false, /* isAlwaysInSlot.  Only relevant for getters. */
5109
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
5110
  false,  /* isTypedMethod.  Only relevant for methods. */
5111
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
5112
};
5113
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
5114
static_assert(0 < 1, "There is no slot for us");
5115
static const JSJitInfo onicegatheringstatechange_setterinfo = {
5116
  { (JSJitGetterOp)set_onicegatheringstatechange },
5117
  { prototypes::id::RTCPeerConnection },
5118
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
5119
  JSJitInfo::Setter,
5120
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
5121
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
5122
  false,  /* isInfallible. False in setters. */
5123
  false,  /* isMovable.  Not relevant for setters. */
5124
  false, /* isEliminatable.  Not relevant for setters. */
5125
  false, /* isAlwaysInSlot.  Only relevant for getters. */
5126
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
5127
  false,  /* isTypedMethod.  Only relevant for methods. */
5128
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
5129
};
5130
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
5131
static_assert(0 < 1, "There is no slot for us");
5132
5133
MOZ_CAN_RUN_SCRIPT static bool
5134
getStats(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
5135
0
{
5136
0
  AUTO_PROFILER_LABEL_FAST("RTCPeerConnection.getStats", DOM, cx);
5137
0
5138
0
  unsigned argcount = std::min(args.length(), 3u);
5139
0
  switch (argcount) {
5140
0
    case 0: {
5141
0
      MOZ_FALLTHROUGH;
5142
0
    }
5143
0
    case 1: {
5144
0
      Maybe<JS::Rooted<JSObject*> > unwrappedObj;
5145
0
      bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
5146
0
      if (objIsXray) {
5147
0
        unwrappedObj.emplace(cx, obj);
5148
0
      }
5149
0
      Optional<mozilla::dom::MediaStreamTrack*> arg0;
5150
0
      if (args.hasDefined(0)) {
5151
0
        arg0.Construct();
5152
0
        if (args[0].isObject()) {
5153
0
          {
5154
0
            nsresult rv = UnwrapObject<prototypes::id::MediaStreamTrack, mozilla::dom::MediaStreamTrack>(args[0], arg0.Value());
5155
0
            if (NS_FAILED(rv)) {
5156
0
              ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of RTCPeerConnection.getStats", "MediaStreamTrack");
5157
0
              return false;
5158
0
            }
5159
0
          }
5160
0
        } else if (args[0].isNullOrUndefined()) {
5161
0
          arg0.Value() = nullptr;
5162
0
        } else {
5163
0
          ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of RTCPeerConnection.getStats");
5164
0
          return false;
5165
0
        }
5166
0
      }
5167
0
      if (objIsXray) {
5168
0
        unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
5169
0
        if (!unwrappedObj.ref()) {
5170
0
          return false;
5171
0
        }
5172
0
      }
5173
0
      FastErrorResult rv;
5174
0
      auto result(StrongOrRawPtr<Promise>(self->GetStats(MOZ_KnownLive(Constify(arg0)), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)))));
5175
0
      if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
5176
0
        return false;
5177
0
      }
5178
0
      MOZ_ASSERT(!JS_IsExceptionPending(cx));
5179
0
      if (!ToJSValue(cx, result, args.rval())) {
5180
0
        return false;
5181
0
      }
5182
0
      return true;
5183
0
      break;
5184
0
    }
5185
0
    case 3: {
5186
0
      Maybe<JS::Rooted<JSObject*> > unwrappedObj;
5187
0
      bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
5188
0
      if (objIsXray) {
5189
0
        unwrappedObj.emplace(cx, obj);
5190
0
      }
5191
0
      mozilla::dom::MediaStreamTrack* arg0;
5192
0
      if (args[0].isObject()) {
5193
0
        {
5194
0
          nsresult rv = UnwrapObject<prototypes::id::MediaStreamTrack, mozilla::dom::MediaStreamTrack>(args[0], arg0);
5195
0
          if (NS_FAILED(rv)) {
5196
0
            ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of RTCPeerConnection.getStats", "MediaStreamTrack");
5197
0
            return false;
5198
0
          }
5199
0
        }
5200
0
      } else if (args[0].isNullOrUndefined()) {
5201
0
        arg0 = nullptr;
5202
0
      } else {
5203
0
        ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of RTCPeerConnection.getStats");
5204
0
        return false;
5205
0
      }
5206
0
      RootedCallback<OwningNonNull<binding_detail::FastRTCStatsCallback>> arg1(cx);
5207
0
      if (args[1].isObject()) {
5208
0
        if (JS::IsCallable(&args[1].toObject())) {
5209
0
        { // scope for tempRoot and tempGlobalRoot if needed
5210
0
          arg1 = new binding_detail::FastRTCStatsCallback(&args[1].toObject(), JS::CurrentGlobalOrNull(cx));
5211
0
        }
5212
0
        } else {
5213
0
          ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 2 of RTCPeerConnection.getStats");
5214
0
          return false;
5215
0
        }
5216
0
      } else {
5217
0
        ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of RTCPeerConnection.getStats");
5218
0
        return false;
5219
0
      }
5220
0
      RootedCallback<OwningNonNull<binding_detail::FastRTCPeerConnectionErrorCallback>> arg2(cx);
5221
0
      if (args[2].isObject()) {
5222
0
        if (JS::IsCallable(&args[2].toObject())) {
5223
0
        { // scope for tempRoot and tempGlobalRoot if needed
5224
0
          arg2 = new binding_detail::FastRTCPeerConnectionErrorCallback(&args[2].toObject(), JS::CurrentGlobalOrNull(cx));
5225
0
        }
5226
0
        } else {
5227
0
          ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 3 of RTCPeerConnection.getStats");
5228
0
          return false;
5229
0
        }
5230
0
      } else {
5231
0
        ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 3 of RTCPeerConnection.getStats");
5232
0
        return false;
5233
0
      }
5234
0
      if (objIsXray) {
5235
0
        unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
5236
0
        if (!unwrappedObj.ref()) {
5237
0
          return false;
5238
0
        }
5239
0
      }
5240
0
      FastErrorResult rv;
5241
0
      auto result(StrongOrRawPtr<Promise>(self->GetStats(MOZ_KnownLive(Constify(arg0)), NonNullHelper(arg1), NonNullHelper(arg2), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)))));
5242
0
      if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
5243
0
        return false;
5244
0
      }
5245
0
      MOZ_ASSERT(!JS_IsExceptionPending(cx));
5246
0
      if (!ToJSValue(cx, result, args.rval())) {
5247
0
        return false;
5248
0
      }
5249
0
      return true;
5250
0
      break;
5251
0
    }
5252
0
    default: {
5253
0
      return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCPeerConnection.getStats");
5254
0
      break;
5255
0
    }
5256
0
  }
5257
0
  MOZ_CRASH("We have an always-returning default case");
5258
0
  return false;
5259
0
}
5260
5261
MOZ_CAN_RUN_SCRIPT static bool
5262
getStats_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
5263
0
{
5264
0
  bool ok = getStats(cx, obj, self, args);
5265
0
  if (ok) {
5266
0
    return true;
5267
0
  }
5268
0
  return ConvertExceptionToPromise(cx, args.rval());
5269
0
}
5270
5271
static const JSJitInfo getStats_methodinfo = {
5272
  { (JSJitGetterOp)getStats_promiseWrapper },
5273
  { prototypes::id::RTCPeerConnection },
5274
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
5275
  JSJitInfo::Method,
5276
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
5277
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
5278
  false,  /* isInfallible. False in setters. */
5279
  false,  /* isMovable.  Not relevant for setters. */
5280
  false, /* isEliminatable.  Not relevant for setters. */
5281
  false, /* isAlwaysInSlot.  Only relevant for getters. */
5282
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
5283
  false,  /* isTypedMethod.  Only relevant for methods. */
5284
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
5285
};
5286
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
5287
static_assert(0 < 1, "There is no slot for us");
5288
5289
MOZ_CAN_RUN_SCRIPT static bool
5290
createDataChannel(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, const JSJitMethodCallArgs& args)
5291
0
{
5292
0
  AUTO_PROFILER_LABEL_FAST("RTCPeerConnection.createDataChannel", DOM, cx);
5293
0
5294
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
5295
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCPeerConnection.createDataChannel");
5296
0
  }
5297
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
5298
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
5299
0
  if (objIsXray) {
5300
0
    unwrappedObj.emplace(cx, obj);
5301
0
  }
5302
0
  binding_detail::FakeString arg0;
5303
0
  if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
5304
0
    return false;
5305
0
  }
5306
0
  binding_detail::FastRTCDataChannelInit arg1;
5307
0
  if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue,  "Argument 2 of RTCPeerConnection.createDataChannel", true)) {
5308
0
    return false;
5309
0
  }
5310
0
  if (objIsXray) {
5311
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
5312
0
    if (!unwrappedObj.ref()) {
5313
0
      return false;
5314
0
    }
5315
0
  }
5316
0
  FastErrorResult rv;
5317
0
  auto result(StrongOrRawPtr<nsDOMDataChannel>(self->CreateDataChannel(NonNullHelper(Constify(arg0)), Constify(arg1), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)))));
5318
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
5319
0
    return false;
5320
0
  }
5321
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
5322
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
5323
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
5324
0
    return false;
5325
0
  }
5326
0
  return true;
5327
0
}
5328
5329
static const JSJitInfo createDataChannel_methodinfo = {
5330
  { (JSJitGetterOp)createDataChannel },
5331
  { prototypes::id::RTCPeerConnection },
5332
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
5333
  JSJitInfo::Method,
5334
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
5335
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
5336
  false,  /* isInfallible. False in setters. */
5337
  false,  /* isMovable.  Not relevant for setters. */
5338
  false, /* isEliminatable.  Not relevant for setters. */
5339
  false, /* isAlwaysInSlot.  Only relevant for getters. */
5340
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
5341
  false,  /* isTypedMethod.  Only relevant for methods. */
5342
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
5343
};
5344
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
5345
static_assert(0 < 1, "There is no slot for us");
5346
5347
MOZ_CAN_RUN_SCRIPT static bool
5348
get_ondatachannel(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitGetterCallArgs args)
5349
0
{
5350
0
  AUTO_PROFILER_LABEL_FAST("get RTCPeerConnection.ondatachannel", DOM, cx);
5351
0
5352
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
5353
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
5354
0
  if (objIsXray) {
5355
0
    unwrappedObj.emplace(cx, obj);
5356
0
  }
5357
0
  if (objIsXray) {
5358
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
5359
0
    if (!unwrappedObj.ref()) {
5360
0
      return false;
5361
0
    }
5362
0
  }
5363
0
  FastErrorResult rv;
5364
0
  RefPtr<EventHandlerNonNull> result(self->GetOndatachannel(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx))));
5365
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
5366
0
    return false;
5367
0
  }
5368
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
5369
0
  if (result) {
5370
0
    args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result));
5371
0
    if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
5372
0
      return false;
5373
0
    }
5374
0
    return true;
5375
0
  } else {
5376
0
    args.rval().setNull();
5377
0
    return true;
5378
0
  }
5379
0
}
5380
5381
MOZ_CAN_RUN_SCRIPT static bool
5382
set_ondatachannel(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCPeerConnection* self, JSJitSetterCallArgs args)
5383
0
{
5384
0
  AUTO_PROFILER_LABEL_FAST("set RTCPeerConnection.ondatachannel", DOM, cx);
5385
0
5386
0
  Maybe<JS::Rooted<JSObject*> > unwrappedObj;
5387
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
5388
0
  if (objIsXray) {
5389
0
    unwrappedObj.emplace(cx, obj);
5390
0
  }
5391
0
  RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
5392
0
  if (args[0].isObject()) {
5393
0
    { // scope for tempRoot and tempGlobalRoot if needed
5394
0
      arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx));
5395
0
    }
5396
0
  } else {
5397
0
    arg0 = nullptr;
5398
0
  }
5399
0
  if (objIsXray) {
5400
0
    unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
5401
0
    if (!unwrappedObj.ref()) {
5402
0
      return false;
5403
0
    }
5404
0
  }
5405
0
  FastErrorResult rv;
5406
0
  self->SetOndatachannel(Constify(arg0), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)));
5407
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
5408
0
    return false;
5409
0
  }
5410
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
5411
0
5412
0
  return true;
5413
0
}
5414
5415
static const JSJitInfo ondatachannel_getterinfo = {
5416
  { (JSJitGetterOp)get_ondatachannel },
5417
  { prototypes::id::RTCPeerConnection },
5418
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
5419
  JSJitInfo::Getter,
5420
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
5421
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
5422
  false,  /* isInfallible. False in setters. */
5423
  false,  /* isMovable.  Not relevant for setters. */
5424
  false, /* isEliminatable.  Not relevant for setters. */
5425
  false, /* isAlwaysInSlot.  Only relevant for getters. */
5426
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
5427
  false,  /* isTypedMethod.  Only relevant for methods. */
5428
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
5429
};
5430
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
5431
static_assert(0 < 1, "There is no slot for us");
5432
static const JSJitInfo ondatachannel_setterinfo = {
5433
  { (JSJitGetterOp)set_ondatachannel },
5434
  { prototypes::id::RTCPeerConnection },
5435
  { PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth },
5436
  JSJitInfo::Setter,
5437
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
5438
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
5439
  false,  /* isInfallible. False in setters. */
5440
  false,  /* isMovable.  Not relevant for setters. */
5441
  false, /* isEliminatable.  Not relevant for setters. */
5442
  false, /* isAlwaysInSlot.  Only relevant for getters. */
5443
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
5444
  false,  /* isTypedMethod.  Only relevant for methods. */
5445
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
5446
};
5447
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
5448
static_assert(0 < 1, "There is no slot for us");
5449
5450
static bool
5451
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
5452
0
{
5453
0
  mozilla::dom::RTCPeerConnection* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::RTCPeerConnection>(obj);
5454
0
  // We don't want to preserve if we don't have a wrapper, and we
5455
0
  // obviously can't preserve if we're not initialized.
5456
0
  if (self && self->GetWrapperPreserveColor()) {
5457
0
    PreserveWrapper(self);
5458
0
  }
5459
0
  return true;
5460
0
}
5461
5462
static void
5463
_finalize(js::FreeOp* fop, JSObject* obj)
5464
0
{
5465
0
  mozilla::dom::RTCPeerConnection* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::RTCPeerConnection>(obj);
5466
0
  if (self) {
5467
0
    ClearWrapper(self, self, obj);
5468
0
    AddForDeferredFinalization<mozilla::dom::RTCPeerConnection>(self);
5469
0
  }
5470
0
}
5471
5472
static size_t
5473
_objectMoved(JSObject* obj, JSObject* old)
5474
0
{
5475
0
  mozilla::dom::RTCPeerConnection* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::RTCPeerConnection>(obj);
5476
0
  if (self) {
5477
0
    UpdateWrapper(self, self, obj, old);
5478
0
  }
5479
0
5480
0
  return 0;
5481
0
}
5482
5483
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
5484
#if defined(__clang__)
5485
#pragma clang diagnostic push
5486
#pragma clang diagnostic ignored "-Wmissing-braces"
5487
#endif
5488
static const JSFunctionSpec sStaticMethods_specs[] = {
5489
  JS_FNSPEC("generateCertificate", StaticMethodPromiseWrapper, &generateCertificate_methodinfo, 1, JSPROP_ENUMERATE, nullptr),
5490
  JS_FS_END
5491
};
5492
#if defined(__clang__)
5493
#pragma clang diagnostic pop
5494
#endif
5495
5496
5497
static const Prefable<const JSFunctionSpec> sStaticMethods[] = {
5498
  { nullptr, &sStaticMethods_specs[0] },
5499
  { nullptr, nullptr }
5500
};
5501
5502
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
5503
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
5504
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
5505
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
5506
5507
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
5508
#if defined(__clang__)
5509
#pragma clang diagnostic push
5510
#pragma clang diagnostic ignored "-Wmissing-braces"
5511
#endif
5512
static const JSFunctionSpec sChromeStaticMethods_specs[] = {
5513
  JS_FNSPEC("_create", RTCPeerConnection::_Create, nullptr, 2, 0, nullptr),
5514
  JS_FS_END
5515
};
5516
#if defined(__clang__)
5517
#pragma clang diagnostic pop
5518
#endif
5519
5520
5521
static const Prefable<const JSFunctionSpec> sChromeStaticMethods[] = {
5522
  { nullptr, &sChromeStaticMethods_specs[0] },
5523
  { nullptr, nullptr }
5524
};
5525
5526
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
5527
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
5528
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
5529
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
5530
5531
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
5532
#if defined(__clang__)
5533
#pragma clang diagnostic push
5534
#pragma clang diagnostic ignored "-Wmissing-braces"
5535
#endif
5536
static const JSFunctionSpec sMethods_specs[] = {
5537
  JS_FNSPEC("setIdentityProvider", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&setIdentityProvider_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
5538
  JS_FNSPEC("getIdentityAssertion", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&getIdentityAssertion_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
5539
  JS_FS_END,
5540
  JS_FNSPEC("createOffer", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&createOffer_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
5541
  JS_FNSPEC("createAnswer", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&createAnswer_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
5542
  JS_FNSPEC("setLocalDescription", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&setLocalDescription_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
5543
  JS_FNSPEC("setRemoteDescription", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&setRemoteDescription_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
5544
  JS_FNSPEC("addIceCandidate", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&addIceCandidate_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
5545
  JS_FNSPEC("getConfiguration", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getConfiguration_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
5546
  JS_FNSPEC("getLocalStreams", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getLocalStreams_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
5547
  JS_FNSPEC("getRemoteStreams", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getRemoteStreams_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
5548
  JS_FNSPEC("addStream", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&addStream_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
5549
  JS_FNSPEC("addTrack", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&addTrack_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
5550
  JS_FNSPEC("removeTrack", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&removeTrack_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
5551
  JS_FNSPEC("addTransceiver", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&addTransceiver_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
5552
  JS_FNSPEC("getSenders", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getSenders_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
5553
  JS_FNSPEC("getReceivers", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getReceivers_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
5554
  JS_FNSPEC("getTransceivers", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getTransceivers_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
5555
  JS_FNSPEC("close", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&close_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
5556
  JS_FNSPEC("getStats", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&getStats_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
5557
  JS_FNSPEC("createDataChannel", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&createDataChannel_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
5558
  JS_FS_END
5559
};
5560
#if defined(__clang__)
5561
#pragma clang diagnostic pop
5562
#endif
5563
5564
// Can't be const because the pref-enabled boolean needs to be writable
5565
static PrefableDisablers sMethods_disablers0 = {
5566
  true, false, 0, nullptr
5567
};
5568
5569
static const Prefable<const JSFunctionSpec> sMethods[] = {
5570
  { &sMethods_disablers0, &sMethods_specs[0] },
5571
  { nullptr, &sMethods_specs[3] },
5572
  { nullptr, nullptr }
5573
};
5574
5575
static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
5576
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
5577
static_assert(18 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
5578
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
5579
5580
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
5581
#if defined(__clang__)
5582
#pragma clang diagnostic push
5583
#pragma clang diagnostic ignored "-Wmissing-braces"
5584
#endif
5585
static const JSFunctionSpec sChromeMethods_specs[] = {
5586
  JS_FNSPEC("mozGetNowInRtpSourceReferenceTime", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&mozGetNowInRtpSourceReferenceTime_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
5587
  JS_FNSPEC("mozInsertAudioLevelForContributingSource", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&mozInsertAudioLevelForContributingSource_methodinfo), 5, JSPROP_ENUMERATE, nullptr),
5588
  JS_FNSPEC("mozAddRIDExtension", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&mozAddRIDExtension_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
5589
  JS_FNSPEC("mozAddRIDFilter", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&mozAddRIDFilter_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
5590
  JS_FNSPEC("mozSetPacketCallback", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&mozSetPacketCallback_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
5591
  JS_FNSPEC("mozEnablePacketDump", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&mozEnablePacketDump_methodinfo), 3, JSPROP_ENUMERATE, nullptr),
5592
  JS_FNSPEC("mozDisablePacketDump", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&mozDisablePacketDump_methodinfo), 3, JSPROP_ENUMERATE, nullptr),
5593
  JS_FS_END
5594
};
5595
#if defined(__clang__)
5596
#pragma clang diagnostic pop
5597
#endif
5598
5599
5600
static const Prefable<const JSFunctionSpec> sChromeMethods[] = {
5601
  { nullptr, &sChromeMethods_specs[0] },
5602
  { nullptr, nullptr }
5603
};
5604
5605
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
5606
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
5607
static_assert(7 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
5608
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
5609
5610
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
5611
#if defined(__clang__)
5612
#pragma clang diagnostic push
5613
#pragma clang diagnostic ignored "-Wmissing-braces"
5614
#endif
5615
static const JSPropertySpec sAttributes_specs[] = {
5616
  { "localDescription", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &localDescription_getterinfo, nullptr, nullptr },
5617
  { "currentLocalDescription", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &currentLocalDescription_getterinfo, nullptr, nullptr },
5618
  { "pendingLocalDescription", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &pendingLocalDescription_getterinfo, nullptr, nullptr },
5619
  { "remoteDescription", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &remoteDescription_getterinfo, nullptr, nullptr },
5620
  { "currentRemoteDescription", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &currentRemoteDescription_getterinfo, nullptr, nullptr },
5621
  { "pendingRemoteDescription", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &pendingRemoteDescription_getterinfo, nullptr, nullptr },
5622
  { "signalingState", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &signalingState_getterinfo, nullptr, nullptr },
5623
  { "canTrickleIceCandidates", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &canTrickleIceCandidates_getterinfo, nullptr, nullptr },
5624
  { "iceGatheringState", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &iceGatheringState_getterinfo, nullptr, nullptr },
5625
  { "iceConnectionState", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &iceConnectionState_getterinfo, nullptr, nullptr },
5626
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr },
5627
  { "peerIdentity", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ConvertExceptionsToPromises>, &peerIdentity_getterinfo, nullptr, nullptr },
5628
  { "idpLoginUrl", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &idpLoginUrl_getterinfo, nullptr, nullptr },
5629
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr },
5630
  { "onnegotiationneeded", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onnegotiationneeded_getterinfo, GenericSetter<NormalThisPolicy>, &onnegotiationneeded_setterinfo },
5631
  { "onicecandidate", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onicecandidate_getterinfo, GenericSetter<NormalThisPolicy>, &onicecandidate_setterinfo },
5632
  { "onsignalingstatechange", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onsignalingstatechange_getterinfo, GenericSetter<NormalThisPolicy>, &onsignalingstatechange_setterinfo },
5633
  { "onaddstream", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onaddstream_getterinfo, GenericSetter<NormalThisPolicy>, &onaddstream_setterinfo },
5634
  { "onaddtrack", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onaddtrack_getterinfo, GenericSetter<NormalThisPolicy>, &onaddtrack_setterinfo },
5635
  { "ontrack", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &ontrack_getterinfo, GenericSetter<NormalThisPolicy>, &ontrack_setterinfo },
5636
  { "onremovestream", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onremovestream_getterinfo, GenericSetter<NormalThisPolicy>, &onremovestream_setterinfo },
5637
  { "oniceconnectionstatechange", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &oniceconnectionstatechange_getterinfo, GenericSetter<NormalThisPolicy>, &oniceconnectionstatechange_setterinfo },
5638
  { "onicegatheringstatechange", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onicegatheringstatechange_getterinfo, GenericSetter<NormalThisPolicy>, &onicegatheringstatechange_setterinfo },
5639
  { "ondatachannel", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &ondatachannel_getterinfo, GenericSetter<NormalThisPolicy>, &ondatachannel_setterinfo },
5640
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
5641
};
5642
#if defined(__clang__)
5643
#pragma clang diagnostic pop
5644
#endif
5645
5646
// Can't be const because the pref-enabled boolean needs to be writable
5647
static PrefableDisablers sAttributes_disablers11 = {
5648
  true, false, 0, nullptr
5649
};
5650
5651
static const Prefable<const JSPropertySpec> sAttributes[] = {
5652
  { nullptr, &sAttributes_specs[0] },
5653
  { &sAttributes_disablers11, &sAttributes_specs[11] },
5654
  { nullptr, &sAttributes_specs[14] },
5655
  { nullptr, nullptr }
5656
};
5657
5658
static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
5659
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
5660
static_assert(10 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
5661
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
5662
5663
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
5664
#if defined(__clang__)
5665
#pragma clang diagnostic push
5666
#pragma clang diagnostic ignored "-Wmissing-braces"
5667
#endif
5668
static const JSPropertySpec sChromeAttributes_specs[] = {
5669
  { "id", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &id_getterinfo, GenericSetter<NormalThisPolicy>, &id_setterinfo },
5670
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
5671
};
5672
#if defined(__clang__)
5673
#pragma clang diagnostic pop
5674
#endif
5675
5676
5677
static const Prefable<const JSPropertySpec> sChromeAttributes[] = {
5678
  { nullptr, &sChromeAttributes_specs[0] },
5679
  { nullptr, nullptr }
5680
};
5681
5682
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
5683
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
5684
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
5685
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
5686
5687
5688
static uint16_t sNativeProperties_sortedPropertyIndices[43];
5689
static PropertyInfo sNativeProperties_propertyInfos[43];
5690
5691
static const NativePropertiesN<3> sNativeProperties = {
5692
  true,  0 /* sStaticMethods */,
5693
  false, 0,
5694
  true,  1 /* sMethods */,
5695
  true,  2 /* sAttributes */,
5696
  false, 0,
5697
  false, 0,
5698
  false, 0,
5699
  -1,
5700
  43,
5701
  sNativeProperties_sortedPropertyIndices,
5702
  {
5703
    { sStaticMethods, &sNativeProperties_propertyInfos[0] },
5704
    { sMethods, &sNativeProperties_propertyInfos[1] },
5705
    { sAttributes, &sNativeProperties_propertyInfos[21] }
5706
  }
5707
};
5708
static_assert(43 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
5709
    "We have a property info count that is oversized");
5710
5711
static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[9];
5712
static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[9];
5713
5714
static const NativePropertiesN<3> sChromeOnlyNativeProperties = {
5715
  true,  0 /* sChromeStaticMethods */,
5716
  false, 0,
5717
  true,  1 /* sChromeMethods */,
5718
  true,  2 /* sChromeAttributes */,
5719
  false, 0,
5720
  false, 0,
5721
  false, 0,
5722
  -1,
5723
  9,
5724
  sChromeOnlyNativeProperties_sortedPropertyIndices,
5725
  {
5726
    { sChromeStaticMethods, &sChromeOnlyNativeProperties_propertyInfos[0] },
5727
    { sChromeMethods, &sChromeOnlyNativeProperties_propertyInfos[1] },
5728
    { sChromeAttributes, &sChromeOnlyNativeProperties_propertyInfos[8] }
5729
  }
5730
};
5731
static_assert(9 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount),
5732
    "We have a property info count that is oversized");
5733
5734
static bool
5735
_constructor(JSContext* cx, unsigned argc, JS::Value* vp)
5736
0
{
5737
0
  AUTO_PROFILER_LABEL_FAST("RTCPeerConnection constructor", DOM, cx);
5738
0
5739
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
5740
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
5741
0
  if (!args.isConstructing()) {
5742
0
    // XXXbz wish I could get the name from the callee instead of
5743
0
    // Adding more relocations
5744
0
    return ThrowConstructorWithoutNew(cx, "RTCPeerConnection");
5745
0
  }
5746
0
5747
0
  JS::Rooted<JSObject*> desiredProto(cx);
5748
0
  if (!GetDesiredProto(cx, args, &desiredProto)) {
5749
0
    return false;
5750
0
  }
5751
0
5752
0
  GlobalObject global(cx, obj);
5753
0
  if (global.Failed()) {
5754
0
    return false;
5755
0
  }
5756
0
5757
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
5758
0
  binding_detail::FastRTCConfiguration arg0;
5759
0
  if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue,  "Argument 1 of RTCPeerConnection.constructor", true)) {
5760
0
    return false;
5761
0
  }
5762
0
  Optional<JS::Handle<JSObject*>> arg1;
5763
0
  if (args.hasDefined(1)) {
5764
0
    arg1.Construct(cx);
5765
0
    if (args[1].isObject()) {
5766
0
#ifdef __clang__
5767
0
#pragma clang diagnostic push
5768
0
#pragma clang diagnostic ignored "-Wunreachable-code"
5769
0
#pragma clang diagnostic ignored "-Wunreachable-code-return"
5770
0
#endif // __clang__
5771
0
      if ((true) && !CallerSubsumes(args[1])) {
5772
0
        ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "argument 2 of RTCPeerConnection.constructor");
5773
0
        return false;
5774
0
      }
5775
0
#ifdef __clang__
5776
0
#pragma clang diagnostic pop
5777
0
#endif // __clang__
5778
0
      arg1.Value() = &args[1].toObject();
5779
0
    } else if (args[1].isNullOrUndefined()) {
5780
0
      arg1.Value() = nullptr;
5781
0
    } else {
5782
0
      ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of RTCPeerConnection.constructor");
5783
0
      return false;
5784
0
    }
5785
0
  }
5786
0
  Maybe<JSAutoRealm> ar;
5787
0
  if (objIsXray) {
5788
0
    obj = js::CheckedUnwrap(obj);
5789
0
    if (!obj) {
5790
0
      return false;
5791
0
    }
5792
0
    ar.emplace(cx, obj);
5793
0
    if (!JS_WrapObject(cx, &desiredProto)) {
5794
0
      return false;
5795
0
    }
5796
0
    if (arg1.WasPassed()) {
5797
0
      if (!JS_WrapObject(cx, &arg1.Value())) {
5798
0
        return false;
5799
0
      }
5800
0
    }
5801
0
  }
5802
0
  FastErrorResult rv;
5803
0
  auto result(StrongOrRawPtr<mozilla::dom::RTCPeerConnection>(mozilla::dom::RTCPeerConnection::Constructor(global, cx, Constify(arg0), Constify(arg1), rv, desiredProto)));
5804
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
5805
0
    return false;
5806
0
  }
5807
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
5808
0
  static_assert(!IsPointer<decltype(result)>::value,
5809
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
5810
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
5811
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
5812
0
    return false;
5813
0
  }
5814
0
  return true;
5815
0
}
5816
5817
static const js::ClassOps sInterfaceObjectClassOps = {
5818
    nullptr,               /* addProperty */
5819
    nullptr,               /* delProperty */
5820
    nullptr,               /* enumerate */
5821
    nullptr,               /* newEnumerate */
5822
    nullptr,               /* resolve */
5823
    nullptr,               /* mayResolve */
5824
    nullptr,               /* finalize */
5825
    _constructor, /* call */
5826
    nullptr,               /* hasInstance */
5827
    _constructor, /* construct */
5828
    nullptr,               /* trace */
5829
};
5830
5831
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
5832
  {
5833
    "Function",
5834
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
5835
    &sInterfaceObjectClassOps,
5836
    JS_NULL_CLASS_SPEC,
5837
    JS_NULL_CLASS_EXT,
5838
    &sInterfaceObjectClassObjectOps
5839
  },
5840
  eInterface,
5841
  true,
5842
  prototypes::id::RTCPeerConnection,
5843
  PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth,
5844
  sNativePropertyHooks,
5845
  "function RTCPeerConnection() {\n    [native code]\n}",
5846
  EventTarget_Binding::GetConstructorObject
5847
};
5848
5849
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
5850
  {
5851
    "RTCPeerConnectionPrototype",
5852
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
5853
    JS_NULL_CLASS_OPS,
5854
    JS_NULL_CLASS_SPEC,
5855
    JS_NULL_CLASS_EXT,
5856
    JS_NULL_OBJECT_OPS
5857
  },
5858
  eInterfacePrototype,
5859
  false,
5860
  prototypes::id::RTCPeerConnection,
5861
  PrototypeTraits<prototypes::id::RTCPeerConnection>::Depth,
5862
  sNativePropertyHooks,
5863
  "[object RTCPeerConnectionPrototype]",
5864
  EventTarget_Binding::GetProtoObject
5865
};
5866
5867
bool
5868
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
5869
0
{
5870
0
  static bool sPrefValue;
5871
0
  static bool sPrefCacheSetUp = false;
5872
0
  if (!sPrefCacheSetUp) {
5873
0
    sPrefCacheSetUp = true;
5874
0
    Preferences::AddBoolVarCache(&sPrefValue, "media.peerconnection.enabled");
5875
0
  }
5876
0
5877
0
  return sPrefValue;
5878
0
}
5879
5880
static const js::ClassOps sClassOps = {
5881
  _addProperty, /* addProperty */
5882
  nullptr,               /* delProperty */
5883
  nullptr,               /* enumerate */
5884
  nullptr, /* newEnumerate */
5885
  nullptr, /* resolve */
5886
  nullptr, /* mayResolve */
5887
  _finalize, /* finalize */
5888
  nullptr, /* call */
5889
  nullptr,               /* hasInstance */
5890
  nullptr,               /* construct */
5891
  nullptr, /* trace */
5892
};
5893
5894
static const js::ClassExtension sClassExtension = {
5895
  nullptr, /* weakmapKeyDelegateOp */
5896
  _objectMoved /* objectMovedOp */
5897
};
5898
5899
static const DOMJSClass sClass = {
5900
  { "RTCPeerConnection",
5901
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
5902
    &sClassOps,
5903
    JS_NULL_CLASS_SPEC,
5904
    &sClassExtension,
5905
    JS_NULL_OBJECT_OPS
5906
  },
5907
  { prototypes::id::EventTarget, prototypes::id::RTCPeerConnection, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
5908
  IsBaseOf<nsISupports, mozilla::dom::RTCPeerConnection >::value,
5909
  sNativePropertyHooks,
5910
  FindAssociatedGlobalForNative<mozilla::dom::RTCPeerConnection>::Get,
5911
  GetProtoObjectHandle,
5912
  GetCCParticipant<mozilla::dom::RTCPeerConnection>::Get()
5913
};
5914
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
5915
              "Must have the right minimal number of reserved slots.");
5916
static_assert(1 >= 1,
5917
              "Must have enough reserved slots.");
5918
5919
const JSClass*
5920
GetJSClass()
5921
0
{
5922
0
  return sClass.ToJSClass();
5923
0
}
5924
5925
bool
5926
Wrap(JSContext* aCx, mozilla::dom::RTCPeerConnection* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
5927
0
{
5928
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::RTCPeerConnection>::value,
5929
0
                "Shouldn't have wrappercached things that are not refcounted.");
5930
0
  MOZ_ASSERT(static_cast<mozilla::dom::RTCPeerConnection*>(aObject) ==
5931
0
             reinterpret_cast<mozilla::dom::RTCPeerConnection*>(aObject),
5932
0
             "Multiple inheritance for mozilla::dom::RTCPeerConnection is broken.");
5933
0
  MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
5934
0
             reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
5935
0
             "Multiple inheritance for mozilla::dom::EventTarget is broken.");
5936
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
5937
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
5938
0
  MOZ_ASSERT(!aCache->GetWrapper(),
5939
0
             "You should probably not be using Wrap() directly; use "
5940
0
             "GetOrCreateDOMReflector instead");
5941
0
5942
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
5943
0
             "nsISupports must be on our primary inheritance chain");
5944
0
5945
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
5946
0
  if (!global) {
5947
0
    return false;
5948
0
  }
5949
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
5950
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
5951
0
5952
0
  // That might have ended up wrapping us already, due to the wonders
5953
0
  // of XBL.  Check for that, and bail out as needed.
5954
0
  aReflector.set(aCache->GetWrapper());
5955
0
  if (aReflector) {
5956
#ifdef DEBUG
5957
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
5958
#endif // DEBUG
5959
    return true;
5960
0
  }
5961
0
5962
0
  JSAutoRealm ar(aCx, global);
5963
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
5964
0
  if (!canonicalProto) {
5965
0
    return false;
5966
0
  }
5967
0
  JS::Rooted<JSObject*> proto(aCx);
5968
0
  if (aGivenProto) {
5969
0
    proto = aGivenProto;
5970
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
5971
0
    // coming in, we changed compartments to that of "parent" so may need
5972
0
    // to wrap the proto here.
5973
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
5974
0
      if (!JS_WrapObject(aCx, &proto)) {
5975
0
        return false;
5976
0
      }
5977
0
    }
5978
0
  } else {
5979
0
    proto = canonicalProto;
5980
0
  }
5981
0
5982
0
  BindingJSObjectCreator<mozilla::dom::RTCPeerConnection> creator(aCx);
5983
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
5984
0
  if (!aReflector) {
5985
0
    return false;
5986
0
  }
5987
0
5988
0
  aCache->SetWrapper(aReflector);
5989
0
  creator.InitializationSucceeded();
5990
0
5991
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
5992
0
             aCache->GetWrapperPreserveColor() == aReflector);
5993
0
  // If proto != canonicalProto, we have to preserve our wrapper;
5994
0
  // otherwise we won't be able to properly recreate it later, since
5995
0
  // we won't know what proto to use.  Note that we don't check
5996
0
  // aGivenProto here, since it's entirely possible (and even
5997
0
  // somewhat common) to have a non-null aGivenProto which is the
5998
0
  // same as canonicalProto.
5999
0
  if (proto != canonicalProto) {
6000
0
    PreserveWrapper(aObject);
6001
0
  }
6002
0
6003
0
  return true;
6004
0
}
6005
6006
const NativePropertyHooks sNativePropertyHooks[] = { {
6007
  nullptr,
6008
  nullptr,
6009
  nullptr,
6010
  { sNativeProperties.Upcast(), sChromeOnlyNativeProperties.Upcast() },
6011
  prototypes::id::RTCPeerConnection,
6012
  constructors::id::RTCPeerConnection,
6013
  EventTarget_Binding::sNativePropertyHooks,
6014
  &DefaultXrayExpandoObjectClass
6015
} };
6016
6017
void
6018
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
6019
0
{
6020
0
  JS::Handle<JSObject*> parentProto(EventTarget_Binding::GetProtoObjectHandle(aCx));
6021
0
  if (!parentProto) {
6022
0
    return;
6023
0
  }
6024
0
6025
0
  JS::Handle<JSObject*> constructorProto(EventTarget_Binding::GetConstructorObjectHandle(aCx));
6026
0
  if (!constructorProto) {
6027
0
    return;
6028
0
  }
6029
0
6030
0
  static bool sIdsInited = false;
6031
0
  if (!sIdsInited && NS_IsMainThread()) {
6032
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
6033
0
      return;
6034
0
    }
6035
0
    if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) {
6036
0
      return;
6037
0
    }
6038
0
    sIdsInited = true;
6039
0
  }
6040
0
6041
0
  static bool sPrefCachesInited = false;
6042
0
  if (!sPrefCachesInited && NS_IsMainThread()) {
6043
0
    sPrefCachesInited = true;
6044
0
    Preferences::AddBoolVarCache(&sMethods[0].disablers->enabled, "media.peerconnection.identity.enabled");
6045
0
    Preferences::AddBoolVarCache(&sAttributes[1].disablers->enabled, "media.peerconnection.identity.enabled");
6046
0
  }
6047
0
6048
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::RTCPeerConnection);
6049
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::RTCPeerConnection);
6050
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
6051
0
                              &sPrototypeClass.mBase, protoCache,
6052
0
                              nullptr,
6053
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
6054
0
                              interfaceCache,
6055
0
                              sNativeProperties.Upcast(),
6056
0
                              sChromeOnlyNativeProperties.Upcast(),
6057
0
                              "RTCPeerConnection", aDefineOnGlobal,
6058
0
                              nullptr,
6059
0
                              false);
6060
0
}
6061
6062
JSObject*
6063
GetProtoObject(JSContext* aCx)
6064
0
{
6065
0
  return GetProtoObjectHandle(aCx);
6066
0
}
6067
6068
JSObject*
6069
GetConstructorObject(JSContext* aCx)
6070
0
{
6071
0
  return GetConstructorObjectHandle(aCx);
6072
0
}
6073
6074
} // namespace RTCPeerConnection_Binding
6075
6076
6077
6078
void
6079
RTCPeerConnectionJSImpl::SetIdentityProvider(const nsAString& provider, const RTCIdentityProviderOptions& options, ErrorResult& aRv, JS::Realm* aRealm)
6080
0
{
6081
0
  CallSetup s(this, aRv, "RTCPeerConnection.setIdentityProvider", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
6082
0
  JSContext* cx = s.GetContext();
6083
0
  if (!cx) {
6084
0
    MOZ_ASSERT(aRv.Failed());
6085
0
    return;
6086
0
  }
6087
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
6088
0
  JS::AutoValueVector argv(cx);
6089
0
  if (!argv.resize(2)) {
6090
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
6091
0
    return;
6092
0
  }
6093
0
  unsigned argc = 2;
6094
0
6095
0
  do {
6096
0
    if (!options.ToObjectInternal(cx, argv[1])) {
6097
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6098
0
      return;
6099
0
    }
6100
0
    break;
6101
0
  } while (false);
6102
0
6103
0
  do {
6104
0
    nsString mutableStr(provider);
6105
0
    if (!xpc::NonVoidStringToJsval(cx, mutableStr, argv[0])) {
6106
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6107
0
      return;
6108
0
    }
6109
0
    break;
6110
0
  } while (false);
6111
0
6112
0
  JS::Rooted<JS::Value> callable(cx);
6113
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
6114
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
6115
0
      !GetCallableProperty(cx, atomsCache->setIdentityProvider_id, &callable)) {
6116
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
6117
0
    return;
6118
0
  }
6119
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
6120
0
  if (!JS::Call(cx, thisValue, callable,
6121
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
6122
0
    aRv.NoteJSContextException(cx);
6123
0
    return;
6124
0
  }
6125
0
}
6126
6127
already_AddRefed<Promise>
6128
RTCPeerConnectionJSImpl::GetIdentityAssertion(ErrorResult& aRv, JS::Realm* aRealm)
6129
0
{
6130
0
  CallSetup s(this, aRv, "RTCPeerConnection.getIdentityAssertion", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
6131
0
  JSContext* cx = s.GetContext();
6132
0
  if (!cx) {
6133
0
    MOZ_ASSERT(aRv.Failed());
6134
0
    return nullptr;
6135
0
  }
6136
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
6137
0
6138
0
  JS::Rooted<JS::Value> callable(cx);
6139
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
6140
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
6141
0
      !GetCallableProperty(cx, atomsCache->getIdentityAssertion_id, &callable)) {
6142
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
6143
0
    return nullptr;
6144
0
  }
6145
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
6146
0
  if (!JS::Call(cx, thisValue, callable,
6147
0
                JS::HandleValueArray::empty(), &rval)) {
6148
0
    aRv.NoteJSContextException(cx);
6149
0
    return nullptr;
6150
0
  }
6151
0
  RefPtr<Promise> rvalDecl;
6152
0
  { // Scope for our GlobalObject, FastErrorResult, JSAutoRealm,
6153
0
    // etc.
6154
0
6155
0
    JS::Rooted<JSObject*> globalObj(cx);
6156
0
    if (!rval.isObject()) {
6157
0
      aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.getIdentityAssertion"));
6158
0
      return nullptr;
6159
0
    }
6160
0
    JSObject* unwrappedVal = js::CheckedUnwrap(&rval.toObject());
6161
0
    if (!unwrappedVal) {
6162
0
      // A slight lie, but not much of one, for a dead object wrapper.
6163
0
      aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.getIdentityAssertion"));
6164
0
      return nullptr;
6165
0
    }
6166
0
    globalObj = JS::GetNonCCWObjectGlobal(unwrappedVal);
6167
0
    JSAutoRealm ar(cx, globalObj);
6168
0
    GlobalObject promiseGlobal(cx, globalObj);
6169
0
    if (promiseGlobal.Failed()) {
6170
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6171
0
      return nullptr;
6172
0
    }
6173
0
6174
0
    JS::Rooted<JS::Value> valueToResolve(cx, rval);
6175
0
    if (!JS_WrapValue(cx, &valueToResolve)) {
6176
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6177
0
      return nullptr;
6178
0
    }
6179
0
    binding_detail::FastErrorResult promiseRv;
6180
0
    nsCOMPtr<nsIGlobalObject> global =
6181
0
      do_QueryInterface(promiseGlobal.GetAsSupports());
6182
0
    if (!global) {
6183
0
      promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED);
6184
0
      MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
6185
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6186
0
      return nullptr;
6187
0
    }
6188
0
    rvalDecl = Promise::Resolve(global, cx, valueToResolve,
6189
0
                                    promiseRv);
6190
0
    if (promiseRv.MaybeSetPendingException(cx)) {
6191
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6192
0
      return nullptr;
6193
0
    }
6194
0
  }
6195
0
  return rvalDecl.forget();
6196
0
}
6197
6198
already_AddRefed<Promise>
6199
RTCPeerConnectionJSImpl::CreateOffer(const RTCOfferOptions& options, ErrorResult& aRv, JS::Realm* aRealm)
6200
0
{
6201
0
  CallSetup s(this, aRv, "RTCPeerConnection.createOffer", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
6202
0
  JSContext* cx = s.GetContext();
6203
0
  if (!cx) {
6204
0
    MOZ_ASSERT(aRv.Failed());
6205
0
    return nullptr;
6206
0
  }
6207
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
6208
0
  JS::AutoValueVector argv(cx);
6209
0
  if (!argv.resize(1)) {
6210
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
6211
0
    return nullptr;
6212
0
  }
6213
0
  unsigned argc = 1;
6214
0
6215
0
  do {
6216
0
    if (!options.ToObjectInternal(cx, argv[0])) {
6217
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6218
0
      return nullptr;
6219
0
    }
6220
0
    break;
6221
0
  } while (false);
6222
0
6223
0
  JS::Rooted<JS::Value> callable(cx);
6224
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
6225
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
6226
0
      !GetCallableProperty(cx, atomsCache->createOffer_id, &callable)) {
6227
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
6228
0
    return nullptr;
6229
0
  }
6230
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
6231
0
  if (!JS::Call(cx, thisValue, callable,
6232
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
6233
0
    aRv.NoteJSContextException(cx);
6234
0
    return nullptr;
6235
0
  }
6236
0
  RefPtr<Promise> rvalDecl;
6237
0
  { // Scope for our GlobalObject, FastErrorResult, JSAutoRealm,
6238
0
    // etc.
6239
0
6240
0
    JS::Rooted<JSObject*> globalObj(cx);
6241
0
    if (!rval.isObject()) {
6242
0
      aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.createOffer"));
6243
0
      return nullptr;
6244
0
    }
6245
0
    JSObject* unwrappedVal = js::CheckedUnwrap(&rval.toObject());
6246
0
    if (!unwrappedVal) {
6247
0
      // A slight lie, but not much of one, for a dead object wrapper.
6248
0
      aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.createOffer"));
6249
0
      return nullptr;
6250
0
    }
6251
0
    globalObj = JS::GetNonCCWObjectGlobal(unwrappedVal);
6252
0
    JSAutoRealm ar(cx, globalObj);
6253
0
    GlobalObject promiseGlobal(cx, globalObj);
6254
0
    if (promiseGlobal.Failed()) {
6255
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6256
0
      return nullptr;
6257
0
    }
6258
0
6259
0
    JS::Rooted<JS::Value> valueToResolve(cx, rval);
6260
0
    if (!JS_WrapValue(cx, &valueToResolve)) {
6261
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6262
0
      return nullptr;
6263
0
    }
6264
0
    binding_detail::FastErrorResult promiseRv;
6265
0
    nsCOMPtr<nsIGlobalObject> global =
6266
0
      do_QueryInterface(promiseGlobal.GetAsSupports());
6267
0
    if (!global) {
6268
0
      promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED);
6269
0
      MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
6270
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6271
0
      return nullptr;
6272
0
    }
6273
0
    rvalDecl = Promise::Resolve(global, cx, valueToResolve,
6274
0
                                    promiseRv);
6275
0
    if (promiseRv.MaybeSetPendingException(cx)) {
6276
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6277
0
      return nullptr;
6278
0
    }
6279
0
  }
6280
0
  return rvalDecl.forget();
6281
0
}
6282
6283
already_AddRefed<Promise>
6284
RTCPeerConnectionJSImpl::CreateOffer(RTCSessionDescriptionCallback& successCallback, RTCPeerConnectionErrorCallback& failureCallback, const RTCOfferOptions& options, ErrorResult& aRv, JS::Realm* aRealm)
6285
0
{
6286
0
  CallSetup s(this, aRv, "RTCPeerConnection.createOffer", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
6287
0
  JSContext* cx = s.GetContext();
6288
0
  if (!cx) {
6289
0
    MOZ_ASSERT(aRv.Failed());
6290
0
    return nullptr;
6291
0
  }
6292
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
6293
0
  JS::AutoValueVector argv(cx);
6294
0
  if (!argv.resize(3)) {
6295
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
6296
0
    return nullptr;
6297
0
  }
6298
0
  unsigned argc = 3;
6299
0
6300
0
  do {
6301
0
    if (!options.ToObjectInternal(cx, argv[2])) {
6302
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6303
0
      return nullptr;
6304
0
    }
6305
0
    break;
6306
0
  } while (false);
6307
0
6308
0
  do {
6309
0
    argv[1].setObjectOrNull(GetCallbackFromCallbackObject(cx, failureCallback));
6310
0
    if (!MaybeWrapObjectValue(cx, argv[1])) {
6311
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6312
0
      return nullptr;
6313
0
    }
6314
0
    break;
6315
0
  } while (false);
6316
0
6317
0
  do {
6318
0
    argv[0].setObjectOrNull(GetCallbackFromCallbackObject(cx, successCallback));
6319
0
    if (!MaybeWrapObjectValue(cx, argv[0])) {
6320
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6321
0
      return nullptr;
6322
0
    }
6323
0
    break;
6324
0
  } while (false);
6325
0
6326
0
  JS::Rooted<JS::Value> callable(cx);
6327
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
6328
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
6329
0
      !GetCallableProperty(cx, atomsCache->createOffer_id, &callable)) {
6330
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
6331
0
    return nullptr;
6332
0
  }
6333
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
6334
0
  if (!JS::Call(cx, thisValue, callable,
6335
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
6336
0
    aRv.NoteJSContextException(cx);
6337
0
    return nullptr;
6338
0
  }
6339
0
  RefPtr<Promise> rvalDecl;
6340
0
  { // Scope for our GlobalObject, FastErrorResult, JSAutoRealm,
6341
0
    // etc.
6342
0
6343
0
    JS::Rooted<JSObject*> globalObj(cx);
6344
0
    if (!rval.isObject()) {
6345
0
      aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.createOffer"));
6346
0
      return nullptr;
6347
0
    }
6348
0
    JSObject* unwrappedVal = js::CheckedUnwrap(&rval.toObject());
6349
0
    if (!unwrappedVal) {
6350
0
      // A slight lie, but not much of one, for a dead object wrapper.
6351
0
      aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.createOffer"));
6352
0
      return nullptr;
6353
0
    }
6354
0
    globalObj = JS::GetNonCCWObjectGlobal(unwrappedVal);
6355
0
    JSAutoRealm ar(cx, globalObj);
6356
0
    GlobalObject promiseGlobal(cx, globalObj);
6357
0
    if (promiseGlobal.Failed()) {
6358
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6359
0
      return nullptr;
6360
0
    }
6361
0
6362
0
    JS::Rooted<JS::Value> valueToResolve(cx, rval);
6363
0
    if (!JS_WrapValue(cx, &valueToResolve)) {
6364
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6365
0
      return nullptr;
6366
0
    }
6367
0
    binding_detail::FastErrorResult promiseRv;
6368
0
    nsCOMPtr<nsIGlobalObject> global =
6369
0
      do_QueryInterface(promiseGlobal.GetAsSupports());
6370
0
    if (!global) {
6371
0
      promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED);
6372
0
      MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
6373
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6374
0
      return nullptr;
6375
0
    }
6376
0
    rvalDecl = Promise::Resolve(global, cx, valueToResolve,
6377
0
                                    promiseRv);
6378
0
    if (promiseRv.MaybeSetPendingException(cx)) {
6379
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6380
0
      return nullptr;
6381
0
    }
6382
0
  }
6383
0
  return rvalDecl.forget();
6384
0
}
6385
6386
already_AddRefed<Promise>
6387
RTCPeerConnectionJSImpl::CreateAnswer(const RTCAnswerOptions& options, ErrorResult& aRv, JS::Realm* aRealm)
6388
0
{
6389
0
  CallSetup s(this, aRv, "RTCPeerConnection.createAnswer", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
6390
0
  JSContext* cx = s.GetContext();
6391
0
  if (!cx) {
6392
0
    MOZ_ASSERT(aRv.Failed());
6393
0
    return nullptr;
6394
0
  }
6395
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
6396
0
  JS::AutoValueVector argv(cx);
6397
0
  if (!argv.resize(1)) {
6398
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
6399
0
    return nullptr;
6400
0
  }
6401
0
  unsigned argc = 1;
6402
0
6403
0
  do {
6404
0
    if (!options.ToObjectInternal(cx, argv[0])) {
6405
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6406
0
      return nullptr;
6407
0
    }
6408
0
    break;
6409
0
  } while (false);
6410
0
6411
0
  JS::Rooted<JS::Value> callable(cx);
6412
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
6413
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
6414
0
      !GetCallableProperty(cx, atomsCache->createAnswer_id, &callable)) {
6415
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
6416
0
    return nullptr;
6417
0
  }
6418
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
6419
0
  if (!JS::Call(cx, thisValue, callable,
6420
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
6421
0
    aRv.NoteJSContextException(cx);
6422
0
    return nullptr;
6423
0
  }
6424
0
  RefPtr<Promise> rvalDecl;
6425
0
  { // Scope for our GlobalObject, FastErrorResult, JSAutoRealm,
6426
0
    // etc.
6427
0
6428
0
    JS::Rooted<JSObject*> globalObj(cx);
6429
0
    if (!rval.isObject()) {
6430
0
      aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.createAnswer"));
6431
0
      return nullptr;
6432
0
    }
6433
0
    JSObject* unwrappedVal = js::CheckedUnwrap(&rval.toObject());
6434
0
    if (!unwrappedVal) {
6435
0
      // A slight lie, but not much of one, for a dead object wrapper.
6436
0
      aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.createAnswer"));
6437
0
      return nullptr;
6438
0
    }
6439
0
    globalObj = JS::GetNonCCWObjectGlobal(unwrappedVal);
6440
0
    JSAutoRealm ar(cx, globalObj);
6441
0
    GlobalObject promiseGlobal(cx, globalObj);
6442
0
    if (promiseGlobal.Failed()) {
6443
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6444
0
      return nullptr;
6445
0
    }
6446
0
6447
0
    JS::Rooted<JS::Value> valueToResolve(cx, rval);
6448
0
    if (!JS_WrapValue(cx, &valueToResolve)) {
6449
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6450
0
      return nullptr;
6451
0
    }
6452
0
    binding_detail::FastErrorResult promiseRv;
6453
0
    nsCOMPtr<nsIGlobalObject> global =
6454
0
      do_QueryInterface(promiseGlobal.GetAsSupports());
6455
0
    if (!global) {
6456
0
      promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED);
6457
0
      MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
6458
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6459
0
      return nullptr;
6460
0
    }
6461
0
    rvalDecl = Promise::Resolve(global, cx, valueToResolve,
6462
0
                                    promiseRv);
6463
0
    if (promiseRv.MaybeSetPendingException(cx)) {
6464
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6465
0
      return nullptr;
6466
0
    }
6467
0
  }
6468
0
  return rvalDecl.forget();
6469
0
}
6470
6471
already_AddRefed<Promise>
6472
RTCPeerConnectionJSImpl::CreateAnswer(RTCSessionDescriptionCallback& successCallback, RTCPeerConnectionErrorCallback& failureCallback, ErrorResult& aRv, JS::Realm* aRealm)
6473
0
{
6474
0
  CallSetup s(this, aRv, "RTCPeerConnection.createAnswer", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
6475
0
  JSContext* cx = s.GetContext();
6476
0
  if (!cx) {
6477
0
    MOZ_ASSERT(aRv.Failed());
6478
0
    return nullptr;
6479
0
  }
6480
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
6481
0
  JS::AutoValueVector argv(cx);
6482
0
  if (!argv.resize(2)) {
6483
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
6484
0
    return nullptr;
6485
0
  }
6486
0
  unsigned argc = 2;
6487
0
6488
0
  do {
6489
0
    argv[1].setObjectOrNull(GetCallbackFromCallbackObject(cx, failureCallback));
6490
0
    if (!MaybeWrapObjectValue(cx, argv[1])) {
6491
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6492
0
      return nullptr;
6493
0
    }
6494
0
    break;
6495
0
  } while (false);
6496
0
6497
0
  do {
6498
0
    argv[0].setObjectOrNull(GetCallbackFromCallbackObject(cx, successCallback));
6499
0
    if (!MaybeWrapObjectValue(cx, argv[0])) {
6500
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6501
0
      return nullptr;
6502
0
    }
6503
0
    break;
6504
0
  } while (false);
6505
0
6506
0
  JS::Rooted<JS::Value> callable(cx);
6507
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
6508
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
6509
0
      !GetCallableProperty(cx, atomsCache->createAnswer_id, &callable)) {
6510
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
6511
0
    return nullptr;
6512
0
  }
6513
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
6514
0
  if (!JS::Call(cx, thisValue, callable,
6515
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
6516
0
    aRv.NoteJSContextException(cx);
6517
0
    return nullptr;
6518
0
  }
6519
0
  RefPtr<Promise> rvalDecl;
6520
0
  { // Scope for our GlobalObject, FastErrorResult, JSAutoRealm,
6521
0
    // etc.
6522
0
6523
0
    JS::Rooted<JSObject*> globalObj(cx);
6524
0
    if (!rval.isObject()) {
6525
0
      aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.createAnswer"));
6526
0
      return nullptr;
6527
0
    }
6528
0
    JSObject* unwrappedVal = js::CheckedUnwrap(&rval.toObject());
6529
0
    if (!unwrappedVal) {
6530
0
      // A slight lie, but not much of one, for a dead object wrapper.
6531
0
      aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.createAnswer"));
6532
0
      return nullptr;
6533
0
    }
6534
0
    globalObj = JS::GetNonCCWObjectGlobal(unwrappedVal);
6535
0
    JSAutoRealm ar(cx, globalObj);
6536
0
    GlobalObject promiseGlobal(cx, globalObj);
6537
0
    if (promiseGlobal.Failed()) {
6538
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6539
0
      return nullptr;
6540
0
    }
6541
0
6542
0
    JS::Rooted<JS::Value> valueToResolve(cx, rval);
6543
0
    if (!JS_WrapValue(cx, &valueToResolve)) {
6544
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6545
0
      return nullptr;
6546
0
    }
6547
0
    binding_detail::FastErrorResult promiseRv;
6548
0
    nsCOMPtr<nsIGlobalObject> global =
6549
0
      do_QueryInterface(promiseGlobal.GetAsSupports());
6550
0
    if (!global) {
6551
0
      promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED);
6552
0
      MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
6553
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6554
0
      return nullptr;
6555
0
    }
6556
0
    rvalDecl = Promise::Resolve(global, cx, valueToResolve,
6557
0
                                    promiseRv);
6558
0
    if (promiseRv.MaybeSetPendingException(cx)) {
6559
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6560
0
      return nullptr;
6561
0
    }
6562
0
  }
6563
0
  return rvalDecl.forget();
6564
0
}
6565
6566
already_AddRefed<Promise>
6567
RTCPeerConnectionJSImpl::SetLocalDescription(const RTCSessionDescriptionInit& description, ErrorResult& aRv, JS::Realm* aRealm)
6568
0
{
6569
0
  CallSetup s(this, aRv, "RTCPeerConnection.setLocalDescription", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
6570
0
  JSContext* cx = s.GetContext();
6571
0
  if (!cx) {
6572
0
    MOZ_ASSERT(aRv.Failed());
6573
0
    return nullptr;
6574
0
  }
6575
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
6576
0
  JS::AutoValueVector argv(cx);
6577
0
  if (!argv.resize(1)) {
6578
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
6579
0
    return nullptr;
6580
0
  }
6581
0
  unsigned argc = 1;
6582
0
6583
0
  do {
6584
0
    if (!description.ToObjectInternal(cx, argv[0])) {
6585
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6586
0
      return nullptr;
6587
0
    }
6588
0
    break;
6589
0
  } while (false);
6590
0
6591
0
  JS::Rooted<JS::Value> callable(cx);
6592
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
6593
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
6594
0
      !GetCallableProperty(cx, atomsCache->setLocalDescription_id, &callable)) {
6595
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
6596
0
    return nullptr;
6597
0
  }
6598
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
6599
0
  if (!JS::Call(cx, thisValue, callable,
6600
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
6601
0
    aRv.NoteJSContextException(cx);
6602
0
    return nullptr;
6603
0
  }
6604
0
  RefPtr<Promise> rvalDecl;
6605
0
  { // Scope for our GlobalObject, FastErrorResult, JSAutoRealm,
6606
0
    // etc.
6607
0
6608
0
    JS::Rooted<JSObject*> globalObj(cx);
6609
0
    if (!rval.isObject()) {
6610
0
      aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.setLocalDescription"));
6611
0
      return nullptr;
6612
0
    }
6613
0
    JSObject* unwrappedVal = js::CheckedUnwrap(&rval.toObject());
6614
0
    if (!unwrappedVal) {
6615
0
      // A slight lie, but not much of one, for a dead object wrapper.
6616
0
      aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.setLocalDescription"));
6617
0
      return nullptr;
6618
0
    }
6619
0
    globalObj = JS::GetNonCCWObjectGlobal(unwrappedVal);
6620
0
    JSAutoRealm ar(cx, globalObj);
6621
0
    GlobalObject promiseGlobal(cx, globalObj);
6622
0
    if (promiseGlobal.Failed()) {
6623
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6624
0
      return nullptr;
6625
0
    }
6626
0
6627
0
    JS::Rooted<JS::Value> valueToResolve(cx, rval);
6628
0
    if (!JS_WrapValue(cx, &valueToResolve)) {
6629
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6630
0
      return nullptr;
6631
0
    }
6632
0
    binding_detail::FastErrorResult promiseRv;
6633
0
    nsCOMPtr<nsIGlobalObject> global =
6634
0
      do_QueryInterface(promiseGlobal.GetAsSupports());
6635
0
    if (!global) {
6636
0
      promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED);
6637
0
      MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
6638
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6639
0
      return nullptr;
6640
0
    }
6641
0
    rvalDecl = Promise::Resolve(global, cx, valueToResolve,
6642
0
                                    promiseRv);
6643
0
    if (promiseRv.MaybeSetPendingException(cx)) {
6644
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6645
0
      return nullptr;
6646
0
    }
6647
0
  }
6648
0
  return rvalDecl.forget();
6649
0
}
6650
6651
already_AddRefed<Promise>
6652
RTCPeerConnectionJSImpl::SetLocalDescription(const RTCSessionDescriptionInit& description, VoidFunction& successCallback, RTCPeerConnectionErrorCallback& failureCallback, ErrorResult& aRv, JS::Realm* aRealm)
6653
0
{
6654
0
  CallSetup s(this, aRv, "RTCPeerConnection.setLocalDescription", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
6655
0
  JSContext* cx = s.GetContext();
6656
0
  if (!cx) {
6657
0
    MOZ_ASSERT(aRv.Failed());
6658
0
    return nullptr;
6659
0
  }
6660
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
6661
0
  JS::AutoValueVector argv(cx);
6662
0
  if (!argv.resize(3)) {
6663
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
6664
0
    return nullptr;
6665
0
  }
6666
0
  unsigned argc = 3;
6667
0
6668
0
  do {
6669
0
    argv[2].setObjectOrNull(GetCallbackFromCallbackObject(cx, failureCallback));
6670
0
    if (!MaybeWrapObjectValue(cx, argv[2])) {
6671
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6672
0
      return nullptr;
6673
0
    }
6674
0
    break;
6675
0
  } while (false);
6676
0
6677
0
  do {
6678
0
    argv[1].setObjectOrNull(GetCallbackFromCallbackObject(cx, successCallback));
6679
0
    if (!MaybeWrapObjectValue(cx, argv[1])) {
6680
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6681
0
      return nullptr;
6682
0
    }
6683
0
    break;
6684
0
  } while (false);
6685
0
6686
0
  do {
6687
0
    if (!description.ToObjectInternal(cx, argv[0])) {
6688
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6689
0
      return nullptr;
6690
0
    }
6691
0
    break;
6692
0
  } while (false);
6693
0
6694
0
  JS::Rooted<JS::Value> callable(cx);
6695
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
6696
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
6697
0
      !GetCallableProperty(cx, atomsCache->setLocalDescription_id, &callable)) {
6698
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
6699
0
    return nullptr;
6700
0
  }
6701
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
6702
0
  if (!JS::Call(cx, thisValue, callable,
6703
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
6704
0
    aRv.NoteJSContextException(cx);
6705
0
    return nullptr;
6706
0
  }
6707
0
  RefPtr<Promise> rvalDecl;
6708
0
  { // Scope for our GlobalObject, FastErrorResult, JSAutoRealm,
6709
0
    // etc.
6710
0
6711
0
    JS::Rooted<JSObject*> globalObj(cx);
6712
0
    if (!rval.isObject()) {
6713
0
      aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.setLocalDescription"));
6714
0
      return nullptr;
6715
0
    }
6716
0
    JSObject* unwrappedVal = js::CheckedUnwrap(&rval.toObject());
6717
0
    if (!unwrappedVal) {
6718
0
      // A slight lie, but not much of one, for a dead object wrapper.
6719
0
      aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.setLocalDescription"));
6720
0
      return nullptr;
6721
0
    }
6722
0
    globalObj = JS::GetNonCCWObjectGlobal(unwrappedVal);
6723
0
    JSAutoRealm ar(cx, globalObj);
6724
0
    GlobalObject promiseGlobal(cx, globalObj);
6725
0
    if (promiseGlobal.Failed()) {
6726
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6727
0
      return nullptr;
6728
0
    }
6729
0
6730
0
    JS::Rooted<JS::Value> valueToResolve(cx, rval);
6731
0
    if (!JS_WrapValue(cx, &valueToResolve)) {
6732
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6733
0
      return nullptr;
6734
0
    }
6735
0
    binding_detail::FastErrorResult promiseRv;
6736
0
    nsCOMPtr<nsIGlobalObject> global =
6737
0
      do_QueryInterface(promiseGlobal.GetAsSupports());
6738
0
    if (!global) {
6739
0
      promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED);
6740
0
      MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
6741
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6742
0
      return nullptr;
6743
0
    }
6744
0
    rvalDecl = Promise::Resolve(global, cx, valueToResolve,
6745
0
                                    promiseRv);
6746
0
    if (promiseRv.MaybeSetPendingException(cx)) {
6747
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6748
0
      return nullptr;
6749
0
    }
6750
0
  }
6751
0
  return rvalDecl.forget();
6752
0
}
6753
6754
already_AddRefed<Promise>
6755
RTCPeerConnectionJSImpl::SetRemoteDescription(const RTCSessionDescriptionInit& description, ErrorResult& aRv, JS::Realm* aRealm)
6756
0
{
6757
0
  CallSetup s(this, aRv, "RTCPeerConnection.setRemoteDescription", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
6758
0
  JSContext* cx = s.GetContext();
6759
0
  if (!cx) {
6760
0
    MOZ_ASSERT(aRv.Failed());
6761
0
    return nullptr;
6762
0
  }
6763
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
6764
0
  JS::AutoValueVector argv(cx);
6765
0
  if (!argv.resize(1)) {
6766
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
6767
0
    return nullptr;
6768
0
  }
6769
0
  unsigned argc = 1;
6770
0
6771
0
  do {
6772
0
    if (!description.ToObjectInternal(cx, argv[0])) {
6773
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6774
0
      return nullptr;
6775
0
    }
6776
0
    break;
6777
0
  } while (false);
6778
0
6779
0
  JS::Rooted<JS::Value> callable(cx);
6780
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
6781
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
6782
0
      !GetCallableProperty(cx, atomsCache->setRemoteDescription_id, &callable)) {
6783
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
6784
0
    return nullptr;
6785
0
  }
6786
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
6787
0
  if (!JS::Call(cx, thisValue, callable,
6788
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
6789
0
    aRv.NoteJSContextException(cx);
6790
0
    return nullptr;
6791
0
  }
6792
0
  RefPtr<Promise> rvalDecl;
6793
0
  { // Scope for our GlobalObject, FastErrorResult, JSAutoRealm,
6794
0
    // etc.
6795
0
6796
0
    JS::Rooted<JSObject*> globalObj(cx);
6797
0
    if (!rval.isObject()) {
6798
0
      aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.setRemoteDescription"));
6799
0
      return nullptr;
6800
0
    }
6801
0
    JSObject* unwrappedVal = js::CheckedUnwrap(&rval.toObject());
6802
0
    if (!unwrappedVal) {
6803
0
      // A slight lie, but not much of one, for a dead object wrapper.
6804
0
      aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.setRemoteDescription"));
6805
0
      return nullptr;
6806
0
    }
6807
0
    globalObj = JS::GetNonCCWObjectGlobal(unwrappedVal);
6808
0
    JSAutoRealm ar(cx, globalObj);
6809
0
    GlobalObject promiseGlobal(cx, globalObj);
6810
0
    if (promiseGlobal.Failed()) {
6811
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6812
0
      return nullptr;
6813
0
    }
6814
0
6815
0
    JS::Rooted<JS::Value> valueToResolve(cx, rval);
6816
0
    if (!JS_WrapValue(cx, &valueToResolve)) {
6817
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6818
0
      return nullptr;
6819
0
    }
6820
0
    binding_detail::FastErrorResult promiseRv;
6821
0
    nsCOMPtr<nsIGlobalObject> global =
6822
0
      do_QueryInterface(promiseGlobal.GetAsSupports());
6823
0
    if (!global) {
6824
0
      promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED);
6825
0
      MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
6826
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6827
0
      return nullptr;
6828
0
    }
6829
0
    rvalDecl = Promise::Resolve(global, cx, valueToResolve,
6830
0
                                    promiseRv);
6831
0
    if (promiseRv.MaybeSetPendingException(cx)) {
6832
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6833
0
      return nullptr;
6834
0
    }
6835
0
  }
6836
0
  return rvalDecl.forget();
6837
0
}
6838
6839
already_AddRefed<Promise>
6840
RTCPeerConnectionJSImpl::SetRemoteDescription(const RTCSessionDescriptionInit& description, VoidFunction& successCallback, RTCPeerConnectionErrorCallback& failureCallback, ErrorResult& aRv, JS::Realm* aRealm)
6841
0
{
6842
0
  CallSetup s(this, aRv, "RTCPeerConnection.setRemoteDescription", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
6843
0
  JSContext* cx = s.GetContext();
6844
0
  if (!cx) {
6845
0
    MOZ_ASSERT(aRv.Failed());
6846
0
    return nullptr;
6847
0
  }
6848
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
6849
0
  JS::AutoValueVector argv(cx);
6850
0
  if (!argv.resize(3)) {
6851
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
6852
0
    return nullptr;
6853
0
  }
6854
0
  unsigned argc = 3;
6855
0
6856
0
  do {
6857
0
    argv[2].setObjectOrNull(GetCallbackFromCallbackObject(cx, failureCallback));
6858
0
    if (!MaybeWrapObjectValue(cx, argv[2])) {
6859
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6860
0
      return nullptr;
6861
0
    }
6862
0
    break;
6863
0
  } while (false);
6864
0
6865
0
  do {
6866
0
    argv[1].setObjectOrNull(GetCallbackFromCallbackObject(cx, successCallback));
6867
0
    if (!MaybeWrapObjectValue(cx, argv[1])) {
6868
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6869
0
      return nullptr;
6870
0
    }
6871
0
    break;
6872
0
  } while (false);
6873
0
6874
0
  do {
6875
0
    if (!description.ToObjectInternal(cx, argv[0])) {
6876
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6877
0
      return nullptr;
6878
0
    }
6879
0
    break;
6880
0
  } while (false);
6881
0
6882
0
  JS::Rooted<JS::Value> callable(cx);
6883
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
6884
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
6885
0
      !GetCallableProperty(cx, atomsCache->setRemoteDescription_id, &callable)) {
6886
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
6887
0
    return nullptr;
6888
0
  }
6889
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
6890
0
  if (!JS::Call(cx, thisValue, callable,
6891
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
6892
0
    aRv.NoteJSContextException(cx);
6893
0
    return nullptr;
6894
0
  }
6895
0
  RefPtr<Promise> rvalDecl;
6896
0
  { // Scope for our GlobalObject, FastErrorResult, JSAutoRealm,
6897
0
    // etc.
6898
0
6899
0
    JS::Rooted<JSObject*> globalObj(cx);
6900
0
    if (!rval.isObject()) {
6901
0
      aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.setRemoteDescription"));
6902
0
      return nullptr;
6903
0
    }
6904
0
    JSObject* unwrappedVal = js::CheckedUnwrap(&rval.toObject());
6905
0
    if (!unwrappedVal) {
6906
0
      // A slight lie, but not much of one, for a dead object wrapper.
6907
0
      aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.setRemoteDescription"));
6908
0
      return nullptr;
6909
0
    }
6910
0
    globalObj = JS::GetNonCCWObjectGlobal(unwrappedVal);
6911
0
    JSAutoRealm ar(cx, globalObj);
6912
0
    GlobalObject promiseGlobal(cx, globalObj);
6913
0
    if (promiseGlobal.Failed()) {
6914
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6915
0
      return nullptr;
6916
0
    }
6917
0
6918
0
    JS::Rooted<JS::Value> valueToResolve(cx, rval);
6919
0
    if (!JS_WrapValue(cx, &valueToResolve)) {
6920
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6921
0
      return nullptr;
6922
0
    }
6923
0
    binding_detail::FastErrorResult promiseRv;
6924
0
    nsCOMPtr<nsIGlobalObject> global =
6925
0
      do_QueryInterface(promiseGlobal.GetAsSupports());
6926
0
    if (!global) {
6927
0
      promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED);
6928
0
      MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
6929
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6930
0
      return nullptr;
6931
0
    }
6932
0
    rvalDecl = Promise::Resolve(global, cx, valueToResolve,
6933
0
                                    promiseRv);
6934
0
    if (promiseRv.MaybeSetPendingException(cx)) {
6935
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6936
0
      return nullptr;
6937
0
    }
6938
0
  }
6939
0
  return rvalDecl.forget();
6940
0
}
6941
6942
already_AddRefed<Promise>
6943
RTCPeerConnectionJSImpl::AddIceCandidate(const Nullable<RTCIceCandidateInitOrRTCIceCandidate>& candidate, ErrorResult& aRv, JS::Realm* aRealm)
6944
0
{
6945
0
  CallSetup s(this, aRv, "RTCPeerConnection.addIceCandidate", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
6946
0
  JSContext* cx = s.GetContext();
6947
0
  if (!cx) {
6948
0
    MOZ_ASSERT(aRv.Failed());
6949
0
    return nullptr;
6950
0
  }
6951
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
6952
0
  JS::AutoValueVector argv(cx);
6953
0
  if (!argv.resize(1)) {
6954
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
6955
0
    return nullptr;
6956
0
  }
6957
0
  unsigned argc = 1;
6958
0
6959
0
  do {
6960
0
    if (candidate.IsNull()) {
6961
0
      argv[0].setNull();
6962
0
      break;
6963
0
    }
6964
0
    if (!candidate.Value().ToJSVal(cx, CallbackKnownNotGray(), argv[0])) {
6965
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
6966
0
      return nullptr;
6967
0
    }
6968
0
    break;
6969
0
  } while (false);
6970
0
6971
0
  JS::Rooted<JS::Value> callable(cx);
6972
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
6973
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
6974
0
      !GetCallableProperty(cx, atomsCache->addIceCandidate_id, &callable)) {
6975
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
6976
0
    return nullptr;
6977
0
  }
6978
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
6979
0
  if (!JS::Call(cx, thisValue, callable,
6980
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
6981
0
    aRv.NoteJSContextException(cx);
6982
0
    return nullptr;
6983
0
  }
6984
0
  RefPtr<Promise> rvalDecl;
6985
0
  { // Scope for our GlobalObject, FastErrorResult, JSAutoRealm,
6986
0
    // etc.
6987
0
6988
0
    JS::Rooted<JSObject*> globalObj(cx);
6989
0
    if (!rval.isObject()) {
6990
0
      aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.addIceCandidate"));
6991
0
      return nullptr;
6992
0
    }
6993
0
    JSObject* unwrappedVal = js::CheckedUnwrap(&rval.toObject());
6994
0
    if (!unwrappedVal) {
6995
0
      // A slight lie, but not much of one, for a dead object wrapper.
6996
0
      aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.addIceCandidate"));
6997
0
      return nullptr;
6998
0
    }
6999
0
    globalObj = JS::GetNonCCWObjectGlobal(unwrappedVal);
7000
0
    JSAutoRealm ar(cx, globalObj);
7001
0
    GlobalObject promiseGlobal(cx, globalObj);
7002
0
    if (promiseGlobal.Failed()) {
7003
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
7004
0
      return nullptr;
7005
0
    }
7006
0
7007
0
    JS::Rooted<JS::Value> valueToResolve(cx, rval);
7008
0
    if (!JS_WrapValue(cx, &valueToResolve)) {
7009
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
7010
0
      return nullptr;
7011
0
    }
7012
0
    binding_detail::FastErrorResult promiseRv;
7013
0
    nsCOMPtr<nsIGlobalObject> global =
7014
0
      do_QueryInterface(promiseGlobal.GetAsSupports());
7015
0
    if (!global) {
7016
0
      promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED);
7017
0
      MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
7018
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
7019
0
      return nullptr;
7020
0
    }
7021
0
    rvalDecl = Promise::Resolve(global, cx, valueToResolve,
7022
0
                                    promiseRv);
7023
0
    if (promiseRv.MaybeSetPendingException(cx)) {
7024
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
7025
0
      return nullptr;
7026
0
    }
7027
0
  }
7028
0
  return rvalDecl.forget();
7029
0
}
7030
7031
already_AddRefed<Promise>
7032
RTCPeerConnectionJSImpl::AddIceCandidate(RTCIceCandidate& candidate, VoidFunction& successCallback, RTCPeerConnectionErrorCallback& failureCallback, ErrorResult& aRv, JS::Realm* aRealm)
7033
0
{
7034
0
  CallSetup s(this, aRv, "RTCPeerConnection.addIceCandidate", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
7035
0
  JSContext* cx = s.GetContext();
7036
0
  if (!cx) {
7037
0
    MOZ_ASSERT(aRv.Failed());
7038
0
    return nullptr;
7039
0
  }
7040
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
7041
0
  JS::AutoValueVector argv(cx);
7042
0
  if (!argv.resize(3)) {
7043
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
7044
0
    return nullptr;
7045
0
  }
7046
0
  unsigned argc = 3;
7047
0
7048
0
  do {
7049
0
    argv[2].setObjectOrNull(GetCallbackFromCallbackObject(cx, failureCallback));
7050
0
    if (!MaybeWrapObjectValue(cx, argv[2])) {
7051
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
7052
0
      return nullptr;
7053
0
    }
7054
0
    break;
7055
0
  } while (false);
7056
0
7057
0
  do {
7058
0
    argv[1].setObjectOrNull(GetCallbackFromCallbackObject(cx, successCallback));
7059
0
    if (!MaybeWrapObjectValue(cx, argv[1])) {
7060
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
7061
0
      return nullptr;
7062
0
    }
7063
0
    break;
7064
0
  } while (false);
7065
0
7066
0
  do {
7067
0
    if (!GetOrCreateDOMReflector(cx, candidate, argv[0])) {
7068
0
      MOZ_ASSERT(JS_IsExceptionPending(cx));
7069
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
7070
0
      return nullptr;
7071
0
    }
7072
0
    break;
7073
0
  } while (false);
7074
0
7075
0
  JS::Rooted<JS::Value> callable(cx);
7076
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
7077
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
7078
0
      !GetCallableProperty(cx, atomsCache->addIceCandidate_id, &callable)) {
7079
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
7080
0
    return nullptr;
7081
0
  }
7082
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
7083
0
  if (!JS::Call(cx, thisValue, callable,
7084
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
7085
0
    aRv.NoteJSContextException(cx);
7086
0
    return nullptr;
7087
0
  }
7088
0
  RefPtr<Promise> rvalDecl;
7089
0
  { // Scope for our GlobalObject, FastErrorResult, JSAutoRealm,
7090
0
    // etc.
7091
0
7092
0
    JS::Rooted<JSObject*> globalObj(cx);
7093
0
    if (!rval.isObject()) {
7094
0
      aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.addIceCandidate"));
7095
0
      return nullptr;
7096
0
    }
7097
0
    JSObject* unwrappedVal = js::CheckedUnwrap(&rval.toObject());
7098
0
    if (!unwrappedVal) {
7099
0
      // A slight lie, but not much of one, for a dead object wrapper.
7100
0
      aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.addIceCandidate"));
7101
0
      return nullptr;
7102
0
    }
7103
0
    globalObj = JS::GetNonCCWObjectGlobal(unwrappedVal);
7104
0
    JSAutoRealm ar(cx, globalObj);
7105
0
    GlobalObject promiseGlobal(cx, globalObj);
7106
0
    if (promiseGlobal.Failed()) {
7107
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
7108
0
      return nullptr;
7109
0
    }
7110
0
7111
0
    JS::Rooted<JS::Value> valueToResolve(cx, rval);
7112
0
    if (!JS_WrapValue(cx, &valueToResolve)) {
7113
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
7114
0
      return nullptr;
7115
0
    }
7116
0
    binding_detail::FastErrorResult promiseRv;
7117
0
    nsCOMPtr<nsIGlobalObject> global =
7118
0
      do_QueryInterface(promiseGlobal.GetAsSupports());
7119
0
    if (!global) {
7120
0
      promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED);
7121
0
      MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
7122
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
7123
0
      return nullptr;
7124
0
    }
7125
0
    rvalDecl = Promise::Resolve(global, cx, valueToResolve,
7126
0
                                    promiseRv);
7127
0
    if (promiseRv.MaybeSetPendingException(cx)) {
7128
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
7129
0
      return nullptr;
7130
0
    }
7131
0
  }
7132
0
  return rvalDecl.forget();
7133
0
}
7134
7135
void
7136
RTCPeerConnectionJSImpl::GetConfiguration(RTCConfiguration& aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
7137
0
{
7138
0
  CallSetup s(this, aRv, "RTCPeerConnection.getConfiguration", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
7139
0
  JSContext* cx = s.GetContext();
7140
0
  if (!cx) {
7141
0
    MOZ_ASSERT(aRv.Failed());
7142
0
    return;
7143
0
  }
7144
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
7145
0
7146
0
  JS::Rooted<JS::Value> callable(cx);
7147
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
7148
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
7149
0
      !GetCallableProperty(cx, atomsCache->getConfiguration_id, &callable)) {
7150
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
7151
0
    return;
7152
0
  }
7153
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
7154
0
  if (!JS::Call(cx, thisValue, callable,
7155
0
                JS::HandleValueArray::empty(), &rval)) {
7156
0
    aRv.NoteJSContextException(cx);
7157
0
    return;
7158
0
  }
7159
0
  RTCConfiguration& rvalDecl(aRetVal);
7160
0
  if (!rvalDecl.Init(cx, rval,  "Return value of RTCPeerConnection.getConfiguration", false)) {
7161
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
7162
0
    return;
7163
0
  }
7164
0
}
7165
7166
void
7167
RTCPeerConnectionJSImpl::GetLocalStreams(nsTArray<RefPtr<DOMMediaStream>>& aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
7168
0
{
7169
0
  CallSetup s(this, aRv, "RTCPeerConnection.getLocalStreams", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
7170
0
  JSContext* cx = s.GetContext();
7171
0
  if (!cx) {
7172
0
    MOZ_ASSERT(aRv.Failed());
7173
0
    return;
7174
0
  }
7175
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
7176
0
7177
0
  JS::Rooted<JS::Value> callable(cx);
7178
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
7179
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
7180
0
      !GetCallableProperty(cx, atomsCache->getLocalStreams_id, &callable)) {
7181
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
7182
0
    return;
7183
0
  }
7184
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
7185
0
  if (!JS::Call(cx, thisValue, callable,
7186
0
                JS::HandleValueArray::empty(), &rval)) {
7187
0
    aRv.NoteJSContextException(cx);
7188
0
    return;
7189
0
  }
7190
0
  Sequence<RefPtr<mozilla::DOMMediaStream>> rvalDecl;
7191
0
  if (rval.isObject()) {
7192
0
    JS::ForOfIterator iter(cx);
7193
0
    if (!iter.init(rval, JS::ForOfIterator::AllowNonIterable)) {
7194
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
7195
0
      return;
7196
0
    }
7197
0
    if (!iter.valueIsIterable()) {
7198
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Return value of RTCPeerConnection.getLocalStreams");
7199
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
7200
0
      return;
7201
0
    }
7202
0
    Sequence<RefPtr<mozilla::DOMMediaStream>> &arr = rvalDecl;
7203
0
    JS::Rooted<JS::Value> temp(cx);
7204
0
    while (true) {
7205
0
      bool done;
7206
0
      if (!iter.next(&temp, &done)) {
7207
0
        aRv.Throw(NS_ERROR_UNEXPECTED);
7208
0
        return;
7209
0
      }
7210
0
      if (done) {
7211
0
        break;
7212
0
      }
7213
0
      RefPtr<mozilla::DOMMediaStream>* slotPtr = arr.AppendElement(mozilla::fallible);
7214
0
      if (!slotPtr) {
7215
0
        JS_ReportOutOfMemory(cx);
7216
0
        aRv.Throw(NS_ERROR_UNEXPECTED);
7217
0
        return;
7218
0
      }
7219
0
      RefPtr<mozilla::DOMMediaStream>& slot = *slotPtr;
7220
0
      if (temp.isObject()) {
7221
0
        static_assert(IsRefcounted<mozilla::DOMMediaStream>::value, "We can only store refcounted classes.");{
7222
0
          nsresult rv = UnwrapObject<prototypes::id::MediaStream, mozilla::DOMMediaStream>(&temp, slot);
7223
0
          if (NS_FAILED(rv)) {
7224
0
            ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Element of return value of RTCPeerConnection.getLocalStreams", "MediaStream");
7225
0
            aRv.Throw(NS_ERROR_UNEXPECTED);
7226
0
            return;
7227
0
          }
7228
0
        }
7229
0
      } else {
7230
0
        ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of return value of RTCPeerConnection.getLocalStreams");
7231
0
        aRv.Throw(NS_ERROR_UNEXPECTED);
7232
0
        return;
7233
0
      }
7234
0
    }
7235
0
  } else {
7236
0
    ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Return value of RTCPeerConnection.getLocalStreams");
7237
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
7238
0
    return;
7239
0
  }
7240
0
  aRetVal.SwapElements(rvalDecl);
7241
0
}
7242
7243
void
7244
RTCPeerConnectionJSImpl::GetRemoteStreams(nsTArray<RefPtr<DOMMediaStream>>& aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
7245
0
{
7246
0
  CallSetup s(this, aRv, "RTCPeerConnection.getRemoteStreams", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
7247
0
  JSContext* cx = s.GetContext();
7248
0
  if (!cx) {
7249
0
    MOZ_ASSERT(aRv.Failed());
7250
0
    return;
7251
0
  }
7252
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
7253
0
7254
0
  JS::Rooted<JS::Value> callable(cx);
7255
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
7256
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
7257
0
      !GetCallableProperty(cx, atomsCache->getRemoteStreams_id, &callable)) {
7258
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
7259
0
    return;
7260
0
  }
7261
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
7262
0
  if (!JS::Call(cx, thisValue, callable,
7263
0
                JS::HandleValueArray::empty(), &rval)) {
7264
0
    aRv.NoteJSContextException(cx);
7265
0
    return;
7266
0
  }
7267
0
  Sequence<RefPtr<mozilla::DOMMediaStream>> rvalDecl;
7268
0
  if (rval.isObject()) {
7269
0
    JS::ForOfIterator iter(cx);
7270
0
    if (!iter.init(rval, JS::ForOfIterator::AllowNonIterable)) {
7271
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
7272
0
      return;
7273
0
    }
7274
0
    if (!iter.valueIsIterable()) {
7275
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Return value of RTCPeerConnection.getRemoteStreams");
7276
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
7277
0
      return;
7278
0
    }
7279
0
    Sequence<RefPtr<mozilla::DOMMediaStream>> &arr = rvalDecl;
7280
0
    JS::Rooted<JS::Value> temp(cx);
7281
0
    while (true) {
7282
0
      bool done;
7283
0
      if (!iter.next(&temp, &done)) {
7284
0
        aRv.Throw(NS_ERROR_UNEXPECTED);
7285
0
        return;
7286
0
      }
7287
0
      if (done) {
7288
0
        break;
7289
0
      }
7290
0
      RefPtr<mozilla::DOMMediaStream>* slotPtr = arr.AppendElement(mozilla::fallible);
7291
0
      if (!slotPtr) {
7292
0
        JS_ReportOutOfMemory(cx);
7293
0
        aRv.Throw(NS_ERROR_UNEXPECTED);
7294
0
        return;
7295
0
      }
7296
0
      RefPtr<mozilla::DOMMediaStream>& slot = *slotPtr;
7297
0
      if (temp.isObject()) {
7298
0
        static_assert(IsRefcounted<mozilla::DOMMediaStream>::value, "We can only store refcounted classes.");{
7299
0
          nsresult rv = UnwrapObject<prototypes::id::MediaStream, mozilla::DOMMediaStream>(&temp, slot);
7300
0
          if (NS_FAILED(rv)) {
7301
0
            ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Element of return value of RTCPeerConnection.getRemoteStreams", "MediaStream");
7302
0
            aRv.Throw(NS_ERROR_UNEXPECTED);
7303
0
            return;
7304
0
          }
7305
0
        }
7306
0
      } else {
7307
0
        ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of return value of RTCPeerConnection.getRemoteStreams");
7308
0
        aRv.Throw(NS_ERROR_UNEXPECTED);
7309
0
        return;
7310
0
      }
7311
0
    }
7312
0
  } else {
7313
0
    ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Return value of RTCPeerConnection.getRemoteStreams");
7314
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
7315
0
    return;
7316
0
  }
7317
0
  aRetVal.SwapElements(rvalDecl);
7318
0
}
7319
7320
void
7321
RTCPeerConnectionJSImpl::AddStream(DOMMediaStream& stream, ErrorResult& aRv, JS::Realm* aRealm)
7322
0
{
7323
0
  CallSetup s(this, aRv, "RTCPeerConnection.addStream", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
7324
0
  JSContext* cx = s.GetContext();
7325
0
  if (!cx) {
7326
0
    MOZ_ASSERT(aRv.Failed());
7327
0
    return;
7328
0
  }
7329
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
7330
0
  JS::AutoValueVector argv(cx);
7331
0
  if (!argv.resize(1)) {
7332
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
7333
0
    return;
7334
0
  }
7335
0
  unsigned argc = 1;
7336
0
7337
0
  do {
7338
0
    if (!GetOrCreateDOMReflector(cx, stream, argv[0])) {
7339
0
      MOZ_ASSERT(JS_IsExceptionPending(cx));
7340
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
7341
0
      return;
7342
0
    }
7343
0
    break;
7344
0
  } while (false);
7345
0
7346
0
  JS::Rooted<JS::Value> callable(cx);
7347
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
7348
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
7349
0
      !GetCallableProperty(cx, atomsCache->addStream_id, &callable)) {
7350
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
7351
0
    return;
7352
0
  }
7353
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
7354
0
  if (!JS::Call(cx, thisValue, callable,
7355
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
7356
0
    aRv.NoteJSContextException(cx);
7357
0
    return;
7358
0
  }
7359
0
}
7360
7361
already_AddRefed<RTCRtpSender>
7362
RTCPeerConnectionJSImpl::AddTrack(MediaStreamTrack& track, DOMMediaStream& stream, const nsTArray<OwningNonNull<DOMMediaStream>>& moreStreams, ErrorResult& aRv, JS::Realm* aRealm)
7363
0
{
7364
0
  CallSetup s(this, aRv, "RTCPeerConnection.addTrack", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
7365
0
  JSContext* cx = s.GetContext();
7366
0
  if (!cx) {
7367
0
    MOZ_ASSERT(aRv.Failed());
7368
0
    return nullptr;
7369
0
  }
7370
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
7371
0
  JS::AutoValueVector argv(cx);
7372
0
  if (!argv.resize((3 - 1) + moreStreams.Length())) {
7373
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
7374
0
    return nullptr;
7375
0
  }
7376
0
  unsigned argc = (3 - 1) + moreStreams.Length();
7377
0
7378
0
  do {
7379
0
    for (uint32_t idx = 0; idx < moreStreams.Length(); ++idx) {
7380
0
      if (!GetOrCreateDOMReflector(cx, moreStreams[idx], argv[2 + idx])) {
7381
0
        MOZ_ASSERT(JS_IsExceptionPending(cx));
7382
0
        aRv.Throw(NS_ERROR_UNEXPECTED);
7383
0
        return nullptr;
7384
0
      }
7385
0
      continue;
7386
0
    }
7387
0
    break;
7388
0
  } while (false);
7389
0
7390
0
  do {
7391
0
    if (!GetOrCreateDOMReflector(cx, stream, argv[1])) {
7392
0
      MOZ_ASSERT(JS_IsExceptionPending(cx));
7393
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
7394
0
      return nullptr;
7395
0
    }
7396
0
    break;
7397
0
  } while (false);
7398
0
7399
0
  do {
7400
0
    if (!GetOrCreateDOMReflector(cx, track, argv[0])) {
7401
0
      MOZ_ASSERT(JS_IsExceptionPending(cx));
7402
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
7403
0
      return nullptr;
7404
0
    }
7405
0
    break;
7406
0
  } while (false);
7407
0
7408
0
  JS::Rooted<JS::Value> callable(cx);
7409
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
7410
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
7411
0
      !GetCallableProperty(cx, atomsCache->addTrack_id, &callable)) {
7412
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
7413
0
    return nullptr;
7414
0
  }
7415
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
7416
0
  if (!JS::Call(cx, thisValue, callable,
7417
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
7418
0
    aRv.NoteJSContextException(cx);
7419
0
    return nullptr;
7420
0
  }
7421
0
  RefPtr<mozilla::dom::RTCRtpSender> rvalDecl;
7422
0
  if (rval.isObject()) {
7423
0
    static_assert(IsRefcounted<mozilla::dom::RTCRtpSender>::value, "We can only store refcounted classes.");{
7424
0
      nsresult rv = UnwrapObject<prototypes::id::RTCRtpSender, mozilla::dom::RTCRtpSender>(rval, rvalDecl);
7425
0
      if (NS_FAILED(rv)) {
7426
0
        // Be careful to not wrap random DOM objects here, even if
7427
0
        // they're wrapped in opaque security wrappers for some reason.
7428
0
        // XXXbz Wish we could check for a JS-implemented object
7429
0
        // that already has a content reflection...
7430
0
        if (!IsDOMObject(js::UncheckedUnwrap(&rval.toObject()))) {
7431
0
          nsCOMPtr<nsIGlobalObject> contentGlobal;
7432
0
          JS::Handle<JSObject*> callback = CallbackOrNull();
7433
0
          if (!callback ||
7434
0
              !GetContentGlobalForJSImplementedObject(cx, callback, getter_AddRefs(contentGlobal))) {
7435
0
            aRv.Throw(NS_ERROR_UNEXPECTED);
7436
0
            return nullptr;
7437
0
          }
7438
0
          JS::Rooted<JSObject*> jsImplSourceObj(cx, &rval.toObject());
7439
0
          MOZ_RELEASE_ASSERT(!js::IsWrapper(jsImplSourceObj),
7440
0
                             "Don't return JS implementations from other compartments");
7441
0
          JS::Rooted<JSObject*> jsImplSourceGlobal(cx, JS::GetNonCCWObjectGlobal(jsImplSourceObj));
7442
0
          rvalDecl = new mozilla::dom::RTCRtpSender(jsImplSourceObj, jsImplSourceGlobal, contentGlobal);
7443
0
        } else {
7444
0
          ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Return value of RTCPeerConnection.addTrack", "RTCRtpSender");
7445
0
          aRv.Throw(NS_ERROR_UNEXPECTED);
7446
0
          return nullptr;
7447
0
        }
7448
0
      }
7449
0
    }
7450
0
  } else {
7451
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Return value of RTCPeerConnection.addTrack");
7452
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
7453
0
    return nullptr;
7454
0
  }
7455
0
  return rvalDecl.forget();
7456
0
}
7457
7458
void
7459
RTCPeerConnectionJSImpl::RemoveTrack(RTCRtpSender& sender, ErrorResult& aRv, JS::Realm* aRealm)
7460
0
{
7461
0
  CallSetup s(this, aRv, "RTCPeerConnection.removeTrack", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
7462
0
  JSContext* cx = s.GetContext();
7463
0
  if (!cx) {
7464
0
    MOZ_ASSERT(aRv.Failed());
7465
0
    return;
7466
0
  }
7467
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
7468
0
  JS::AutoValueVector argv(cx);
7469
0
  if (!argv.resize(1)) {
7470
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
7471
0
    return;
7472
0
  }
7473
0
  unsigned argc = 1;
7474
0
7475
0
  do {
7476
0
    if (!GetOrCreateDOMReflector(cx, sender, argv[0])) {
7477
0
      MOZ_ASSERT(JS_IsExceptionPending(cx));
7478
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
7479
0
      return;
7480
0
    }
7481
0
    break;
7482
0
  } while (false);
7483
0
7484
0
  JS::Rooted<JS::Value> callable(cx);
7485
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
7486
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
7487
0
      !GetCallableProperty(cx, atomsCache->removeTrack_id, &callable)) {
7488
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
7489
0
    return;
7490
0
  }
7491
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
7492
0
  if (!JS::Call(cx, thisValue, callable,
7493
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
7494
0
    aRv.NoteJSContextException(cx);
7495
0
    return;
7496
0
  }
7497
0
}
7498
7499
already_AddRefed<RTCRtpTransceiver>
7500
RTCPeerConnectionJSImpl::AddTransceiver(const MediaStreamTrackOrString& trackOrKind, const RTCRtpTransceiverInit& init, ErrorResult& aRv, JS::Realm* aRealm)
7501
0
{
7502
0
  CallSetup s(this, aRv, "RTCPeerConnection.addTransceiver", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
7503
0
  JSContext* cx = s.GetContext();
7504
0
  if (!cx) {
7505
0
    MOZ_ASSERT(aRv.Failed());
7506
0
    return nullptr;
7507
0
  }
7508
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
7509
0
  JS::AutoValueVector argv(cx);
7510
0
  if (!argv.resize(2)) {
7511
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
7512
0
    return nullptr;
7513
0
  }
7514
0
  unsigned argc = 2;
7515
0
7516
0
  do {
7517
0
    if (!init.ToObjectInternal(cx, argv[1])) {
7518
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
7519
0
      return nullptr;
7520
0
    }
7521
0
    break;
7522
0
  } while (false);
7523
0
7524
0
  do {
7525
0
    if (!trackOrKind.ToJSVal(cx, CallbackKnownNotGray(), argv[0])) {
7526
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
7527
0
      return nullptr;
7528
0
    }
7529
0
    break;
7530
0
  } while (false);
7531
0
7532
0
  JS::Rooted<JS::Value> callable(cx);
7533
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
7534
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
7535
0
      !GetCallableProperty(cx, atomsCache->addTransceiver_id, &callable)) {
7536
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
7537
0
    return nullptr;
7538
0
  }
7539
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
7540
0
  if (!JS::Call(cx, thisValue, callable,
7541
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
7542
0
    aRv.NoteJSContextException(cx);
7543
0
    return nullptr;
7544
0
  }
7545
0
  RefPtr<mozilla::dom::RTCRtpTransceiver> rvalDecl;
7546
0
  if (rval.isObject()) {
7547
0
    static_assert(IsRefcounted<mozilla::dom::RTCRtpTransceiver>::value, "We can only store refcounted classes.");{
7548
0
      nsresult rv = UnwrapObject<prototypes::id::RTCRtpTransceiver, mozilla::dom::RTCRtpTransceiver>(rval, rvalDecl);
7549
0
      if (NS_FAILED(rv)) {
7550
0
        // Be careful to not wrap random DOM objects here, even if
7551
0
        // they're wrapped in opaque security wrappers for some reason.
7552
0
        // XXXbz Wish we could check for a JS-implemented object
7553
0
        // that already has a content reflection...
7554
0
        if (!IsDOMObject(js::UncheckedUnwrap(&rval.toObject()))) {
7555
0
          nsCOMPtr<nsIGlobalObject> contentGlobal;
7556
0
          JS::Handle<JSObject*> callback = CallbackOrNull();
7557
0
          if (!callback ||
7558
0
              !GetContentGlobalForJSImplementedObject(cx, callback, getter_AddRefs(contentGlobal))) {
7559
0
            aRv.Throw(NS_ERROR_UNEXPECTED);
7560
0
            return nullptr;
7561
0
          }
7562
0
          JS::Rooted<JSObject*> jsImplSourceObj(cx, &rval.toObject());
7563
0
          MOZ_RELEASE_ASSERT(!js::IsWrapper(jsImplSourceObj),
7564
0
                             "Don't return JS implementations from other compartments");
7565
0
          JS::Rooted<JSObject*> jsImplSourceGlobal(cx, JS::GetNonCCWObjectGlobal(jsImplSourceObj));
7566
0
          rvalDecl = new mozilla::dom::RTCRtpTransceiver(jsImplSourceObj, jsImplSourceGlobal, contentGlobal);
7567
0
        } else {
7568
0
          ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Return value of RTCPeerConnection.addTransceiver", "RTCRtpTransceiver");
7569
0
          aRv.Throw(NS_ERROR_UNEXPECTED);
7570
0
          return nullptr;
7571
0
        }
7572
0
      }
7573
0
    }
7574
0
  } else {
7575
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Return value of RTCPeerConnection.addTransceiver");
7576
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
7577
0
    return nullptr;
7578
0
  }
7579
0
  return rvalDecl.forget();
7580
0
}
7581
7582
void
7583
RTCPeerConnectionJSImpl::GetSenders(nsTArray<RefPtr<RTCRtpSender>>& aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
7584
0
{
7585
0
  CallSetup s(this, aRv, "RTCPeerConnection.getSenders", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
7586
0
  JSContext* cx = s.GetContext();
7587
0
  if (!cx) {
7588
0
    MOZ_ASSERT(aRv.Failed());
7589
0
    return;
7590
0
  }
7591
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
7592
0
7593
0
  JS::Rooted<JS::Value> callable(cx);
7594
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
7595
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
7596
0
      !GetCallableProperty(cx, atomsCache->getSenders_id, &callable)) {
7597
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
7598
0
    return;
7599
0
  }
7600
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
7601
0
  if (!JS::Call(cx, thisValue, callable,
7602
0
                JS::HandleValueArray::empty(), &rval)) {
7603
0
    aRv.NoteJSContextException(cx);
7604
0
    return;
7605
0
  }
7606
0
  Sequence<RefPtr<mozilla::dom::RTCRtpSender>> rvalDecl;
7607
0
  if (rval.isObject()) {
7608
0
    JS::ForOfIterator iter(cx);
7609
0
    if (!iter.init(rval, JS::ForOfIterator::AllowNonIterable)) {
7610
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
7611
0
      return;
7612
0
    }
7613
0
    if (!iter.valueIsIterable()) {
7614
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Return value of RTCPeerConnection.getSenders");
7615
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
7616
0
      return;
7617
0
    }
7618
0
    Sequence<RefPtr<mozilla::dom::RTCRtpSender>> &arr = rvalDecl;
7619
0
    JS::Rooted<JS::Value> temp(cx);
7620
0
    while (true) {
7621
0
      bool done;
7622
0
      if (!iter.next(&temp, &done)) {
7623
0
        aRv.Throw(NS_ERROR_UNEXPECTED);
7624
0
        return;
7625
0
      }
7626
0
      if (done) {
7627
0
        break;
7628
0
      }
7629
0
      RefPtr<mozilla::dom::RTCRtpSender>* slotPtr = arr.AppendElement(mozilla::fallible);
7630
0
      if (!slotPtr) {
7631
0
        JS_ReportOutOfMemory(cx);
7632
0
        aRv.Throw(NS_ERROR_UNEXPECTED);
7633
0
        return;
7634
0
      }
7635
0
      RefPtr<mozilla::dom::RTCRtpSender>& slot = *slotPtr;
7636
0
      if (temp.isObject()) {
7637
0
        static_assert(IsRefcounted<mozilla::dom::RTCRtpSender>::value, "We can only store refcounted classes.");{
7638
0
          nsresult rv = UnwrapObject<prototypes::id::RTCRtpSender, mozilla::dom::RTCRtpSender>(&temp, slot);
7639
0
          if (NS_FAILED(rv)) {
7640
0
            // Be careful to not wrap random DOM objects here, even if
7641
0
            // they're wrapped in opaque security wrappers for some reason.
7642
0
            // XXXbz Wish we could check for a JS-implemented object
7643
0
            // that already has a content reflection...
7644
0
            if (!IsDOMObject(js::UncheckedUnwrap(&temp.toObject()))) {
7645
0
              nsCOMPtr<nsIGlobalObject> contentGlobal;
7646
0
              JS::Handle<JSObject*> callback = CallbackOrNull();
7647
0
              if (!callback ||
7648
0
                  !GetContentGlobalForJSImplementedObject(cx, callback, getter_AddRefs(contentGlobal))) {
7649
0
                aRv.Throw(NS_ERROR_UNEXPECTED);
7650
0
                return;
7651
0
              }
7652
0
              JS::Rooted<JSObject*> jsImplSourceObj(cx, &temp.toObject());
7653
0
              MOZ_RELEASE_ASSERT(!js::IsWrapper(jsImplSourceObj),
7654
0
                                 "Don't return JS implementations from other compartments");
7655
0
              JS::Rooted<JSObject*> jsImplSourceGlobal(cx, JS::GetNonCCWObjectGlobal(jsImplSourceObj));
7656
0
              slot = new mozilla::dom::RTCRtpSender(jsImplSourceObj, jsImplSourceGlobal, contentGlobal);
7657
0
            } else {
7658
0
              ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Element of return value of RTCPeerConnection.getSenders", "RTCRtpSender");
7659
0
              aRv.Throw(NS_ERROR_UNEXPECTED);
7660
0
              return;
7661
0
            }
7662
0
          }
7663
0
        }
7664
0
      } else {
7665
0
        ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of return value of RTCPeerConnection.getSenders");
7666
0
        aRv.Throw(NS_ERROR_UNEXPECTED);
7667
0
        return;
7668
0
      }
7669
0
    }
7670
0
  } else {
7671
0
    ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Return value of RTCPeerConnection.getSenders");
7672
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
7673
0
    return;
7674
0
  }
7675
0
  aRetVal.SwapElements(rvalDecl);
7676
0
}
7677
7678
void
7679
RTCPeerConnectionJSImpl::GetReceivers(nsTArray<RefPtr<RTCRtpReceiver>>& aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
7680
0
{
7681
0
  CallSetup s(this, aRv, "RTCPeerConnection.getReceivers", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
7682
0
  JSContext* cx = s.GetContext();
7683
0
  if (!cx) {
7684
0
    MOZ_ASSERT(aRv.Failed());
7685
0
    return;
7686
0
  }
7687
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
7688
0
7689
0
  JS::Rooted<JS::Value> callable(cx);
7690
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
7691
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
7692
0
      !GetCallableProperty(cx, atomsCache->getReceivers_id, &callable)) {
7693
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
7694
0
    return;
7695
0
  }
7696
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
7697
0
  if (!JS::Call(cx, thisValue, callable,
7698
0
                JS::HandleValueArray::empty(), &rval)) {
7699
0
    aRv.NoteJSContextException(cx);
7700
0
    return;
7701
0
  }
7702
0
  Sequence<RefPtr<mozilla::dom::RTCRtpReceiver>> rvalDecl;
7703
0
  if (rval.isObject()) {
7704
0
    JS::ForOfIterator iter(cx);
7705
0
    if (!iter.init(rval, JS::ForOfIterator::AllowNonIterable)) {
7706
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
7707
0
      return;
7708
0
    }
7709
0
    if (!iter.valueIsIterable()) {
7710
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Return value of RTCPeerConnection.getReceivers");
7711
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
7712
0
      return;
7713
0
    }
7714
0
    Sequence<RefPtr<mozilla::dom::RTCRtpReceiver>> &arr = rvalDecl;
7715
0
    JS::Rooted<JS::Value> temp(cx);
7716
0
    while (true) {
7717
0
      bool done;
7718
0
      if (!iter.next(&temp, &done)) {
7719
0
        aRv.Throw(NS_ERROR_UNEXPECTED);
7720
0
        return;
7721
0
      }
7722
0
      if (done) {
7723
0
        break;
7724
0
      }
7725
0
      RefPtr<mozilla::dom::RTCRtpReceiver>* slotPtr = arr.AppendElement(mozilla::fallible);
7726
0
      if (!slotPtr) {
7727
0
        JS_ReportOutOfMemory(cx);
7728
0
        aRv.Throw(NS_ERROR_UNEXPECTED);
7729
0
        return;
7730
0
      }
7731
0
      RefPtr<mozilla::dom::RTCRtpReceiver>& slot = *slotPtr;
7732
0
      if (temp.isObject()) {
7733
0
        static_assert(IsRefcounted<mozilla::dom::RTCRtpReceiver>::value, "We can only store refcounted classes.");{
7734
0
          nsresult rv = UnwrapObject<prototypes::id::RTCRtpReceiver, mozilla::dom::RTCRtpReceiver>(&temp, slot);
7735
0
          if (NS_FAILED(rv)) {
7736
0
            // Be careful to not wrap random DOM objects here, even if
7737
0
            // they're wrapped in opaque security wrappers for some reason.
7738
0
            // XXXbz Wish we could check for a JS-implemented object
7739
0
            // that already has a content reflection...
7740
0
            if (!IsDOMObject(js::UncheckedUnwrap(&temp.toObject()))) {
7741
0
              nsCOMPtr<nsIGlobalObject> contentGlobal;
7742
0
              JS::Handle<JSObject*> callback = CallbackOrNull();
7743
0
              if (!callback ||
7744
0
                  !GetContentGlobalForJSImplementedObject(cx, callback, getter_AddRefs(contentGlobal))) {
7745
0
                aRv.Throw(NS_ERROR_UNEXPECTED);
7746
0
                return;
7747
0
              }
7748
0
              JS::Rooted<JSObject*> jsImplSourceObj(cx, &temp.toObject());
7749
0
              MOZ_RELEASE_ASSERT(!js::IsWrapper(jsImplSourceObj),
7750
0
                                 "Don't return JS implementations from other compartments");
7751
0
              JS::Rooted<JSObject*> jsImplSourceGlobal(cx, JS::GetNonCCWObjectGlobal(jsImplSourceObj));
7752
0
              slot = new mozilla::dom::RTCRtpReceiver(jsImplSourceObj, jsImplSourceGlobal, contentGlobal);
7753
0
            } else {
7754
0
              ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Element of return value of RTCPeerConnection.getReceivers", "RTCRtpReceiver");
7755
0
              aRv.Throw(NS_ERROR_UNEXPECTED);
7756
0
              return;
7757
0
            }
7758
0
          }
7759
0
        }
7760
0
      } else {
7761
0
        ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of return value of RTCPeerConnection.getReceivers");
7762
0
        aRv.Throw(NS_ERROR_UNEXPECTED);
7763
0
        return;
7764
0
      }
7765
0
    }
7766
0
  } else {
7767
0
    ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Return value of RTCPeerConnection.getReceivers");
7768
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
7769
0
    return;
7770
0
  }
7771
0
  aRetVal.SwapElements(rvalDecl);
7772
0
}
7773
7774
void
7775
RTCPeerConnectionJSImpl::GetTransceivers(nsTArray<RefPtr<RTCRtpTransceiver>>& aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
7776
0
{
7777
0
  CallSetup s(this, aRv, "RTCPeerConnection.getTransceivers", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
7778
0
  JSContext* cx = s.GetContext();
7779
0
  if (!cx) {
7780
0
    MOZ_ASSERT(aRv.Failed());
7781
0
    return;
7782
0
  }
7783
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
7784
0
7785
0
  JS::Rooted<JS::Value> callable(cx);
7786
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
7787
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
7788
0
      !GetCallableProperty(cx, atomsCache->getTransceivers_id, &callable)) {
7789
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
7790
0
    return;
7791
0
  }
7792
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
7793
0
  if (!JS::Call(cx, thisValue, callable,
7794
0
                JS::HandleValueArray::empty(), &rval)) {
7795
0
    aRv.NoteJSContextException(cx);
7796
0
    return;
7797
0
  }
7798
0
  Sequence<RefPtr<mozilla::dom::RTCRtpTransceiver>> rvalDecl;
7799
0
  if (rval.isObject()) {
7800
0
    JS::ForOfIterator iter(cx);
7801
0
    if (!iter.init(rval, JS::ForOfIterator::AllowNonIterable)) {
7802
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
7803
0
      return;
7804
0
    }
7805
0
    if (!iter.valueIsIterable()) {
7806
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Return value of RTCPeerConnection.getTransceivers");
7807
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
7808
0
      return;
7809
0
    }
7810
0
    Sequence<RefPtr<mozilla::dom::RTCRtpTransceiver>> &arr = rvalDecl;
7811
0
    JS::Rooted<JS::Value> temp(cx);
7812
0
    while (true) {
7813
0
      bool done;
7814
0
      if (!iter.next(&temp, &done)) {
7815
0
        aRv.Throw(NS_ERROR_UNEXPECTED);
7816
0
        return;
7817
0
      }
7818
0
      if (done) {
7819
0
        break;
7820
0
      }
7821
0
      RefPtr<mozilla::dom::RTCRtpTransceiver>* slotPtr = arr.AppendElement(mozilla::fallible);
7822
0
      if (!slotPtr) {
7823
0
        JS_ReportOutOfMemory(cx);
7824
0
        aRv.Throw(NS_ERROR_UNEXPECTED);
7825
0
        return;
7826
0
      }
7827
0
      RefPtr<mozilla::dom::RTCRtpTransceiver>& slot = *slotPtr;
7828
0
      if (temp.isObject()) {
7829
0
        static_assert(IsRefcounted<mozilla::dom::RTCRtpTransceiver>::value, "We can only store refcounted classes.");{
7830
0
          nsresult rv = UnwrapObject<prototypes::id::RTCRtpTransceiver, mozilla::dom::RTCRtpTransceiver>(&temp, slot);
7831
0
          if (NS_FAILED(rv)) {
7832
0
            // Be careful to not wrap random DOM objects here, even if
7833
0
            // they're wrapped in opaque security wrappers for some reason.
7834
0
            // XXXbz Wish we could check for a JS-implemented object
7835
0
            // that already has a content reflection...
7836
0
            if (!IsDOMObject(js::UncheckedUnwrap(&temp.toObject()))) {
7837
0
              nsCOMPtr<nsIGlobalObject> contentGlobal;
7838
0
              JS::Handle<JSObject*> callback = CallbackOrNull();
7839
0
              if (!callback ||
7840
0
                  !GetContentGlobalForJSImplementedObject(cx, callback, getter_AddRefs(contentGlobal))) {
7841
0
                aRv.Throw(NS_ERROR_UNEXPECTED);
7842
0
                return;
7843
0
              }
7844
0
              JS::Rooted<JSObject*> jsImplSourceObj(cx, &temp.toObject());
7845
0
              MOZ_RELEASE_ASSERT(!js::IsWrapper(jsImplSourceObj),
7846
0
                                 "Don't return JS implementations from other compartments");
7847
0
              JS::Rooted<JSObject*> jsImplSourceGlobal(cx, JS::GetNonCCWObjectGlobal(jsImplSourceObj));
7848
0
              slot = new mozilla::dom::RTCRtpTransceiver(jsImplSourceObj, jsImplSourceGlobal, contentGlobal);
7849
0
            } else {
7850
0
              ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Element of return value of RTCPeerConnection.getTransceivers", "RTCRtpTransceiver");
7851
0
              aRv.Throw(NS_ERROR_UNEXPECTED);
7852
0
              return;
7853
0
            }
7854
0
          }
7855
0
        }
7856
0
      } else {
7857
0
        ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of return value of RTCPeerConnection.getTransceivers");
7858
0
        aRv.Throw(NS_ERROR_UNEXPECTED);
7859
0
        return;
7860
0
      }
7861
0
    }
7862
0
  } else {
7863
0
    ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Return value of RTCPeerConnection.getTransceivers");
7864
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
7865
0
    return;
7866
0
  }
7867
0
  aRetVal.SwapElements(rvalDecl);
7868
0
}
7869
7870
double
7871
RTCPeerConnectionJSImpl::MozGetNowInRtpSourceReferenceTime(ErrorResult& aRv, JS::Realm* aRealm)
7872
0
{
7873
0
  CallSetup s(this, aRv, "RTCPeerConnection.mozGetNowInRtpSourceReferenceTime", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
7874
0
  JSContext* cx = s.GetContext();
7875
0
  if (!cx) {
7876
0
    MOZ_ASSERT(aRv.Failed());
7877
0
    return double(0);
7878
0
  }
7879
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
7880
0
7881
0
  JS::Rooted<JS::Value> callable(cx);
7882
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
7883
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
7884
0
      !GetCallableProperty(cx, atomsCache->mozGetNowInRtpSourceReferenceTime_id, &callable)) {
7885
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
7886
0
    return double(0);
7887
0
  }
7888
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
7889
0
  if (!JS::Call(cx, thisValue, callable,
7890
0
                JS::HandleValueArray::empty(), &rval)) {
7891
0
    aRv.NoteJSContextException(cx);
7892
0
    return double(0);
7893
0
  }
7894
0
  double rvalDecl;
7895
0
  if (!ValueToPrimitive<double, eDefault>(cx, rval, &rvalDecl)) {
7896
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
7897
0
    return double(0);
7898
0
  } else if (!mozilla::IsFinite(rvalDecl)) {
7899
0
    ThrowErrorMessage(cx, MSG_NOT_FINITE, "Return value of RTCPeerConnection.mozGetNowInRtpSourceReferenceTime");
7900
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
7901
0
    return double(0);
7902
0
  }
7903
0
  return rvalDecl;
7904
0
}
7905
7906
void
7907
RTCPeerConnectionJSImpl::MozInsertAudioLevelForContributingSource(RTCRtpReceiver& receiver, uint32_t source, double timestamp, bool hasLevel, int8_t level, ErrorResult& aRv, JS::Realm* aRealm)
7908
0
{
7909
0
  CallSetup s(this, aRv, "RTCPeerConnection.mozInsertAudioLevelForContributingSource", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
7910
0
  JSContext* cx = s.GetContext();
7911
0
  if (!cx) {
7912
0
    MOZ_ASSERT(aRv.Failed());
7913
0
    return;
7914
0
  }
7915
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
7916
0
  JS::AutoValueVector argv(cx);
7917
0
  if (!argv.resize(5)) {
7918
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
7919
0
    return;
7920
0
  }
7921
0
  unsigned argc = 5;
7922
0
7923
0
  do {
7924
0
    argv[4].setInt32(int32_t(level));
7925
0
    break;
7926
0
  } while (false);
7927
0
7928
0
  do {
7929
0
    argv[3].setBoolean(hasLevel);
7930
0
    break;
7931
0
  } while (false);
7932
0
7933
0
  do {
7934
0
    argv[2].set(JS_NumberValue(double(timestamp)));
7935
0
    break;
7936
0
  } while (false);
7937
0
7938
0
  do {
7939
0
    argv[1].setNumber(source);
7940
0
    break;
7941
0
  } while (false);
7942
0
7943
0
  do {
7944
0
    if (!GetOrCreateDOMReflector(cx, receiver, argv[0])) {
7945
0
      MOZ_ASSERT(JS_IsExceptionPending(cx));
7946
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
7947
0
      return;
7948
0
    }
7949
0
    break;
7950
0
  } while (false);
7951
0
7952
0
  JS::Rooted<JS::Value> callable(cx);
7953
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
7954
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
7955
0
      !GetCallableProperty(cx, atomsCache->mozInsertAudioLevelForContributingSource_id, &callable)) {
7956
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
7957
0
    return;
7958
0
  }
7959
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
7960
0
  if (!JS::Call(cx, thisValue, callable,
7961
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
7962
0
    aRv.NoteJSContextException(cx);
7963
0
    return;
7964
0
  }
7965
0
}
7966
7967
void
7968
RTCPeerConnectionJSImpl::MozAddRIDExtension(RTCRtpReceiver& receiver, uint16_t extensionId, ErrorResult& aRv, JS::Realm* aRealm)
7969
0
{
7970
0
  CallSetup s(this, aRv, "RTCPeerConnection.mozAddRIDExtension", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
7971
0
  JSContext* cx = s.GetContext();
7972
0
  if (!cx) {
7973
0
    MOZ_ASSERT(aRv.Failed());
7974
0
    return;
7975
0
  }
7976
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
7977
0
  JS::AutoValueVector argv(cx);
7978
0
  if (!argv.resize(2)) {
7979
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
7980
0
    return;
7981
0
  }
7982
0
  unsigned argc = 2;
7983
0
7984
0
  do {
7985
0
    argv[1].setInt32(int32_t(extensionId));
7986
0
    break;
7987
0
  } while (false);
7988
0
7989
0
  do {
7990
0
    if (!GetOrCreateDOMReflector(cx, receiver, argv[0])) {
7991
0
      MOZ_ASSERT(JS_IsExceptionPending(cx));
7992
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
7993
0
      return;
7994
0
    }
7995
0
    break;
7996
0
  } while (false);
7997
0
7998
0
  JS::Rooted<JS::Value> callable(cx);
7999
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
8000
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
8001
0
      !GetCallableProperty(cx, atomsCache->mozAddRIDExtension_id, &callable)) {
8002
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
8003
0
    return;
8004
0
  }
8005
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
8006
0
  if (!JS::Call(cx, thisValue, callable,
8007
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
8008
0
    aRv.NoteJSContextException(cx);
8009
0
    return;
8010
0
  }
8011
0
}
8012
8013
void
8014
RTCPeerConnectionJSImpl::MozAddRIDFilter(RTCRtpReceiver& receiver, const nsAString& rid, ErrorResult& aRv, JS::Realm* aRealm)
8015
0
{
8016
0
  CallSetup s(this, aRv, "RTCPeerConnection.mozAddRIDFilter", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
8017
0
  JSContext* cx = s.GetContext();
8018
0
  if (!cx) {
8019
0
    MOZ_ASSERT(aRv.Failed());
8020
0
    return;
8021
0
  }
8022
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
8023
0
  JS::AutoValueVector argv(cx);
8024
0
  if (!argv.resize(2)) {
8025
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
8026
0
    return;
8027
0
  }
8028
0
  unsigned argc = 2;
8029
0
8030
0
  do {
8031
0
    nsString mutableStr(rid);
8032
0
    if (!xpc::NonVoidStringToJsval(cx, mutableStr, argv[1])) {
8033
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
8034
0
      return;
8035
0
    }
8036
0
    break;
8037
0
  } while (false);
8038
0
8039
0
  do {
8040
0
    if (!GetOrCreateDOMReflector(cx, receiver, argv[0])) {
8041
0
      MOZ_ASSERT(JS_IsExceptionPending(cx));
8042
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
8043
0
      return;
8044
0
    }
8045
0
    break;
8046
0
  } while (false);
8047
0
8048
0
  JS::Rooted<JS::Value> callable(cx);
8049
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
8050
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
8051
0
      !GetCallableProperty(cx, atomsCache->mozAddRIDFilter_id, &callable)) {
8052
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
8053
0
    return;
8054
0
  }
8055
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
8056
0
  if (!JS::Call(cx, thisValue, callable,
8057
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
8058
0
    aRv.NoteJSContextException(cx);
8059
0
    return;
8060
0
  }
8061
0
}
8062
8063
void
8064
RTCPeerConnectionJSImpl::MozSetPacketCallback(mozPacketCallback& callback, ErrorResult& aRv, JS::Realm* aRealm)
8065
0
{
8066
0
  CallSetup s(this, aRv, "RTCPeerConnection.mozSetPacketCallback", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
8067
0
  JSContext* cx = s.GetContext();
8068
0
  if (!cx) {
8069
0
    MOZ_ASSERT(aRv.Failed());
8070
0
    return;
8071
0
  }
8072
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
8073
0
  JS::AutoValueVector argv(cx);
8074
0
  if (!argv.resize(1)) {
8075
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
8076
0
    return;
8077
0
  }
8078
0
  unsigned argc = 1;
8079
0
8080
0
  do {
8081
0
    argv[0].setObjectOrNull(GetCallbackFromCallbackObject(cx, callback));
8082
0
    if (!MaybeWrapObjectValue(cx, argv[0])) {
8083
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
8084
0
      return;
8085
0
    }
8086
0
    break;
8087
0
  } while (false);
8088
0
8089
0
  JS::Rooted<JS::Value> callable(cx);
8090
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
8091
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
8092
0
      !GetCallableProperty(cx, atomsCache->mozSetPacketCallback_id, &callable)) {
8093
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
8094
0
    return;
8095
0
  }
8096
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
8097
0
  if (!JS::Call(cx, thisValue, callable,
8098
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
8099
0
    aRv.NoteJSContextException(cx);
8100
0
    return;
8101
0
  }
8102
0
}
8103
8104
void
8105
RTCPeerConnectionJSImpl::MozEnablePacketDump(uint32_t level, mozPacketDumpType type, bool sending, ErrorResult& aRv, JS::Realm* aRealm)
8106
0
{
8107
0
  CallSetup s(this, aRv, "RTCPeerConnection.mozEnablePacketDump", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
8108
0
  JSContext* cx = s.GetContext();
8109
0
  if (!cx) {
8110
0
    MOZ_ASSERT(aRv.Failed());
8111
0
    return;
8112
0
  }
8113
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
8114
0
  JS::AutoValueVector argv(cx);
8115
0
  if (!argv.resize(3)) {
8116
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
8117
0
    return;
8118
0
  }
8119
0
  unsigned argc = 3;
8120
0
8121
0
  do {
8122
0
    argv[2].setBoolean(sending);
8123
0
    break;
8124
0
  } while (false);
8125
0
8126
0
  do {
8127
0
    if (!ToJSValue(cx, type, argv[1])) {
8128
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
8129
0
      return;
8130
0
    }
8131
0
    break;
8132
0
  } while (false);
8133
0
8134
0
  do {
8135
0
    argv[0].setNumber(level);
8136
0
    break;
8137
0
  } while (false);
8138
0
8139
0
  JS::Rooted<JS::Value> callable(cx);
8140
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
8141
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
8142
0
      !GetCallableProperty(cx, atomsCache->mozEnablePacketDump_id, &callable)) {
8143
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
8144
0
    return;
8145
0
  }
8146
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
8147
0
  if (!JS::Call(cx, thisValue, callable,
8148
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
8149
0
    aRv.NoteJSContextException(cx);
8150
0
    return;
8151
0
  }
8152
0
}
8153
8154
void
8155
RTCPeerConnectionJSImpl::MozDisablePacketDump(uint32_t level, mozPacketDumpType type, bool sending, ErrorResult& aRv, JS::Realm* aRealm)
8156
0
{
8157
0
  CallSetup s(this, aRv, "RTCPeerConnection.mozDisablePacketDump", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
8158
0
  JSContext* cx = s.GetContext();
8159
0
  if (!cx) {
8160
0
    MOZ_ASSERT(aRv.Failed());
8161
0
    return;
8162
0
  }
8163
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
8164
0
  JS::AutoValueVector argv(cx);
8165
0
  if (!argv.resize(3)) {
8166
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
8167
0
    return;
8168
0
  }
8169
0
  unsigned argc = 3;
8170
0
8171
0
  do {
8172
0
    argv[2].setBoolean(sending);
8173
0
    break;
8174
0
  } while (false);
8175
0
8176
0
  do {
8177
0
    if (!ToJSValue(cx, type, argv[1])) {
8178
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
8179
0
      return;
8180
0
    }
8181
0
    break;
8182
0
  } while (false);
8183
0
8184
0
  do {
8185
0
    argv[0].setNumber(level);
8186
0
    break;
8187
0
  } while (false);
8188
0
8189
0
  JS::Rooted<JS::Value> callable(cx);
8190
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
8191
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
8192
0
      !GetCallableProperty(cx, atomsCache->mozDisablePacketDump_id, &callable)) {
8193
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
8194
0
    return;
8195
0
  }
8196
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
8197
0
  if (!JS::Call(cx, thisValue, callable,
8198
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
8199
0
    aRv.NoteJSContextException(cx);
8200
0
    return;
8201
0
  }
8202
0
}
8203
8204
void
8205
RTCPeerConnectionJSImpl::Close(ErrorResult& aRv, JS::Realm* aRealm)
8206
0
{
8207
0
  CallSetup s(this, aRv, "RTCPeerConnection.close", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
8208
0
  JSContext* cx = s.GetContext();
8209
0
  if (!cx) {
8210
0
    MOZ_ASSERT(aRv.Failed());
8211
0
    return;
8212
0
  }
8213
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
8214
0
8215
0
  JS::Rooted<JS::Value> callable(cx);
8216
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
8217
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
8218
0
      !GetCallableProperty(cx, atomsCache->close_id, &callable)) {
8219
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
8220
0
    return;
8221
0
  }
8222
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
8223
0
  if (!JS::Call(cx, thisValue, callable,
8224
0
                JS::HandleValueArray::empty(), &rval)) {
8225
0
    aRv.NoteJSContextException(cx);
8226
0
    return;
8227
0
  }
8228
0
}
8229
8230
already_AddRefed<Promise>
8231
RTCPeerConnectionJSImpl::GetStats(const Optional<MediaStreamTrack*>& selector, ErrorResult& aRv, JS::Realm* aRealm)
8232
0
{
8233
0
  CallSetup s(this, aRv, "RTCPeerConnection.getStats", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
8234
0
  JSContext* cx = s.GetContext();
8235
0
  if (!cx) {
8236
0
    MOZ_ASSERT(aRv.Failed());
8237
0
    return nullptr;
8238
0
  }
8239
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
8240
0
  JS::AutoValueVector argv(cx);
8241
0
  if (!argv.resize(1)) {
8242
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
8243
0
    return nullptr;
8244
0
  }
8245
0
  unsigned argc = 1;
8246
0
8247
0
  do {
8248
0
    if (selector.WasPassed()) {
8249
0
      if (!selector.Value()) {
8250
0
        argv[0].setNull();
8251
0
        break;
8252
0
      }
8253
0
      if (!GetOrCreateDOMReflector(cx, selector.Value(), argv[0])) {
8254
0
        MOZ_ASSERT(JS_IsExceptionPending(cx));
8255
0
        aRv.Throw(NS_ERROR_UNEXPECTED);
8256
0
        return nullptr;
8257
0
      }
8258
0
      break;
8259
0
    } else if (argc == 1) {
8260
0
      // This is our current trailing argument; reduce argc
8261
0
      --argc;
8262
0
    } else {
8263
0
      argv[0].setUndefined();
8264
0
    }
8265
0
  } while (false);
8266
0
8267
0
  JS::Rooted<JS::Value> callable(cx);
8268
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
8269
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
8270
0
      !GetCallableProperty(cx, atomsCache->getStats_id, &callable)) {
8271
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
8272
0
    return nullptr;
8273
0
  }
8274
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
8275
0
  if (!JS::Call(cx, thisValue, callable,
8276
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
8277
0
    aRv.NoteJSContextException(cx);
8278
0
    return nullptr;
8279
0
  }
8280
0
  RefPtr<Promise> rvalDecl;
8281
0
  { // Scope for our GlobalObject, FastErrorResult, JSAutoRealm,
8282
0
    // etc.
8283
0
8284
0
    JS::Rooted<JSObject*> globalObj(cx);
8285
0
    if (!rval.isObject()) {
8286
0
      aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.getStats"));
8287
0
      return nullptr;
8288
0
    }
8289
0
    JSObject* unwrappedVal = js::CheckedUnwrap(&rval.toObject());
8290
0
    if (!unwrappedVal) {
8291
0
      // A slight lie, but not much of one, for a dead object wrapper.
8292
0
      aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.getStats"));
8293
0
      return nullptr;
8294
0
    }
8295
0
    globalObj = JS::GetNonCCWObjectGlobal(unwrappedVal);
8296
0
    JSAutoRealm ar(cx, globalObj);
8297
0
    GlobalObject promiseGlobal(cx, globalObj);
8298
0
    if (promiseGlobal.Failed()) {
8299
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
8300
0
      return nullptr;
8301
0
    }
8302
0
8303
0
    JS::Rooted<JS::Value> valueToResolve(cx, rval);
8304
0
    if (!JS_WrapValue(cx, &valueToResolve)) {
8305
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
8306
0
      return nullptr;
8307
0
    }
8308
0
    binding_detail::FastErrorResult promiseRv;
8309
0
    nsCOMPtr<nsIGlobalObject> global =
8310
0
      do_QueryInterface(promiseGlobal.GetAsSupports());
8311
0
    if (!global) {
8312
0
      promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED);
8313
0
      MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
8314
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
8315
0
      return nullptr;
8316
0
    }
8317
0
    rvalDecl = Promise::Resolve(global, cx, valueToResolve,
8318
0
                                    promiseRv);
8319
0
    if (promiseRv.MaybeSetPendingException(cx)) {
8320
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
8321
0
      return nullptr;
8322
0
    }
8323
0
  }
8324
0
  return rvalDecl.forget();
8325
0
}
8326
8327
already_AddRefed<Promise>
8328
RTCPeerConnectionJSImpl::GetStats(MediaStreamTrack* selector, RTCStatsCallback& successCallback, RTCPeerConnectionErrorCallback& failureCallback, ErrorResult& aRv, JS::Realm* aRealm)
8329
0
{
8330
0
  CallSetup s(this, aRv, "RTCPeerConnection.getStats", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
8331
0
  JSContext* cx = s.GetContext();
8332
0
  if (!cx) {
8333
0
    MOZ_ASSERT(aRv.Failed());
8334
0
    return nullptr;
8335
0
  }
8336
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
8337
0
  JS::AutoValueVector argv(cx);
8338
0
  if (!argv.resize(3)) {
8339
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
8340
0
    return nullptr;
8341
0
  }
8342
0
  unsigned argc = 3;
8343
0
8344
0
  do {
8345
0
    argv[2].setObjectOrNull(GetCallbackFromCallbackObject(cx, failureCallback));
8346
0
    if (!MaybeWrapObjectValue(cx, argv[2])) {
8347
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
8348
0
      return nullptr;
8349
0
    }
8350
0
    break;
8351
0
  } while (false);
8352
0
8353
0
  do {
8354
0
    argv[1].setObjectOrNull(GetCallbackFromCallbackObject(cx, successCallback));
8355
0
    if (!MaybeWrapObjectValue(cx, argv[1])) {
8356
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
8357
0
      return nullptr;
8358
0
    }
8359
0
    break;
8360
0
  } while (false);
8361
0
8362
0
  do {
8363
0
    if (!selector) {
8364
0
      argv[0].setNull();
8365
0
      break;
8366
0
    }
8367
0
    if (!GetOrCreateDOMReflector(cx, selector, argv[0])) {
8368
0
      MOZ_ASSERT(JS_IsExceptionPending(cx));
8369
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
8370
0
      return nullptr;
8371
0
    }
8372
0
    break;
8373
0
  } while (false);
8374
0
8375
0
  JS::Rooted<JS::Value> callable(cx);
8376
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
8377
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
8378
0
      !GetCallableProperty(cx, atomsCache->getStats_id, &callable)) {
8379
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
8380
0
    return nullptr;
8381
0
  }
8382
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
8383
0
  if (!JS::Call(cx, thisValue, callable,
8384
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
8385
0
    aRv.NoteJSContextException(cx);
8386
0
    return nullptr;
8387
0
  }
8388
0
  RefPtr<Promise> rvalDecl;
8389
0
  { // Scope for our GlobalObject, FastErrorResult, JSAutoRealm,
8390
0
    // etc.
8391
0
8392
0
    JS::Rooted<JSObject*> globalObj(cx);
8393
0
    if (!rval.isObject()) {
8394
0
      aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.getStats"));
8395
0
      return nullptr;
8396
0
    }
8397
0
    JSObject* unwrappedVal = js::CheckedUnwrap(&rval.toObject());
8398
0
    if (!unwrappedVal) {
8399
0
      // A slight lie, but not much of one, for a dead object wrapper.
8400
0
      aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.getStats"));
8401
0
      return nullptr;
8402
0
    }
8403
0
    globalObj = JS::GetNonCCWObjectGlobal(unwrappedVal);
8404
0
    JSAutoRealm ar(cx, globalObj);
8405
0
    GlobalObject promiseGlobal(cx, globalObj);
8406
0
    if (promiseGlobal.Failed()) {
8407
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
8408
0
      return nullptr;
8409
0
    }
8410
0
8411
0
    JS::Rooted<JS::Value> valueToResolve(cx, rval);
8412
0
    if (!JS_WrapValue(cx, &valueToResolve)) {
8413
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
8414
0
      return nullptr;
8415
0
    }
8416
0
    binding_detail::FastErrorResult promiseRv;
8417
0
    nsCOMPtr<nsIGlobalObject> global =
8418
0
      do_QueryInterface(promiseGlobal.GetAsSupports());
8419
0
    if (!global) {
8420
0
      promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED);
8421
0
      MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
8422
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
8423
0
      return nullptr;
8424
0
    }
8425
0
    rvalDecl = Promise::Resolve(global, cx, valueToResolve,
8426
0
                                    promiseRv);
8427
0
    if (promiseRv.MaybeSetPendingException(cx)) {
8428
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
8429
0
      return nullptr;
8430
0
    }
8431
0
  }
8432
0
  return rvalDecl.forget();
8433
0
}
8434
8435
already_AddRefed<nsDOMDataChannel>
8436
RTCPeerConnectionJSImpl::CreateDataChannel(const nsAString& label, const RTCDataChannelInit& dataChannelDict, ErrorResult& aRv, JS::Realm* aRealm)
8437
0
{
8438
0
  CallSetup s(this, aRv, "RTCPeerConnection.createDataChannel", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
8439
0
  JSContext* cx = s.GetContext();
8440
0
  if (!cx) {
8441
0
    MOZ_ASSERT(aRv.Failed());
8442
0
    return nullptr;
8443
0
  }
8444
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
8445
0
  JS::AutoValueVector argv(cx);
8446
0
  if (!argv.resize(2)) {
8447
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
8448
0
    return nullptr;
8449
0
  }
8450
0
  unsigned argc = 2;
8451
0
8452
0
  do {
8453
0
    if (!dataChannelDict.ToObjectInternal(cx, argv[1])) {
8454
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
8455
0
      return nullptr;
8456
0
    }
8457
0
    break;
8458
0
  } while (false);
8459
0
8460
0
  do {
8461
0
    nsString mutableStr(label);
8462
0
    if (!xpc::NonVoidStringToJsval(cx, mutableStr, argv[0])) {
8463
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
8464
0
      return nullptr;
8465
0
    }
8466
0
    break;
8467
0
  } while (false);
8468
0
8469
0
  JS::Rooted<JS::Value> callable(cx);
8470
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
8471
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
8472
0
      !GetCallableProperty(cx, atomsCache->createDataChannel_id, &callable)) {
8473
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
8474
0
    return nullptr;
8475
0
  }
8476
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
8477
0
  if (!JS::Call(cx, thisValue, callable,
8478
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
8479
0
    aRv.NoteJSContextException(cx);
8480
0
    return nullptr;
8481
0
  }
8482
0
  RefPtr<nsDOMDataChannel> rvalDecl;
8483
0
  if (rval.isObject()) {
8484
0
    static_assert(IsRefcounted<nsDOMDataChannel>::value, "We can only store refcounted classes.");{
8485
0
      nsresult rv = UnwrapObject<prototypes::id::RTCDataChannel, nsDOMDataChannel>(rval, rvalDecl);
8486
0
      if (NS_FAILED(rv)) {
8487
0
        ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Return value of RTCPeerConnection.createDataChannel", "RTCDataChannel");
8488
0
        aRv.Throw(NS_ERROR_UNEXPECTED);
8489
0
        return nullptr;
8490
0
      }
8491
0
    }
8492
0
  } else {
8493
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Return value of RTCPeerConnection.createDataChannel");
8494
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
8495
0
    return nullptr;
8496
0
  }
8497
0
  return rvalDecl.forget();
8498
0
}
8499
8500
void
8501
RTCPeerConnectionJSImpl::__Init(const RTCConfiguration& configuration, const Optional<JS::Handle<JSObject*>>& constraints, ErrorResult& aRv, JS::Realm* aRealm)
8502
0
{
8503
0
  CallSetup s(this, aRv, "__init", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
8504
0
  JSContext* cx = s.GetContext();
8505
0
  if (!cx) {
8506
0
    MOZ_ASSERT(aRv.Failed());
8507
0
    return;
8508
0
  }
8509
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
8510
0
  JS::AutoValueVector argv(cx);
8511
0
  if (!argv.resize(2)) {
8512
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
8513
0
    return;
8514
0
  }
8515
0
  unsigned argc = 2;
8516
0
8517
0
  do {
8518
0
    if (constraints.WasPassed()) {
8519
0
      if (constraints.Value()) {
8520
0
                    JS::ExposeObjectToActiveJS(constraints.Value());
8521
0
                  }
8522
0
                  argv[1].setObjectOrNull(constraints.Value());
8523
0
      if (!MaybeWrapObjectOrNullValue(cx, argv[1])) {
8524
0
        aRv.Throw(NS_ERROR_UNEXPECTED);
8525
0
        return;
8526
0
      }
8527
0
      break;
8528
0
    } else if (argc == 2) {
8529
0
      // This is our current trailing argument; reduce argc
8530
0
      --argc;
8531
0
    } else {
8532
0
      argv[1].setUndefined();
8533
0
    }
8534
0
  } while (false);
8535
0
8536
0
  do {
8537
0
    if (!configuration.ToObjectInternal(cx, argv[0])) {
8538
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
8539
0
      return;
8540
0
    }
8541
0
    break;
8542
0
  } while (false);
8543
0
8544
0
  JS::Rooted<JS::Value> callable(cx);
8545
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
8546
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
8547
0
      !GetCallableProperty(cx, atomsCache->__init_id, &callable)) {
8548
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
8549
0
    return;
8550
0
  }
8551
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
8552
0
  if (!JS::Call(cx, thisValue, callable,
8553
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
8554
0
    aRv.NoteJSContextException(cx);
8555
0
    return;
8556
0
  }
8557
0
}
8558
8559
bool
8560
RTCPeerConnectionJSImpl::InitIds(JSContext* cx, RTCPeerConnectionAtoms* atomsCache)
8561
0
{
8562
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
8563
0
8564
0
  // Initialize these in reverse order so that any failure leaves the first one
8565
0
  // uninitialized.
8566
0
  if (!atomsCache->__init_id.init(cx, "__init") ||
8567
0
      !atomsCache->ondatachannel_id.init(cx, "ondatachannel") ||
8568
0
      !atomsCache->createDataChannel_id.init(cx, "createDataChannel") ||
8569
0
      !atomsCache->getStats_id.init(cx, "getStats") ||
8570
0
      !atomsCache->onicegatheringstatechange_id.init(cx, "onicegatheringstatechange") ||
8571
0
      !atomsCache->oniceconnectionstatechange_id.init(cx, "oniceconnectionstatechange") ||
8572
0
      !atomsCache->onremovestream_id.init(cx, "onremovestream") ||
8573
0
      !atomsCache->ontrack_id.init(cx, "ontrack") ||
8574
0
      !atomsCache->onaddtrack_id.init(cx, "onaddtrack") ||
8575
0
      !atomsCache->onaddstream_id.init(cx, "onaddstream") ||
8576
0
      !atomsCache->onsignalingstatechange_id.init(cx, "onsignalingstatechange") ||
8577
0
      !atomsCache->onicecandidate_id.init(cx, "onicecandidate") ||
8578
0
      !atomsCache->onnegotiationneeded_id.init(cx, "onnegotiationneeded") ||
8579
0
      !atomsCache->close_id.init(cx, "close") ||
8580
0
      !atomsCache->mozDisablePacketDump_id.init(cx, "mozDisablePacketDump") ||
8581
0
      !atomsCache->mozEnablePacketDump_id.init(cx, "mozEnablePacketDump") ||
8582
0
      !atomsCache->mozSetPacketCallback_id.init(cx, "mozSetPacketCallback") ||
8583
0
      !atomsCache->mozAddRIDFilter_id.init(cx, "mozAddRIDFilter") ||
8584
0
      !atomsCache->mozAddRIDExtension_id.init(cx, "mozAddRIDExtension") ||
8585
0
      !atomsCache->mozInsertAudioLevelForContributingSource_id.init(cx, "mozInsertAudioLevelForContributingSource") ||
8586
0
      !atomsCache->mozGetNowInRtpSourceReferenceTime_id.init(cx, "mozGetNowInRtpSourceReferenceTime") ||
8587
0
      !atomsCache->getTransceivers_id.init(cx, "getTransceivers") ||
8588
0
      !atomsCache->getReceivers_id.init(cx, "getReceivers") ||
8589
0
      !atomsCache->getSenders_id.init(cx, "getSenders") ||
8590
0
      !atomsCache->addTransceiver_id.init(cx, "addTransceiver") ||
8591
0
      !atomsCache->removeTrack_id.init(cx, "removeTrack") ||
8592
0
      !atomsCache->addTrack_id.init(cx, "addTrack") ||
8593
0
      !atomsCache->addStream_id.init(cx, "addStream") ||
8594
0
      !atomsCache->getRemoteStreams_id.init(cx, "getRemoteStreams") ||
8595
0
      !atomsCache->getLocalStreams_id.init(cx, "getLocalStreams") ||
8596
0
      !atomsCache->getConfiguration_id.init(cx, "getConfiguration") ||
8597
0
      !atomsCache->id_id.init(cx, "id") ||
8598
0
      !atomsCache->idpLoginUrl_id.init(cx, "idpLoginUrl") ||
8599
0
      !atomsCache->peerIdentity_id.init(cx, "peerIdentity") ||
8600
0
      !atomsCache->iceConnectionState_id.init(cx, "iceConnectionState") ||
8601
0
      !atomsCache->iceGatheringState_id.init(cx, "iceGatheringState") ||
8602
0
      !atomsCache->canTrickleIceCandidates_id.init(cx, "canTrickleIceCandidates") ||
8603
0
      !atomsCache->addIceCandidate_id.init(cx, "addIceCandidate") ||
8604
0
      !atomsCache->signalingState_id.init(cx, "signalingState") ||
8605
0
      !atomsCache->pendingRemoteDescription_id.init(cx, "pendingRemoteDescription") ||
8606
0
      !atomsCache->currentRemoteDescription_id.init(cx, "currentRemoteDescription") ||
8607
0
      !atomsCache->remoteDescription_id.init(cx, "remoteDescription") ||
8608
0
      !atomsCache->pendingLocalDescription_id.init(cx, "pendingLocalDescription") ||
8609
0
      !atomsCache->currentLocalDescription_id.init(cx, "currentLocalDescription") ||
8610
0
      !atomsCache->localDescription_id.init(cx, "localDescription") ||
8611
0
      !atomsCache->setRemoteDescription_id.init(cx, "setRemoteDescription") ||
8612
0
      !atomsCache->setLocalDescription_id.init(cx, "setLocalDescription") ||
8613
0
      !atomsCache->createAnswer_id.init(cx, "createAnswer") ||
8614
0
      !atomsCache->createOffer_id.init(cx, "createOffer") ||
8615
0
      !atomsCache->getIdentityAssertion_id.init(cx, "getIdentityAssertion") ||
8616
0
      !atomsCache->setIdentityProvider_id.init(cx, "setIdentityProvider") ||
8617
0
      !atomsCache->generateCertificate_id.init(cx, "generateCertificate")) {
8618
0
    return false;
8619
0
  }
8620
0
  return true;
8621
0
}
8622
8623
8624
already_AddRefed<RTCSessionDescription>
8625
RTCPeerConnectionJSImpl::GetLocalDescription(ErrorResult& aRv, JS::Realm* aRealm)
8626
0
{
8627
0
  CallSetup s(this, aRv, "RTCPeerConnection.localDescription", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
8628
0
  JSContext* cx = s.GetContext();
8629
0
  if (!cx) {
8630
0
    MOZ_ASSERT(aRv.Failed());
8631
0
    return nullptr;
8632
0
  }
8633
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
8634
0
8635
0
  JS::Rooted<JSObject *> callback(cx, mCallback);
8636
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
8637
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
8638
0
      !JS_GetPropertyById(cx, callback, atomsCache->localDescription_id, &rval)) {
8639
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
8640
0
    return nullptr;
8641
0
  }
8642
0
  RefPtr<mozilla::dom::RTCSessionDescription> rvalDecl;
8643
0
  if (rval.isObject()) {
8644
0
    static_assert(IsRefcounted<mozilla::dom::RTCSessionDescription>::value, "We can only store refcounted classes.");{
8645
0
      nsresult rv = UnwrapObject<prototypes::id::RTCSessionDescription, mozilla::dom::RTCSessionDescription>(rval, rvalDecl);
8646
0
      if (NS_FAILED(rv)) {
8647
0
        // Be careful to not wrap random DOM objects here, even if
8648
0
        // they're wrapped in opaque security wrappers for some reason.
8649
0
        // XXXbz Wish we could check for a JS-implemented object
8650
0
        // that already has a content reflection...
8651
0
        if (!IsDOMObject(js::UncheckedUnwrap(&rval.toObject()))) {
8652
0
          nsCOMPtr<nsIGlobalObject> contentGlobal;
8653
0
          JS::Handle<JSObject*> callback = CallbackOrNull();
8654
0
          if (!callback ||
8655
0
              !GetContentGlobalForJSImplementedObject(cx, callback, getter_AddRefs(contentGlobal))) {
8656
0
            aRv.Throw(NS_ERROR_UNEXPECTED);
8657
0
            return nullptr;
8658
0
          }
8659
0
          JS::Rooted<JSObject*> jsImplSourceObj(cx, &rval.toObject());
8660
0
          MOZ_RELEASE_ASSERT(!js::IsWrapper(jsImplSourceObj),
8661
0
                             "Don't return JS implementations from other compartments");
8662
0
          JS::Rooted<JSObject*> jsImplSourceGlobal(cx, JS::GetNonCCWObjectGlobal(jsImplSourceObj));
8663
0
          rvalDecl = new mozilla::dom::RTCSessionDescription(jsImplSourceObj, jsImplSourceGlobal, contentGlobal);
8664
0
        } else {
8665
0
          ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Return value of RTCPeerConnection.localDescription", "RTCSessionDescription");
8666
0
          aRv.Throw(NS_ERROR_UNEXPECTED);
8667
0
          return nullptr;
8668
0
        }
8669
0
      }
8670
0
    }
8671
0
  } else if (rval.isNullOrUndefined()) {
8672
0
    rvalDecl = nullptr;
8673
0
  } else {
8674
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Return value of RTCPeerConnection.localDescription");
8675
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
8676
0
    return nullptr;
8677
0
  }
8678
0
  return rvalDecl.forget();
8679
0
}
8680
8681
already_AddRefed<RTCSessionDescription>
8682
RTCPeerConnectionJSImpl::GetCurrentLocalDescription(ErrorResult& aRv, JS::Realm* aRealm)
8683
0
{
8684
0
  CallSetup s(this, aRv, "RTCPeerConnection.currentLocalDescription", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
8685
0
  JSContext* cx = s.GetContext();
8686
0
  if (!cx) {
8687
0
    MOZ_ASSERT(aRv.Failed());
8688
0
    return nullptr;
8689
0
  }
8690
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
8691
0
8692
0
  JS::Rooted<JSObject *> callback(cx, mCallback);
8693
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
8694
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
8695
0
      !JS_GetPropertyById(cx, callback, atomsCache->currentLocalDescription_id, &rval)) {
8696
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
8697
0
    return nullptr;
8698
0
  }
8699
0
  RefPtr<mozilla::dom::RTCSessionDescription> rvalDecl;
8700
0
  if (rval.isObject()) {
8701
0
    static_assert(IsRefcounted<mozilla::dom::RTCSessionDescription>::value, "We can only store refcounted classes.");{
8702
0
      nsresult rv = UnwrapObject<prototypes::id::RTCSessionDescription, mozilla::dom::RTCSessionDescription>(rval, rvalDecl);
8703
0
      if (NS_FAILED(rv)) {
8704
0
        // Be careful to not wrap random DOM objects here, even if
8705
0
        // they're wrapped in opaque security wrappers for some reason.
8706
0
        // XXXbz Wish we could check for a JS-implemented object
8707
0
        // that already has a content reflection...
8708
0
        if (!IsDOMObject(js::UncheckedUnwrap(&rval.toObject()))) {
8709
0
          nsCOMPtr<nsIGlobalObject> contentGlobal;
8710
0
          JS::Handle<JSObject*> callback = CallbackOrNull();
8711
0
          if (!callback ||
8712
0
              !GetContentGlobalForJSImplementedObject(cx, callback, getter_AddRefs(contentGlobal))) {
8713
0
            aRv.Throw(NS_ERROR_UNEXPECTED);
8714
0
            return nullptr;
8715
0
          }
8716
0
          JS::Rooted<JSObject*> jsImplSourceObj(cx, &rval.toObject());
8717
0
          MOZ_RELEASE_ASSERT(!js::IsWrapper(jsImplSourceObj),
8718
0
                             "Don't return JS implementations from other compartments");
8719
0
          JS::Rooted<JSObject*> jsImplSourceGlobal(cx, JS::GetNonCCWObjectGlobal(jsImplSourceObj));
8720
0
          rvalDecl = new mozilla::dom::RTCSessionDescription(jsImplSourceObj, jsImplSourceGlobal, contentGlobal);
8721
0
        } else {
8722
0
          ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Return value of RTCPeerConnection.currentLocalDescription", "RTCSessionDescription");
8723
0
          aRv.Throw(NS_ERROR_UNEXPECTED);
8724
0
          return nullptr;
8725
0
        }
8726
0
      }
8727
0
    }
8728
0
  } else if (rval.isNullOrUndefined()) {
8729
0
    rvalDecl = nullptr;
8730
0
  } else {
8731
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Return value of RTCPeerConnection.currentLocalDescription");
8732
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
8733
0
    return nullptr;
8734
0
  }
8735
0
  return rvalDecl.forget();
8736
0
}
8737
8738
already_AddRefed<RTCSessionDescription>
8739
RTCPeerConnectionJSImpl::GetPendingLocalDescription(ErrorResult& aRv, JS::Realm* aRealm)
8740
0
{
8741
0
  CallSetup s(this, aRv, "RTCPeerConnection.pendingLocalDescription", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
8742
0
  JSContext* cx = s.GetContext();
8743
0
  if (!cx) {
8744
0
    MOZ_ASSERT(aRv.Failed());
8745
0
    return nullptr;
8746
0
  }
8747
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
8748
0
8749
0
  JS::Rooted<JSObject *> callback(cx, mCallback);
8750
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
8751
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
8752
0
      !JS_GetPropertyById(cx, callback, atomsCache->pendingLocalDescription_id, &rval)) {
8753
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
8754
0
    return nullptr;
8755
0
  }
8756
0
  RefPtr<mozilla::dom::RTCSessionDescription> rvalDecl;
8757
0
  if (rval.isObject()) {
8758
0
    static_assert(IsRefcounted<mozilla::dom::RTCSessionDescription>::value, "We can only store refcounted classes.");{
8759
0
      nsresult rv = UnwrapObject<prototypes::id::RTCSessionDescription, mozilla::dom::RTCSessionDescription>(rval, rvalDecl);
8760
0
      if (NS_FAILED(rv)) {
8761
0
        // Be careful to not wrap random DOM objects here, even if
8762
0
        // they're wrapped in opaque security wrappers for some reason.
8763
0
        // XXXbz Wish we could check for a JS-implemented object
8764
0
        // that already has a content reflection...
8765
0
        if (!IsDOMObject(js::UncheckedUnwrap(&rval.toObject()))) {
8766
0
          nsCOMPtr<nsIGlobalObject> contentGlobal;
8767
0
          JS::Handle<JSObject*> callback = CallbackOrNull();
8768
0
          if (!callback ||
8769
0
              !GetContentGlobalForJSImplementedObject(cx, callback, getter_AddRefs(contentGlobal))) {
8770
0
            aRv.Throw(NS_ERROR_UNEXPECTED);
8771
0
            return nullptr;
8772
0
          }
8773
0
          JS::Rooted<JSObject*> jsImplSourceObj(cx, &rval.toObject());
8774
0
          MOZ_RELEASE_ASSERT(!js::IsWrapper(jsImplSourceObj),
8775
0
                             "Don't return JS implementations from other compartments");
8776
0
          JS::Rooted<JSObject*> jsImplSourceGlobal(cx, JS::GetNonCCWObjectGlobal(jsImplSourceObj));
8777
0
          rvalDecl = new mozilla::dom::RTCSessionDescription(jsImplSourceObj, jsImplSourceGlobal, contentGlobal);
8778
0
        } else {
8779
0
          ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Return value of RTCPeerConnection.pendingLocalDescription", "RTCSessionDescription");
8780
0
          aRv.Throw(NS_ERROR_UNEXPECTED);
8781
0
          return nullptr;
8782
0
        }
8783
0
      }
8784
0
    }
8785
0
  } else if (rval.isNullOrUndefined()) {
8786
0
    rvalDecl = nullptr;
8787
0
  } else {
8788
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Return value of RTCPeerConnection.pendingLocalDescription");
8789
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
8790
0
    return nullptr;
8791
0
  }
8792
0
  return rvalDecl.forget();
8793
0
}
8794
8795
already_AddRefed<RTCSessionDescription>
8796
RTCPeerConnectionJSImpl::GetRemoteDescription(ErrorResult& aRv, JS::Realm* aRealm)
8797
0
{
8798
0
  CallSetup s(this, aRv, "RTCPeerConnection.remoteDescription", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
8799
0
  JSContext* cx = s.GetContext();
8800
0
  if (!cx) {
8801
0
    MOZ_ASSERT(aRv.Failed());
8802
0
    return nullptr;
8803
0
  }
8804
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
8805
0
8806
0
  JS::Rooted<JSObject *> callback(cx, mCallback);
8807
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
8808
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
8809
0
      !JS_GetPropertyById(cx, callback, atomsCache->remoteDescription_id, &rval)) {
8810
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
8811
0
    return nullptr;
8812
0
  }
8813
0
  RefPtr<mozilla::dom::RTCSessionDescription> rvalDecl;
8814
0
  if (rval.isObject()) {
8815
0
    static_assert(IsRefcounted<mozilla::dom::RTCSessionDescription>::value, "We can only store refcounted classes.");{
8816
0
      nsresult rv = UnwrapObject<prototypes::id::RTCSessionDescription, mozilla::dom::RTCSessionDescription>(rval, rvalDecl);
8817
0
      if (NS_FAILED(rv)) {
8818
0
        // Be careful to not wrap random DOM objects here, even if
8819
0
        // they're wrapped in opaque security wrappers for some reason.
8820
0
        // XXXbz Wish we could check for a JS-implemented object
8821
0
        // that already has a content reflection...
8822
0
        if (!IsDOMObject(js::UncheckedUnwrap(&rval.toObject()))) {
8823
0
          nsCOMPtr<nsIGlobalObject> contentGlobal;
8824
0
          JS::Handle<JSObject*> callback = CallbackOrNull();
8825
0
          if (!callback ||
8826
0
              !GetContentGlobalForJSImplementedObject(cx, callback, getter_AddRefs(contentGlobal))) {
8827
0
            aRv.Throw(NS_ERROR_UNEXPECTED);
8828
0
            return nullptr;
8829
0
          }
8830
0
          JS::Rooted<JSObject*> jsImplSourceObj(cx, &rval.toObject());
8831
0
          MOZ_RELEASE_ASSERT(!js::IsWrapper(jsImplSourceObj),
8832
0
                             "Don't return JS implementations from other compartments");
8833
0
          JS::Rooted<JSObject*> jsImplSourceGlobal(cx, JS::GetNonCCWObjectGlobal(jsImplSourceObj));
8834
0
          rvalDecl = new mozilla::dom::RTCSessionDescription(jsImplSourceObj, jsImplSourceGlobal, contentGlobal);
8835
0
        } else {
8836
0
          ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Return value of RTCPeerConnection.remoteDescription", "RTCSessionDescription");
8837
0
          aRv.Throw(NS_ERROR_UNEXPECTED);
8838
0
          return nullptr;
8839
0
        }
8840
0
      }
8841
0
    }
8842
0
  } else if (rval.isNullOrUndefined()) {
8843
0
    rvalDecl = nullptr;
8844
0
  } else {
8845
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Return value of RTCPeerConnection.remoteDescription");
8846
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
8847
0
    return nullptr;
8848
0
  }
8849
0
  return rvalDecl.forget();
8850
0
}
8851
8852
already_AddRefed<RTCSessionDescription>
8853
RTCPeerConnectionJSImpl::GetCurrentRemoteDescription(ErrorResult& aRv, JS::Realm* aRealm)
8854
0
{
8855
0
  CallSetup s(this, aRv, "RTCPeerConnection.currentRemoteDescription", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
8856
0
  JSContext* cx = s.GetContext();
8857
0
  if (!cx) {
8858
0
    MOZ_ASSERT(aRv.Failed());
8859
0
    return nullptr;
8860
0
  }
8861
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
8862
0
8863
0
  JS::Rooted<JSObject *> callback(cx, mCallback);
8864
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
8865
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
8866
0
      !JS_GetPropertyById(cx, callback, atomsCache->currentRemoteDescription_id, &rval)) {
8867
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
8868
0
    return nullptr;
8869
0
  }
8870
0
  RefPtr<mozilla::dom::RTCSessionDescription> rvalDecl;
8871
0
  if (rval.isObject()) {
8872
0
    static_assert(IsRefcounted<mozilla::dom::RTCSessionDescription>::value, "We can only store refcounted classes.");{
8873
0
      nsresult rv = UnwrapObject<prototypes::id::RTCSessionDescription, mozilla::dom::RTCSessionDescription>(rval, rvalDecl);
8874
0
      if (NS_FAILED(rv)) {
8875
0
        // Be careful to not wrap random DOM objects here, even if
8876
0
        // they're wrapped in opaque security wrappers for some reason.
8877
0
        // XXXbz Wish we could check for a JS-implemented object
8878
0
        // that already has a content reflection...
8879
0
        if (!IsDOMObject(js::UncheckedUnwrap(&rval.toObject()))) {
8880
0
          nsCOMPtr<nsIGlobalObject> contentGlobal;
8881
0
          JS::Handle<JSObject*> callback = CallbackOrNull();
8882
0
          if (!callback ||
8883
0
              !GetContentGlobalForJSImplementedObject(cx, callback, getter_AddRefs(contentGlobal))) {
8884
0
            aRv.Throw(NS_ERROR_UNEXPECTED);
8885
0
            return nullptr;
8886
0
          }
8887
0
          JS::Rooted<JSObject*> jsImplSourceObj(cx, &rval.toObject());
8888
0
          MOZ_RELEASE_ASSERT(!js::IsWrapper(jsImplSourceObj),
8889
0
                             "Don't return JS implementations from other compartments");
8890
0
          JS::Rooted<JSObject*> jsImplSourceGlobal(cx, JS::GetNonCCWObjectGlobal(jsImplSourceObj));
8891
0
          rvalDecl = new mozilla::dom::RTCSessionDescription(jsImplSourceObj, jsImplSourceGlobal, contentGlobal);
8892
0
        } else {
8893
0
          ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Return value of RTCPeerConnection.currentRemoteDescription", "RTCSessionDescription");
8894
0
          aRv.Throw(NS_ERROR_UNEXPECTED);
8895
0
          return nullptr;
8896
0
        }
8897
0
      }
8898
0
    }
8899
0
  } else if (rval.isNullOrUndefined()) {
8900
0
    rvalDecl = nullptr;
8901
0
  } else {
8902
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Return value of RTCPeerConnection.currentRemoteDescription");
8903
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
8904
0
    return nullptr;
8905
0
  }
8906
0
  return rvalDecl.forget();
8907
0
}
8908
8909
already_AddRefed<RTCSessionDescription>
8910
RTCPeerConnectionJSImpl::GetPendingRemoteDescription(ErrorResult& aRv, JS::Realm* aRealm)
8911
0
{
8912
0
  CallSetup s(this, aRv, "RTCPeerConnection.pendingRemoteDescription", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
8913
0
  JSContext* cx = s.GetContext();
8914
0
  if (!cx) {
8915
0
    MOZ_ASSERT(aRv.Failed());
8916
0
    return nullptr;
8917
0
  }
8918
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
8919
0
8920
0
  JS::Rooted<JSObject *> callback(cx, mCallback);
8921
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
8922
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
8923
0
      !JS_GetPropertyById(cx, callback, atomsCache->pendingRemoteDescription_id, &rval)) {
8924
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
8925
0
    return nullptr;
8926
0
  }
8927
0
  RefPtr<mozilla::dom::RTCSessionDescription> rvalDecl;
8928
0
  if (rval.isObject()) {
8929
0
    static_assert(IsRefcounted<mozilla::dom::RTCSessionDescription>::value, "We can only store refcounted classes.");{
8930
0
      nsresult rv = UnwrapObject<prototypes::id::RTCSessionDescription, mozilla::dom::RTCSessionDescription>(rval, rvalDecl);
8931
0
      if (NS_FAILED(rv)) {
8932
0
        // Be careful to not wrap random DOM objects here, even if
8933
0
        // they're wrapped in opaque security wrappers for some reason.
8934
0
        // XXXbz Wish we could check for a JS-implemented object
8935
0
        // that already has a content reflection...
8936
0
        if (!IsDOMObject(js::UncheckedUnwrap(&rval.toObject()))) {
8937
0
          nsCOMPtr<nsIGlobalObject> contentGlobal;
8938
0
          JS::Handle<JSObject*> callback = CallbackOrNull();
8939
0
          if (!callback ||
8940
0
              !GetContentGlobalForJSImplementedObject(cx, callback, getter_AddRefs(contentGlobal))) {
8941
0
            aRv.Throw(NS_ERROR_UNEXPECTED);
8942
0
            return nullptr;
8943
0
          }
8944
0
          JS::Rooted<JSObject*> jsImplSourceObj(cx, &rval.toObject());
8945
0
          MOZ_RELEASE_ASSERT(!js::IsWrapper(jsImplSourceObj),
8946
0
                             "Don't return JS implementations from other compartments");
8947
0
          JS::Rooted<JSObject*> jsImplSourceGlobal(cx, JS::GetNonCCWObjectGlobal(jsImplSourceObj));
8948
0
          rvalDecl = new mozilla::dom::RTCSessionDescription(jsImplSourceObj, jsImplSourceGlobal, contentGlobal);
8949
0
        } else {
8950
0
          ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Return value of RTCPeerConnection.pendingRemoteDescription", "RTCSessionDescription");
8951
0
          aRv.Throw(NS_ERROR_UNEXPECTED);
8952
0
          return nullptr;
8953
0
        }
8954
0
      }
8955
0
    }
8956
0
  } else if (rval.isNullOrUndefined()) {
8957
0
    rvalDecl = nullptr;
8958
0
  } else {
8959
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Return value of RTCPeerConnection.pendingRemoteDescription");
8960
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
8961
0
    return nullptr;
8962
0
  }
8963
0
  return rvalDecl.forget();
8964
0
}
8965
8966
RTCSignalingState
8967
RTCPeerConnectionJSImpl::GetSignalingState(ErrorResult& aRv, JS::Realm* aRealm)
8968
0
{
8969
0
  CallSetup s(this, aRv, "RTCPeerConnection.signalingState", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
8970
0
  JSContext* cx = s.GetContext();
8971
0
  if (!cx) {
8972
0
    MOZ_ASSERT(aRv.Failed());
8973
0
    return RTCSignalingState(0);
8974
0
  }
8975
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
8976
0
8977
0
  JS::Rooted<JSObject *> callback(cx, mCallback);
8978
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
8979
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
8980
0
      !JS_GetPropertyById(cx, callback, atomsCache->signalingState_id, &rval)) {
8981
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
8982
0
    return RTCSignalingState(0);
8983
0
  }
8984
0
  RTCSignalingState rvalDecl;
8985
0
  {
8986
0
    int index;
8987
0
    if (!FindEnumStringIndex<true>(cx, rval, RTCSignalingStateValues::strings, "RTCSignalingState", "Return value of RTCPeerConnection.signalingState", &index)) {
8988
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
8989
0
      return RTCSignalingState(0);
8990
0
    }
8991
0
    MOZ_ASSERT(index >= 0);
8992
0
    rvalDecl = static_cast<RTCSignalingState>(index);
8993
0
  }
8994
0
  return rvalDecl;
8995
0
}
8996
8997
Nullable<bool>
8998
RTCPeerConnectionJSImpl::GetCanTrickleIceCandidates(ErrorResult& aRv, JS::Realm* aRealm)
8999
0
{
9000
0
  CallSetup s(this, aRv, "RTCPeerConnection.canTrickleIceCandidates", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
9001
0
  JSContext* cx = s.GetContext();
9002
0
  if (!cx) {
9003
0
    MOZ_ASSERT(aRv.Failed());
9004
0
    return Nullable<bool>();
9005
0
  }
9006
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
9007
0
9008
0
  JS::Rooted<JSObject *> callback(cx, mCallback);
9009
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
9010
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
9011
0
      !JS_GetPropertyById(cx, callback, atomsCache->canTrickleIceCandidates_id, &rval)) {
9012
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
9013
0
    return Nullable<bool>();
9014
0
  }
9015
0
  Nullable<bool> rvalDecl;
9016
0
  if (rval.isNullOrUndefined()) {
9017
0
    rvalDecl.SetNull();
9018
0
  } else if (!ValueToPrimitive<bool, eDefault>(cx, rval, &rvalDecl.SetValue())) {
9019
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
9020
0
    return Nullable<bool>();
9021
0
  }
9022
0
  return rvalDecl;
9023
0
}
9024
9025
RTCIceGatheringState
9026
RTCPeerConnectionJSImpl::GetIceGatheringState(ErrorResult& aRv, JS::Realm* aRealm)
9027
0
{
9028
0
  CallSetup s(this, aRv, "RTCPeerConnection.iceGatheringState", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
9029
0
  JSContext* cx = s.GetContext();
9030
0
  if (!cx) {
9031
0
    MOZ_ASSERT(aRv.Failed());
9032
0
    return RTCIceGatheringState(0);
9033
0
  }
9034
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
9035
0
9036
0
  JS::Rooted<JSObject *> callback(cx, mCallback);
9037
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
9038
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
9039
0
      !JS_GetPropertyById(cx, callback, atomsCache->iceGatheringState_id, &rval)) {
9040
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
9041
0
    return RTCIceGatheringState(0);
9042
0
  }
9043
0
  RTCIceGatheringState rvalDecl;
9044
0
  {
9045
0
    int index;
9046
0
    if (!FindEnumStringIndex<true>(cx, rval, RTCIceGatheringStateValues::strings, "RTCIceGatheringState", "Return value of RTCPeerConnection.iceGatheringState", &index)) {
9047
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
9048
0
      return RTCIceGatheringState(0);
9049
0
    }
9050
0
    MOZ_ASSERT(index >= 0);
9051
0
    rvalDecl = static_cast<RTCIceGatheringState>(index);
9052
0
  }
9053
0
  return rvalDecl;
9054
0
}
9055
9056
RTCIceConnectionState
9057
RTCPeerConnectionJSImpl::GetIceConnectionState(ErrorResult& aRv, JS::Realm* aRealm)
9058
0
{
9059
0
  CallSetup s(this, aRv, "RTCPeerConnection.iceConnectionState", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
9060
0
  JSContext* cx = s.GetContext();
9061
0
  if (!cx) {
9062
0
    MOZ_ASSERT(aRv.Failed());
9063
0
    return RTCIceConnectionState(0);
9064
0
  }
9065
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
9066
0
9067
0
  JS::Rooted<JSObject *> callback(cx, mCallback);
9068
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
9069
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
9070
0
      !JS_GetPropertyById(cx, callback, atomsCache->iceConnectionState_id, &rval)) {
9071
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
9072
0
    return RTCIceConnectionState(0);
9073
0
  }
9074
0
  RTCIceConnectionState rvalDecl;
9075
0
  {
9076
0
    int index;
9077
0
    if (!FindEnumStringIndex<true>(cx, rval, RTCIceConnectionStateValues::strings, "RTCIceConnectionState", "Return value of RTCPeerConnection.iceConnectionState", &index)) {
9078
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
9079
0
      return RTCIceConnectionState(0);
9080
0
    }
9081
0
    MOZ_ASSERT(index >= 0);
9082
0
    rvalDecl = static_cast<RTCIceConnectionState>(index);
9083
0
  }
9084
0
  return rvalDecl;
9085
0
}
9086
9087
already_AddRefed<Promise>
9088
RTCPeerConnectionJSImpl::GetPeerIdentity(ErrorResult& aRv, JS::Realm* aRealm)
9089
0
{
9090
0
  CallSetup s(this, aRv, "RTCPeerConnection.peerIdentity", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
9091
0
  JSContext* cx = s.GetContext();
9092
0
  if (!cx) {
9093
0
    MOZ_ASSERT(aRv.Failed());
9094
0
    return nullptr;
9095
0
  }
9096
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
9097
0
9098
0
  JS::Rooted<JSObject *> callback(cx, mCallback);
9099
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
9100
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
9101
0
      !JS_GetPropertyById(cx, callback, atomsCache->peerIdentity_id, &rval)) {
9102
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
9103
0
    return nullptr;
9104
0
  }
9105
0
  RefPtr<Promise> rvalDecl;
9106
0
  { // Scope for our GlobalObject, FastErrorResult, JSAutoRealm,
9107
0
    // etc.
9108
0
9109
0
    JS::Rooted<JSObject*> globalObj(cx);
9110
0
    if (!rval.isObject()) {
9111
0
      aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.peerIdentity"));
9112
0
      return nullptr;
9113
0
    }
9114
0
    JSObject* unwrappedVal = js::CheckedUnwrap(&rval.toObject());
9115
0
    if (!unwrappedVal) {
9116
0
      // A slight lie, but not much of one, for a dead object wrapper.
9117
0
      aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of RTCPeerConnection.peerIdentity"));
9118
0
      return nullptr;
9119
0
    }
9120
0
    globalObj = JS::GetNonCCWObjectGlobal(unwrappedVal);
9121
0
    JSAutoRealm ar(cx, globalObj);
9122
0
    GlobalObject promiseGlobal(cx, globalObj);
9123
0
    if (promiseGlobal.Failed()) {
9124
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
9125
0
      return nullptr;
9126
0
    }
9127
0
9128
0
    JS::Rooted<JS::Value> valueToResolve(cx, rval);
9129
0
    if (!JS_WrapValue(cx, &valueToResolve)) {
9130
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
9131
0
      return nullptr;
9132
0
    }
9133
0
    binding_detail::FastErrorResult promiseRv;
9134
0
    nsCOMPtr<nsIGlobalObject> global =
9135
0
      do_QueryInterface(promiseGlobal.GetAsSupports());
9136
0
    if (!global) {
9137
0
      promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED);
9138
0
      MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
9139
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
9140
0
      return nullptr;
9141
0
    }
9142
0
    rvalDecl = Promise::Resolve(global, cx, valueToResolve,
9143
0
                                    promiseRv);
9144
0
    if (promiseRv.MaybeSetPendingException(cx)) {
9145
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
9146
0
      return nullptr;
9147
0
    }
9148
0
  }
9149
0
  return rvalDecl.forget();
9150
0
}
9151
9152
void
9153
RTCPeerConnectionJSImpl::GetIdpLoginUrl(nsString& aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
9154
0
{
9155
0
  CallSetup s(this, aRv, "RTCPeerConnection.idpLoginUrl", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
9156
0
  JSContext* cx = s.GetContext();
9157
0
  if (!cx) {
9158
0
    MOZ_ASSERT(aRv.Failed());
9159
0
    return;
9160
0
  }
9161
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
9162
0
9163
0
  JS::Rooted<JSObject *> callback(cx, mCallback);
9164
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
9165
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
9166
0
      !JS_GetPropertyById(cx, callback, atomsCache->idpLoginUrl_id, &rval)) {
9167
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
9168
0
    return;
9169
0
  }
9170
0
  binding_detail::FakeString rvalDecl;
9171
0
  if (!ConvertJSValueToString(cx, rval, eNull, eNull, rvalDecl)) {
9172
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
9173
0
    return;
9174
0
  }
9175
0
  aRetVal = rvalDecl;
9176
0
}
9177
9178
void
9179
RTCPeerConnectionJSImpl::GetId(nsString& aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
9180
0
{
9181
0
  CallSetup s(this, aRv, "RTCPeerConnection.id", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
9182
0
  JSContext* cx = s.GetContext();
9183
0
  if (!cx) {
9184
0
    MOZ_ASSERT(aRv.Failed());
9185
0
    return;
9186
0
  }
9187
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
9188
0
9189
0
  JS::Rooted<JSObject *> callback(cx, mCallback);
9190
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
9191
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
9192
0
      !JS_GetPropertyById(cx, callback, atomsCache->id_id, &rval)) {
9193
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
9194
0
    return;
9195
0
  }
9196
0
  binding_detail::FakeString rvalDecl;
9197
0
  if (!ConvertJSValueToString(cx, rval, eStringify, eStringify, rvalDecl)) {
9198
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
9199
0
    return;
9200
0
  }
9201
0
  aRetVal = rvalDecl;
9202
0
}
9203
9204
already_AddRefed<EventHandlerNonNull>
9205
RTCPeerConnectionJSImpl::GetOnnegotiationneeded(ErrorResult& aRv, JS::Realm* aRealm)
9206
0
{
9207
0
  CallSetup s(this, aRv, "RTCPeerConnection.onnegotiationneeded", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
9208
0
  JSContext* cx = s.GetContext();
9209
0
  if (!cx) {
9210
0
    MOZ_ASSERT(aRv.Failed());
9211
0
    return nullptr;
9212
0
  }
9213
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
9214
0
9215
0
  JS::Rooted<JSObject *> callback(cx, mCallback);
9216
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
9217
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
9218
0
      !JS_GetPropertyById(cx, callback, atomsCache->onnegotiationneeded_id, &rval)) {
9219
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
9220
0
    return nullptr;
9221
0
  }
9222
0
  RefPtr<EventHandlerNonNull> rvalDecl;
9223
0
  if (rval.isObject()) {
9224
0
    { // scope for tempRoot and tempGlobalRoot if needed
9225
0
      JS::Rooted<JSObject*> tempRoot(cx, &rval.toObject());
9226
0
      JS::Rooted<JSObject*> tempGlobalRoot(cx, JS::CurrentGlobalOrNull(cx));
9227
0
      rvalDecl = new EventHandlerNonNull(cx, tempRoot, tempGlobalRoot, GetIncumbentGlobal());
9228
0
    }
9229
0
  } else {
9230
0
    rvalDecl = nullptr;
9231
0
  }
9232
0
  return rvalDecl.forget();
9233
0
}
9234
9235
already_AddRefed<EventHandlerNonNull>
9236
RTCPeerConnectionJSImpl::GetOnicecandidate(ErrorResult& aRv, JS::Realm* aRealm)
9237
0
{
9238
0
  CallSetup s(this, aRv, "RTCPeerConnection.onicecandidate", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
9239
0
  JSContext* cx = s.GetContext();
9240
0
  if (!cx) {
9241
0
    MOZ_ASSERT(aRv.Failed());
9242
0
    return nullptr;
9243
0
  }
9244
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
9245
0
9246
0
  JS::Rooted<JSObject *> callback(cx, mCallback);
9247
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
9248
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
9249
0
      !JS_GetPropertyById(cx, callback, atomsCache->onicecandidate_id, &rval)) {
9250
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
9251
0
    return nullptr;
9252
0
  }
9253
0
  RefPtr<EventHandlerNonNull> rvalDecl;
9254
0
  if (rval.isObject()) {
9255
0
    { // scope for tempRoot and tempGlobalRoot if needed
9256
0
      JS::Rooted<JSObject*> tempRoot(cx, &rval.toObject());
9257
0
      JS::Rooted<JSObject*> tempGlobalRoot(cx, JS::CurrentGlobalOrNull(cx));
9258
0
      rvalDecl = new EventHandlerNonNull(cx, tempRoot, tempGlobalRoot, GetIncumbentGlobal());
9259
0
    }
9260
0
  } else {
9261
0
    rvalDecl = nullptr;
9262
0
  }
9263
0
  return rvalDecl.forget();
9264
0
}
9265
9266
already_AddRefed<EventHandlerNonNull>
9267
RTCPeerConnectionJSImpl::GetOnsignalingstatechange(ErrorResult& aRv, JS::Realm* aRealm)
9268
0
{
9269
0
  CallSetup s(this, aRv, "RTCPeerConnection.onsignalingstatechange", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
9270
0
  JSContext* cx = s.GetContext();
9271
0
  if (!cx) {
9272
0
    MOZ_ASSERT(aRv.Failed());
9273
0
    return nullptr;
9274
0
  }
9275
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
9276
0
9277
0
  JS::Rooted<JSObject *> callback(cx, mCallback);
9278
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
9279
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
9280
0
      !JS_GetPropertyById(cx, callback, atomsCache->onsignalingstatechange_id, &rval)) {
9281
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
9282
0
    return nullptr;
9283
0
  }
9284
0
  RefPtr<EventHandlerNonNull> rvalDecl;
9285
0
  if (rval.isObject()) {
9286
0
    { // scope for tempRoot and tempGlobalRoot if needed
9287
0
      JS::Rooted<JSObject*> tempRoot(cx, &rval.toObject());
9288
0
      JS::Rooted<JSObject*> tempGlobalRoot(cx, JS::CurrentGlobalOrNull(cx));
9289
0
      rvalDecl = new EventHandlerNonNull(cx, tempRoot, tempGlobalRoot, GetIncumbentGlobal());
9290
0
    }
9291
0
  } else {
9292
0
    rvalDecl = nullptr;
9293
0
  }
9294
0
  return rvalDecl.forget();
9295
0
}
9296
9297
already_AddRefed<EventHandlerNonNull>
9298
RTCPeerConnectionJSImpl::GetOnaddstream(ErrorResult& aRv, JS::Realm* aRealm)
9299
0
{
9300
0
  CallSetup s(this, aRv, "RTCPeerConnection.onaddstream", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
9301
0
  JSContext* cx = s.GetContext();
9302
0
  if (!cx) {
9303
0
    MOZ_ASSERT(aRv.Failed());
9304
0
    return nullptr;
9305
0
  }
9306
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
9307
0
9308
0
  JS::Rooted<JSObject *> callback(cx, mCallback);
9309
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
9310
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
9311
0
      !JS_GetPropertyById(cx, callback, atomsCache->onaddstream_id, &rval)) {
9312
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
9313
0
    return nullptr;
9314
0
  }
9315
0
  RefPtr<EventHandlerNonNull> rvalDecl;
9316
0
  if (rval.isObject()) {
9317
0
    { // scope for tempRoot and tempGlobalRoot if needed
9318
0
      JS::Rooted<JSObject*> tempRoot(cx, &rval.toObject());
9319
0
      JS::Rooted<JSObject*> tempGlobalRoot(cx, JS::CurrentGlobalOrNull(cx));
9320
0
      rvalDecl = new EventHandlerNonNull(cx, tempRoot, tempGlobalRoot, GetIncumbentGlobal());
9321
0
    }
9322
0
  } else {
9323
0
    rvalDecl = nullptr;
9324
0
  }
9325
0
  return rvalDecl.forget();
9326
0
}
9327
9328
already_AddRefed<EventHandlerNonNull>
9329
RTCPeerConnectionJSImpl::GetOnaddtrack(ErrorResult& aRv, JS::Realm* aRealm)
9330
0
{
9331
0
  CallSetup s(this, aRv, "RTCPeerConnection.onaddtrack", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
9332
0
  JSContext* cx = s.GetContext();
9333
0
  if (!cx) {
9334
0
    MOZ_ASSERT(aRv.Failed());
9335
0
    return nullptr;
9336
0
  }
9337
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
9338
0
9339
0
  JS::Rooted<JSObject *> callback(cx, mCallback);
9340
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
9341
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
9342
0
      !JS_GetPropertyById(cx, callback, atomsCache->onaddtrack_id, &rval)) {
9343
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
9344
0
    return nullptr;
9345
0
  }
9346
0
  RefPtr<EventHandlerNonNull> rvalDecl;
9347
0
  if (rval.isObject()) {
9348
0
    { // scope for tempRoot and tempGlobalRoot if needed
9349
0
      JS::Rooted<JSObject*> tempRoot(cx, &rval.toObject());
9350
0
      JS::Rooted<JSObject*> tempGlobalRoot(cx, JS::CurrentGlobalOrNull(cx));
9351
0
      rvalDecl = new EventHandlerNonNull(cx, tempRoot, tempGlobalRoot, GetIncumbentGlobal());
9352
0
    }
9353
0
  } else {
9354
0
    rvalDecl = nullptr;
9355
0
  }
9356
0
  return rvalDecl.forget();
9357
0
}
9358
9359
already_AddRefed<EventHandlerNonNull>
9360
RTCPeerConnectionJSImpl::GetOntrack(ErrorResult& aRv, JS::Realm* aRealm)
9361
0
{
9362
0
  CallSetup s(this, aRv, "RTCPeerConnection.ontrack", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
9363
0
  JSContext* cx = s.GetContext();
9364
0
  if (!cx) {
9365
0
    MOZ_ASSERT(aRv.Failed());
9366
0
    return nullptr;
9367
0
  }
9368
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
9369
0
9370
0
  JS::Rooted<JSObject *> callback(cx, mCallback);
9371
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
9372
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
9373
0
      !JS_GetPropertyById(cx, callback, atomsCache->ontrack_id, &rval)) {
9374
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
9375
0
    return nullptr;
9376
0
  }
9377
0
  RefPtr<EventHandlerNonNull> rvalDecl;
9378
0
  if (rval.isObject()) {
9379
0
    { // scope for tempRoot and tempGlobalRoot if needed
9380
0
      JS::Rooted<JSObject*> tempRoot(cx, &rval.toObject());
9381
0
      JS::Rooted<JSObject*> tempGlobalRoot(cx, JS::CurrentGlobalOrNull(cx));
9382
0
      rvalDecl = new EventHandlerNonNull(cx, tempRoot, tempGlobalRoot, GetIncumbentGlobal());
9383
0
    }
9384
0
  } else {
9385
0
    rvalDecl = nullptr;
9386
0
  }
9387
0
  return rvalDecl.forget();
9388
0
}
9389
9390
already_AddRefed<EventHandlerNonNull>
9391
RTCPeerConnectionJSImpl::GetOnremovestream(ErrorResult& aRv, JS::Realm* aRealm)
9392
0
{
9393
0
  CallSetup s(this, aRv, "RTCPeerConnection.onremovestream", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
9394
0
  JSContext* cx = s.GetContext();
9395
0
  if (!cx) {
9396
0
    MOZ_ASSERT(aRv.Failed());
9397
0
    return nullptr;
9398
0
  }
9399
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
9400
0
9401
0
  JS::Rooted<JSObject *> callback(cx, mCallback);
9402
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
9403
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
9404
0
      !JS_GetPropertyById(cx, callback, atomsCache->onremovestream_id, &rval)) {
9405
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
9406
0
    return nullptr;
9407
0
  }
9408
0
  RefPtr<EventHandlerNonNull> rvalDecl;
9409
0
  if (rval.isObject()) {
9410
0
    { // scope for tempRoot and tempGlobalRoot if needed
9411
0
      JS::Rooted<JSObject*> tempRoot(cx, &rval.toObject());
9412
0
      JS::Rooted<JSObject*> tempGlobalRoot(cx, JS::CurrentGlobalOrNull(cx));
9413
0
      rvalDecl = new EventHandlerNonNull(cx, tempRoot, tempGlobalRoot, GetIncumbentGlobal());
9414
0
    }
9415
0
  } else {
9416
0
    rvalDecl = nullptr;
9417
0
  }
9418
0
  return rvalDecl.forget();
9419
0
}
9420
9421
already_AddRefed<EventHandlerNonNull>
9422
RTCPeerConnectionJSImpl::GetOniceconnectionstatechange(ErrorResult& aRv, JS::Realm* aRealm)
9423
0
{
9424
0
  CallSetup s(this, aRv, "RTCPeerConnection.oniceconnectionstatechange", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
9425
0
  JSContext* cx = s.GetContext();
9426
0
  if (!cx) {
9427
0
    MOZ_ASSERT(aRv.Failed());
9428
0
    return nullptr;
9429
0
  }
9430
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
9431
0
9432
0
  JS::Rooted<JSObject *> callback(cx, mCallback);
9433
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
9434
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
9435
0
      !JS_GetPropertyById(cx, callback, atomsCache->oniceconnectionstatechange_id, &rval)) {
9436
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
9437
0
    return nullptr;
9438
0
  }
9439
0
  RefPtr<EventHandlerNonNull> rvalDecl;
9440
0
  if (rval.isObject()) {
9441
0
    { // scope for tempRoot and tempGlobalRoot if needed
9442
0
      JS::Rooted<JSObject*> tempRoot(cx, &rval.toObject());
9443
0
      JS::Rooted<JSObject*> tempGlobalRoot(cx, JS::CurrentGlobalOrNull(cx));
9444
0
      rvalDecl = new EventHandlerNonNull(cx, tempRoot, tempGlobalRoot, GetIncumbentGlobal());
9445
0
    }
9446
0
  } else {
9447
0
    rvalDecl = nullptr;
9448
0
  }
9449
0
  return rvalDecl.forget();
9450
0
}
9451
9452
already_AddRefed<EventHandlerNonNull>
9453
RTCPeerConnectionJSImpl::GetOnicegatheringstatechange(ErrorResult& aRv, JS::Realm* aRealm)
9454
0
{
9455
0
  CallSetup s(this, aRv, "RTCPeerConnection.onicegatheringstatechange", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
9456
0
  JSContext* cx = s.GetContext();
9457
0
  if (!cx) {
9458
0
    MOZ_ASSERT(aRv.Failed());
9459
0
    return nullptr;
9460
0
  }
9461
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
9462
0
9463
0
  JS::Rooted<JSObject *> callback(cx, mCallback);
9464
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
9465
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
9466
0
      !JS_GetPropertyById(cx, callback, atomsCache->onicegatheringstatechange_id, &rval)) {
9467
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
9468
0
    return nullptr;
9469
0
  }
9470
0
  RefPtr<EventHandlerNonNull> rvalDecl;
9471
0
  if (rval.isObject()) {
9472
0
    { // scope for tempRoot and tempGlobalRoot if needed
9473
0
      JS::Rooted<JSObject*> tempRoot(cx, &rval.toObject());
9474
0
      JS::Rooted<JSObject*> tempGlobalRoot(cx, JS::CurrentGlobalOrNull(cx));
9475
0
      rvalDecl = new EventHandlerNonNull(cx, tempRoot, tempGlobalRoot, GetIncumbentGlobal());
9476
0
    }
9477
0
  } else {
9478
0
    rvalDecl = nullptr;
9479
0
  }
9480
0
  return rvalDecl.forget();
9481
0
}
9482
9483
already_AddRefed<EventHandlerNonNull>
9484
RTCPeerConnectionJSImpl::GetOndatachannel(ErrorResult& aRv, JS::Realm* aRealm)
9485
0
{
9486
0
  CallSetup s(this, aRv, "RTCPeerConnection.ondatachannel", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
9487
0
  JSContext* cx = s.GetContext();
9488
0
  if (!cx) {
9489
0
    MOZ_ASSERT(aRv.Failed());
9490
0
    return nullptr;
9491
0
  }
9492
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
9493
0
9494
0
  JS::Rooted<JSObject *> callback(cx, mCallback);
9495
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
9496
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
9497
0
      !JS_GetPropertyById(cx, callback, atomsCache->ondatachannel_id, &rval)) {
9498
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
9499
0
    return nullptr;
9500
0
  }
9501
0
  RefPtr<EventHandlerNonNull> rvalDecl;
9502
0
  if (rval.isObject()) {
9503
0
    { // scope for tempRoot and tempGlobalRoot if needed
9504
0
      JS::Rooted<JSObject*> tempRoot(cx, &rval.toObject());
9505
0
      JS::Rooted<JSObject*> tempGlobalRoot(cx, JS::CurrentGlobalOrNull(cx));
9506
0
      rvalDecl = new EventHandlerNonNull(cx, tempRoot, tempGlobalRoot, GetIncumbentGlobal());
9507
0
    }
9508
0
  } else {
9509
0
    rvalDecl = nullptr;
9510
0
  }
9511
0
  return rvalDecl.forget();
9512
0
}
9513
9514
void
9515
RTCPeerConnectionJSImpl::SetId(const nsAString& arg, ErrorResult& aRv, JS::Realm* aRealm)
9516
0
{
9517
0
  CallSetup s(this, aRv, "RTCPeerConnection.id", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
9518
0
  JSContext* cx = s.GetContext();
9519
0
  if (!cx) {
9520
0
    MOZ_ASSERT(aRv.Failed());
9521
0
    return;
9522
0
  }
9523
0
  JS::AutoValueVector argv(cx);
9524
0
  if (!argv.resize(1)) {
9525
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
9526
0
    return;
9527
0
  }
9528
0
  do {
9529
0
    nsString mutableStr(arg);
9530
0
    if (!xpc::NonVoidStringToJsval(cx, mutableStr, argv[0])) {
9531
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
9532
0
      return;
9533
0
    }
9534
0
    break;
9535
0
  } while (false);
9536
0
9537
0
  MOZ_ASSERT(argv.length() == 1);
9538
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
9539
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
9540
0
      !JS_SetPropertyById(cx, CallbackKnownNotGray(), atomsCache->id_id, argv[0])) {
9541
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
9542
0
    return;
9543
0
  }
9544
0
}
9545
9546
void
9547
RTCPeerConnectionJSImpl::SetOnnegotiationneeded(EventHandlerNonNull* arg, ErrorResult& aRv, JS::Realm* aRealm)
9548
0
{
9549
0
  CallSetup s(this, aRv, "RTCPeerConnection.onnegotiationneeded", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
9550
0
  JSContext* cx = s.GetContext();
9551
0
  if (!cx) {
9552
0
    MOZ_ASSERT(aRv.Failed());
9553
0
    return;
9554
0
  }
9555
0
  JS::AutoValueVector argv(cx);
9556
0
  if (!argv.resize(1)) {
9557
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
9558
0
    return;
9559
0
  }
9560
0
  do {
9561
0
    if (arg) {
9562
0
      argv[0].setObjectOrNull(GetCallbackFromCallbackObject(cx, arg));
9563
0
      if (!MaybeWrapObjectOrNullValue(cx, argv[0])) {
9564
0
        aRv.Throw(NS_ERROR_UNEXPECTED);
9565
0
        return;
9566
0
      }
9567
0
      break;
9568
0
    } else {
9569
0
      argv[0].setNull();
9570
0
      break;
9571
0
    }
9572
0
  } while (false);
9573
0
9574
0
  MOZ_ASSERT(argv.length() == 1);
9575
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
9576
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
9577
0
      !JS_SetPropertyById(cx, CallbackKnownNotGray(), atomsCache->onnegotiationneeded_id, argv[0])) {
9578
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
9579
0
    return;
9580
0
  }
9581
0
}
9582
9583
void
9584
RTCPeerConnectionJSImpl::SetOnicecandidate(EventHandlerNonNull* arg, ErrorResult& aRv, JS::Realm* aRealm)
9585
0
{
9586
0
  CallSetup s(this, aRv, "RTCPeerConnection.onicecandidate", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
9587
0
  JSContext* cx = s.GetContext();
9588
0
  if (!cx) {
9589
0
    MOZ_ASSERT(aRv.Failed());
9590
0
    return;
9591
0
  }
9592
0
  JS::AutoValueVector argv(cx);
9593
0
  if (!argv.resize(1)) {
9594
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
9595
0
    return;
9596
0
  }
9597
0
  do {
9598
0
    if (arg) {
9599
0
      argv[0].setObjectOrNull(GetCallbackFromCallbackObject(cx, arg));
9600
0
      if (!MaybeWrapObjectOrNullValue(cx, argv[0])) {
9601
0
        aRv.Throw(NS_ERROR_UNEXPECTED);
9602
0
        return;
9603
0
      }
9604
0
      break;
9605
0
    } else {
9606
0
      argv[0].setNull();
9607
0
      break;
9608
0
    }
9609
0
  } while (false);
9610
0
9611
0
  MOZ_ASSERT(argv.length() == 1);
9612
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
9613
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
9614
0
      !JS_SetPropertyById(cx, CallbackKnownNotGray(), atomsCache->onicecandidate_id, argv[0])) {
9615
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
9616
0
    return;
9617
0
  }
9618
0
}
9619
9620
void
9621
RTCPeerConnectionJSImpl::SetOnsignalingstatechange(EventHandlerNonNull* arg, ErrorResult& aRv, JS::Realm* aRealm)
9622
0
{
9623
0
  CallSetup s(this, aRv, "RTCPeerConnection.onsignalingstatechange", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
9624
0
  JSContext* cx = s.GetContext();
9625
0
  if (!cx) {
9626
0
    MOZ_ASSERT(aRv.Failed());
9627
0
    return;
9628
0
  }
9629
0
  JS::AutoValueVector argv(cx);
9630
0
  if (!argv.resize(1)) {
9631
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
9632
0
    return;
9633
0
  }
9634
0
  do {
9635
0
    if (arg) {
9636
0
      argv[0].setObjectOrNull(GetCallbackFromCallbackObject(cx, arg));
9637
0
      if (!MaybeWrapObjectOrNullValue(cx, argv[0])) {
9638
0
        aRv.Throw(NS_ERROR_UNEXPECTED);
9639
0
        return;
9640
0
      }
9641
0
      break;
9642
0
    } else {
9643
0
      argv[0].setNull();
9644
0
      break;
9645
0
    }
9646
0
  } while (false);
9647
0
9648
0
  MOZ_ASSERT(argv.length() == 1);
9649
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
9650
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
9651
0
      !JS_SetPropertyById(cx, CallbackKnownNotGray(), atomsCache->onsignalingstatechange_id, argv[0])) {
9652
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
9653
0
    return;
9654
0
  }
9655
0
}
9656
9657
void
9658
RTCPeerConnectionJSImpl::SetOnaddstream(EventHandlerNonNull* arg, ErrorResult& aRv, JS::Realm* aRealm)
9659
0
{
9660
0
  CallSetup s(this, aRv, "RTCPeerConnection.onaddstream", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
9661
0
  JSContext* cx = s.GetContext();
9662
0
  if (!cx) {
9663
0
    MOZ_ASSERT(aRv.Failed());
9664
0
    return;
9665
0
  }
9666
0
  JS::AutoValueVector argv(cx);
9667
0
  if (!argv.resize(1)) {
9668
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
9669
0
    return;
9670
0
  }
9671
0
  do {
9672
0
    if (arg) {
9673
0
      argv[0].setObjectOrNull(GetCallbackFromCallbackObject(cx, arg));
9674
0
      if (!MaybeWrapObjectOrNullValue(cx, argv[0])) {
9675
0
        aRv.Throw(NS_ERROR_UNEXPECTED);
9676
0
        return;
9677
0
      }
9678
0
      break;
9679
0
    } else {
9680
0
      argv[0].setNull();
9681
0
      break;
9682
0
    }
9683
0
  } while (false);
9684
0
9685
0
  MOZ_ASSERT(argv.length() == 1);
9686
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
9687
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
9688
0
      !JS_SetPropertyById(cx, CallbackKnownNotGray(), atomsCache->onaddstream_id, argv[0])) {
9689
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
9690
0
    return;
9691
0
  }
9692
0
}
9693
9694
void
9695
RTCPeerConnectionJSImpl::SetOnaddtrack(EventHandlerNonNull* arg, ErrorResult& aRv, JS::Realm* aRealm)
9696
0
{
9697
0
  CallSetup s(this, aRv, "RTCPeerConnection.onaddtrack", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
9698
0
  JSContext* cx = s.GetContext();
9699
0
  if (!cx) {
9700
0
    MOZ_ASSERT(aRv.Failed());
9701
0
    return;
9702
0
  }
9703
0
  JS::AutoValueVector argv(cx);
9704
0
  if (!argv.resize(1)) {
9705
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
9706
0
    return;
9707
0
  }
9708
0
  do {
9709
0
    if (arg) {
9710
0
      argv[0].setObjectOrNull(GetCallbackFromCallbackObject(cx, arg));
9711
0
      if (!MaybeWrapObjectOrNullValue(cx, argv[0])) {
9712
0
        aRv.Throw(NS_ERROR_UNEXPECTED);
9713
0
        return;
9714
0
      }
9715
0
      break;
9716
0
    } else {
9717
0
      argv[0].setNull();
9718
0
      break;
9719
0
    }
9720
0
  } while (false);
9721
0
9722
0
  MOZ_ASSERT(argv.length() == 1);
9723
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
9724
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
9725
0
      !JS_SetPropertyById(cx, CallbackKnownNotGray(), atomsCache->onaddtrack_id, argv[0])) {
9726
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
9727
0
    return;
9728
0
  }
9729
0
}
9730
9731
void
9732
RTCPeerConnectionJSImpl::SetOntrack(EventHandlerNonNull* arg, ErrorResult& aRv, JS::Realm* aRealm)
9733
0
{
9734
0
  CallSetup s(this, aRv, "RTCPeerConnection.ontrack", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
9735
0
  JSContext* cx = s.GetContext();
9736
0
  if (!cx) {
9737
0
    MOZ_ASSERT(aRv.Failed());
9738
0
    return;
9739
0
  }
9740
0
  JS::AutoValueVector argv(cx);
9741
0
  if (!argv.resize(1)) {
9742
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
9743
0
    return;
9744
0
  }
9745
0
  do {
9746
0
    if (arg) {
9747
0
      argv[0].setObjectOrNull(GetCallbackFromCallbackObject(cx, arg));
9748
0
      if (!MaybeWrapObjectOrNullValue(cx, argv[0])) {
9749
0
        aRv.Throw(NS_ERROR_UNEXPECTED);
9750
0
        return;
9751
0
      }
9752
0
      break;
9753
0
    } else {
9754
0
      argv[0].setNull();
9755
0
      break;
9756
0
    }
9757
0
  } while (false);
9758
0
9759
0
  MOZ_ASSERT(argv.length() == 1);
9760
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
9761
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
9762
0
      !JS_SetPropertyById(cx, CallbackKnownNotGray(), atomsCache->ontrack_id, argv[0])) {
9763
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
9764
0
    return;
9765
0
  }
9766
0
}
9767
9768
void
9769
RTCPeerConnectionJSImpl::SetOnremovestream(EventHandlerNonNull* arg, ErrorResult& aRv, JS::Realm* aRealm)
9770
0
{
9771
0
  CallSetup s(this, aRv, "RTCPeerConnection.onremovestream", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
9772
0
  JSContext* cx = s.GetContext();
9773
0
  if (!cx) {
9774
0
    MOZ_ASSERT(aRv.Failed());
9775
0
    return;
9776
0
  }
9777
0
  JS::AutoValueVector argv(cx);
9778
0
  if (!argv.resize(1)) {
9779
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
9780
0
    return;
9781
0
  }
9782
0
  do {
9783
0
    if (arg) {
9784
0
      argv[0].setObjectOrNull(GetCallbackFromCallbackObject(cx, arg));
9785
0
      if (!MaybeWrapObjectOrNullValue(cx, argv[0])) {
9786
0
        aRv.Throw(NS_ERROR_UNEXPECTED);
9787
0
        return;
9788
0
      }
9789
0
      break;
9790
0
    } else {
9791
0
      argv[0].setNull();
9792
0
      break;
9793
0
    }
9794
0
  } while (false);
9795
0
9796
0
  MOZ_ASSERT(argv.length() == 1);
9797
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
9798
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
9799
0
      !JS_SetPropertyById(cx, CallbackKnownNotGray(), atomsCache->onremovestream_id, argv[0])) {
9800
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
9801
0
    return;
9802
0
  }
9803
0
}
9804
9805
void
9806
RTCPeerConnectionJSImpl::SetOniceconnectionstatechange(EventHandlerNonNull* arg, ErrorResult& aRv, JS::Realm* aRealm)
9807
0
{
9808
0
  CallSetup s(this, aRv, "RTCPeerConnection.oniceconnectionstatechange", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
9809
0
  JSContext* cx = s.GetContext();
9810
0
  if (!cx) {
9811
0
    MOZ_ASSERT(aRv.Failed());
9812
0
    return;
9813
0
  }
9814
0
  JS::AutoValueVector argv(cx);
9815
0
  if (!argv.resize(1)) {
9816
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
9817
0
    return;
9818
0
  }
9819
0
  do {
9820
0
    if (arg) {
9821
0
      argv[0].setObjectOrNull(GetCallbackFromCallbackObject(cx, arg));
9822
0
      if (!MaybeWrapObjectOrNullValue(cx, argv[0])) {
9823
0
        aRv.Throw(NS_ERROR_UNEXPECTED);
9824
0
        return;
9825
0
      }
9826
0
      break;
9827
0
    } else {
9828
0
      argv[0].setNull();
9829
0
      break;
9830
0
    }
9831
0
  } while (false);
9832
0
9833
0
  MOZ_ASSERT(argv.length() == 1);
9834
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
9835
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
9836
0
      !JS_SetPropertyById(cx, CallbackKnownNotGray(), atomsCache->oniceconnectionstatechange_id, argv[0])) {
9837
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
9838
0
    return;
9839
0
  }
9840
0
}
9841
9842
void
9843
RTCPeerConnectionJSImpl::SetOnicegatheringstatechange(EventHandlerNonNull* arg, ErrorResult& aRv, JS::Realm* aRealm)
9844
0
{
9845
0
  CallSetup s(this, aRv, "RTCPeerConnection.onicegatheringstatechange", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
9846
0
  JSContext* cx = s.GetContext();
9847
0
  if (!cx) {
9848
0
    MOZ_ASSERT(aRv.Failed());
9849
0
    return;
9850
0
  }
9851
0
  JS::AutoValueVector argv(cx);
9852
0
  if (!argv.resize(1)) {
9853
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
9854
0
    return;
9855
0
  }
9856
0
  do {
9857
0
    if (arg) {
9858
0
      argv[0].setObjectOrNull(GetCallbackFromCallbackObject(cx, arg));
9859
0
      if (!MaybeWrapObjectOrNullValue(cx, argv[0])) {
9860
0
        aRv.Throw(NS_ERROR_UNEXPECTED);
9861
0
        return;
9862
0
      }
9863
0
      break;
9864
0
    } else {
9865
0
      argv[0].setNull();
9866
0
      break;
9867
0
    }
9868
0
  } while (false);
9869
0
9870
0
  MOZ_ASSERT(argv.length() == 1);
9871
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
9872
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
9873
0
      !JS_SetPropertyById(cx, CallbackKnownNotGray(), atomsCache->onicegatheringstatechange_id, argv[0])) {
9874
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
9875
0
    return;
9876
0
  }
9877
0
}
9878
9879
void
9880
RTCPeerConnectionJSImpl::SetOndatachannel(EventHandlerNonNull* arg, ErrorResult& aRv, JS::Realm* aRealm)
9881
0
{
9882
0
  CallSetup s(this, aRv, "RTCPeerConnection.ondatachannel", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
9883
0
  JSContext* cx = s.GetContext();
9884
0
  if (!cx) {
9885
0
    MOZ_ASSERT(aRv.Failed());
9886
0
    return;
9887
0
  }
9888
0
  JS::AutoValueVector argv(cx);
9889
0
  if (!argv.resize(1)) {
9890
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
9891
0
    return;
9892
0
  }
9893
0
  do {
9894
0
    if (arg) {
9895
0
      argv[0].setObjectOrNull(GetCallbackFromCallbackObject(cx, arg));
9896
0
      if (!MaybeWrapObjectOrNullValue(cx, argv[0])) {
9897
0
        aRv.Throw(NS_ERROR_UNEXPECTED);
9898
0
        return;
9899
0
      }
9900
0
      break;
9901
0
    } else {
9902
0
      argv[0].setNull();
9903
0
      break;
9904
0
    }
9905
0
  } while (false);
9906
0
9907
0
  MOZ_ASSERT(argv.length() == 1);
9908
0
  RTCPeerConnectionAtoms* atomsCache = GetAtomCache<RTCPeerConnectionAtoms>(cx);
9909
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
9910
0
      !JS_SetPropertyById(cx, CallbackKnownNotGray(), atomsCache->ondatachannel_id, argv[0])) {
9911
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
9912
0
    return;
9913
0
  }
9914
0
}
9915
9916
9917
NS_IMPL_CYCLE_COLLECTION_INHERITED(RTCPeerConnection, mozilla::DOMEventTargetHelper, mImpl, mParent)
9918
NS_IMPL_ADDREF_INHERITED(RTCPeerConnection, mozilla::DOMEventTargetHelper)
9919
NS_IMPL_RELEASE_INHERITED(RTCPeerConnection, mozilla::DOMEventTargetHelper)
9920
0
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(RTCPeerConnection)
9921
0
NS_INTERFACE_MAP_END_INHERITING(mozilla::DOMEventTargetHelper)
9922
9923
RTCPeerConnection::RTCPeerConnection(JS::Handle<JSObject*> aJSImplObject, JS::Handle<JSObject*> aJSImplGlobal, nsIGlobalObject* aParent)
9924
  : mozilla::DOMEventTargetHelper(aParent),
9925
    mImpl(new RTCPeerConnectionJSImpl(nullptr, aJSImplObject, aJSImplGlobal, /* aIncumbentGlobal = */ nullptr)),
9926
    mParent(aParent)
9927
0
{
9928
0
}
9929
9930
9931
RTCPeerConnection::~RTCPeerConnection()
9932
0
{
9933
0
}
9934
9935
nsISupports*
9936
RTCPeerConnection::GetParentObject() const
9937
0
{
9938
0
  return mParent;
9939
0
}
9940
9941
JSObject*
9942
RTCPeerConnection::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
9943
0
{
9944
0
  JS::Rooted<JSObject*> obj(aCx, RTCPeerConnection_Binding::Wrap(aCx, this, aGivenProto));
9945
0
  if (!obj) {
9946
0
    return nullptr;
9947
0
  }
9948
0
9949
0
  // Now define it on our chrome object
9950
0
  JSAutoRealm ar(aCx, mImpl->CallbackGlobalOrNull());
9951
0
  if (!JS_WrapObject(aCx, &obj)) {
9952
0
    return nullptr;
9953
0
  }
9954
0
  if (!JS_DefineProperty(aCx, mImpl->CallbackOrNull(), "__DOM_IMPL__", obj, 0)) {
9955
0
    return nullptr;
9956
0
  }
9957
0
  return obj;
9958
0
}
9959
9960
already_AddRefed<RTCPeerConnection>
9961
RTCPeerConnection::Constructor(const GlobalObject& global, JSContext* cx, const RTCConfiguration& configuration, const Optional<JS::Handle<JSObject*>>& constraints, ErrorResult& aRv, JS::Handle<JSObject*> aGivenProto)
9962
0
{
9963
0
  JS::Rooted<JSObject*> jsImplObj(cx);
9964
0
  nsCOMPtr<nsIGlobalObject> globalHolder =
9965
0
    ConstructJSImplementation("@mozilla.org/dom/peerconnection;1", global, &jsImplObj, aRv);
9966
0
  if (aRv.Failed()) {
9967
0
    return nullptr;
9968
0
  }
9969
0
  // We should be getting the implementation object for the relevant
9970
0
  // contract here, which should never be a cross-compartment wrapper.
9971
0
  JS::Rooted<JSObject*> jsImplGlobal(cx, JS::GetNonCCWObjectGlobal(jsImplObj));
9972
0
  // Build the C++ implementation.
9973
0
  RefPtr<RTCPeerConnection> impl = new RTCPeerConnection(jsImplObj, jsImplGlobal, globalHolder);
9974
0
  // Wrap the object before calling __Init so that __DOM_IMPL__ is available.
9975
0
  JS::Rooted<JSObject*> scopeObj(cx, globalHolder->GetGlobalJSObject());
9976
0
  MOZ_ASSERT(js::IsObjectInContextCompartment(scopeObj, cx));
9977
0
  JS::Rooted<JS::Value> wrappedVal(cx);
9978
0
  if (!GetOrCreateDOMReflector(cx, impl, &wrappedVal, aGivenProto)) {
9979
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
9980
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
9981
0
    return nullptr;
9982
0
  }
9983
0
  // Initialize the object with the constructor arguments.
9984
0
  impl->mImpl->__Init(configuration, constraints, aRv, js::GetNonCCWObjectRealm(scopeObj));
9985
0
  if (aRv.Failed()) {
9986
0
    return nullptr;
9987
0
  }
9988
0
  return impl.forget();
9989
0
}
9990
9991
void
9992
RTCPeerConnection::SetIdentityProvider(const nsAString& provider, const RTCIdentityProviderOptions& options, ErrorResult& aRv, JS::Realm* aRealm)
9993
0
{
9994
0
  return mImpl->SetIdentityProvider(provider, options, aRv, aRealm);
9995
0
}
9996
9997
// Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
9998
already_AddRefed<Promise>
9999
RTCPeerConnection::GetIdentityAssertion(ErrorResult& aRv, JS::Realm* aRealm)
10000
0
{
10001
0
  return mImpl->GetIdentityAssertion(aRv, aRealm);
10002
0
}
10003
10004
// Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
10005
already_AddRefed<Promise>
10006
RTCPeerConnection::CreateOffer(const RTCOfferOptions& options, ErrorResult& aRv, JS::Realm* aRealm)
10007
0
{
10008
0
  return mImpl->CreateOffer(options, aRv, aRealm);
10009
0
}
10010
10011
// Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
10012
already_AddRefed<Promise>
10013
RTCPeerConnection::CreateOffer(RTCSessionDescriptionCallback& successCallback, RTCPeerConnectionErrorCallback& failureCallback, const RTCOfferOptions& options, ErrorResult& aRv, JS::Realm* aRealm)
10014
0
{
10015
0
  return mImpl->CreateOffer(successCallback, failureCallback, options, aRv, aRealm);
10016
0
}
10017
10018
// Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
10019
already_AddRefed<Promise>
10020
RTCPeerConnection::CreateAnswer(const RTCAnswerOptions& options, ErrorResult& aRv, JS::Realm* aRealm)
10021
0
{
10022
0
  return mImpl->CreateAnswer(options, aRv, aRealm);
10023
0
}
10024
10025
// Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
10026
already_AddRefed<Promise>
10027
RTCPeerConnection::CreateAnswer(RTCSessionDescriptionCallback& successCallback, RTCPeerConnectionErrorCallback& failureCallback, ErrorResult& aRv, JS::Realm* aRealm)
10028
0
{
10029
0
  return mImpl->CreateAnswer(successCallback, failureCallback, aRv, aRealm);
10030
0
}
10031
10032
// Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
10033
already_AddRefed<Promise>
10034
RTCPeerConnection::SetLocalDescription(const RTCSessionDescriptionInit& description, ErrorResult& aRv, JS::Realm* aRealm)
10035
0
{
10036
0
  return mImpl->SetLocalDescription(description, aRv, aRealm);
10037
0
}
10038
10039
// Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
10040
already_AddRefed<Promise>
10041
RTCPeerConnection::SetLocalDescription(const RTCSessionDescriptionInit& description, VoidFunction& successCallback, RTCPeerConnectionErrorCallback& failureCallback, ErrorResult& aRv, JS::Realm* aRealm)
10042
0
{
10043
0
  return mImpl->SetLocalDescription(description, successCallback, failureCallback, aRv, aRealm);
10044
0
}
10045
10046
// Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
10047
already_AddRefed<Promise>
10048
RTCPeerConnection::SetRemoteDescription(const RTCSessionDescriptionInit& description, ErrorResult& aRv, JS::Realm* aRealm)
10049
0
{
10050
0
  return mImpl->SetRemoteDescription(description, aRv, aRealm);
10051
0
}
10052
10053
// Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
10054
already_AddRefed<Promise>
10055
RTCPeerConnection::SetRemoteDescription(const RTCSessionDescriptionInit& description, VoidFunction& successCallback, RTCPeerConnectionErrorCallback& failureCallback, ErrorResult& aRv, JS::Realm* aRealm)
10056
0
{
10057
0
  return mImpl->SetRemoteDescription(description, successCallback, failureCallback, aRv, aRealm);
10058
0
}
10059
10060
// Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
10061
already_AddRefed<RTCSessionDescription>
10062
RTCPeerConnection::GetLocalDescription(ErrorResult& aRv, JS::Realm* aRealm) const
10063
0
{
10064
0
  return mImpl->GetLocalDescription(aRv, aRealm);
10065
0
}
10066
10067
// Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
10068
already_AddRefed<RTCSessionDescription>
10069
RTCPeerConnection::GetCurrentLocalDescription(ErrorResult& aRv, JS::Realm* aRealm) const
10070
0
{
10071
0
  return mImpl->GetCurrentLocalDescription(aRv, aRealm);
10072
0
}
10073
10074
// Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
10075
already_AddRefed<RTCSessionDescription>
10076
RTCPeerConnection::GetPendingLocalDescription(ErrorResult& aRv, JS::Realm* aRealm) const
10077
0
{
10078
0
  return mImpl->GetPendingLocalDescription(aRv, aRealm);
10079
0
}
10080
10081
// Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
10082
already_AddRefed<RTCSessionDescription>
10083
RTCPeerConnection::GetRemoteDescription(ErrorResult& aRv, JS::Realm* aRealm) const
10084
0
{
10085
0
  return mImpl->GetRemoteDescription(aRv, aRealm);
10086
0
}
10087
10088
// Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
10089
already_AddRefed<RTCSessionDescription>
10090
RTCPeerConnection::GetCurrentRemoteDescription(ErrorResult& aRv, JS::Realm* aRealm) const
10091
0
{
10092
0
  return mImpl->GetCurrentRemoteDescription(aRv, aRealm);
10093
0
}
10094
10095
// Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
10096
already_AddRefed<RTCSessionDescription>
10097
RTCPeerConnection::GetPendingRemoteDescription(ErrorResult& aRv, JS::Realm* aRealm) const
10098
0
{
10099
0
  return mImpl->GetPendingRemoteDescription(aRv, aRealm);
10100
0
}
10101
10102
RTCSignalingState
10103
RTCPeerConnection::GetSignalingState(ErrorResult& aRv, JS::Realm* aRealm) const
10104
0
{
10105
0
  return mImpl->GetSignalingState(aRv, aRealm);
10106
0
}
10107
10108
// Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
10109
already_AddRefed<Promise>
10110
RTCPeerConnection::AddIceCandidate(const Nullable<RTCIceCandidateInitOrRTCIceCandidate>& candidate, ErrorResult& aRv, JS::Realm* aRealm)
10111
0
{
10112
0
  return mImpl->AddIceCandidate(candidate, aRv, aRealm);
10113
0
}
10114
10115
// Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
10116
already_AddRefed<Promise>
10117
RTCPeerConnection::AddIceCandidate(RTCIceCandidate& candidate, VoidFunction& successCallback, RTCPeerConnectionErrorCallback& failureCallback, ErrorResult& aRv, JS::Realm* aRealm)
10118
0
{
10119
0
  return mImpl->AddIceCandidate(candidate, successCallback, failureCallback, aRv, aRealm);
10120
0
}
10121
10122
Nullable<bool>
10123
RTCPeerConnection::GetCanTrickleIceCandidates(ErrorResult& aRv, JS::Realm* aRealm) const
10124
0
{
10125
0
  return mImpl->GetCanTrickleIceCandidates(aRv, aRealm);
10126
0
}
10127
10128
RTCIceGatheringState
10129
RTCPeerConnection::GetIceGatheringState(ErrorResult& aRv, JS::Realm* aRealm) const
10130
0
{
10131
0
  return mImpl->GetIceGatheringState(aRv, aRealm);
10132
0
}
10133
10134
RTCIceConnectionState
10135
RTCPeerConnection::GetIceConnectionState(ErrorResult& aRv, JS::Realm* aRealm) const
10136
0
{
10137
0
  return mImpl->GetIceConnectionState(aRv, aRealm);
10138
0
}
10139
10140
// Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
10141
already_AddRefed<Promise>
10142
RTCPeerConnection::GetPeerIdentity(ErrorResult& aRv, JS::Realm* aRealm) const
10143
0
{
10144
0
  return mImpl->GetPeerIdentity(aRv, aRealm);
10145
0
}
10146
10147
void
10148
RTCPeerConnection::GetIdpLoginUrl(nsString& aRetVal, ErrorResult& aRv, JS::Realm* aRealm) const
10149
0
{
10150
0
  return mImpl->GetIdpLoginUrl(aRetVal, aRv, aRealm);
10151
0
}
10152
10153
void
10154
RTCPeerConnection::GetId(nsString& aRetVal, ErrorResult& aRv, JS::Realm* aRealm) const
10155
0
{
10156
0
  return mImpl->GetId(aRetVal, aRv, aRealm);
10157
0
}
10158
10159
void
10160
RTCPeerConnection::SetId(const nsAString& arg, ErrorResult& aRv, JS::Realm* aRealm)
10161
0
{
10162
0
  mImpl->SetId(arg, aRv, aRealm);
10163
0
}
10164
10165
void
10166
RTCPeerConnection::GetConfiguration(RTCConfiguration& aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
10167
0
{
10168
0
  return mImpl->GetConfiguration(aRetVal, aRv, aRealm);
10169
0
}
10170
10171
void
10172
RTCPeerConnection::GetLocalStreams(nsTArray<RefPtr<DOMMediaStream>>& aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
10173
0
{
10174
0
  return mImpl->GetLocalStreams(aRetVal, aRv, aRealm);
10175
0
}
10176
10177
void
10178
RTCPeerConnection::GetRemoteStreams(nsTArray<RefPtr<DOMMediaStream>>& aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
10179
0
{
10180
0
  return mImpl->GetRemoteStreams(aRetVal, aRv, aRealm);
10181
0
}
10182
10183
void
10184
RTCPeerConnection::AddStream(DOMMediaStream& stream, ErrorResult& aRv, JS::Realm* aRealm)
10185
0
{
10186
0
  return mImpl->AddStream(stream, aRv, aRealm);
10187
0
}
10188
10189
// Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
10190
already_AddRefed<RTCRtpSender>
10191
RTCPeerConnection::AddTrack(MediaStreamTrack& track, DOMMediaStream& stream, const Sequence<OwningNonNull<DOMMediaStream>>& moreStreams, ErrorResult& aRv, JS::Realm* aRealm)
10192
0
{
10193
0
  return mImpl->AddTrack(track, stream, moreStreams, aRv, aRealm);
10194
0
}
10195
10196
void
10197
RTCPeerConnection::RemoveTrack(RTCRtpSender& sender, ErrorResult& aRv, JS::Realm* aRealm)
10198
0
{
10199
0
  return mImpl->RemoveTrack(sender, aRv, aRealm);
10200
0
}
10201
10202
// Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
10203
already_AddRefed<RTCRtpTransceiver>
10204
RTCPeerConnection::AddTransceiver(const MediaStreamTrackOrString& trackOrKind, const RTCRtpTransceiverInit& init, ErrorResult& aRv, JS::Realm* aRealm)
10205
0
{
10206
0
  return mImpl->AddTransceiver(trackOrKind, init, aRv, aRealm);
10207
0
}
10208
10209
void
10210
RTCPeerConnection::GetSenders(nsTArray<RefPtr<RTCRtpSender>>& aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
10211
0
{
10212
0
  return mImpl->GetSenders(aRetVal, aRv, aRealm);
10213
0
}
10214
10215
void
10216
RTCPeerConnection::GetReceivers(nsTArray<RefPtr<RTCRtpReceiver>>& aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
10217
0
{
10218
0
  return mImpl->GetReceivers(aRetVal, aRv, aRealm);
10219
0
}
10220
10221
void
10222
RTCPeerConnection::GetTransceivers(nsTArray<RefPtr<RTCRtpTransceiver>>& aRetVal, ErrorResult& aRv, JS::Realm* aRealm)
10223
0
{
10224
0
  return mImpl->GetTransceivers(aRetVal, aRv, aRealm);
10225
0
}
10226
10227
double
10228
RTCPeerConnection::MozGetNowInRtpSourceReferenceTime(ErrorResult& aRv, JS::Realm* aRealm)
10229
0
{
10230
0
  return mImpl->MozGetNowInRtpSourceReferenceTime(aRv, aRealm);
10231
0
}
10232
10233
void
10234
RTCPeerConnection::MozInsertAudioLevelForContributingSource(RTCRtpReceiver& receiver, uint32_t source, double timestamp, bool hasLevel, int8_t level, ErrorResult& aRv, JS::Realm* aRealm)
10235
0
{
10236
0
  return mImpl->MozInsertAudioLevelForContributingSource(receiver, source, timestamp, hasLevel, level, aRv, aRealm);
10237
0
}
10238
10239
void
10240
RTCPeerConnection::MozAddRIDExtension(RTCRtpReceiver& receiver, uint16_t extensionId, ErrorResult& aRv, JS::Realm* aRealm)
10241
0
{
10242
0
  return mImpl->MozAddRIDExtension(receiver, extensionId, aRv, aRealm);
10243
0
}
10244
10245
void
10246
RTCPeerConnection::MozAddRIDFilter(RTCRtpReceiver& receiver, const nsAString& rid, ErrorResult& aRv, JS::Realm* aRealm)
10247
0
{
10248
0
  return mImpl->MozAddRIDFilter(receiver, rid, aRv, aRealm);
10249
0
}
10250
10251
void
10252
RTCPeerConnection::MozSetPacketCallback(mozPacketCallback& callback, ErrorResult& aRv, JS::Realm* aRealm)
10253
0
{
10254
0
  return mImpl->MozSetPacketCallback(callback, aRv, aRealm);
10255
0
}
10256
10257
void
10258
RTCPeerConnection::MozEnablePacketDump(uint32_t level, mozPacketDumpType type, bool sending, ErrorResult& aRv, JS::Realm* aRealm)
10259
0
{
10260
0
  return mImpl->MozEnablePacketDump(level, type, sending, aRv, aRealm);
10261
0
}
10262
10263
void
10264
RTCPeerConnection::MozDisablePacketDump(uint32_t level, mozPacketDumpType type, bool sending, ErrorResult& aRv, JS::Realm* aRealm)
10265
0
{
10266
0
  return mImpl->MozDisablePacketDump(level, type, sending, aRv, aRealm);
10267
0
}
10268
10269
void
10270
RTCPeerConnection::Close(ErrorResult& aRv, JS::Realm* aRealm)
10271
0
{
10272
0
  return mImpl->Close(aRv, aRealm);
10273
0
}
10274
10275
already_AddRefed<EventHandlerNonNull>
10276
RTCPeerConnection::GetOnnegotiationneeded(ErrorResult& aRv, JS::Realm* aRealm) const
10277
0
{
10278
0
  return mImpl->GetOnnegotiationneeded(aRv, aRealm);
10279
0
}
10280
10281
void
10282
RTCPeerConnection::SetOnnegotiationneeded(EventHandlerNonNull* arg, ErrorResult& aRv, JS::Realm* aRealm)
10283
0
{
10284
0
  mImpl->SetOnnegotiationneeded(arg, aRv, aRealm);
10285
0
}
10286
10287
already_AddRefed<EventHandlerNonNull>
10288
RTCPeerConnection::GetOnicecandidate(ErrorResult& aRv, JS::Realm* aRealm) const
10289
0
{
10290
0
  return mImpl->GetOnicecandidate(aRv, aRealm);
10291
0
}
10292
10293
void
10294
RTCPeerConnection::SetOnicecandidate(EventHandlerNonNull* arg, ErrorResult& aRv, JS::Realm* aRealm)
10295
0
{
10296
0
  mImpl->SetOnicecandidate(arg, aRv, aRealm);
10297
0
}
10298
10299
already_AddRefed<EventHandlerNonNull>
10300
RTCPeerConnection::GetOnsignalingstatechange(ErrorResult& aRv, JS::Realm* aRealm) const
10301
0
{
10302
0
  return mImpl->GetOnsignalingstatechange(aRv, aRealm);
10303
0
}
10304
10305
void
10306
RTCPeerConnection::SetOnsignalingstatechange(EventHandlerNonNull* arg, ErrorResult& aRv, JS::Realm* aRealm)
10307
0
{
10308
0
  mImpl->SetOnsignalingstatechange(arg, aRv, aRealm);
10309
0
}
10310
10311
already_AddRefed<EventHandlerNonNull>
10312
RTCPeerConnection::GetOnaddstream(ErrorResult& aRv, JS::Realm* aRealm) const
10313
0
{
10314
0
  return mImpl->GetOnaddstream(aRv, aRealm);
10315
0
}
10316
10317
void
10318
RTCPeerConnection::SetOnaddstream(EventHandlerNonNull* arg, ErrorResult& aRv, JS::Realm* aRealm)
10319
0
{
10320
0
  mImpl->SetOnaddstream(arg, aRv, aRealm);
10321
0
}
10322
10323
already_AddRefed<EventHandlerNonNull>
10324
RTCPeerConnection::GetOnaddtrack(ErrorResult& aRv, JS::Realm* aRealm) const
10325
0
{
10326
0
  return mImpl->GetOnaddtrack(aRv, aRealm);
10327
0
}
10328
10329
void
10330
RTCPeerConnection::SetOnaddtrack(EventHandlerNonNull* arg, ErrorResult& aRv, JS::Realm* aRealm)
10331
0
{
10332
0
  mImpl->SetOnaddtrack(arg, aRv, aRealm);
10333
0
}
10334
10335
already_AddRefed<EventHandlerNonNull>
10336
RTCPeerConnection::GetOntrack(ErrorResult& aRv, JS::Realm* aRealm) const
10337
0
{
10338
0
  return mImpl->GetOntrack(aRv, aRealm);
10339
0
}
10340
10341
void
10342
RTCPeerConnection::SetOntrack(EventHandlerNonNull* arg, ErrorResult& aRv, JS::Realm* aRealm)
10343
0
{
10344
0
  mImpl->SetOntrack(arg, aRv, aRealm);
10345
0
}
10346
10347
already_AddRefed<EventHandlerNonNull>
10348
RTCPeerConnection::GetOnremovestream(ErrorResult& aRv, JS::Realm* aRealm) const
10349
0
{
10350
0
  return mImpl->GetOnremovestream(aRv, aRealm);
10351
0
}
10352
10353
void
10354
RTCPeerConnection::SetOnremovestream(EventHandlerNonNull* arg, ErrorResult& aRv, JS::Realm* aRealm)
10355
0
{
10356
0
  mImpl->SetOnremovestream(arg, aRv, aRealm);
10357
0
}
10358
10359
already_AddRefed<EventHandlerNonNull>
10360
RTCPeerConnection::GetOniceconnectionstatechange(ErrorResult& aRv, JS::Realm* aRealm) const
10361
0
{
10362
0
  return mImpl->GetOniceconnectionstatechange(aRv, aRealm);
10363
0
}
10364
10365
void
10366
RTCPeerConnection::SetOniceconnectionstatechange(EventHandlerNonNull* arg, ErrorResult& aRv, JS::Realm* aRealm)
10367
0
{
10368
0
  mImpl->SetOniceconnectionstatechange(arg, aRv, aRealm);
10369
0
}
10370
10371
already_AddRefed<EventHandlerNonNull>
10372
RTCPeerConnection::GetOnicegatheringstatechange(ErrorResult& aRv, JS::Realm* aRealm) const
10373
0
{
10374
0
  return mImpl->GetOnicegatheringstatechange(aRv, aRealm);
10375
0
}
10376
10377
void
10378
RTCPeerConnection::SetOnicegatheringstatechange(EventHandlerNonNull* arg, ErrorResult& aRv, JS::Realm* aRealm)
10379
0
{
10380
0
  mImpl->SetOnicegatheringstatechange(arg, aRv, aRealm);
10381
0
}
10382
10383
// Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
10384
already_AddRefed<Promise>
10385
RTCPeerConnection::GetStats(const Optional<MediaStreamTrack*>& selector, ErrorResult& aRv, JS::Realm* aRealm)
10386
0
{
10387
0
  return mImpl->GetStats(selector, aRv, aRealm);
10388
0
}
10389
10390
// Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
10391
already_AddRefed<Promise>
10392
RTCPeerConnection::GetStats(MediaStreamTrack* selector, RTCStatsCallback& successCallback, RTCPeerConnectionErrorCallback& failureCallback, ErrorResult& aRv, JS::Realm* aRealm)
10393
0
{
10394
0
  return mImpl->GetStats(selector, successCallback, failureCallback, aRv, aRealm);
10395
0
}
10396
10397
// Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
10398
already_AddRefed<nsDOMDataChannel>
10399
RTCPeerConnection::CreateDataChannel(const nsAString& label, const RTCDataChannelInit& dataChannelDict, ErrorResult& aRv, JS::Realm* aRealm)
10400
0
{
10401
0
  return mImpl->CreateDataChannel(label, dataChannelDict, aRv, aRealm);
10402
0
}
10403
10404
already_AddRefed<EventHandlerNonNull>
10405
RTCPeerConnection::GetOndatachannel(ErrorResult& aRv, JS::Realm* aRealm) const
10406
0
{
10407
0
  return mImpl->GetOndatachannel(aRv, aRealm);
10408
0
}
10409
10410
void
10411
RTCPeerConnection::SetOndatachannel(EventHandlerNonNull* arg, ErrorResult& aRv, JS::Realm* aRealm)
10412
0
{
10413
0
  mImpl->SetOndatachannel(arg, aRv, aRealm);
10414
0
}
10415
10416
bool
10417
RTCPeerConnection::_Create(JSContext* cx, unsigned argc, JS::Value* vp)
10418
0
{
10419
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
10420
0
  if (args.length() < 2) {
10421
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCPeerConnection._create");
10422
0
  }
10423
0
  if (!args[0].isObject()) {
10424
0
    return ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of RTCPeerConnection._create");
10425
0
  }
10426
0
  if (!args[1].isObject()) {
10427
0
    return ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of RTCPeerConnection._create");
10428
0
  }
10429
0
10430
0
  // GlobalObject will go through wrappers as needed for us, and
10431
0
  // is simpler than the right UnwrapArg incantation.
10432
0
  GlobalObject global(cx, &args[0].toObject());
10433
0
  if (global.Failed()) {
10434
0
    return false;
10435
0
  }
10436
0
  nsCOMPtr<nsIGlobalObject> globalHolder = do_QueryInterface(global.GetAsSupports());
10437
0
  MOZ_ASSERT(globalHolder);
10438
0
  JS::Rooted<JSObject*> arg(cx, &args[1].toObject());
10439
0
  JS::Rooted<JSObject*> argGlobal(cx, JS::CurrentGlobalOrNull(cx));
10440
0
  RefPtr<RTCPeerConnection> impl = new RTCPeerConnection(arg, argGlobal, globalHolder);
10441
0
  MOZ_ASSERT(js::IsObjectInContextCompartment(arg, cx));
10442
0
  return GetOrCreateDOMReflector(cx, impl, args.rval());
10443
0
}
10444
10445
10446
} // namespace dom
10447
} // namespace mozilla