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

          Line data    Source code
       1             : /* THIS FILE IS AUTOGENERATED FROM KeyIdsInitData.webidl BY Codegen.py - DO NOT EDIT */
       2             : 
       3             : #include "AtomList.h"
       4             : #include "KeyIdsInitDataBinding.h"
       5             : #include "mozilla/OwningNonNull.h"
       6             : #include "mozilla/dom/BindingUtils.h"
       7             : #include "mozilla/dom/NonRefcountedDOMObject.h"
       8             : #include "mozilla/dom/ScriptSettings.h"
       9             : #include "mozilla/dom/SimpleGlobalObject.h"
      10             : 
      11             : namespace mozilla {
      12             : namespace dom {
      13             : 
      14             : 
      15           0 : KeyIdsInitData::KeyIdsInitData()
      16             : {
      17             :   // Safe to pass a null context if we pass a null value
      18           0 :   Init(nullptr, JS::NullHandleValue);
      19           0 : }
      20             : 
      21             : 
      22             : 
      23             : bool
      24           0 : KeyIdsInitData::InitIds(JSContext* cx, KeyIdsInitDataAtoms* atomsCache)
      25             : {
      26           0 :   MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
      27             : 
      28             :   // Initialize these in reverse order so that any failure leaves the first one
      29             :   // uninitialized.
      30           0 :   if (!atomsCache->kids_id.init(cx, "kids")) {
      31           0 :     return false;
      32             :   }
      33           0 :   return true;
      34             : }
      35             : 
      36             : bool
      37           0 : KeyIdsInitData::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
      38             : {
      39             :   // Passing a null JSContext is OK only if we're initing from null,
      40             :   // Since in that case we will not have to do any property gets
      41             :   // Also evaluate isNullOrUndefined in order to avoid false-positive
      42             :   // checkers by static analysis tools
      43           0 :   MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
      44           0 :   KeyIdsInitDataAtoms* atomsCache = nullptr;
      45           0 :   if (cx) {
      46           0 :     atomsCache = GetAtomCache<KeyIdsInitDataAtoms>(cx);
      47           0 :     if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
      48           0 :       return false;
      49             :     }
      50             :   }
      51             : 
      52           0 :   if (!IsConvertibleToDictionary(val)) {
      53           0 :     return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
      54             :   }
      55             : 
      56           0 :   bool isNull = val.isNullOrUndefined();
      57             :   // We only need these if !isNull, in which case we have |cx|.
      58           0 :   Maybe<JS::Rooted<JSObject *> > object;
      59           0 :   Maybe<JS::Rooted<JS::Value> > temp;
      60           0 :   if (!isNull) {
      61           0 :     MOZ_ASSERT(cx);
      62           0 :     object.emplace(cx, &val.toObject());
      63           0 :     temp.emplace(cx);
      64             :   }
      65           0 :   if (!isNull) {
      66           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->kids_id, temp.ptr())) {
      67           0 :       return false;
      68             :     }
      69             :   }
      70           0 :   if (!isNull && !temp->isUndefined()) {
      71           0 :     if (temp.ref().isObject()) {
      72           0 :       JS::ForOfIterator iter(cx);
      73           0 :       if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
      74           0 :         return false;
      75             :       }
      76           0 :       if (!iter.valueIsIterable()) {
      77           0 :         ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'kids' member of KeyIdsInitData");
      78           0 :         return false;
      79             :       }
      80           0 :       Sequence<nsString> &arr = mKids;
      81           0 :       JS::Rooted<JS::Value> temp(cx);
      82             :       while (true) {
      83             :         bool done;
      84           0 :         if (!iter.next(&temp, &done)) {
      85           0 :           return false;
      86             :         }
      87           0 :         if (done) {
      88           0 :           break;
      89             :         }
      90           0 :         nsString* slotPtr = arr.AppendElement(mozilla::fallible);
      91           0 :         if (!slotPtr) {
      92           0 :           JS_ReportOutOfMemory(cx);
      93           0 :           return false;
      94             :         }
      95           0 :         nsString& slot = *slotPtr;
      96           0 :         if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
      97           0 :           return false;
      98             :         }
      99           0 :       }
     100             :     } else {
     101           0 :       ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'kids' member of KeyIdsInitData");
     102           0 :       return false;
     103             :     }
     104           0 :     mIsAnyMemberPresent = true;
     105           0 :   } else if (cx) {
     106             :     // Don't error out if we have no cx.  In that
     107             :     // situation the caller is default-constructing us and we'll
     108             :     // just assume they know what they're doing.
     109           0 :     return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER,
     110           0 :                              "'kids' member of KeyIdsInitData");
     111             :   }
     112           0 :   return true;
     113             : }
     114             : 
     115             : bool
     116           0 : KeyIdsInitData::Init(const nsAString& aJSON)
     117             : {
     118           0 :   AutoJSAPI jsapi;
     119           0 :   JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
     120           0 :   if (!cleanGlobal) {
     121           0 :     return false;
     122             :   }
     123           0 :   if (!jsapi.Init(cleanGlobal)) {
     124           0 :     return false;
     125             :   }
     126           0 :   JSContext* cx = jsapi.cx();
     127           0 :   JS::Rooted<JS::Value> json(cx);
     128           0 :   bool ok = ParseJSON(cx, aJSON, &json);
     129           0 :   NS_ENSURE_TRUE(ok, false);
     130           0 :   return Init(cx, json);
     131             : }
     132             : 
     133             : bool
     134           0 : KeyIdsInitData::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
     135             : {
     136           0 :   KeyIdsInitDataAtoms* atomsCache = GetAtomCache<KeyIdsInitDataAtoms>(cx);
     137           0 :   if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
     138           0 :     return false;
     139             :   }
     140             : 
     141           0 :   JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
     142           0 :   if (!obj) {
     143           0 :     return false;
     144             :   }
     145           0 :   rval.set(JS::ObjectValue(*obj));
     146             : 
     147             :   do {
     148             :     // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     149           0 :     JS::Rooted<JS::Value> temp(cx);
     150           0 :     Sequence<nsString> const & currentValue = mKids;
     151             : 
     152           0 :     uint32_t length = currentValue.Length();
     153           0 :     JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
     154           0 :     if (!returnArray) {
     155           0 :       return false;
     156             :     }
     157             :     // Scope for 'tmp'
     158             :     {
     159           0 :       JS::Rooted<JS::Value> tmp(cx);
     160           0 :       for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
     161             :         // Control block to let us common up the JS_DefineElement calls when there
     162             :         // are different ways to succeed at wrapping the object.
     163             :         do {
     164           0 :           if (!xpc::NonVoidStringToJsval(cx, currentValue[sequenceIdx0], &tmp)) {
     165           0 :             return false;
     166             :           }
     167           0 :           break;
     168             :         } while (0);
     169           0 :         if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
     170             :                               JSPROP_ENUMERATE)) {
     171           0 :           return false;
     172             :         }
     173             :       }
     174             :     }
     175           0 :     temp.setObject(*returnArray);
     176           0 :     if (!JS_DefinePropertyById(cx, obj, atomsCache->kids_id, temp, JSPROP_ENUMERATE)) {
     177           0 :       return false;
     178             :     }
     179           0 :     break;
     180             :   } while(0);
     181             : 
     182           0 :   return true;
     183             : }
     184             : 
     185             : bool
     186           0 : KeyIdsInitData::ToJSON(nsAString& aJSON) const
     187             : {
     188           0 :   AutoJSAPI jsapi;
     189           0 :   jsapi.Init();
     190           0 :   JSContext *cx = jsapi.cx();
     191             :   // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
     192             :   // because we'll only be creating objects, in ways that have no
     193             :   // side-effects, followed by a call to JS::ToJSONMaybeSafely,
     194             :   // which likewise guarantees no side-effects for the sorts of
     195             :   // things we will pass it.
     196           0 :   JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
     197           0 :   JS::Rooted<JS::Value> val(cx);
     198           0 :   if (!ToObjectInternal(cx, &val)) {
     199           0 :     return false;
     200             :   }
     201           0 :   JS::Rooted<JSObject*> obj(cx, &val.toObject());
     202           0 :   return StringifyToJSON(cx, obj, aJSON);
     203             : }
     204             : 
     205             : void
     206           0 : KeyIdsInitData::TraceDictionary(JSTracer* trc)
     207             : {
     208           0 : }
     209             : 
     210             : KeyIdsInitData&
     211           0 : KeyIdsInitData::operator=(const KeyIdsInitData& aOther)
     212             : {
     213           0 :   mKids = aOther.mKids;
     214           0 :   return *this;
     215             : }
     216             : 
     217             : namespace binding_detail {
     218             : } // namespace binding_detail
     219             : 
     220             : 
     221             : } // namespace dom
     222             : } // namespace mozilla

Generated by: LCOV version 1.13