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

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

Generated by: LCOV version 1.13