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

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

Generated by: LCOV version 1.13