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

          Line data    Source code
       1             : /* THIS FILE IS AUTOGENERATED FROM TestInterfaceJSDictionaries.webidl BY Codegen.py - DO NOT EDIT */
       2             : 
       3             : #include "AtomList.h"
       4             : #include "TestInterfaceJSDictionariesBinding.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/UnionConversions.h"
      10             : 
      11             : namespace mozilla {
      12             : namespace dom {
      13             : 
      14             : 
      15           0 : TestInterfaceJSDictionary2::TestInterfaceJSDictionary2()
      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             : bool
      23           0 : TestInterfaceJSDictionary2::InitIds(JSContext* cx, TestInterfaceJSDictionary2Atoms* atomsCache)
      24             : {
      25           0 :   MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
      26             : 
      27             :   // Initialize these in reverse order so that any failure leaves the first one
      28             :   // uninitialized.
      29           0 :   if (!atomsCache->innerObject_id.init(cx, "innerObject")) {
      30           0 :     return false;
      31             :   }
      32           0 :   return true;
      33             : }
      34             : 
      35             : bool
      36           0 : TestInterfaceJSDictionary2::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
      37             : {
      38             :   // Passing a null JSContext is OK only if we're initing from null,
      39             :   // Since in that case we will not have to do any property gets
      40             :   // Also evaluate isNullOrUndefined in order to avoid false-positive
      41             :   // checkers by static analysis tools
      42           0 :   MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
      43           0 :   TestInterfaceJSDictionary2Atoms* atomsCache = nullptr;
      44           0 :   if (cx) {
      45           0 :     atomsCache = GetAtomCache<TestInterfaceJSDictionary2Atoms>(cx);
      46           0 :     if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
      47           0 :       return false;
      48             :     }
      49             :   }
      50             : 
      51           0 :   if (!IsConvertibleToDictionary(val)) {
      52           0 :     return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
      53             :   }
      54             : 
      55           0 :   bool isNull = val.isNullOrUndefined();
      56             :   // We only need these if !isNull, in which case we have |cx|.
      57           0 :   Maybe<JS::Rooted<JSObject *> > object;
      58           0 :   Maybe<JS::Rooted<JS::Value> > temp;
      59           0 :   if (!isNull) {
      60           0 :     MOZ_ASSERT(cx);
      61           0 :     object.emplace(cx, &val.toObject());
      62           0 :     temp.emplace(cx);
      63             :   }
      64           0 :   if (!isNull) {
      65           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->innerObject_id, temp.ptr())) {
      66           0 :       return false;
      67             :     }
      68             :   }
      69           0 :   if (!isNull && !temp->isUndefined()) {
      70           0 :     mInnerObject.Construct();
      71           0 :     if (temp.ref().isObject()) {
      72             : #ifdef __clang__
      73             : #pragma clang diagnostic push
      74             : #pragma clang diagnostic ignored "-Wunreachable-code"
      75             : #pragma clang diagnostic ignored "-Wunreachable-code-return"
      76             : #endif // __clang__
      77           0 :       if ((passedToJSImpl) && !CallerSubsumes(temp.ref())) {
      78           0 :         ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "'innerObject' member of TestInterfaceJSDictionary2");
      79           0 :         return false;
      80             :       }
      81             : #ifdef __clang__
      82             : #pragma clang diagnostic pop
      83             : #endif // __clang__
      84           0 :       (mInnerObject.Value()) = &temp.ref().toObject();
      85             :     } else {
      86           0 :       ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'innerObject' member of TestInterfaceJSDictionary2");
      87           0 :       return false;
      88             :     }
      89           0 :     mIsAnyMemberPresent = true;
      90             :   }
      91           0 :   return true;
      92             : }
      93             : 
      94             : bool
      95           0 : TestInterfaceJSDictionary2::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
      96             : {
      97           0 :   TestInterfaceJSDictionary2Atoms* atomsCache = GetAtomCache<TestInterfaceJSDictionary2Atoms>(cx);
      98           0 :   if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
      99           0 :     return false;
     100             :   }
     101             : 
     102           0 :   JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
     103           0 :   if (!obj) {
     104           0 :     return false;
     105             :   }
     106           0 :   rval.set(JS::ObjectValue(*obj));
     107             : 
     108           0 :   if (mInnerObject.WasPassed()) {
     109             :     do {
     110             :       // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     111           0 :       JS::Rooted<JS::Value> temp(cx);
     112           0 :       JSObject* const & currentValue = mInnerObject.InternalValue();
     113           0 :       JS::ExposeObjectToActiveJS(currentValue);
     114           0 :       temp.setObject(*currentValue);
     115           0 :       if (!MaybeWrapObjectValue(cx, &temp)) {
     116           0 :         return false;
     117             :       }
     118           0 :       if (!JS_DefinePropertyById(cx, obj, atomsCache->innerObject_id, temp, JSPROP_ENUMERATE)) {
     119           0 :         return false;
     120             :       }
     121           0 :       break;
     122             :     } while(0);
     123             :   }
     124             : 
     125           0 :   return true;
     126             : }
     127             : 
     128             : void
     129           0 : TestInterfaceJSDictionary2::TraceDictionary(JSTracer* trc)
     130             : {
     131           0 :   if (mInnerObject.WasPassed()) {
     132           0 :     JS::UnsafeTraceRoot(trc, &mInnerObject.Value(), "TestInterfaceJSDictionary2.mInnerObject");
     133             :   }
     134           0 : }
     135             : 
     136             : namespace binding_detail {
     137             : } // namespace binding_detail
     138             : 
     139             : 
     140             : 
     141           0 : TestInterfaceJSDictionary::TestInterfaceJSDictionary()
     142             :   : mAnyMember(JS::UndefinedValue()),
     143           0 :     mInnerDictionary(FastDictionaryInitializer())
     144             : {
     145             :   // Safe to pass a null context if we pass a null value
     146           0 :   Init(nullptr, JS::NullHandleValue);
     147           0 : }
     148             : 
     149             : 
     150             : bool
     151           0 : TestInterfaceJSDictionary::InitIds(JSContext* cx, TestInterfaceJSDictionaryAtoms* atomsCache)
     152             : {
     153           0 :   MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
     154             : 
     155             :   // Initialize these in reverse order so that any failure leaves the first one
     156             :   // uninitialized.
     157           0 :   if (!atomsCache->objectOrStringMember_id.init(cx, "objectOrStringMember") ||
     158           0 :       !atomsCache->objectMember_id.init(cx, "objectMember") ||
     159           0 :       !atomsCache->innerDictionary_id.init(cx, "innerDictionary") ||
     160           0 :       !atomsCache->anySequenceMember_id.init(cx, "anySequenceMember") ||
     161           0 :       !atomsCache->anyMember_id.init(cx, "anyMember")) {
     162           0 :     return false;
     163             :   }
     164           0 :   return true;
     165             : }
     166             : 
     167             : bool
     168           0 : TestInterfaceJSDictionary::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
     169             : {
     170             :   // Passing a null JSContext is OK only if we're initing from null,
     171             :   // Since in that case we will not have to do any property gets
     172             :   // Also evaluate isNullOrUndefined in order to avoid false-positive
     173             :   // checkers by static analysis tools
     174           0 :   MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
     175           0 :   TestInterfaceJSDictionaryAtoms* atomsCache = nullptr;
     176           0 :   if (cx) {
     177           0 :     atomsCache = GetAtomCache<TestInterfaceJSDictionaryAtoms>(cx);
     178           0 :     if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
     179           0 :       return false;
     180             :     }
     181             :   }
     182             : 
     183           0 :   if (!IsConvertibleToDictionary(val)) {
     184           0 :     return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
     185             :   }
     186             : 
     187           0 :   bool isNull = val.isNullOrUndefined();
     188             :   // We only need these if !isNull, in which case we have |cx|.
     189           0 :   Maybe<JS::Rooted<JSObject *> > object;
     190           0 :   Maybe<JS::Rooted<JS::Value> > temp;
     191           0 :   if (!isNull) {
     192           0 :     MOZ_ASSERT(cx);
     193           0 :     object.emplace(cx, &val.toObject());
     194           0 :     temp.emplace(cx);
     195             :   }
     196           0 :   if (!isNull) {
     197           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->anyMember_id, temp.ptr())) {
     198           0 :       return false;
     199             :     }
     200             :   }
     201           0 :   if (!isNull && !temp->isUndefined()) {
     202             : #ifdef __clang__
     203             : #pragma clang diagnostic push
     204             : #pragma clang diagnostic ignored "-Wunreachable-code"
     205             : #pragma clang diagnostic ignored "-Wunreachable-code-return"
     206             : #endif // __clang__
     207           0 :     if ((passedToJSImpl) && !CallerSubsumes(temp.ref())) {
     208           0 :       ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "'anyMember' member of TestInterfaceJSDictionary");
     209           0 :       return false;
     210             :     }
     211             : #ifdef __clang__
     212             : #pragma clang diagnostic pop
     213             : #endif // __clang__
     214           0 :     mAnyMember = temp.ref();
     215             :   } else {
     216           0 :     mAnyMember = JS::UndefinedValue();
     217             :   }
     218           0 :   mIsAnyMemberPresent = true;
     219             : 
     220           0 :   if (!isNull) {
     221           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->anySequenceMember_id, temp.ptr())) {
     222           0 :       return false;
     223             :     }
     224             :   }
     225           0 :   if (!isNull && !temp->isUndefined()) {
     226           0 :     mAnySequenceMember.Construct();
     227           0 :     if (temp.ref().isObject()) {
     228           0 :       JS::ForOfIterator iter(cx);
     229           0 :       if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
     230           0 :         return false;
     231             :       }
     232           0 :       if (!iter.valueIsIterable()) {
     233           0 :         ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'anySequenceMember' member of TestInterfaceJSDictionary");
     234           0 :         return false;
     235             :       }
     236           0 :       Sequence<JS::Value> &arr = (mAnySequenceMember.Value());
     237           0 :       JS::Rooted<JS::Value> temp(cx);
     238             :       while (true) {
     239             :         bool done;
     240           0 :         if (!iter.next(&temp, &done)) {
     241           0 :           return false;
     242             :         }
     243           0 :         if (done) {
     244           0 :           break;
     245             :         }
     246           0 :         JS::Value* slotPtr = arr.AppendElement(mozilla::fallible);
     247           0 :         if (!slotPtr) {
     248           0 :           JS_ReportOutOfMemory(cx);
     249           0 :           return false;
     250             :         }
     251           0 :         JS::Value& slot = *slotPtr;
     252             : #ifdef __clang__
     253             : #pragma clang diagnostic push
     254             : #pragma clang diagnostic ignored "-Wunreachable-code"
     255             : #pragma clang diagnostic ignored "-Wunreachable-code-return"
     256             : #endif // __clang__
     257           0 :         if ((passedToJSImpl) && !CallerSubsumes(temp)) {
     258           0 :           ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "element of 'anySequenceMember' member of TestInterfaceJSDictionary");
     259           0 :           return false;
     260             :         }
     261             : #ifdef __clang__
     262             : #pragma clang diagnostic pop
     263             : #endif // __clang__
     264           0 :         slot = temp;
     265           0 :       }
     266             :     } else {
     267           0 :       ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'anySequenceMember' member of TestInterfaceJSDictionary");
     268           0 :       return false;
     269             :     }
     270           0 :     mIsAnyMemberPresent = true;
     271             :   }
     272             : 
     273           0 :   if (!isNull) {
     274           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->innerDictionary_id, temp.ptr())) {
     275           0 :       return false;
     276             :     }
     277             :   }
     278           0 :   if (!mInnerDictionary.Init(cx, (!isNull && !temp->isUndefined()) ? temp.ref() : JS::NullHandleValue,  "'innerDictionary' member of TestInterfaceJSDictionary", passedToJSImpl)) {
     279           0 :     return false;
     280             :   }
     281           0 :   mIsAnyMemberPresent = true;
     282             : 
     283           0 :   if (!isNull) {
     284           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->objectMember_id, temp.ptr())) {
     285           0 :       return false;
     286             :     }
     287             :   }
     288           0 :   if (!isNull && !temp->isUndefined()) {
     289           0 :     mObjectMember.Construct();
     290           0 :     if (temp.ref().isObject()) {
     291             : #ifdef __clang__
     292             : #pragma clang diagnostic push
     293             : #pragma clang diagnostic ignored "-Wunreachable-code"
     294             : #pragma clang diagnostic ignored "-Wunreachable-code-return"
     295             : #endif // __clang__
     296           0 :       if ((passedToJSImpl) && !CallerSubsumes(temp.ref())) {
     297           0 :         ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "'objectMember' member of TestInterfaceJSDictionary");
     298           0 :         return false;
     299             :       }
     300             : #ifdef __clang__
     301             : #pragma clang diagnostic pop
     302             : #endif // __clang__
     303           0 :       (mObjectMember.Value()) = &temp.ref().toObject();
     304             :     } else {
     305           0 :       ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'objectMember' member of TestInterfaceJSDictionary");
     306           0 :       return false;
     307             :     }
     308           0 :     mIsAnyMemberPresent = true;
     309             :   }
     310             : 
     311           0 :   if (!isNull) {
     312           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->objectOrStringMember_id, temp.ptr())) {
     313           0 :       return false;
     314             :     }
     315             :   }
     316           0 :   if (!isNull && !temp->isUndefined()) {
     317           0 :     mObjectOrStringMember.Construct();
     318             :     {
     319           0 :       bool done = false, failed = false, tryNext;
     320           0 :       if (temp.ref().isObject()) {
     321           0 :         if (!(mObjectOrStringMember.Value()).SetToObject(cx, &temp.ref().toObject(), passedToJSImpl)) {
     322           0 :           return false;
     323             :         }
     324           0 :         done = true;
     325             :       } else {
     326             :         do {
     327           0 :           done = (failed = !(mObjectOrStringMember.Value()).TrySetToString(cx, temp.ref(), tryNext)) || !tryNext;
     328           0 :           break;
     329             :         } while (0);
     330             :       }
     331           0 :       if (failed) {
     332           0 :         return false;
     333             :       }
     334           0 :       if (!done) {
     335           0 :         ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "'objectOrStringMember' member of TestInterfaceJSDictionary", "Object");
     336           0 :         return false;
     337             :       }
     338             :     }
     339           0 :     mIsAnyMemberPresent = true;
     340             :   }
     341           0 :   return true;
     342             : }
     343             : 
     344             : bool
     345           0 : TestInterfaceJSDictionary::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
     346             : {
     347           0 :   TestInterfaceJSDictionaryAtoms* atomsCache = GetAtomCache<TestInterfaceJSDictionaryAtoms>(cx);
     348           0 :   if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
     349           0 :     return false;
     350             :   }
     351             : 
     352           0 :   JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
     353           0 :   if (!obj) {
     354           0 :     return false;
     355             :   }
     356           0 :   rval.set(JS::ObjectValue(*obj));
     357             : 
     358             :   do {
     359             :     // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     360           0 :     JS::Rooted<JS::Value> temp(cx);
     361           0 :     JS::Value const & currentValue = mAnyMember;
     362           0 :     JS::ExposeValueToActiveJS(currentValue);
     363           0 :     temp.set(currentValue);
     364           0 :     if (!MaybeWrapValue(cx, &temp)) {
     365           0 :       return false;
     366             :     }
     367           0 :     if (!JS_DefinePropertyById(cx, obj, atomsCache->anyMember_id, temp, JSPROP_ENUMERATE)) {
     368           0 :       return false;
     369             :     }
     370           0 :     break;
     371             :   } while(0);
     372             : 
     373           0 :   if (mAnySequenceMember.WasPassed()) {
     374             :     do {
     375             :       // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     376           0 :       JS::Rooted<JS::Value> temp(cx);
     377           0 :       Sequence<JS::Value> const & currentValue = mAnySequenceMember.InternalValue();
     378             : 
     379           0 :       uint32_t length = currentValue.Length();
     380           0 :       JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
     381           0 :       if (!returnArray) {
     382           0 :         return false;
     383             :       }
     384             :       // Scope for 'tmp'
     385             :       {
     386           0 :         JS::Rooted<JS::Value> tmp(cx);
     387           0 :         for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
     388             :           // Control block to let us common up the JS_DefineElement calls when there
     389             :           // are different ways to succeed at wrapping the object.
     390             :           do {
     391           0 :             JS::ExposeValueToActiveJS(currentValue[sequenceIdx0]);
     392           0 :             tmp.set(currentValue[sequenceIdx0]);
     393           0 :             if (!MaybeWrapValue(cx, &tmp)) {
     394           0 :               return false;
     395             :             }
     396           0 :             break;
     397             :           } while (0);
     398           0 :           if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
     399             :                                 JSPROP_ENUMERATE)) {
     400           0 :             return false;
     401             :           }
     402             :         }
     403             :       }
     404           0 :       temp.setObject(*returnArray);
     405           0 :       if (!JS_DefinePropertyById(cx, obj, atomsCache->anySequenceMember_id, temp, JSPROP_ENUMERATE)) {
     406           0 :         return false;
     407             :       }
     408           0 :       break;
     409             :     } while(0);
     410             :   }
     411             : 
     412             :   do {
     413             :     // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     414           0 :     JS::Rooted<JS::Value> temp(cx);
     415           0 :     TestInterfaceJSDictionary2 const & currentValue = mInnerDictionary;
     416           0 :     if (!currentValue.ToObjectInternal(cx, &temp)) {
     417           0 :       return false;
     418             :     }
     419           0 :     if (!JS_DefinePropertyById(cx, obj, atomsCache->innerDictionary_id, temp, JSPROP_ENUMERATE)) {
     420           0 :       return false;
     421             :     }
     422           0 :     break;
     423             :   } while(0);
     424             : 
     425           0 :   if (mObjectMember.WasPassed()) {
     426             :     do {
     427             :       // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     428           0 :       JS::Rooted<JS::Value> temp(cx);
     429           0 :       JSObject* const & currentValue = mObjectMember.InternalValue();
     430           0 :       JS::ExposeObjectToActiveJS(currentValue);
     431           0 :       temp.setObject(*currentValue);
     432           0 :       if (!MaybeWrapObjectValue(cx, &temp)) {
     433           0 :         return false;
     434             :       }
     435           0 :       if (!JS_DefinePropertyById(cx, obj, atomsCache->objectMember_id, temp, JSPROP_ENUMERATE)) {
     436           0 :         return false;
     437             :       }
     438           0 :       break;
     439             :     } while(0);
     440             :   }
     441             : 
     442           0 :   if (mObjectOrStringMember.WasPassed()) {
     443             :     do {
     444             :       // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     445           0 :       JS::Rooted<JS::Value> temp(cx);
     446           0 :       OwningObjectOrString const & currentValue = mObjectOrStringMember.InternalValue();
     447           0 :       if (!currentValue.ToJSVal(cx, obj, &temp)) {
     448           0 :         return false;
     449             :       }
     450           0 :       if (!JS_DefinePropertyById(cx, obj, atomsCache->objectOrStringMember_id, temp, JSPROP_ENUMERATE)) {
     451           0 :         return false;
     452             :       }
     453           0 :       break;
     454             :     } while(0);
     455             :   }
     456             : 
     457           0 :   return true;
     458             : }
     459             : 
     460             : void
     461           0 : TestInterfaceJSDictionary::TraceDictionary(JSTracer* trc)
     462             : {
     463           0 :   JS::UnsafeTraceRoot(trc, &mAnyMember, "TestInterfaceJSDictionary.mAnyMember");
     464             : 
     465           0 :   if (mAnySequenceMember.WasPassed()) {
     466           0 :     DoTraceSequence(trc, mAnySequenceMember.Value());
     467             :   }
     468             : 
     469           0 :   mInnerDictionary.TraceDictionary(trc);
     470             : 
     471           0 :   if (mObjectMember.WasPassed()) {
     472           0 :     JS::UnsafeTraceRoot(trc, &mObjectMember.Value(), "TestInterfaceJSDictionary.mObjectMember");
     473             :   }
     474             : 
     475           0 :   if (mObjectOrStringMember.WasPassed()) {
     476           0 :     mObjectOrStringMember.Value().TraceUnion(trc);
     477             :   }
     478           0 : }
     479             : 
     480             : namespace binding_detail {
     481             : } // namespace binding_detail
     482             : 
     483             : 
     484             : } // namespace dom
     485             : } // namespace mozilla

Generated by: LCOV version 1.13