LCOV - code coverage report
Current view: top level - obj-x86_64-pc-linux-gnu/dom/bindings - WebrtcDeprecatedBinding.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 695 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 78 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.13