Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/WebrtcDeprecatedBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM WebrtcDeprecated.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "AtomList.h"
4
#include "RTCConfigurationBinding.h"
5
#include "RTCIceCandidateBinding.h"
6
#include "RTCPeerConnectionBinding.h"
7
#include "RTCSessionDescriptionBinding.h"
8
#include "WebrtcDeprecatedBinding.h"
9
#include "WrapperFactory.h"
10
#include "mozilla/OwningNonNull.h"
11
#include "mozilla/Preferences.h"
12
#include "mozilla/dom/BindingUtils.h"
13
#include "mozilla/dom/DOMJSClass.h"
14
#include "mozilla/dom/NonRefcountedDOMObject.h"
15
#include "mozilla/dom/Nullable.h"
16
#include "mozilla/dom/XrayExpandoClass.h"
17
#include "nsContentUtils.h"
18
#include "nsIDocument.h"
19
#include "nsIGlobalObject.h"
20
21
namespace mozilla {
22
namespace dom {
23
24
namespace binding_detail {}; // Just to make sure it's known as a namespace
25
using namespace mozilla::dom::binding_detail;
26
27
28
namespace mozRTCIceCandidate_Binding {
29
30
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<RTCIceCandidate_Binding::NativeType>::value,
31
              "Can't inherit from an interface with a different ownership model.");
32
33
static bool
34
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
35
0
{
36
0
  mozilla::dom::mozRTCIceCandidate* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::mozRTCIceCandidate>(obj);
37
0
  // We don't want to preserve if we don't have a wrapper, and we
38
0
  // obviously can't preserve if we're not initialized.
39
0
  if (self && self->GetWrapperPreserveColor()) {
40
0
    PreserveWrapper(self);
41
0
  }
42
0
  return true;
43
0
}
44
45
static void
46
_finalize(js::FreeOp* fop, JSObject* obj)
47
0
{
48
0
  mozilla::dom::mozRTCIceCandidate* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::mozRTCIceCandidate>(obj);
49
0
  if (self) {
50
0
    ClearWrapper(self, self, obj);
51
0
    AddForDeferredFinalization<mozilla::dom::mozRTCIceCandidate>(self);
52
0
  }
53
0
}
54
55
static size_t
56
_objectMoved(JSObject* obj, JSObject* old)
57
0
{
58
0
  mozilla::dom::mozRTCIceCandidate* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::mozRTCIceCandidate>(obj);
59
0
  if (self) {
60
0
    UpdateWrapper(self, self, obj, old);
61
0
  }
62
0
63
0
  return 0;
64
0
}
65
66
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
67
#if defined(__clang__)
68
#pragma clang diagnostic push
69
#pragma clang diagnostic ignored "-Wmissing-braces"
70
#endif
71
static const JSFunctionSpec sChromeStaticMethods_specs[] = {
72
  JS_FNSPEC("_create", mozRTCIceCandidate::_Create, nullptr, 2, 0, nullptr),
73
  JS_FS_END
74
};
75
#if defined(__clang__)
76
#pragma clang diagnostic pop
77
#endif
78
79
80
static const Prefable<const JSFunctionSpec> sChromeStaticMethods[] = {
81
  { nullptr, &sChromeStaticMethods_specs[0] },
82
  { nullptr, nullptr }
83
};
84
85
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
86
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
87
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
88
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
89
90
91
static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[1];
92
static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[1];
93
94
static const NativePropertiesN<1> sChromeOnlyNativeProperties = {
95
  true,  0 /* sChromeStaticMethods */,
96
  false, 0,
97
  false, 0,
98
  false, 0,
99
  false, 0,
100
  false, 0,
101
  false, 0,
102
  -1,
103
  1,
104
  sChromeOnlyNativeProperties_sortedPropertyIndices,
105
  {
106
    { sChromeStaticMethods, &sChromeOnlyNativeProperties_propertyInfos[0] }
107
  }
108
};
109
static_assert(1 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount),
110
    "We have a property info count that is oversized");
111
112
static bool
113
_constructor(JSContext* cx, unsigned argc, JS::Value* vp)
114
0
{
115
0
  AUTO_PROFILER_LABEL_FAST("mozRTCIceCandidate constructor", DOM, cx);
116
0
117
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
118
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
119
0
  if (!args.isConstructing()) {
120
0
    // XXXbz wish I could get the name from the callee instead of
121
0
    // Adding more relocations
122
0
    return ThrowConstructorWithoutNew(cx, "mozRTCIceCandidate");
123
0
  }
124
0
125
0
  JS::Rooted<JSObject*> desiredProto(cx);
126
0
  if (!GetDesiredProto(cx, args, &desiredProto)) {
127
0
    return false;
128
0
  }
129
0
130
0
  DeprecationWarning(cx, obj, nsIDocument::eWebrtcDeprecatedPrefix);
131
0
  GlobalObject global(cx, obj);
132
0
  if (global.Failed()) {
133
0
    return false;
134
0
  }
135
0
136
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
137
0
  binding_detail::FastRTCIceCandidateInit arg0;
138
0
  if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue,  "Argument 1 of mozRTCIceCandidate.constructor", true)) {
139
0
    return false;
140
0
  }
141
0
  Maybe<JSAutoRealm> ar;
142
0
  if (objIsXray) {
143
0
    obj = js::CheckedUnwrap(obj);
144
0
    if (!obj) {
145
0
      return false;
146
0
    }
147
0
    ar.emplace(cx, obj);
148
0
    if (!JS_WrapObject(cx, &desiredProto)) {
149
0
      return false;
150
0
    }
151
0
  }
152
0
  FastErrorResult rv;
153
0
  auto result(StrongOrRawPtr<mozilla::dom::mozRTCIceCandidate>(mozilla::dom::mozRTCIceCandidate::Constructor(global, cx, Constify(arg0), rv, desiredProto)));
154
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
155
0
    return false;
156
0
  }
157
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
158
0
  static_assert(!IsPointer<decltype(result)>::value,
159
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
160
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
161
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
162
0
    return false;
163
0
  }
164
0
  return true;
165
0
}
166
167
static const js::ClassOps sInterfaceObjectClassOps = {
168
    nullptr,               /* addProperty */
169
    nullptr,               /* delProperty */
170
    nullptr,               /* enumerate */
171
    nullptr,               /* newEnumerate */
172
    nullptr,               /* resolve */
173
    nullptr,               /* mayResolve */
174
    nullptr,               /* finalize */
175
    _constructor, /* call */
176
    nullptr,               /* hasInstance */
177
    _constructor, /* construct */
178
    nullptr,               /* trace */
179
};
180
181
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
182
  {
183
    "Function",
184
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
185
    &sInterfaceObjectClassOps,
186
    JS_NULL_CLASS_SPEC,
187
    JS_NULL_CLASS_EXT,
188
    &sInterfaceObjectClassObjectOps
189
  },
190
  eInterface,
191
  true,
192
  prototypes::id::mozRTCIceCandidate,
193
  PrototypeTraits<prototypes::id::mozRTCIceCandidate>::Depth,
194
  sNativePropertyHooks,
195
  "function mozRTCIceCandidate() {\n    [native code]\n}",
196
  RTCIceCandidate_Binding::GetConstructorObject
197
};
198
199
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
200
  {
201
    "mozRTCIceCandidatePrototype",
202
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
203
    JS_NULL_CLASS_OPS,
204
    JS_NULL_CLASS_SPEC,
205
    JS_NULL_CLASS_EXT,
206
    JS_NULL_OBJECT_OPS
207
  },
208
  eInterfacePrototype,
209
  false,
210
  prototypes::id::mozRTCIceCandidate,
211
  PrototypeTraits<prototypes::id::mozRTCIceCandidate>::Depth,
212
  sNativePropertyHooks,
213
  "[object mozRTCIceCandidatePrototype]",
214
  RTCIceCandidate_Binding::GetProtoObject
215
};
216
217
bool
218
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
219
0
{
220
0
  static bool sPrefValue;
221
0
  static bool sPrefCacheSetUp = false;
222
0
  if (!sPrefCacheSetUp) {
223
0
    sPrefCacheSetUp = true;
224
0
    Preferences::AddBoolVarCache(&sPrefValue, "media.peerconnection.enabled");
225
0
  }
226
0
227
0
  return sPrefValue;
228
0
}
229
230
static const js::ClassOps sClassOps = {
231
  _addProperty, /* addProperty */
232
  nullptr,               /* delProperty */
233
  nullptr,               /* enumerate */
234
  nullptr, /* newEnumerate */
235
  nullptr, /* resolve */
236
  nullptr, /* mayResolve */
237
  _finalize, /* finalize */
238
  nullptr, /* call */
239
  nullptr,               /* hasInstance */
240
  nullptr,               /* construct */
241
  nullptr, /* trace */
242
};
243
244
static const js::ClassExtension sClassExtension = {
245
  nullptr, /* weakmapKeyDelegateOp */
246
  _objectMoved /* objectMovedOp */
247
};
248
249
static const DOMJSClass sClass = {
250
  { "mozRTCIceCandidate",
251
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
252
    &sClassOps,
253
    JS_NULL_CLASS_SPEC,
254
    &sClassExtension,
255
    JS_NULL_OBJECT_OPS
256
  },
257
  { prototypes::id::RTCIceCandidate, prototypes::id::mozRTCIceCandidate, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
258
  IsBaseOf<nsISupports, mozilla::dom::mozRTCIceCandidate >::value,
259
  sNativePropertyHooks,
260
  FindAssociatedGlobalForNative<mozilla::dom::mozRTCIceCandidate>::Get,
261
  GetProtoObjectHandle,
262
  GetCCParticipant<mozilla::dom::mozRTCIceCandidate>::Get()
263
};
264
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
265
              "Must have the right minimal number of reserved slots.");
266
static_assert(1 >= 1,
267
              "Must have enough reserved slots.");
268
269
const JSClass*
270
GetJSClass()
271
0
{
272
0
  return sClass.ToJSClass();
273
0
}
274
275
bool
276
Wrap(JSContext* aCx, mozilla::dom::mozRTCIceCandidate* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
277
0
{
278
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::mozRTCIceCandidate>::value,
279
0
                "Shouldn't have wrappercached things that are not refcounted.");
280
0
  MOZ_ASSERT(static_cast<mozilla::dom::mozRTCIceCandidate*>(aObject) ==
281
0
             reinterpret_cast<mozilla::dom::mozRTCIceCandidate*>(aObject),
282
0
             "Multiple inheritance for mozilla::dom::mozRTCIceCandidate is broken.");
283
0
  MOZ_ASSERT(static_cast<mozilla::dom::RTCIceCandidate*>(aObject) ==
284
0
             reinterpret_cast<mozilla::dom::RTCIceCandidate*>(aObject),
285
0
             "Multiple inheritance for mozilla::dom::RTCIceCandidate is broken.");
286
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
287
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
288
0
  MOZ_ASSERT(!aCache->GetWrapper(),
289
0
             "You should probably not be using Wrap() directly; use "
290
0
             "GetOrCreateDOMReflector instead");
291
0
292
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
293
0
             "nsISupports must be on our primary inheritance chain");
294
0
295
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
296
0
  if (!global) {
297
0
    return false;
298
0
  }
299
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
300
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
301
0
302
0
  // That might have ended up wrapping us already, due to the wonders
303
0
  // of XBL.  Check for that, and bail out as needed.
304
0
  aReflector.set(aCache->GetWrapper());
305
0
  if (aReflector) {
306
#ifdef DEBUG
307
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
308
#endif // DEBUG
309
    return true;
310
0
  }
311
0
312
0
  JSAutoRealm ar(aCx, global);
313
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
314
0
  if (!canonicalProto) {
315
0
    return false;
316
0
  }
317
0
  JS::Rooted<JSObject*> proto(aCx);
318
0
  if (aGivenProto) {
319
0
    proto = aGivenProto;
320
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
321
0
    // coming in, we changed compartments to that of "parent" so may need
322
0
    // to wrap the proto here.
323
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
324
0
      if (!JS_WrapObject(aCx, &proto)) {
325
0
        return false;
326
0
      }
327
0
    }
328
0
  } else {
329
0
    proto = canonicalProto;
330
0
  }
331
0
332
0
  BindingJSObjectCreator<mozilla::dom::mozRTCIceCandidate> creator(aCx);
333
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
334
0
  if (!aReflector) {
335
0
    return false;
336
0
  }
337
0
338
0
  aCache->SetWrapper(aReflector);
339
0
  creator.InitializationSucceeded();
340
0
341
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
342
0
             aCache->GetWrapperPreserveColor() == aReflector);
343
0
  // If proto != canonicalProto, we have to preserve our wrapper;
344
0
  // otherwise we won't be able to properly recreate it later, since
345
0
  // we won't know what proto to use.  Note that we don't check
346
0
  // aGivenProto here, since it's entirely possible (and even
347
0
  // somewhat common) to have a non-null aGivenProto which is the
348
0
  // same as canonicalProto.
349
0
  if (proto != canonicalProto) {
350
0
    PreserveWrapper(aObject);
351
0
  }
352
0
353
0
  return true;
354
0
}
355
356
const NativePropertyHooks sNativePropertyHooks[] = { {
357
  nullptr,
358
  nullptr,
359
  nullptr,
360
  { nullptr, sChromeOnlyNativeProperties.Upcast() },
361
  prototypes::id::mozRTCIceCandidate,
362
  constructors::id::mozRTCIceCandidate,
363
  RTCIceCandidate_Binding::sNativePropertyHooks,
364
  &DefaultXrayExpandoObjectClass
365
} };
366
367
void
368
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
369
0
{
370
0
  JS::Handle<JSObject*> parentProto(RTCIceCandidate_Binding::GetProtoObjectHandle(aCx));
371
0
  if (!parentProto) {
372
0
    return;
373
0
  }
374
0
375
0
  JS::Handle<JSObject*> constructorProto(RTCIceCandidate_Binding::GetConstructorObjectHandle(aCx));
376
0
  if (!constructorProto) {
377
0
    return;
378
0
  }
379
0
380
0
  static bool sIdsInited = false;
381
0
  if (!sIdsInited && NS_IsMainThread()) {
382
0
    if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) {
383
0
      return;
384
0
    }
385
0
    sIdsInited = true;
386
0
  }
387
0
388
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::mozRTCIceCandidate);
389
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::mozRTCIceCandidate);
390
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
391
0
                              &sPrototypeClass.mBase, protoCache,
392
0
                              nullptr,
393
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
394
0
                              interfaceCache,
395
0
                              nullptr,
396
0
                              sChromeOnlyNativeProperties.Upcast(),
397
0
                              "mozRTCIceCandidate", aDefineOnGlobal,
398
0
                              nullptr,
399
0
                              false);
400
0
}
401
402
JSObject*
403
GetConstructorObject(JSContext* aCx)
404
0
{
405
0
  return GetConstructorObjectHandle(aCx);
406
0
}
407
408
} // namespace mozRTCIceCandidate_Binding
409
410
411
412
namespace mozRTCPeerConnection_Binding {
413
414
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<RTCPeerConnection_Binding::NativeType>::value,
415
              "Can't inherit from an interface with a different ownership model.");
416
417
static bool
418
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
419
0
{
420
0
  mozilla::dom::mozRTCPeerConnection* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::mozRTCPeerConnection>(obj);
421
0
  // We don't want to preserve if we don't have a wrapper, and we
422
0
  // obviously can't preserve if we're not initialized.
423
0
  if (self && self->GetWrapperPreserveColor()) {
424
0
    PreserveWrapper(self);
425
0
  }
426
0
  return true;
427
0
}
428
429
static void
430
_finalize(js::FreeOp* fop, JSObject* obj)
431
0
{
432
0
  mozilla::dom::mozRTCPeerConnection* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::mozRTCPeerConnection>(obj);
433
0
  if (self) {
434
0
    ClearWrapper(self, self, obj);
435
0
    AddForDeferredFinalization<mozilla::dom::mozRTCPeerConnection>(self);
436
0
  }
437
0
}
438
439
static size_t
440
_objectMoved(JSObject* obj, JSObject* old)
441
0
{
442
0
  mozilla::dom::mozRTCPeerConnection* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::mozRTCPeerConnection>(obj);
443
0
  if (self) {
444
0
    UpdateWrapper(self, self, obj, old);
445
0
  }
446
0
447
0
  return 0;
448
0
}
449
450
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
451
#if defined(__clang__)
452
#pragma clang diagnostic push
453
#pragma clang diagnostic ignored "-Wmissing-braces"
454
#endif
455
static const JSFunctionSpec sChromeStaticMethods_specs[] = {
456
  JS_FNSPEC("_create", mozRTCPeerConnection::_Create, nullptr, 2, 0, nullptr),
457
  JS_FS_END
458
};
459
#if defined(__clang__)
460
#pragma clang diagnostic pop
461
#endif
462
463
464
static const Prefable<const JSFunctionSpec> sChromeStaticMethods[] = {
465
  { nullptr, &sChromeStaticMethods_specs[0] },
466
  { nullptr, nullptr }
467
};
468
469
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
470
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
471
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
472
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
473
474
475
static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[1];
476
static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[1];
477
478
static const NativePropertiesN<1> sChromeOnlyNativeProperties = {
479
  true,  0 /* sChromeStaticMethods */,
480
  false, 0,
481
  false, 0,
482
  false, 0,
483
  false, 0,
484
  false, 0,
485
  false, 0,
486
  -1,
487
  1,
488
  sChromeOnlyNativeProperties_sortedPropertyIndices,
489
  {
490
    { sChromeStaticMethods, &sChromeOnlyNativeProperties_propertyInfos[0] }
491
  }
492
};
493
static_assert(1 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount),
494
    "We have a property info count that is oversized");
495
496
static bool
497
_constructor(JSContext* cx, unsigned argc, JS::Value* vp)
498
0
{
499
0
  AUTO_PROFILER_LABEL_FAST("mozRTCPeerConnection constructor", DOM, cx);
500
0
501
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
502
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
503
0
  if (!args.isConstructing()) {
504
0
    // XXXbz wish I could get the name from the callee instead of
505
0
    // Adding more relocations
506
0
    return ThrowConstructorWithoutNew(cx, "mozRTCPeerConnection");
507
0
  }
508
0
509
0
  JS::Rooted<JSObject*> desiredProto(cx);
510
0
  if (!GetDesiredProto(cx, args, &desiredProto)) {
511
0
    return false;
512
0
  }
513
0
514
0
  DeprecationWarning(cx, obj, nsIDocument::eWebrtcDeprecatedPrefix);
515
0
  GlobalObject global(cx, obj);
516
0
  if (global.Failed()) {
517
0
    return false;
518
0
  }
519
0
520
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
521
0
  binding_detail::FastRTCConfiguration arg0;
522
0
  if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue,  "Argument 1 of mozRTCPeerConnection.constructor", true)) {
523
0
    return false;
524
0
  }
525
0
  Optional<JS::Handle<JSObject*>> arg1;
526
0
  if (args.hasDefined(1)) {
527
0
    arg1.Construct(cx);
528
0
    if (args[1].isObject()) {
529
0
#ifdef __clang__
530
0
#pragma clang diagnostic push
531
0
#pragma clang diagnostic ignored "-Wunreachable-code"
532
0
#pragma clang diagnostic ignored "-Wunreachable-code-return"
533
0
#endif // __clang__
534
0
      if ((true) && !CallerSubsumes(args[1])) {
535
0
        ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "argument 2 of mozRTCPeerConnection.constructor");
536
0
        return false;
537
0
      }
538
0
#ifdef __clang__
539
0
#pragma clang diagnostic pop
540
0
#endif // __clang__
541
0
      arg1.Value() = &args[1].toObject();
542
0
    } else if (args[1].isNullOrUndefined()) {
543
0
      arg1.Value() = nullptr;
544
0
    } else {
545
0
      ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of mozRTCPeerConnection.constructor");
546
0
      return false;
547
0
    }
548
0
  }
549
0
  Maybe<JSAutoRealm> ar;
550
0
  if (objIsXray) {
551
0
    obj = js::CheckedUnwrap(obj);
552
0
    if (!obj) {
553
0
      return false;
554
0
    }
555
0
    ar.emplace(cx, obj);
556
0
    if (!JS_WrapObject(cx, &desiredProto)) {
557
0
      return false;
558
0
    }
559
0
    if (arg1.WasPassed()) {
560
0
      if (!JS_WrapObject(cx, &arg1.Value())) {
561
0
        return false;
562
0
      }
563
0
    }
564
0
  }
565
0
  FastErrorResult rv;
566
0
  auto result(StrongOrRawPtr<mozilla::dom::mozRTCPeerConnection>(mozilla::dom::mozRTCPeerConnection::Constructor(global, cx, Constify(arg0), Constify(arg1), rv, desiredProto)));
567
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
568
0
    return false;
569
0
  }
570
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
571
0
  static_assert(!IsPointer<decltype(result)>::value,
572
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
573
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
574
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
575
0
    return false;
576
0
  }
577
0
  return true;
578
0
}
579
580
static const js::ClassOps sInterfaceObjectClassOps = {
581
    nullptr,               /* addProperty */
582
    nullptr,               /* delProperty */
583
    nullptr,               /* enumerate */
584
    nullptr,               /* newEnumerate */
585
    nullptr,               /* resolve */
586
    nullptr,               /* mayResolve */
587
    nullptr,               /* finalize */
588
    _constructor, /* call */
589
    nullptr,               /* hasInstance */
590
    _constructor, /* construct */
591
    nullptr,               /* trace */
592
};
593
594
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
595
  {
596
    "Function",
597
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
598
    &sInterfaceObjectClassOps,
599
    JS_NULL_CLASS_SPEC,
600
    JS_NULL_CLASS_EXT,
601
    &sInterfaceObjectClassObjectOps
602
  },
603
  eInterface,
604
  true,
605
  prototypes::id::mozRTCPeerConnection,
606
  PrototypeTraits<prototypes::id::mozRTCPeerConnection>::Depth,
607
  sNativePropertyHooks,
608
  "function mozRTCPeerConnection() {\n    [native code]\n}",
609
  RTCPeerConnection_Binding::GetConstructorObject
610
};
611
612
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
613
  {
614
    "mozRTCPeerConnectionPrototype",
615
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
616
    JS_NULL_CLASS_OPS,
617
    JS_NULL_CLASS_SPEC,
618
    JS_NULL_CLASS_EXT,
619
    JS_NULL_OBJECT_OPS
620
  },
621
  eInterfacePrototype,
622
  false,
623
  prototypes::id::mozRTCPeerConnection,
624
  PrototypeTraits<prototypes::id::mozRTCPeerConnection>::Depth,
625
  sNativePropertyHooks,
626
  "[object mozRTCPeerConnectionPrototype]",
627
  RTCPeerConnection_Binding::GetProtoObject
628
};
629
630
bool
631
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
632
0
{
633
0
  static bool sPrefValue;
634
0
  static bool sPrefCacheSetUp = false;
635
0
  if (!sPrefCacheSetUp) {
636
0
    sPrefCacheSetUp = true;
637
0
    Preferences::AddBoolVarCache(&sPrefValue, "media.peerconnection.enabled");
638
0
  }
639
0
640
0
  return sPrefValue;
641
0
}
642
643
static const js::ClassOps sClassOps = {
644
  _addProperty, /* addProperty */
645
  nullptr,               /* delProperty */
646
  nullptr,               /* enumerate */
647
  nullptr, /* newEnumerate */
648
  nullptr, /* resolve */
649
  nullptr, /* mayResolve */
650
  _finalize, /* finalize */
651
  nullptr, /* call */
652
  nullptr,               /* hasInstance */
653
  nullptr,               /* construct */
654
  nullptr, /* trace */
655
};
656
657
static const js::ClassExtension sClassExtension = {
658
  nullptr, /* weakmapKeyDelegateOp */
659
  _objectMoved /* objectMovedOp */
660
};
661
662
static const DOMJSClass sClass = {
663
  { "mozRTCPeerConnection",
664
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
665
    &sClassOps,
666
    JS_NULL_CLASS_SPEC,
667
    &sClassExtension,
668
    JS_NULL_OBJECT_OPS
669
  },
670
  { prototypes::id::EventTarget, prototypes::id::RTCPeerConnection, prototypes::id::mozRTCPeerConnection, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
671
  IsBaseOf<nsISupports, mozilla::dom::mozRTCPeerConnection >::value,
672
  sNativePropertyHooks,
673
  FindAssociatedGlobalForNative<mozilla::dom::mozRTCPeerConnection>::Get,
674
  GetProtoObjectHandle,
675
  GetCCParticipant<mozilla::dom::mozRTCPeerConnection>::Get()
676
};
677
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
678
              "Must have the right minimal number of reserved slots.");
679
static_assert(1 >= 1,
680
              "Must have enough reserved slots.");
681
682
const JSClass*
683
GetJSClass()
684
0
{
685
0
  return sClass.ToJSClass();
686
0
}
687
688
bool
689
Wrap(JSContext* aCx, mozilla::dom::mozRTCPeerConnection* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
690
0
{
691
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::mozRTCPeerConnection>::value,
692
0
                "Shouldn't have wrappercached things that are not refcounted.");
693
0
  MOZ_ASSERT(static_cast<mozilla::dom::mozRTCPeerConnection*>(aObject) ==
694
0
             reinterpret_cast<mozilla::dom::mozRTCPeerConnection*>(aObject),
695
0
             "Multiple inheritance for mozilla::dom::mozRTCPeerConnection is broken.");
696
0
  MOZ_ASSERT(static_cast<mozilla::dom::RTCPeerConnection*>(aObject) ==
697
0
             reinterpret_cast<mozilla::dom::RTCPeerConnection*>(aObject),
698
0
             "Multiple inheritance for mozilla::dom::RTCPeerConnection is broken.");
699
0
  MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
700
0
             reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
701
0
             "Multiple inheritance for mozilla::dom::EventTarget is broken.");
702
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
703
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
704
0
  MOZ_ASSERT(!aCache->GetWrapper(),
705
0
             "You should probably not be using Wrap() directly; use "
706
0
             "GetOrCreateDOMReflector instead");
707
0
708
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
709
0
             "nsISupports must be on our primary inheritance chain");
710
0
711
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
712
0
  if (!global) {
713
0
    return false;
714
0
  }
715
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
716
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
717
0
718
0
  // That might have ended up wrapping us already, due to the wonders
719
0
  // of XBL.  Check for that, and bail out as needed.
720
0
  aReflector.set(aCache->GetWrapper());
721
0
  if (aReflector) {
722
#ifdef DEBUG
723
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
724
#endif // DEBUG
725
    return true;
726
0
  }
727
0
728
0
  JSAutoRealm ar(aCx, global);
729
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
730
0
  if (!canonicalProto) {
731
0
    return false;
732
0
  }
733
0
  JS::Rooted<JSObject*> proto(aCx);
734
0
  if (aGivenProto) {
735
0
    proto = aGivenProto;
736
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
737
0
    // coming in, we changed compartments to that of "parent" so may need
738
0
    // to wrap the proto here.
739
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
740
0
      if (!JS_WrapObject(aCx, &proto)) {
741
0
        return false;
742
0
      }
743
0
    }
744
0
  } else {
745
0
    proto = canonicalProto;
746
0
  }
747
0
748
0
  BindingJSObjectCreator<mozilla::dom::mozRTCPeerConnection> creator(aCx);
749
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
750
0
  if (!aReflector) {
751
0
    return false;
752
0
  }
753
0
754
0
  aCache->SetWrapper(aReflector);
755
0
  creator.InitializationSucceeded();
756
0
757
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
758
0
             aCache->GetWrapperPreserveColor() == aReflector);
759
0
  // If proto != canonicalProto, we have to preserve our wrapper;
760
0
  // otherwise we won't be able to properly recreate it later, since
761
0
  // we won't know what proto to use.  Note that we don't check
762
0
  // aGivenProto here, since it's entirely possible (and even
763
0
  // somewhat common) to have a non-null aGivenProto which is the
764
0
  // same as canonicalProto.
765
0
  if (proto != canonicalProto) {
766
0
    PreserveWrapper(aObject);
767
0
  }
768
0
769
0
  return true;
770
0
}
771
772
const NativePropertyHooks sNativePropertyHooks[] = { {
773
  nullptr,
774
  nullptr,
775
  nullptr,
776
  { nullptr, sChromeOnlyNativeProperties.Upcast() },
777
  prototypes::id::mozRTCPeerConnection,
778
  constructors::id::mozRTCPeerConnection,
779
  RTCPeerConnection_Binding::sNativePropertyHooks,
780
  &DefaultXrayExpandoObjectClass
781
} };
782
783
void
784
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
785
0
{
786
0
  JS::Handle<JSObject*> parentProto(RTCPeerConnection_Binding::GetProtoObjectHandle(aCx));
787
0
  if (!parentProto) {
788
0
    return;
789
0
  }
790
0
791
0
  JS::Handle<JSObject*> constructorProto(RTCPeerConnection_Binding::GetConstructorObjectHandle(aCx));
792
0
  if (!constructorProto) {
793
0
    return;
794
0
  }
795
0
796
0
  static bool sIdsInited = false;
797
0
  if (!sIdsInited && NS_IsMainThread()) {
798
0
    if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) {
799
0
      return;
800
0
    }
801
0
    sIdsInited = true;
802
0
  }
803
0
804
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::mozRTCPeerConnection);
805
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::mozRTCPeerConnection);
806
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
807
0
                              &sPrototypeClass.mBase, protoCache,
808
0
                              nullptr,
809
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
810
0
                              interfaceCache,
811
0
                              nullptr,
812
0
                              sChromeOnlyNativeProperties.Upcast(),
813
0
                              "mozRTCPeerConnection", aDefineOnGlobal,
814
0
                              nullptr,
815
0
                              false);
816
0
}
817
818
JSObject*
819
GetConstructorObject(JSContext* aCx)
820
0
{
821
0
  return GetConstructorObjectHandle(aCx);
822
0
}
823
824
} // namespace mozRTCPeerConnection_Binding
825
826
827
828
namespace mozRTCSessionDescription_Binding {
829
830
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<RTCSessionDescription_Binding::NativeType>::value,
831
              "Can't inherit from an interface with a different ownership model.");
832
833
static bool
834
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
835
0
{
836
0
  mozilla::dom::mozRTCSessionDescription* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::mozRTCSessionDescription>(obj);
837
0
  // We don't want to preserve if we don't have a wrapper, and we
838
0
  // obviously can't preserve if we're not initialized.
839
0
  if (self && self->GetWrapperPreserveColor()) {
840
0
    PreserveWrapper(self);
841
0
  }
842
0
  return true;
843
0
}
844
845
static void
846
_finalize(js::FreeOp* fop, JSObject* obj)
847
0
{
848
0
  mozilla::dom::mozRTCSessionDescription* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::mozRTCSessionDescription>(obj);
849
0
  if (self) {
850
0
    ClearWrapper(self, self, obj);
851
0
    AddForDeferredFinalization<mozilla::dom::mozRTCSessionDescription>(self);
852
0
  }
853
0
}
854
855
static size_t
856
_objectMoved(JSObject* obj, JSObject* old)
857
0
{
858
0
  mozilla::dom::mozRTCSessionDescription* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::mozRTCSessionDescription>(obj);
859
0
  if (self) {
860
0
    UpdateWrapper(self, self, obj, old);
861
0
  }
862
0
863
0
  return 0;
864
0
}
865
866
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
867
#if defined(__clang__)
868
#pragma clang diagnostic push
869
#pragma clang diagnostic ignored "-Wmissing-braces"
870
#endif
871
static const JSFunctionSpec sChromeStaticMethods_specs[] = {
872
  JS_FNSPEC("_create", mozRTCSessionDescription::_Create, nullptr, 2, 0, nullptr),
873
  JS_FS_END
874
};
875
#if defined(__clang__)
876
#pragma clang diagnostic pop
877
#endif
878
879
880
static const Prefable<const JSFunctionSpec> sChromeStaticMethods[] = {
881
  { nullptr, &sChromeStaticMethods_specs[0] },
882
  { nullptr, nullptr }
883
};
884
885
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
886
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
887
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
888
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
889
890
891
static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[1];
892
static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[1];
893
894
static const NativePropertiesN<1> sChromeOnlyNativeProperties = {
895
  true,  0 /* sChromeStaticMethods */,
896
  false, 0,
897
  false, 0,
898
  false, 0,
899
  false, 0,
900
  false, 0,
901
  false, 0,
902
  -1,
903
  1,
904
  sChromeOnlyNativeProperties_sortedPropertyIndices,
905
  {
906
    { sChromeStaticMethods, &sChromeOnlyNativeProperties_propertyInfos[0] }
907
  }
908
};
909
static_assert(1 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount),
910
    "We have a property info count that is oversized");
911
912
static bool
913
_constructor(JSContext* cx, unsigned argc, JS::Value* vp)
914
0
{
915
0
  AUTO_PROFILER_LABEL_FAST("mozRTCSessionDescription constructor", DOM, cx);
916
0
917
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
918
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
919
0
  if (!args.isConstructing()) {
920
0
    // XXXbz wish I could get the name from the callee instead of
921
0
    // Adding more relocations
922
0
    return ThrowConstructorWithoutNew(cx, "mozRTCSessionDescription");
923
0
  }
924
0
925
0
  JS::Rooted<JSObject*> desiredProto(cx);
926
0
  if (!GetDesiredProto(cx, args, &desiredProto)) {
927
0
    return false;
928
0
  }
929
0
930
0
  DeprecationWarning(cx, obj, nsIDocument::eWebrtcDeprecatedPrefix);
931
0
  GlobalObject global(cx, obj);
932
0
  if (global.Failed()) {
933
0
    return false;
934
0
  }
935
0
936
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
937
0
  binding_detail::FastRTCSessionDescriptionInit arg0;
938
0
  if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue,  "Argument 1 of mozRTCSessionDescription.constructor", true)) {
939
0
    return false;
940
0
  }
941
0
  Maybe<JSAutoRealm> ar;
942
0
  if (objIsXray) {
943
0
    obj = js::CheckedUnwrap(obj);
944
0
    if (!obj) {
945
0
      return false;
946
0
    }
947
0
    ar.emplace(cx, obj);
948
0
    if (!JS_WrapObject(cx, &desiredProto)) {
949
0
      return false;
950
0
    }
951
0
  }
952
0
  FastErrorResult rv;
953
0
  auto result(StrongOrRawPtr<mozilla::dom::mozRTCSessionDescription>(mozilla::dom::mozRTCSessionDescription::Constructor(global, cx, Constify(arg0), rv, desiredProto)));
954
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
955
0
    return false;
956
0
  }
957
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
958
0
  static_assert(!IsPointer<decltype(result)>::value,
959
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
960
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
961
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
962
0
    return false;
963
0
  }
964
0
  return true;
965
0
}
966
967
static const js::ClassOps sInterfaceObjectClassOps = {
968
    nullptr,               /* addProperty */
969
    nullptr,               /* delProperty */
970
    nullptr,               /* enumerate */
971
    nullptr,               /* newEnumerate */
972
    nullptr,               /* resolve */
973
    nullptr,               /* mayResolve */
974
    nullptr,               /* finalize */
975
    _constructor, /* call */
976
    nullptr,               /* hasInstance */
977
    _constructor, /* construct */
978
    nullptr,               /* trace */
979
};
980
981
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
982
  {
983
    "Function",
984
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
985
    &sInterfaceObjectClassOps,
986
    JS_NULL_CLASS_SPEC,
987
    JS_NULL_CLASS_EXT,
988
    &sInterfaceObjectClassObjectOps
989
  },
990
  eInterface,
991
  true,
992
  prototypes::id::mozRTCSessionDescription,
993
  PrototypeTraits<prototypes::id::mozRTCSessionDescription>::Depth,
994
  sNativePropertyHooks,
995
  "function mozRTCSessionDescription() {\n    [native code]\n}",
996
  RTCSessionDescription_Binding::GetConstructorObject
997
};
998
999
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
1000
  {
1001
    "mozRTCSessionDescriptionPrototype",
1002
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
1003
    JS_NULL_CLASS_OPS,
1004
    JS_NULL_CLASS_SPEC,
1005
    JS_NULL_CLASS_EXT,
1006
    JS_NULL_OBJECT_OPS
1007
  },
1008
  eInterfacePrototype,
1009
  false,
1010
  prototypes::id::mozRTCSessionDescription,
1011
  PrototypeTraits<prototypes::id::mozRTCSessionDescription>::Depth,
1012
  sNativePropertyHooks,
1013
  "[object mozRTCSessionDescriptionPrototype]",
1014
  RTCSessionDescription_Binding::GetProtoObject
1015
};
1016
1017
bool
1018
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
1019
0
{
1020
0
  static bool sPrefValue;
1021
0
  static bool sPrefCacheSetUp = false;
1022
0
  if (!sPrefCacheSetUp) {
1023
0
    sPrefCacheSetUp = true;
1024
0
    Preferences::AddBoolVarCache(&sPrefValue, "media.peerconnection.enabled");
1025
0
  }
1026
0
1027
0
  return sPrefValue;
1028
0
}
1029
1030
static const js::ClassOps sClassOps = {
1031
  _addProperty, /* addProperty */
1032
  nullptr,               /* delProperty */
1033
  nullptr,               /* enumerate */
1034
  nullptr, /* newEnumerate */
1035
  nullptr, /* resolve */
1036
  nullptr, /* mayResolve */
1037
  _finalize, /* finalize */
1038
  nullptr, /* call */
1039
  nullptr,               /* hasInstance */
1040
  nullptr,               /* construct */
1041
  nullptr, /* trace */
1042
};
1043
1044
static const js::ClassExtension sClassExtension = {
1045
  nullptr, /* weakmapKeyDelegateOp */
1046
  _objectMoved /* objectMovedOp */
1047
};
1048
1049
static const DOMJSClass sClass = {
1050
  { "mozRTCSessionDescription",
1051
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
1052
    &sClassOps,
1053
    JS_NULL_CLASS_SPEC,
1054
    &sClassExtension,
1055
    JS_NULL_OBJECT_OPS
1056
  },
1057
  { prototypes::id::RTCSessionDescription, prototypes::id::mozRTCSessionDescription, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
1058
  IsBaseOf<nsISupports, mozilla::dom::mozRTCSessionDescription >::value,
1059
  sNativePropertyHooks,
1060
  FindAssociatedGlobalForNative<mozilla::dom::mozRTCSessionDescription>::Get,
1061
  GetProtoObjectHandle,
1062
  GetCCParticipant<mozilla::dom::mozRTCSessionDescription>::Get()
1063
};
1064
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
1065
              "Must have the right minimal number of reserved slots.");
1066
static_assert(1 >= 1,
1067
              "Must have enough reserved slots.");
1068
1069
const JSClass*
1070
GetJSClass()
1071
0
{
1072
0
  return sClass.ToJSClass();
1073
0
}
1074
1075
bool
1076
Wrap(JSContext* aCx, mozilla::dom::mozRTCSessionDescription* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
1077
0
{
1078
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::mozRTCSessionDescription>::value,
1079
0
                "Shouldn't have wrappercached things that are not refcounted.");
1080
0
  MOZ_ASSERT(static_cast<mozilla::dom::mozRTCSessionDescription*>(aObject) ==
1081
0
             reinterpret_cast<mozilla::dom::mozRTCSessionDescription*>(aObject),
1082
0
             "Multiple inheritance for mozilla::dom::mozRTCSessionDescription is broken.");
1083
0
  MOZ_ASSERT(static_cast<mozilla::dom::RTCSessionDescription*>(aObject) ==
1084
0
             reinterpret_cast<mozilla::dom::RTCSessionDescription*>(aObject),
1085
0
             "Multiple inheritance for mozilla::dom::RTCSessionDescription is broken.");
1086
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
1087
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
1088
0
  MOZ_ASSERT(!aCache->GetWrapper(),
1089
0
             "You should probably not be using Wrap() directly; use "
1090
0
             "GetOrCreateDOMReflector instead");
1091
0
1092
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
1093
0
             "nsISupports must be on our primary inheritance chain");
1094
0
1095
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
1096
0
  if (!global) {
1097
0
    return false;
1098
0
  }
1099
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
1100
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
1101
0
1102
0
  // That might have ended up wrapping us already, due to the wonders
1103
0
  // of XBL.  Check for that, and bail out as needed.
1104
0
  aReflector.set(aCache->GetWrapper());
1105
0
  if (aReflector) {
1106
#ifdef DEBUG
1107
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
1108
#endif // DEBUG
1109
    return true;
1110
0
  }
1111
0
1112
0
  JSAutoRealm ar(aCx, global);
1113
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
1114
0
  if (!canonicalProto) {
1115
0
    return false;
1116
0
  }
1117
0
  JS::Rooted<JSObject*> proto(aCx);
1118
0
  if (aGivenProto) {
1119
0
    proto = aGivenProto;
1120
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
1121
0
    // coming in, we changed compartments to that of "parent" so may need
1122
0
    // to wrap the proto here.
1123
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
1124
0
      if (!JS_WrapObject(aCx, &proto)) {
1125
0
        return false;
1126
0
      }
1127
0
    }
1128
0
  } else {
1129
0
    proto = canonicalProto;
1130
0
  }
1131
0
1132
0
  BindingJSObjectCreator<mozilla::dom::mozRTCSessionDescription> creator(aCx);
1133
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
1134
0
  if (!aReflector) {
1135
0
    return false;
1136
0
  }
1137
0
1138
0
  aCache->SetWrapper(aReflector);
1139
0
  creator.InitializationSucceeded();
1140
0
1141
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
1142
0
             aCache->GetWrapperPreserveColor() == aReflector);
1143
0
  // If proto != canonicalProto, we have to preserve our wrapper;
1144
0
  // otherwise we won't be able to properly recreate it later, since
1145
0
  // we won't know what proto to use.  Note that we don't check
1146
0
  // aGivenProto here, since it's entirely possible (and even
1147
0
  // somewhat common) to have a non-null aGivenProto which is the
1148
0
  // same as canonicalProto.
1149
0
  if (proto != canonicalProto) {
1150
0
    PreserveWrapper(aObject);
1151
0
  }
1152
0
1153
0
  return true;
1154
0
}
1155
1156
const NativePropertyHooks sNativePropertyHooks[] = { {
1157
  nullptr,
1158
  nullptr,
1159
  nullptr,
1160
  { nullptr, sChromeOnlyNativeProperties.Upcast() },
1161
  prototypes::id::mozRTCSessionDescription,
1162
  constructors::id::mozRTCSessionDescription,
1163
  RTCSessionDescription_Binding::sNativePropertyHooks,
1164
  &DefaultXrayExpandoObjectClass
1165
} };
1166
1167
void
1168
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
1169
0
{
1170
0
  JS::Handle<JSObject*> parentProto(RTCSessionDescription_Binding::GetProtoObjectHandle(aCx));
1171
0
  if (!parentProto) {
1172
0
    return;
1173
0
  }
1174
0
1175
0
  JS::Handle<JSObject*> constructorProto(RTCSessionDescription_Binding::GetConstructorObjectHandle(aCx));
1176
0
  if (!constructorProto) {
1177
0
    return;
1178
0
  }
1179
0
1180
0
  static bool sIdsInited = false;
1181
0
  if (!sIdsInited && NS_IsMainThread()) {
1182
0
    if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) {
1183
0
      return;
1184
0
    }
1185
0
    sIdsInited = true;
1186
0
  }
1187
0
1188
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::mozRTCSessionDescription);
1189
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::mozRTCSessionDescription);
1190
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
1191
0
                              &sPrototypeClass.mBase, protoCache,
1192
0
                              nullptr,
1193
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
1194
0
                              interfaceCache,
1195
0
                              nullptr,
1196
0
                              sChromeOnlyNativeProperties.Upcast(),
1197
0
                              "mozRTCSessionDescription", aDefineOnGlobal,
1198
0
                              nullptr,
1199
0
                              false);
1200
0
}
1201
1202
JSObject*
1203
GetConstructorObject(JSContext* aCx)
1204
0
{
1205
0
  return GetConstructorObjectHandle(aCx);
1206
0
}
1207
1208
} // namespace mozRTCSessionDescription_Binding
1209
1210
1211
1212
void
1213
mozRTCIceCandidateJSImpl::__Init(const RTCIceCandidateInit& candidateInitDict, ErrorResult& aRv, JS::Realm* aRealm)
1214
0
{
1215
0
  CallSetup s(this, aRv, "__init", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
1216
0
  JSContext* cx = s.GetContext();
1217
0
  if (!cx) {
1218
0
    MOZ_ASSERT(aRv.Failed());
1219
0
    return;
1220
0
  }
1221
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
1222
0
  JS::AutoValueVector argv(cx);
1223
0
  if (!argv.resize(1)) {
1224
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
1225
0
    return;
1226
0
  }
1227
0
  unsigned argc = 1;
1228
0
1229
0
  do {
1230
0
    if (!candidateInitDict.ToObjectInternal(cx, argv[0])) {
1231
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
1232
0
      return;
1233
0
    }
1234
0
    break;
1235
0
  } while (false);
1236
0
1237
0
  JS::Rooted<JS::Value> callable(cx);
1238
0
  mozRTCIceCandidateAtoms* atomsCache = GetAtomCache<mozRTCIceCandidateAtoms>(cx);
1239
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
1240
0
      !GetCallableProperty(cx, atomsCache->__init_id, &callable)) {
1241
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
1242
0
    return;
1243
0
  }
1244
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
1245
0
  if (!JS::Call(cx, thisValue, callable,
1246
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
1247
0
    aRv.NoteJSContextException(cx);
1248
0
    return;
1249
0
  }
1250
0
}
1251
1252
bool
1253
mozRTCIceCandidateJSImpl::InitIds(JSContext* cx, mozRTCIceCandidateAtoms* atomsCache)
1254
0
{
1255
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
1256
0
1257
0
  // Initialize these in reverse order so that any failure leaves the first one
1258
0
  // uninitialized.
1259
0
  if (!atomsCache->__init_id.init(cx, "__init")) {
1260
0
    return false;
1261
0
  }
1262
0
  return true;
1263
0
}
1264
1265
1266
1267
NS_IMPL_CYCLE_COLLECTION_INHERITED(mozRTCIceCandidate, mozilla::dom::RTCIceCandidate, mImpl, mParent)
1268
NS_IMPL_ADDREF_INHERITED(mozRTCIceCandidate, mozilla::dom::RTCIceCandidate)
1269
NS_IMPL_RELEASE_INHERITED(mozRTCIceCandidate, mozilla::dom::RTCIceCandidate)
1270
0
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(mozRTCIceCandidate)
1271
0
NS_INTERFACE_MAP_END_INHERITING(mozilla::dom::RTCIceCandidate)
1272
1273
mozRTCIceCandidate::mozRTCIceCandidate(JS::Handle<JSObject*> aJSImplObject, JS::Handle<JSObject*> aJSImplGlobal, nsIGlobalObject* aParent)
1274
  : mozilla::dom::RTCIceCandidate(aJSImplObject, aJSImplGlobal, aParent),
1275
    mImpl(new mozRTCIceCandidateJSImpl(nullptr, aJSImplObject, aJSImplGlobal, /* aIncumbentGlobal = */ nullptr)),
1276
    mParent(aParent)
1277
0
{
1278
0
}
1279
1280
1281
mozRTCIceCandidate::~mozRTCIceCandidate()
1282
0
{
1283
0
}
1284
1285
nsISupports*
1286
mozRTCIceCandidate::GetParentObject() const
1287
0
{
1288
0
  return mParent;
1289
0
}
1290
1291
JSObject*
1292
mozRTCIceCandidate::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
1293
0
{
1294
0
  JS::Rooted<JSObject*> obj(aCx, mozRTCIceCandidate_Binding::Wrap(aCx, this, aGivenProto));
1295
0
  if (!obj) {
1296
0
    return nullptr;
1297
0
  }
1298
0
1299
0
  // Now define it on our chrome object
1300
0
  JSAutoRealm ar(aCx, mImpl->CallbackGlobalOrNull());
1301
0
  if (!JS_WrapObject(aCx, &obj)) {
1302
0
    return nullptr;
1303
0
  }
1304
0
  if (!JS_DefineProperty(aCx, mImpl->CallbackOrNull(), "__DOM_IMPL__", obj, 0)) {
1305
0
    return nullptr;
1306
0
  }
1307
0
  return obj;
1308
0
}
1309
1310
already_AddRefed<mozRTCIceCandidate>
1311
mozRTCIceCandidate::Constructor(const GlobalObject& global, JSContext* cx, const RTCIceCandidateInit& candidateInitDict, ErrorResult& aRv, JS::Handle<JSObject*> aGivenProto)
1312
0
{
1313
0
  JS::Rooted<JSObject*> jsImplObj(cx);
1314
0
  nsCOMPtr<nsIGlobalObject> globalHolder =
1315
0
    ConstructJSImplementation("@mozilla.org/dom/rtcicecandidate;1", global, &jsImplObj, aRv);
1316
0
  if (aRv.Failed()) {
1317
0
    return nullptr;
1318
0
  }
1319
0
  // We should be getting the implementation object for the relevant
1320
0
  // contract here, which should never be a cross-compartment wrapper.
1321
0
  JS::Rooted<JSObject*> jsImplGlobal(cx, JS::GetNonCCWObjectGlobal(jsImplObj));
1322
0
  // Build the C++ implementation.
1323
0
  RefPtr<mozRTCIceCandidate> impl = new mozRTCIceCandidate(jsImplObj, jsImplGlobal, globalHolder);
1324
0
  // Wrap the object before calling __Init so that __DOM_IMPL__ is available.
1325
0
  JS::Rooted<JSObject*> scopeObj(cx, globalHolder->GetGlobalJSObject());
1326
0
  MOZ_ASSERT(js::IsObjectInContextCompartment(scopeObj, cx));
1327
0
  JS::Rooted<JS::Value> wrappedVal(cx);
1328
0
  if (!GetOrCreateDOMReflector(cx, impl, &wrappedVal, aGivenProto)) {
1329
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
1330
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
1331
0
    return nullptr;
1332
0
  }
1333
0
  // Initialize the object with the constructor arguments.
1334
0
  impl->mImpl->__Init(candidateInitDict, aRv, js::GetNonCCWObjectRealm(scopeObj));
1335
0
  if (aRv.Failed()) {
1336
0
    return nullptr;
1337
0
  }
1338
0
  return impl.forget();
1339
0
}
1340
1341
bool
1342
mozRTCIceCandidate::_Create(JSContext* cx, unsigned argc, JS::Value* vp)
1343
0
{
1344
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
1345
0
  if (args.length() < 2) {
1346
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "mozRTCIceCandidate._create");
1347
0
  }
1348
0
  if (!args[0].isObject()) {
1349
0
    return ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of mozRTCIceCandidate._create");
1350
0
  }
1351
0
  if (!args[1].isObject()) {
1352
0
    return ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of mozRTCIceCandidate._create");
1353
0
  }
1354
0
1355
0
  // GlobalObject will go through wrappers as needed for us, and
1356
0
  // is simpler than the right UnwrapArg incantation.
1357
0
  GlobalObject global(cx, &args[0].toObject());
1358
0
  if (global.Failed()) {
1359
0
    return false;
1360
0
  }
1361
0
  nsCOMPtr<nsIGlobalObject> globalHolder = do_QueryInterface(global.GetAsSupports());
1362
0
  MOZ_ASSERT(globalHolder);
1363
0
  JS::Rooted<JSObject*> arg(cx, &args[1].toObject());
1364
0
  JS::Rooted<JSObject*> argGlobal(cx, JS::CurrentGlobalOrNull(cx));
1365
0
  RefPtr<mozRTCIceCandidate> impl = new mozRTCIceCandidate(arg, argGlobal, globalHolder);
1366
0
  MOZ_ASSERT(js::IsObjectInContextCompartment(arg, cx));
1367
0
  return GetOrCreateDOMReflector(cx, impl, args.rval());
1368
0
}
1369
1370
1371
void
1372
mozRTCPeerConnectionJSImpl::__Init(const RTCConfiguration& configuration, const Optional<JS::Handle<JSObject*>>& constraints, ErrorResult& aRv, JS::Realm* aRealm)
1373
0
{
1374
0
  CallSetup s(this, aRv, "__init", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
1375
0
  JSContext* cx = s.GetContext();
1376
0
  if (!cx) {
1377
0
    MOZ_ASSERT(aRv.Failed());
1378
0
    return;
1379
0
  }
1380
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
1381
0
  JS::AutoValueVector argv(cx);
1382
0
  if (!argv.resize(2)) {
1383
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
1384
0
    return;
1385
0
  }
1386
0
  unsigned argc = 2;
1387
0
1388
0
  do {
1389
0
    if (constraints.WasPassed()) {
1390
0
      if (constraints.Value()) {
1391
0
                    JS::ExposeObjectToActiveJS(constraints.Value());
1392
0
                  }
1393
0
                  argv[1].setObjectOrNull(constraints.Value());
1394
0
      if (!MaybeWrapObjectOrNullValue(cx, argv[1])) {
1395
0
        aRv.Throw(NS_ERROR_UNEXPECTED);
1396
0
        return;
1397
0
      }
1398
0
      break;
1399
0
    } else if (argc == 2) {
1400
0
      // This is our current trailing argument; reduce argc
1401
0
      --argc;
1402
0
    } else {
1403
0
      argv[1].setUndefined();
1404
0
    }
1405
0
  } while (false);
1406
0
1407
0
  do {
1408
0
    if (!configuration.ToObjectInternal(cx, argv[0])) {
1409
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
1410
0
      return;
1411
0
    }
1412
0
    break;
1413
0
  } while (false);
1414
0
1415
0
  JS::Rooted<JS::Value> callable(cx);
1416
0
  mozRTCPeerConnectionAtoms* atomsCache = GetAtomCache<mozRTCPeerConnectionAtoms>(cx);
1417
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
1418
0
      !GetCallableProperty(cx, atomsCache->__init_id, &callable)) {
1419
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
1420
0
    return;
1421
0
  }
1422
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
1423
0
  if (!JS::Call(cx, thisValue, callable,
1424
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
1425
0
    aRv.NoteJSContextException(cx);
1426
0
    return;
1427
0
  }
1428
0
}
1429
1430
bool
1431
mozRTCPeerConnectionJSImpl::InitIds(JSContext* cx, mozRTCPeerConnectionAtoms* atomsCache)
1432
0
{
1433
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
1434
0
1435
0
  // Initialize these in reverse order so that any failure leaves the first one
1436
0
  // uninitialized.
1437
0
  if (!atomsCache->__init_id.init(cx, "__init")) {
1438
0
    return false;
1439
0
  }
1440
0
  return true;
1441
0
}
1442
1443
1444
1445
NS_IMPL_CYCLE_COLLECTION_INHERITED(mozRTCPeerConnection, mozilla::dom::RTCPeerConnection, mImpl, mParent)
1446
NS_IMPL_ADDREF_INHERITED(mozRTCPeerConnection, mozilla::dom::RTCPeerConnection)
1447
NS_IMPL_RELEASE_INHERITED(mozRTCPeerConnection, mozilla::dom::RTCPeerConnection)
1448
0
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(mozRTCPeerConnection)
1449
0
NS_INTERFACE_MAP_END_INHERITING(mozilla::dom::RTCPeerConnection)
1450
1451
mozRTCPeerConnection::mozRTCPeerConnection(JS::Handle<JSObject*> aJSImplObject, JS::Handle<JSObject*> aJSImplGlobal, nsIGlobalObject* aParent)
1452
  : mozilla::dom::RTCPeerConnection(aJSImplObject, aJSImplGlobal, aParent),
1453
    mImpl(new mozRTCPeerConnectionJSImpl(nullptr, aJSImplObject, aJSImplGlobal, /* aIncumbentGlobal = */ nullptr)),
1454
    mParent(aParent)
1455
0
{
1456
0
}
1457
1458
1459
mozRTCPeerConnection::~mozRTCPeerConnection()
1460
0
{
1461
0
}
1462
1463
nsISupports*
1464
mozRTCPeerConnection::GetParentObject() const
1465
0
{
1466
0
  return mParent;
1467
0
}
1468
1469
JSObject*
1470
mozRTCPeerConnection::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
1471
0
{
1472
0
  JS::Rooted<JSObject*> obj(aCx, mozRTCPeerConnection_Binding::Wrap(aCx, this, aGivenProto));
1473
0
  if (!obj) {
1474
0
    return nullptr;
1475
0
  }
1476
0
1477
0
  // Now define it on our chrome object
1478
0
  JSAutoRealm ar(aCx, mImpl->CallbackGlobalOrNull());
1479
0
  if (!JS_WrapObject(aCx, &obj)) {
1480
0
    return nullptr;
1481
0
  }
1482
0
  if (!JS_DefineProperty(aCx, mImpl->CallbackOrNull(), "__DOM_IMPL__", obj, 0)) {
1483
0
    return nullptr;
1484
0
  }
1485
0
  return obj;
1486
0
}
1487
1488
already_AddRefed<mozRTCPeerConnection>
1489
mozRTCPeerConnection::Constructor(const GlobalObject& global, JSContext* cx, const RTCConfiguration& configuration, const Optional<JS::Handle<JSObject*>>& constraints, ErrorResult& aRv, JS::Handle<JSObject*> aGivenProto)
1490
0
{
1491
0
  JS::Rooted<JSObject*> jsImplObj(cx);
1492
0
  nsCOMPtr<nsIGlobalObject> globalHolder =
1493
0
    ConstructJSImplementation("@mozilla.org/dom/peerconnection;1", global, &jsImplObj, aRv);
1494
0
  if (aRv.Failed()) {
1495
0
    return nullptr;
1496
0
  }
1497
0
  // We should be getting the implementation object for the relevant
1498
0
  // contract here, which should never be a cross-compartment wrapper.
1499
0
  JS::Rooted<JSObject*> jsImplGlobal(cx, JS::GetNonCCWObjectGlobal(jsImplObj));
1500
0
  // Build the C++ implementation.
1501
0
  RefPtr<mozRTCPeerConnection> impl = new mozRTCPeerConnection(jsImplObj, jsImplGlobal, globalHolder);
1502
0
  // Wrap the object before calling __Init so that __DOM_IMPL__ is available.
1503
0
  JS::Rooted<JSObject*> scopeObj(cx, globalHolder->GetGlobalJSObject());
1504
0
  MOZ_ASSERT(js::IsObjectInContextCompartment(scopeObj, cx));
1505
0
  JS::Rooted<JS::Value> wrappedVal(cx);
1506
0
  if (!GetOrCreateDOMReflector(cx, impl, &wrappedVal, aGivenProto)) {
1507
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
1508
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
1509
0
    return nullptr;
1510
0
  }
1511
0
  // Initialize the object with the constructor arguments.
1512
0
  impl->mImpl->__Init(configuration, constraints, aRv, js::GetNonCCWObjectRealm(scopeObj));
1513
0
  if (aRv.Failed()) {
1514
0
    return nullptr;
1515
0
  }
1516
0
  return impl.forget();
1517
0
}
1518
1519
bool
1520
mozRTCPeerConnection::_Create(JSContext* cx, unsigned argc, JS::Value* vp)
1521
0
{
1522
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
1523
0
  if (args.length() < 2) {
1524
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "mozRTCPeerConnection._create");
1525
0
  }
1526
0
  if (!args[0].isObject()) {
1527
0
    return ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of mozRTCPeerConnection._create");
1528
0
  }
1529
0
  if (!args[1].isObject()) {
1530
0
    return ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of mozRTCPeerConnection._create");
1531
0
  }
1532
0
1533
0
  // GlobalObject will go through wrappers as needed for us, and
1534
0
  // is simpler than the right UnwrapArg incantation.
1535
0
  GlobalObject global(cx, &args[0].toObject());
1536
0
  if (global.Failed()) {
1537
0
    return false;
1538
0
  }
1539
0
  nsCOMPtr<nsIGlobalObject> globalHolder = do_QueryInterface(global.GetAsSupports());
1540
0
  MOZ_ASSERT(globalHolder);
1541
0
  JS::Rooted<JSObject*> arg(cx, &args[1].toObject());
1542
0
  JS::Rooted<JSObject*> argGlobal(cx, JS::CurrentGlobalOrNull(cx));
1543
0
  RefPtr<mozRTCPeerConnection> impl = new mozRTCPeerConnection(arg, argGlobal, globalHolder);
1544
0
  MOZ_ASSERT(js::IsObjectInContextCompartment(arg, cx));
1545
0
  return GetOrCreateDOMReflector(cx, impl, args.rval());
1546
0
}
1547
1548
1549
void
1550
mozRTCSessionDescriptionJSImpl::__Init(const RTCSessionDescriptionInit& descriptionInitDict, ErrorResult& aRv, JS::Realm* aRealm)
1551
0
{
1552
0
  CallSetup s(this, aRv, "__init", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true);
1553
0
  JSContext* cx = s.GetContext();
1554
0
  if (!cx) {
1555
0
    MOZ_ASSERT(aRv.Failed());
1556
0
    return;
1557
0
  }
1558
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
1559
0
  JS::AutoValueVector argv(cx);
1560
0
  if (!argv.resize(1)) {
1561
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
1562
0
    return;
1563
0
  }
1564
0
  unsigned argc = 1;
1565
0
1566
0
  do {
1567
0
    if (!descriptionInitDict.ToObjectInternal(cx, argv[0])) {
1568
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
1569
0
      return;
1570
0
    }
1571
0
    break;
1572
0
  } while (false);
1573
0
1574
0
  JS::Rooted<JS::Value> callable(cx);
1575
0
  mozRTCSessionDescriptionAtoms* atomsCache = GetAtomCache<mozRTCSessionDescriptionAtoms>(cx);
1576
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
1577
0
      !GetCallableProperty(cx, atomsCache->__init_id, &callable)) {
1578
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
1579
0
    return;
1580
0
  }
1581
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
1582
0
  if (!JS::Call(cx, thisValue, callable,
1583
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
1584
0
    aRv.NoteJSContextException(cx);
1585
0
    return;
1586
0
  }
1587
0
}
1588
1589
bool
1590
mozRTCSessionDescriptionJSImpl::InitIds(JSContext* cx, mozRTCSessionDescriptionAtoms* atomsCache)
1591
0
{
1592
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
1593
0
1594
0
  // Initialize these in reverse order so that any failure leaves the first one
1595
0
  // uninitialized.
1596
0
  if (!atomsCache->__init_id.init(cx, "__init")) {
1597
0
    return false;
1598
0
  }
1599
0
  return true;
1600
0
}
1601
1602
1603
1604
NS_IMPL_CYCLE_COLLECTION_INHERITED(mozRTCSessionDescription, mozilla::dom::RTCSessionDescription, mImpl, mParent)
1605
NS_IMPL_ADDREF_INHERITED(mozRTCSessionDescription, mozilla::dom::RTCSessionDescription)
1606
NS_IMPL_RELEASE_INHERITED(mozRTCSessionDescription, mozilla::dom::RTCSessionDescription)
1607
0
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(mozRTCSessionDescription)
1608
0
NS_INTERFACE_MAP_END_INHERITING(mozilla::dom::RTCSessionDescription)
1609
1610
mozRTCSessionDescription::mozRTCSessionDescription(JS::Handle<JSObject*> aJSImplObject, JS::Handle<JSObject*> aJSImplGlobal, nsIGlobalObject* aParent)
1611
  : mozilla::dom::RTCSessionDescription(aJSImplObject, aJSImplGlobal, aParent),
1612
    mImpl(new mozRTCSessionDescriptionJSImpl(nullptr, aJSImplObject, aJSImplGlobal, /* aIncumbentGlobal = */ nullptr)),
1613
    mParent(aParent)
1614
0
{
1615
0
}
1616
1617
1618
mozRTCSessionDescription::~mozRTCSessionDescription()
1619
0
{
1620
0
}
1621
1622
nsISupports*
1623
mozRTCSessionDescription::GetParentObject() const
1624
0
{
1625
0
  return mParent;
1626
0
}
1627
1628
JSObject*
1629
mozRTCSessionDescription::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
1630
0
{
1631
0
  JS::Rooted<JSObject*> obj(aCx, mozRTCSessionDescription_Binding::Wrap(aCx, this, aGivenProto));
1632
0
  if (!obj) {
1633
0
    return nullptr;
1634
0
  }
1635
0
1636
0
  // Now define it on our chrome object
1637
0
  JSAutoRealm ar(aCx, mImpl->CallbackGlobalOrNull());
1638
0
  if (!JS_WrapObject(aCx, &obj)) {
1639
0
    return nullptr;
1640
0
  }
1641
0
  if (!JS_DefineProperty(aCx, mImpl->CallbackOrNull(), "__DOM_IMPL__", obj, 0)) {
1642
0
    return nullptr;
1643
0
  }
1644
0
  return obj;
1645
0
}
1646
1647
already_AddRefed<mozRTCSessionDescription>
1648
mozRTCSessionDescription::Constructor(const GlobalObject& global, JSContext* cx, const RTCSessionDescriptionInit& descriptionInitDict, ErrorResult& aRv, JS::Handle<JSObject*> aGivenProto)
1649
0
{
1650
0
  JS::Rooted<JSObject*> jsImplObj(cx);
1651
0
  nsCOMPtr<nsIGlobalObject> globalHolder =
1652
0
    ConstructJSImplementation("@mozilla.org/dom/rtcsessiondescription;1", global, &jsImplObj, aRv);
1653
0
  if (aRv.Failed()) {
1654
0
    return nullptr;
1655
0
  }
1656
0
  // We should be getting the implementation object for the relevant
1657
0
  // contract here, which should never be a cross-compartment wrapper.
1658
0
  JS::Rooted<JSObject*> jsImplGlobal(cx, JS::GetNonCCWObjectGlobal(jsImplObj));
1659
0
  // Build the C++ implementation.
1660
0
  RefPtr<mozRTCSessionDescription> impl = new mozRTCSessionDescription(jsImplObj, jsImplGlobal, globalHolder);
1661
0
  // Wrap the object before calling __Init so that __DOM_IMPL__ is available.
1662
0
  JS::Rooted<JSObject*> scopeObj(cx, globalHolder->GetGlobalJSObject());
1663
0
  MOZ_ASSERT(js::IsObjectInContextCompartment(scopeObj, cx));
1664
0
  JS::Rooted<JS::Value> wrappedVal(cx);
1665
0
  if (!GetOrCreateDOMReflector(cx, impl, &wrappedVal, aGivenProto)) {
1666
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
1667
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
1668
0
    return nullptr;
1669
0
  }
1670
0
  // Initialize the object with the constructor arguments.
1671
0
  impl->mImpl->__Init(descriptionInitDict, aRv, js::GetNonCCWObjectRealm(scopeObj));
1672
0
  if (aRv.Failed()) {
1673
0
    return nullptr;
1674
0
  }
1675
0
  return impl.forget();
1676
0
}
1677
1678
bool
1679
mozRTCSessionDescription::_Create(JSContext* cx, unsigned argc, JS::Value* vp)
1680
0
{
1681
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
1682
0
  if (args.length() < 2) {
1683
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "mozRTCSessionDescription._create");
1684
0
  }
1685
0
  if (!args[0].isObject()) {
1686
0
    return ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of mozRTCSessionDescription._create");
1687
0
  }
1688
0
  if (!args[1].isObject()) {
1689
0
    return ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of mozRTCSessionDescription._create");
1690
0
  }
1691
0
1692
0
  // GlobalObject will go through wrappers as needed for us, and
1693
0
  // is simpler than the right UnwrapArg incantation.
1694
0
  GlobalObject global(cx, &args[0].toObject());
1695
0
  if (global.Failed()) {
1696
0
    return false;
1697
0
  }
1698
0
  nsCOMPtr<nsIGlobalObject> globalHolder = do_QueryInterface(global.GetAsSupports());
1699
0
  MOZ_ASSERT(globalHolder);
1700
0
  JS::Rooted<JSObject*> arg(cx, &args[1].toObject());
1701
0
  JS::Rooted<JSObject*> argGlobal(cx, JS::CurrentGlobalOrNull(cx));
1702
0
  RefPtr<mozRTCSessionDescription> impl = new mozRTCSessionDescription(arg, argGlobal, globalHolder);
1703
0
  MOZ_ASSERT(js::IsObjectInContextCompartment(arg, cx));
1704
0
  return GetOrCreateDOMReflector(cx, impl, args.rval());
1705
0
}
1706
1707
1708
} // namespace dom
1709
} // namespace mozilla