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

          Line data    Source code
       1             : /* THIS FILE IS AUTOGENERATED FROM FlyWebDiscoveryManager.webidl BY Codegen.py - DO NOT EDIT */
       2             : 
       3             : #include "AtomList.h"
       4             : #include "FlyWebDiscoveryManagerBinding.h"
       5             : #include "WrapperFactory.h"
       6             : #include "mozilla/OwningNonNull.h"
       7             : #include "mozilla/dom/BindingUtils.h"
       8             : #include "mozilla/dom/DOMJSClass.h"
       9             : #include "mozilla/dom/FlyWebDiscoveryManager.h"
      10             : #include "mozilla/dom/NonRefcountedDOMObject.h"
      11             : #include "mozilla/dom/PrimitiveConversions.h"
      12             : #include "mozilla/dom/ScriptSettings.h"
      13             : #include "mozilla/dom/SimpleGlobalObject.h"
      14             : #include "mozilla/dom/XrayExpandoClass.h"
      15             : #include "nsContentUtils.h"
      16             : 
      17             : namespace mozilla {
      18             : namespace dom {
      19             : 
      20             : 
      21           0 : FlyWebDiscoveredService::FlyWebDiscoveredService()
      22             : {
      23             :   // Safe to pass a null context if we pass a null value
      24           0 :   Init(nullptr, JS::NullHandleValue);
      25           0 : }
      26             : 
      27             : 
      28             : 
      29             : bool
      30           0 : FlyWebDiscoveredService::InitIds(JSContext* cx, FlyWebDiscoveredServiceAtoms* atomsCache)
      31             : {
      32           0 :   MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
      33             : 
      34             :   // Initialize these in reverse order so that any failure leaves the first one
      35             :   // uninitialized.
      36           0 :   if (!atomsCache->transport_id.init(cx, "transport") ||
      37           0 :       !atomsCache->serviceType_id.init(cx, "serviceType") ||
      38           0 :       !atomsCache->serviceId_id.init(cx, "serviceId") ||
      39           0 :       !atomsCache->path_id.init(cx, "path") ||
      40           0 :       !atomsCache->displayName_id.init(cx, "displayName") ||
      41           0 :       !atomsCache->cert_id.init(cx, "cert")) {
      42           0 :     return false;
      43             :   }
      44           0 :   return true;
      45             : }
      46             : 
      47             : bool
      48           0 : FlyWebDiscoveredService::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
      49             : {
      50             :   // Passing a null JSContext is OK only if we're initing from null,
      51             :   // Since in that case we will not have to do any property gets
      52             :   // Also evaluate isNullOrUndefined in order to avoid false-positive
      53             :   // checkers by static analysis tools
      54           0 :   MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
      55           0 :   FlyWebDiscoveredServiceAtoms* atomsCache = nullptr;
      56           0 :   if (cx) {
      57           0 :     atomsCache = GetAtomCache<FlyWebDiscoveredServiceAtoms>(cx);
      58           0 :     if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
      59           0 :       return false;
      60             :     }
      61             :   }
      62             : 
      63           0 :   if (!IsConvertibleToDictionary(val)) {
      64           0 :     return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
      65             :   }
      66             : 
      67           0 :   bool isNull = val.isNullOrUndefined();
      68             :   // We only need these if !isNull, in which case we have |cx|.
      69           0 :   Maybe<JS::Rooted<JSObject *> > object;
      70           0 :   Maybe<JS::Rooted<JS::Value> > temp;
      71           0 :   if (!isNull) {
      72           0 :     MOZ_ASSERT(cx);
      73           0 :     object.emplace(cx, &val.toObject());
      74           0 :     temp.emplace(cx);
      75             :   }
      76           0 :   if (!isNull) {
      77           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->cert_id, temp.ptr())) {
      78           0 :       return false;
      79             :     }
      80             :   }
      81           0 :   if (!isNull && !temp->isUndefined()) {
      82           0 :     if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mCert)) {
      83           0 :       return false;
      84             :     }
      85             :   } else {
      86             :     static const char16_t data[] = { 0 };
      87           0 :     mCert.Rebind(data, ArrayLength(data) - 1);
      88             :   }
      89           0 :   mIsAnyMemberPresent = true;
      90             : 
      91           0 :   if (!isNull) {
      92           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->displayName_id, temp.ptr())) {
      93           0 :       return false;
      94             :     }
      95             :   }
      96           0 :   if (!isNull && !temp->isUndefined()) {
      97           0 :     if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mDisplayName)) {
      98           0 :       return false;
      99             :     }
     100             :   } else {
     101             :     static const char16_t data[] = { 0 };
     102           0 :     mDisplayName.Rebind(data, ArrayLength(data) - 1);
     103             :   }
     104           0 :   mIsAnyMemberPresent = true;
     105             : 
     106           0 :   if (!isNull) {
     107           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->path_id, temp.ptr())) {
     108           0 :       return false;
     109             :     }
     110             :   }
     111           0 :   if (!isNull && !temp->isUndefined()) {
     112           0 :     if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mPath)) {
     113           0 :       return false;
     114             :     }
     115             :   } else {
     116             :     static const char16_t data[] = { 0 };
     117           0 :     mPath.Rebind(data, ArrayLength(data) - 1);
     118             :   }
     119           0 :   mIsAnyMemberPresent = true;
     120             : 
     121           0 :   if (!isNull) {
     122           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->serviceId_id, temp.ptr())) {
     123           0 :       return false;
     124             :     }
     125             :   }
     126           0 :   if (!isNull && !temp->isUndefined()) {
     127           0 :     if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mServiceId)) {
     128           0 :       return false;
     129             :     }
     130             :   } else {
     131             :     static const char16_t data[] = { 0 };
     132           0 :     mServiceId.Rebind(data, ArrayLength(data) - 1);
     133             :   }
     134           0 :   mIsAnyMemberPresent = true;
     135             : 
     136           0 :   if (!isNull) {
     137           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->serviceType_id, temp.ptr())) {
     138           0 :       return false;
     139             :     }
     140             :   }
     141           0 :   if (!isNull && !temp->isUndefined()) {
     142           0 :     if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mServiceType)) {
     143           0 :       return false;
     144             :     }
     145             :   } else {
     146             :     static const char16_t data[] = { 0 };
     147           0 :     mServiceType.Rebind(data, ArrayLength(data) - 1);
     148             :   }
     149           0 :   mIsAnyMemberPresent = true;
     150             : 
     151           0 :   if (!isNull) {
     152           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->transport_id, temp.ptr())) {
     153           0 :       return false;
     154             :     }
     155             :   }
     156           0 :   if (!isNull && !temp->isUndefined()) {
     157           0 :     if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mTransport)) {
     158           0 :       return false;
     159             :     }
     160             :   } else {
     161             :     static const char16_t data[] = { 0 };
     162           0 :     mTransport.Rebind(data, ArrayLength(data) - 1);
     163             :   }
     164           0 :   mIsAnyMemberPresent = true;
     165           0 :   return true;
     166             : }
     167             : 
     168             : bool
     169           0 : FlyWebDiscoveredService::Init(const nsAString& aJSON)
     170             : {
     171           0 :   AutoJSAPI jsapi;
     172           0 :   JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
     173           0 :   if (!cleanGlobal) {
     174           0 :     return false;
     175             :   }
     176           0 :   if (!jsapi.Init(cleanGlobal)) {
     177           0 :     return false;
     178             :   }
     179           0 :   JSContext* cx = jsapi.cx();
     180           0 :   JS::Rooted<JS::Value> json(cx);
     181           0 :   bool ok = ParseJSON(cx, aJSON, &json);
     182           0 :   NS_ENSURE_TRUE(ok, false);
     183           0 :   return Init(cx, json);
     184             : }
     185             : 
     186             : bool
     187           0 : FlyWebDiscoveredService::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
     188             : {
     189           0 :   FlyWebDiscoveredServiceAtoms* atomsCache = GetAtomCache<FlyWebDiscoveredServiceAtoms>(cx);
     190           0 :   if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
     191           0 :     return false;
     192             :   }
     193             : 
     194           0 :   JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
     195           0 :   if (!obj) {
     196           0 :     return false;
     197             :   }
     198           0 :   rval.set(JS::ObjectValue(*obj));
     199             : 
     200             :   do {
     201             :     // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     202           0 :     JS::Rooted<JS::Value> temp(cx);
     203           0 :     nsString const & currentValue = mCert;
     204           0 :     if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
     205           0 :       return false;
     206             :     }
     207           0 :     if (!JS_DefinePropertyById(cx, obj, atomsCache->cert_id, temp, JSPROP_ENUMERATE)) {
     208           0 :       return false;
     209             :     }
     210           0 :     break;
     211             :   } while(0);
     212             : 
     213             :   do {
     214             :     // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     215           0 :     JS::Rooted<JS::Value> temp(cx);
     216           0 :     nsString const & currentValue = mDisplayName;
     217           0 :     if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
     218           0 :       return false;
     219             :     }
     220           0 :     if (!JS_DefinePropertyById(cx, obj, atomsCache->displayName_id, temp, JSPROP_ENUMERATE)) {
     221           0 :       return false;
     222             :     }
     223           0 :     break;
     224             :   } while(0);
     225             : 
     226             :   do {
     227             :     // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     228           0 :     JS::Rooted<JS::Value> temp(cx);
     229           0 :     nsString const & currentValue = mPath;
     230           0 :     if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
     231           0 :       return false;
     232             :     }
     233           0 :     if (!JS_DefinePropertyById(cx, obj, atomsCache->path_id, temp, JSPROP_ENUMERATE)) {
     234           0 :       return false;
     235             :     }
     236           0 :     break;
     237             :   } while(0);
     238             : 
     239             :   do {
     240             :     // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     241           0 :     JS::Rooted<JS::Value> temp(cx);
     242           0 :     nsString const & currentValue = mServiceId;
     243           0 :     if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
     244           0 :       return false;
     245             :     }
     246           0 :     if (!JS_DefinePropertyById(cx, obj, atomsCache->serviceId_id, temp, JSPROP_ENUMERATE)) {
     247           0 :       return false;
     248             :     }
     249           0 :     break;
     250             :   } while(0);
     251             : 
     252             :   do {
     253             :     // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     254           0 :     JS::Rooted<JS::Value> temp(cx);
     255           0 :     nsString const & currentValue = mServiceType;
     256           0 :     if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
     257           0 :       return false;
     258             :     }
     259           0 :     if (!JS_DefinePropertyById(cx, obj, atomsCache->serviceType_id, temp, JSPROP_ENUMERATE)) {
     260           0 :       return false;
     261             :     }
     262           0 :     break;
     263             :   } while(0);
     264             : 
     265             :   do {
     266             :     // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     267           0 :     JS::Rooted<JS::Value> temp(cx);
     268           0 :     nsString const & currentValue = mTransport;
     269           0 :     if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
     270           0 :       return false;
     271             :     }
     272           0 :     if (!JS_DefinePropertyById(cx, obj, atomsCache->transport_id, temp, JSPROP_ENUMERATE)) {
     273           0 :       return false;
     274             :     }
     275           0 :     break;
     276             :   } while(0);
     277             : 
     278           0 :   return true;
     279             : }
     280             : 
     281             : bool
     282           0 : FlyWebDiscoveredService::ToJSON(nsAString& aJSON) const
     283             : {
     284           0 :   AutoJSAPI jsapi;
     285           0 :   jsapi.Init();
     286           0 :   JSContext *cx = jsapi.cx();
     287             :   // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
     288             :   // because we'll only be creating objects, in ways that have no
     289             :   // side-effects, followed by a call to JS::ToJSONMaybeSafely,
     290             :   // which likewise guarantees no side-effects for the sorts of
     291             :   // things we will pass it.
     292           0 :   JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
     293           0 :   JS::Rooted<JS::Value> val(cx);
     294           0 :   if (!ToObjectInternal(cx, &val)) {
     295           0 :     return false;
     296             :   }
     297           0 :   JS::Rooted<JSObject*> obj(cx, &val.toObject());
     298           0 :   return StringifyToJSON(cx, obj, aJSON);
     299             : }
     300             : 
     301             : void
     302           0 : FlyWebDiscoveredService::TraceDictionary(JSTracer* trc)
     303             : {
     304           0 : }
     305             : 
     306             : FlyWebDiscoveredService&
     307           0 : FlyWebDiscoveredService::operator=(const FlyWebDiscoveredService& aOther)
     308             : {
     309           0 :   mCert = aOther.mCert;
     310           0 :   mDisplayName = aOther.mDisplayName;
     311           0 :   mPath = aOther.mPath;
     312           0 :   mServiceId = aOther.mServiceId;
     313           0 :   mServiceType = aOther.mServiceType;
     314           0 :   mTransport = aOther.mTransport;
     315           0 :   return *this;
     316             : }
     317             : 
     318             : namespace binding_detail {
     319             : } // namespace binding_detail
     320             : 
     321             : 
     322             : 
     323           0 : FlyWebPairedService::FlyWebPairedService()
     324           0 :   : mDiscoveredService(FastDictionaryInitializer())
     325             : {
     326             :   // Safe to pass a null context if we pass a null value
     327           0 :   Init(nullptr, JS::NullHandleValue);
     328           0 : }
     329             : 
     330             : 
     331             : 
     332             : bool
     333           0 : FlyWebPairedService::InitIds(JSContext* cx, FlyWebPairedServiceAtoms* atomsCache)
     334             : {
     335           0 :   MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
     336             : 
     337             :   // Initialize these in reverse order so that any failure leaves the first one
     338             :   // uninitialized.
     339           0 :   if (!atomsCache->uiUrl_id.init(cx, "uiUrl") ||
     340           0 :       !atomsCache->hostname_id.init(cx, "hostname") ||
     341           0 :       !atomsCache->discoveredService_id.init(cx, "discoveredService")) {
     342           0 :     return false;
     343             :   }
     344           0 :   return true;
     345             : }
     346             : 
     347             : bool
     348           0 : FlyWebPairedService::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
     349             : {
     350             :   // Passing a null JSContext is OK only if we're initing from null,
     351             :   // Since in that case we will not have to do any property gets
     352             :   // Also evaluate isNullOrUndefined in order to avoid false-positive
     353             :   // checkers by static analysis tools
     354           0 :   MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
     355           0 :   FlyWebPairedServiceAtoms* atomsCache = nullptr;
     356           0 :   if (cx) {
     357           0 :     atomsCache = GetAtomCache<FlyWebPairedServiceAtoms>(cx);
     358           0 :     if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
     359           0 :       return false;
     360             :     }
     361             :   }
     362             : 
     363           0 :   if (!IsConvertibleToDictionary(val)) {
     364           0 :     return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
     365             :   }
     366             : 
     367           0 :   bool isNull = val.isNullOrUndefined();
     368             :   // We only need these if !isNull, in which case we have |cx|.
     369           0 :   Maybe<JS::Rooted<JSObject *> > object;
     370           0 :   Maybe<JS::Rooted<JS::Value> > temp;
     371           0 :   if (!isNull) {
     372           0 :     MOZ_ASSERT(cx);
     373           0 :     object.emplace(cx, &val.toObject());
     374           0 :     temp.emplace(cx);
     375             :   }
     376           0 :   if (!isNull) {
     377           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->discoveredService_id, temp.ptr())) {
     378           0 :       return false;
     379             :     }
     380             :   }
     381           0 :   if (!mDiscoveredService.Init(cx, (!isNull && !temp->isUndefined()) ? temp.ref() : JS::NullHandleValue,  "'discoveredService' member of FlyWebPairedService", passedToJSImpl)) {
     382           0 :     return false;
     383             :   }
     384           0 :   mIsAnyMemberPresent = true;
     385             : 
     386           0 :   if (!isNull) {
     387           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->hostname_id, temp.ptr())) {
     388           0 :       return false;
     389             :     }
     390             :   }
     391           0 :   if (!isNull && !temp->isUndefined()) {
     392           0 :     if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mHostname)) {
     393           0 :       return false;
     394             :     }
     395             :   } else {
     396             :     static const char16_t data[] = { 0 };
     397           0 :     mHostname.Rebind(data, ArrayLength(data) - 1);
     398             :   }
     399           0 :   mIsAnyMemberPresent = true;
     400             : 
     401           0 :   if (!isNull) {
     402           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->uiUrl_id, temp.ptr())) {
     403           0 :       return false;
     404             :     }
     405             :   }
     406           0 :   if (!isNull && !temp->isUndefined()) {
     407           0 :     if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mUiUrl)) {
     408           0 :       return false;
     409             :     }
     410             :   } else {
     411             :     static const char16_t data[] = { 0 };
     412           0 :     mUiUrl.Rebind(data, ArrayLength(data) - 1);
     413             :   }
     414           0 :   mIsAnyMemberPresent = true;
     415           0 :   return true;
     416             : }
     417             : 
     418             : bool
     419           0 : FlyWebPairedService::Init(const nsAString& aJSON)
     420             : {
     421           0 :   AutoJSAPI jsapi;
     422           0 :   JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
     423           0 :   if (!cleanGlobal) {
     424           0 :     return false;
     425             :   }
     426           0 :   if (!jsapi.Init(cleanGlobal)) {
     427           0 :     return false;
     428             :   }
     429           0 :   JSContext* cx = jsapi.cx();
     430           0 :   JS::Rooted<JS::Value> json(cx);
     431           0 :   bool ok = ParseJSON(cx, aJSON, &json);
     432           0 :   NS_ENSURE_TRUE(ok, false);
     433           0 :   return Init(cx, json);
     434             : }
     435             : 
     436             : bool
     437           0 : FlyWebPairedService::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
     438             : {
     439           0 :   FlyWebPairedServiceAtoms* atomsCache = GetAtomCache<FlyWebPairedServiceAtoms>(cx);
     440           0 :   if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
     441           0 :     return false;
     442             :   }
     443             : 
     444           0 :   JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
     445           0 :   if (!obj) {
     446           0 :     return false;
     447             :   }
     448           0 :   rval.set(JS::ObjectValue(*obj));
     449             : 
     450             :   do {
     451             :     // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     452           0 :     JS::Rooted<JS::Value> temp(cx);
     453           0 :     FlyWebDiscoveredService const & currentValue = mDiscoveredService;
     454           0 :     if (!currentValue.ToObjectInternal(cx, &temp)) {
     455           0 :       return false;
     456             :     }
     457           0 :     if (!JS_DefinePropertyById(cx, obj, atomsCache->discoveredService_id, temp, JSPROP_ENUMERATE)) {
     458           0 :       return false;
     459             :     }
     460           0 :     break;
     461             :   } while(0);
     462             : 
     463             :   do {
     464             :     // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     465           0 :     JS::Rooted<JS::Value> temp(cx);
     466           0 :     nsString const & currentValue = mHostname;
     467           0 :     if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
     468           0 :       return false;
     469             :     }
     470           0 :     if (!JS_DefinePropertyById(cx, obj, atomsCache->hostname_id, temp, JSPROP_ENUMERATE)) {
     471           0 :       return false;
     472             :     }
     473           0 :     break;
     474             :   } while(0);
     475             : 
     476             :   do {
     477             :     // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     478           0 :     JS::Rooted<JS::Value> temp(cx);
     479           0 :     nsString const & currentValue = mUiUrl;
     480           0 :     if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
     481           0 :       return false;
     482             :     }
     483           0 :     if (!JS_DefinePropertyById(cx, obj, atomsCache->uiUrl_id, temp, JSPROP_ENUMERATE)) {
     484           0 :       return false;
     485             :     }
     486           0 :     break;
     487             :   } while(0);
     488             : 
     489           0 :   return true;
     490             : }
     491             : 
     492             : bool
     493           0 : FlyWebPairedService::ToJSON(nsAString& aJSON) const
     494             : {
     495           0 :   AutoJSAPI jsapi;
     496           0 :   jsapi.Init();
     497           0 :   JSContext *cx = jsapi.cx();
     498             :   // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
     499             :   // because we'll only be creating objects, in ways that have no
     500             :   // side-effects, followed by a call to JS::ToJSONMaybeSafely,
     501             :   // which likewise guarantees no side-effects for the sorts of
     502             :   // things we will pass it.
     503           0 :   JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
     504           0 :   JS::Rooted<JS::Value> val(cx);
     505           0 :   if (!ToObjectInternal(cx, &val)) {
     506           0 :     return false;
     507             :   }
     508           0 :   JS::Rooted<JSObject*> obj(cx, &val.toObject());
     509           0 :   return StringifyToJSON(cx, obj, aJSON);
     510             : }
     511             : 
     512             : void
     513           0 : FlyWebPairedService::TraceDictionary(JSTracer* trc)
     514             : {
     515           0 : }
     516             : 
     517             : FlyWebPairedService&
     518           0 : FlyWebPairedService::operator=(const FlyWebPairedService& aOther)
     519             : {
     520           0 :   mDiscoveredService = aOther.mDiscoveredService;
     521           0 :   mHostname = aOther.mHostname;
     522           0 :   mUiUrl = aOther.mUiUrl;
     523           0 :   return *this;
     524             : }
     525             : 
     526             : namespace binding_detail {
     527             : } // namespace binding_detail
     528             : 
     529             : 
     530             : namespace FlyWebDiscoveryManagerBinding {
     531             : 
     532             : static bool
     533           0 : listServices(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::FlyWebDiscoveryManager* self, const JSJitMethodCallArgs& args)
     534             : {
     535           0 :   nsTArray<FlyWebDiscoveredService> result;
     536           0 :   self->ListServices(result);
     537           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     538             : 
     539           0 :   uint32_t length = result.Length();
     540           0 :   JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
     541           0 :   if (!returnArray) {
     542           0 :     return false;
     543             :   }
     544             :   // Scope for 'tmp'
     545             :   {
     546           0 :     JS::Rooted<JS::Value> tmp(cx);
     547           0 :     for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
     548             :       // Control block to let us common up the JS_DefineElement calls when there
     549             :       // are different ways to succeed at wrapping the object.
     550             :       do {
     551           0 :         if (!result[sequenceIdx0].ToObjectInternal(cx, &tmp)) {
     552           0 :           return false;
     553             :         }
     554           0 :         break;
     555             :       } while (0);
     556           0 :       if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
     557             :                             JSPROP_ENUMERATE)) {
     558           0 :         return false;
     559             :       }
     560             :     }
     561             :   }
     562           0 :   args.rval().setObject(*returnArray);
     563           0 :   return true;
     564             : }
     565             : 
     566             : static const JSJitInfo listServices_methodinfo = {
     567             :   { (JSJitGetterOp)listServices },
     568             :   { prototypes::id::FlyWebDiscoveryManager },
     569             :   { PrototypeTraits<prototypes::id::FlyWebDiscoveryManager>::Depth },
     570             :   JSJitInfo::Method,
     571             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     572             :   JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
     573             :   false,  /* isInfallible. False in setters. */
     574             :   false,  /* isMovable.  Not relevant for setters. */
     575             :   false, /* isEliminatable.  Not relevant for setters. */
     576             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     577             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     578             :   false,  /* isTypedMethod.  Only relevant for methods. */
     579             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     580             : };
     581             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     582             : static_assert(0 < 1, "There is no slot for us");
     583             : 
     584             : static bool
     585           0 : startDiscovery(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::FlyWebDiscoveryManager* self, const JSJitMethodCallArgs& args)
     586             : {
     587           0 :   if (MOZ_UNLIKELY(args.length() < 1)) {
     588           0 :     return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "FlyWebDiscoveryManager.startDiscovery");
     589             :   }
     590           0 :   RootedCallback<OwningNonNull<binding_detail::FastFlyWebDiscoveryCallback>> arg0(cx);
     591           0 :   if (args[0].isObject()) {
     592             :     { // scope for tempRoot
     593           0 :       JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
     594           0 :       arg0 = new binding_detail::FastFlyWebDiscoveryCallback(tempRoot);
     595             :     }
     596             :   } else {
     597           0 :     ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of FlyWebDiscoveryManager.startDiscovery");
     598           0 :     return false;
     599             :   }
     600           0 :   uint32_t result(self->StartDiscovery(NonNullHelper(arg0)));
     601           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     602           0 :   args.rval().setNumber(result);
     603           0 :   return true;
     604             : }
     605             : 
     606             : static const JSJitInfo startDiscovery_methodinfo = {
     607             :   { (JSJitGetterOp)startDiscovery },
     608             :   { prototypes::id::FlyWebDiscoveryManager },
     609             :   { PrototypeTraits<prototypes::id::FlyWebDiscoveryManager>::Depth },
     610             :   JSJitInfo::Method,
     611             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     612             :   JSVAL_TYPE_DOUBLE,  /* returnType.  Not relevant for setters. */
     613             :   false,  /* isInfallible. False in setters. */
     614             :   false,  /* isMovable.  Not relevant for setters. */
     615             :   false, /* isEliminatable.  Not relevant for setters. */
     616             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     617             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     618             :   false,  /* isTypedMethod.  Only relevant for methods. */
     619             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     620             : };
     621             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     622             : static_assert(0 < 1, "There is no slot for us");
     623             : 
     624             : static bool
     625           0 : stopDiscovery(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::FlyWebDiscoveryManager* self, const JSJitMethodCallArgs& args)
     626             : {
     627           0 :   if (MOZ_UNLIKELY(args.length() < 1)) {
     628           0 :     return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "FlyWebDiscoveryManager.stopDiscovery");
     629             :   }
     630             :   uint32_t arg0;
     631           0 :   if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], &arg0)) {
     632           0 :     return false;
     633             :   }
     634           0 :   self->StopDiscovery(arg0);
     635           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     636           0 :   args.rval().setUndefined();
     637           0 :   return true;
     638             : }
     639             : 
     640             : static const JSJitInfo stopDiscovery_methodinfo = {
     641             :   { (JSJitGetterOp)stopDiscovery },
     642             :   { prototypes::id::FlyWebDiscoveryManager },
     643             :   { PrototypeTraits<prototypes::id::FlyWebDiscoveryManager>::Depth },
     644             :   JSJitInfo::Method,
     645             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     646             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
     647             :   false,  /* isInfallible. False in setters. */
     648             :   false,  /* isMovable.  Not relevant for setters. */
     649             :   false, /* isEliminatable.  Not relevant for setters. */
     650             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     651             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     652             :   false,  /* isTypedMethod.  Only relevant for methods. */
     653             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     654             : };
     655             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     656             : static_assert(0 < 1, "There is no slot for us");
     657             : 
     658             : static bool
     659           0 : pairWithService(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::FlyWebDiscoveryManager* self, const JSJitMethodCallArgs& args)
     660             : {
     661           0 :   if (MOZ_UNLIKELY(args.length() < 2)) {
     662           0 :     return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "FlyWebDiscoveryManager.pairWithService");
     663             :   }
     664           0 :   binding_detail::FakeString arg0;
     665           0 :   if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
     666           0 :     return false;
     667             :   }
     668           0 :   RootedCallback<OwningNonNull<binding_detail::FastFlyWebPairingCallback>> arg1(cx);
     669           0 :   if (args[1].isObject()) {
     670             :     { // scope for tempRoot
     671           0 :       JS::Rooted<JSObject*> tempRoot(cx, &args[1].toObject());
     672           0 :       arg1 = new binding_detail::FastFlyWebPairingCallback(tempRoot);
     673             :     }
     674             :   } else {
     675           0 :     ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of FlyWebDiscoveryManager.pairWithService");
     676           0 :     return false;
     677             :   }
     678           0 :   self->PairWithService(NonNullHelper(Constify(arg0)), NonNullHelper(arg1));
     679           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     680           0 :   args.rval().setUndefined();
     681           0 :   return true;
     682             : }
     683             : 
     684             : static const JSJitInfo pairWithService_methodinfo = {
     685             :   { (JSJitGetterOp)pairWithService },
     686             :   { prototypes::id::FlyWebDiscoveryManager },
     687             :   { PrototypeTraits<prototypes::id::FlyWebDiscoveryManager>::Depth },
     688             :   JSJitInfo::Method,
     689             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     690             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
     691             :   false,  /* isInfallible. False in setters. */
     692             :   false,  /* isMovable.  Not relevant for setters. */
     693             :   false, /* isEliminatable.  Not relevant for setters. */
     694             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     695             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     696             :   false,  /* isTypedMethod.  Only relevant for methods. */
     697             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     698             : };
     699             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     700             : static_assert(0 < 1, "There is no slot for us");
     701             : 
     702             : static bool
     703           0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
     704             : {
     705           0 :   mozilla::dom::FlyWebDiscoveryManager* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::FlyWebDiscoveryManager>(obj);
     706             :   // We don't want to preserve if we don't have a wrapper, and we
     707             :   // obviously can't preserve if we're not initialized.
     708           0 :   if (self && self->GetWrapperPreserveColor()) {
     709           0 :     PreserveWrapper(self);
     710             :   }
     711           0 :   return true;
     712             : }
     713             : 
     714             : static void
     715           0 : _finalize(js::FreeOp* fop, JSObject* obj)
     716             : {
     717           0 :   mozilla::dom::FlyWebDiscoveryManager* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::FlyWebDiscoveryManager>(obj);
     718           0 :   if (self) {
     719           0 :     ClearWrapper(self, self, obj);
     720           0 :     AddForDeferredFinalization<mozilla::dom::FlyWebDiscoveryManager>(self);
     721             :   }
     722           0 : }
     723             : 
     724             : static void
     725           0 : _objectMoved(JSObject* obj, const JSObject* old)
     726             : {
     727           0 :   mozilla::dom::FlyWebDiscoveryManager* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::FlyWebDiscoveryManager>(obj);
     728           0 :   if (self) {
     729           0 :     UpdateWrapper(self, self, obj, old);
     730             :   }
     731           0 : }
     732             : 
     733             : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
     734             : #if defined(__clang__)
     735             : #pragma clang diagnostic push
     736             : #pragma clang diagnostic ignored "-Wmissing-braces"
     737             : #endif
     738             : static const JSFunctionSpec sMethods_specs[] = {
     739             :   JS_FNSPEC("listServices", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&listServices_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
     740             :   JS_FNSPEC("startDiscovery", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&startDiscovery_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
     741             :   JS_FNSPEC("stopDiscovery", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&stopDiscovery_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
     742             :   JS_FNSPEC("pairWithService", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&pairWithService_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
     743             :   JS_FS_END
     744             : };
     745             : #if defined(__clang__)
     746             : #pragma clang diagnostic pop
     747             : #endif
     748             : 
     749             : 
     750             : // Can't be const because the pref-enabled boolean needs to be writable
     751             : static Prefable<const JSFunctionSpec> sMethods[] = {
     752             :   { nullptr, &sMethods_specs[0] },
     753             :   { nullptr, nullptr }
     754             : };
     755             : 
     756             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
     757             :     "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
     758             : static_assert(4 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
     759             :     "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
     760             : 
     761             : 
     762             : static uint16_t sNativeProperties_sortedPropertyIndices[4];
     763             : static PropertyInfo sNativeProperties_propertyInfos[4];
     764             : 
     765             : static const NativePropertiesN<1> sNativeProperties = {
     766             :   false, 0,
     767             :   false, 0,
     768             :   true,  0 /* sMethods */,
     769             :   false, 0,
     770             :   false, 0,
     771             :   false, 0,
     772             :   false, 0,
     773             :   -1,
     774             :   4,
     775             :   sNativeProperties_sortedPropertyIndices,
     776             :   {
     777             :     { sMethods, &sNativeProperties_propertyInfos[0] }
     778             :   }
     779             : };
     780             : static_assert(4 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
     781             :     "We have a property info count that is oversized");
     782             : 
     783             : static bool
     784           0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
     785             : {
     786           0 :   JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
     787           0 :   JS::Rooted<JSObject*> obj(cx, &args.callee());
     788           0 :   if (!nsContentUtils::ThreadsafeIsSystemCaller(cx)) {
     789           0 :     return ThrowingConstructor(cx, argc, vp);
     790             :   }
     791             : 
     792           0 :   if (!args.isConstructing()) {
     793             :     // XXXbz wish I could get the name from the callee instead of
     794             :     // Adding more relocations
     795           0 :     return ThrowConstructorWithoutNew(cx, "FlyWebDiscoveryManager");
     796             :   }
     797             : 
     798           0 :   GlobalObject global(cx, obj);
     799           0 :   if (global.Failed()) {
     800           0 :     return false;
     801             :   }
     802             : 
     803           0 :   JS::Rooted<JSObject*> desiredProto(cx);
     804           0 :   if (!GetDesiredProto(cx, args, &desiredProto)) {
     805           0 :     return false;
     806             :   }
     807             : 
     808           0 :   bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
     809           0 :   Maybe<JSAutoCompartment> ac;
     810           0 :   if (objIsXray) {
     811           0 :     obj = js::CheckedUnwrap(obj);
     812           0 :     if (!obj) {
     813           0 :       return false;
     814             :     }
     815           0 :     ac.emplace(cx, obj);
     816           0 :     if (!JS_WrapObject(cx, &desiredProto)) {
     817           0 :       return false;
     818             :     }
     819             :   }
     820           0 :   binding_detail::FastErrorResult rv;
     821           0 :   auto result(StrongOrRawPtr<mozilla::dom::FlyWebDiscoveryManager>(mozilla::dom::FlyWebDiscoveryManager::Constructor(global, rv)));
     822           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     823           0 :     return false;
     824             :   }
     825           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     826             :   static_assert(!IsPointer<decltype(result)>::value,
     827             :                 "NewObject implies that we need to keep the object alive with a strong reference.");
     828           0 :   if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
     829           0 :     MOZ_ASSERT(true || JS_IsExceptionPending(cx));
     830           0 :     return false;
     831             :   }
     832           0 :   return true;
     833             : }
     834             : 
     835             : static const js::ClassOps sInterfaceObjectClassOps = {
     836             :     nullptr,               /* addProperty */
     837             :     nullptr,               /* delProperty */
     838             :     nullptr,               /* getProperty */
     839             :     nullptr,               /* setProperty */
     840             :     nullptr,               /* enumerate */
     841             :     nullptr,               /* newEnumerate */
     842             :     nullptr,               /* resolve */
     843             :     nullptr,               /* mayResolve */
     844             :     nullptr,               /* finalize */
     845             :     _constructor, /* call */
     846             :     nullptr,               /* hasInstance */
     847             :     _constructor, /* construct */
     848             :     nullptr,               /* trace */
     849             : };
     850             : 
     851             : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
     852             :   {
     853             :     "Function",
     854             :     JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
     855             :     &sInterfaceObjectClassOps,
     856             :     JS_NULL_CLASS_SPEC,
     857             :     JS_NULL_CLASS_EXT,
     858             :     &sInterfaceObjectClassObjectOps
     859             :   },
     860             :   eInterface,
     861             :   true,
     862             :   prototypes::id::FlyWebDiscoveryManager,
     863             :   PrototypeTraits<prototypes::id::FlyWebDiscoveryManager>::Depth,
     864             :   sNativePropertyHooks,
     865             :   "function FlyWebDiscoveryManager() {\n    [native code]\n}",
     866             :   JS::GetRealmFunctionPrototype
     867             : };
     868             : 
     869             : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
     870             :   {
     871             :     "FlyWebDiscoveryManagerPrototype",
     872             :     JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
     873             :     JS_NULL_CLASS_OPS,
     874             :     JS_NULL_CLASS_SPEC,
     875             :     JS_NULL_CLASS_EXT,
     876             :     JS_NULL_OBJECT_OPS
     877             :   },
     878             :   eInterfacePrototype,
     879             :   false,
     880             :   prototypes::id::FlyWebDiscoveryManager,
     881             :   PrototypeTraits<prototypes::id::FlyWebDiscoveryManager>::Depth,
     882             :   sNativePropertyHooks,
     883             :   "[object FlyWebDiscoveryManagerPrototype]",
     884             :   JS::GetRealmObjectPrototype
     885             : };
     886             : 
     887             : bool
     888           0 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
     889             : {
     890           0 :   return nsContentUtils::ThreadsafeIsSystemCaller(aCx);
     891             : }
     892             : 
     893             : JSObject*
     894           0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
     895             : {
     896           0 :   return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
     897             : }
     898             : 
     899             : static const js::ClassOps sClassOps = {
     900             :   _addProperty, /* addProperty */
     901             :   nullptr,               /* delProperty */
     902             :   nullptr,               /* getProperty */
     903             :   nullptr,               /* setProperty */
     904             :   nullptr,               /* enumerate */
     905             :   nullptr, /* newEnumerate */
     906             :   nullptr, /* resolve */
     907             :   nullptr, /* mayResolve */
     908             :   _finalize, /* finalize */
     909             :   nullptr, /* call */
     910             :   nullptr,               /* hasInstance */
     911             :   nullptr,               /* construct */
     912             :   nullptr, /* trace */
     913             : };
     914             : 
     915             : static const js::ClassExtension sClassExtension = {
     916             :   nullptr, /* weakmapKeyDelegateOp */
     917             :   _objectMoved /* objectMovedOp */
     918             : };
     919             : 
     920             : static const DOMJSClass sClass = {
     921             :   { "FlyWebDiscoveryManager",
     922             :     JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
     923             :     &sClassOps,
     924             :     JS_NULL_CLASS_SPEC,
     925             :     &sClassExtension,
     926             :     JS_NULL_OBJECT_OPS
     927             :   },
     928             :   { prototypes::id::FlyWebDiscoveryManager, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
     929             :   IsBaseOf<nsISupports, mozilla::dom::FlyWebDiscoveryManager >::value,
     930             :   sNativePropertyHooks,
     931             :   FindAssociatedGlobalForNative<mozilla::dom::FlyWebDiscoveryManager>::Get,
     932             :   GetProtoObjectHandle,
     933             :   GetCCParticipant<mozilla::dom::FlyWebDiscoveryManager>::Get()
     934             : };
     935             : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
     936             :               "Must have the right minimal number of reserved slots.");
     937             : static_assert(1 >= 1,
     938             :               "Must have enough reserved slots.");
     939             : 
     940             : const JSClass*
     941           0 : GetJSClass()
     942             : {
     943           0 :   return sClass.ToJSClass();
     944             : }
     945             : 
     946             : bool
     947           0 : Wrap(JSContext* aCx, mozilla::dom::FlyWebDiscoveryManager* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
     948             : {
     949             :   MOZ_ASSERT(static_cast<mozilla::dom::FlyWebDiscoveryManager*>(aObject) ==
     950             :              reinterpret_cast<mozilla::dom::FlyWebDiscoveryManager*>(aObject),
     951             :              "Multiple inheritance for mozilla::dom::FlyWebDiscoveryManager is broken.");
     952           0 :   MOZ_ASSERT(ToSupportsIsCorrect(aObject));
     953           0 :   MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
     954           0 :   MOZ_ASSERT(!aCache->GetWrapper(),
     955             :              "You should probably not be using Wrap() directly; use "
     956             :              "GetOrCreateDOMReflector instead");
     957             : 
     958           0 :   MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
     959             :              "nsISupports must be on our primary inheritance chain");
     960             : 
     961           0 :   JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
     962           0 :   if (!global) {
     963           0 :     return false;
     964             :   }
     965           0 :   MOZ_ASSERT(JS_IsGlobalObject(global));
     966           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(global));
     967             : 
     968             :   // That might have ended up wrapping us already, due to the wonders
     969             :   // of XBL.  Check for that, and bail out as needed.
     970           0 :   aReflector.set(aCache->GetWrapper());
     971           0 :   if (aReflector) {
     972             : #ifdef DEBUG
     973           0 :     binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
     974             : #endif // DEBUG
     975           0 :     return true;
     976             :   }
     977             : 
     978           0 :   JSAutoCompartment ac(aCx, global);
     979           0 :   JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
     980           0 :   if (!canonicalProto) {
     981           0 :     return false;
     982             :   }
     983           0 :   JS::Rooted<JSObject*> proto(aCx);
     984           0 :   if (aGivenProto) {
     985           0 :     proto = aGivenProto;
     986             :     // Unfortunately, while aGivenProto was in the compartment of aCx
     987             :     // coming in, we changed compartments to that of "parent" so may need
     988             :     // to wrap the proto here.
     989           0 :     if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
     990           0 :       if (!JS_WrapObject(aCx, &proto)) {
     991           0 :         return false;
     992             :       }
     993             :     }
     994             :   } else {
     995           0 :     proto = canonicalProto;
     996             :   }
     997             : 
     998           0 :   BindingJSObjectCreator<mozilla::dom::FlyWebDiscoveryManager> creator(aCx);
     999           0 :   creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
    1000           0 :   if (!aReflector) {
    1001           0 :     return false;
    1002             :   }
    1003             : 
    1004           0 :   aCache->SetWrapper(aReflector);
    1005           0 :   creator.InitializationSucceeded();
    1006             : 
    1007           0 :   MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
    1008             :              aCache->GetWrapperPreserveColor() == aReflector);
    1009             :   // If proto != canonicalProto, we have to preserve our wrapper;
    1010             :   // otherwise we won't be able to properly recreate it later, since
    1011             :   // we won't know what proto to use.  Note that we don't check
    1012             :   // aGivenProto here, since it's entirely possible (and even
    1013             :   // somewhat common) to have a non-null aGivenProto which is the
    1014             :   // same as canonicalProto.
    1015           0 :   if (proto != canonicalProto) {
    1016           0 :     PreserveWrapper(aObject);
    1017             :   }
    1018             : 
    1019           0 :   return true;
    1020             : }
    1021             : 
    1022             : const NativePropertyHooks sNativePropertyHooks[] = { {
    1023             :   nullptr,
    1024             :   nullptr,
    1025             :   nullptr,
    1026             :   { sNativeProperties.Upcast(), nullptr },
    1027             :   prototypes::id::FlyWebDiscoveryManager,
    1028             :   constructors::id::FlyWebDiscoveryManager,
    1029             :   nullptr,
    1030             :   &DefaultXrayExpandoObjectClass
    1031             : } };
    1032             : 
    1033             : void
    1034           0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
    1035             : {
    1036           0 :   JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
    1037           0 :   if (!parentProto) {
    1038           0 :     return;
    1039             :   }
    1040             : 
    1041           0 :   JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
    1042           0 :   if (!constructorProto) {
    1043           0 :     return;
    1044             :   }
    1045             : 
    1046             :   static bool sIdsInited = false;
    1047           0 :   if (!sIdsInited && NS_IsMainThread()) {
    1048           0 :     if (!InitIds(aCx, sNativeProperties.Upcast())) {
    1049           0 :       return;
    1050             :     }
    1051           0 :     sIdsInited = true;
    1052             :   }
    1053             : 
    1054           0 :   JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::FlyWebDiscoveryManager);
    1055           0 :   JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::FlyWebDiscoveryManager);
    1056           0 :   dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
    1057             :                               &sPrototypeClass.mBase, protoCache,
    1058             :                               constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
    1059             :                               interfaceCache,
    1060             :                               sNativeProperties.Upcast(),
    1061             :                               nullptr,
    1062             :                               "FlyWebDiscoveryManager", aDefineOnGlobal,
    1063             :                               nullptr,
    1064           0 :                               false);
    1065             : }
    1066             : 
    1067             : JS::Handle<JSObject*>
    1068           0 : GetProtoObjectHandle(JSContext* aCx)
    1069             : {
    1070             :   /* Get the interface prototype object for this class.  This will create the
    1071             :      object as needed. */
    1072           0 :   bool aDefineOnGlobal = true;
    1073             : 
    1074             :   /* Make sure our global is sane.  Hopefully we can remove this sometime */
    1075           0 :   JSObject* global = JS::CurrentGlobalOrNull(aCx);
    1076           0 :   if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
    1077           0 :     return nullptr;
    1078             :   }
    1079             : 
    1080             :   /* Check to see whether the interface objects are already installed */
    1081           0 :   ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
    1082           0 :   if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::FlyWebDiscoveryManager)) {
    1083           0 :     JS::Rooted<JSObject*> rootedGlobal(aCx, global);
    1084           0 :     CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
    1085             :   }
    1086             : 
    1087             :   /*
    1088             :    * The object might _still_ be null, but that's OK.
    1089             :    *
    1090             :    * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
    1091             :    * traced by TraceProtoAndIfaceCache() and its contents are never
    1092             :    * changed after they have been set.
    1093             :    *
    1094             :    * Calling address() avoids the read read barrier that does gray
    1095             :    * unmarking, but it's not possible for the object to be gray here.
    1096             :    */
    1097             : 
    1098           0 :   const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::FlyWebDiscoveryManager);
    1099           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
    1100           0 :   return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
    1101             : }
    1102             : 
    1103             : JS::Handle<JSObject*>
    1104           0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
    1105             : {
    1106             :   /* Get the interface object for this class.  This will create the object as
    1107             :      needed. */
    1108             : 
    1109             :   /* Make sure our global is sane.  Hopefully we can remove this sometime */
    1110           0 :   JSObject* global = JS::CurrentGlobalOrNull(aCx);
    1111           0 :   if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
    1112           0 :     return nullptr;
    1113             :   }
    1114             : 
    1115             :   /* Check to see whether the interface objects are already installed */
    1116           0 :   ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
    1117           0 :   if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::FlyWebDiscoveryManager)) {
    1118           0 :     JS::Rooted<JSObject*> rootedGlobal(aCx, global);
    1119           0 :     CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
    1120             :   }
    1121             : 
    1122             :   /*
    1123             :    * The object might _still_ be null, but that's OK.
    1124             :    *
    1125             :    * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
    1126             :    * traced by TraceProtoAndIfaceCache() and its contents are never
    1127             :    * changed after they have been set.
    1128             :    *
    1129             :    * Calling address() avoids the read read barrier that does gray
    1130             :    * unmarking, but it's not possible for the object to be gray here.
    1131             :    */
    1132             : 
    1133           0 :   const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::FlyWebDiscoveryManager);
    1134           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
    1135           0 :   return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
    1136             : }
    1137             : 
    1138             : JSObject*
    1139           0 : GetConstructorObject(JSContext* aCx)
    1140             : {
    1141           0 :   return GetConstructorObjectHandle(aCx);
    1142             : }
    1143             : 
    1144             : } // namespace FlyWebDiscoveryManagerBinding
    1145             : 
    1146             : 
    1147             : 
    1148             : void
    1149           0 : FlyWebDiscoveryCallback::OnDiscoveredServicesChanged(JSContext* cx, JS::Handle<JS::Value> aThisVal, const Sequence<FlyWebDiscoveredService>& serviceList, ErrorResult& aRv)
    1150             : {
    1151           0 :   JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
    1152           0 :   JS::AutoValueVector argv(cx);
    1153           0 :   if (!argv.resize(1)) {
    1154           0 :     aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
    1155           0 :     return;
    1156             :   }
    1157           0 :   unsigned argc = 1;
    1158             : 
    1159             :   do {
    1160             : 
    1161           0 :     uint32_t length = serviceList.Length();
    1162           0 :     JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
    1163           0 :     if (!returnArray) {
    1164           0 :       aRv.Throw(NS_ERROR_UNEXPECTED);
    1165           0 :       return;
    1166             :     }
    1167             :     // Scope for 'tmp'
    1168             :     {
    1169           0 :       JS::Rooted<JS::Value> tmp(cx);
    1170           0 :       for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
    1171             :         // Control block to let us common up the JS_DefineElement calls when there
    1172             :         // are different ways to succeed at wrapping the object.
    1173             :         do {
    1174           0 :           if (!serviceList[sequenceIdx0].ToObjectInternal(cx, &tmp)) {
    1175           0 :             aRv.Throw(NS_ERROR_UNEXPECTED);
    1176           0 :             return;
    1177             :           }
    1178           0 :           break;
    1179             :         } while (0);
    1180           0 :         if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
    1181             :                               JSPROP_ENUMERATE)) {
    1182           0 :           aRv.Throw(NS_ERROR_UNEXPECTED);
    1183           0 :           return;
    1184             :         }
    1185             :       }
    1186             :     }
    1187           0 :     argv[0].setObject(*returnArray);
    1188           0 :     break;
    1189             :   } while (0);
    1190             : 
    1191           0 :   bool isCallable = JS::IsCallable(mCallback);
    1192           0 :   JS::Rooted<JS::Value> callable(cx);
    1193           0 :   if (isCallable) {
    1194           0 :     callable = JS::ObjectValue(*mCallback);
    1195             :   } else {
    1196           0 :     FlyWebDiscoveryCallbackAtoms* atomsCache = GetAtomCache<FlyWebDiscoveryCallbackAtoms>(cx);
    1197           0 :     if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
    1198           0 :         !GetCallableProperty(cx, atomsCache->onDiscoveredServicesChanged_id, &callable)) {
    1199           0 :       aRv.Throw(NS_ERROR_UNEXPECTED);
    1200           0 :       return;
    1201             :     }
    1202             :   }
    1203           0 :   JS::Rooted<JS::Value> thisValue(cx, isCallable ? aThisVal.get()
    1204           0 :                                                  : JS::ObjectValue(*mCallback));
    1205           0 :   if (!JS::Call(cx, thisValue, callable,
    1206           0 :                 JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
    1207           0 :     aRv.NoteJSContextException(cx);
    1208           0 :     return;
    1209             :   }
    1210             : }
    1211             : 
    1212             : bool
    1213           0 : FlyWebDiscoveryCallback::InitIds(JSContext* cx, FlyWebDiscoveryCallbackAtoms* atomsCache)
    1214             : {
    1215           0 :   MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
    1216             : 
    1217             :   // Initialize these in reverse order so that any failure leaves the first one
    1218             :   // uninitialized.
    1219           0 :   if (!atomsCache->onDiscoveredServicesChanged_id.init(cx, "onDiscoveredServicesChanged")) {
    1220           0 :     return false;
    1221             :   }
    1222           0 :   return true;
    1223             : }
    1224             : 
    1225             : 
    1226             : 
    1227             : void
    1228           0 : FlyWebPairingCallback::PairingSucceeded(const FlyWebPairedService& service, ErrorResult& aRv, const char* aExecutionReason, ExceptionHandling aExceptionHandling, JSCompartment* aCompartment)
    1229             : {
    1230           0 :   CallSetup s(this, aRv, "FlyWebPairingCallback.pairingSucceeded", aExceptionHandling, aCompartment);
    1231           0 :   JSContext* cx = s.GetContext();
    1232           0 :   if (!cx) {
    1233           0 :     MOZ_ASSERT(aRv.Failed());
    1234           0 :     return;
    1235             :   }
    1236           0 :   JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
    1237           0 :   JS::AutoValueVector argv(cx);
    1238           0 :   if (!argv.resize(1)) {
    1239           0 :     aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
    1240           0 :     return;
    1241             :   }
    1242           0 :   unsigned argc = 1;
    1243             : 
    1244             :   do {
    1245           0 :     if (!service.ToObjectInternal(cx, argv[0])) {
    1246           0 :       aRv.Throw(NS_ERROR_UNEXPECTED);
    1247           0 :       return;
    1248             :     }
    1249           0 :     break;
    1250             :   } while (0);
    1251             : 
    1252           0 :   JS::Rooted<JS::Value> callable(cx);
    1253           0 :   FlyWebPairingCallbackAtoms* atomsCache = GetAtomCache<FlyWebPairingCallbackAtoms>(cx);
    1254           0 :   if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
    1255           0 :       !GetCallableProperty(cx, atomsCache->pairingSucceeded_id, &callable)) {
    1256           0 :     aRv.Throw(NS_ERROR_UNEXPECTED);
    1257           0 :     return;
    1258             :   }
    1259           0 :   JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
    1260           0 :   if (!JS::Call(cx, thisValue, callable,
    1261           0 :                 JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
    1262           0 :     aRv.NoteJSContextException(cx);
    1263           0 :     return;
    1264             :   }
    1265             : }
    1266             : 
    1267             : void
    1268           0 : FlyWebPairingCallback::PairingFailed(const nsAString& error, ErrorResult& aRv, const char* aExecutionReason, ExceptionHandling aExceptionHandling, JSCompartment* aCompartment)
    1269             : {
    1270           0 :   CallSetup s(this, aRv, "FlyWebPairingCallback.pairingFailed", aExceptionHandling, aCompartment);
    1271           0 :   JSContext* cx = s.GetContext();
    1272           0 :   if (!cx) {
    1273           0 :     MOZ_ASSERT(aRv.Failed());
    1274           0 :     return;
    1275             :   }
    1276           0 :   JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
    1277           0 :   JS::AutoValueVector argv(cx);
    1278           0 :   if (!argv.resize(1)) {
    1279           0 :     aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
    1280           0 :     return;
    1281             :   }
    1282           0 :   unsigned argc = 1;
    1283             : 
    1284             :   do {
    1285           0 :     nsString mutableStr(error);
    1286           0 :     if (!xpc::NonVoidStringToJsval(cx, mutableStr, argv[0])) {
    1287           0 :       aRv.Throw(NS_ERROR_UNEXPECTED);
    1288           0 :       return;
    1289             :     }
    1290           0 :     break;
    1291             :   } while (0);
    1292             : 
    1293           0 :   JS::Rooted<JS::Value> callable(cx);
    1294           0 :   FlyWebPairingCallbackAtoms* atomsCache = GetAtomCache<FlyWebPairingCallbackAtoms>(cx);
    1295           0 :   if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
    1296           0 :       !GetCallableProperty(cx, atomsCache->pairingFailed_id, &callable)) {
    1297           0 :     aRv.Throw(NS_ERROR_UNEXPECTED);
    1298           0 :     return;
    1299             :   }
    1300           0 :   JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
    1301           0 :   if (!JS::Call(cx, thisValue, callable,
    1302           0 :                 JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
    1303           0 :     aRv.NoteJSContextException(cx);
    1304           0 :     return;
    1305             :   }
    1306             : }
    1307             : 
    1308             : bool
    1309           0 : FlyWebPairingCallback::InitIds(JSContext* cx, FlyWebPairingCallbackAtoms* atomsCache)
    1310             : {
    1311           0 :   MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
    1312             : 
    1313             :   // Initialize these in reverse order so that any failure leaves the first one
    1314             :   // uninitialized.
    1315           0 :   if (!atomsCache->pairingFailed_id.init(cx, "pairingFailed") ||
    1316           0 :       !atomsCache->pairingSucceeded_id.init(cx, "pairingSucceeded")) {
    1317           0 :     return false;
    1318             :   }
    1319           0 :   return true;
    1320             : }
    1321             : 
    1322             : 
    1323             : 
    1324             : namespace binding_detail {
    1325             : } // namespace binding_detail
    1326             : 
    1327             : 
    1328             : namespace binding_detail {
    1329             : } // namespace binding_detail
    1330             : 
    1331             : 
    1332             : } // namespace dom
    1333             : } // namespace mozilla

Generated by: LCOV version 1.13