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

          Line data    Source code
       1             : #include "mozilla/FloatingPoint.h"
       2             : #include "mozilla/dom/CanvasGradient.h"
       3             : #include "mozilla/dom/CanvasPattern.h"
       4             : #include "mozilla/dom/Directory.h"
       5             : #include "mozilla/dom/File.h"
       6             : #include "mozilla/dom/HTMLOptGroupElement.h"
       7             : #include "mozilla/dom/HTMLOptionElement.h"
       8             : #include "mozilla/dom/PrimitiveConversions.h"
       9             : #include "mozilla/dom/UnionTypes.h"
      10             : #include "nsGenericHTMLElement.h"
      11             : #include "nsINode.h"
      12             : 
      13             : namespace mozilla {
      14             : namespace dom {
      15             : void
      16           0 : ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningCanvasPatternOrCanvasGradient& aUnion, const char* aName, uint32_t aFlags)
      17             : {
      18           0 :   if (aUnion.IsCanvasPattern()) {
      19           0 :     ImplCycleCollectionTraverse(aCallback, aUnion.GetAsCanvasPattern(), "mCanvasPattern", aFlags);
      20           0 :   } else if (aUnion.IsCanvasGradient()) {
      21           0 :     ImplCycleCollectionTraverse(aCallback, aUnion.GetAsCanvasGradient(), "mCanvasGradient", aFlags);
      22             :   }
      23           0 : }
      24             : 
      25             : void
      26           0 : ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningCanvasPatternOrNullOrCanvasGradient& aUnion, const char* aName, uint32_t aFlags)
      27             : {
      28           0 :   if (aUnion.IsCanvasPattern()) {
      29           0 :     ImplCycleCollectionTraverse(aCallback, aUnion.GetAsCanvasPattern(), "mCanvasPattern", aFlags);
      30           0 :   } else if (aUnion.IsCanvasGradient()) {
      31           0 :     ImplCycleCollectionTraverse(aCallback, aUnion.GetAsCanvasGradient(), "mCanvasGradient", aFlags);
      32             :   }
      33           0 : }
      34             : 
      35             : void
      36           0 : ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningEventHandlerNonNullOrNullOrLong& aUnion, const char* aName, uint32_t aFlags)
      37             : {
      38           0 :   if (aUnion.IsEventHandlerNonNull()) {
      39           0 :     ImplCycleCollectionTraverse(aCallback, aUnion.GetAsEventHandlerNonNull(), "mEventHandlerNonNull", aFlags);
      40             :   }
      41           0 : }
      42             : 
      43             : void
      44           0 : ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningFileOrDirectory& aUnion, const char* aName, uint32_t aFlags)
      45             : {
      46           0 :   if (aUnion.IsFile()) {
      47           0 :     ImplCycleCollectionTraverse(aCallback, aUnion.GetAsFile(), "mFile", aFlags);
      48           0 :   } else if (aUnion.IsDirectory()) {
      49           0 :     ImplCycleCollectionTraverse(aCallback, aUnion.GetAsDirectory(), "mDirectory", aFlags);
      50             :   }
      51           0 : }
      52             : 
      53             : void
      54           0 : ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningHTMLElementOrLong& aUnion, const char* aName, uint32_t aFlags)
      55             : {
      56           0 :   if (aUnion.IsHTMLElement()) {
      57           0 :     ImplCycleCollectionTraverse(aCallback, aUnion.GetAsHTMLElement(), "mHTMLElement", aFlags);
      58             :   }
      59           0 : }
      60             : 
      61             : void
      62           0 : ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningHTMLOptionElementOrHTMLOptGroupElement& aUnion, const char* aName, uint32_t aFlags)
      63             : {
      64           0 :   if (aUnion.IsHTMLOptionElement()) {
      65           0 :     ImplCycleCollectionTraverse(aCallback, aUnion.GetAsHTMLOptionElement(), "mHTMLOptionElement", aFlags);
      66           0 :   } else if (aUnion.IsHTMLOptGroupElement()) {
      67           0 :     ImplCycleCollectionTraverse(aCallback, aUnion.GetAsHTMLOptGroupElement(), "mHTMLOptGroupElement", aFlags);
      68             :   }
      69           0 : }
      70             : 
      71             : void
      72           0 : ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningImageDataOrNullSequenceOrLong& aUnion, const char* aName, uint32_t aFlags)
      73             : {
      74           0 :   if (aUnion.IsImageDataOrNullSequence()) {
      75           0 :     ImplCycleCollectionTraverse(aCallback, aUnion.GetAsImageDataOrNullSequence(), "mImageDataOrNullSequence", aFlags);
      76             :   }
      77           0 : }
      78             : 
      79             : void
      80           0 : ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningImageDataOrNullSequenceSequenceOrLong& aUnion, const char* aName, uint32_t aFlags)
      81             : {
      82           0 :   if (aUnion.IsImageDataOrNullSequenceSequence()) {
      83           0 :     ImplCycleCollectionTraverse(aCallback, aUnion.GetAsImageDataOrNullSequenceSequence(), "mImageDataOrNullSequenceSequence", aFlags);
      84             :   }
      85           0 : }
      86             : 
      87             : void
      88           0 : ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningImageDataSequenceOrLong& aUnion, const char* aName, uint32_t aFlags)
      89             : {
      90           0 :   if (aUnion.IsImageDataSequence()) {
      91           0 :     ImplCycleCollectionTraverse(aCallback, aUnion.GetAsImageDataSequence(), "mImageDataSequence", aFlags);
      92             :   }
      93           0 : }
      94             : 
      95             : void
      96           0 : ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningImageDataSequenceSequenceOrLong& aUnion, const char* aName, uint32_t aFlags)
      97             : {
      98           0 :   if (aUnion.IsImageDataSequenceSequence()) {
      99           0 :     ImplCycleCollectionTraverse(aCallback, aUnion.GetAsImageDataSequenceSequence(), "mImageDataSequenceSequence", aFlags);
     100             :   }
     101           0 : }
     102             : 
     103             : void
     104           0 : ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningNodeOrLongOrBoolean& aUnion, const char* aName, uint32_t aFlags)
     105             : {
     106           0 :   if (aUnion.IsNode()) {
     107           0 :     ImplCycleCollectionTraverse(aCallback, aUnion.GetAsNode(), "mNode", aFlags);
     108             :   }
     109           0 : }
     110             : 
     111             : void
     112           0 : ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningNodeOrString& aUnion, const char* aName, uint32_t aFlags)
     113             : {
     114           0 :   if (aUnion.IsNode()) {
     115           0 :     ImplCycleCollectionTraverse(aCallback, aUnion.GetAsNode(), "mNode", aFlags);
     116             :   }
     117           0 : }
     118             : 
     119             : void
     120           0 : ImplCycleCollectionUnlink(OwningCanvasPatternOrCanvasGradient& aUnion)
     121             : {
     122           0 :   aUnion.Uninit();
     123           0 : }
     124             : 
     125             : void
     126           0 : ImplCycleCollectionUnlink(OwningCanvasPatternOrNullOrCanvasGradient& aUnion)
     127             : {
     128           0 :   aUnion.Uninit();
     129           0 : }
     130             : 
     131             : void
     132           0 : ImplCycleCollectionUnlink(OwningEventHandlerNonNullOrNullOrLong& aUnion)
     133             : {
     134           0 :   aUnion.Uninit();
     135           0 : }
     136             : 
     137             : void
     138           0 : ImplCycleCollectionUnlink(OwningFileOrDirectory& aUnion)
     139             : {
     140           0 :   aUnion.Uninit();
     141           0 : }
     142             : 
     143             : void
     144           0 : ImplCycleCollectionUnlink(OwningHTMLElementOrLong& aUnion)
     145             : {
     146           0 :   aUnion.Uninit();
     147           0 : }
     148             : 
     149             : void
     150           0 : ImplCycleCollectionUnlink(OwningHTMLOptionElementOrHTMLOptGroupElement& aUnion)
     151             : {
     152           0 :   aUnion.Uninit();
     153           0 : }
     154             : 
     155             : void
     156           0 : ImplCycleCollectionUnlink(OwningImageDataOrNullSequenceOrLong& aUnion)
     157             : {
     158           0 :   aUnion.Uninit();
     159           0 : }
     160             : 
     161             : void
     162           0 : ImplCycleCollectionUnlink(OwningImageDataOrNullSequenceSequenceOrLong& aUnion)
     163             : {
     164           0 :   aUnion.Uninit();
     165           0 : }
     166             : 
     167             : void
     168           0 : ImplCycleCollectionUnlink(OwningImageDataSequenceOrLong& aUnion)
     169             : {
     170           0 :   aUnion.Uninit();
     171           0 : }
     172             : 
     173             : void
     174           0 : ImplCycleCollectionUnlink(OwningImageDataSequenceSequenceOrLong& aUnion)
     175             : {
     176           0 :   aUnion.Uninit();
     177           0 : }
     178             : 
     179             : void
     180           0 : ImplCycleCollectionUnlink(OwningNodeOrLongOrBoolean& aUnion)
     181             : {
     182           0 :   aUnion.Uninit();
     183           0 : }
     184             : 
     185             : void
     186           0 : ImplCycleCollectionUnlink(OwningNodeOrString& aUnion)
     187             : {
     188           0 :   aUnion.Uninit();
     189           0 : }
     190             : 
     191             : bool
     192           0 : ArrayBufferOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
     193             : {
     194           0 :   switch (mType) {
     195             :     case eUninitialized: {
     196           0 :       return false;
     197             :       break;
     198             :     }
     199             :     case eArrayBuffer: {
     200           0 :       rval.setObject(*mValue.mArrayBuffer.Value().Obj());
     201           0 :       if (!MaybeWrapNonDOMObjectValue(cx, rval)) {
     202           0 :         return false;
     203             :       }
     204           0 :       return true;
     205             :       break;
     206             :     }
     207             :     case eLong: {
     208           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
     209           0 :       return true;
     210             :       break;
     211             :     }
     212             :     default: {
     213           0 :       return false;
     214             :       break;
     215             :     }
     216             :   }
     217             : 
     218             :   return false;
     219             : }
     220             : 
     221             : bool
     222           0 : ArrayBufferViewOrArrayBuffer::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
     223             : {
     224           0 :   switch (mType) {
     225             :     case eUninitialized: {
     226           0 :       return false;
     227             :       break;
     228             :     }
     229             :     case eArrayBufferView: {
     230           0 :       rval.setObject(*mValue.mArrayBufferView.Value().Obj());
     231           0 :       if (!MaybeWrapNonDOMObjectValue(cx, rval)) {
     232           0 :         return false;
     233             :       }
     234           0 :       return true;
     235             :       break;
     236             :     }
     237             :     case eArrayBuffer: {
     238           0 :       rval.setObject(*mValue.mArrayBuffer.Value().Obj());
     239           0 :       if (!MaybeWrapNonDOMObjectValue(cx, rval)) {
     240           0 :         return false;
     241             :       }
     242           0 :       return true;
     243             :       break;
     244             :     }
     245             :     default: {
     246           0 :       return false;
     247             :       break;
     248             :     }
     249             :   }
     250             : 
     251             :   return false;
     252             : }
     253             : 
     254             : bool
     255           0 : ByteStringOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
     256             : {
     257           0 :   switch (mType) {
     258             :     case eUninitialized: {
     259           0 :       return false;
     260             :       break;
     261             :     }
     262             :     case eByteString: {
     263           0 :       if (!NonVoidByteStringToJsval(cx, mValue.mByteString.Value(), rval)) {
     264           0 :         return false;
     265             :       }
     266           0 :       return true;
     267             :       break;
     268             :     }
     269             :     case eLong: {
     270           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
     271           0 :       return true;
     272             :       break;
     273             :     }
     274             :     default: {
     275           0 :       return false;
     276             :       break;
     277             :     }
     278             :   }
     279             : 
     280             :   return false;
     281             : }
     282             : 
     283             : bool
     284           0 : CanvasPatternOrCanvasGradient::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
     285             : {
     286           0 :   switch (mType) {
     287             :     case eUninitialized: {
     288           0 :       return false;
     289             :       break;
     290             :     }
     291             :     case eCanvasPattern: {
     292           0 :       if (!GetOrCreateDOMReflector(cx, mValue.mCanvasPattern.Value(), rval)) {
     293           0 :         MOZ_ASSERT(true || JS_IsExceptionPending(cx));
     294           0 :         return false;
     295             :       }
     296           0 :       return true;
     297             :       break;
     298             :     }
     299             :     case eCanvasGradient: {
     300           0 :       if (!GetOrCreateDOMReflector(cx, mValue.mCanvasGradient.Value(), rval)) {
     301           0 :         MOZ_ASSERT(true || JS_IsExceptionPending(cx));
     302           0 :         return false;
     303             :       }
     304           0 :       return true;
     305             :       break;
     306             :     }
     307             :     default: {
     308           0 :       return false;
     309             :       break;
     310             :     }
     311             :   }
     312             : 
     313             :   return false;
     314             : }
     315             : 
     316             : bool
     317           0 : CanvasPatternOrNullOrCanvasGradient::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
     318             : {
     319           0 :   switch (mType) {
     320             :     case eUninitialized: {
     321           0 :       return false;
     322             :       break;
     323             :     }
     324             :     case eNull: {
     325           0 :       rval.setNull();
     326           0 :       return true;
     327             :       break;
     328             :     }
     329             :     case eCanvasPattern: {
     330           0 :       if (!GetOrCreateDOMReflector(cx, mValue.mCanvasPattern.Value(), rval)) {
     331           0 :         MOZ_ASSERT(true || JS_IsExceptionPending(cx));
     332           0 :         return false;
     333             :       }
     334           0 :       return true;
     335             :       break;
     336             :     }
     337             :     case eCanvasGradient: {
     338           0 :       if (!GetOrCreateDOMReflector(cx, mValue.mCanvasGradient.Value(), rval)) {
     339           0 :         MOZ_ASSERT(true || JS_IsExceptionPending(cx));
     340           0 :         return false;
     341             :       }
     342           0 :       return true;
     343             :       break;
     344             :     }
     345             :     default: {
     346           0 :       return false;
     347             :       break;
     348             :     }
     349             :   }
     350             : 
     351             :   return false;
     352             : }
     353             : 
     354             : bool
     355           0 : CustomEventInitOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
     356             : {
     357           0 :   switch (mType) {
     358             :     case eUninitialized: {
     359           0 :       return false;
     360             :       break;
     361             :     }
     362             :     case eCustomEventInit: {
     363           0 :       if (!mValue.mCustomEventInit.Value().ToObjectInternal(cx, rval)) {
     364           0 :         return false;
     365             :       }
     366           0 :       return true;
     367             :       break;
     368             :     }
     369             :     case eLong: {
     370           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
     371           0 :       return true;
     372             :       break;
     373             :     }
     374             :     default: {
     375           0 :       return false;
     376             :       break;
     377             :     }
     378             :   }
     379             : 
     380             :   return false;
     381             : }
     382             : 
     383             : bool
     384           0 : DoubleOrByteString::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
     385             : {
     386           0 :   switch (mType) {
     387             :     case eUninitialized: {
     388           0 :       return false;
     389             :       break;
     390             :     }
     391             :     case eDouble: {
     392           0 :       rval.set(JS_NumberValue(double(mValue.mDouble.Value())));
     393           0 :       return true;
     394             :       break;
     395             :     }
     396             :     case eByteString: {
     397           0 :       if (!NonVoidByteStringToJsval(cx, mValue.mByteString.Value(), rval)) {
     398           0 :         return false;
     399             :       }
     400           0 :       return true;
     401             :       break;
     402             :     }
     403             :     default: {
     404           0 :       return false;
     405             :       break;
     406             :     }
     407             :   }
     408             : 
     409             :   return false;
     410             : }
     411             : 
     412             : bool
     413           0 : DoubleOrString::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
     414             : {
     415           0 :   switch (mType) {
     416             :     case eUninitialized: {
     417           0 :       return false;
     418             :       break;
     419             :     }
     420             :     case eDouble: {
     421           0 :       rval.set(JS_NumberValue(double(mValue.mDouble.Value())));
     422           0 :       return true;
     423             :       break;
     424             :     }
     425             :     case eString: {
     426           0 :       if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) {
     427           0 :         return false;
     428             :       }
     429           0 :       return true;
     430             :       break;
     431             :     }
     432             :     default: {
     433           0 :       return false;
     434             :       break;
     435             :     }
     436             :   }
     437             : 
     438             :   return false;
     439             : }
     440             : 
     441             : bool
     442           0 : DoubleOrSupportedType::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
     443             : {
     444           0 :   switch (mType) {
     445             :     case eUninitialized: {
     446           0 :       return false;
     447             :       break;
     448             :     }
     449             :     case eDouble: {
     450           0 :       rval.set(JS_NumberValue(double(mValue.mDouble.Value())));
     451           0 :       return true;
     452             :       break;
     453             :     }
     454             :     case eSupportedType: {
     455           0 :       if (!ToJSValue(cx, mValue.mSupportedType.Value(), rval)) {
     456           0 :         return false;
     457             :       }
     458           0 :       return true;
     459             :       break;
     460             :     }
     461             :     default: {
     462           0 :       return false;
     463             :       break;
     464             :     }
     465             :   }
     466             : 
     467             :   return false;
     468             : }
     469             : 
     470             : bool
     471           0 : DoubleOrUSVString::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 eDouble: {
     479           0 :       rval.set(JS_NumberValue(double(mValue.mDouble.Value())));
     480           0 :       return true;
     481             :       break;
     482             :     }
     483             :     case eUSVString: {
     484           0 :       if (!xpc::NonVoidStringToJsval(cx, mValue.mUSVString.Value(), rval)) {
     485           0 :         return false;
     486             :       }
     487           0 :       return true;
     488             :       break;
     489             :     }
     490             :     default: {
     491           0 :       return false;
     492             :       break;
     493             :     }
     494             :   }
     495             : 
     496             :   return false;
     497             : }
     498             : 
     499             : bool
     500           0 : EventHandlerNonNullOrNullOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
     501             : {
     502           0 :   switch (mType) {
     503             :     case eUninitialized: {
     504           0 :       return false;
     505             :       break;
     506             :     }
     507             :     case eNull: {
     508           0 :       rval.setNull();
     509           0 :       return true;
     510             :       break;
     511             :     }
     512             :     case eEventHandlerNonNull: {
     513           0 :       rval.setObjectOrNull(GetCallbackFromCallbackObject(mValue.mEventHandlerNonNull.Value()));
     514           0 :       if (!MaybeWrapObjectValue(cx, rval)) {
     515           0 :         return false;
     516             :       }
     517           0 :       return true;
     518             :       break;
     519             :     }
     520             :     case eLong: {
     521           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
     522           0 :       return true;
     523             :       break;
     524             :     }
     525             :     default: {
     526           0 :       return false;
     527             :       break;
     528             :     }
     529             :   }
     530             : 
     531             :   return false;
     532             : }
     533             : 
     534             : bool
     535           0 : EventInitOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
     536             : {
     537           0 :   switch (mType) {
     538             :     case eUninitialized: {
     539           0 :       return false;
     540             :       break;
     541             :     }
     542             :     case eEventInit: {
     543           0 :       if (!mValue.mEventInit.Value().ToObjectInternal(cx, rval)) {
     544           0 :         return false;
     545             :       }
     546           0 :       return true;
     547             :       break;
     548             :     }
     549             :     case eLong: {
     550           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
     551           0 :       return true;
     552             :       break;
     553             :     }
     554             :     default: {
     555           0 :       return false;
     556             :       break;
     557             :     }
     558             :   }
     559             : 
     560             :   return false;
     561             : }
     562             : 
     563             : bool
     564           0 : EventInitOrStringSequence::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
     565             : {
     566           0 :   switch (mType) {
     567             :     case eUninitialized: {
     568           0 :       return false;
     569             :       break;
     570             :     }
     571             :     case eEventInit: {
     572           0 :       if (!mValue.mEventInit.Value().ToObjectInternal(cx, rval)) {
     573           0 :         return false;
     574             :       }
     575           0 :       return true;
     576             :       break;
     577             :     }
     578             :     case eStringSequence: {
     579             : 
     580           0 :       uint32_t length = mValue.mStringSequence.Value().Length();
     581           0 :       JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
     582           0 :       if (!returnArray) {
     583           0 :         return false;
     584             :       }
     585             :       // Scope for 'tmp'
     586             :       {
     587           0 :         JS::Rooted<JS::Value> tmp(cx);
     588           0 :         for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
     589             :           // Control block to let us common up the JS_DefineElement calls when there
     590             :           // are different ways to succeed at wrapping the object.
     591             :           do {
     592           0 :             if (!xpc::NonVoidStringToJsval(cx, mValue.mStringSequence.Value()[sequenceIdx0], &tmp)) {
     593           0 :               return false;
     594             :             }
     595           0 :             break;
     596             :           } while (0);
     597           0 :           if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
     598             :                                 JSPROP_ENUMERATE)) {
     599           0 :             return false;
     600             :           }
     601             :         }
     602             :       }
     603           0 :       rval.setObject(*returnArray);
     604           0 :       return true;
     605             :       break;
     606             :     }
     607             :     default: {
     608           0 :       return false;
     609             :       break;
     610             :     }
     611             :   }
     612             : 
     613             :   return false;
     614             : }
     615             : 
     616             : bool
     617           0 : FileOrDirectory::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
     618             : {
     619           0 :   switch (mType) {
     620             :     case eUninitialized: {
     621           0 :       return false;
     622             :       break;
     623             :     }
     624             :     case eFile: {
     625           0 :       if (!GetOrCreateDOMReflector(cx, mValue.mFile.Value(), rval)) {
     626           0 :         MOZ_ASSERT(true || JS_IsExceptionPending(cx));
     627           0 :         return false;
     628             :       }
     629           0 :       return true;
     630             :       break;
     631             :     }
     632             :     case eDirectory: {
     633           0 :       if (!GetOrCreateDOMReflector(cx, mValue.mDirectory.Value(), rval)) {
     634           0 :         MOZ_ASSERT(true || JS_IsExceptionPending(cx));
     635           0 :         return false;
     636             :       }
     637           0 :       return true;
     638             :       break;
     639             :     }
     640             :     default: {
     641           0 :       return false;
     642             :       break;
     643             :     }
     644             :   }
     645             : 
     646             :   return false;
     647             : }
     648             : 
     649             : bool
     650           0 : FloatOrString::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
     651             : {
     652           0 :   switch (mType) {
     653             :     case eUninitialized: {
     654           0 :       return false;
     655             :       break;
     656             :     }
     657             :     case eFloat: {
     658           0 :       rval.set(JS_NumberValue(double(mValue.mFloat.Value())));
     659           0 :       return true;
     660             :       break;
     661             :     }
     662             :     case eString: {
     663           0 :       if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) {
     664           0 :         return false;
     665             :       }
     666           0 :       return true;
     667             :       break;
     668             :     }
     669             :     default: {
     670           0 :       return false;
     671             :       break;
     672             :     }
     673             :   }
     674             : 
     675             :   return false;
     676             : }
     677             : 
     678             : bool
     679           0 : HTMLElementOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
     680             : {
     681           0 :   switch (mType) {
     682             :     case eUninitialized: {
     683           0 :       return false;
     684             :       break;
     685             :     }
     686             :     case eHTMLElement: {
     687           0 :       if (!GetOrCreateDOMReflector(cx, mValue.mHTMLElement.Value(), rval)) {
     688           0 :         MOZ_ASSERT(true || JS_IsExceptionPending(cx));
     689           0 :         return false;
     690             :       }
     691           0 :       return true;
     692             :       break;
     693             :     }
     694             :     case eLong: {
     695           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
     696           0 :       return true;
     697             :       break;
     698             :     }
     699             :     default: {
     700           0 :       return false;
     701             :       break;
     702             :     }
     703             :   }
     704             : 
     705             :   return false;
     706             : }
     707             : 
     708             : bool
     709           0 : HTMLOptionElementOrHTMLOptGroupElement::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
     710             : {
     711           0 :   switch (mType) {
     712             :     case eUninitialized: {
     713           0 :       return false;
     714             :       break;
     715             :     }
     716             :     case eHTMLOptionElement: {
     717           0 :       if (!GetOrCreateDOMReflector(cx, mValue.mHTMLOptionElement.Value(), rval)) {
     718           0 :         MOZ_ASSERT(true || JS_IsExceptionPending(cx));
     719           0 :         return false;
     720             :       }
     721           0 :       return true;
     722             :       break;
     723             :     }
     724             :     case eHTMLOptGroupElement: {
     725           0 :       if (!GetOrCreateDOMReflector(cx, mValue.mHTMLOptGroupElement.Value(), rval)) {
     726           0 :         MOZ_ASSERT(true || JS_IsExceptionPending(cx));
     727           0 :         return false;
     728             :       }
     729           0 :       return true;
     730             :       break;
     731             :     }
     732             :     default: {
     733           0 :       return false;
     734             :       break;
     735             :     }
     736             :   }
     737             : 
     738             :   return false;
     739             : }
     740             : 
     741             : bool
     742           0 : ImageDataOrNullSequenceOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
     743             : {
     744           0 :   switch (mType) {
     745             :     case eUninitialized: {
     746           0 :       return false;
     747             :       break;
     748             :     }
     749             :     case eImageDataOrNullSequence: {
     750             : 
     751           0 :       uint32_t length = mValue.mImageDataOrNullSequence.Value().Length();
     752           0 :       JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
     753           0 :       if (!returnArray) {
     754           0 :         return false;
     755             :       }
     756             :       // Scope for 'tmp'
     757             :       {
     758           0 :         JS::Rooted<JS::Value> tmp(cx);
     759           0 :         for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
     760             :           // Control block to let us common up the JS_DefineElement calls when there
     761             :           // are different ways to succeed at wrapping the object.
     762             :           do {
     763           0 :             if (!mValue.mImageDataOrNullSequence.Value()[sequenceIdx0]) {
     764           0 :               tmp.setNull();
     765           0 :               break;
     766             :             }
     767           0 :             if (!WrapNewBindingNonWrapperCachedObject(cx, returnArray, mValue.mImageDataOrNullSequence.Value()[sequenceIdx0], &tmp)) {
     768           0 :               MOZ_ASSERT(true || JS_IsExceptionPending(cx));
     769           0 :               return false;
     770             :             }
     771           0 :             break;
     772             :           } while (0);
     773           0 :           if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
     774             :                                 JSPROP_ENUMERATE)) {
     775           0 :             return false;
     776             :           }
     777             :         }
     778             :       }
     779           0 :       rval.setObject(*returnArray);
     780           0 :       return true;
     781             :       break;
     782             :     }
     783             :     case eLong: {
     784           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
     785           0 :       return true;
     786             :       break;
     787             :     }
     788             :     default: {
     789           0 :       return false;
     790             :       break;
     791             :     }
     792             :   }
     793             : 
     794             :   return false;
     795             : }
     796             : 
     797             : bool
     798           0 : ImageDataOrNullSequenceSequenceOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
     799             : {
     800           0 :   switch (mType) {
     801             :     case eUninitialized: {
     802           0 :       return false;
     803             :       break;
     804             :     }
     805             :     case eImageDataOrNullSequenceSequence: {
     806             : 
     807           0 :       uint32_t length = mValue.mImageDataOrNullSequenceSequence.Value().Length();
     808           0 :       JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
     809           0 :       if (!returnArray) {
     810           0 :         return false;
     811             :       }
     812             :       // Scope for 'tmp'
     813             :       {
     814           0 :         JS::Rooted<JS::Value> tmp(cx);
     815           0 :         for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
     816             :           // Control block to let us common up the JS_DefineElement calls when there
     817             :           // are different ways to succeed at wrapping the object.
     818             :           do {
     819             : 
     820           0 :             uint32_t length = mValue.mImageDataOrNullSequenceSequence.Value()[sequenceIdx0].Length();
     821           0 :             JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
     822           0 :             if (!returnArray) {
     823           0 :               return false;
     824             :             }
     825             :             // Scope for 'tmp'
     826             :             {
     827           0 :               JS::Rooted<JS::Value> tmp(cx);
     828           0 :               for (uint32_t sequenceIdx1 = 0; sequenceIdx1 < length; ++sequenceIdx1) {
     829             :                 // Control block to let us common up the JS_DefineElement calls when there
     830             :                 // are different ways to succeed at wrapping the object.
     831             :                 do {
     832           0 :                   if (!mValue.mImageDataOrNullSequenceSequence.Value()[sequenceIdx0][sequenceIdx1]) {
     833           0 :                     tmp.setNull();
     834           0 :                     break;
     835             :                   }
     836           0 :                   if (!WrapNewBindingNonWrapperCachedObject(cx, returnArray, mValue.mImageDataOrNullSequenceSequence.Value()[sequenceIdx0][sequenceIdx1], &tmp)) {
     837           0 :                     MOZ_ASSERT(true || JS_IsExceptionPending(cx));
     838           0 :                     return false;
     839             :                   }
     840           0 :                   break;
     841             :                 } while (0);
     842           0 :                 if (!JS_DefineElement(cx, returnArray, sequenceIdx1, tmp,
     843             :                                       JSPROP_ENUMERATE)) {
     844           0 :                   return false;
     845             :                 }
     846             :               }
     847             :             }
     848           0 :             tmp.setObject(*returnArray);
     849           0 :             break;
     850             :           } while (0);
     851           0 :           if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
     852             :                                 JSPROP_ENUMERATE)) {
     853           0 :             return false;
     854             :           }
     855             :         }
     856             :       }
     857           0 :       rval.setObject(*returnArray);
     858           0 :       return true;
     859             :       break;
     860             :     }
     861             :     case eLong: {
     862           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
     863           0 :       return true;
     864             :       break;
     865             :     }
     866             :     default: {
     867           0 :       return false;
     868             :       break;
     869             :     }
     870             :   }
     871             : 
     872             :   return false;
     873             : }
     874             : 
     875             : bool
     876           0 : ImageDataSequenceOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
     877             : {
     878           0 :   switch (mType) {
     879             :     case eUninitialized: {
     880           0 :       return false;
     881             :       break;
     882             :     }
     883             :     case eImageDataSequence: {
     884             : 
     885           0 :       uint32_t length = mValue.mImageDataSequence.Value().Length();
     886           0 :       JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
     887           0 :       if (!returnArray) {
     888           0 :         return false;
     889             :       }
     890             :       // Scope for 'tmp'
     891             :       {
     892           0 :         JS::Rooted<JS::Value> tmp(cx);
     893           0 :         for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
     894             :           // Control block to let us common up the JS_DefineElement calls when there
     895             :           // are different ways to succeed at wrapping the object.
     896             :           do {
     897           0 :             if (!WrapNewBindingNonWrapperCachedObject(cx, returnArray, mValue.mImageDataSequence.Value()[sequenceIdx0], &tmp)) {
     898           0 :               MOZ_ASSERT(true || JS_IsExceptionPending(cx));
     899           0 :               return false;
     900             :             }
     901           0 :             break;
     902             :           } while (0);
     903           0 :           if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
     904             :                                 JSPROP_ENUMERATE)) {
     905           0 :             return false;
     906             :           }
     907             :         }
     908             :       }
     909           0 :       rval.setObject(*returnArray);
     910           0 :       return true;
     911             :       break;
     912             :     }
     913             :     case eLong: {
     914           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
     915           0 :       return true;
     916             :       break;
     917             :     }
     918             :     default: {
     919           0 :       return false;
     920             :       break;
     921             :     }
     922             :   }
     923             : 
     924             :   return false;
     925             : }
     926             : 
     927             : bool
     928           0 : ImageDataSequenceSequenceOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
     929             : {
     930           0 :   switch (mType) {
     931             :     case eUninitialized: {
     932           0 :       return false;
     933             :       break;
     934             :     }
     935             :     case eImageDataSequenceSequence: {
     936             : 
     937           0 :       uint32_t length = mValue.mImageDataSequenceSequence.Value().Length();
     938           0 :       JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
     939           0 :       if (!returnArray) {
     940           0 :         return false;
     941             :       }
     942             :       // Scope for 'tmp'
     943             :       {
     944           0 :         JS::Rooted<JS::Value> tmp(cx);
     945           0 :         for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
     946             :           // Control block to let us common up the JS_DefineElement calls when there
     947             :           // are different ways to succeed at wrapping the object.
     948             :           do {
     949             : 
     950           0 :             uint32_t length = mValue.mImageDataSequenceSequence.Value()[sequenceIdx0].Length();
     951           0 :             JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
     952           0 :             if (!returnArray) {
     953           0 :               return false;
     954             :             }
     955             :             // Scope for 'tmp'
     956             :             {
     957           0 :               JS::Rooted<JS::Value> tmp(cx);
     958           0 :               for (uint32_t sequenceIdx1 = 0; sequenceIdx1 < length; ++sequenceIdx1) {
     959             :                 // Control block to let us common up the JS_DefineElement calls when there
     960             :                 // are different ways to succeed at wrapping the object.
     961             :                 do {
     962           0 :                   if (!WrapNewBindingNonWrapperCachedObject(cx, returnArray, mValue.mImageDataSequenceSequence.Value()[sequenceIdx0][sequenceIdx1], &tmp)) {
     963           0 :                     MOZ_ASSERT(true || JS_IsExceptionPending(cx));
     964           0 :                     return false;
     965             :                   }
     966           0 :                   break;
     967             :                 } while (0);
     968           0 :                 if (!JS_DefineElement(cx, returnArray, sequenceIdx1, tmp,
     969             :                                       JSPROP_ENUMERATE)) {
     970           0 :                   return false;
     971             :                 }
     972             :               }
     973             :             }
     974           0 :             tmp.setObject(*returnArray);
     975           0 :             break;
     976             :           } while (0);
     977           0 :           if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
     978             :                                 JSPROP_ENUMERATE)) {
     979           0 :             return false;
     980             :           }
     981             :         }
     982             :       }
     983           0 :       rval.setObject(*returnArray);
     984           0 :       return true;
     985             :       break;
     986             :     }
     987             :     case eLong: {
     988           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
     989           0 :       return true;
     990             :       break;
     991             :     }
     992             :     default: {
     993           0 :       return false;
     994             :       break;
     995             :     }
     996             :   }
     997             : 
     998             :   return false;
     999             : }
    1000             : 
    1001             : bool
    1002           0 : LongOrBoolean::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    1003             : {
    1004           0 :   switch (mType) {
    1005             :     case eUninitialized: {
    1006           0 :       return false;
    1007             :       break;
    1008             :     }
    1009             :     case eLong: {
    1010           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    1011           0 :       return true;
    1012             :       break;
    1013             :     }
    1014             :     case eBoolean: {
    1015           0 :       rval.setBoolean(mValue.mBoolean.Value());
    1016           0 :       return true;
    1017             :       break;
    1018             :     }
    1019             :     default: {
    1020           0 :       return false;
    1021             :       break;
    1022             :     }
    1023             :   }
    1024             : 
    1025             :   return false;
    1026             : }
    1027             : 
    1028             : bool
    1029           0 : LongOrStringAnyRecord::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    1030             : {
    1031           0 :   switch (mType) {
    1032             :     case eUninitialized: {
    1033           0 :       return false;
    1034             :       break;
    1035             :     }
    1036             :     case eLong: {
    1037           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    1038           0 :       return true;
    1039             :       break;
    1040             :     }
    1041             :     case eStringAnyRecord: {
    1042             : 
    1043           0 :       JS::Rooted<JSObject*> returnObj(cx, JS_NewPlainObject(cx));
    1044           0 :       if (!returnObj) {
    1045           0 :         return false;
    1046             :       }
    1047             :       // Scope for 'tmp'
    1048             :       {
    1049           0 :         JS::Rooted<JS::Value> tmp(cx);
    1050           0 :         for (auto& entry : mValue.mStringAnyRecord.Value().Entries()) {
    1051           0 :           auto& recordValue0 = entry.mValue;
    1052             :           // Control block to let us common up the JS_DefineUCProperty calls when there
    1053             :           // are different ways to succeed at wrapping the value.
    1054             :           do {
    1055           0 :             JS::ExposeValueToActiveJS(recordValue0);
    1056           0 :             tmp.set(recordValue0);
    1057           0 :             if (!MaybeWrapValue(cx, &tmp)) {
    1058           0 :               return false;
    1059             :             }
    1060           0 :             break;
    1061             :           } while (0);
    1062           0 :           if (!JS_DefineUCProperty(cx, returnObj,
    1063             :                                    entry.mKey.BeginReading(),
    1064           0 :                                    entry.mKey.Length(), tmp,
    1065             :                                    JSPROP_ENUMERATE)) {
    1066           0 :             return false;
    1067             :           }
    1068             :         }
    1069             :       }
    1070           0 :       rval.setObject(*returnObj);
    1071           0 :       return true;
    1072             :       break;
    1073             :     }
    1074             :     default: {
    1075           0 :       return false;
    1076             :       break;
    1077             :     }
    1078             :   }
    1079             : 
    1080             :   return false;
    1081             : }
    1082             : 
    1083             : bool
    1084           0 : LongSequenceOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    1085             : {
    1086           0 :   switch (mType) {
    1087             :     case eUninitialized: {
    1088           0 :       return false;
    1089             :       break;
    1090             :     }
    1091             :     case eLongSequence: {
    1092             : 
    1093           0 :       uint32_t length = mValue.mLongSequence.Value().Length();
    1094           0 :       JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
    1095           0 :       if (!returnArray) {
    1096           0 :         return false;
    1097             :       }
    1098             :       // Scope for 'tmp'
    1099             :       {
    1100           0 :         JS::Rooted<JS::Value> tmp(cx);
    1101           0 :         for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
    1102             :           // Control block to let us common up the JS_DefineElement calls when there
    1103             :           // are different ways to succeed at wrapping the object.
    1104             :           do {
    1105           0 :             tmp.setInt32(int32_t(mValue.mLongSequence.Value()[sequenceIdx0]));
    1106           0 :             break;
    1107             :           } while (0);
    1108           0 :           if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
    1109             :                                 JSPROP_ENUMERATE)) {
    1110           0 :             return false;
    1111             :           }
    1112             :         }
    1113             :       }
    1114           0 :       rval.setObject(*returnArray);
    1115           0 :       return true;
    1116             :       break;
    1117             :     }
    1118             :     case eLong: {
    1119           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    1120           0 :       return true;
    1121             :       break;
    1122             :     }
    1123             :     default: {
    1124           0 :       return false;
    1125             :       break;
    1126             :     }
    1127             :   }
    1128             : 
    1129             :   return false;
    1130             : }
    1131             : 
    1132             : bool
    1133           0 : LongSequenceOrNullOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    1134             : {
    1135           0 :   switch (mType) {
    1136             :     case eUninitialized: {
    1137           0 :       return false;
    1138             :       break;
    1139             :     }
    1140             :     case eNull: {
    1141           0 :       rval.setNull();
    1142           0 :       return true;
    1143             :       break;
    1144             :     }
    1145             :     case eLongSequence: {
    1146             : 
    1147           0 :       uint32_t length = mValue.mLongSequence.Value().Length();
    1148           0 :       JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
    1149           0 :       if (!returnArray) {
    1150           0 :         return false;
    1151             :       }
    1152             :       // Scope for 'tmp'
    1153             :       {
    1154           0 :         JS::Rooted<JS::Value> tmp(cx);
    1155           0 :         for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
    1156             :           // Control block to let us common up the JS_DefineElement calls when there
    1157             :           // are different ways to succeed at wrapping the object.
    1158             :           do {
    1159           0 :             tmp.setInt32(int32_t(mValue.mLongSequence.Value()[sequenceIdx0]));
    1160           0 :             break;
    1161             :           } while (0);
    1162           0 :           if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
    1163             :                                 JSPROP_ENUMERATE)) {
    1164           0 :             return false;
    1165             :           }
    1166             :         }
    1167             :       }
    1168           0 :       rval.setObject(*returnArray);
    1169           0 :       return true;
    1170             :       break;
    1171             :     }
    1172             :     case eLong: {
    1173           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    1174           0 :       return true;
    1175             :       break;
    1176             :     }
    1177             :     default: {
    1178           0 :       return false;
    1179             :       break;
    1180             :     }
    1181             :   }
    1182             : 
    1183             :   return false;
    1184             : }
    1185             : 
    1186             : bool
    1187           0 : NodeOrLongOrBoolean::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    1188             : {
    1189           0 :   switch (mType) {
    1190             :     case eUninitialized: {
    1191           0 :       return false;
    1192             :       break;
    1193             :     }
    1194             :     case eNode: {
    1195           0 :       if (!GetOrCreateDOMReflector(cx, mValue.mNode.Value(), rval)) {
    1196           0 :         MOZ_ASSERT(true || JS_IsExceptionPending(cx));
    1197           0 :         return false;
    1198             :       }
    1199           0 :       return true;
    1200             :       break;
    1201             :     }
    1202             :     case eLong: {
    1203           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    1204           0 :       return true;
    1205             :       break;
    1206             :     }
    1207             :     case eBoolean: {
    1208           0 :       rval.setBoolean(mValue.mBoolean.Value());
    1209           0 :       return true;
    1210             :       break;
    1211             :     }
    1212             :     default: {
    1213           0 :       return false;
    1214             :       break;
    1215             :     }
    1216             :   }
    1217             : 
    1218             :   return false;
    1219             : }
    1220             : 
    1221             : bool
    1222           0 : NodeOrString::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    1223             : {
    1224           0 :   switch (mType) {
    1225             :     case eUninitialized: {
    1226           0 :       return false;
    1227             :       break;
    1228             :     }
    1229             :     case eNode: {
    1230           0 :       if (!GetOrCreateDOMReflector(cx, mValue.mNode.Value(), rval)) {
    1231           0 :         MOZ_ASSERT(true || JS_IsExceptionPending(cx));
    1232           0 :         return false;
    1233             :       }
    1234           0 :       return true;
    1235             :       break;
    1236             :     }
    1237             :     case eString: {
    1238           0 :       if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) {
    1239           0 :         return false;
    1240             :       }
    1241           0 :       return true;
    1242             :       break;
    1243             :     }
    1244             :     default: {
    1245           0 :       return false;
    1246             :       break;
    1247             :     }
    1248             :   }
    1249             : 
    1250             :   return false;
    1251             : }
    1252             : 
    1253             : bool
    1254           0 : ObjectOrBoolean::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    1255             : {
    1256           0 :   switch (mType) {
    1257             :     case eUninitialized: {
    1258           0 :       return false;
    1259             :       break;
    1260             :     }
    1261             :     case eObject: {
    1262           0 :       JS::ExposeObjectToActiveJS(mValue.mObject.Value());
    1263           0 :       rval.setObject(*mValue.mObject.Value());
    1264           0 :       if (!MaybeWrapObjectValue(cx, rval)) {
    1265           0 :         return false;
    1266             :       }
    1267           0 :       return true;
    1268             :       break;
    1269             :     }
    1270             :     case eBoolean: {
    1271           0 :       rval.setBoolean(mValue.mBoolean.Value());
    1272           0 :       return true;
    1273             :       break;
    1274             :     }
    1275             :     default: {
    1276           0 :       return false;
    1277             :       break;
    1278             :     }
    1279             :   }
    1280             : 
    1281             :   return false;
    1282             : }
    1283             : 
    1284             : bool
    1285           0 : ObjectOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    1286             : {
    1287           0 :   switch (mType) {
    1288             :     case eUninitialized: {
    1289           0 :       return false;
    1290             :       break;
    1291             :     }
    1292             :     case eObject: {
    1293           0 :       JS::ExposeObjectToActiveJS(mValue.mObject.Value());
    1294           0 :       rval.setObject(*mValue.mObject.Value());
    1295           0 :       if (!MaybeWrapObjectValue(cx, rval)) {
    1296           0 :         return false;
    1297             :       }
    1298           0 :       return true;
    1299             :       break;
    1300             :     }
    1301             :     case eLong: {
    1302           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    1303           0 :       return true;
    1304             :       break;
    1305             :     }
    1306             :     default: {
    1307           0 :       return false;
    1308             :       break;
    1309             :     }
    1310             :   }
    1311             : 
    1312             :   return false;
    1313             : }
    1314             : 
    1315             : bool
    1316           0 : ObjectOrLongOrBoolean::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    1317             : {
    1318           0 :   switch (mType) {
    1319             :     case eUninitialized: {
    1320           0 :       return false;
    1321             :       break;
    1322             :     }
    1323             :     case eObject: {
    1324           0 :       JS::ExposeObjectToActiveJS(mValue.mObject.Value());
    1325           0 :       rval.setObject(*mValue.mObject.Value());
    1326           0 :       if (!MaybeWrapObjectValue(cx, rval)) {
    1327           0 :         return false;
    1328             :       }
    1329           0 :       return true;
    1330             :       break;
    1331             :     }
    1332             :     case eLong: {
    1333           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    1334           0 :       return true;
    1335             :       break;
    1336             :     }
    1337             :     case eBoolean: {
    1338           0 :       rval.setBoolean(mValue.mBoolean.Value());
    1339           0 :       return true;
    1340             :       break;
    1341             :     }
    1342             :     default: {
    1343           0 :       return false;
    1344             :       break;
    1345             :     }
    1346             :   }
    1347             : 
    1348             :   return false;
    1349             : }
    1350             : 
    1351             : bool
    1352           0 : ObjectOrLongOrNull::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    1353             : {
    1354           0 :   switch (mType) {
    1355             :     case eUninitialized: {
    1356           0 :       return false;
    1357             :       break;
    1358             :     }
    1359             :     case eNull: {
    1360           0 :       rval.setNull();
    1361           0 :       return true;
    1362             :       break;
    1363             :     }
    1364             :     case eObject: {
    1365           0 :       JS::ExposeObjectToActiveJS(mValue.mObject.Value());
    1366           0 :       rval.setObject(*mValue.mObject.Value());
    1367           0 :       if (!MaybeWrapObjectValue(cx, rval)) {
    1368           0 :         return false;
    1369             :       }
    1370           0 :       return true;
    1371             :       break;
    1372             :     }
    1373             :     case eLong: {
    1374           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    1375           0 :       return true;
    1376             :       break;
    1377             :     }
    1378             :     default: {
    1379           0 :       return false;
    1380             :       break;
    1381             :     }
    1382             :   }
    1383             : 
    1384             :   return false;
    1385             : }
    1386             : 
    1387             : bool
    1388           0 : ObjectOrNullOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    1389             : {
    1390           0 :   switch (mType) {
    1391             :     case eUninitialized: {
    1392           0 :       return false;
    1393             :       break;
    1394             :     }
    1395             :     case eNull: {
    1396           0 :       rval.setNull();
    1397           0 :       return true;
    1398             :       break;
    1399             :     }
    1400             :     case eObject: {
    1401           0 :       JS::ExposeObjectToActiveJS(mValue.mObject.Value());
    1402           0 :       rval.setObject(*mValue.mObject.Value());
    1403           0 :       if (!MaybeWrapObjectValue(cx, rval)) {
    1404           0 :         return false;
    1405             :       }
    1406           0 :       return true;
    1407             :       break;
    1408             :     }
    1409             :     case eLong: {
    1410           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    1411           0 :       return true;
    1412             :       break;
    1413             :     }
    1414             :     default: {
    1415           0 :       return false;
    1416             :       break;
    1417             :     }
    1418             :   }
    1419             : 
    1420             :   return false;
    1421             : }
    1422             : 
    1423             : bool
    1424           0 : ObjectOrString::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    1425             : {
    1426           0 :   switch (mType) {
    1427             :     case eUninitialized: {
    1428           0 :       return false;
    1429             :       break;
    1430             :     }
    1431             :     case eObject: {
    1432           0 :       JS::ExposeObjectToActiveJS(mValue.mObject.Value());
    1433           0 :       rval.setObject(*mValue.mObject.Value());
    1434           0 :       if (!MaybeWrapObjectValue(cx, rval)) {
    1435           0 :         return false;
    1436             :       }
    1437           0 :       return true;
    1438             :       break;
    1439             :     }
    1440             :     case eString: {
    1441           0 :       if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) {
    1442           0 :         return false;
    1443             :       }
    1444           0 :       return true;
    1445             :       break;
    1446             :     }
    1447             :     default: {
    1448           0 :       return false;
    1449             :       break;
    1450             :     }
    1451             :   }
    1452             : 
    1453             :   return false;
    1454             : }
    1455             : 
    1456             : bool
    1457           0 : ObjectOrStringOrBoolean::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    1458             : {
    1459           0 :   switch (mType) {
    1460             :     case eUninitialized: {
    1461           0 :       return false;
    1462             :       break;
    1463             :     }
    1464             :     case eObject: {
    1465           0 :       JS::ExposeObjectToActiveJS(mValue.mObject.Value());
    1466           0 :       rval.setObject(*mValue.mObject.Value());
    1467           0 :       if (!MaybeWrapObjectValue(cx, rval)) {
    1468           0 :         return false;
    1469             :       }
    1470           0 :       return true;
    1471             :       break;
    1472             :     }
    1473             :     case eString: {
    1474           0 :       if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) {
    1475           0 :         return false;
    1476             :       }
    1477           0 :       return true;
    1478             :       break;
    1479             :     }
    1480             :     case eBoolean: {
    1481           0 :       rval.setBoolean(mValue.mBoolean.Value());
    1482           0 :       return true;
    1483             :       break;
    1484             :     }
    1485             :     default: {
    1486           0 :       return false;
    1487             :       break;
    1488             :     }
    1489             :   }
    1490             : 
    1491             :   return false;
    1492             : }
    1493             : 
    1494             : bool
    1495           0 : ObjectOrStringOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    1496             : {
    1497           0 :   switch (mType) {
    1498             :     case eUninitialized: {
    1499           0 :       return false;
    1500             :       break;
    1501             :     }
    1502             :     case eObject: {
    1503           0 :       JS::ExposeObjectToActiveJS(mValue.mObject.Value());
    1504           0 :       rval.setObject(*mValue.mObject.Value());
    1505           0 :       if (!MaybeWrapObjectValue(cx, rval)) {
    1506           0 :         return false;
    1507             :       }
    1508           0 :       return true;
    1509             :       break;
    1510             :     }
    1511             :     case eString: {
    1512           0 :       if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) {
    1513           0 :         return false;
    1514             :       }
    1515           0 :       return true;
    1516             :       break;
    1517             :     }
    1518             :     case eLong: {
    1519           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    1520           0 :       return true;
    1521             :       break;
    1522             :     }
    1523             :     default: {
    1524           0 :       return false;
    1525             :       break;
    1526             :     }
    1527             :   }
    1528             : 
    1529             :   return false;
    1530             : }
    1531             : 
    1532             : bool
    1533           0 : ObjectOrStringOrLongOrBoolean::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    1534             : {
    1535           0 :   switch (mType) {
    1536             :     case eUninitialized: {
    1537           0 :       return false;
    1538             :       break;
    1539             :     }
    1540             :     case eObject: {
    1541           0 :       JS::ExposeObjectToActiveJS(mValue.mObject.Value());
    1542           0 :       rval.setObject(*mValue.mObject.Value());
    1543           0 :       if (!MaybeWrapObjectValue(cx, rval)) {
    1544           0 :         return false;
    1545             :       }
    1546           0 :       return true;
    1547             :       break;
    1548             :     }
    1549             :     case eString: {
    1550           0 :       if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) {
    1551           0 :         return false;
    1552             :       }
    1553           0 :       return true;
    1554             :       break;
    1555             :     }
    1556             :     case eLong: {
    1557           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    1558           0 :       return true;
    1559             :       break;
    1560             :     }
    1561             :     case eBoolean: {
    1562           0 :       rval.setBoolean(mValue.mBoolean.Value());
    1563           0 :       return true;
    1564             :       break;
    1565             :     }
    1566             :     default: {
    1567           0 :       return false;
    1568             :       break;
    1569             :     }
    1570             :   }
    1571             : 
    1572             :   return false;
    1573             : }
    1574             : 
    1575             : bool
    1576           0 : ObjectSequenceOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    1577             : {
    1578           0 :   switch (mType) {
    1579             :     case eUninitialized: {
    1580           0 :       return false;
    1581             :       break;
    1582             :     }
    1583             :     case eObjectSequence: {
    1584             : 
    1585           0 :       uint32_t length = mValue.mObjectSequence.Value().Length();
    1586           0 :       JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
    1587           0 :       if (!returnArray) {
    1588           0 :         return false;
    1589             :       }
    1590             :       // Scope for 'tmp'
    1591             :       {
    1592           0 :         JS::Rooted<JS::Value> tmp(cx);
    1593           0 :         for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
    1594             :           // Control block to let us common up the JS_DefineElement calls when there
    1595             :           // are different ways to succeed at wrapping the object.
    1596             :           do {
    1597           0 :             JS::ExposeObjectToActiveJS(mValue.mObjectSequence.Value()[sequenceIdx0]);
    1598           0 :             tmp.setObject(*mValue.mObjectSequence.Value()[sequenceIdx0]);
    1599           0 :             if (!MaybeWrapObjectValue(cx, &tmp)) {
    1600           0 :               return false;
    1601             :             }
    1602           0 :             break;
    1603             :           } while (0);
    1604           0 :           if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
    1605             :                                 JSPROP_ENUMERATE)) {
    1606           0 :             return false;
    1607             :           }
    1608             :         }
    1609             :       }
    1610           0 :       rval.setObject(*returnArray);
    1611           0 :       return true;
    1612             :       break;
    1613             :     }
    1614             :     case eLong: {
    1615           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    1616           0 :       return true;
    1617             :       break;
    1618             :     }
    1619             :     default: {
    1620           0 :       return false;
    1621             :       break;
    1622             :     }
    1623             :   }
    1624             : 
    1625             :   return false;
    1626             : }
    1627             : 
    1628             : bool
    1629           0 : StringLongRecordOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    1630             : {
    1631           0 :   switch (mType) {
    1632             :     case eUninitialized: {
    1633           0 :       return false;
    1634             :       break;
    1635             :     }
    1636             :     case eStringLongRecord: {
    1637             : 
    1638           0 :       JS::Rooted<JSObject*> returnObj(cx, JS_NewPlainObject(cx));
    1639           0 :       if (!returnObj) {
    1640           0 :         return false;
    1641             :       }
    1642             :       // Scope for 'tmp'
    1643             :       {
    1644           0 :         JS::Rooted<JS::Value> tmp(cx);
    1645           0 :         for (auto& entry : mValue.mStringLongRecord.Value().Entries()) {
    1646           0 :           auto& recordValue0 = entry.mValue;
    1647             :           // Control block to let us common up the JS_DefineUCProperty calls when there
    1648             :           // are different ways to succeed at wrapping the value.
    1649             :           do {
    1650           0 :             tmp.setInt32(int32_t(recordValue0));
    1651           0 :             break;
    1652             :           } while (0);
    1653           0 :           if (!JS_DefineUCProperty(cx, returnObj,
    1654             :                                    entry.mKey.BeginReading(),
    1655           0 :                                    entry.mKey.Length(), tmp,
    1656             :                                    JSPROP_ENUMERATE)) {
    1657           0 :             return false;
    1658             :           }
    1659             :         }
    1660             :       }
    1661           0 :       rval.setObject(*returnObj);
    1662           0 :       return true;
    1663             :       break;
    1664             :     }
    1665             :     case eLong: {
    1666           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    1667           0 :       return true;
    1668             :       break;
    1669             :     }
    1670             :     default: {
    1671           0 :       return false;
    1672             :       break;
    1673             :     }
    1674             :   }
    1675             : 
    1676             :   return false;
    1677             : }
    1678             : 
    1679             : bool
    1680           0 : StringObjectRecordOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    1681             : {
    1682           0 :   switch (mType) {
    1683             :     case eUninitialized: {
    1684           0 :       return false;
    1685             :       break;
    1686             :     }
    1687             :     case eStringObjectRecord: {
    1688             : 
    1689           0 :       JS::Rooted<JSObject*> returnObj(cx, JS_NewPlainObject(cx));
    1690           0 :       if (!returnObj) {
    1691           0 :         return false;
    1692             :       }
    1693             :       // Scope for 'tmp'
    1694             :       {
    1695           0 :         JS::Rooted<JS::Value> tmp(cx);
    1696           0 :         for (auto& entry : mValue.mStringObjectRecord.Value().Entries()) {
    1697           0 :           auto& recordValue0 = entry.mValue;
    1698             :           // Control block to let us common up the JS_DefineUCProperty calls when there
    1699             :           // are different ways to succeed at wrapping the value.
    1700             :           do {
    1701           0 :             JS::ExposeObjectToActiveJS(recordValue0);
    1702           0 :             tmp.setObject(*recordValue0);
    1703           0 :             if (!MaybeWrapObjectValue(cx, &tmp)) {
    1704           0 :               return false;
    1705             :             }
    1706           0 :             break;
    1707             :           } while (0);
    1708           0 :           if (!JS_DefineUCProperty(cx, returnObj,
    1709             :                                    entry.mKey.BeginReading(),
    1710           0 :                                    entry.mKey.Length(), tmp,
    1711             :                                    JSPROP_ENUMERATE)) {
    1712           0 :             return false;
    1713             :           }
    1714             :         }
    1715             :       }
    1716           0 :       rval.setObject(*returnObj);
    1717           0 :       return true;
    1718             :       break;
    1719             :     }
    1720             :     case eLong: {
    1721           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    1722           0 :       return true;
    1723             :       break;
    1724             :     }
    1725             :     default: {
    1726           0 :       return false;
    1727             :       break;
    1728             :     }
    1729             :   }
    1730             : 
    1731             :   return false;
    1732             : }
    1733             : 
    1734             : bool
    1735           0 : StringOrObject::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    1736             : {
    1737           0 :   switch (mType) {
    1738             :     case eUninitialized: {
    1739           0 :       return false;
    1740             :       break;
    1741             :     }
    1742             :     case eString: {
    1743           0 :       if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) {
    1744           0 :         return false;
    1745             :       }
    1746           0 :       return true;
    1747             :       break;
    1748             :     }
    1749             :     case eObject: {
    1750           0 :       JS::ExposeObjectToActiveJS(mValue.mObject.Value());
    1751           0 :       rval.setObject(*mValue.mObject.Value());
    1752           0 :       if (!MaybeWrapObjectValue(cx, rval)) {
    1753           0 :         return false;
    1754             :       }
    1755           0 :       return true;
    1756             :       break;
    1757             :     }
    1758             :     default: {
    1759           0 :       return false;
    1760             :       break;
    1761             :     }
    1762             :   }
    1763             : 
    1764             :   return false;
    1765             : }
    1766             : 
    1767             : bool
    1768           0 : StringOrStringSequence::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    1769             : {
    1770           0 :   switch (mType) {
    1771             :     case eUninitialized: {
    1772           0 :       return false;
    1773             :       break;
    1774             :     }
    1775             :     case eString: {
    1776           0 :       if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) {
    1777           0 :         return false;
    1778             :       }
    1779           0 :       return true;
    1780             :       break;
    1781             :     }
    1782             :     case eStringSequence: {
    1783             : 
    1784           0 :       uint32_t length = mValue.mStringSequence.Value().Length();
    1785           0 :       JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
    1786           0 :       if (!returnArray) {
    1787           0 :         return false;
    1788             :       }
    1789             :       // Scope for 'tmp'
    1790             :       {
    1791           0 :         JS::Rooted<JS::Value> tmp(cx);
    1792           0 :         for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
    1793             :           // Control block to let us common up the JS_DefineElement calls when there
    1794             :           // are different ways to succeed at wrapping the object.
    1795             :           do {
    1796           0 :             if (!xpc::NonVoidStringToJsval(cx, mValue.mStringSequence.Value()[sequenceIdx0], &tmp)) {
    1797           0 :               return false;
    1798             :             }
    1799           0 :             break;
    1800             :           } while (0);
    1801           0 :           if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
    1802             :                                 JSPROP_ENUMERATE)) {
    1803           0 :             return false;
    1804             :           }
    1805             :         }
    1806             :       }
    1807           0 :       rval.setObject(*returnArray);
    1808           0 :       return true;
    1809             :       break;
    1810             :     }
    1811             :     default: {
    1812           0 :       return false;
    1813             :       break;
    1814             :     }
    1815             :   }
    1816             : 
    1817             :   return false;
    1818             : }
    1819             : 
    1820             : bool
    1821           0 : StringSequenceOrEventInit::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    1822             : {
    1823           0 :   switch (mType) {
    1824             :     case eUninitialized: {
    1825           0 :       return false;
    1826             :       break;
    1827             :     }
    1828             :     case eStringSequence: {
    1829             : 
    1830           0 :       uint32_t length = mValue.mStringSequence.Value().Length();
    1831           0 :       JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
    1832           0 :       if (!returnArray) {
    1833           0 :         return false;
    1834             :       }
    1835             :       // Scope for 'tmp'
    1836             :       {
    1837           0 :         JS::Rooted<JS::Value> tmp(cx);
    1838           0 :         for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
    1839             :           // Control block to let us common up the JS_DefineElement calls when there
    1840             :           // are different ways to succeed at wrapping the object.
    1841             :           do {
    1842           0 :             if (!xpc::NonVoidStringToJsval(cx, mValue.mStringSequence.Value()[sequenceIdx0], &tmp)) {
    1843           0 :               return false;
    1844             :             }
    1845           0 :             break;
    1846             :           } while (0);
    1847           0 :           if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
    1848             :                                 JSPROP_ENUMERATE)) {
    1849           0 :             return false;
    1850             :           }
    1851             :         }
    1852             :       }
    1853           0 :       rval.setObject(*returnArray);
    1854           0 :       return true;
    1855             :       break;
    1856             :     }
    1857             :     case eEventInit: {
    1858           0 :       if (!mValue.mEventInit.Value().ToObjectInternal(cx, rval)) {
    1859           0 :         return false;
    1860             :       }
    1861           0 :       return true;
    1862             :       break;
    1863             :     }
    1864             :     default: {
    1865           0 :       return false;
    1866             :       break;
    1867             :     }
    1868             :   }
    1869             : 
    1870             :   return false;
    1871             : }
    1872             : 
    1873             : bool
    1874           0 : StringSequenceOrStringStringRecord::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    1875             : {
    1876           0 :   switch (mType) {
    1877             :     case eUninitialized: {
    1878           0 :       return false;
    1879             :       break;
    1880             :     }
    1881             :     case eStringSequence: {
    1882             : 
    1883           0 :       uint32_t length = mValue.mStringSequence.Value().Length();
    1884           0 :       JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
    1885           0 :       if (!returnArray) {
    1886           0 :         return false;
    1887             :       }
    1888             :       // Scope for 'tmp'
    1889             :       {
    1890           0 :         JS::Rooted<JS::Value> tmp(cx);
    1891           0 :         for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
    1892             :           // Control block to let us common up the JS_DefineElement calls when there
    1893             :           // are different ways to succeed at wrapping the object.
    1894             :           do {
    1895           0 :             if (!xpc::NonVoidStringToJsval(cx, mValue.mStringSequence.Value()[sequenceIdx0], &tmp)) {
    1896           0 :               return false;
    1897             :             }
    1898           0 :             break;
    1899             :           } while (0);
    1900           0 :           if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
    1901             :                                 JSPROP_ENUMERATE)) {
    1902           0 :             return false;
    1903             :           }
    1904             :         }
    1905             :       }
    1906           0 :       rval.setObject(*returnArray);
    1907           0 :       return true;
    1908             :       break;
    1909             :     }
    1910             :     case eStringStringRecord: {
    1911             : 
    1912           0 :       JS::Rooted<JSObject*> returnObj(cx, JS_NewPlainObject(cx));
    1913           0 :       if (!returnObj) {
    1914           0 :         return false;
    1915             :       }
    1916             :       // Scope for 'tmp'
    1917             :       {
    1918           0 :         JS::Rooted<JS::Value> tmp(cx);
    1919           0 :         for (auto& entry : mValue.mStringStringRecord.Value().Entries()) {
    1920           0 :           auto& recordValue0 = entry.mValue;
    1921             :           // Control block to let us common up the JS_DefineUCProperty calls when there
    1922             :           // are different ways to succeed at wrapping the value.
    1923             :           do {
    1924           0 :             if (!xpc::NonVoidStringToJsval(cx, recordValue0, &tmp)) {
    1925           0 :               return false;
    1926             :             }
    1927           0 :             break;
    1928             :           } while (0);
    1929           0 :           if (!JS_DefineUCProperty(cx, returnObj,
    1930             :                                    entry.mKey.BeginReading(),
    1931           0 :                                    entry.mKey.Length(), tmp,
    1932             :                                    JSPROP_ENUMERATE)) {
    1933           0 :             return false;
    1934             :           }
    1935             :         }
    1936             :       }
    1937           0 :       rval.setObject(*returnObj);
    1938           0 :       return true;
    1939             :       break;
    1940             :     }
    1941             :     default: {
    1942           0 :       return false;
    1943             :       break;
    1944             :     }
    1945             :   }
    1946             : 
    1947             :   return false;
    1948             : }
    1949             : 
    1950             : bool
    1951           0 : StringStringRecordOrString::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    1952             : {
    1953           0 :   switch (mType) {
    1954             :     case eUninitialized: {
    1955           0 :       return false;
    1956             :       break;
    1957             :     }
    1958             :     case eStringStringRecord: {
    1959             : 
    1960           0 :       JS::Rooted<JSObject*> returnObj(cx, JS_NewPlainObject(cx));
    1961           0 :       if (!returnObj) {
    1962           0 :         return false;
    1963             :       }
    1964             :       // Scope for 'tmp'
    1965             :       {
    1966           0 :         JS::Rooted<JS::Value> tmp(cx);
    1967           0 :         for (auto& entry : mValue.mStringStringRecord.Value().Entries()) {
    1968           0 :           auto& recordValue0 = entry.mValue;
    1969             :           // Control block to let us common up the JS_DefineUCProperty calls when there
    1970             :           // are different ways to succeed at wrapping the value.
    1971             :           do {
    1972           0 :             if (!xpc::NonVoidStringToJsval(cx, recordValue0, &tmp)) {
    1973           0 :               return false;
    1974             :             }
    1975           0 :             break;
    1976             :           } while (0);
    1977           0 :           if (!JS_DefineUCProperty(cx, returnObj,
    1978             :                                    entry.mKey.BeginReading(),
    1979           0 :                                    entry.mKey.Length(), tmp,
    1980             :                                    JSPROP_ENUMERATE)) {
    1981           0 :             return false;
    1982             :           }
    1983             :         }
    1984             :       }
    1985           0 :       rval.setObject(*returnObj);
    1986           0 :       return true;
    1987             :       break;
    1988             :     }
    1989             :     case eString: {
    1990           0 :       if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) {
    1991           0 :         return false;
    1992             :       }
    1993           0 :       return true;
    1994             :       break;
    1995             :     }
    1996             :     default: {
    1997           0 :       return false;
    1998             :       break;
    1999             :     }
    2000             :   }
    2001             : 
    2002             :   return false;
    2003             : }
    2004             : 
    2005             : bool
    2006           0 : StringStringRecordOrStringSequence::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    2007             : {
    2008           0 :   switch (mType) {
    2009             :     case eUninitialized: {
    2010           0 :       return false;
    2011             :       break;
    2012             :     }
    2013             :     case eStringStringRecord: {
    2014             : 
    2015           0 :       JS::Rooted<JSObject*> returnObj(cx, JS_NewPlainObject(cx));
    2016           0 :       if (!returnObj) {
    2017           0 :         return false;
    2018             :       }
    2019             :       // Scope for 'tmp'
    2020             :       {
    2021           0 :         JS::Rooted<JS::Value> tmp(cx);
    2022           0 :         for (auto& entry : mValue.mStringStringRecord.Value().Entries()) {
    2023           0 :           auto& recordValue0 = entry.mValue;
    2024             :           // Control block to let us common up the JS_DefineUCProperty calls when there
    2025             :           // are different ways to succeed at wrapping the value.
    2026             :           do {
    2027           0 :             if (!xpc::NonVoidStringToJsval(cx, recordValue0, &tmp)) {
    2028           0 :               return false;
    2029             :             }
    2030           0 :             break;
    2031             :           } while (0);
    2032           0 :           if (!JS_DefineUCProperty(cx, returnObj,
    2033             :                                    entry.mKey.BeginReading(),
    2034           0 :                                    entry.mKey.Length(), tmp,
    2035             :                                    JSPROP_ENUMERATE)) {
    2036           0 :             return false;
    2037             :           }
    2038             :         }
    2039             :       }
    2040           0 :       rval.setObject(*returnObj);
    2041           0 :       return true;
    2042             :       break;
    2043             :     }
    2044             :     case eStringSequence: {
    2045             : 
    2046           0 :       uint32_t length = mValue.mStringSequence.Value().Length();
    2047           0 :       JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
    2048           0 :       if (!returnArray) {
    2049           0 :         return false;
    2050             :       }
    2051             :       // Scope for 'tmp'
    2052             :       {
    2053           0 :         JS::Rooted<JS::Value> tmp(cx);
    2054           0 :         for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
    2055             :           // Control block to let us common up the JS_DefineElement calls when there
    2056             :           // are different ways to succeed at wrapping the object.
    2057             :           do {
    2058           0 :             if (!xpc::NonVoidStringToJsval(cx, mValue.mStringSequence.Value()[sequenceIdx0], &tmp)) {
    2059           0 :               return false;
    2060             :             }
    2061           0 :             break;
    2062             :           } while (0);
    2063           0 :           if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
    2064             :                                 JSPROP_ENUMERATE)) {
    2065           0 :             return false;
    2066             :           }
    2067             :         }
    2068             :       }
    2069           0 :       rval.setObject(*returnArray);
    2070           0 :       return true;
    2071             :       break;
    2072             :     }
    2073             :     default: {
    2074           0 :       return false;
    2075             :       break;
    2076             :     }
    2077             :   }
    2078             : 
    2079             :   return false;
    2080             : }
    2081             : 
    2082             : bool
    2083           0 : SupportedTypeOrObject::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    2084             : {
    2085           0 :   switch (mType) {
    2086             :     case eUninitialized: {
    2087           0 :       return false;
    2088             :       break;
    2089             :     }
    2090             :     case eSupportedType: {
    2091           0 :       if (!ToJSValue(cx, mValue.mSupportedType.Value(), rval)) {
    2092           0 :         return false;
    2093             :       }
    2094           0 :       return true;
    2095             :       break;
    2096             :     }
    2097             :     case eObject: {
    2098           0 :       JS::ExposeObjectToActiveJS(mValue.mObject.Value());
    2099           0 :       rval.setObject(*mValue.mObject.Value());
    2100           0 :       if (!MaybeWrapObjectValue(cx, rval)) {
    2101           0 :         return false;
    2102             :       }
    2103           0 :       return true;
    2104             :       break;
    2105             :     }
    2106             :     default: {
    2107           0 :       return false;
    2108             :       break;
    2109             :     }
    2110             :   }
    2111             : 
    2112             :   return false;
    2113             : }
    2114             : 
    2115             : bool
    2116           0 : USVStringOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    2117             : {
    2118           0 :   switch (mType) {
    2119             :     case eUninitialized: {
    2120           0 :       return false;
    2121             :       break;
    2122             :     }
    2123             :     case eUSVString: {
    2124           0 :       if (!xpc::NonVoidStringToJsval(cx, mValue.mUSVString.Value(), rval)) {
    2125           0 :         return false;
    2126             :       }
    2127           0 :       return true;
    2128             :       break;
    2129             :     }
    2130             :     case eLong: {
    2131           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    2132           0 :       return true;
    2133             :       break;
    2134             :     }
    2135             :     default: {
    2136           0 :       return false;
    2137             :       break;
    2138             :     }
    2139             :   }
    2140             : 
    2141             :   return false;
    2142             : }
    2143             : 
    2144             : bool
    2145           0 : UnrestrictedDoubleOrString::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    2146             : {
    2147           0 :   switch (mType) {
    2148             :     case eUninitialized: {
    2149           0 :       return false;
    2150             :       break;
    2151             :     }
    2152             :     case eUnrestrictedDouble: {
    2153           0 :       rval.set(JS_NumberValue(double(mValue.mUnrestrictedDouble.Value())));
    2154           0 :       return true;
    2155             :       break;
    2156             :     }
    2157             :     case eString: {
    2158           0 :       if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) {
    2159           0 :         return false;
    2160             :       }
    2161           0 :       return true;
    2162             :       break;
    2163             :     }
    2164             :     default: {
    2165           0 :       return false;
    2166             :       break;
    2167             :     }
    2168             :   }
    2169             : 
    2170             :   return false;
    2171             : }
    2172             : 
    2173             : bool
    2174           0 : UnrestrictedFloatOrString::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    2175             : {
    2176           0 :   switch (mType) {
    2177             :     case eUninitialized: {
    2178           0 :       return false;
    2179             :       break;
    2180             :     }
    2181             :     case eUnrestrictedFloat: {
    2182           0 :       rval.set(JS_NumberValue(double(mValue.mUnrestrictedFloat.Value())));
    2183           0 :       return true;
    2184             :       break;
    2185             :     }
    2186             :     case eString: {
    2187           0 :       if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) {
    2188           0 :         return false;
    2189             :       }
    2190           0 :       return true;
    2191             :       break;
    2192             :     }
    2193             :     default: {
    2194           0 :       return false;
    2195             :       break;
    2196             :     }
    2197             :   }
    2198             : 
    2199             :   return false;
    2200             : }
    2201             : 
    2202             : ArrayBuffer&
    2203           0 : OwningArrayBufferOrLong::RawSetAsArrayBuffer()
    2204             : {
    2205           0 :   if (mType == eArrayBuffer) {
    2206           0 :     return mValue.mArrayBuffer.Value();
    2207             :   }
    2208           0 :   MOZ_ASSERT(mType == eUninitialized);
    2209           0 :   mType = eArrayBuffer;
    2210           0 :   return mValue.mArrayBuffer.SetValue();
    2211             : }
    2212             : 
    2213             : ArrayBuffer&
    2214           0 : OwningArrayBufferOrLong::SetAsArrayBuffer()
    2215             : {
    2216           0 :   if (mType == eArrayBuffer) {
    2217           0 :     return mValue.mArrayBuffer.Value();
    2218             :   }
    2219           0 :   Uninit();
    2220           0 :   mType = eArrayBuffer;
    2221           0 :   return mValue.mArrayBuffer.SetValue();
    2222             : }
    2223             : 
    2224             : bool
    2225           0 : OwningArrayBufferOrLong::TrySetToArrayBuffer(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    2226             : {
    2227           0 :   tryNext = false;
    2228             :   { // scope for memberSlot
    2229           0 :     ArrayBuffer& memberSlot = RawSetAsArrayBuffer();
    2230           0 :     if (!memberSlot.Init(&value.toObject())) {
    2231           0 :       DestroyArrayBuffer();
    2232           0 :       tryNext = true;
    2233           0 :       return true;
    2234             :     }
    2235             :   }
    2236           0 :   return true;
    2237             : }
    2238             : 
    2239             : void
    2240           0 : OwningArrayBufferOrLong::DestroyArrayBuffer()
    2241             : {
    2242           0 :   MOZ_ASSERT(IsArrayBuffer(), "Wrong type!");
    2243           0 :   mValue.mArrayBuffer.Destroy();
    2244           0 :   mType = eUninitialized;
    2245           0 : }
    2246             : 
    2247             : 
    2248             : 
    2249             : 
    2250             : int32_t&
    2251           0 : OwningArrayBufferOrLong::RawSetAsLong()
    2252             : {
    2253           0 :   if (mType == eLong) {
    2254           0 :     return mValue.mLong.Value();
    2255             :   }
    2256           0 :   MOZ_ASSERT(mType == eUninitialized);
    2257           0 :   mType = eLong;
    2258           0 :   return mValue.mLong.SetValue();
    2259             : }
    2260             : 
    2261             : int32_t&
    2262           0 : OwningArrayBufferOrLong::SetAsLong()
    2263             : {
    2264           0 :   if (mType == eLong) {
    2265           0 :     return mValue.mLong.Value();
    2266             :   }
    2267           0 :   Uninit();
    2268           0 :   mType = eLong;
    2269           0 :   return mValue.mLong.SetValue();
    2270             : }
    2271             : 
    2272             : bool
    2273           0 : OwningArrayBufferOrLong::TrySetToLong(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    2274             : {
    2275           0 :   tryNext = false;
    2276             :   { // scope for memberSlot
    2277           0 :     int32_t& memberSlot = RawSetAsLong();
    2278           0 :     if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
    2279           0 :       return false;
    2280             :     }
    2281             :   }
    2282           0 :   return true;
    2283             : }
    2284             : 
    2285             : void
    2286           0 : OwningArrayBufferOrLong::DestroyLong()
    2287             : {
    2288           0 :   MOZ_ASSERT(IsLong(), "Wrong type!");
    2289           0 :   mValue.mLong.Destroy();
    2290           0 :   mType = eUninitialized;
    2291           0 : }
    2292             : 
    2293             : 
    2294             : 
    2295             : 
    2296             : void
    2297           0 : OwningArrayBufferOrLong::Uninit()
    2298             : {
    2299           0 :   switch (mType) {
    2300             :     case eUninitialized: {
    2301           0 :       break;
    2302             :     }
    2303             :     case eArrayBuffer: {
    2304           0 :       DestroyArrayBuffer();
    2305           0 :       break;
    2306             :     }
    2307             :     case eLong: {
    2308           0 :       DestroyLong();
    2309           0 :       break;
    2310             :     }
    2311             :   }
    2312           0 : }
    2313             : 
    2314             : bool
    2315           0 : OwningArrayBufferOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    2316             : {
    2317           0 :   switch (mType) {
    2318             :     case eUninitialized: {
    2319           0 :       return false;
    2320             :       break;
    2321             :     }
    2322             :     case eArrayBuffer: {
    2323           0 :       rval.setObject(*mValue.mArrayBuffer.Value().Obj());
    2324           0 :       if (!MaybeWrapNonDOMObjectValue(cx, rval)) {
    2325           0 :         return false;
    2326             :       }
    2327           0 :       return true;
    2328             :       break;
    2329             :     }
    2330             :     case eLong: {
    2331           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    2332           0 :       return true;
    2333             :       break;
    2334             :     }
    2335             :     default: {
    2336           0 :       return false;
    2337             :       break;
    2338             :     }
    2339             :   }
    2340             : 
    2341             :   return false;
    2342             : }
    2343             : 
    2344             : void
    2345           0 : OwningArrayBufferOrLong::TraceUnion(JSTracer* trc)
    2346             : {
    2347           0 :   switch (mType) {
    2348             :     case eArrayBuffer: {
    2349           0 :       mValue.mArrayBuffer.Value().TraceSelf(trc);
    2350           0 :       break;
    2351             :     }
    2352             :     default: {
    2353           0 :       break;
    2354             :     }
    2355             :   }
    2356           0 : }
    2357             : 
    2358             : ArrayBufferView&
    2359           0 : OwningArrayBufferViewOrArrayBuffer::RawSetAsArrayBufferView()
    2360             : {
    2361           0 :   if (mType == eArrayBufferView) {
    2362           0 :     return mValue.mArrayBufferView.Value();
    2363             :   }
    2364           0 :   MOZ_ASSERT(mType == eUninitialized);
    2365           0 :   mType = eArrayBufferView;
    2366           0 :   return mValue.mArrayBufferView.SetValue();
    2367             : }
    2368             : 
    2369             : ArrayBufferView&
    2370           0 : OwningArrayBufferViewOrArrayBuffer::SetAsArrayBufferView()
    2371             : {
    2372           0 :   if (mType == eArrayBufferView) {
    2373           0 :     return mValue.mArrayBufferView.Value();
    2374             :   }
    2375           0 :   Uninit();
    2376           0 :   mType = eArrayBufferView;
    2377           0 :   return mValue.mArrayBufferView.SetValue();
    2378             : }
    2379             : 
    2380             : bool
    2381           0 : OwningArrayBufferViewOrArrayBuffer::TrySetToArrayBufferView(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    2382             : {
    2383           0 :   tryNext = false;
    2384             :   { // scope for memberSlot
    2385           0 :     ArrayBufferView& memberSlot = RawSetAsArrayBufferView();
    2386           0 :     if (!memberSlot.Init(&value.toObject())) {
    2387           0 :       DestroyArrayBufferView();
    2388           0 :       tryNext = true;
    2389           0 :       return true;
    2390             :     }
    2391             :   }
    2392           0 :   return true;
    2393             : }
    2394             : 
    2395             : void
    2396           0 : OwningArrayBufferViewOrArrayBuffer::DestroyArrayBufferView()
    2397             : {
    2398           0 :   MOZ_ASSERT(IsArrayBufferView(), "Wrong type!");
    2399           0 :   mValue.mArrayBufferView.Destroy();
    2400           0 :   mType = eUninitialized;
    2401           0 : }
    2402             : 
    2403             : 
    2404             : 
    2405             : 
    2406             : ArrayBuffer&
    2407           0 : OwningArrayBufferViewOrArrayBuffer::RawSetAsArrayBuffer()
    2408             : {
    2409           0 :   if (mType == eArrayBuffer) {
    2410           0 :     return mValue.mArrayBuffer.Value();
    2411             :   }
    2412           0 :   MOZ_ASSERT(mType == eUninitialized);
    2413           0 :   mType = eArrayBuffer;
    2414           0 :   return mValue.mArrayBuffer.SetValue();
    2415             : }
    2416             : 
    2417             : ArrayBuffer&
    2418           0 : OwningArrayBufferViewOrArrayBuffer::SetAsArrayBuffer()
    2419             : {
    2420           0 :   if (mType == eArrayBuffer) {
    2421           0 :     return mValue.mArrayBuffer.Value();
    2422             :   }
    2423           0 :   Uninit();
    2424           0 :   mType = eArrayBuffer;
    2425           0 :   return mValue.mArrayBuffer.SetValue();
    2426             : }
    2427             : 
    2428             : bool
    2429           0 : OwningArrayBufferViewOrArrayBuffer::TrySetToArrayBuffer(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    2430             : {
    2431           0 :   tryNext = false;
    2432             :   { // scope for memberSlot
    2433           0 :     ArrayBuffer& memberSlot = RawSetAsArrayBuffer();
    2434           0 :     if (!memberSlot.Init(&value.toObject())) {
    2435           0 :       DestroyArrayBuffer();
    2436           0 :       tryNext = true;
    2437           0 :       return true;
    2438             :     }
    2439             :   }
    2440           0 :   return true;
    2441             : }
    2442             : 
    2443             : void
    2444           0 : OwningArrayBufferViewOrArrayBuffer::DestroyArrayBuffer()
    2445             : {
    2446           0 :   MOZ_ASSERT(IsArrayBuffer(), "Wrong type!");
    2447           0 :   mValue.mArrayBuffer.Destroy();
    2448           0 :   mType = eUninitialized;
    2449           0 : }
    2450             : 
    2451             : 
    2452             : 
    2453             : 
    2454             : void
    2455           0 : OwningArrayBufferViewOrArrayBuffer::Uninit()
    2456             : {
    2457           0 :   switch (mType) {
    2458             :     case eUninitialized: {
    2459           0 :       break;
    2460             :     }
    2461             :     case eArrayBufferView: {
    2462           0 :       DestroyArrayBufferView();
    2463           0 :       break;
    2464             :     }
    2465             :     case eArrayBuffer: {
    2466           0 :       DestroyArrayBuffer();
    2467           0 :       break;
    2468             :     }
    2469             :   }
    2470           0 : }
    2471             : 
    2472             : bool
    2473           0 : OwningArrayBufferViewOrArrayBuffer::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    2474             : {
    2475           0 :   switch (mType) {
    2476             :     case eUninitialized: {
    2477           0 :       return false;
    2478             :       break;
    2479             :     }
    2480             :     case eArrayBufferView: {
    2481           0 :       rval.setObject(*mValue.mArrayBufferView.Value().Obj());
    2482           0 :       if (!MaybeWrapNonDOMObjectValue(cx, rval)) {
    2483           0 :         return false;
    2484             :       }
    2485           0 :       return true;
    2486             :       break;
    2487             :     }
    2488             :     case eArrayBuffer: {
    2489           0 :       rval.setObject(*mValue.mArrayBuffer.Value().Obj());
    2490           0 :       if (!MaybeWrapNonDOMObjectValue(cx, rval)) {
    2491           0 :         return false;
    2492             :       }
    2493           0 :       return true;
    2494             :       break;
    2495             :     }
    2496             :     default: {
    2497           0 :       return false;
    2498             :       break;
    2499             :     }
    2500             :   }
    2501             : 
    2502             :   return false;
    2503             : }
    2504             : 
    2505             : void
    2506           0 : OwningArrayBufferViewOrArrayBuffer::TraceUnion(JSTracer* trc)
    2507             : {
    2508           0 :   switch (mType) {
    2509             :     case eArrayBufferView: {
    2510           0 :       mValue.mArrayBufferView.Value().TraceSelf(trc);
    2511           0 :       break;
    2512             :     }
    2513             :     case eArrayBuffer: {
    2514           0 :       mValue.mArrayBuffer.Value().TraceSelf(trc);
    2515           0 :       break;
    2516             :     }
    2517             :     default: {
    2518           0 :       break;
    2519             :     }
    2520             :   }
    2521           0 : }
    2522             : 
    2523             : nsCString&
    2524           0 : OwningByteStringOrLong::RawSetAsByteString()
    2525             : {
    2526           0 :   if (mType == eByteString) {
    2527           0 :     return mValue.mByteString.Value();
    2528             :   }
    2529           0 :   MOZ_ASSERT(mType == eUninitialized);
    2530           0 :   mType = eByteString;
    2531           0 :   return mValue.mByteString.SetValue();
    2532             : }
    2533             : 
    2534             : nsCString&
    2535           0 : OwningByteStringOrLong::SetAsByteString()
    2536             : {
    2537           0 :   if (mType == eByteString) {
    2538           0 :     return mValue.mByteString.Value();
    2539             :   }
    2540           0 :   Uninit();
    2541           0 :   mType = eByteString;
    2542           0 :   return mValue.mByteString.SetValue();
    2543             : }
    2544             : 
    2545             : bool
    2546           0 : OwningByteStringOrLong::TrySetToByteString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    2547             : {
    2548           0 :   tryNext = false;
    2549             :   { // scope for memberSlot
    2550           0 :     nsCString& memberSlot = RawSetAsByteString();
    2551           0 :     if (!ConvertJSValueToByteString(cx, value, false, memberSlot)) {
    2552           0 :       return false;
    2553             :     }
    2554             :   }
    2555           0 :   return true;
    2556             : }
    2557             : 
    2558             : 
    2559             : void
    2560           0 : OwningByteStringOrLong::DestroyByteString()
    2561             : {
    2562           0 :   MOZ_ASSERT(IsByteString(), "Wrong type!");
    2563           0 :   mValue.mByteString.Destroy();
    2564           0 :   mType = eUninitialized;
    2565           0 : }
    2566             : 
    2567             : 
    2568             : 
    2569             : 
    2570             : int32_t&
    2571           0 : OwningByteStringOrLong::RawSetAsLong()
    2572             : {
    2573           0 :   if (mType == eLong) {
    2574           0 :     return mValue.mLong.Value();
    2575             :   }
    2576           0 :   MOZ_ASSERT(mType == eUninitialized);
    2577           0 :   mType = eLong;
    2578           0 :   return mValue.mLong.SetValue();
    2579             : }
    2580             : 
    2581             : int32_t&
    2582           0 : OwningByteStringOrLong::SetAsLong()
    2583             : {
    2584           0 :   if (mType == eLong) {
    2585           0 :     return mValue.mLong.Value();
    2586             :   }
    2587           0 :   Uninit();
    2588           0 :   mType = eLong;
    2589           0 :   return mValue.mLong.SetValue();
    2590             : }
    2591             : 
    2592             : bool
    2593           0 : OwningByteStringOrLong::TrySetToLong(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    2594             : {
    2595           0 :   tryNext = false;
    2596             :   { // scope for memberSlot
    2597           0 :     int32_t& memberSlot = RawSetAsLong();
    2598           0 :     if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
    2599           0 :       return false;
    2600             :     }
    2601             :   }
    2602           0 :   return true;
    2603             : }
    2604             : 
    2605             : void
    2606           0 : OwningByteStringOrLong::DestroyLong()
    2607             : {
    2608           0 :   MOZ_ASSERT(IsLong(), "Wrong type!");
    2609           0 :   mValue.mLong.Destroy();
    2610           0 :   mType = eUninitialized;
    2611           0 : }
    2612             : 
    2613             : 
    2614             : 
    2615             : 
    2616             : void
    2617           0 : OwningByteStringOrLong::Uninit()
    2618             : {
    2619           0 :   switch (mType) {
    2620             :     case eUninitialized: {
    2621           0 :       break;
    2622             :     }
    2623             :     case eByteString: {
    2624           0 :       DestroyByteString();
    2625           0 :       break;
    2626             :     }
    2627             :     case eLong: {
    2628           0 :       DestroyLong();
    2629           0 :       break;
    2630             :     }
    2631             :   }
    2632           0 : }
    2633             : 
    2634             : bool
    2635           0 : OwningByteStringOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    2636             : {
    2637           0 :   switch (mType) {
    2638             :     case eUninitialized: {
    2639           0 :       return false;
    2640             :       break;
    2641             :     }
    2642             :     case eByteString: {
    2643           0 :       if (!NonVoidByteStringToJsval(cx, mValue.mByteString.Value(), rval)) {
    2644           0 :         return false;
    2645             :       }
    2646           0 :       return true;
    2647             :       break;
    2648             :     }
    2649             :     case eLong: {
    2650           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    2651           0 :       return true;
    2652             :       break;
    2653             :     }
    2654             :     default: {
    2655           0 :       return false;
    2656             :       break;
    2657             :     }
    2658             :   }
    2659             : 
    2660             :   return false;
    2661             : }
    2662             : 
    2663             : void
    2664           0 : OwningByteStringOrLong::TraceUnion(JSTracer* trc)
    2665             : {
    2666           0 : }
    2667             : 
    2668             : OwningByteStringOrLong&
    2669           0 : OwningByteStringOrLong::operator=(const OwningByteStringOrLong& aOther)
    2670             : {
    2671           0 :   switch (aOther.mType) {
    2672             :     case eUninitialized: {
    2673           0 :       MOZ_ASSERT(mType == eUninitialized,
    2674             :                  "We need to destroy ourselves?");
    2675           0 :       break;
    2676             :     }
    2677             :     case eByteString: {
    2678           0 :       SetAsByteString() = aOther.GetAsByteString();
    2679           0 :       break;
    2680             :     }
    2681             :     case eLong: {
    2682           0 :       SetAsLong() = aOther.GetAsLong();
    2683           0 :       break;
    2684             :     }
    2685             :   }
    2686           0 :   return *this;
    2687             : }
    2688             : 
    2689             : OwningNonNull<mozilla::dom::CanvasPattern>&
    2690           0 : OwningCanvasPatternOrCanvasGradient::RawSetAsCanvasPattern()
    2691             : {
    2692           0 :   if (mType == eCanvasPattern) {
    2693           0 :     return mValue.mCanvasPattern.Value();
    2694             :   }
    2695           0 :   MOZ_ASSERT(mType == eUninitialized);
    2696           0 :   mType = eCanvasPattern;
    2697           0 :   return mValue.mCanvasPattern.SetValue();
    2698             : }
    2699             : 
    2700             : OwningNonNull<mozilla::dom::CanvasPattern>&
    2701           0 : OwningCanvasPatternOrCanvasGradient::SetAsCanvasPattern()
    2702             : {
    2703           0 :   if (mType == eCanvasPattern) {
    2704           0 :     return mValue.mCanvasPattern.Value();
    2705             :   }
    2706           0 :   Uninit();
    2707           0 :   mType = eCanvasPattern;
    2708           0 :   return mValue.mCanvasPattern.SetValue();
    2709             : }
    2710             : 
    2711             : bool
    2712           0 : OwningCanvasPatternOrCanvasGradient::TrySetToCanvasPattern(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    2713             : {
    2714           0 :   tryNext = false;
    2715             :   { // scope for memberSlot
    2716           0 :     OwningNonNull<mozilla::dom::CanvasPattern>& memberSlot = RawSetAsCanvasPattern();
    2717             :     static_assert(IsRefcounted<mozilla::dom::CanvasPattern>::value, "We can only store refcounted classes.");{
    2718           0 :       nsresult rv = UnwrapObject<prototypes::id::CanvasPattern, mozilla::dom::CanvasPattern>(value, memberSlot);
    2719           0 :       if (NS_FAILED(rv)) {
    2720           0 :         DestroyCanvasPattern();
    2721           0 :         tryNext = true;
    2722           0 :         return true;
    2723             :       }
    2724             :     }
    2725             :   }
    2726           0 :   return true;
    2727             : }
    2728             : 
    2729             : void
    2730           0 : OwningCanvasPatternOrCanvasGradient::DestroyCanvasPattern()
    2731             : {
    2732           0 :   MOZ_ASSERT(IsCanvasPattern(), "Wrong type!");
    2733           0 :   mValue.mCanvasPattern.Destroy();
    2734           0 :   mType = eUninitialized;
    2735           0 : }
    2736             : 
    2737             : 
    2738             : 
    2739             : 
    2740             : OwningNonNull<mozilla::dom::CanvasGradient>&
    2741           0 : OwningCanvasPatternOrCanvasGradient::RawSetAsCanvasGradient()
    2742             : {
    2743           0 :   if (mType == eCanvasGradient) {
    2744           0 :     return mValue.mCanvasGradient.Value();
    2745             :   }
    2746           0 :   MOZ_ASSERT(mType == eUninitialized);
    2747           0 :   mType = eCanvasGradient;
    2748           0 :   return mValue.mCanvasGradient.SetValue();
    2749             : }
    2750             : 
    2751             : OwningNonNull<mozilla::dom::CanvasGradient>&
    2752           0 : OwningCanvasPatternOrCanvasGradient::SetAsCanvasGradient()
    2753             : {
    2754           0 :   if (mType == eCanvasGradient) {
    2755           0 :     return mValue.mCanvasGradient.Value();
    2756             :   }
    2757           0 :   Uninit();
    2758           0 :   mType = eCanvasGradient;
    2759           0 :   return mValue.mCanvasGradient.SetValue();
    2760             : }
    2761             : 
    2762             : bool
    2763           0 : OwningCanvasPatternOrCanvasGradient::TrySetToCanvasGradient(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    2764             : {
    2765           0 :   tryNext = false;
    2766             :   { // scope for memberSlot
    2767           0 :     OwningNonNull<mozilla::dom::CanvasGradient>& memberSlot = RawSetAsCanvasGradient();
    2768             :     static_assert(IsRefcounted<mozilla::dom::CanvasGradient>::value, "We can only store refcounted classes.");{
    2769           0 :       nsresult rv = UnwrapObject<prototypes::id::CanvasGradient, mozilla::dom::CanvasGradient>(value, memberSlot);
    2770           0 :       if (NS_FAILED(rv)) {
    2771           0 :         DestroyCanvasGradient();
    2772           0 :         tryNext = true;
    2773           0 :         return true;
    2774             :       }
    2775             :     }
    2776             :   }
    2777           0 :   return true;
    2778             : }
    2779             : 
    2780             : void
    2781           0 : OwningCanvasPatternOrCanvasGradient::DestroyCanvasGradient()
    2782             : {
    2783           0 :   MOZ_ASSERT(IsCanvasGradient(), "Wrong type!");
    2784           0 :   mValue.mCanvasGradient.Destroy();
    2785           0 :   mType = eUninitialized;
    2786           0 : }
    2787             : 
    2788             : 
    2789             : 
    2790             : 
    2791             : void
    2792           0 : OwningCanvasPatternOrCanvasGradient::Uninit()
    2793             : {
    2794           0 :   switch (mType) {
    2795             :     case eUninitialized: {
    2796           0 :       break;
    2797             :     }
    2798             :     case eCanvasPattern: {
    2799           0 :       DestroyCanvasPattern();
    2800           0 :       break;
    2801             :     }
    2802             :     case eCanvasGradient: {
    2803           0 :       DestroyCanvasGradient();
    2804           0 :       break;
    2805             :     }
    2806             :   }
    2807           0 : }
    2808             : 
    2809             : bool
    2810           0 : OwningCanvasPatternOrCanvasGradient::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    2811             : {
    2812           0 :   switch (mType) {
    2813             :     case eUninitialized: {
    2814           0 :       return false;
    2815             :       break;
    2816             :     }
    2817             :     case eCanvasPattern: {
    2818           0 :       if (!GetOrCreateDOMReflector(cx, mValue.mCanvasPattern.Value(), rval)) {
    2819           0 :         MOZ_ASSERT(true || JS_IsExceptionPending(cx));
    2820           0 :         return false;
    2821             :       }
    2822           0 :       return true;
    2823             :       break;
    2824             :     }
    2825             :     case eCanvasGradient: {
    2826           0 :       if (!GetOrCreateDOMReflector(cx, mValue.mCanvasGradient.Value(), rval)) {
    2827           0 :         MOZ_ASSERT(true || JS_IsExceptionPending(cx));
    2828           0 :         return false;
    2829             :       }
    2830           0 :       return true;
    2831             :       break;
    2832             :     }
    2833             :     default: {
    2834           0 :       return false;
    2835             :       break;
    2836             :     }
    2837             :   }
    2838             : 
    2839             :   return false;
    2840             : }
    2841             : 
    2842             : void
    2843           0 : OwningCanvasPatternOrCanvasGradient::TraceUnion(JSTracer* trc)
    2844             : {
    2845           0 : }
    2846             : 
    2847             : OwningCanvasPatternOrCanvasGradient&
    2848           0 : OwningCanvasPatternOrCanvasGradient::operator=(const OwningCanvasPatternOrCanvasGradient& aOther)
    2849             : {
    2850           0 :   switch (aOther.mType) {
    2851             :     case eUninitialized: {
    2852           0 :       MOZ_ASSERT(mType == eUninitialized,
    2853             :                  "We need to destroy ourselves?");
    2854           0 :       break;
    2855             :     }
    2856             :     case eCanvasPattern: {
    2857           0 :       SetAsCanvasPattern() = aOther.GetAsCanvasPattern();
    2858           0 :       break;
    2859             :     }
    2860             :     case eCanvasGradient: {
    2861           0 :       SetAsCanvasGradient() = aOther.GetAsCanvasGradient();
    2862           0 :       break;
    2863             :     }
    2864             :   }
    2865           0 :   return *this;
    2866             : }
    2867             : 
    2868             : OwningNonNull<mozilla::dom::CanvasPattern>&
    2869           0 : OwningCanvasPatternOrNullOrCanvasGradient::RawSetAsCanvasPattern()
    2870             : {
    2871           0 :   if (mType == eCanvasPattern) {
    2872           0 :     return mValue.mCanvasPattern.Value();
    2873             :   }
    2874           0 :   MOZ_ASSERT(mType == eUninitialized);
    2875           0 :   mType = eCanvasPattern;
    2876           0 :   return mValue.mCanvasPattern.SetValue();
    2877             : }
    2878             : 
    2879             : OwningNonNull<mozilla::dom::CanvasPattern>&
    2880           0 : OwningCanvasPatternOrNullOrCanvasGradient::SetAsCanvasPattern()
    2881             : {
    2882           0 :   if (mType == eCanvasPattern) {
    2883           0 :     return mValue.mCanvasPattern.Value();
    2884             :   }
    2885           0 :   Uninit();
    2886           0 :   mType = eCanvasPattern;
    2887           0 :   return mValue.mCanvasPattern.SetValue();
    2888             : }
    2889             : 
    2890             : bool
    2891           0 : OwningCanvasPatternOrNullOrCanvasGradient::TrySetToCanvasPattern(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    2892             : {
    2893           0 :   tryNext = false;
    2894             :   { // scope for memberSlot
    2895           0 :     OwningNonNull<mozilla::dom::CanvasPattern>& memberSlot = RawSetAsCanvasPattern();
    2896             :     static_assert(IsRefcounted<mozilla::dom::CanvasPattern>::value, "We can only store refcounted classes.");{
    2897           0 :       nsresult rv = UnwrapObject<prototypes::id::CanvasPattern, mozilla::dom::CanvasPattern>(value, memberSlot);
    2898           0 :       if (NS_FAILED(rv)) {
    2899           0 :         DestroyCanvasPattern();
    2900           0 :         tryNext = true;
    2901           0 :         return true;
    2902             :       }
    2903             :     }
    2904             :   }
    2905           0 :   return true;
    2906             : }
    2907             : 
    2908             : void
    2909           0 : OwningCanvasPatternOrNullOrCanvasGradient::DestroyCanvasPattern()
    2910             : {
    2911           0 :   MOZ_ASSERT(IsCanvasPattern(), "Wrong type!");
    2912           0 :   mValue.mCanvasPattern.Destroy();
    2913           0 :   mType = eUninitialized;
    2914           0 : }
    2915             : 
    2916             : 
    2917             : 
    2918             : 
    2919             : OwningNonNull<mozilla::dom::CanvasGradient>&
    2920           0 : OwningCanvasPatternOrNullOrCanvasGradient::RawSetAsCanvasGradient()
    2921             : {
    2922           0 :   if (mType == eCanvasGradient) {
    2923           0 :     return mValue.mCanvasGradient.Value();
    2924             :   }
    2925           0 :   MOZ_ASSERT(mType == eUninitialized);
    2926           0 :   mType = eCanvasGradient;
    2927           0 :   return mValue.mCanvasGradient.SetValue();
    2928             : }
    2929             : 
    2930             : OwningNonNull<mozilla::dom::CanvasGradient>&
    2931           0 : OwningCanvasPatternOrNullOrCanvasGradient::SetAsCanvasGradient()
    2932             : {
    2933           0 :   if (mType == eCanvasGradient) {
    2934           0 :     return mValue.mCanvasGradient.Value();
    2935             :   }
    2936           0 :   Uninit();
    2937           0 :   mType = eCanvasGradient;
    2938           0 :   return mValue.mCanvasGradient.SetValue();
    2939             : }
    2940             : 
    2941             : bool
    2942           0 : OwningCanvasPatternOrNullOrCanvasGradient::TrySetToCanvasGradient(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    2943             : {
    2944           0 :   tryNext = false;
    2945             :   { // scope for memberSlot
    2946           0 :     OwningNonNull<mozilla::dom::CanvasGradient>& memberSlot = RawSetAsCanvasGradient();
    2947             :     static_assert(IsRefcounted<mozilla::dom::CanvasGradient>::value, "We can only store refcounted classes.");{
    2948           0 :       nsresult rv = UnwrapObject<prototypes::id::CanvasGradient, mozilla::dom::CanvasGradient>(value, memberSlot);
    2949           0 :       if (NS_FAILED(rv)) {
    2950           0 :         DestroyCanvasGradient();
    2951           0 :         tryNext = true;
    2952           0 :         return true;
    2953             :       }
    2954             :     }
    2955             :   }
    2956           0 :   return true;
    2957             : }
    2958             : 
    2959             : void
    2960           0 : OwningCanvasPatternOrNullOrCanvasGradient::DestroyCanvasGradient()
    2961             : {
    2962           0 :   MOZ_ASSERT(IsCanvasGradient(), "Wrong type!");
    2963           0 :   mValue.mCanvasGradient.Destroy();
    2964           0 :   mType = eUninitialized;
    2965           0 : }
    2966             : 
    2967             : 
    2968             : 
    2969             : 
    2970             : void
    2971           0 : OwningCanvasPatternOrNullOrCanvasGradient::Uninit()
    2972             : {
    2973           0 :   switch (mType) {
    2974             :     case eUninitialized: {
    2975           0 :       break;
    2976             :     }
    2977             :     case eNull: {
    2978           0 :       break;
    2979             :     }
    2980             :     case eCanvasPattern: {
    2981           0 :       DestroyCanvasPattern();
    2982           0 :       break;
    2983             :     }
    2984             :     case eCanvasGradient: {
    2985           0 :       DestroyCanvasGradient();
    2986           0 :       break;
    2987             :     }
    2988             :   }
    2989           0 : }
    2990             : 
    2991             : bool
    2992           0 : OwningCanvasPatternOrNullOrCanvasGradient::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    2993             : {
    2994           0 :   switch (mType) {
    2995             :     case eUninitialized: {
    2996           0 :       return false;
    2997             :       break;
    2998             :     }
    2999             :     case eNull: {
    3000           0 :       rval.setNull();
    3001           0 :       return true;
    3002             :       break;
    3003             :     }
    3004             :     case eCanvasPattern: {
    3005           0 :       if (!GetOrCreateDOMReflector(cx, mValue.mCanvasPattern.Value(), rval)) {
    3006           0 :         MOZ_ASSERT(true || JS_IsExceptionPending(cx));
    3007           0 :         return false;
    3008             :       }
    3009           0 :       return true;
    3010             :       break;
    3011             :     }
    3012             :     case eCanvasGradient: {
    3013           0 :       if (!GetOrCreateDOMReflector(cx, mValue.mCanvasGradient.Value(), rval)) {
    3014           0 :         MOZ_ASSERT(true || JS_IsExceptionPending(cx));
    3015           0 :         return false;
    3016             :       }
    3017           0 :       return true;
    3018             :       break;
    3019             :     }
    3020             :     default: {
    3021           0 :       return false;
    3022             :       break;
    3023             :     }
    3024             :   }
    3025             : 
    3026             :   return false;
    3027             : }
    3028             : 
    3029             : void
    3030           0 : OwningCanvasPatternOrNullOrCanvasGradient::TraceUnion(JSTracer* trc)
    3031             : {
    3032           0 : }
    3033             : 
    3034             : OwningCanvasPatternOrNullOrCanvasGradient&
    3035           0 : OwningCanvasPatternOrNullOrCanvasGradient::operator=(const OwningCanvasPatternOrNullOrCanvasGradient& aOther)
    3036             : {
    3037           0 :   switch (aOther.mType) {
    3038             :     case eUninitialized: {
    3039           0 :       MOZ_ASSERT(mType == eUninitialized,
    3040             :                  "We need to destroy ourselves?");
    3041           0 :       break;
    3042             :     }
    3043             :     case eNull: {
    3044           0 :       MOZ_ASSERT(mType == eUninitialized);
    3045           0 :       mType = eNull;
    3046           0 :       break;
    3047             :     }
    3048             :     case eCanvasPattern: {
    3049           0 :       SetAsCanvasPattern() = aOther.GetAsCanvasPattern();
    3050           0 :       break;
    3051             :     }
    3052             :     case eCanvasGradient: {
    3053           0 :       SetAsCanvasGradient() = aOther.GetAsCanvasGradient();
    3054           0 :       break;
    3055             :     }
    3056             :   }
    3057           0 :   return *this;
    3058             : }
    3059             : 
    3060             : CustomEventInit&
    3061           0 : OwningCustomEventInitOrLong::RawSetAsCustomEventInit()
    3062             : {
    3063           0 :   if (mType == eCustomEventInit) {
    3064           0 :     return mValue.mCustomEventInit.Value();
    3065             :   }
    3066           0 :   MOZ_ASSERT(mType == eUninitialized);
    3067           0 :   mType = eCustomEventInit;
    3068           0 :   return mValue.mCustomEventInit.SetValue();
    3069             : }
    3070             : 
    3071             : CustomEventInit&
    3072           0 : OwningCustomEventInitOrLong::SetAsCustomEventInit()
    3073             : {
    3074           0 :   if (mType == eCustomEventInit) {
    3075           0 :     return mValue.mCustomEventInit.Value();
    3076             :   }
    3077           0 :   Uninit();
    3078           0 :   mType = eCustomEventInit;
    3079           0 :   return mValue.mCustomEventInit.SetValue();
    3080             : }
    3081             : 
    3082             : bool
    3083           0 : OwningCustomEventInitOrLong::TrySetToCustomEventInit(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    3084             : {
    3085           0 :   tryNext = false;
    3086             :   { // scope for memberSlot
    3087           0 :     CustomEventInit& memberSlot = RawSetAsCustomEventInit();
    3088           0 :     if (!IsConvertibleToDictionary(value)) {
    3089           0 :       DestroyCustomEventInit();
    3090           0 :       tryNext = true;
    3091           0 :       return true;
    3092             :     }
    3093           0 :     if (!memberSlot.Init(cx, value,  "Member of CustomEventInitOrLong", passedToJSImpl)) {
    3094           0 :       return false;
    3095             :     }
    3096             :   }
    3097           0 :   return true;
    3098             : }
    3099             : 
    3100             : void
    3101           0 : OwningCustomEventInitOrLong::DestroyCustomEventInit()
    3102             : {
    3103           0 :   MOZ_ASSERT(IsCustomEventInit(), "Wrong type!");
    3104           0 :   mValue.mCustomEventInit.Destroy();
    3105           0 :   mType = eUninitialized;
    3106           0 : }
    3107             : 
    3108             : 
    3109             : 
    3110             : 
    3111             : int32_t&
    3112           0 : OwningCustomEventInitOrLong::RawSetAsLong()
    3113             : {
    3114           0 :   if (mType == eLong) {
    3115           0 :     return mValue.mLong.Value();
    3116             :   }
    3117           0 :   MOZ_ASSERT(mType == eUninitialized);
    3118           0 :   mType = eLong;
    3119           0 :   return mValue.mLong.SetValue();
    3120             : }
    3121             : 
    3122             : int32_t&
    3123           0 : OwningCustomEventInitOrLong::SetAsLong()
    3124             : {
    3125           0 :   if (mType == eLong) {
    3126           0 :     return mValue.mLong.Value();
    3127             :   }
    3128           0 :   Uninit();
    3129           0 :   mType = eLong;
    3130           0 :   return mValue.mLong.SetValue();
    3131             : }
    3132             : 
    3133             : bool
    3134           0 : OwningCustomEventInitOrLong::TrySetToLong(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    3135             : {
    3136           0 :   tryNext = false;
    3137             :   { // scope for memberSlot
    3138           0 :     int32_t& memberSlot = RawSetAsLong();
    3139           0 :     if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
    3140           0 :       return false;
    3141             :     }
    3142             :   }
    3143           0 :   return true;
    3144             : }
    3145             : 
    3146             : void
    3147           0 : OwningCustomEventInitOrLong::DestroyLong()
    3148             : {
    3149           0 :   MOZ_ASSERT(IsLong(), "Wrong type!");
    3150           0 :   mValue.mLong.Destroy();
    3151           0 :   mType = eUninitialized;
    3152           0 : }
    3153             : 
    3154             : 
    3155             : 
    3156             : 
    3157             : void
    3158           0 : OwningCustomEventInitOrLong::Uninit()
    3159             : {
    3160           0 :   switch (mType) {
    3161             :     case eUninitialized: {
    3162           0 :       break;
    3163             :     }
    3164             :     case eCustomEventInit: {
    3165           0 :       DestroyCustomEventInit();
    3166           0 :       break;
    3167             :     }
    3168             :     case eLong: {
    3169           0 :       DestroyLong();
    3170           0 :       break;
    3171             :     }
    3172             :   }
    3173           0 : }
    3174             : 
    3175             : bool
    3176           0 : OwningCustomEventInitOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    3177             : {
    3178           0 :   switch (mType) {
    3179             :     case eUninitialized: {
    3180           0 :       return false;
    3181             :       break;
    3182             :     }
    3183             :     case eCustomEventInit: {
    3184           0 :       if (!mValue.mCustomEventInit.Value().ToObjectInternal(cx, rval)) {
    3185           0 :         return false;
    3186             :       }
    3187           0 :       return true;
    3188             :       break;
    3189             :     }
    3190             :     case eLong: {
    3191           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    3192           0 :       return true;
    3193             :       break;
    3194             :     }
    3195             :     default: {
    3196           0 :       return false;
    3197             :       break;
    3198             :     }
    3199             :   }
    3200             : 
    3201             :   return false;
    3202             : }
    3203             : 
    3204             : void
    3205           0 : OwningCustomEventInitOrLong::TraceUnion(JSTracer* trc)
    3206             : {
    3207           0 :   switch (mType) {
    3208             :     case eCustomEventInit: {
    3209           0 :       mValue.mCustomEventInit.Value().TraceDictionary(trc);
    3210           0 :       break;
    3211             :     }
    3212             :     default: {
    3213           0 :       break;
    3214             :     }
    3215             :   }
    3216           0 : }
    3217             : 
    3218             : double&
    3219           0 : OwningDoubleOrByteString::RawSetAsDouble()
    3220             : {
    3221           0 :   if (mType == eDouble) {
    3222           0 :     return mValue.mDouble.Value();
    3223             :   }
    3224           0 :   MOZ_ASSERT(mType == eUninitialized);
    3225           0 :   mType = eDouble;
    3226           0 :   return mValue.mDouble.SetValue();
    3227             : }
    3228             : 
    3229             : double&
    3230           0 : OwningDoubleOrByteString::SetAsDouble()
    3231             : {
    3232           0 :   if (mType == eDouble) {
    3233           0 :     return mValue.mDouble.Value();
    3234             :   }
    3235           0 :   Uninit();
    3236           0 :   mType = eDouble;
    3237           0 :   return mValue.mDouble.SetValue();
    3238             : }
    3239             : 
    3240             : bool
    3241           0 : OwningDoubleOrByteString::TrySetToDouble(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    3242             : {
    3243           0 :   tryNext = false;
    3244             :   { // scope for memberSlot
    3245           0 :     double& memberSlot = RawSetAsDouble();
    3246           0 :     if (!ValueToPrimitive<double, eDefault>(cx, value, &memberSlot)) {
    3247           0 :       return false;
    3248           0 :     } else if (!mozilla::IsFinite(memberSlot)) {
    3249           0 :       ThrowErrorMessage(cx, MSG_NOT_FINITE, "Member of DoubleOrByteString");
    3250           0 :       return false;
    3251             :     }
    3252             :   }
    3253           0 :   return true;
    3254             : }
    3255             : 
    3256             : void
    3257           0 : OwningDoubleOrByteString::DestroyDouble()
    3258             : {
    3259           0 :   MOZ_ASSERT(IsDouble(), "Wrong type!");
    3260           0 :   mValue.mDouble.Destroy();
    3261           0 :   mType = eUninitialized;
    3262           0 : }
    3263             : 
    3264             : 
    3265             : 
    3266             : 
    3267             : nsCString&
    3268           0 : OwningDoubleOrByteString::RawSetAsByteString()
    3269             : {
    3270           0 :   if (mType == eByteString) {
    3271           0 :     return mValue.mByteString.Value();
    3272             :   }
    3273           0 :   MOZ_ASSERT(mType == eUninitialized);
    3274           0 :   mType = eByteString;
    3275           0 :   return mValue.mByteString.SetValue();
    3276             : }
    3277             : 
    3278             : nsCString&
    3279           0 : OwningDoubleOrByteString::SetAsByteString()
    3280             : {
    3281           0 :   if (mType == eByteString) {
    3282           0 :     return mValue.mByteString.Value();
    3283             :   }
    3284           0 :   Uninit();
    3285           0 :   mType = eByteString;
    3286           0 :   return mValue.mByteString.SetValue();
    3287             : }
    3288             : 
    3289             : bool
    3290           0 : OwningDoubleOrByteString::TrySetToByteString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    3291             : {
    3292           0 :   tryNext = false;
    3293             :   { // scope for memberSlot
    3294           0 :     nsCString& memberSlot = RawSetAsByteString();
    3295           0 :     if (!ConvertJSValueToByteString(cx, value, false, memberSlot)) {
    3296           0 :       return false;
    3297             :     }
    3298             :   }
    3299           0 :   return true;
    3300             : }
    3301             : 
    3302             : 
    3303             : void
    3304           0 : OwningDoubleOrByteString::DestroyByteString()
    3305             : {
    3306           0 :   MOZ_ASSERT(IsByteString(), "Wrong type!");
    3307           0 :   mValue.mByteString.Destroy();
    3308           0 :   mType = eUninitialized;
    3309           0 : }
    3310             : 
    3311             : 
    3312             : 
    3313             : 
    3314             : void
    3315           0 : OwningDoubleOrByteString::Uninit()
    3316             : {
    3317           0 :   switch (mType) {
    3318             :     case eUninitialized: {
    3319           0 :       break;
    3320             :     }
    3321             :     case eDouble: {
    3322           0 :       DestroyDouble();
    3323           0 :       break;
    3324             :     }
    3325             :     case eByteString: {
    3326           0 :       DestroyByteString();
    3327           0 :       break;
    3328             :     }
    3329             :   }
    3330           0 : }
    3331             : 
    3332             : bool
    3333           0 : OwningDoubleOrByteString::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    3334             : {
    3335           0 :   switch (mType) {
    3336             :     case eUninitialized: {
    3337           0 :       return false;
    3338             :       break;
    3339             :     }
    3340             :     case eDouble: {
    3341           0 :       rval.set(JS_NumberValue(double(mValue.mDouble.Value())));
    3342           0 :       return true;
    3343             :       break;
    3344             :     }
    3345             :     case eByteString: {
    3346           0 :       if (!NonVoidByteStringToJsval(cx, mValue.mByteString.Value(), rval)) {
    3347           0 :         return false;
    3348             :       }
    3349           0 :       return true;
    3350             :       break;
    3351             :     }
    3352             :     default: {
    3353           0 :       return false;
    3354             :       break;
    3355             :     }
    3356             :   }
    3357             : 
    3358             :   return false;
    3359             : }
    3360             : 
    3361             : void
    3362           0 : OwningDoubleOrByteString::TraceUnion(JSTracer* trc)
    3363             : {
    3364           0 : }
    3365             : 
    3366             : OwningDoubleOrByteString&
    3367           0 : OwningDoubleOrByteString::operator=(const OwningDoubleOrByteString& aOther)
    3368             : {
    3369           0 :   switch (aOther.mType) {
    3370             :     case eUninitialized: {
    3371           0 :       MOZ_ASSERT(mType == eUninitialized,
    3372             :                  "We need to destroy ourselves?");
    3373           0 :       break;
    3374             :     }
    3375             :     case eDouble: {
    3376           0 :       SetAsDouble() = aOther.GetAsDouble();
    3377           0 :       break;
    3378             :     }
    3379             :     case eByteString: {
    3380           0 :       SetAsByteString() = aOther.GetAsByteString();
    3381           0 :       break;
    3382             :     }
    3383             :   }
    3384           0 :   return *this;
    3385             : }
    3386             : 
    3387             : double&
    3388           0 : OwningDoubleOrString::RawSetAsDouble()
    3389             : {
    3390           0 :   if (mType == eDouble) {
    3391           0 :     return mValue.mDouble.Value();
    3392             :   }
    3393           0 :   MOZ_ASSERT(mType == eUninitialized);
    3394           0 :   mType = eDouble;
    3395           0 :   return mValue.mDouble.SetValue();
    3396             : }
    3397             : 
    3398             : double&
    3399           0 : OwningDoubleOrString::SetAsDouble()
    3400             : {
    3401           0 :   if (mType == eDouble) {
    3402           0 :     return mValue.mDouble.Value();
    3403             :   }
    3404           0 :   Uninit();
    3405           0 :   mType = eDouble;
    3406           0 :   return mValue.mDouble.SetValue();
    3407             : }
    3408             : 
    3409             : bool
    3410           0 : OwningDoubleOrString::TrySetToDouble(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    3411             : {
    3412           0 :   tryNext = false;
    3413             :   { // scope for memberSlot
    3414           0 :     double& memberSlot = RawSetAsDouble();
    3415           0 :     if (!ValueToPrimitive<double, eDefault>(cx, value, &memberSlot)) {
    3416           0 :       return false;
    3417           0 :     } else if (!mozilla::IsFinite(memberSlot)) {
    3418           0 :       ThrowErrorMessage(cx, MSG_NOT_FINITE, "Member of DoubleOrString");
    3419           0 :       return false;
    3420             :     }
    3421             :   }
    3422           0 :   return true;
    3423             : }
    3424             : 
    3425             : void
    3426           0 : OwningDoubleOrString::DestroyDouble()
    3427             : {
    3428           0 :   MOZ_ASSERT(IsDouble(), "Wrong type!");
    3429           0 :   mValue.mDouble.Destroy();
    3430           0 :   mType = eUninitialized;
    3431           0 : }
    3432             : 
    3433             : 
    3434             : 
    3435             : 
    3436             : nsString&
    3437           0 : OwningDoubleOrString::RawSetAsString()
    3438             : {
    3439           0 :   if (mType == eString) {
    3440           0 :     return mValue.mString.Value();
    3441             :   }
    3442           0 :   MOZ_ASSERT(mType == eUninitialized);
    3443           0 :   mType = eString;
    3444           0 :   return mValue.mString.SetValue();
    3445             : }
    3446             : 
    3447             : nsString&
    3448           0 : OwningDoubleOrString::SetAsString()
    3449             : {
    3450           0 :   if (mType == eString) {
    3451           0 :     return mValue.mString.Value();
    3452             :   }
    3453           0 :   Uninit();
    3454           0 :   mType = eString;
    3455           0 :   return mValue.mString.SetValue();
    3456             : }
    3457             : 
    3458             : bool
    3459           0 : OwningDoubleOrString::TrySetToString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    3460             : {
    3461           0 :   tryNext = false;
    3462             :   { // scope for memberSlot
    3463           0 :     nsString& memberSlot = RawSetAsString();
    3464           0 :     if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
    3465           0 :       return false;
    3466             :     }
    3467             :   }
    3468           0 :   return true;
    3469             : }
    3470             : 
    3471             : 
    3472             : void
    3473           0 : OwningDoubleOrString::DestroyString()
    3474             : {
    3475           0 :   MOZ_ASSERT(IsString(), "Wrong type!");
    3476           0 :   mValue.mString.Destroy();
    3477           0 :   mType = eUninitialized;
    3478           0 : }
    3479             : 
    3480             : 
    3481             : 
    3482             : 
    3483             : void
    3484           0 : OwningDoubleOrString::Uninit()
    3485             : {
    3486           0 :   switch (mType) {
    3487             :     case eUninitialized: {
    3488           0 :       break;
    3489             :     }
    3490             :     case eDouble: {
    3491           0 :       DestroyDouble();
    3492           0 :       break;
    3493             :     }
    3494             :     case eString: {
    3495           0 :       DestroyString();
    3496           0 :       break;
    3497             :     }
    3498             :   }
    3499           0 : }
    3500             : 
    3501             : bool
    3502           0 : OwningDoubleOrString::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    3503             : {
    3504           0 :   switch (mType) {
    3505             :     case eUninitialized: {
    3506           0 :       return false;
    3507             :       break;
    3508             :     }
    3509             :     case eDouble: {
    3510           0 :       rval.set(JS_NumberValue(double(mValue.mDouble.Value())));
    3511           0 :       return true;
    3512             :       break;
    3513             :     }
    3514             :     case eString: {
    3515           0 :       if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) {
    3516           0 :         return false;
    3517             :       }
    3518           0 :       return true;
    3519             :       break;
    3520             :     }
    3521             :     default: {
    3522           0 :       return false;
    3523             :       break;
    3524             :     }
    3525             :   }
    3526             : 
    3527             :   return false;
    3528             : }
    3529             : 
    3530             : void
    3531           0 : OwningDoubleOrString::TraceUnion(JSTracer* trc)
    3532             : {
    3533           0 : }
    3534             : 
    3535             : OwningDoubleOrString&
    3536           0 : OwningDoubleOrString::operator=(const OwningDoubleOrString& aOther)
    3537             : {
    3538           0 :   switch (aOther.mType) {
    3539             :     case eUninitialized: {
    3540           0 :       MOZ_ASSERT(mType == eUninitialized,
    3541             :                  "We need to destroy ourselves?");
    3542           0 :       break;
    3543             :     }
    3544             :     case eDouble: {
    3545           0 :       SetAsDouble() = aOther.GetAsDouble();
    3546           0 :       break;
    3547             :     }
    3548             :     case eString: {
    3549           0 :       SetAsString() = aOther.GetAsString();
    3550           0 :       break;
    3551             :     }
    3552             :   }
    3553           0 :   return *this;
    3554             : }
    3555             : 
    3556             : double&
    3557           0 : OwningDoubleOrSupportedType::RawSetAsDouble()
    3558             : {
    3559           0 :   if (mType == eDouble) {
    3560           0 :     return mValue.mDouble.Value();
    3561             :   }
    3562           0 :   MOZ_ASSERT(mType == eUninitialized);
    3563           0 :   mType = eDouble;
    3564           0 :   return mValue.mDouble.SetValue();
    3565             : }
    3566             : 
    3567             : double&
    3568           0 : OwningDoubleOrSupportedType::SetAsDouble()
    3569             : {
    3570           0 :   if (mType == eDouble) {
    3571           0 :     return mValue.mDouble.Value();
    3572             :   }
    3573           0 :   Uninit();
    3574           0 :   mType = eDouble;
    3575           0 :   return mValue.mDouble.SetValue();
    3576             : }
    3577             : 
    3578             : bool
    3579           0 : OwningDoubleOrSupportedType::TrySetToDouble(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    3580             : {
    3581           0 :   tryNext = false;
    3582             :   { // scope for memberSlot
    3583           0 :     double& memberSlot = RawSetAsDouble();
    3584           0 :     if (!ValueToPrimitive<double, eDefault>(cx, value, &memberSlot)) {
    3585           0 :       return false;
    3586           0 :     } else if (!mozilla::IsFinite(memberSlot)) {
    3587           0 :       ThrowErrorMessage(cx, MSG_NOT_FINITE, "Member of DoubleOrSupportedType");
    3588           0 :       return false;
    3589             :     }
    3590             :   }
    3591           0 :   return true;
    3592             : }
    3593             : 
    3594             : void
    3595           0 : OwningDoubleOrSupportedType::DestroyDouble()
    3596             : {
    3597           0 :   MOZ_ASSERT(IsDouble(), "Wrong type!");
    3598           0 :   mValue.mDouble.Destroy();
    3599           0 :   mType = eUninitialized;
    3600           0 : }
    3601             : 
    3602             : 
    3603             : 
    3604             : 
    3605             : SupportedType&
    3606           0 : OwningDoubleOrSupportedType::RawSetAsSupportedType()
    3607             : {
    3608           0 :   if (mType == eSupportedType) {
    3609           0 :     return mValue.mSupportedType.Value();
    3610             :   }
    3611           0 :   MOZ_ASSERT(mType == eUninitialized);
    3612           0 :   mType = eSupportedType;
    3613           0 :   return mValue.mSupportedType.SetValue();
    3614             : }
    3615             : 
    3616             : SupportedType&
    3617           0 : OwningDoubleOrSupportedType::SetAsSupportedType()
    3618             : {
    3619           0 :   if (mType == eSupportedType) {
    3620           0 :     return mValue.mSupportedType.Value();
    3621             :   }
    3622           0 :   Uninit();
    3623           0 :   mType = eSupportedType;
    3624           0 :   return mValue.mSupportedType.SetValue();
    3625             : }
    3626             : 
    3627             : bool
    3628           0 : OwningDoubleOrSupportedType::TrySetToSupportedType(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    3629             : {
    3630           0 :   tryNext = false;
    3631             :   { // scope for memberSlot
    3632           0 :     SupportedType& memberSlot = RawSetAsSupportedType();
    3633             :     {
    3634             :       int index;
    3635           0 :       if (!FindEnumStringIndex<true>(cx, value, SupportedTypeValues::strings, "SupportedType", "Member of DoubleOrSupportedType", &index)) {
    3636           0 :         return false;
    3637             :       }
    3638           0 :       MOZ_ASSERT(index >= 0);
    3639           0 :       memberSlot = static_cast<SupportedType>(index);
    3640             :     }
    3641             :   }
    3642           0 :   return true;
    3643             : }
    3644             : 
    3645             : void
    3646           0 : OwningDoubleOrSupportedType::DestroySupportedType()
    3647             : {
    3648           0 :   MOZ_ASSERT(IsSupportedType(), "Wrong type!");
    3649           0 :   mValue.mSupportedType.Destroy();
    3650           0 :   mType = eUninitialized;
    3651           0 : }
    3652             : 
    3653             : 
    3654             : 
    3655             : 
    3656             : void
    3657           0 : OwningDoubleOrSupportedType::Uninit()
    3658             : {
    3659           0 :   switch (mType) {
    3660             :     case eUninitialized: {
    3661           0 :       break;
    3662             :     }
    3663             :     case eDouble: {
    3664           0 :       DestroyDouble();
    3665           0 :       break;
    3666             :     }
    3667             :     case eSupportedType: {
    3668           0 :       DestroySupportedType();
    3669           0 :       break;
    3670             :     }
    3671             :   }
    3672           0 : }
    3673             : 
    3674             : bool
    3675           0 : OwningDoubleOrSupportedType::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    3676             : {
    3677           0 :   switch (mType) {
    3678             :     case eUninitialized: {
    3679           0 :       return false;
    3680             :       break;
    3681             :     }
    3682             :     case eDouble: {
    3683           0 :       rval.set(JS_NumberValue(double(mValue.mDouble.Value())));
    3684           0 :       return true;
    3685             :       break;
    3686             :     }
    3687             :     case eSupportedType: {
    3688           0 :       if (!ToJSValue(cx, mValue.mSupportedType.Value(), rval)) {
    3689           0 :         return false;
    3690             :       }
    3691           0 :       return true;
    3692             :       break;
    3693             :     }
    3694             :     default: {
    3695           0 :       return false;
    3696             :       break;
    3697             :     }
    3698             :   }
    3699             : 
    3700             :   return false;
    3701             : }
    3702             : 
    3703             : void
    3704           0 : OwningDoubleOrSupportedType::TraceUnion(JSTracer* trc)
    3705             : {
    3706           0 : }
    3707             : 
    3708             : OwningDoubleOrSupportedType&
    3709           0 : OwningDoubleOrSupportedType::operator=(const OwningDoubleOrSupportedType& aOther)
    3710             : {
    3711           0 :   switch (aOther.mType) {
    3712             :     case eUninitialized: {
    3713           0 :       MOZ_ASSERT(mType == eUninitialized,
    3714             :                  "We need to destroy ourselves?");
    3715           0 :       break;
    3716             :     }
    3717             :     case eDouble: {
    3718           0 :       SetAsDouble() = aOther.GetAsDouble();
    3719           0 :       break;
    3720             :     }
    3721             :     case eSupportedType: {
    3722           0 :       SetAsSupportedType() = aOther.GetAsSupportedType();
    3723           0 :       break;
    3724             :     }
    3725             :   }
    3726           0 :   return *this;
    3727             : }
    3728             : 
    3729             : double&
    3730           0 : OwningDoubleOrUSVString::RawSetAsDouble()
    3731             : {
    3732           0 :   if (mType == eDouble) {
    3733           0 :     return mValue.mDouble.Value();
    3734             :   }
    3735           0 :   MOZ_ASSERT(mType == eUninitialized);
    3736           0 :   mType = eDouble;
    3737           0 :   return mValue.mDouble.SetValue();
    3738             : }
    3739             : 
    3740             : double&
    3741           0 : OwningDoubleOrUSVString::SetAsDouble()
    3742             : {
    3743           0 :   if (mType == eDouble) {
    3744           0 :     return mValue.mDouble.Value();
    3745             :   }
    3746           0 :   Uninit();
    3747           0 :   mType = eDouble;
    3748           0 :   return mValue.mDouble.SetValue();
    3749             : }
    3750             : 
    3751             : bool
    3752           0 : OwningDoubleOrUSVString::TrySetToDouble(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    3753             : {
    3754           0 :   tryNext = false;
    3755             :   { // scope for memberSlot
    3756           0 :     double& memberSlot = RawSetAsDouble();
    3757           0 :     if (!ValueToPrimitive<double, eDefault>(cx, value, &memberSlot)) {
    3758           0 :       return false;
    3759           0 :     } else if (!mozilla::IsFinite(memberSlot)) {
    3760           0 :       ThrowErrorMessage(cx, MSG_NOT_FINITE, "Member of DoubleOrUSVString");
    3761           0 :       return false;
    3762             :     }
    3763             :   }
    3764           0 :   return true;
    3765             : }
    3766             : 
    3767             : void
    3768           0 : OwningDoubleOrUSVString::DestroyDouble()
    3769             : {
    3770           0 :   MOZ_ASSERT(IsDouble(), "Wrong type!");
    3771           0 :   mValue.mDouble.Destroy();
    3772           0 :   mType = eUninitialized;
    3773           0 : }
    3774             : 
    3775             : 
    3776             : 
    3777             : 
    3778             : nsString&
    3779           0 : OwningDoubleOrUSVString::RawSetAsUSVString()
    3780             : {
    3781           0 :   if (mType == eUSVString) {
    3782           0 :     return mValue.mUSVString.Value();
    3783             :   }
    3784           0 :   MOZ_ASSERT(mType == eUninitialized);
    3785           0 :   mType = eUSVString;
    3786           0 :   return mValue.mUSVString.SetValue();
    3787             : }
    3788             : 
    3789             : nsString&
    3790           0 : OwningDoubleOrUSVString::SetAsUSVString()
    3791             : {
    3792           0 :   if (mType == eUSVString) {
    3793           0 :     return mValue.mUSVString.Value();
    3794             :   }
    3795           0 :   Uninit();
    3796           0 :   mType = eUSVString;
    3797           0 :   return mValue.mUSVString.SetValue();
    3798             : }
    3799             : 
    3800             : bool
    3801           0 : OwningDoubleOrUSVString::TrySetToUSVString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    3802             : {
    3803           0 :   tryNext = false;
    3804             :   { // scope for memberSlot
    3805           0 :     nsString& memberSlot = RawSetAsUSVString();
    3806           0 :     if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
    3807           0 :       return false;
    3808             :     }
    3809           0 :     NormalizeUSVString(memberSlot);
    3810             :   }
    3811           0 :   return true;
    3812             : }
    3813             : 
    3814             : 
    3815             : void
    3816           0 : OwningDoubleOrUSVString::DestroyUSVString()
    3817             : {
    3818           0 :   MOZ_ASSERT(IsUSVString(), "Wrong type!");
    3819           0 :   mValue.mUSVString.Destroy();
    3820           0 :   mType = eUninitialized;
    3821           0 : }
    3822             : 
    3823             : 
    3824             : 
    3825             : 
    3826             : void
    3827           0 : OwningDoubleOrUSVString::Uninit()
    3828             : {
    3829           0 :   switch (mType) {
    3830             :     case eUninitialized: {
    3831           0 :       break;
    3832             :     }
    3833             :     case eDouble: {
    3834           0 :       DestroyDouble();
    3835           0 :       break;
    3836             :     }
    3837             :     case eUSVString: {
    3838           0 :       DestroyUSVString();
    3839           0 :       break;
    3840             :     }
    3841             :   }
    3842           0 : }
    3843             : 
    3844             : bool
    3845           0 : OwningDoubleOrUSVString::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    3846             : {
    3847           0 :   switch (mType) {
    3848             :     case eUninitialized: {
    3849           0 :       return false;
    3850             :       break;
    3851             :     }
    3852             :     case eDouble: {
    3853           0 :       rval.set(JS_NumberValue(double(mValue.mDouble.Value())));
    3854           0 :       return true;
    3855             :       break;
    3856             :     }
    3857             :     case eUSVString: {
    3858           0 :       if (!xpc::NonVoidStringToJsval(cx, mValue.mUSVString.Value(), rval)) {
    3859           0 :         return false;
    3860             :       }
    3861           0 :       return true;
    3862             :       break;
    3863             :     }
    3864             :     default: {
    3865           0 :       return false;
    3866             :       break;
    3867             :     }
    3868             :   }
    3869             : 
    3870             :   return false;
    3871             : }
    3872             : 
    3873             : void
    3874           0 : OwningDoubleOrUSVString::TraceUnion(JSTracer* trc)
    3875             : {
    3876           0 : }
    3877             : 
    3878             : OwningDoubleOrUSVString&
    3879           0 : OwningDoubleOrUSVString::operator=(const OwningDoubleOrUSVString& aOther)
    3880             : {
    3881           0 :   switch (aOther.mType) {
    3882             :     case eUninitialized: {
    3883           0 :       MOZ_ASSERT(mType == eUninitialized,
    3884             :                  "We need to destroy ourselves?");
    3885           0 :       break;
    3886             :     }
    3887             :     case eDouble: {
    3888           0 :       SetAsDouble() = aOther.GetAsDouble();
    3889           0 :       break;
    3890             :     }
    3891             :     case eUSVString: {
    3892           0 :       SetAsUSVString() = aOther.GetAsUSVString();
    3893           0 :       break;
    3894             :     }
    3895             :   }
    3896           0 :   return *this;
    3897             : }
    3898             : 
    3899             : OwningNonNull<EventHandlerNonNull>&
    3900           0 : OwningEventHandlerNonNullOrNullOrLong::RawSetAsEventHandlerNonNull()
    3901             : {
    3902           0 :   if (mType == eEventHandlerNonNull) {
    3903           0 :     return mValue.mEventHandlerNonNull.Value();
    3904             :   }
    3905           0 :   MOZ_ASSERT(mType == eUninitialized);
    3906           0 :   mType = eEventHandlerNonNull;
    3907           0 :   return mValue.mEventHandlerNonNull.SetValue();
    3908             : }
    3909             : 
    3910             : OwningNonNull<EventHandlerNonNull>&
    3911           0 : OwningEventHandlerNonNullOrNullOrLong::SetAsEventHandlerNonNull()
    3912             : {
    3913           0 :   if (mType == eEventHandlerNonNull) {
    3914           0 :     return mValue.mEventHandlerNonNull.Value();
    3915             :   }
    3916           0 :   Uninit();
    3917           0 :   mType = eEventHandlerNonNull;
    3918           0 :   return mValue.mEventHandlerNonNull.SetValue();
    3919             : }
    3920             : 
    3921             : bool
    3922           0 : OwningEventHandlerNonNullOrNullOrLong::TrySetToEventHandlerNonNull(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    3923             : {
    3924           0 :   tryNext = false;
    3925             :   { // scope for memberSlot
    3926           0 :     OwningNonNull<EventHandlerNonNull>& memberSlot = RawSetAsEventHandlerNonNull();
    3927           0 :     if (JS::IsCallable(&value.toObject())) {
    3928             :     { // scope for tempRoot
    3929           0 :       JS::Rooted<JSObject*> tempRoot(cx, &value.toObject());
    3930           0 :       memberSlot = new EventHandlerNonNull(cx, tempRoot, GetIncumbentGlobal());
    3931             :     }
    3932             :     } else {
    3933           0 :       DestroyEventHandlerNonNull();
    3934           0 :       tryNext = true;
    3935           0 :       return true;
    3936             :     }
    3937             :   }
    3938           0 :   return true;
    3939             : }
    3940             : 
    3941             : void
    3942           0 : OwningEventHandlerNonNullOrNullOrLong::DestroyEventHandlerNonNull()
    3943             : {
    3944           0 :   MOZ_ASSERT(IsEventHandlerNonNull(), "Wrong type!");
    3945           0 :   mValue.mEventHandlerNonNull.Destroy();
    3946           0 :   mType = eUninitialized;
    3947           0 : }
    3948             : 
    3949             : 
    3950             : 
    3951             : 
    3952             : int32_t&
    3953           0 : OwningEventHandlerNonNullOrNullOrLong::RawSetAsLong()
    3954             : {
    3955           0 :   if (mType == eLong) {
    3956           0 :     return mValue.mLong.Value();
    3957             :   }
    3958           0 :   MOZ_ASSERT(mType == eUninitialized);
    3959           0 :   mType = eLong;
    3960           0 :   return mValue.mLong.SetValue();
    3961             : }
    3962             : 
    3963             : int32_t&
    3964           0 : OwningEventHandlerNonNullOrNullOrLong::SetAsLong()
    3965             : {
    3966           0 :   if (mType == eLong) {
    3967           0 :     return mValue.mLong.Value();
    3968             :   }
    3969           0 :   Uninit();
    3970           0 :   mType = eLong;
    3971           0 :   return mValue.mLong.SetValue();
    3972             : }
    3973             : 
    3974             : bool
    3975           0 : OwningEventHandlerNonNullOrNullOrLong::TrySetToLong(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    3976             : {
    3977           0 :   tryNext = false;
    3978             :   { // scope for memberSlot
    3979           0 :     int32_t& memberSlot = RawSetAsLong();
    3980           0 :     if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
    3981           0 :       return false;
    3982             :     }
    3983             :   }
    3984           0 :   return true;
    3985             : }
    3986             : 
    3987             : void
    3988           0 : OwningEventHandlerNonNullOrNullOrLong::DestroyLong()
    3989             : {
    3990           0 :   MOZ_ASSERT(IsLong(), "Wrong type!");
    3991           0 :   mValue.mLong.Destroy();
    3992           0 :   mType = eUninitialized;
    3993           0 : }
    3994             : 
    3995             : 
    3996             : 
    3997             : 
    3998             : void
    3999           0 : OwningEventHandlerNonNullOrNullOrLong::Uninit()
    4000             : {
    4001           0 :   switch (mType) {
    4002             :     case eUninitialized: {
    4003           0 :       break;
    4004             :     }
    4005             :     case eNull: {
    4006           0 :       break;
    4007             :     }
    4008             :     case eEventHandlerNonNull: {
    4009           0 :       DestroyEventHandlerNonNull();
    4010           0 :       break;
    4011             :     }
    4012             :     case eLong: {
    4013           0 :       DestroyLong();
    4014           0 :       break;
    4015             :     }
    4016             :   }
    4017           0 : }
    4018             : 
    4019             : bool
    4020           0 : OwningEventHandlerNonNullOrNullOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    4021             : {
    4022           0 :   switch (mType) {
    4023             :     case eUninitialized: {
    4024           0 :       return false;
    4025             :       break;
    4026             :     }
    4027             :     case eNull: {
    4028           0 :       rval.setNull();
    4029           0 :       return true;
    4030             :       break;
    4031             :     }
    4032             :     case eEventHandlerNonNull: {
    4033           0 :       rval.setObjectOrNull(GetCallbackFromCallbackObject(mValue.mEventHandlerNonNull.Value()));
    4034           0 :       if (!MaybeWrapObjectValue(cx, rval)) {
    4035           0 :         return false;
    4036             :       }
    4037           0 :       return true;
    4038             :       break;
    4039             :     }
    4040             :     case eLong: {
    4041           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    4042           0 :       return true;
    4043             :       break;
    4044             :     }
    4045             :     default: {
    4046           0 :       return false;
    4047             :       break;
    4048             :     }
    4049             :   }
    4050             : 
    4051             :   return false;
    4052             : }
    4053             : 
    4054             : void
    4055           0 : OwningEventHandlerNonNullOrNullOrLong::TraceUnion(JSTracer* trc)
    4056             : {
    4057           0 : }
    4058             : 
    4059             : EventInit&
    4060           0 : OwningEventInitOrLong::RawSetAsEventInit()
    4061             : {
    4062           0 :   if (mType == eEventInit) {
    4063           0 :     return mValue.mEventInit.Value();
    4064             :   }
    4065           0 :   MOZ_ASSERT(mType == eUninitialized);
    4066           0 :   mType = eEventInit;
    4067           0 :   return mValue.mEventInit.SetValue();
    4068             : }
    4069             : 
    4070             : EventInit&
    4071           0 : OwningEventInitOrLong::SetAsEventInit()
    4072             : {
    4073           0 :   if (mType == eEventInit) {
    4074           0 :     return mValue.mEventInit.Value();
    4075             :   }
    4076           0 :   Uninit();
    4077           0 :   mType = eEventInit;
    4078           0 :   return mValue.mEventInit.SetValue();
    4079             : }
    4080             : 
    4081             : bool
    4082           0 : OwningEventInitOrLong::TrySetToEventInit(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    4083             : {
    4084           0 :   tryNext = false;
    4085             :   { // scope for memberSlot
    4086           0 :     EventInit& memberSlot = RawSetAsEventInit();
    4087           0 :     if (!IsConvertibleToDictionary(value)) {
    4088           0 :       DestroyEventInit();
    4089           0 :       tryNext = true;
    4090           0 :       return true;
    4091             :     }
    4092           0 :     if (!memberSlot.Init(cx, value,  "Member of EventInitOrLong", passedToJSImpl)) {
    4093           0 :       return false;
    4094             :     }
    4095             :   }
    4096           0 :   return true;
    4097             : }
    4098             : 
    4099             : void
    4100           0 : OwningEventInitOrLong::DestroyEventInit()
    4101             : {
    4102           0 :   MOZ_ASSERT(IsEventInit(), "Wrong type!");
    4103           0 :   mValue.mEventInit.Destroy();
    4104           0 :   mType = eUninitialized;
    4105           0 : }
    4106             : 
    4107             : 
    4108             : 
    4109             : 
    4110             : int32_t&
    4111           0 : OwningEventInitOrLong::RawSetAsLong()
    4112             : {
    4113           0 :   if (mType == eLong) {
    4114           0 :     return mValue.mLong.Value();
    4115             :   }
    4116           0 :   MOZ_ASSERT(mType == eUninitialized);
    4117           0 :   mType = eLong;
    4118           0 :   return mValue.mLong.SetValue();
    4119             : }
    4120             : 
    4121             : int32_t&
    4122           0 : OwningEventInitOrLong::SetAsLong()
    4123             : {
    4124           0 :   if (mType == eLong) {
    4125           0 :     return mValue.mLong.Value();
    4126             :   }
    4127           0 :   Uninit();
    4128           0 :   mType = eLong;
    4129           0 :   return mValue.mLong.SetValue();
    4130             : }
    4131             : 
    4132             : bool
    4133           0 : OwningEventInitOrLong::TrySetToLong(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    4134             : {
    4135           0 :   tryNext = false;
    4136             :   { // scope for memberSlot
    4137           0 :     int32_t& memberSlot = RawSetAsLong();
    4138           0 :     if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
    4139           0 :       return false;
    4140             :     }
    4141             :   }
    4142           0 :   return true;
    4143             : }
    4144             : 
    4145             : void
    4146           0 : OwningEventInitOrLong::DestroyLong()
    4147             : {
    4148           0 :   MOZ_ASSERT(IsLong(), "Wrong type!");
    4149           0 :   mValue.mLong.Destroy();
    4150           0 :   mType = eUninitialized;
    4151           0 : }
    4152             : 
    4153             : 
    4154             : 
    4155             : 
    4156             : void
    4157           0 : OwningEventInitOrLong::Uninit()
    4158             : {
    4159           0 :   switch (mType) {
    4160             :     case eUninitialized: {
    4161           0 :       break;
    4162             :     }
    4163             :     case eEventInit: {
    4164           0 :       DestroyEventInit();
    4165           0 :       break;
    4166             :     }
    4167             :     case eLong: {
    4168           0 :       DestroyLong();
    4169           0 :       break;
    4170             :     }
    4171             :   }
    4172           0 : }
    4173             : 
    4174             : bool
    4175           0 : OwningEventInitOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    4176             : {
    4177           0 :   switch (mType) {
    4178             :     case eUninitialized: {
    4179           0 :       return false;
    4180             :       break;
    4181             :     }
    4182             :     case eEventInit: {
    4183           0 :       if (!mValue.mEventInit.Value().ToObjectInternal(cx, rval)) {
    4184           0 :         return false;
    4185             :       }
    4186           0 :       return true;
    4187             :       break;
    4188             :     }
    4189             :     case eLong: {
    4190           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    4191           0 :       return true;
    4192             :       break;
    4193             :     }
    4194             :     default: {
    4195           0 :       return false;
    4196             :       break;
    4197             :     }
    4198             :   }
    4199             : 
    4200             :   return false;
    4201             : }
    4202             : 
    4203             : void
    4204           0 : OwningEventInitOrLong::TraceUnion(JSTracer* trc)
    4205             : {
    4206           0 : }
    4207             : 
    4208             : OwningEventInitOrLong&
    4209           0 : OwningEventInitOrLong::operator=(const OwningEventInitOrLong& aOther)
    4210             : {
    4211           0 :   switch (aOther.mType) {
    4212             :     case eUninitialized: {
    4213           0 :       MOZ_ASSERT(mType == eUninitialized,
    4214             :                  "We need to destroy ourselves?");
    4215           0 :       break;
    4216             :     }
    4217             :     case eEventInit: {
    4218           0 :       SetAsEventInit() = aOther.GetAsEventInit();
    4219           0 :       break;
    4220             :     }
    4221             :     case eLong: {
    4222           0 :       SetAsLong() = aOther.GetAsLong();
    4223           0 :       break;
    4224             :     }
    4225             :   }
    4226           0 :   return *this;
    4227             : }
    4228             : 
    4229             : EventInit&
    4230           0 : OwningEventInitOrStringSequence::RawSetAsEventInit()
    4231             : {
    4232           0 :   if (mType == eEventInit) {
    4233           0 :     return mValue.mEventInit.Value();
    4234             :   }
    4235           0 :   MOZ_ASSERT(mType == eUninitialized);
    4236           0 :   mType = eEventInit;
    4237           0 :   return mValue.mEventInit.SetValue();
    4238             : }
    4239             : 
    4240             : EventInit&
    4241           0 : OwningEventInitOrStringSequence::SetAsEventInit()
    4242             : {
    4243           0 :   if (mType == eEventInit) {
    4244           0 :     return mValue.mEventInit.Value();
    4245             :   }
    4246           0 :   Uninit();
    4247           0 :   mType = eEventInit;
    4248           0 :   return mValue.mEventInit.SetValue();
    4249             : }
    4250             : 
    4251             : bool
    4252           0 : OwningEventInitOrStringSequence::TrySetToEventInit(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    4253             : {
    4254           0 :   tryNext = false;
    4255             :   { // scope for memberSlot
    4256           0 :     EventInit& memberSlot = RawSetAsEventInit();
    4257           0 :     if (!IsConvertibleToDictionary(value)) {
    4258           0 :       DestroyEventInit();
    4259           0 :       tryNext = true;
    4260           0 :       return true;
    4261             :     }
    4262           0 :     if (!memberSlot.Init(cx, value,  "Member of EventInitOrStringSequence", passedToJSImpl)) {
    4263           0 :       return false;
    4264             :     }
    4265             :   }
    4266           0 :   return true;
    4267             : }
    4268             : 
    4269             : void
    4270           0 : OwningEventInitOrStringSequence::DestroyEventInit()
    4271             : {
    4272           0 :   MOZ_ASSERT(IsEventInit(), "Wrong type!");
    4273           0 :   mValue.mEventInit.Destroy();
    4274           0 :   mType = eUninitialized;
    4275           0 : }
    4276             : 
    4277             : 
    4278             : 
    4279             : 
    4280             : Sequence<nsString>&
    4281           0 : OwningEventInitOrStringSequence::RawSetAsStringSequence()
    4282             : {
    4283           0 :   if (mType == eStringSequence) {
    4284           0 :     return mValue.mStringSequence.Value();
    4285             :   }
    4286           0 :   MOZ_ASSERT(mType == eUninitialized);
    4287           0 :   mType = eStringSequence;
    4288           0 :   return mValue.mStringSequence.SetValue();
    4289             : }
    4290             : 
    4291             : Sequence<nsString>&
    4292           0 : OwningEventInitOrStringSequence::SetAsStringSequence()
    4293             : {
    4294           0 :   if (mType == eStringSequence) {
    4295           0 :     return mValue.mStringSequence.Value();
    4296             :   }
    4297           0 :   Uninit();
    4298           0 :   mType = eStringSequence;
    4299           0 :   return mValue.mStringSequence.SetValue();
    4300             : }
    4301             : 
    4302             : bool
    4303           0 : OwningEventInitOrStringSequence::TrySetToStringSequence(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    4304             : {
    4305           0 :   tryNext = false;
    4306             :   { // scope for memberSlot
    4307           0 :     Sequence<nsString>& memberSlot = RawSetAsStringSequence();
    4308           0 :     JS::ForOfIterator iter(cx);
    4309           0 :     if (!iter.init(value, JS::ForOfIterator::AllowNonIterable)) {
    4310           0 :       return false;
    4311             :     }
    4312           0 :     if (!iter.valueIsIterable()) {
    4313           0 :       DestroyStringSequence();
    4314           0 :       tryNext = true;
    4315           0 :       return true;
    4316             :     }
    4317           0 :     Sequence<nsString> &arr = memberSlot;
    4318           0 :     JS::Rooted<JS::Value> temp(cx);
    4319             :     while (true) {
    4320             :       bool done;
    4321           0 :       if (!iter.next(&temp, &done)) {
    4322           0 :         return false;
    4323             :       }
    4324           0 :       if (done) {
    4325           0 :         break;
    4326             :       }
    4327           0 :       nsString* slotPtr = arr.AppendElement(mozilla::fallible);
    4328           0 :       if (!slotPtr) {
    4329           0 :         JS_ReportOutOfMemory(cx);
    4330           0 :         return false;
    4331             :       }
    4332           0 :       nsString& slot = *slotPtr;
    4333           0 :       if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
    4334           0 :         return false;
    4335             :       }
    4336           0 :     }
    4337             :   }
    4338           0 :   return true;
    4339             : }
    4340             : 
    4341             : void
    4342           0 : OwningEventInitOrStringSequence::DestroyStringSequence()
    4343             : {
    4344           0 :   MOZ_ASSERT(IsStringSequence(), "Wrong type!");
    4345           0 :   mValue.mStringSequence.Destroy();
    4346           0 :   mType = eUninitialized;
    4347           0 : }
    4348             : 
    4349             : 
    4350             : 
    4351             : 
    4352             : void
    4353           0 : OwningEventInitOrStringSequence::Uninit()
    4354             : {
    4355           0 :   switch (mType) {
    4356             :     case eUninitialized: {
    4357           0 :       break;
    4358             :     }
    4359             :     case eEventInit: {
    4360           0 :       DestroyEventInit();
    4361           0 :       break;
    4362             :     }
    4363             :     case eStringSequence: {
    4364           0 :       DestroyStringSequence();
    4365           0 :       break;
    4366             :     }
    4367             :   }
    4368           0 : }
    4369             : 
    4370             : bool
    4371           0 : OwningEventInitOrStringSequence::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    4372             : {
    4373           0 :   switch (mType) {
    4374             :     case eUninitialized: {
    4375           0 :       return false;
    4376             :       break;
    4377             :     }
    4378             :     case eEventInit: {
    4379           0 :       if (!mValue.mEventInit.Value().ToObjectInternal(cx, rval)) {
    4380           0 :         return false;
    4381             :       }
    4382           0 :       return true;
    4383             :       break;
    4384             :     }
    4385             :     case eStringSequence: {
    4386             : 
    4387           0 :       uint32_t length = mValue.mStringSequence.Value().Length();
    4388           0 :       JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
    4389           0 :       if (!returnArray) {
    4390           0 :         return false;
    4391             :       }
    4392             :       // Scope for 'tmp'
    4393             :       {
    4394           0 :         JS::Rooted<JS::Value> tmp(cx);
    4395           0 :         for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
    4396             :           // Control block to let us common up the JS_DefineElement calls when there
    4397             :           // are different ways to succeed at wrapping the object.
    4398             :           do {
    4399           0 :             if (!xpc::NonVoidStringToJsval(cx, mValue.mStringSequence.Value()[sequenceIdx0], &tmp)) {
    4400           0 :               return false;
    4401             :             }
    4402           0 :             break;
    4403             :           } while (0);
    4404           0 :           if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
    4405             :                                 JSPROP_ENUMERATE)) {
    4406           0 :             return false;
    4407             :           }
    4408             :         }
    4409             :       }
    4410           0 :       rval.setObject(*returnArray);
    4411           0 :       return true;
    4412             :       break;
    4413             :     }
    4414             :     default: {
    4415           0 :       return false;
    4416             :       break;
    4417             :     }
    4418             :   }
    4419             : 
    4420             :   return false;
    4421             : }
    4422             : 
    4423             : void
    4424           0 : OwningEventInitOrStringSequence::TraceUnion(JSTracer* trc)
    4425             : {
    4426           0 : }
    4427             : 
    4428             : OwningEventInitOrStringSequence&
    4429           0 : OwningEventInitOrStringSequence::operator=(const OwningEventInitOrStringSequence& aOther)
    4430             : {
    4431           0 :   switch (aOther.mType) {
    4432             :     case eUninitialized: {
    4433           0 :       MOZ_ASSERT(mType == eUninitialized,
    4434             :                  "We need to destroy ourselves?");
    4435           0 :       break;
    4436             :     }
    4437             :     case eEventInit: {
    4438           0 :       SetAsEventInit() = aOther.GetAsEventInit();
    4439           0 :       break;
    4440             :     }
    4441             :     case eStringSequence: {
    4442           0 :       SetAsStringSequence() = aOther.GetAsStringSequence();
    4443           0 :       break;
    4444             :     }
    4445             :   }
    4446           0 :   return *this;
    4447             : }
    4448             : 
    4449             : OwningNonNull<mozilla::dom::File>&
    4450           0 : OwningFileOrDirectory::RawSetAsFile()
    4451             : {
    4452           0 :   if (mType == eFile) {
    4453           0 :     return mValue.mFile.Value();
    4454             :   }
    4455           0 :   MOZ_ASSERT(mType == eUninitialized);
    4456           0 :   mType = eFile;
    4457           0 :   return mValue.mFile.SetValue();
    4458             : }
    4459             : 
    4460             : OwningNonNull<mozilla::dom::File>&
    4461           0 : OwningFileOrDirectory::SetAsFile()
    4462             : {
    4463           0 :   if (mType == eFile) {
    4464           0 :     return mValue.mFile.Value();
    4465             :   }
    4466           0 :   Uninit();
    4467           0 :   mType = eFile;
    4468           0 :   return mValue.mFile.SetValue();
    4469             : }
    4470             : 
    4471             : bool
    4472           0 : OwningFileOrDirectory::TrySetToFile(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    4473             : {
    4474           0 :   tryNext = false;
    4475             :   { // scope for memberSlot
    4476           0 :     OwningNonNull<mozilla::dom::File>& memberSlot = RawSetAsFile();
    4477             :     static_assert(IsRefcounted<mozilla::dom::File>::value, "We can only store refcounted classes.");{
    4478           0 :       nsresult rv = UnwrapObject<prototypes::id::File, mozilla::dom::File>(value, memberSlot);
    4479           0 :       if (NS_FAILED(rv)) {
    4480           0 :         DestroyFile();
    4481           0 :         tryNext = true;
    4482           0 :         return true;
    4483             :       }
    4484             :     }
    4485             :   }
    4486           0 :   return true;
    4487             : }
    4488             : 
    4489             : void
    4490           0 : OwningFileOrDirectory::DestroyFile()
    4491             : {
    4492           0 :   MOZ_ASSERT(IsFile(), "Wrong type!");
    4493           0 :   mValue.mFile.Destroy();
    4494           0 :   mType = eUninitialized;
    4495           0 : }
    4496             : 
    4497             : 
    4498             : 
    4499             : 
    4500             : OwningNonNull<mozilla::dom::Directory>&
    4501           0 : OwningFileOrDirectory::RawSetAsDirectory()
    4502             : {
    4503           0 :   if (mType == eDirectory) {
    4504           0 :     return mValue.mDirectory.Value();
    4505             :   }
    4506           0 :   MOZ_ASSERT(mType == eUninitialized);
    4507           0 :   mType = eDirectory;
    4508           0 :   return mValue.mDirectory.SetValue();
    4509             : }
    4510             : 
    4511             : OwningNonNull<mozilla::dom::Directory>&
    4512           0 : OwningFileOrDirectory::SetAsDirectory()
    4513             : {
    4514           0 :   if (mType == eDirectory) {
    4515           0 :     return mValue.mDirectory.Value();
    4516             :   }
    4517           0 :   Uninit();
    4518           0 :   mType = eDirectory;
    4519           0 :   return mValue.mDirectory.SetValue();
    4520             : }
    4521             : 
    4522             : bool
    4523           0 : OwningFileOrDirectory::TrySetToDirectory(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    4524             : {
    4525           0 :   tryNext = false;
    4526             :   { // scope for memberSlot
    4527           0 :     OwningNonNull<mozilla::dom::Directory>& memberSlot = RawSetAsDirectory();
    4528             :     static_assert(IsRefcounted<mozilla::dom::Directory>::value, "We can only store refcounted classes.");{
    4529           0 :       nsresult rv = UnwrapObject<prototypes::id::Directory, mozilla::dom::Directory>(value, memberSlot);
    4530           0 :       if (NS_FAILED(rv)) {
    4531           0 :         DestroyDirectory();
    4532           0 :         tryNext = true;
    4533           0 :         return true;
    4534             :       }
    4535             :     }
    4536             :   }
    4537           0 :   return true;
    4538             : }
    4539             : 
    4540             : void
    4541           0 : OwningFileOrDirectory::DestroyDirectory()
    4542             : {
    4543           0 :   MOZ_ASSERT(IsDirectory(), "Wrong type!");
    4544           0 :   mValue.mDirectory.Destroy();
    4545           0 :   mType = eUninitialized;
    4546           0 : }
    4547             : 
    4548             : 
    4549             : 
    4550             : 
    4551             : void
    4552           0 : OwningFileOrDirectory::Uninit()
    4553             : {
    4554           0 :   switch (mType) {
    4555             :     case eUninitialized: {
    4556           0 :       break;
    4557             :     }
    4558             :     case eFile: {
    4559           0 :       DestroyFile();
    4560           0 :       break;
    4561             :     }
    4562             :     case eDirectory: {
    4563           0 :       DestroyDirectory();
    4564           0 :       break;
    4565             :     }
    4566             :   }
    4567           0 : }
    4568             : 
    4569             : bool
    4570           0 : OwningFileOrDirectory::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    4571             : {
    4572           0 :   switch (mType) {
    4573             :     case eUninitialized: {
    4574           0 :       return false;
    4575             :       break;
    4576             :     }
    4577             :     case eFile: {
    4578           0 :       if (!GetOrCreateDOMReflector(cx, mValue.mFile.Value(), rval)) {
    4579           0 :         MOZ_ASSERT(true || JS_IsExceptionPending(cx));
    4580           0 :         return false;
    4581             :       }
    4582           0 :       return true;
    4583             :       break;
    4584             :     }
    4585             :     case eDirectory: {
    4586           0 :       if (!GetOrCreateDOMReflector(cx, mValue.mDirectory.Value(), rval)) {
    4587           0 :         MOZ_ASSERT(true || JS_IsExceptionPending(cx));
    4588           0 :         return false;
    4589             :       }
    4590           0 :       return true;
    4591             :       break;
    4592             :     }
    4593             :     default: {
    4594           0 :       return false;
    4595             :       break;
    4596             :     }
    4597             :   }
    4598             : 
    4599             :   return false;
    4600             : }
    4601             : 
    4602             : void
    4603           0 : OwningFileOrDirectory::TraceUnion(JSTracer* trc)
    4604             : {
    4605           0 : }
    4606             : 
    4607             : OwningFileOrDirectory&
    4608           0 : OwningFileOrDirectory::operator=(const OwningFileOrDirectory& aOther)
    4609             : {
    4610           0 :   switch (aOther.mType) {
    4611             :     case eUninitialized: {
    4612           0 :       MOZ_ASSERT(mType == eUninitialized,
    4613             :                  "We need to destroy ourselves?");
    4614           0 :       break;
    4615             :     }
    4616             :     case eFile: {
    4617           0 :       SetAsFile() = aOther.GetAsFile();
    4618           0 :       break;
    4619             :     }
    4620             :     case eDirectory: {
    4621           0 :       SetAsDirectory() = aOther.GetAsDirectory();
    4622           0 :       break;
    4623             :     }
    4624             :   }
    4625           0 :   return *this;
    4626             : }
    4627             : 
    4628             : float&
    4629           0 : OwningFloatOrString::RawSetAsFloat()
    4630             : {
    4631           0 :   if (mType == eFloat) {
    4632           0 :     return mValue.mFloat.Value();
    4633             :   }
    4634           0 :   MOZ_ASSERT(mType == eUninitialized);
    4635           0 :   mType = eFloat;
    4636           0 :   return mValue.mFloat.SetValue();
    4637             : }
    4638             : 
    4639             : float&
    4640           0 : OwningFloatOrString::SetAsFloat()
    4641             : {
    4642           0 :   if (mType == eFloat) {
    4643           0 :     return mValue.mFloat.Value();
    4644             :   }
    4645           0 :   Uninit();
    4646           0 :   mType = eFloat;
    4647           0 :   return mValue.mFloat.SetValue();
    4648             : }
    4649             : 
    4650             : bool
    4651           0 : OwningFloatOrString::TrySetToFloat(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    4652             : {
    4653           0 :   tryNext = false;
    4654             :   { // scope for memberSlot
    4655           0 :     float& memberSlot = RawSetAsFloat();
    4656           0 :     if (!ValueToPrimitive<float, eDefault>(cx, value, &memberSlot)) {
    4657           0 :       return false;
    4658           0 :     } else if (!mozilla::IsFinite(memberSlot)) {
    4659           0 :       ThrowErrorMessage(cx, MSG_NOT_FINITE, "Member of FloatOrString");
    4660           0 :       return false;
    4661             :     }
    4662             :   }
    4663           0 :   return true;
    4664             : }
    4665             : 
    4666             : void
    4667           0 : OwningFloatOrString::DestroyFloat()
    4668             : {
    4669           0 :   MOZ_ASSERT(IsFloat(), "Wrong type!");
    4670           0 :   mValue.mFloat.Destroy();
    4671           0 :   mType = eUninitialized;
    4672           0 : }
    4673             : 
    4674             : 
    4675             : 
    4676             : 
    4677             : nsString&
    4678           0 : OwningFloatOrString::RawSetAsString()
    4679             : {
    4680           0 :   if (mType == eString) {
    4681           0 :     return mValue.mString.Value();
    4682             :   }
    4683           0 :   MOZ_ASSERT(mType == eUninitialized);
    4684           0 :   mType = eString;
    4685           0 :   return mValue.mString.SetValue();
    4686             : }
    4687             : 
    4688             : nsString&
    4689           0 : OwningFloatOrString::SetAsString()
    4690             : {
    4691           0 :   if (mType == eString) {
    4692           0 :     return mValue.mString.Value();
    4693             :   }
    4694           0 :   Uninit();
    4695           0 :   mType = eString;
    4696           0 :   return mValue.mString.SetValue();
    4697             : }
    4698             : 
    4699             : bool
    4700           0 : OwningFloatOrString::TrySetToString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    4701             : {
    4702           0 :   tryNext = false;
    4703             :   { // scope for memberSlot
    4704           0 :     nsString& memberSlot = RawSetAsString();
    4705           0 :     if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
    4706           0 :       return false;
    4707             :     }
    4708             :   }
    4709           0 :   return true;
    4710             : }
    4711             : 
    4712             : 
    4713             : void
    4714           0 : OwningFloatOrString::DestroyString()
    4715             : {
    4716           0 :   MOZ_ASSERT(IsString(), "Wrong type!");
    4717           0 :   mValue.mString.Destroy();
    4718           0 :   mType = eUninitialized;
    4719           0 : }
    4720             : 
    4721             : 
    4722             : 
    4723             : 
    4724             : void
    4725           0 : OwningFloatOrString::Uninit()
    4726             : {
    4727           0 :   switch (mType) {
    4728             :     case eUninitialized: {
    4729           0 :       break;
    4730             :     }
    4731             :     case eFloat: {
    4732           0 :       DestroyFloat();
    4733           0 :       break;
    4734             :     }
    4735             :     case eString: {
    4736           0 :       DestroyString();
    4737           0 :       break;
    4738             :     }
    4739             :   }
    4740           0 : }
    4741             : 
    4742             : bool
    4743           0 : OwningFloatOrString::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    4744             : {
    4745           0 :   switch (mType) {
    4746             :     case eUninitialized: {
    4747           0 :       return false;
    4748             :       break;
    4749             :     }
    4750             :     case eFloat: {
    4751           0 :       rval.set(JS_NumberValue(double(mValue.mFloat.Value())));
    4752           0 :       return true;
    4753             :       break;
    4754             :     }
    4755             :     case eString: {
    4756           0 :       if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) {
    4757           0 :         return false;
    4758             :       }
    4759           0 :       return true;
    4760             :       break;
    4761             :     }
    4762             :     default: {
    4763           0 :       return false;
    4764             :       break;
    4765             :     }
    4766             :   }
    4767             : 
    4768             :   return false;
    4769             : }
    4770             : 
    4771             : void
    4772           0 : OwningFloatOrString::TraceUnion(JSTracer* trc)
    4773             : {
    4774           0 : }
    4775             : 
    4776             : OwningFloatOrString&
    4777           0 : OwningFloatOrString::operator=(const OwningFloatOrString& aOther)
    4778             : {
    4779           0 :   switch (aOther.mType) {
    4780             :     case eUninitialized: {
    4781           0 :       MOZ_ASSERT(mType == eUninitialized,
    4782             :                  "We need to destroy ourselves?");
    4783           0 :       break;
    4784             :     }
    4785             :     case eFloat: {
    4786           0 :       SetAsFloat() = aOther.GetAsFloat();
    4787           0 :       break;
    4788             :     }
    4789             :     case eString: {
    4790           0 :       SetAsString() = aOther.GetAsString();
    4791           0 :       break;
    4792             :     }
    4793             :   }
    4794           0 :   return *this;
    4795             : }
    4796             : 
    4797             : OwningNonNull<nsGenericHTMLElement>&
    4798           0 : OwningHTMLElementOrLong::RawSetAsHTMLElement()
    4799             : {
    4800           0 :   if (mType == eHTMLElement) {
    4801           0 :     return mValue.mHTMLElement.Value();
    4802             :   }
    4803           0 :   MOZ_ASSERT(mType == eUninitialized);
    4804           0 :   mType = eHTMLElement;
    4805           0 :   return mValue.mHTMLElement.SetValue();
    4806             : }
    4807             : 
    4808             : OwningNonNull<nsGenericHTMLElement>&
    4809           0 : OwningHTMLElementOrLong::SetAsHTMLElement()
    4810             : {
    4811           0 :   if (mType == eHTMLElement) {
    4812           0 :     return mValue.mHTMLElement.Value();
    4813             :   }
    4814           0 :   Uninit();
    4815           0 :   mType = eHTMLElement;
    4816           0 :   return mValue.mHTMLElement.SetValue();
    4817             : }
    4818             : 
    4819             : bool
    4820           0 : OwningHTMLElementOrLong::TrySetToHTMLElement(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    4821             : {
    4822           0 :   tryNext = false;
    4823             :   { // scope for memberSlot
    4824           0 :     OwningNonNull<nsGenericHTMLElement>& memberSlot = RawSetAsHTMLElement();
    4825             :     static_assert(IsRefcounted<nsGenericHTMLElement>::value, "We can only store refcounted classes.");{
    4826           0 :       nsresult rv = UnwrapObject<prototypes::id::HTMLElement, nsGenericHTMLElement>(value, memberSlot);
    4827           0 :       if (NS_FAILED(rv)) {
    4828           0 :         DestroyHTMLElement();
    4829           0 :         tryNext = true;
    4830           0 :         return true;
    4831             :       }
    4832             :     }
    4833             :   }
    4834           0 :   return true;
    4835             : }
    4836             : 
    4837             : void
    4838           0 : OwningHTMLElementOrLong::DestroyHTMLElement()
    4839             : {
    4840           0 :   MOZ_ASSERT(IsHTMLElement(), "Wrong type!");
    4841           0 :   mValue.mHTMLElement.Destroy();
    4842           0 :   mType = eUninitialized;
    4843           0 : }
    4844             : 
    4845             : 
    4846             : 
    4847             : 
    4848             : int32_t&
    4849           0 : OwningHTMLElementOrLong::RawSetAsLong()
    4850             : {
    4851           0 :   if (mType == eLong) {
    4852           0 :     return mValue.mLong.Value();
    4853             :   }
    4854           0 :   MOZ_ASSERT(mType == eUninitialized);
    4855           0 :   mType = eLong;
    4856           0 :   return mValue.mLong.SetValue();
    4857             : }
    4858             : 
    4859             : int32_t&
    4860           0 : OwningHTMLElementOrLong::SetAsLong()
    4861             : {
    4862           0 :   if (mType == eLong) {
    4863           0 :     return mValue.mLong.Value();
    4864             :   }
    4865           0 :   Uninit();
    4866           0 :   mType = eLong;
    4867           0 :   return mValue.mLong.SetValue();
    4868             : }
    4869             : 
    4870             : bool
    4871           0 : OwningHTMLElementOrLong::TrySetToLong(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    4872             : {
    4873           0 :   tryNext = false;
    4874             :   { // scope for memberSlot
    4875           0 :     int32_t& memberSlot = RawSetAsLong();
    4876           0 :     if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
    4877           0 :       return false;
    4878             :     }
    4879             :   }
    4880           0 :   return true;
    4881             : }
    4882             : 
    4883             : void
    4884           0 : OwningHTMLElementOrLong::DestroyLong()
    4885             : {
    4886           0 :   MOZ_ASSERT(IsLong(), "Wrong type!");
    4887           0 :   mValue.mLong.Destroy();
    4888           0 :   mType = eUninitialized;
    4889           0 : }
    4890             : 
    4891             : 
    4892             : 
    4893             : 
    4894             : void
    4895           0 : OwningHTMLElementOrLong::Uninit()
    4896             : {
    4897           0 :   switch (mType) {
    4898             :     case eUninitialized: {
    4899           0 :       break;
    4900             :     }
    4901             :     case eHTMLElement: {
    4902           0 :       DestroyHTMLElement();
    4903           0 :       break;
    4904             :     }
    4905             :     case eLong: {
    4906           0 :       DestroyLong();
    4907           0 :       break;
    4908             :     }
    4909             :   }
    4910           0 : }
    4911             : 
    4912             : bool
    4913           0 : OwningHTMLElementOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    4914             : {
    4915           0 :   switch (mType) {
    4916             :     case eUninitialized: {
    4917           0 :       return false;
    4918             :       break;
    4919             :     }
    4920             :     case eHTMLElement: {
    4921           0 :       if (!GetOrCreateDOMReflector(cx, mValue.mHTMLElement.Value(), rval)) {
    4922           0 :         MOZ_ASSERT(true || JS_IsExceptionPending(cx));
    4923           0 :         return false;
    4924             :       }
    4925           0 :       return true;
    4926             :       break;
    4927             :     }
    4928             :     case eLong: {
    4929           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    4930           0 :       return true;
    4931             :       break;
    4932             :     }
    4933             :     default: {
    4934           0 :       return false;
    4935             :       break;
    4936             :     }
    4937             :   }
    4938             : 
    4939             :   return false;
    4940             : }
    4941             : 
    4942             : void
    4943           0 : OwningHTMLElementOrLong::TraceUnion(JSTracer* trc)
    4944             : {
    4945           0 : }
    4946             : 
    4947             : OwningHTMLElementOrLong&
    4948           0 : OwningHTMLElementOrLong::operator=(const OwningHTMLElementOrLong& aOther)
    4949             : {
    4950           0 :   switch (aOther.mType) {
    4951             :     case eUninitialized: {
    4952           0 :       MOZ_ASSERT(mType == eUninitialized,
    4953             :                  "We need to destroy ourselves?");
    4954           0 :       break;
    4955             :     }
    4956             :     case eHTMLElement: {
    4957           0 :       SetAsHTMLElement() = aOther.GetAsHTMLElement();
    4958           0 :       break;
    4959             :     }
    4960             :     case eLong: {
    4961           0 :       SetAsLong() = aOther.GetAsLong();
    4962           0 :       break;
    4963             :     }
    4964             :   }
    4965           0 :   return *this;
    4966             : }
    4967             : 
    4968             : OwningNonNull<mozilla::dom::HTMLOptionElement>&
    4969           0 : OwningHTMLOptionElementOrHTMLOptGroupElement::RawSetAsHTMLOptionElement()
    4970             : {
    4971           0 :   if (mType == eHTMLOptionElement) {
    4972           0 :     return mValue.mHTMLOptionElement.Value();
    4973             :   }
    4974           0 :   MOZ_ASSERT(mType == eUninitialized);
    4975           0 :   mType = eHTMLOptionElement;
    4976           0 :   return mValue.mHTMLOptionElement.SetValue();
    4977             : }
    4978             : 
    4979             : OwningNonNull<mozilla::dom::HTMLOptionElement>&
    4980           0 : OwningHTMLOptionElementOrHTMLOptGroupElement::SetAsHTMLOptionElement()
    4981             : {
    4982           0 :   if (mType == eHTMLOptionElement) {
    4983           0 :     return mValue.mHTMLOptionElement.Value();
    4984             :   }
    4985           0 :   Uninit();
    4986           0 :   mType = eHTMLOptionElement;
    4987           0 :   return mValue.mHTMLOptionElement.SetValue();
    4988             : }
    4989             : 
    4990             : bool
    4991           0 : OwningHTMLOptionElementOrHTMLOptGroupElement::TrySetToHTMLOptionElement(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    4992             : {
    4993           0 :   tryNext = false;
    4994             :   { // scope for memberSlot
    4995           0 :     OwningNonNull<mozilla::dom::HTMLOptionElement>& memberSlot = RawSetAsHTMLOptionElement();
    4996             :     static_assert(IsRefcounted<mozilla::dom::HTMLOptionElement>::value, "We can only store refcounted classes.");{
    4997           0 :       nsresult rv = UnwrapObject<prototypes::id::HTMLOptionElement, mozilla::dom::HTMLOptionElement>(value, memberSlot);
    4998           0 :       if (NS_FAILED(rv)) {
    4999           0 :         DestroyHTMLOptionElement();
    5000           0 :         tryNext = true;
    5001           0 :         return true;
    5002             :       }
    5003             :     }
    5004             :   }
    5005           0 :   return true;
    5006             : }
    5007             : 
    5008             : void
    5009           0 : OwningHTMLOptionElementOrHTMLOptGroupElement::DestroyHTMLOptionElement()
    5010             : {
    5011           0 :   MOZ_ASSERT(IsHTMLOptionElement(), "Wrong type!");
    5012           0 :   mValue.mHTMLOptionElement.Destroy();
    5013           0 :   mType = eUninitialized;
    5014           0 : }
    5015             : 
    5016             : 
    5017             : 
    5018             : 
    5019             : OwningNonNull<mozilla::dom::HTMLOptGroupElement>&
    5020           0 : OwningHTMLOptionElementOrHTMLOptGroupElement::RawSetAsHTMLOptGroupElement()
    5021             : {
    5022           0 :   if (mType == eHTMLOptGroupElement) {
    5023           0 :     return mValue.mHTMLOptGroupElement.Value();
    5024             :   }
    5025           0 :   MOZ_ASSERT(mType == eUninitialized);
    5026           0 :   mType = eHTMLOptGroupElement;
    5027           0 :   return mValue.mHTMLOptGroupElement.SetValue();
    5028             : }
    5029             : 
    5030             : OwningNonNull<mozilla::dom::HTMLOptGroupElement>&
    5031           0 : OwningHTMLOptionElementOrHTMLOptGroupElement::SetAsHTMLOptGroupElement()
    5032             : {
    5033           0 :   if (mType == eHTMLOptGroupElement) {
    5034           0 :     return mValue.mHTMLOptGroupElement.Value();
    5035             :   }
    5036           0 :   Uninit();
    5037           0 :   mType = eHTMLOptGroupElement;
    5038           0 :   return mValue.mHTMLOptGroupElement.SetValue();
    5039             : }
    5040             : 
    5041             : bool
    5042           0 : OwningHTMLOptionElementOrHTMLOptGroupElement::TrySetToHTMLOptGroupElement(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    5043             : {
    5044           0 :   tryNext = false;
    5045             :   { // scope for memberSlot
    5046           0 :     OwningNonNull<mozilla::dom::HTMLOptGroupElement>& memberSlot = RawSetAsHTMLOptGroupElement();
    5047             :     static_assert(IsRefcounted<mozilla::dom::HTMLOptGroupElement>::value, "We can only store refcounted classes.");{
    5048           0 :       nsresult rv = UnwrapObject<prototypes::id::HTMLOptGroupElement, mozilla::dom::HTMLOptGroupElement>(value, memberSlot);
    5049           0 :       if (NS_FAILED(rv)) {
    5050           0 :         DestroyHTMLOptGroupElement();
    5051           0 :         tryNext = true;
    5052           0 :         return true;
    5053             :       }
    5054             :     }
    5055             :   }
    5056           0 :   return true;
    5057             : }
    5058             : 
    5059             : void
    5060           0 : OwningHTMLOptionElementOrHTMLOptGroupElement::DestroyHTMLOptGroupElement()
    5061             : {
    5062           0 :   MOZ_ASSERT(IsHTMLOptGroupElement(), "Wrong type!");
    5063           0 :   mValue.mHTMLOptGroupElement.Destroy();
    5064           0 :   mType = eUninitialized;
    5065           0 : }
    5066             : 
    5067             : 
    5068             : 
    5069             : 
    5070             : void
    5071           0 : OwningHTMLOptionElementOrHTMLOptGroupElement::Uninit()
    5072             : {
    5073           0 :   switch (mType) {
    5074             :     case eUninitialized: {
    5075           0 :       break;
    5076             :     }
    5077             :     case eHTMLOptionElement: {
    5078           0 :       DestroyHTMLOptionElement();
    5079           0 :       break;
    5080             :     }
    5081             :     case eHTMLOptGroupElement: {
    5082           0 :       DestroyHTMLOptGroupElement();
    5083           0 :       break;
    5084             :     }
    5085             :   }
    5086           0 : }
    5087             : 
    5088             : bool
    5089           0 : OwningHTMLOptionElementOrHTMLOptGroupElement::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    5090             : {
    5091           0 :   switch (mType) {
    5092             :     case eUninitialized: {
    5093           0 :       return false;
    5094             :       break;
    5095             :     }
    5096             :     case eHTMLOptionElement: {
    5097           0 :       if (!GetOrCreateDOMReflector(cx, mValue.mHTMLOptionElement.Value(), rval)) {
    5098           0 :         MOZ_ASSERT(true || JS_IsExceptionPending(cx));
    5099           0 :         return false;
    5100             :       }
    5101           0 :       return true;
    5102             :       break;
    5103             :     }
    5104             :     case eHTMLOptGroupElement: {
    5105           0 :       if (!GetOrCreateDOMReflector(cx, mValue.mHTMLOptGroupElement.Value(), rval)) {
    5106           0 :         MOZ_ASSERT(true || JS_IsExceptionPending(cx));
    5107           0 :         return false;
    5108             :       }
    5109           0 :       return true;
    5110             :       break;
    5111             :     }
    5112             :     default: {
    5113           0 :       return false;
    5114             :       break;
    5115             :     }
    5116             :   }
    5117             : 
    5118             :   return false;
    5119             : }
    5120             : 
    5121             : void
    5122           0 : OwningHTMLOptionElementOrHTMLOptGroupElement::TraceUnion(JSTracer* trc)
    5123             : {
    5124           0 : }
    5125             : 
    5126             : OwningHTMLOptionElementOrHTMLOptGroupElement&
    5127           0 : OwningHTMLOptionElementOrHTMLOptGroupElement::operator=(const OwningHTMLOptionElementOrHTMLOptGroupElement& aOther)
    5128             : {
    5129           0 :   switch (aOther.mType) {
    5130             :     case eUninitialized: {
    5131           0 :       MOZ_ASSERT(mType == eUninitialized,
    5132             :                  "We need to destroy ourselves?");
    5133           0 :       break;
    5134             :     }
    5135             :     case eHTMLOptionElement: {
    5136           0 :       SetAsHTMLOptionElement() = aOther.GetAsHTMLOptionElement();
    5137           0 :       break;
    5138             :     }
    5139             :     case eHTMLOptGroupElement: {
    5140           0 :       SetAsHTMLOptGroupElement() = aOther.GetAsHTMLOptGroupElement();
    5141           0 :       break;
    5142             :     }
    5143             :   }
    5144           0 :   return *this;
    5145             : }
    5146             : 
    5147             : Sequence<RefPtr<mozilla::dom::ImageData>>&
    5148           0 : OwningImageDataOrNullSequenceOrLong::RawSetAsImageDataOrNullSequence()
    5149             : {
    5150           0 :   if (mType == eImageDataOrNullSequence) {
    5151           0 :     return mValue.mImageDataOrNullSequence.Value();
    5152             :   }
    5153           0 :   MOZ_ASSERT(mType == eUninitialized);
    5154           0 :   mType = eImageDataOrNullSequence;
    5155           0 :   return mValue.mImageDataOrNullSequence.SetValue();
    5156             : }
    5157             : 
    5158             : Sequence<RefPtr<mozilla::dom::ImageData>>&
    5159           0 : OwningImageDataOrNullSequenceOrLong::SetAsImageDataOrNullSequence()
    5160             : {
    5161           0 :   if (mType == eImageDataOrNullSequence) {
    5162           0 :     return mValue.mImageDataOrNullSequence.Value();
    5163             :   }
    5164           0 :   Uninit();
    5165           0 :   mType = eImageDataOrNullSequence;
    5166           0 :   return mValue.mImageDataOrNullSequence.SetValue();
    5167             : }
    5168             : 
    5169             : bool
    5170           0 : OwningImageDataOrNullSequenceOrLong::TrySetToImageDataOrNullSequence(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    5171             : {
    5172           0 :   tryNext = false;
    5173             :   { // scope for memberSlot
    5174           0 :     Sequence<RefPtr<mozilla::dom::ImageData>>& memberSlot = RawSetAsImageDataOrNullSequence();
    5175           0 :     JS::ForOfIterator iter(cx);
    5176           0 :     if (!iter.init(value, JS::ForOfIterator::AllowNonIterable)) {
    5177           0 :       return false;
    5178             :     }
    5179           0 :     if (!iter.valueIsIterable()) {
    5180           0 :       DestroyImageDataOrNullSequence();
    5181           0 :       tryNext = true;
    5182           0 :       return true;
    5183             :     }
    5184           0 :     Sequence<RefPtr<mozilla::dom::ImageData>> &arr = memberSlot;
    5185           0 :     JS::Rooted<JS::Value> temp(cx);
    5186             :     while (true) {
    5187             :       bool done;
    5188           0 :       if (!iter.next(&temp, &done)) {
    5189           0 :         return false;
    5190             :       }
    5191           0 :       if (done) {
    5192           0 :         break;
    5193             :       }
    5194           0 :       RefPtr<mozilla::dom::ImageData>* slotPtr = arr.AppendElement(mozilla::fallible);
    5195           0 :       if (!slotPtr) {
    5196           0 :         JS_ReportOutOfMemory(cx);
    5197           0 :         return false;
    5198             :       }
    5199           0 :       RefPtr<mozilla::dom::ImageData>& slot = *slotPtr;
    5200           0 :       if (temp.isObject()) {
    5201             :         static_assert(IsRefcounted<mozilla::dom::ImageData>::value, "We can only store refcounted classes.");{
    5202           0 :           nsresult rv = UnwrapObject<prototypes::id::ImageData, mozilla::dom::ImageData>(&temp, slot);
    5203           0 :           if (NS_FAILED(rv)) {
    5204           0 :             ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Element of member of ImageDataOrNullSequenceOrLong", "ImageData");
    5205           0 :             return false;
    5206             :           }
    5207             :         }
    5208           0 :       } else if (temp.isNullOrUndefined()) {
    5209           0 :         slot = nullptr;
    5210             :       } else {
    5211           0 :         ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of member of ImageDataOrNullSequenceOrLong");
    5212           0 :         return false;
    5213             :       }
    5214           0 :     }
    5215             :   }
    5216           0 :   return true;
    5217             : }
    5218             : 
    5219             : void
    5220           0 : OwningImageDataOrNullSequenceOrLong::DestroyImageDataOrNullSequence()
    5221             : {
    5222           0 :   MOZ_ASSERT(IsImageDataOrNullSequence(), "Wrong type!");
    5223           0 :   mValue.mImageDataOrNullSequence.Destroy();
    5224           0 :   mType = eUninitialized;
    5225           0 : }
    5226             : 
    5227             : 
    5228             : 
    5229             : 
    5230             : int32_t&
    5231           0 : OwningImageDataOrNullSequenceOrLong::RawSetAsLong()
    5232             : {
    5233           0 :   if (mType == eLong) {
    5234           0 :     return mValue.mLong.Value();
    5235             :   }
    5236           0 :   MOZ_ASSERT(mType == eUninitialized);
    5237           0 :   mType = eLong;
    5238           0 :   return mValue.mLong.SetValue();
    5239             : }
    5240             : 
    5241             : int32_t&
    5242           0 : OwningImageDataOrNullSequenceOrLong::SetAsLong()
    5243             : {
    5244           0 :   if (mType == eLong) {
    5245           0 :     return mValue.mLong.Value();
    5246             :   }
    5247           0 :   Uninit();
    5248           0 :   mType = eLong;
    5249           0 :   return mValue.mLong.SetValue();
    5250             : }
    5251             : 
    5252             : bool
    5253           0 : OwningImageDataOrNullSequenceOrLong::TrySetToLong(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    5254             : {
    5255           0 :   tryNext = false;
    5256             :   { // scope for memberSlot
    5257           0 :     int32_t& memberSlot = RawSetAsLong();
    5258           0 :     if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
    5259           0 :       return false;
    5260             :     }
    5261             :   }
    5262           0 :   return true;
    5263             : }
    5264             : 
    5265             : void
    5266           0 : OwningImageDataOrNullSequenceOrLong::DestroyLong()
    5267             : {
    5268           0 :   MOZ_ASSERT(IsLong(), "Wrong type!");
    5269           0 :   mValue.mLong.Destroy();
    5270           0 :   mType = eUninitialized;
    5271           0 : }
    5272             : 
    5273             : 
    5274             : 
    5275             : 
    5276             : void
    5277           0 : OwningImageDataOrNullSequenceOrLong::Uninit()
    5278             : {
    5279           0 :   switch (mType) {
    5280             :     case eUninitialized: {
    5281           0 :       break;
    5282             :     }
    5283             :     case eImageDataOrNullSequence: {
    5284           0 :       DestroyImageDataOrNullSequence();
    5285           0 :       break;
    5286             :     }
    5287             :     case eLong: {
    5288           0 :       DestroyLong();
    5289           0 :       break;
    5290             :     }
    5291             :   }
    5292           0 : }
    5293             : 
    5294             : bool
    5295           0 : OwningImageDataOrNullSequenceOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    5296             : {
    5297           0 :   switch (mType) {
    5298             :     case eUninitialized: {
    5299           0 :       return false;
    5300             :       break;
    5301             :     }
    5302             :     case eImageDataOrNullSequence: {
    5303             : 
    5304           0 :       uint32_t length = mValue.mImageDataOrNullSequence.Value().Length();
    5305           0 :       JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
    5306           0 :       if (!returnArray) {
    5307           0 :         return false;
    5308             :       }
    5309             :       // Scope for 'tmp'
    5310             :       {
    5311           0 :         JS::Rooted<JS::Value> tmp(cx);
    5312           0 :         for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
    5313             :           // Control block to let us common up the JS_DefineElement calls when there
    5314             :           // are different ways to succeed at wrapping the object.
    5315             :           do {
    5316           0 :             if (!mValue.mImageDataOrNullSequence.Value()[sequenceIdx0]) {
    5317           0 :               tmp.setNull();
    5318           0 :               break;
    5319             :             }
    5320           0 :             if (!WrapNewBindingNonWrapperCachedObject(cx, returnArray, mValue.mImageDataOrNullSequence.Value()[sequenceIdx0], &tmp)) {
    5321           0 :               MOZ_ASSERT(true || JS_IsExceptionPending(cx));
    5322           0 :               return false;
    5323             :             }
    5324           0 :             break;
    5325             :           } while (0);
    5326           0 :           if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
    5327             :                                 JSPROP_ENUMERATE)) {
    5328           0 :             return false;
    5329             :           }
    5330             :         }
    5331             :       }
    5332           0 :       rval.setObject(*returnArray);
    5333           0 :       return true;
    5334             :       break;
    5335             :     }
    5336             :     case eLong: {
    5337           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    5338           0 :       return true;
    5339             :       break;
    5340             :     }
    5341             :     default: {
    5342           0 :       return false;
    5343             :       break;
    5344             :     }
    5345             :   }
    5346             : 
    5347             :   return false;
    5348             : }
    5349             : 
    5350             : void
    5351           0 : OwningImageDataOrNullSequenceOrLong::TraceUnion(JSTracer* trc)
    5352             : {
    5353           0 : }
    5354             : 
    5355             : OwningImageDataOrNullSequenceOrLong&
    5356           0 : OwningImageDataOrNullSequenceOrLong::operator=(const OwningImageDataOrNullSequenceOrLong& aOther)
    5357             : {
    5358           0 :   switch (aOther.mType) {
    5359             :     case eUninitialized: {
    5360           0 :       MOZ_ASSERT(mType == eUninitialized,
    5361             :                  "We need to destroy ourselves?");
    5362           0 :       break;
    5363             :     }
    5364             :     case eImageDataOrNullSequence: {
    5365           0 :       SetAsImageDataOrNullSequence() = aOther.GetAsImageDataOrNullSequence();
    5366           0 :       break;
    5367             :     }
    5368             :     case eLong: {
    5369           0 :       SetAsLong() = aOther.GetAsLong();
    5370           0 :       break;
    5371             :     }
    5372             :   }
    5373           0 :   return *this;
    5374             : }
    5375             : 
    5376             : Sequence<Sequence<RefPtr<mozilla::dom::ImageData>>>&
    5377           0 : OwningImageDataOrNullSequenceSequenceOrLong::RawSetAsImageDataOrNullSequenceSequence()
    5378             : {
    5379           0 :   if (mType == eImageDataOrNullSequenceSequence) {
    5380           0 :     return mValue.mImageDataOrNullSequenceSequence.Value();
    5381             :   }
    5382           0 :   MOZ_ASSERT(mType == eUninitialized);
    5383           0 :   mType = eImageDataOrNullSequenceSequence;
    5384           0 :   return mValue.mImageDataOrNullSequenceSequence.SetValue();
    5385             : }
    5386             : 
    5387             : Sequence<Sequence<RefPtr<mozilla::dom::ImageData>>>&
    5388           0 : OwningImageDataOrNullSequenceSequenceOrLong::SetAsImageDataOrNullSequenceSequence()
    5389             : {
    5390           0 :   if (mType == eImageDataOrNullSequenceSequence) {
    5391           0 :     return mValue.mImageDataOrNullSequenceSequence.Value();
    5392             :   }
    5393           0 :   Uninit();
    5394           0 :   mType = eImageDataOrNullSequenceSequence;
    5395           0 :   return mValue.mImageDataOrNullSequenceSequence.SetValue();
    5396             : }
    5397             : 
    5398             : bool
    5399           0 : OwningImageDataOrNullSequenceSequenceOrLong::TrySetToImageDataOrNullSequenceSequence(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    5400             : {
    5401           0 :   tryNext = false;
    5402             :   { // scope for memberSlot
    5403           0 :     Sequence<Sequence<RefPtr<mozilla::dom::ImageData>>>& memberSlot = RawSetAsImageDataOrNullSequenceSequence();
    5404           0 :     JS::ForOfIterator iter(cx);
    5405           0 :     if (!iter.init(value, JS::ForOfIterator::AllowNonIterable)) {
    5406           0 :       return false;
    5407             :     }
    5408           0 :     if (!iter.valueIsIterable()) {
    5409           0 :       DestroyImageDataOrNullSequenceSequence();
    5410           0 :       tryNext = true;
    5411           0 :       return true;
    5412             :     }
    5413           0 :     Sequence<Sequence<RefPtr<mozilla::dom::ImageData>>> &arr = memberSlot;
    5414           0 :     JS::Rooted<JS::Value> temp(cx);
    5415             :     while (true) {
    5416             :       bool done;
    5417           0 :       if (!iter.next(&temp, &done)) {
    5418           0 :         return false;
    5419             :       }
    5420           0 :       if (done) {
    5421           0 :         break;
    5422             :       }
    5423           0 :       Sequence<RefPtr<mozilla::dom::ImageData>>* slotPtr = arr.AppendElement(mozilla::fallible);
    5424           0 :       if (!slotPtr) {
    5425           0 :         JS_ReportOutOfMemory(cx);
    5426           0 :         return false;
    5427             :       }
    5428           0 :       Sequence<RefPtr<mozilla::dom::ImageData>>& slot = *slotPtr;
    5429           0 :       if (temp.isObject()) {
    5430           0 :         JS::ForOfIterator iter1(cx);
    5431           0 :         if (!iter1.init(temp, JS::ForOfIterator::AllowNonIterable)) {
    5432           0 :           return false;
    5433             :         }
    5434           0 :         if (!iter1.valueIsIterable()) {
    5435           0 :           ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Element of member of ImageDataOrNullSequenceSequenceOrLong");
    5436           0 :           return false;
    5437             :         }
    5438           0 :         Sequence<RefPtr<mozilla::dom::ImageData>> &arr1 = slot;
    5439           0 :         JS::Rooted<JS::Value> temp1(cx);
    5440             :         while (true) {
    5441             :           bool done1;
    5442           0 :           if (!iter1.next(&temp1, &done1)) {
    5443           0 :             return false;
    5444             :           }
    5445           0 :           if (done1) {
    5446           0 :             break;
    5447             :           }
    5448           0 :           RefPtr<mozilla::dom::ImageData>* slotPtr1 = arr1.AppendElement(mozilla::fallible);
    5449           0 :           if (!slotPtr1) {
    5450           0 :             JS_ReportOutOfMemory(cx);
    5451           0 :             return false;
    5452             :           }
    5453           0 :           RefPtr<mozilla::dom::ImageData>& slot1 = *slotPtr1;
    5454           0 :           if (temp1.isObject()) {
    5455             :             static_assert(IsRefcounted<mozilla::dom::ImageData>::value, "We can only store refcounted classes.");{
    5456           0 :               nsresult rv = UnwrapObject<prototypes::id::ImageData, mozilla::dom::ImageData>(&temp1, slot1);
    5457           0 :               if (NS_FAILED(rv)) {
    5458           0 :                 ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Element of element of member of ImageDataOrNullSequenceSequenceOrLong", "ImageData");
    5459           0 :                 return false;
    5460             :               }
    5461             :             }
    5462           0 :           } else if (temp1.isNullOrUndefined()) {
    5463           0 :             slot1 = nullptr;
    5464             :           } else {
    5465           0 :             ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of element of member of ImageDataOrNullSequenceSequenceOrLong");
    5466           0 :             return false;
    5467             :           }
    5468           0 :         }
    5469             :       } else {
    5470           0 :         ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Element of member of ImageDataOrNullSequenceSequenceOrLong");
    5471           0 :         return false;
    5472             :       }
    5473           0 :     }
    5474             :   }
    5475           0 :   return true;
    5476             : }
    5477             : 
    5478             : void
    5479           0 : OwningImageDataOrNullSequenceSequenceOrLong::DestroyImageDataOrNullSequenceSequence()
    5480             : {
    5481           0 :   MOZ_ASSERT(IsImageDataOrNullSequenceSequence(), "Wrong type!");
    5482           0 :   mValue.mImageDataOrNullSequenceSequence.Destroy();
    5483           0 :   mType = eUninitialized;
    5484           0 : }
    5485             : 
    5486             : 
    5487             : 
    5488             : 
    5489             : int32_t&
    5490           0 : OwningImageDataOrNullSequenceSequenceOrLong::RawSetAsLong()
    5491             : {
    5492           0 :   if (mType == eLong) {
    5493           0 :     return mValue.mLong.Value();
    5494             :   }
    5495           0 :   MOZ_ASSERT(mType == eUninitialized);
    5496           0 :   mType = eLong;
    5497           0 :   return mValue.mLong.SetValue();
    5498             : }
    5499             : 
    5500             : int32_t&
    5501           0 : OwningImageDataOrNullSequenceSequenceOrLong::SetAsLong()
    5502             : {
    5503           0 :   if (mType == eLong) {
    5504           0 :     return mValue.mLong.Value();
    5505             :   }
    5506           0 :   Uninit();
    5507           0 :   mType = eLong;
    5508           0 :   return mValue.mLong.SetValue();
    5509             : }
    5510             : 
    5511             : bool
    5512           0 : OwningImageDataOrNullSequenceSequenceOrLong::TrySetToLong(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    5513             : {
    5514           0 :   tryNext = false;
    5515             :   { // scope for memberSlot
    5516           0 :     int32_t& memberSlot = RawSetAsLong();
    5517           0 :     if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
    5518           0 :       return false;
    5519             :     }
    5520             :   }
    5521           0 :   return true;
    5522             : }
    5523             : 
    5524             : void
    5525           0 : OwningImageDataOrNullSequenceSequenceOrLong::DestroyLong()
    5526             : {
    5527           0 :   MOZ_ASSERT(IsLong(), "Wrong type!");
    5528           0 :   mValue.mLong.Destroy();
    5529           0 :   mType = eUninitialized;
    5530           0 : }
    5531             : 
    5532             : 
    5533             : 
    5534             : 
    5535             : void
    5536           0 : OwningImageDataOrNullSequenceSequenceOrLong::Uninit()
    5537             : {
    5538           0 :   switch (mType) {
    5539             :     case eUninitialized: {
    5540           0 :       break;
    5541             :     }
    5542             :     case eImageDataOrNullSequenceSequence: {
    5543           0 :       DestroyImageDataOrNullSequenceSequence();
    5544           0 :       break;
    5545             :     }
    5546             :     case eLong: {
    5547           0 :       DestroyLong();
    5548           0 :       break;
    5549             :     }
    5550             :   }
    5551           0 : }
    5552             : 
    5553             : bool
    5554           0 : OwningImageDataOrNullSequenceSequenceOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    5555             : {
    5556           0 :   switch (mType) {
    5557             :     case eUninitialized: {
    5558           0 :       return false;
    5559             :       break;
    5560             :     }
    5561             :     case eImageDataOrNullSequenceSequence: {
    5562             : 
    5563           0 :       uint32_t length = mValue.mImageDataOrNullSequenceSequence.Value().Length();
    5564           0 :       JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
    5565           0 :       if (!returnArray) {
    5566           0 :         return false;
    5567             :       }
    5568             :       // Scope for 'tmp'
    5569             :       {
    5570           0 :         JS::Rooted<JS::Value> tmp(cx);
    5571           0 :         for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
    5572             :           // Control block to let us common up the JS_DefineElement calls when there
    5573             :           // are different ways to succeed at wrapping the object.
    5574             :           do {
    5575             : 
    5576           0 :             uint32_t length = mValue.mImageDataOrNullSequenceSequence.Value()[sequenceIdx0].Length();
    5577           0 :             JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
    5578           0 :             if (!returnArray) {
    5579           0 :               return false;
    5580             :             }
    5581             :             // Scope for 'tmp'
    5582             :             {
    5583           0 :               JS::Rooted<JS::Value> tmp(cx);
    5584           0 :               for (uint32_t sequenceIdx1 = 0; sequenceIdx1 < length; ++sequenceIdx1) {
    5585             :                 // Control block to let us common up the JS_DefineElement calls when there
    5586             :                 // are different ways to succeed at wrapping the object.
    5587             :                 do {
    5588           0 :                   if (!mValue.mImageDataOrNullSequenceSequence.Value()[sequenceIdx0][sequenceIdx1]) {
    5589           0 :                     tmp.setNull();
    5590           0 :                     break;
    5591             :                   }
    5592           0 :                   if (!WrapNewBindingNonWrapperCachedObject(cx, returnArray, mValue.mImageDataOrNullSequenceSequence.Value()[sequenceIdx0][sequenceIdx1], &tmp)) {
    5593           0 :                     MOZ_ASSERT(true || JS_IsExceptionPending(cx));
    5594           0 :                     return false;
    5595             :                   }
    5596           0 :                   break;
    5597             :                 } while (0);
    5598           0 :                 if (!JS_DefineElement(cx, returnArray, sequenceIdx1, tmp,
    5599             :                                       JSPROP_ENUMERATE)) {
    5600           0 :                   return false;
    5601             :                 }
    5602             :               }
    5603             :             }
    5604           0 :             tmp.setObject(*returnArray);
    5605           0 :             break;
    5606             :           } while (0);
    5607           0 :           if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
    5608             :                                 JSPROP_ENUMERATE)) {
    5609           0 :             return false;
    5610             :           }
    5611             :         }
    5612             :       }
    5613           0 :       rval.setObject(*returnArray);
    5614           0 :       return true;
    5615             :       break;
    5616             :     }
    5617             :     case eLong: {
    5618           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    5619           0 :       return true;
    5620             :       break;
    5621             :     }
    5622             :     default: {
    5623           0 :       return false;
    5624             :       break;
    5625             :     }
    5626             :   }
    5627             : 
    5628             :   return false;
    5629             : }
    5630             : 
    5631             : void
    5632           0 : OwningImageDataOrNullSequenceSequenceOrLong::TraceUnion(JSTracer* trc)
    5633             : {
    5634           0 : }
    5635             : 
    5636             : OwningImageDataOrNullSequenceSequenceOrLong&
    5637           0 : OwningImageDataOrNullSequenceSequenceOrLong::operator=(const OwningImageDataOrNullSequenceSequenceOrLong& aOther)
    5638             : {
    5639           0 :   switch (aOther.mType) {
    5640             :     case eUninitialized: {
    5641           0 :       MOZ_ASSERT(mType == eUninitialized,
    5642             :                  "We need to destroy ourselves?");
    5643           0 :       break;
    5644             :     }
    5645             :     case eImageDataOrNullSequenceSequence: {
    5646           0 :       SetAsImageDataOrNullSequenceSequence() = aOther.GetAsImageDataOrNullSequenceSequence();
    5647           0 :       break;
    5648             :     }
    5649             :     case eLong: {
    5650           0 :       SetAsLong() = aOther.GetAsLong();
    5651           0 :       break;
    5652             :     }
    5653             :   }
    5654           0 :   return *this;
    5655             : }
    5656             : 
    5657             : Sequence<OwningNonNull<mozilla::dom::ImageData>>&
    5658           0 : OwningImageDataSequenceOrLong::RawSetAsImageDataSequence()
    5659             : {
    5660           0 :   if (mType == eImageDataSequence) {
    5661           0 :     return mValue.mImageDataSequence.Value();
    5662             :   }
    5663           0 :   MOZ_ASSERT(mType == eUninitialized);
    5664           0 :   mType = eImageDataSequence;
    5665           0 :   return mValue.mImageDataSequence.SetValue();
    5666             : }
    5667             : 
    5668             : Sequence<OwningNonNull<mozilla::dom::ImageData>>&
    5669           0 : OwningImageDataSequenceOrLong::SetAsImageDataSequence()
    5670             : {
    5671           0 :   if (mType == eImageDataSequence) {
    5672           0 :     return mValue.mImageDataSequence.Value();
    5673             :   }
    5674           0 :   Uninit();
    5675           0 :   mType = eImageDataSequence;
    5676           0 :   return mValue.mImageDataSequence.SetValue();
    5677             : }
    5678             : 
    5679             : bool
    5680           0 : OwningImageDataSequenceOrLong::TrySetToImageDataSequence(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    5681             : {
    5682           0 :   tryNext = false;
    5683             :   { // scope for memberSlot
    5684           0 :     Sequence<OwningNonNull<mozilla::dom::ImageData>>& memberSlot = RawSetAsImageDataSequence();
    5685           0 :     JS::ForOfIterator iter(cx);
    5686           0 :     if (!iter.init(value, JS::ForOfIterator::AllowNonIterable)) {
    5687           0 :       return false;
    5688             :     }
    5689           0 :     if (!iter.valueIsIterable()) {
    5690           0 :       DestroyImageDataSequence();
    5691           0 :       tryNext = true;
    5692           0 :       return true;
    5693             :     }
    5694           0 :     Sequence<OwningNonNull<mozilla::dom::ImageData>> &arr = memberSlot;
    5695           0 :     JS::Rooted<JS::Value> temp(cx);
    5696             :     while (true) {
    5697             :       bool done;
    5698           0 :       if (!iter.next(&temp, &done)) {
    5699           0 :         return false;
    5700             :       }
    5701           0 :       if (done) {
    5702           0 :         break;
    5703             :       }
    5704           0 :       OwningNonNull<mozilla::dom::ImageData>* slotPtr = arr.AppendElement(mozilla::fallible);
    5705           0 :       if (!slotPtr) {
    5706           0 :         JS_ReportOutOfMemory(cx);
    5707           0 :         return false;
    5708             :       }
    5709           0 :       OwningNonNull<mozilla::dom::ImageData>& slot = *slotPtr;
    5710           0 :       if (temp.isObject()) {
    5711             :         static_assert(IsRefcounted<mozilla::dom::ImageData>::value, "We can only store refcounted classes.");{
    5712           0 :           nsresult rv = UnwrapObject<prototypes::id::ImageData, mozilla::dom::ImageData>(&temp, slot);
    5713           0 :           if (NS_FAILED(rv)) {
    5714           0 :             ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Element of member of ImageDataSequenceOrLong", "ImageData");
    5715           0 :             return false;
    5716             :           }
    5717             :         }
    5718             :       } else {
    5719           0 :         ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of member of ImageDataSequenceOrLong");
    5720           0 :         return false;
    5721             :       }
    5722           0 :     }
    5723             :   }
    5724           0 :   return true;
    5725             : }
    5726             : 
    5727             : void
    5728           0 : OwningImageDataSequenceOrLong::DestroyImageDataSequence()
    5729             : {
    5730           0 :   MOZ_ASSERT(IsImageDataSequence(), "Wrong type!");
    5731           0 :   mValue.mImageDataSequence.Destroy();
    5732           0 :   mType = eUninitialized;
    5733           0 : }
    5734             : 
    5735             : 
    5736             : 
    5737             : 
    5738             : int32_t&
    5739           0 : OwningImageDataSequenceOrLong::RawSetAsLong()
    5740             : {
    5741           0 :   if (mType == eLong) {
    5742           0 :     return mValue.mLong.Value();
    5743             :   }
    5744           0 :   MOZ_ASSERT(mType == eUninitialized);
    5745           0 :   mType = eLong;
    5746           0 :   return mValue.mLong.SetValue();
    5747             : }
    5748             : 
    5749             : int32_t&
    5750           0 : OwningImageDataSequenceOrLong::SetAsLong()
    5751             : {
    5752           0 :   if (mType == eLong) {
    5753           0 :     return mValue.mLong.Value();
    5754             :   }
    5755           0 :   Uninit();
    5756           0 :   mType = eLong;
    5757           0 :   return mValue.mLong.SetValue();
    5758             : }
    5759             : 
    5760             : bool
    5761           0 : OwningImageDataSequenceOrLong::TrySetToLong(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    5762             : {
    5763           0 :   tryNext = false;
    5764             :   { // scope for memberSlot
    5765           0 :     int32_t& memberSlot = RawSetAsLong();
    5766           0 :     if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
    5767           0 :       return false;
    5768             :     }
    5769             :   }
    5770           0 :   return true;
    5771             : }
    5772             : 
    5773             : void
    5774           0 : OwningImageDataSequenceOrLong::DestroyLong()
    5775             : {
    5776           0 :   MOZ_ASSERT(IsLong(), "Wrong type!");
    5777           0 :   mValue.mLong.Destroy();
    5778           0 :   mType = eUninitialized;
    5779           0 : }
    5780             : 
    5781             : 
    5782             : 
    5783             : 
    5784             : void
    5785           0 : OwningImageDataSequenceOrLong::Uninit()
    5786             : {
    5787           0 :   switch (mType) {
    5788             :     case eUninitialized: {
    5789           0 :       break;
    5790             :     }
    5791             :     case eImageDataSequence: {
    5792           0 :       DestroyImageDataSequence();
    5793           0 :       break;
    5794             :     }
    5795             :     case eLong: {
    5796           0 :       DestroyLong();
    5797           0 :       break;
    5798             :     }
    5799             :   }
    5800           0 : }
    5801             : 
    5802             : bool
    5803           0 : OwningImageDataSequenceOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    5804             : {
    5805           0 :   switch (mType) {
    5806             :     case eUninitialized: {
    5807           0 :       return false;
    5808             :       break;
    5809             :     }
    5810             :     case eImageDataSequence: {
    5811             : 
    5812           0 :       uint32_t length = mValue.mImageDataSequence.Value().Length();
    5813           0 :       JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
    5814           0 :       if (!returnArray) {
    5815           0 :         return false;
    5816             :       }
    5817             :       // Scope for 'tmp'
    5818             :       {
    5819           0 :         JS::Rooted<JS::Value> tmp(cx);
    5820           0 :         for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
    5821             :           // Control block to let us common up the JS_DefineElement calls when there
    5822             :           // are different ways to succeed at wrapping the object.
    5823             :           do {
    5824           0 :             if (!WrapNewBindingNonWrapperCachedObject(cx, returnArray, mValue.mImageDataSequence.Value()[sequenceIdx0], &tmp)) {
    5825           0 :               MOZ_ASSERT(true || JS_IsExceptionPending(cx));
    5826           0 :               return false;
    5827             :             }
    5828           0 :             break;
    5829             :           } while (0);
    5830           0 :           if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
    5831             :                                 JSPROP_ENUMERATE)) {
    5832           0 :             return false;
    5833             :           }
    5834             :         }
    5835             :       }
    5836           0 :       rval.setObject(*returnArray);
    5837           0 :       return true;
    5838             :       break;
    5839             :     }
    5840             :     case eLong: {
    5841           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    5842           0 :       return true;
    5843             :       break;
    5844             :     }
    5845             :     default: {
    5846           0 :       return false;
    5847             :       break;
    5848             :     }
    5849             :   }
    5850             : 
    5851             :   return false;
    5852             : }
    5853             : 
    5854             : void
    5855           0 : OwningImageDataSequenceOrLong::TraceUnion(JSTracer* trc)
    5856             : {
    5857           0 : }
    5858             : 
    5859             : OwningImageDataSequenceOrLong&
    5860           0 : OwningImageDataSequenceOrLong::operator=(const OwningImageDataSequenceOrLong& aOther)
    5861             : {
    5862           0 :   switch (aOther.mType) {
    5863             :     case eUninitialized: {
    5864           0 :       MOZ_ASSERT(mType == eUninitialized,
    5865             :                  "We need to destroy ourselves?");
    5866           0 :       break;
    5867             :     }
    5868             :     case eImageDataSequence: {
    5869           0 :       SetAsImageDataSequence() = aOther.GetAsImageDataSequence();
    5870           0 :       break;
    5871             :     }
    5872             :     case eLong: {
    5873           0 :       SetAsLong() = aOther.GetAsLong();
    5874           0 :       break;
    5875             :     }
    5876             :   }
    5877           0 :   return *this;
    5878             : }
    5879             : 
    5880             : Sequence<Sequence<OwningNonNull<mozilla::dom::ImageData>>>&
    5881           0 : OwningImageDataSequenceSequenceOrLong::RawSetAsImageDataSequenceSequence()
    5882             : {
    5883           0 :   if (mType == eImageDataSequenceSequence) {
    5884           0 :     return mValue.mImageDataSequenceSequence.Value();
    5885             :   }
    5886           0 :   MOZ_ASSERT(mType == eUninitialized);
    5887           0 :   mType = eImageDataSequenceSequence;
    5888           0 :   return mValue.mImageDataSequenceSequence.SetValue();
    5889             : }
    5890             : 
    5891             : Sequence<Sequence<OwningNonNull<mozilla::dom::ImageData>>>&
    5892           0 : OwningImageDataSequenceSequenceOrLong::SetAsImageDataSequenceSequence()
    5893             : {
    5894           0 :   if (mType == eImageDataSequenceSequence) {
    5895           0 :     return mValue.mImageDataSequenceSequence.Value();
    5896             :   }
    5897           0 :   Uninit();
    5898           0 :   mType = eImageDataSequenceSequence;
    5899           0 :   return mValue.mImageDataSequenceSequence.SetValue();
    5900             : }
    5901             : 
    5902             : bool
    5903           0 : OwningImageDataSequenceSequenceOrLong::TrySetToImageDataSequenceSequence(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    5904             : {
    5905           0 :   tryNext = false;
    5906             :   { // scope for memberSlot
    5907           0 :     Sequence<Sequence<OwningNonNull<mozilla::dom::ImageData>>>& memberSlot = RawSetAsImageDataSequenceSequence();
    5908           0 :     JS::ForOfIterator iter(cx);
    5909           0 :     if (!iter.init(value, JS::ForOfIterator::AllowNonIterable)) {
    5910           0 :       return false;
    5911             :     }
    5912           0 :     if (!iter.valueIsIterable()) {
    5913           0 :       DestroyImageDataSequenceSequence();
    5914           0 :       tryNext = true;
    5915           0 :       return true;
    5916             :     }
    5917           0 :     Sequence<Sequence<OwningNonNull<mozilla::dom::ImageData>>> &arr = memberSlot;
    5918           0 :     JS::Rooted<JS::Value> temp(cx);
    5919             :     while (true) {
    5920             :       bool done;
    5921           0 :       if (!iter.next(&temp, &done)) {
    5922           0 :         return false;
    5923             :       }
    5924           0 :       if (done) {
    5925           0 :         break;
    5926             :       }
    5927           0 :       Sequence<OwningNonNull<mozilla::dom::ImageData>>* slotPtr = arr.AppendElement(mozilla::fallible);
    5928           0 :       if (!slotPtr) {
    5929           0 :         JS_ReportOutOfMemory(cx);
    5930           0 :         return false;
    5931             :       }
    5932           0 :       Sequence<OwningNonNull<mozilla::dom::ImageData>>& slot = *slotPtr;
    5933           0 :       if (temp.isObject()) {
    5934           0 :         JS::ForOfIterator iter1(cx);
    5935           0 :         if (!iter1.init(temp, JS::ForOfIterator::AllowNonIterable)) {
    5936           0 :           return false;
    5937             :         }
    5938           0 :         if (!iter1.valueIsIterable()) {
    5939           0 :           ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Element of member of ImageDataSequenceSequenceOrLong");
    5940           0 :           return false;
    5941             :         }
    5942           0 :         Sequence<OwningNonNull<mozilla::dom::ImageData>> &arr1 = slot;
    5943           0 :         JS::Rooted<JS::Value> temp1(cx);
    5944             :         while (true) {
    5945             :           bool done1;
    5946           0 :           if (!iter1.next(&temp1, &done1)) {
    5947           0 :             return false;
    5948             :           }
    5949           0 :           if (done1) {
    5950           0 :             break;
    5951             :           }
    5952           0 :           OwningNonNull<mozilla::dom::ImageData>* slotPtr1 = arr1.AppendElement(mozilla::fallible);
    5953           0 :           if (!slotPtr1) {
    5954           0 :             JS_ReportOutOfMemory(cx);
    5955           0 :             return false;
    5956             :           }
    5957           0 :           OwningNonNull<mozilla::dom::ImageData>& slot1 = *slotPtr1;
    5958           0 :           if (temp1.isObject()) {
    5959             :             static_assert(IsRefcounted<mozilla::dom::ImageData>::value, "We can only store refcounted classes.");{
    5960           0 :               nsresult rv = UnwrapObject<prototypes::id::ImageData, mozilla::dom::ImageData>(&temp1, slot1);
    5961           0 :               if (NS_FAILED(rv)) {
    5962           0 :                 ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Element of element of member of ImageDataSequenceSequenceOrLong", "ImageData");
    5963           0 :                 return false;
    5964             :               }
    5965             :             }
    5966             :           } else {
    5967           0 :             ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of element of member of ImageDataSequenceSequenceOrLong");
    5968           0 :             return false;
    5969             :           }
    5970           0 :         }
    5971             :       } else {
    5972           0 :         ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Element of member of ImageDataSequenceSequenceOrLong");
    5973           0 :         return false;
    5974             :       }
    5975           0 :     }
    5976             :   }
    5977           0 :   return true;
    5978             : }
    5979             : 
    5980             : void
    5981           0 : OwningImageDataSequenceSequenceOrLong::DestroyImageDataSequenceSequence()
    5982             : {
    5983           0 :   MOZ_ASSERT(IsImageDataSequenceSequence(), "Wrong type!");
    5984           0 :   mValue.mImageDataSequenceSequence.Destroy();
    5985           0 :   mType = eUninitialized;
    5986           0 : }
    5987             : 
    5988             : 
    5989             : 
    5990             : 
    5991             : int32_t&
    5992           0 : OwningImageDataSequenceSequenceOrLong::RawSetAsLong()
    5993             : {
    5994           0 :   if (mType == eLong) {
    5995           0 :     return mValue.mLong.Value();
    5996             :   }
    5997           0 :   MOZ_ASSERT(mType == eUninitialized);
    5998           0 :   mType = eLong;
    5999           0 :   return mValue.mLong.SetValue();
    6000             : }
    6001             : 
    6002             : int32_t&
    6003           0 : OwningImageDataSequenceSequenceOrLong::SetAsLong()
    6004             : {
    6005           0 :   if (mType == eLong) {
    6006           0 :     return mValue.mLong.Value();
    6007             :   }
    6008           0 :   Uninit();
    6009           0 :   mType = eLong;
    6010           0 :   return mValue.mLong.SetValue();
    6011             : }
    6012             : 
    6013             : bool
    6014           0 : OwningImageDataSequenceSequenceOrLong::TrySetToLong(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    6015             : {
    6016           0 :   tryNext = false;
    6017             :   { // scope for memberSlot
    6018           0 :     int32_t& memberSlot = RawSetAsLong();
    6019           0 :     if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
    6020           0 :       return false;
    6021             :     }
    6022             :   }
    6023           0 :   return true;
    6024             : }
    6025             : 
    6026             : void
    6027           0 : OwningImageDataSequenceSequenceOrLong::DestroyLong()
    6028             : {
    6029           0 :   MOZ_ASSERT(IsLong(), "Wrong type!");
    6030           0 :   mValue.mLong.Destroy();
    6031           0 :   mType = eUninitialized;
    6032           0 : }
    6033             : 
    6034             : 
    6035             : 
    6036             : 
    6037             : void
    6038           0 : OwningImageDataSequenceSequenceOrLong::Uninit()
    6039             : {
    6040           0 :   switch (mType) {
    6041             :     case eUninitialized: {
    6042           0 :       break;
    6043             :     }
    6044             :     case eImageDataSequenceSequence: {
    6045           0 :       DestroyImageDataSequenceSequence();
    6046           0 :       break;
    6047             :     }
    6048             :     case eLong: {
    6049           0 :       DestroyLong();
    6050           0 :       break;
    6051             :     }
    6052             :   }
    6053           0 : }
    6054             : 
    6055             : bool
    6056           0 : OwningImageDataSequenceSequenceOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    6057             : {
    6058           0 :   switch (mType) {
    6059             :     case eUninitialized: {
    6060           0 :       return false;
    6061             :       break;
    6062             :     }
    6063             :     case eImageDataSequenceSequence: {
    6064             : 
    6065           0 :       uint32_t length = mValue.mImageDataSequenceSequence.Value().Length();
    6066           0 :       JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
    6067           0 :       if (!returnArray) {
    6068           0 :         return false;
    6069             :       }
    6070             :       // Scope for 'tmp'
    6071             :       {
    6072           0 :         JS::Rooted<JS::Value> tmp(cx);
    6073           0 :         for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
    6074             :           // Control block to let us common up the JS_DefineElement calls when there
    6075             :           // are different ways to succeed at wrapping the object.
    6076             :           do {
    6077             : 
    6078           0 :             uint32_t length = mValue.mImageDataSequenceSequence.Value()[sequenceIdx0].Length();
    6079           0 :             JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
    6080           0 :             if (!returnArray) {
    6081           0 :               return false;
    6082             :             }
    6083             :             // Scope for 'tmp'
    6084             :             {
    6085           0 :               JS::Rooted<JS::Value> tmp(cx);
    6086           0 :               for (uint32_t sequenceIdx1 = 0; sequenceIdx1 < length; ++sequenceIdx1) {
    6087             :                 // Control block to let us common up the JS_DefineElement calls when there
    6088             :                 // are different ways to succeed at wrapping the object.
    6089             :                 do {
    6090           0 :                   if (!WrapNewBindingNonWrapperCachedObject(cx, returnArray, mValue.mImageDataSequenceSequence.Value()[sequenceIdx0][sequenceIdx1], &tmp)) {
    6091           0 :                     MOZ_ASSERT(true || JS_IsExceptionPending(cx));
    6092           0 :                     return false;
    6093             :                   }
    6094           0 :                   break;
    6095             :                 } while (0);
    6096           0 :                 if (!JS_DefineElement(cx, returnArray, sequenceIdx1, tmp,
    6097             :                                       JSPROP_ENUMERATE)) {
    6098           0 :                   return false;
    6099             :                 }
    6100             :               }
    6101             :             }
    6102           0 :             tmp.setObject(*returnArray);
    6103           0 :             break;
    6104             :           } while (0);
    6105           0 :           if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
    6106             :                                 JSPROP_ENUMERATE)) {
    6107           0 :             return false;
    6108             :           }
    6109             :         }
    6110             :       }
    6111           0 :       rval.setObject(*returnArray);
    6112           0 :       return true;
    6113             :       break;
    6114             :     }
    6115             :     case eLong: {
    6116           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    6117           0 :       return true;
    6118             :       break;
    6119             :     }
    6120             :     default: {
    6121           0 :       return false;
    6122             :       break;
    6123             :     }
    6124             :   }
    6125             : 
    6126             :   return false;
    6127             : }
    6128             : 
    6129             : void
    6130           0 : OwningImageDataSequenceSequenceOrLong::TraceUnion(JSTracer* trc)
    6131             : {
    6132           0 : }
    6133             : 
    6134             : OwningImageDataSequenceSequenceOrLong&
    6135           0 : OwningImageDataSequenceSequenceOrLong::operator=(const OwningImageDataSequenceSequenceOrLong& aOther)
    6136             : {
    6137           0 :   switch (aOther.mType) {
    6138             :     case eUninitialized: {
    6139           0 :       MOZ_ASSERT(mType == eUninitialized,
    6140             :                  "We need to destroy ourselves?");
    6141           0 :       break;
    6142             :     }
    6143             :     case eImageDataSequenceSequence: {
    6144           0 :       SetAsImageDataSequenceSequence() = aOther.GetAsImageDataSequenceSequence();
    6145           0 :       break;
    6146             :     }
    6147             :     case eLong: {
    6148           0 :       SetAsLong() = aOther.GetAsLong();
    6149           0 :       break;
    6150             :     }
    6151             :   }
    6152           0 :   return *this;
    6153             : }
    6154             : 
    6155             : int32_t&
    6156           0 : OwningLongOrBoolean::RawSetAsLong()
    6157             : {
    6158           0 :   if (mType == eLong) {
    6159           0 :     return mValue.mLong.Value();
    6160             :   }
    6161           0 :   MOZ_ASSERT(mType == eUninitialized);
    6162           0 :   mType = eLong;
    6163           0 :   return mValue.mLong.SetValue();
    6164             : }
    6165             : 
    6166             : int32_t&
    6167           0 : OwningLongOrBoolean::SetAsLong()
    6168             : {
    6169           0 :   if (mType == eLong) {
    6170           0 :     return mValue.mLong.Value();
    6171             :   }
    6172           0 :   Uninit();
    6173           0 :   mType = eLong;
    6174           0 :   return mValue.mLong.SetValue();
    6175             : }
    6176             : 
    6177             : bool
    6178           0 : OwningLongOrBoolean::TrySetToLong(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    6179             : {
    6180           0 :   tryNext = false;
    6181             :   { // scope for memberSlot
    6182           0 :     int32_t& memberSlot = RawSetAsLong();
    6183           0 :     if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
    6184           0 :       return false;
    6185             :     }
    6186             :   }
    6187           0 :   return true;
    6188             : }
    6189             : 
    6190             : void
    6191           0 : OwningLongOrBoolean::DestroyLong()
    6192             : {
    6193           0 :   MOZ_ASSERT(IsLong(), "Wrong type!");
    6194           0 :   mValue.mLong.Destroy();
    6195           0 :   mType = eUninitialized;
    6196           0 : }
    6197             : 
    6198             : 
    6199             : 
    6200             : 
    6201             : bool&
    6202           0 : OwningLongOrBoolean::RawSetAsBoolean()
    6203             : {
    6204           0 :   if (mType == eBoolean) {
    6205           0 :     return mValue.mBoolean.Value();
    6206             :   }
    6207           0 :   MOZ_ASSERT(mType == eUninitialized);
    6208           0 :   mType = eBoolean;
    6209           0 :   return mValue.mBoolean.SetValue();
    6210             : }
    6211             : 
    6212             : bool&
    6213           0 : OwningLongOrBoolean::SetAsBoolean()
    6214             : {
    6215           0 :   if (mType == eBoolean) {
    6216           0 :     return mValue.mBoolean.Value();
    6217             :   }
    6218           0 :   Uninit();
    6219           0 :   mType = eBoolean;
    6220           0 :   return mValue.mBoolean.SetValue();
    6221             : }
    6222             : 
    6223             : bool
    6224           0 : OwningLongOrBoolean::TrySetToBoolean(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    6225             : {
    6226           0 :   tryNext = false;
    6227             :   { // scope for memberSlot
    6228           0 :     bool& memberSlot = RawSetAsBoolean();
    6229           0 :     if (!ValueToPrimitive<bool, eDefault>(cx, value, &memberSlot)) {
    6230           0 :       return false;
    6231             :     }
    6232             :   }
    6233           0 :   return true;
    6234             : }
    6235             : 
    6236             : void
    6237           0 : OwningLongOrBoolean::DestroyBoolean()
    6238             : {
    6239           0 :   MOZ_ASSERT(IsBoolean(), "Wrong type!");
    6240           0 :   mValue.mBoolean.Destroy();
    6241           0 :   mType = eUninitialized;
    6242           0 : }
    6243             : 
    6244             : 
    6245             : 
    6246             : 
    6247             : void
    6248           0 : OwningLongOrBoolean::Uninit()
    6249             : {
    6250           0 :   switch (mType) {
    6251             :     case eUninitialized: {
    6252           0 :       break;
    6253             :     }
    6254             :     case eLong: {
    6255           0 :       DestroyLong();
    6256           0 :       break;
    6257             :     }
    6258             :     case eBoolean: {
    6259           0 :       DestroyBoolean();
    6260           0 :       break;
    6261             :     }
    6262             :   }
    6263           0 : }
    6264             : 
    6265             : bool
    6266           0 : OwningLongOrBoolean::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    6267             : {
    6268           0 :   switch (mType) {
    6269             :     case eUninitialized: {
    6270           0 :       return false;
    6271             :       break;
    6272             :     }
    6273             :     case eLong: {
    6274           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    6275           0 :       return true;
    6276             :       break;
    6277             :     }
    6278             :     case eBoolean: {
    6279           0 :       rval.setBoolean(mValue.mBoolean.Value());
    6280           0 :       return true;
    6281             :       break;
    6282             :     }
    6283             :     default: {
    6284           0 :       return false;
    6285             :       break;
    6286             :     }
    6287             :   }
    6288             : 
    6289             :   return false;
    6290             : }
    6291             : 
    6292             : void
    6293           0 : OwningLongOrBoolean::TraceUnion(JSTracer* trc)
    6294             : {
    6295           0 : }
    6296             : 
    6297             : OwningLongOrBoolean&
    6298           0 : OwningLongOrBoolean::operator=(const OwningLongOrBoolean& aOther)
    6299             : {
    6300           0 :   switch (aOther.mType) {
    6301             :     case eUninitialized: {
    6302           0 :       MOZ_ASSERT(mType == eUninitialized,
    6303             :                  "We need to destroy ourselves?");
    6304           0 :       break;
    6305             :     }
    6306             :     case eLong: {
    6307           0 :       SetAsLong() = aOther.GetAsLong();
    6308           0 :       break;
    6309             :     }
    6310             :     case eBoolean: {
    6311           0 :       SetAsBoolean() = aOther.GetAsBoolean();
    6312           0 :       break;
    6313             :     }
    6314             :   }
    6315           0 :   return *this;
    6316             : }
    6317             : 
    6318             : int32_t&
    6319           0 : OwningLongOrStringAnyRecord::RawSetAsLong()
    6320             : {
    6321           0 :   if (mType == eLong) {
    6322           0 :     return mValue.mLong.Value();
    6323             :   }
    6324           0 :   MOZ_ASSERT(mType == eUninitialized);
    6325           0 :   mType = eLong;
    6326           0 :   return mValue.mLong.SetValue();
    6327             : }
    6328             : 
    6329             : int32_t&
    6330           0 : OwningLongOrStringAnyRecord::SetAsLong()
    6331             : {
    6332           0 :   if (mType == eLong) {
    6333           0 :     return mValue.mLong.Value();
    6334             :   }
    6335           0 :   Uninit();
    6336           0 :   mType = eLong;
    6337           0 :   return mValue.mLong.SetValue();
    6338             : }
    6339             : 
    6340             : bool
    6341           0 : OwningLongOrStringAnyRecord::TrySetToLong(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    6342             : {
    6343           0 :   tryNext = false;
    6344             :   { // scope for memberSlot
    6345           0 :     int32_t& memberSlot = RawSetAsLong();
    6346           0 :     if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
    6347           0 :       return false;
    6348             :     }
    6349             :   }
    6350           0 :   return true;
    6351             : }
    6352             : 
    6353             : void
    6354           0 : OwningLongOrStringAnyRecord::DestroyLong()
    6355             : {
    6356           0 :   MOZ_ASSERT(IsLong(), "Wrong type!");
    6357           0 :   mValue.mLong.Destroy();
    6358           0 :   mType = eUninitialized;
    6359           0 : }
    6360             : 
    6361             : 
    6362             : 
    6363             : 
    6364             : Record<nsString, JS::Value>&
    6365           0 : OwningLongOrStringAnyRecord::RawSetAsStringAnyRecord()
    6366             : {
    6367           0 :   if (mType == eStringAnyRecord) {
    6368           0 :     return mValue.mStringAnyRecord.Value();
    6369             :   }
    6370           0 :   MOZ_ASSERT(mType == eUninitialized);
    6371           0 :   mType = eStringAnyRecord;
    6372           0 :   return mValue.mStringAnyRecord.SetValue();
    6373             : }
    6374             : 
    6375             : Record<nsString, JS::Value>&
    6376           0 : OwningLongOrStringAnyRecord::SetAsStringAnyRecord()
    6377             : {
    6378           0 :   if (mType == eStringAnyRecord) {
    6379           0 :     return mValue.mStringAnyRecord.Value();
    6380             :   }
    6381           0 :   Uninit();
    6382           0 :   mType = eStringAnyRecord;
    6383           0 :   return mValue.mStringAnyRecord.SetValue();
    6384             : }
    6385             : 
    6386             : bool
    6387           0 : OwningLongOrStringAnyRecord::TrySetToStringAnyRecord(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    6388             : {
    6389           0 :   tryNext = false;
    6390             :   { // scope for memberSlot
    6391           0 :     Record<nsString, JS::Value>& memberSlot = RawSetAsStringAnyRecord();
    6392           0 :     auto& recordEntries = memberSlot.Entries();
    6393             : 
    6394           0 :     JS::Rooted<JSObject*> recordObj(cx, &value.toObject());
    6395           0 :     JS::AutoIdVector ids(cx);
    6396           0 :     if (!js::GetPropertyKeys(cx, recordObj,
    6397             :                              JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS, &ids)) {
    6398           0 :       return false;
    6399             :     }
    6400           0 :     if (!recordEntries.SetCapacity(ids.length(), mozilla::fallible)) {
    6401           0 :       JS_ReportOutOfMemory(cx);
    6402           0 :       return false;
    6403             :     }
    6404           0 :     JS::Rooted<JS::Value> propNameValue(cx);
    6405           0 :     JS::Rooted<JS::Value> temp(cx);
    6406           0 :     JS::Rooted<jsid> curId(cx);
    6407           0 :     JS::Rooted<JS::Value> idVal(cx);
    6408             :     // Use a hashset to keep track of ids seen, to avoid
    6409             :     // introducing nasty O(N^2) behavior scanning for them all the
    6410             :     // time.  Ideally we'd use a data structure with O(1) lookup
    6411             :     // _and_ ordering for the MozMap, but we don't have one lying
    6412             :     // around.
    6413           0 :     nsTHashtable<nsStringHashKey> idsSeen;
    6414           0 :     for (size_t i = 0; i < ids.length(); ++i) {
    6415           0 :       curId = ids[i];
    6416             : 
    6417           0 :       JS::Rooted<JS::PropertyDescriptor> desc(cx);
    6418           0 :       if (!JS_GetOwnPropertyDescriptorById(cx, recordObj, curId,
    6419             :                                            &desc)) {
    6420           0 :         return false;
    6421             :       }
    6422             : 
    6423           0 :       if (!desc.object() /* == undefined in spec terms */ ||
    6424           0 :           !desc.enumerable()) {
    6425           0 :         continue;
    6426             :       }
    6427             : 
    6428           0 :       idVal = js::IdToValue(curId);
    6429           0 :       nsString propName;
    6430             :       // This will just throw if idVal is a Symbol, like the spec says
    6431             :       // to do.
    6432           0 :       if (!ConvertJSValueToString(cx, idVal, propName)) {
    6433           0 :         return false;
    6434             :       }
    6435             : 
    6436           0 :       if (!JS_GetPropertyById(cx, recordObj, curId, &temp)) {
    6437           0 :         return false;
    6438             :       }
    6439             : 
    6440             :       Record<nsString, JS::Value>::EntryType* entry;
    6441           0 :       if (!idsSeen.EnsureInserted(propName)) {
    6442             :         // Find the existing entry.
    6443           0 :         auto idx = recordEntries.IndexOf(propName);
    6444           0 :         MOZ_ASSERT(idx != recordEntries.NoIndex,
    6445             :                    "Why is it not found?");
    6446             :         // Now blow it away to make it look like it was just added
    6447             :         // to the array, because it's not obvious that it's
    6448             :         // safe to write to its already-initialized mValue via our
    6449             :         // normal codegen conversions.  For example, the value
    6450             :         // could be a union and this would change its type, but
    6451             :         // codegen assumes we won't do that.
    6452           0 :         entry = recordEntries.ReconstructElementAt(idx);
    6453             :       } else {
    6454             :         // Safe to do an infallible append here, because we did a
    6455             :         // SetCapacity above to the right capacity.
    6456           0 :         entry = recordEntries.AppendElement();
    6457             :       }
    6458           0 :       entry->mKey = propName;
    6459           0 :       JS::Value& slot = entry->mValue;
    6460             : #ifdef __clang__
    6461             : #pragma clang diagnostic push
    6462             : #pragma clang diagnostic ignored "-Wunreachable-code"
    6463             : #pragma clang diagnostic ignored "-Wunreachable-code-return"
    6464             : #endif // __clang__
    6465           0 :       if ((passedToJSImpl) && !CallerSubsumes(temp)) {
    6466           0 :         ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "value in member of LongOrStringAnyRecord");
    6467           0 :         return false;
    6468             :       }
    6469             : #ifdef __clang__
    6470             : #pragma clang diagnostic pop
    6471             : #endif // __clang__
    6472           0 :       slot = temp;
    6473             :     }
    6474             :   }
    6475           0 :   return true;
    6476             : }
    6477             : 
    6478             : void
    6479           0 : OwningLongOrStringAnyRecord::DestroyStringAnyRecord()
    6480             : {
    6481           0 :   MOZ_ASSERT(IsStringAnyRecord(), "Wrong type!");
    6482           0 :   mValue.mStringAnyRecord.Destroy();
    6483           0 :   mType = eUninitialized;
    6484           0 : }
    6485             : 
    6486             : 
    6487             : 
    6488             : 
    6489             : void
    6490           0 : OwningLongOrStringAnyRecord::Uninit()
    6491             : {
    6492           0 :   switch (mType) {
    6493             :     case eUninitialized: {
    6494           0 :       break;
    6495             :     }
    6496             :     case eLong: {
    6497           0 :       DestroyLong();
    6498           0 :       break;
    6499             :     }
    6500             :     case eStringAnyRecord: {
    6501           0 :       DestroyStringAnyRecord();
    6502           0 :       break;
    6503             :     }
    6504             :   }
    6505           0 : }
    6506             : 
    6507             : bool
    6508           0 : OwningLongOrStringAnyRecord::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    6509             : {
    6510           0 :   switch (mType) {
    6511             :     case eUninitialized: {
    6512           0 :       return false;
    6513             :       break;
    6514             :     }
    6515             :     case eLong: {
    6516           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    6517           0 :       return true;
    6518             :       break;
    6519             :     }
    6520             :     case eStringAnyRecord: {
    6521             : 
    6522           0 :       JS::Rooted<JSObject*> returnObj(cx, JS_NewPlainObject(cx));
    6523           0 :       if (!returnObj) {
    6524           0 :         return false;
    6525             :       }
    6526             :       // Scope for 'tmp'
    6527             :       {
    6528           0 :         JS::Rooted<JS::Value> tmp(cx);
    6529           0 :         for (auto& entry : mValue.mStringAnyRecord.Value().Entries()) {
    6530           0 :           auto& recordValue0 = entry.mValue;
    6531             :           // Control block to let us common up the JS_DefineUCProperty calls when there
    6532             :           // are different ways to succeed at wrapping the value.
    6533             :           do {
    6534           0 :             JS::ExposeValueToActiveJS(recordValue0);
    6535           0 :             tmp.set(recordValue0);
    6536           0 :             if (!MaybeWrapValue(cx, &tmp)) {
    6537           0 :               return false;
    6538             :             }
    6539           0 :             break;
    6540             :           } while (0);
    6541           0 :           if (!JS_DefineUCProperty(cx, returnObj,
    6542             :                                    entry.mKey.BeginReading(),
    6543           0 :                                    entry.mKey.Length(), tmp,
    6544             :                                    JSPROP_ENUMERATE)) {
    6545           0 :             return false;
    6546             :           }
    6547             :         }
    6548             :       }
    6549           0 :       rval.setObject(*returnObj);
    6550           0 :       return true;
    6551             :       break;
    6552             :     }
    6553             :     default: {
    6554           0 :       return false;
    6555             :       break;
    6556             :     }
    6557             :   }
    6558             : 
    6559             :   return false;
    6560             : }
    6561             : 
    6562             : void
    6563           0 : OwningLongOrStringAnyRecord::TraceUnion(JSTracer* trc)
    6564             : {
    6565           0 :   switch (mType) {
    6566             :     case eStringAnyRecord: {
    6567           0 :       TraceRecord(trc, mValue.mStringAnyRecord.Value());
    6568           0 :       break;
    6569             :     }
    6570             :     default: {
    6571           0 :       break;
    6572             :     }
    6573             :   }
    6574           0 : }
    6575             : 
    6576             : Sequence<int32_t>&
    6577           0 : OwningLongSequenceOrLong::RawSetAsLongSequence()
    6578             : {
    6579           0 :   if (mType == eLongSequence) {
    6580           0 :     return mValue.mLongSequence.Value();
    6581             :   }
    6582           0 :   MOZ_ASSERT(mType == eUninitialized);
    6583           0 :   mType = eLongSequence;
    6584           0 :   return mValue.mLongSequence.SetValue();
    6585             : }
    6586             : 
    6587             : Sequence<int32_t>&
    6588           0 : OwningLongSequenceOrLong::SetAsLongSequence()
    6589             : {
    6590           0 :   if (mType == eLongSequence) {
    6591           0 :     return mValue.mLongSequence.Value();
    6592             :   }
    6593           0 :   Uninit();
    6594           0 :   mType = eLongSequence;
    6595           0 :   return mValue.mLongSequence.SetValue();
    6596             : }
    6597             : 
    6598             : bool
    6599           0 : OwningLongSequenceOrLong::TrySetToLongSequence(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    6600             : {
    6601           0 :   tryNext = false;
    6602             :   { // scope for memberSlot
    6603           0 :     Sequence<int32_t>& memberSlot = RawSetAsLongSequence();
    6604           0 :     JS::ForOfIterator iter(cx);
    6605           0 :     if (!iter.init(value, JS::ForOfIterator::AllowNonIterable)) {
    6606           0 :       return false;
    6607             :     }
    6608           0 :     if (!iter.valueIsIterable()) {
    6609           0 :       DestroyLongSequence();
    6610           0 :       tryNext = true;
    6611           0 :       return true;
    6612             :     }
    6613           0 :     Sequence<int32_t> &arr = memberSlot;
    6614           0 :     JS::Rooted<JS::Value> temp(cx);
    6615             :     while (true) {
    6616             :       bool done;
    6617           0 :       if (!iter.next(&temp, &done)) {
    6618           0 :         return false;
    6619             :       }
    6620           0 :       if (done) {
    6621           0 :         break;
    6622             :       }
    6623           0 :       int32_t* slotPtr = arr.AppendElement(mozilla::fallible);
    6624           0 :       if (!slotPtr) {
    6625           0 :         JS_ReportOutOfMemory(cx);
    6626           0 :         return false;
    6627             :       }
    6628           0 :       int32_t& slot = *slotPtr;
    6629           0 :       if (!ValueToPrimitive<int32_t, eDefault>(cx, temp, &slot)) {
    6630           0 :         return false;
    6631             :       }
    6632           0 :     }
    6633             :   }
    6634           0 :   return true;
    6635             : }
    6636             : 
    6637             : void
    6638           0 : OwningLongSequenceOrLong::DestroyLongSequence()
    6639             : {
    6640           0 :   MOZ_ASSERT(IsLongSequence(), "Wrong type!");
    6641           0 :   mValue.mLongSequence.Destroy();
    6642           0 :   mType = eUninitialized;
    6643           0 : }
    6644             : 
    6645             : 
    6646             : 
    6647             : 
    6648             : int32_t&
    6649           0 : OwningLongSequenceOrLong::RawSetAsLong()
    6650             : {
    6651           0 :   if (mType == eLong) {
    6652           0 :     return mValue.mLong.Value();
    6653             :   }
    6654           0 :   MOZ_ASSERT(mType == eUninitialized);
    6655           0 :   mType = eLong;
    6656           0 :   return mValue.mLong.SetValue();
    6657             : }
    6658             : 
    6659             : int32_t&
    6660           0 : OwningLongSequenceOrLong::SetAsLong()
    6661             : {
    6662           0 :   if (mType == eLong) {
    6663           0 :     return mValue.mLong.Value();
    6664             :   }
    6665           0 :   Uninit();
    6666           0 :   mType = eLong;
    6667           0 :   return mValue.mLong.SetValue();
    6668             : }
    6669             : 
    6670             : bool
    6671           0 : OwningLongSequenceOrLong::TrySetToLong(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    6672             : {
    6673           0 :   tryNext = false;
    6674             :   { // scope for memberSlot
    6675           0 :     int32_t& memberSlot = RawSetAsLong();
    6676           0 :     if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
    6677           0 :       return false;
    6678             :     }
    6679             :   }
    6680           0 :   return true;
    6681             : }
    6682             : 
    6683             : void
    6684           0 : OwningLongSequenceOrLong::DestroyLong()
    6685             : {
    6686           0 :   MOZ_ASSERT(IsLong(), "Wrong type!");
    6687           0 :   mValue.mLong.Destroy();
    6688           0 :   mType = eUninitialized;
    6689           0 : }
    6690             : 
    6691             : 
    6692             : 
    6693             : 
    6694             : void
    6695           0 : OwningLongSequenceOrLong::Uninit()
    6696             : {
    6697           0 :   switch (mType) {
    6698             :     case eUninitialized: {
    6699           0 :       break;
    6700             :     }
    6701             :     case eLongSequence: {
    6702           0 :       DestroyLongSequence();
    6703           0 :       break;
    6704             :     }
    6705             :     case eLong: {
    6706           0 :       DestroyLong();
    6707           0 :       break;
    6708             :     }
    6709             :   }
    6710           0 : }
    6711             : 
    6712             : bool
    6713           0 : OwningLongSequenceOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    6714             : {
    6715           0 :   switch (mType) {
    6716             :     case eUninitialized: {
    6717           0 :       return false;
    6718             :       break;
    6719             :     }
    6720             :     case eLongSequence: {
    6721             : 
    6722           0 :       uint32_t length = mValue.mLongSequence.Value().Length();
    6723           0 :       JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
    6724           0 :       if (!returnArray) {
    6725           0 :         return false;
    6726             :       }
    6727             :       // Scope for 'tmp'
    6728             :       {
    6729           0 :         JS::Rooted<JS::Value> tmp(cx);
    6730           0 :         for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
    6731             :           // Control block to let us common up the JS_DefineElement calls when there
    6732             :           // are different ways to succeed at wrapping the object.
    6733             :           do {
    6734           0 :             tmp.setInt32(int32_t(mValue.mLongSequence.Value()[sequenceIdx0]));
    6735           0 :             break;
    6736             :           } while (0);
    6737           0 :           if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
    6738             :                                 JSPROP_ENUMERATE)) {
    6739           0 :             return false;
    6740             :           }
    6741             :         }
    6742             :       }
    6743           0 :       rval.setObject(*returnArray);
    6744           0 :       return true;
    6745             :       break;
    6746             :     }
    6747             :     case eLong: {
    6748           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    6749           0 :       return true;
    6750             :       break;
    6751             :     }
    6752             :     default: {
    6753           0 :       return false;
    6754             :       break;
    6755             :     }
    6756             :   }
    6757             : 
    6758             :   return false;
    6759             : }
    6760             : 
    6761             : void
    6762           0 : OwningLongSequenceOrLong::TraceUnion(JSTracer* trc)
    6763             : {
    6764           0 : }
    6765             : 
    6766             : OwningLongSequenceOrLong&
    6767           0 : OwningLongSequenceOrLong::operator=(const OwningLongSequenceOrLong& aOther)
    6768             : {
    6769           0 :   switch (aOther.mType) {
    6770             :     case eUninitialized: {
    6771           0 :       MOZ_ASSERT(mType == eUninitialized,
    6772             :                  "We need to destroy ourselves?");
    6773           0 :       break;
    6774             :     }
    6775             :     case eLongSequence: {
    6776           0 :       SetAsLongSequence() = aOther.GetAsLongSequence();
    6777           0 :       break;
    6778             :     }
    6779             :     case eLong: {
    6780           0 :       SetAsLong() = aOther.GetAsLong();
    6781           0 :       break;
    6782             :     }
    6783             :   }
    6784           0 :   return *this;
    6785             : }
    6786             : 
    6787             : Sequence<int32_t>&
    6788           0 : OwningLongSequenceOrNullOrLong::RawSetAsLongSequence()
    6789             : {
    6790           0 :   if (mType == eLongSequence) {
    6791           0 :     return mValue.mLongSequence.Value();
    6792             :   }
    6793           0 :   MOZ_ASSERT(mType == eUninitialized);
    6794           0 :   mType = eLongSequence;
    6795           0 :   return mValue.mLongSequence.SetValue();
    6796             : }
    6797             : 
    6798             : Sequence<int32_t>&
    6799           0 : OwningLongSequenceOrNullOrLong::SetAsLongSequence()
    6800             : {
    6801           0 :   if (mType == eLongSequence) {
    6802           0 :     return mValue.mLongSequence.Value();
    6803             :   }
    6804           0 :   Uninit();
    6805           0 :   mType = eLongSequence;
    6806           0 :   return mValue.mLongSequence.SetValue();
    6807             : }
    6808             : 
    6809             : bool
    6810           0 : OwningLongSequenceOrNullOrLong::TrySetToLongSequence(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    6811             : {
    6812           0 :   tryNext = false;
    6813             :   { // scope for memberSlot
    6814           0 :     Sequence<int32_t>& memberSlot = RawSetAsLongSequence();
    6815           0 :     JS::ForOfIterator iter(cx);
    6816           0 :     if (!iter.init(value, JS::ForOfIterator::AllowNonIterable)) {
    6817           0 :       return false;
    6818             :     }
    6819           0 :     if (!iter.valueIsIterable()) {
    6820           0 :       DestroyLongSequence();
    6821           0 :       tryNext = true;
    6822           0 :       return true;
    6823             :     }
    6824           0 :     Sequence<int32_t> &arr = memberSlot;
    6825           0 :     JS::Rooted<JS::Value> temp(cx);
    6826             :     while (true) {
    6827             :       bool done;
    6828           0 :       if (!iter.next(&temp, &done)) {
    6829           0 :         return false;
    6830             :       }
    6831           0 :       if (done) {
    6832           0 :         break;
    6833             :       }
    6834           0 :       int32_t* slotPtr = arr.AppendElement(mozilla::fallible);
    6835           0 :       if (!slotPtr) {
    6836           0 :         JS_ReportOutOfMemory(cx);
    6837           0 :         return false;
    6838             :       }
    6839           0 :       int32_t& slot = *slotPtr;
    6840           0 :       if (!ValueToPrimitive<int32_t, eDefault>(cx, temp, &slot)) {
    6841           0 :         return false;
    6842             :       }
    6843           0 :     }
    6844             :   }
    6845           0 :   return true;
    6846             : }
    6847             : 
    6848             : void
    6849           0 : OwningLongSequenceOrNullOrLong::DestroyLongSequence()
    6850             : {
    6851           0 :   MOZ_ASSERT(IsLongSequence(), "Wrong type!");
    6852           0 :   mValue.mLongSequence.Destroy();
    6853           0 :   mType = eUninitialized;
    6854           0 : }
    6855             : 
    6856             : 
    6857             : 
    6858             : 
    6859             : int32_t&
    6860           0 : OwningLongSequenceOrNullOrLong::RawSetAsLong()
    6861             : {
    6862           0 :   if (mType == eLong) {
    6863           0 :     return mValue.mLong.Value();
    6864             :   }
    6865           0 :   MOZ_ASSERT(mType == eUninitialized);
    6866           0 :   mType = eLong;
    6867           0 :   return mValue.mLong.SetValue();
    6868             : }
    6869             : 
    6870             : int32_t&
    6871           0 : OwningLongSequenceOrNullOrLong::SetAsLong()
    6872             : {
    6873           0 :   if (mType == eLong) {
    6874           0 :     return mValue.mLong.Value();
    6875             :   }
    6876           0 :   Uninit();
    6877           0 :   mType = eLong;
    6878           0 :   return mValue.mLong.SetValue();
    6879             : }
    6880             : 
    6881             : bool
    6882           0 : OwningLongSequenceOrNullOrLong::TrySetToLong(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    6883             : {
    6884           0 :   tryNext = false;
    6885             :   { // scope for memberSlot
    6886           0 :     int32_t& memberSlot = RawSetAsLong();
    6887           0 :     if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
    6888           0 :       return false;
    6889             :     }
    6890             :   }
    6891           0 :   return true;
    6892             : }
    6893             : 
    6894             : void
    6895           0 : OwningLongSequenceOrNullOrLong::DestroyLong()
    6896             : {
    6897           0 :   MOZ_ASSERT(IsLong(), "Wrong type!");
    6898           0 :   mValue.mLong.Destroy();
    6899           0 :   mType = eUninitialized;
    6900           0 : }
    6901             : 
    6902             : 
    6903             : 
    6904             : 
    6905             : void
    6906           0 : OwningLongSequenceOrNullOrLong::Uninit()
    6907             : {
    6908           0 :   switch (mType) {
    6909             :     case eUninitialized: {
    6910           0 :       break;
    6911             :     }
    6912             :     case eNull: {
    6913           0 :       break;
    6914             :     }
    6915             :     case eLongSequence: {
    6916           0 :       DestroyLongSequence();
    6917           0 :       break;
    6918             :     }
    6919             :     case eLong: {
    6920           0 :       DestroyLong();
    6921           0 :       break;
    6922             :     }
    6923             :   }
    6924           0 : }
    6925             : 
    6926             : bool
    6927           0 : OwningLongSequenceOrNullOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    6928             : {
    6929           0 :   switch (mType) {
    6930             :     case eUninitialized: {
    6931           0 :       return false;
    6932             :       break;
    6933             :     }
    6934             :     case eNull: {
    6935           0 :       rval.setNull();
    6936           0 :       return true;
    6937             :       break;
    6938             :     }
    6939             :     case eLongSequence: {
    6940             : 
    6941           0 :       uint32_t length = mValue.mLongSequence.Value().Length();
    6942           0 :       JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
    6943           0 :       if (!returnArray) {
    6944           0 :         return false;
    6945             :       }
    6946             :       // Scope for 'tmp'
    6947             :       {
    6948           0 :         JS::Rooted<JS::Value> tmp(cx);
    6949           0 :         for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
    6950             :           // Control block to let us common up the JS_DefineElement calls when there
    6951             :           // are different ways to succeed at wrapping the object.
    6952             :           do {
    6953           0 :             tmp.setInt32(int32_t(mValue.mLongSequence.Value()[sequenceIdx0]));
    6954           0 :             break;
    6955             :           } while (0);
    6956           0 :           if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
    6957             :                                 JSPROP_ENUMERATE)) {
    6958           0 :             return false;
    6959             :           }
    6960             :         }
    6961             :       }
    6962           0 :       rval.setObject(*returnArray);
    6963           0 :       return true;
    6964             :       break;
    6965             :     }
    6966             :     case eLong: {
    6967           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    6968           0 :       return true;
    6969             :       break;
    6970             :     }
    6971             :     default: {
    6972           0 :       return false;
    6973             :       break;
    6974             :     }
    6975             :   }
    6976             : 
    6977             :   return false;
    6978             : }
    6979             : 
    6980             : void
    6981           0 : OwningLongSequenceOrNullOrLong::TraceUnion(JSTracer* trc)
    6982             : {
    6983           0 : }
    6984             : 
    6985             : OwningLongSequenceOrNullOrLong&
    6986           0 : OwningLongSequenceOrNullOrLong::operator=(const OwningLongSequenceOrNullOrLong& aOther)
    6987             : {
    6988           0 :   switch (aOther.mType) {
    6989             :     case eUninitialized: {
    6990           0 :       MOZ_ASSERT(mType == eUninitialized,
    6991             :                  "We need to destroy ourselves?");
    6992           0 :       break;
    6993             :     }
    6994             :     case eNull: {
    6995           0 :       MOZ_ASSERT(mType == eUninitialized);
    6996           0 :       mType = eNull;
    6997           0 :       break;
    6998             :     }
    6999             :     case eLongSequence: {
    7000           0 :       SetAsLongSequence() = aOther.GetAsLongSequence();
    7001           0 :       break;
    7002             :     }
    7003             :     case eLong: {
    7004           0 :       SetAsLong() = aOther.GetAsLong();
    7005           0 :       break;
    7006             :     }
    7007             :   }
    7008           0 :   return *this;
    7009             : }
    7010             : 
    7011             : OwningNonNull<nsINode>&
    7012           0 : OwningNodeOrLongOrBoolean::RawSetAsNode()
    7013             : {
    7014           0 :   if (mType == eNode) {
    7015           0 :     return mValue.mNode.Value();
    7016             :   }
    7017           0 :   MOZ_ASSERT(mType == eUninitialized);
    7018           0 :   mType = eNode;
    7019           0 :   return mValue.mNode.SetValue();
    7020             : }
    7021             : 
    7022             : OwningNonNull<nsINode>&
    7023           0 : OwningNodeOrLongOrBoolean::SetAsNode()
    7024             : {
    7025           0 :   if (mType == eNode) {
    7026           0 :     return mValue.mNode.Value();
    7027             :   }
    7028           0 :   Uninit();
    7029           0 :   mType = eNode;
    7030           0 :   return mValue.mNode.SetValue();
    7031             : }
    7032             : 
    7033             : bool
    7034           0 : OwningNodeOrLongOrBoolean::TrySetToNode(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    7035             : {
    7036           0 :   tryNext = false;
    7037             :   { // scope for memberSlot
    7038           0 :     OwningNonNull<nsINode>& memberSlot = RawSetAsNode();
    7039             :     static_assert(IsRefcounted<nsINode>::value, "We can only store refcounted classes.");{
    7040           0 :       nsresult rv = UnwrapObject<prototypes::id::Node, nsINode>(value, memberSlot);
    7041           0 :       if (NS_FAILED(rv)) {
    7042           0 :         DestroyNode();
    7043           0 :         tryNext = true;
    7044           0 :         return true;
    7045             :       }
    7046             :     }
    7047             :   }
    7048           0 :   return true;
    7049             : }
    7050             : 
    7051             : void
    7052           0 : OwningNodeOrLongOrBoolean::DestroyNode()
    7053             : {
    7054           0 :   MOZ_ASSERT(IsNode(), "Wrong type!");
    7055           0 :   mValue.mNode.Destroy();
    7056           0 :   mType = eUninitialized;
    7057           0 : }
    7058             : 
    7059             : 
    7060             : 
    7061             : 
    7062             : int32_t&
    7063           0 : OwningNodeOrLongOrBoolean::RawSetAsLong()
    7064             : {
    7065           0 :   if (mType == eLong) {
    7066           0 :     return mValue.mLong.Value();
    7067             :   }
    7068           0 :   MOZ_ASSERT(mType == eUninitialized);
    7069           0 :   mType = eLong;
    7070           0 :   return mValue.mLong.SetValue();
    7071             : }
    7072             : 
    7073             : int32_t&
    7074           0 : OwningNodeOrLongOrBoolean::SetAsLong()
    7075             : {
    7076           0 :   if (mType == eLong) {
    7077           0 :     return mValue.mLong.Value();
    7078             :   }
    7079           0 :   Uninit();
    7080           0 :   mType = eLong;
    7081           0 :   return mValue.mLong.SetValue();
    7082             : }
    7083             : 
    7084             : bool
    7085           0 : OwningNodeOrLongOrBoolean::TrySetToLong(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    7086             : {
    7087           0 :   tryNext = false;
    7088             :   { // scope for memberSlot
    7089           0 :     int32_t& memberSlot = RawSetAsLong();
    7090           0 :     if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
    7091           0 :       return false;
    7092             :     }
    7093             :   }
    7094           0 :   return true;
    7095             : }
    7096             : 
    7097             : void
    7098           0 : OwningNodeOrLongOrBoolean::DestroyLong()
    7099             : {
    7100           0 :   MOZ_ASSERT(IsLong(), "Wrong type!");
    7101           0 :   mValue.mLong.Destroy();
    7102           0 :   mType = eUninitialized;
    7103           0 : }
    7104             : 
    7105             : 
    7106             : 
    7107             : 
    7108             : bool&
    7109           0 : OwningNodeOrLongOrBoolean::RawSetAsBoolean()
    7110             : {
    7111           0 :   if (mType == eBoolean) {
    7112           0 :     return mValue.mBoolean.Value();
    7113             :   }
    7114           0 :   MOZ_ASSERT(mType == eUninitialized);
    7115           0 :   mType = eBoolean;
    7116           0 :   return mValue.mBoolean.SetValue();
    7117             : }
    7118             : 
    7119             : bool&
    7120           0 : OwningNodeOrLongOrBoolean::SetAsBoolean()
    7121             : {
    7122           0 :   if (mType == eBoolean) {
    7123           0 :     return mValue.mBoolean.Value();
    7124             :   }
    7125           0 :   Uninit();
    7126           0 :   mType = eBoolean;
    7127           0 :   return mValue.mBoolean.SetValue();
    7128             : }
    7129             : 
    7130             : bool
    7131           0 : OwningNodeOrLongOrBoolean::TrySetToBoolean(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    7132             : {
    7133           0 :   tryNext = false;
    7134             :   { // scope for memberSlot
    7135           0 :     bool& memberSlot = RawSetAsBoolean();
    7136           0 :     if (!ValueToPrimitive<bool, eDefault>(cx, value, &memberSlot)) {
    7137           0 :       return false;
    7138             :     }
    7139             :   }
    7140           0 :   return true;
    7141             : }
    7142             : 
    7143             : void
    7144           0 : OwningNodeOrLongOrBoolean::DestroyBoolean()
    7145             : {
    7146           0 :   MOZ_ASSERT(IsBoolean(), "Wrong type!");
    7147           0 :   mValue.mBoolean.Destroy();
    7148           0 :   mType = eUninitialized;
    7149           0 : }
    7150             : 
    7151             : 
    7152             : 
    7153             : 
    7154             : void
    7155           0 : OwningNodeOrLongOrBoolean::Uninit()
    7156             : {
    7157           0 :   switch (mType) {
    7158             :     case eUninitialized: {
    7159           0 :       break;
    7160             :     }
    7161             :     case eNode: {
    7162           0 :       DestroyNode();
    7163           0 :       break;
    7164             :     }
    7165             :     case eLong: {
    7166           0 :       DestroyLong();
    7167           0 :       break;
    7168             :     }
    7169             :     case eBoolean: {
    7170           0 :       DestroyBoolean();
    7171           0 :       break;
    7172             :     }
    7173             :   }
    7174           0 : }
    7175             : 
    7176             : bool
    7177           0 : OwningNodeOrLongOrBoolean::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    7178             : {
    7179           0 :   switch (mType) {
    7180             :     case eUninitialized: {
    7181           0 :       return false;
    7182             :       break;
    7183             :     }
    7184             :     case eNode: {
    7185           0 :       if (!GetOrCreateDOMReflector(cx, mValue.mNode.Value(), rval)) {
    7186           0 :         MOZ_ASSERT(true || JS_IsExceptionPending(cx));
    7187           0 :         return false;
    7188             :       }
    7189           0 :       return true;
    7190             :       break;
    7191             :     }
    7192             :     case eLong: {
    7193           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    7194           0 :       return true;
    7195             :       break;
    7196             :     }
    7197             :     case eBoolean: {
    7198           0 :       rval.setBoolean(mValue.mBoolean.Value());
    7199           0 :       return true;
    7200             :       break;
    7201             :     }
    7202             :     default: {
    7203           0 :       return false;
    7204             :       break;
    7205             :     }
    7206             :   }
    7207             : 
    7208             :   return false;
    7209             : }
    7210             : 
    7211             : void
    7212           0 : OwningNodeOrLongOrBoolean::TraceUnion(JSTracer* trc)
    7213             : {
    7214           0 : }
    7215             : 
    7216             : OwningNodeOrLongOrBoolean&
    7217           0 : OwningNodeOrLongOrBoolean::operator=(const OwningNodeOrLongOrBoolean& aOther)
    7218             : {
    7219           0 :   switch (aOther.mType) {
    7220             :     case eUninitialized: {
    7221           0 :       MOZ_ASSERT(mType == eUninitialized,
    7222             :                  "We need to destroy ourselves?");
    7223           0 :       break;
    7224             :     }
    7225             :     case eNode: {
    7226           0 :       SetAsNode() = aOther.GetAsNode();
    7227           0 :       break;
    7228             :     }
    7229             :     case eLong: {
    7230           0 :       SetAsLong() = aOther.GetAsLong();
    7231           0 :       break;
    7232             :     }
    7233             :     case eBoolean: {
    7234           0 :       SetAsBoolean() = aOther.GetAsBoolean();
    7235           0 :       break;
    7236             :     }
    7237             :   }
    7238           0 :   return *this;
    7239             : }
    7240             : 
    7241             : OwningNonNull<nsINode>&
    7242           0 : OwningNodeOrString::RawSetAsNode()
    7243             : {
    7244           0 :   if (mType == eNode) {
    7245           0 :     return mValue.mNode.Value();
    7246             :   }
    7247           0 :   MOZ_ASSERT(mType == eUninitialized);
    7248           0 :   mType = eNode;
    7249           0 :   return mValue.mNode.SetValue();
    7250             : }
    7251             : 
    7252             : OwningNonNull<nsINode>&
    7253           0 : OwningNodeOrString::SetAsNode()
    7254             : {
    7255           0 :   if (mType == eNode) {
    7256           0 :     return mValue.mNode.Value();
    7257             :   }
    7258           0 :   Uninit();
    7259           0 :   mType = eNode;
    7260           0 :   return mValue.mNode.SetValue();
    7261             : }
    7262             : 
    7263             : bool
    7264           0 : OwningNodeOrString::TrySetToNode(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    7265             : {
    7266           0 :   tryNext = false;
    7267             :   { // scope for memberSlot
    7268           0 :     OwningNonNull<nsINode>& memberSlot = RawSetAsNode();
    7269             :     static_assert(IsRefcounted<nsINode>::value, "We can only store refcounted classes.");{
    7270           0 :       nsresult rv = UnwrapObject<prototypes::id::Node, nsINode>(value, memberSlot);
    7271           0 :       if (NS_FAILED(rv)) {
    7272           0 :         DestroyNode();
    7273           0 :         tryNext = true;
    7274           0 :         return true;
    7275             :       }
    7276             :     }
    7277             :   }
    7278           0 :   return true;
    7279             : }
    7280             : 
    7281             : void
    7282           0 : OwningNodeOrString::DestroyNode()
    7283             : {
    7284           0 :   MOZ_ASSERT(IsNode(), "Wrong type!");
    7285           0 :   mValue.mNode.Destroy();
    7286           0 :   mType = eUninitialized;
    7287           0 : }
    7288             : 
    7289             : 
    7290             : 
    7291             : 
    7292             : nsString&
    7293           0 : OwningNodeOrString::RawSetAsString()
    7294             : {
    7295           0 :   if (mType == eString) {
    7296           0 :     return mValue.mString.Value();
    7297             :   }
    7298           0 :   MOZ_ASSERT(mType == eUninitialized);
    7299           0 :   mType = eString;
    7300           0 :   return mValue.mString.SetValue();
    7301             : }
    7302             : 
    7303             : nsString&
    7304           0 : OwningNodeOrString::SetAsString()
    7305             : {
    7306           0 :   if (mType == eString) {
    7307           0 :     return mValue.mString.Value();
    7308             :   }
    7309           0 :   Uninit();
    7310           0 :   mType = eString;
    7311           0 :   return mValue.mString.SetValue();
    7312             : }
    7313             : 
    7314             : bool
    7315           0 : OwningNodeOrString::TrySetToString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    7316             : {
    7317           0 :   tryNext = false;
    7318             :   { // scope for memberSlot
    7319           0 :     nsString& memberSlot = RawSetAsString();
    7320           0 :     if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
    7321           0 :       return false;
    7322             :     }
    7323             :   }
    7324           0 :   return true;
    7325             : }
    7326             : 
    7327             : 
    7328             : void
    7329           0 : OwningNodeOrString::DestroyString()
    7330             : {
    7331           0 :   MOZ_ASSERT(IsString(), "Wrong type!");
    7332           0 :   mValue.mString.Destroy();
    7333           0 :   mType = eUninitialized;
    7334           0 : }
    7335             : 
    7336             : 
    7337             : 
    7338             : 
    7339             : void
    7340           0 : OwningNodeOrString::Uninit()
    7341             : {
    7342           0 :   switch (mType) {
    7343             :     case eUninitialized: {
    7344           0 :       break;
    7345             :     }
    7346             :     case eNode: {
    7347           0 :       DestroyNode();
    7348           0 :       break;
    7349             :     }
    7350             :     case eString: {
    7351           0 :       DestroyString();
    7352           0 :       break;
    7353             :     }
    7354             :   }
    7355           0 : }
    7356             : 
    7357             : bool
    7358           0 : OwningNodeOrString::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    7359             : {
    7360           0 :   switch (mType) {
    7361             :     case eUninitialized: {
    7362           0 :       return false;
    7363             :       break;
    7364             :     }
    7365             :     case eNode: {
    7366           0 :       if (!GetOrCreateDOMReflector(cx, mValue.mNode.Value(), rval)) {
    7367           0 :         MOZ_ASSERT(true || JS_IsExceptionPending(cx));
    7368           0 :         return false;
    7369             :       }
    7370           0 :       return true;
    7371             :       break;
    7372             :     }
    7373             :     case eString: {
    7374           0 :       if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) {
    7375           0 :         return false;
    7376             :       }
    7377           0 :       return true;
    7378             :       break;
    7379             :     }
    7380             :     default: {
    7381           0 :       return false;
    7382             :       break;
    7383             :     }
    7384             :   }
    7385             : 
    7386             :   return false;
    7387             : }
    7388             : 
    7389             : void
    7390           0 : OwningNodeOrString::TraceUnion(JSTracer* trc)
    7391             : {
    7392           0 : }
    7393             : 
    7394             : OwningNodeOrString&
    7395           0 : OwningNodeOrString::operator=(const OwningNodeOrString& aOther)
    7396             : {
    7397           0 :   switch (aOther.mType) {
    7398             :     case eUninitialized: {
    7399           0 :       MOZ_ASSERT(mType == eUninitialized,
    7400             :                  "We need to destroy ourselves?");
    7401           0 :       break;
    7402             :     }
    7403             :     case eNode: {
    7404           0 :       SetAsNode() = aOther.GetAsNode();
    7405           0 :       break;
    7406             :     }
    7407             :     case eString: {
    7408           0 :       SetAsString() = aOther.GetAsString();
    7409           0 :       break;
    7410             :     }
    7411             :   }
    7412           0 :   return *this;
    7413             : }
    7414             : 
    7415             : JSObject*&
    7416           0 : OwningObjectOrBoolean::RawSetAsObject()
    7417             : {
    7418           0 :   if (mType == eObject) {
    7419           0 :     return mValue.mObject.Value();
    7420             :   }
    7421           0 :   MOZ_ASSERT(mType == eUninitialized);
    7422           0 :   mType = eObject;
    7423           0 :   return mValue.mObject.SetValue();
    7424             : }
    7425             : 
    7426             : JSObject*&
    7427           0 : OwningObjectOrBoolean::SetAsObject()
    7428             : {
    7429           0 :   if (mType == eObject) {
    7430           0 :     return mValue.mObject.Value();
    7431             :   }
    7432           0 :   Uninit();
    7433           0 :   mType = eObject;
    7434           0 :   return mValue.mObject.SetValue();
    7435             : }
    7436             : 
    7437             : 
    7438             : void
    7439           0 : OwningObjectOrBoolean::DestroyObject()
    7440             : {
    7441           0 :   MOZ_ASSERT(IsObject(), "Wrong type!");
    7442           0 :   mValue.mObject.Destroy();
    7443           0 :   mType = eUninitialized;
    7444           0 : }
    7445             : 
    7446             : 
    7447             : 
    7448             : 
    7449             : bool&
    7450           0 : OwningObjectOrBoolean::RawSetAsBoolean()
    7451             : {
    7452           0 :   if (mType == eBoolean) {
    7453           0 :     return mValue.mBoolean.Value();
    7454             :   }
    7455           0 :   MOZ_ASSERT(mType == eUninitialized);
    7456           0 :   mType = eBoolean;
    7457           0 :   return mValue.mBoolean.SetValue();
    7458             : }
    7459             : 
    7460             : bool&
    7461           0 : OwningObjectOrBoolean::SetAsBoolean()
    7462             : {
    7463           0 :   if (mType == eBoolean) {
    7464           0 :     return mValue.mBoolean.Value();
    7465             :   }
    7466           0 :   Uninit();
    7467           0 :   mType = eBoolean;
    7468           0 :   return mValue.mBoolean.SetValue();
    7469             : }
    7470             : 
    7471             : bool
    7472           0 : OwningObjectOrBoolean::TrySetToBoolean(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    7473             : {
    7474           0 :   tryNext = false;
    7475             :   { // scope for memberSlot
    7476           0 :     bool& memberSlot = RawSetAsBoolean();
    7477           0 :     if (!ValueToPrimitive<bool, eDefault>(cx, value, &memberSlot)) {
    7478           0 :       return false;
    7479             :     }
    7480             :   }
    7481           0 :   return true;
    7482             : }
    7483             : 
    7484             : void
    7485           0 : OwningObjectOrBoolean::DestroyBoolean()
    7486             : {
    7487           0 :   MOZ_ASSERT(IsBoolean(), "Wrong type!");
    7488           0 :   mValue.mBoolean.Destroy();
    7489           0 :   mType = eUninitialized;
    7490           0 : }
    7491             : 
    7492             : 
    7493             : 
    7494             : 
    7495             : void
    7496           0 : OwningObjectOrBoolean::Uninit()
    7497             : {
    7498           0 :   switch (mType) {
    7499             :     case eUninitialized: {
    7500           0 :       break;
    7501             :     }
    7502             :     case eObject: {
    7503           0 :       DestroyObject();
    7504           0 :       break;
    7505             :     }
    7506             :     case eBoolean: {
    7507           0 :       DestroyBoolean();
    7508           0 :       break;
    7509             :     }
    7510             :   }
    7511           0 : }
    7512             : 
    7513             : bool
    7514           0 : OwningObjectOrBoolean::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    7515             : {
    7516           0 :   switch (mType) {
    7517             :     case eUninitialized: {
    7518           0 :       return false;
    7519             :       break;
    7520             :     }
    7521             :     case eObject: {
    7522           0 :       JS::ExposeObjectToActiveJS(mValue.mObject.Value());
    7523           0 :       rval.setObject(*mValue.mObject.Value());
    7524           0 :       if (!MaybeWrapObjectValue(cx, rval)) {
    7525           0 :         return false;
    7526             :       }
    7527           0 :       return true;
    7528             :       break;
    7529             :     }
    7530             :     case eBoolean: {
    7531           0 :       rval.setBoolean(mValue.mBoolean.Value());
    7532           0 :       return true;
    7533             :       break;
    7534             :     }
    7535             :     default: {
    7536           0 :       return false;
    7537             :       break;
    7538             :     }
    7539             :   }
    7540             : 
    7541             :   return false;
    7542             : }
    7543             : 
    7544             : void
    7545           0 : OwningObjectOrBoolean::TraceUnion(JSTracer* trc)
    7546             : {
    7547           0 :   switch (mType) {
    7548             :     case eObject: {
    7549           0 :       JS::UnsafeTraceRoot(trc, &mValue.mObject.Value(), "mValue.mObject");
    7550           0 :       break;
    7551             :     }
    7552             :     default: {
    7553           0 :       break;
    7554             :     }
    7555             :   }
    7556           0 : }
    7557             : 
    7558             : JSObject*&
    7559           0 : OwningObjectOrLong::RawSetAsObject()
    7560             : {
    7561           0 :   if (mType == eObject) {
    7562           0 :     return mValue.mObject.Value();
    7563             :   }
    7564           0 :   MOZ_ASSERT(mType == eUninitialized);
    7565           0 :   mType = eObject;
    7566           0 :   return mValue.mObject.SetValue();
    7567             : }
    7568             : 
    7569             : JSObject*&
    7570           0 : OwningObjectOrLong::SetAsObject()
    7571             : {
    7572           0 :   if (mType == eObject) {
    7573           0 :     return mValue.mObject.Value();
    7574             :   }
    7575           0 :   Uninit();
    7576           0 :   mType = eObject;
    7577           0 :   return mValue.mObject.SetValue();
    7578             : }
    7579             : 
    7580             : 
    7581             : void
    7582           0 : OwningObjectOrLong::DestroyObject()
    7583             : {
    7584           0 :   MOZ_ASSERT(IsObject(), "Wrong type!");
    7585           0 :   mValue.mObject.Destroy();
    7586           0 :   mType = eUninitialized;
    7587           0 : }
    7588             : 
    7589             : 
    7590             : 
    7591             : 
    7592             : int32_t&
    7593           0 : OwningObjectOrLong::RawSetAsLong()
    7594             : {
    7595           0 :   if (mType == eLong) {
    7596           0 :     return mValue.mLong.Value();
    7597             :   }
    7598           0 :   MOZ_ASSERT(mType == eUninitialized);
    7599           0 :   mType = eLong;
    7600           0 :   return mValue.mLong.SetValue();
    7601             : }
    7602             : 
    7603             : int32_t&
    7604           0 : OwningObjectOrLong::SetAsLong()
    7605             : {
    7606           0 :   if (mType == eLong) {
    7607           0 :     return mValue.mLong.Value();
    7608             :   }
    7609           0 :   Uninit();
    7610           0 :   mType = eLong;
    7611           0 :   return mValue.mLong.SetValue();
    7612             : }
    7613             : 
    7614             : bool
    7615           0 : OwningObjectOrLong::TrySetToLong(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    7616             : {
    7617           0 :   tryNext = false;
    7618             :   { // scope for memberSlot
    7619           0 :     int32_t& memberSlot = RawSetAsLong();
    7620           0 :     if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
    7621           0 :       return false;
    7622             :     }
    7623             :   }
    7624           0 :   return true;
    7625             : }
    7626             : 
    7627             : void
    7628           0 : OwningObjectOrLong::DestroyLong()
    7629             : {
    7630           0 :   MOZ_ASSERT(IsLong(), "Wrong type!");
    7631           0 :   mValue.mLong.Destroy();
    7632           0 :   mType = eUninitialized;
    7633           0 : }
    7634             : 
    7635             : 
    7636             : 
    7637             : 
    7638             : void
    7639           0 : OwningObjectOrLong::Uninit()
    7640             : {
    7641           0 :   switch (mType) {
    7642             :     case eUninitialized: {
    7643           0 :       break;
    7644             :     }
    7645             :     case eObject: {
    7646           0 :       DestroyObject();
    7647           0 :       break;
    7648             :     }
    7649             :     case eLong: {
    7650           0 :       DestroyLong();
    7651           0 :       break;
    7652             :     }
    7653             :   }
    7654           0 : }
    7655             : 
    7656             : bool
    7657           0 : OwningObjectOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    7658             : {
    7659           0 :   switch (mType) {
    7660             :     case eUninitialized: {
    7661           0 :       return false;
    7662             :       break;
    7663             :     }
    7664             :     case eObject: {
    7665           0 :       JS::ExposeObjectToActiveJS(mValue.mObject.Value());
    7666           0 :       rval.setObject(*mValue.mObject.Value());
    7667           0 :       if (!MaybeWrapObjectValue(cx, rval)) {
    7668           0 :         return false;
    7669             :       }
    7670           0 :       return true;
    7671             :       break;
    7672             :     }
    7673             :     case eLong: {
    7674           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    7675           0 :       return true;
    7676             :       break;
    7677             :     }
    7678             :     default: {
    7679           0 :       return false;
    7680             :       break;
    7681             :     }
    7682             :   }
    7683             : 
    7684             :   return false;
    7685             : }
    7686             : 
    7687             : void
    7688           0 : OwningObjectOrLong::TraceUnion(JSTracer* trc)
    7689             : {
    7690           0 :   switch (mType) {
    7691             :     case eObject: {
    7692           0 :       JS::UnsafeTraceRoot(trc, &mValue.mObject.Value(), "mValue.mObject");
    7693           0 :       break;
    7694             :     }
    7695             :     default: {
    7696           0 :       break;
    7697             :     }
    7698             :   }
    7699           0 : }
    7700             : 
    7701             : JSObject*&
    7702           0 : OwningObjectOrLongOrBoolean::RawSetAsObject()
    7703             : {
    7704           0 :   if (mType == eObject) {
    7705           0 :     return mValue.mObject.Value();
    7706             :   }
    7707           0 :   MOZ_ASSERT(mType == eUninitialized);
    7708           0 :   mType = eObject;
    7709           0 :   return mValue.mObject.SetValue();
    7710             : }
    7711             : 
    7712             : JSObject*&
    7713           0 : OwningObjectOrLongOrBoolean::SetAsObject()
    7714             : {
    7715           0 :   if (mType == eObject) {
    7716           0 :     return mValue.mObject.Value();
    7717             :   }
    7718           0 :   Uninit();
    7719           0 :   mType = eObject;
    7720           0 :   return mValue.mObject.SetValue();
    7721             : }
    7722             : 
    7723             : 
    7724             : void
    7725           0 : OwningObjectOrLongOrBoolean::DestroyObject()
    7726             : {
    7727           0 :   MOZ_ASSERT(IsObject(), "Wrong type!");
    7728           0 :   mValue.mObject.Destroy();
    7729           0 :   mType = eUninitialized;
    7730           0 : }
    7731             : 
    7732             : 
    7733             : 
    7734             : 
    7735             : int32_t&
    7736           0 : OwningObjectOrLongOrBoolean::RawSetAsLong()
    7737             : {
    7738           0 :   if (mType == eLong) {
    7739           0 :     return mValue.mLong.Value();
    7740             :   }
    7741           0 :   MOZ_ASSERT(mType == eUninitialized);
    7742           0 :   mType = eLong;
    7743           0 :   return mValue.mLong.SetValue();
    7744             : }
    7745             : 
    7746             : int32_t&
    7747           0 : OwningObjectOrLongOrBoolean::SetAsLong()
    7748             : {
    7749           0 :   if (mType == eLong) {
    7750           0 :     return mValue.mLong.Value();
    7751             :   }
    7752           0 :   Uninit();
    7753           0 :   mType = eLong;
    7754           0 :   return mValue.mLong.SetValue();
    7755             : }
    7756             : 
    7757             : bool
    7758           0 : OwningObjectOrLongOrBoolean::TrySetToLong(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    7759             : {
    7760           0 :   tryNext = false;
    7761             :   { // scope for memberSlot
    7762           0 :     int32_t& memberSlot = RawSetAsLong();
    7763           0 :     if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
    7764           0 :       return false;
    7765             :     }
    7766             :   }
    7767           0 :   return true;
    7768             : }
    7769             : 
    7770             : void
    7771           0 : OwningObjectOrLongOrBoolean::DestroyLong()
    7772             : {
    7773           0 :   MOZ_ASSERT(IsLong(), "Wrong type!");
    7774           0 :   mValue.mLong.Destroy();
    7775           0 :   mType = eUninitialized;
    7776           0 : }
    7777             : 
    7778             : 
    7779             : 
    7780             : 
    7781             : bool&
    7782           0 : OwningObjectOrLongOrBoolean::RawSetAsBoolean()
    7783             : {
    7784           0 :   if (mType == eBoolean) {
    7785           0 :     return mValue.mBoolean.Value();
    7786             :   }
    7787           0 :   MOZ_ASSERT(mType == eUninitialized);
    7788           0 :   mType = eBoolean;
    7789           0 :   return mValue.mBoolean.SetValue();
    7790             : }
    7791             : 
    7792             : bool&
    7793           0 : OwningObjectOrLongOrBoolean::SetAsBoolean()
    7794             : {
    7795           0 :   if (mType == eBoolean) {
    7796           0 :     return mValue.mBoolean.Value();
    7797             :   }
    7798           0 :   Uninit();
    7799           0 :   mType = eBoolean;
    7800           0 :   return mValue.mBoolean.SetValue();
    7801             : }
    7802             : 
    7803             : bool
    7804           0 : OwningObjectOrLongOrBoolean::TrySetToBoolean(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    7805             : {
    7806           0 :   tryNext = false;
    7807             :   { // scope for memberSlot
    7808           0 :     bool& memberSlot = RawSetAsBoolean();
    7809           0 :     if (!ValueToPrimitive<bool, eDefault>(cx, value, &memberSlot)) {
    7810           0 :       return false;
    7811             :     }
    7812             :   }
    7813           0 :   return true;
    7814             : }
    7815             : 
    7816             : void
    7817           0 : OwningObjectOrLongOrBoolean::DestroyBoolean()
    7818             : {
    7819           0 :   MOZ_ASSERT(IsBoolean(), "Wrong type!");
    7820           0 :   mValue.mBoolean.Destroy();
    7821           0 :   mType = eUninitialized;
    7822           0 : }
    7823             : 
    7824             : 
    7825             : 
    7826             : 
    7827             : void
    7828           0 : OwningObjectOrLongOrBoolean::Uninit()
    7829             : {
    7830           0 :   switch (mType) {
    7831             :     case eUninitialized: {
    7832           0 :       break;
    7833             :     }
    7834             :     case eObject: {
    7835           0 :       DestroyObject();
    7836           0 :       break;
    7837             :     }
    7838             :     case eLong: {
    7839           0 :       DestroyLong();
    7840           0 :       break;
    7841             :     }
    7842             :     case eBoolean: {
    7843           0 :       DestroyBoolean();
    7844           0 :       break;
    7845             :     }
    7846             :   }
    7847           0 : }
    7848             : 
    7849             : bool
    7850           0 : OwningObjectOrLongOrBoolean::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    7851             : {
    7852           0 :   switch (mType) {
    7853             :     case eUninitialized: {
    7854           0 :       return false;
    7855             :       break;
    7856             :     }
    7857             :     case eObject: {
    7858           0 :       JS::ExposeObjectToActiveJS(mValue.mObject.Value());
    7859           0 :       rval.setObject(*mValue.mObject.Value());
    7860           0 :       if (!MaybeWrapObjectValue(cx, rval)) {
    7861           0 :         return false;
    7862             :       }
    7863           0 :       return true;
    7864             :       break;
    7865             :     }
    7866             :     case eLong: {
    7867           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    7868           0 :       return true;
    7869             :       break;
    7870             :     }
    7871             :     case eBoolean: {
    7872           0 :       rval.setBoolean(mValue.mBoolean.Value());
    7873           0 :       return true;
    7874             :       break;
    7875             :     }
    7876             :     default: {
    7877           0 :       return false;
    7878             :       break;
    7879             :     }
    7880             :   }
    7881             : 
    7882             :   return false;
    7883             : }
    7884             : 
    7885             : void
    7886           0 : OwningObjectOrLongOrBoolean::TraceUnion(JSTracer* trc)
    7887             : {
    7888           0 :   switch (mType) {
    7889             :     case eObject: {
    7890           0 :       JS::UnsafeTraceRoot(trc, &mValue.mObject.Value(), "mValue.mObject");
    7891           0 :       break;
    7892             :     }
    7893             :     default: {
    7894           0 :       break;
    7895             :     }
    7896             :   }
    7897           0 : }
    7898             : 
    7899             : JSObject*&
    7900           0 : OwningObjectOrLongOrNull::RawSetAsObject()
    7901             : {
    7902           0 :   if (mType == eObject) {
    7903           0 :     return mValue.mObject.Value();
    7904             :   }
    7905           0 :   MOZ_ASSERT(mType == eUninitialized);
    7906           0 :   mType = eObject;
    7907           0 :   return mValue.mObject.SetValue();
    7908             : }
    7909             : 
    7910             : JSObject*&
    7911           0 : OwningObjectOrLongOrNull::SetAsObject()
    7912             : {
    7913           0 :   if (mType == eObject) {
    7914           0 :     return mValue.mObject.Value();
    7915             :   }
    7916           0 :   Uninit();
    7917           0 :   mType = eObject;
    7918           0 :   return mValue.mObject.SetValue();
    7919             : }
    7920             : 
    7921             : 
    7922             : void
    7923           0 : OwningObjectOrLongOrNull::DestroyObject()
    7924             : {
    7925           0 :   MOZ_ASSERT(IsObject(), "Wrong type!");
    7926           0 :   mValue.mObject.Destroy();
    7927           0 :   mType = eUninitialized;
    7928           0 : }
    7929             : 
    7930             : 
    7931             : 
    7932             : 
    7933             : int32_t&
    7934           0 : OwningObjectOrLongOrNull::RawSetAsLong()
    7935             : {
    7936           0 :   if (mType == eLong) {
    7937           0 :     return mValue.mLong.Value();
    7938             :   }
    7939           0 :   MOZ_ASSERT(mType == eUninitialized);
    7940           0 :   mType = eLong;
    7941           0 :   return mValue.mLong.SetValue();
    7942             : }
    7943             : 
    7944             : int32_t&
    7945           0 : OwningObjectOrLongOrNull::SetAsLong()
    7946             : {
    7947           0 :   if (mType == eLong) {
    7948           0 :     return mValue.mLong.Value();
    7949             :   }
    7950           0 :   Uninit();
    7951           0 :   mType = eLong;
    7952           0 :   return mValue.mLong.SetValue();
    7953             : }
    7954             : 
    7955             : bool
    7956           0 : OwningObjectOrLongOrNull::TrySetToLong(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    7957             : {
    7958           0 :   tryNext = false;
    7959             :   { // scope for memberSlot
    7960           0 :     int32_t& memberSlot = RawSetAsLong();
    7961           0 :     if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
    7962           0 :       return false;
    7963             :     }
    7964             :   }
    7965           0 :   return true;
    7966             : }
    7967             : 
    7968             : void
    7969           0 : OwningObjectOrLongOrNull::DestroyLong()
    7970             : {
    7971           0 :   MOZ_ASSERT(IsLong(), "Wrong type!");
    7972           0 :   mValue.mLong.Destroy();
    7973           0 :   mType = eUninitialized;
    7974           0 : }
    7975             : 
    7976             : 
    7977             : 
    7978             : 
    7979             : void
    7980           0 : OwningObjectOrLongOrNull::Uninit()
    7981             : {
    7982           0 :   switch (mType) {
    7983             :     case eUninitialized: {
    7984           0 :       break;
    7985             :     }
    7986             :     case eNull: {
    7987           0 :       break;
    7988             :     }
    7989             :     case eObject: {
    7990           0 :       DestroyObject();
    7991           0 :       break;
    7992             :     }
    7993             :     case eLong: {
    7994           0 :       DestroyLong();
    7995           0 :       break;
    7996             :     }
    7997             :   }
    7998           0 : }
    7999             : 
    8000             : bool
    8001           0 : OwningObjectOrLongOrNull::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    8002             : {
    8003           0 :   switch (mType) {
    8004             :     case eUninitialized: {
    8005           0 :       return false;
    8006             :       break;
    8007             :     }
    8008             :     case eNull: {
    8009           0 :       rval.setNull();
    8010           0 :       return true;
    8011             :       break;
    8012             :     }
    8013             :     case eObject: {
    8014           0 :       JS::ExposeObjectToActiveJS(mValue.mObject.Value());
    8015           0 :       rval.setObject(*mValue.mObject.Value());
    8016           0 :       if (!MaybeWrapObjectValue(cx, rval)) {
    8017           0 :         return false;
    8018             :       }
    8019           0 :       return true;
    8020             :       break;
    8021             :     }
    8022             :     case eLong: {
    8023           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    8024           0 :       return true;
    8025             :       break;
    8026             :     }
    8027             :     default: {
    8028           0 :       return false;
    8029             :       break;
    8030             :     }
    8031             :   }
    8032             : 
    8033             :   return false;
    8034             : }
    8035             : 
    8036             : void
    8037           0 : OwningObjectOrLongOrNull::TraceUnion(JSTracer* trc)
    8038             : {
    8039           0 :   switch (mType) {
    8040             :     case eObject: {
    8041           0 :       JS::UnsafeTraceRoot(trc, &mValue.mObject.Value(), "mValue.mObject");
    8042           0 :       break;
    8043             :     }
    8044             :     default: {
    8045           0 :       break;
    8046             :     }
    8047             :   }
    8048           0 : }
    8049             : 
    8050             : JSObject*&
    8051           0 : OwningObjectOrNullOrLong::RawSetAsObject()
    8052             : {
    8053           0 :   if (mType == eObject) {
    8054           0 :     return mValue.mObject.Value();
    8055             :   }
    8056           0 :   MOZ_ASSERT(mType == eUninitialized);
    8057           0 :   mType = eObject;
    8058           0 :   return mValue.mObject.SetValue();
    8059             : }
    8060             : 
    8061             : JSObject*&
    8062           0 : OwningObjectOrNullOrLong::SetAsObject()
    8063             : {
    8064           0 :   if (mType == eObject) {
    8065           0 :     return mValue.mObject.Value();
    8066             :   }
    8067           0 :   Uninit();
    8068           0 :   mType = eObject;
    8069           0 :   return mValue.mObject.SetValue();
    8070             : }
    8071             : 
    8072             : 
    8073             : void
    8074           0 : OwningObjectOrNullOrLong::DestroyObject()
    8075             : {
    8076           0 :   MOZ_ASSERT(IsObject(), "Wrong type!");
    8077           0 :   mValue.mObject.Destroy();
    8078           0 :   mType = eUninitialized;
    8079           0 : }
    8080             : 
    8081             : 
    8082             : 
    8083             : 
    8084             : int32_t&
    8085           0 : OwningObjectOrNullOrLong::RawSetAsLong()
    8086             : {
    8087           0 :   if (mType == eLong) {
    8088           0 :     return mValue.mLong.Value();
    8089             :   }
    8090           0 :   MOZ_ASSERT(mType == eUninitialized);
    8091           0 :   mType = eLong;
    8092           0 :   return mValue.mLong.SetValue();
    8093             : }
    8094             : 
    8095             : int32_t&
    8096           0 : OwningObjectOrNullOrLong::SetAsLong()
    8097             : {
    8098           0 :   if (mType == eLong) {
    8099           0 :     return mValue.mLong.Value();
    8100             :   }
    8101           0 :   Uninit();
    8102           0 :   mType = eLong;
    8103           0 :   return mValue.mLong.SetValue();
    8104             : }
    8105             : 
    8106             : bool
    8107           0 : OwningObjectOrNullOrLong::TrySetToLong(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    8108             : {
    8109           0 :   tryNext = false;
    8110             :   { // scope for memberSlot
    8111           0 :     int32_t& memberSlot = RawSetAsLong();
    8112           0 :     if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
    8113           0 :       return false;
    8114             :     }
    8115             :   }
    8116           0 :   return true;
    8117             : }
    8118             : 
    8119             : void
    8120           0 : OwningObjectOrNullOrLong::DestroyLong()
    8121             : {
    8122           0 :   MOZ_ASSERT(IsLong(), "Wrong type!");
    8123           0 :   mValue.mLong.Destroy();
    8124           0 :   mType = eUninitialized;
    8125           0 : }
    8126             : 
    8127             : 
    8128             : 
    8129             : 
    8130             : void
    8131           0 : OwningObjectOrNullOrLong::Uninit()
    8132             : {
    8133           0 :   switch (mType) {
    8134             :     case eUninitialized: {
    8135           0 :       break;
    8136             :     }
    8137             :     case eNull: {
    8138           0 :       break;
    8139             :     }
    8140             :     case eObject: {
    8141           0 :       DestroyObject();
    8142           0 :       break;
    8143             :     }
    8144             :     case eLong: {
    8145           0 :       DestroyLong();
    8146           0 :       break;
    8147             :     }
    8148             :   }
    8149           0 : }
    8150             : 
    8151             : bool
    8152           0 : OwningObjectOrNullOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    8153             : {
    8154           0 :   switch (mType) {
    8155             :     case eUninitialized: {
    8156           0 :       return false;
    8157             :       break;
    8158             :     }
    8159             :     case eNull: {
    8160           0 :       rval.setNull();
    8161           0 :       return true;
    8162             :       break;
    8163             :     }
    8164             :     case eObject: {
    8165           0 :       JS::ExposeObjectToActiveJS(mValue.mObject.Value());
    8166           0 :       rval.setObject(*mValue.mObject.Value());
    8167           0 :       if (!MaybeWrapObjectValue(cx, rval)) {
    8168           0 :         return false;
    8169             :       }
    8170           0 :       return true;
    8171             :       break;
    8172             :     }
    8173             :     case eLong: {
    8174           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    8175           0 :       return true;
    8176             :       break;
    8177             :     }
    8178             :     default: {
    8179           0 :       return false;
    8180             :       break;
    8181             :     }
    8182             :   }
    8183             : 
    8184             :   return false;
    8185             : }
    8186             : 
    8187             : void
    8188           0 : OwningObjectOrNullOrLong::TraceUnion(JSTracer* trc)
    8189             : {
    8190           0 :   switch (mType) {
    8191             :     case eObject: {
    8192           0 :       JS::UnsafeTraceRoot(trc, &mValue.mObject.Value(), "mValue.mObject");
    8193           0 :       break;
    8194             :     }
    8195             :     default: {
    8196           0 :       break;
    8197             :     }
    8198             :   }
    8199           0 : }
    8200             : 
    8201             : JSObject*&
    8202           0 : OwningObjectOrString::RawSetAsObject()
    8203             : {
    8204           0 :   if (mType == eObject) {
    8205           0 :     return mValue.mObject.Value();
    8206             :   }
    8207           0 :   MOZ_ASSERT(mType == eUninitialized);
    8208           0 :   mType = eObject;
    8209           0 :   return mValue.mObject.SetValue();
    8210             : }
    8211             : 
    8212             : JSObject*&
    8213           0 : OwningObjectOrString::SetAsObject()
    8214             : {
    8215           0 :   if (mType == eObject) {
    8216           0 :     return mValue.mObject.Value();
    8217             :   }
    8218           0 :   Uninit();
    8219           0 :   mType = eObject;
    8220           0 :   return mValue.mObject.SetValue();
    8221             : }
    8222             : 
    8223             : 
    8224             : void
    8225           0 : OwningObjectOrString::DestroyObject()
    8226             : {
    8227           0 :   MOZ_ASSERT(IsObject(), "Wrong type!");
    8228           0 :   mValue.mObject.Destroy();
    8229           0 :   mType = eUninitialized;
    8230           0 : }
    8231             : 
    8232             : 
    8233             : 
    8234             : 
    8235             : nsString&
    8236           0 : OwningObjectOrString::RawSetAsString()
    8237             : {
    8238           0 :   if (mType == eString) {
    8239           0 :     return mValue.mString.Value();
    8240             :   }
    8241           0 :   MOZ_ASSERT(mType == eUninitialized);
    8242           0 :   mType = eString;
    8243           0 :   return mValue.mString.SetValue();
    8244             : }
    8245             : 
    8246             : nsString&
    8247           0 : OwningObjectOrString::SetAsString()
    8248             : {
    8249           0 :   if (mType == eString) {
    8250           0 :     return mValue.mString.Value();
    8251             :   }
    8252           0 :   Uninit();
    8253           0 :   mType = eString;
    8254           0 :   return mValue.mString.SetValue();
    8255             : }
    8256             : 
    8257             : bool
    8258           0 : OwningObjectOrString::TrySetToString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    8259             : {
    8260           0 :   tryNext = false;
    8261             :   { // scope for memberSlot
    8262           0 :     nsString& memberSlot = RawSetAsString();
    8263           0 :     if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
    8264           0 :       return false;
    8265             :     }
    8266             :   }
    8267           0 :   return true;
    8268             : }
    8269             : 
    8270             : 
    8271             : void
    8272           0 : OwningObjectOrString::DestroyString()
    8273             : {
    8274           0 :   MOZ_ASSERT(IsString(), "Wrong type!");
    8275           0 :   mValue.mString.Destroy();
    8276           0 :   mType = eUninitialized;
    8277           0 : }
    8278             : 
    8279             : 
    8280             : 
    8281             : 
    8282             : void
    8283           0 : OwningObjectOrString::Uninit()
    8284             : {
    8285           0 :   switch (mType) {
    8286             :     case eUninitialized: {
    8287           0 :       break;
    8288             :     }
    8289             :     case eObject: {
    8290           0 :       DestroyObject();
    8291           0 :       break;
    8292             :     }
    8293             :     case eString: {
    8294           0 :       DestroyString();
    8295           0 :       break;
    8296             :     }
    8297             :   }
    8298           0 : }
    8299             : 
    8300             : bool
    8301           0 : OwningObjectOrString::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    8302             : {
    8303           0 :   switch (mType) {
    8304             :     case eUninitialized: {
    8305           0 :       return false;
    8306             :       break;
    8307             :     }
    8308             :     case eObject: {
    8309           0 :       JS::ExposeObjectToActiveJS(mValue.mObject.Value());
    8310           0 :       rval.setObject(*mValue.mObject.Value());
    8311           0 :       if (!MaybeWrapObjectValue(cx, rval)) {
    8312           0 :         return false;
    8313             :       }
    8314           0 :       return true;
    8315             :       break;
    8316             :     }
    8317             :     case eString: {
    8318           0 :       if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) {
    8319           0 :         return false;
    8320             :       }
    8321           0 :       return true;
    8322             :       break;
    8323             :     }
    8324             :     default: {
    8325           0 :       return false;
    8326             :       break;
    8327             :     }
    8328             :   }
    8329             : 
    8330             :   return false;
    8331             : }
    8332             : 
    8333             : void
    8334           0 : OwningObjectOrString::TraceUnion(JSTracer* trc)
    8335             : {
    8336           0 :   switch (mType) {
    8337             :     case eObject: {
    8338           0 :       JS::UnsafeTraceRoot(trc, &mValue.mObject.Value(), "mValue.mObject");
    8339           0 :       break;
    8340             :     }
    8341             :     default: {
    8342           0 :       break;
    8343             :     }
    8344             :   }
    8345           0 : }
    8346             : 
    8347             : JSObject*&
    8348           0 : OwningObjectOrStringOrBoolean::RawSetAsObject()
    8349             : {
    8350           0 :   if (mType == eObject) {
    8351           0 :     return mValue.mObject.Value();
    8352             :   }
    8353           0 :   MOZ_ASSERT(mType == eUninitialized);
    8354           0 :   mType = eObject;
    8355           0 :   return mValue.mObject.SetValue();
    8356             : }
    8357             : 
    8358             : JSObject*&
    8359           0 : OwningObjectOrStringOrBoolean::SetAsObject()
    8360             : {
    8361           0 :   if (mType == eObject) {
    8362           0 :     return mValue.mObject.Value();
    8363             :   }
    8364           0 :   Uninit();
    8365           0 :   mType = eObject;
    8366           0 :   return mValue.mObject.SetValue();
    8367             : }
    8368             : 
    8369             : 
    8370             : void
    8371           0 : OwningObjectOrStringOrBoolean::DestroyObject()
    8372             : {
    8373           0 :   MOZ_ASSERT(IsObject(), "Wrong type!");
    8374           0 :   mValue.mObject.Destroy();
    8375           0 :   mType = eUninitialized;
    8376           0 : }
    8377             : 
    8378             : 
    8379             : 
    8380             : 
    8381             : nsString&
    8382           0 : OwningObjectOrStringOrBoolean::RawSetAsString()
    8383             : {
    8384           0 :   if (mType == eString) {
    8385           0 :     return mValue.mString.Value();
    8386             :   }
    8387           0 :   MOZ_ASSERT(mType == eUninitialized);
    8388           0 :   mType = eString;
    8389           0 :   return mValue.mString.SetValue();
    8390             : }
    8391             : 
    8392             : nsString&
    8393           0 : OwningObjectOrStringOrBoolean::SetAsString()
    8394             : {
    8395           0 :   if (mType == eString) {
    8396           0 :     return mValue.mString.Value();
    8397             :   }
    8398           0 :   Uninit();
    8399           0 :   mType = eString;
    8400           0 :   return mValue.mString.SetValue();
    8401             : }
    8402             : 
    8403             : bool
    8404           0 : OwningObjectOrStringOrBoolean::TrySetToString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    8405             : {
    8406           0 :   tryNext = false;
    8407             :   { // scope for memberSlot
    8408           0 :     nsString& memberSlot = RawSetAsString();
    8409           0 :     if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
    8410           0 :       return false;
    8411             :     }
    8412             :   }
    8413           0 :   return true;
    8414             : }
    8415             : 
    8416             : 
    8417             : void
    8418           0 : OwningObjectOrStringOrBoolean::DestroyString()
    8419             : {
    8420           0 :   MOZ_ASSERT(IsString(), "Wrong type!");
    8421           0 :   mValue.mString.Destroy();
    8422           0 :   mType = eUninitialized;
    8423           0 : }
    8424             : 
    8425             : 
    8426             : 
    8427             : 
    8428             : bool&
    8429           0 : OwningObjectOrStringOrBoolean::RawSetAsBoolean()
    8430             : {
    8431           0 :   if (mType == eBoolean) {
    8432           0 :     return mValue.mBoolean.Value();
    8433             :   }
    8434           0 :   MOZ_ASSERT(mType == eUninitialized);
    8435           0 :   mType = eBoolean;
    8436           0 :   return mValue.mBoolean.SetValue();
    8437             : }
    8438             : 
    8439             : bool&
    8440           0 : OwningObjectOrStringOrBoolean::SetAsBoolean()
    8441             : {
    8442           0 :   if (mType == eBoolean) {
    8443           0 :     return mValue.mBoolean.Value();
    8444             :   }
    8445           0 :   Uninit();
    8446           0 :   mType = eBoolean;
    8447           0 :   return mValue.mBoolean.SetValue();
    8448             : }
    8449             : 
    8450             : bool
    8451           0 : OwningObjectOrStringOrBoolean::TrySetToBoolean(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    8452             : {
    8453           0 :   tryNext = false;
    8454             :   { // scope for memberSlot
    8455           0 :     bool& memberSlot = RawSetAsBoolean();
    8456           0 :     if (!ValueToPrimitive<bool, eDefault>(cx, value, &memberSlot)) {
    8457           0 :       return false;
    8458             :     }
    8459             :   }
    8460           0 :   return true;
    8461             : }
    8462             : 
    8463             : void
    8464           0 : OwningObjectOrStringOrBoolean::DestroyBoolean()
    8465             : {
    8466           0 :   MOZ_ASSERT(IsBoolean(), "Wrong type!");
    8467           0 :   mValue.mBoolean.Destroy();
    8468           0 :   mType = eUninitialized;
    8469           0 : }
    8470             : 
    8471             : 
    8472             : 
    8473             : 
    8474             : void
    8475           0 : OwningObjectOrStringOrBoolean::Uninit()
    8476             : {
    8477           0 :   switch (mType) {
    8478             :     case eUninitialized: {
    8479           0 :       break;
    8480             :     }
    8481             :     case eObject: {
    8482           0 :       DestroyObject();
    8483           0 :       break;
    8484             :     }
    8485             :     case eString: {
    8486           0 :       DestroyString();
    8487           0 :       break;
    8488             :     }
    8489             :     case eBoolean: {
    8490           0 :       DestroyBoolean();
    8491           0 :       break;
    8492             :     }
    8493             :   }
    8494           0 : }
    8495             : 
    8496             : bool
    8497           0 : OwningObjectOrStringOrBoolean::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    8498             : {
    8499           0 :   switch (mType) {
    8500             :     case eUninitialized: {
    8501           0 :       return false;
    8502             :       break;
    8503             :     }
    8504             :     case eObject: {
    8505           0 :       JS::ExposeObjectToActiveJS(mValue.mObject.Value());
    8506           0 :       rval.setObject(*mValue.mObject.Value());
    8507           0 :       if (!MaybeWrapObjectValue(cx, rval)) {
    8508           0 :         return false;
    8509             :       }
    8510           0 :       return true;
    8511             :       break;
    8512             :     }
    8513             :     case eString: {
    8514           0 :       if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) {
    8515           0 :         return false;
    8516             :       }
    8517           0 :       return true;
    8518             :       break;
    8519             :     }
    8520             :     case eBoolean: {
    8521           0 :       rval.setBoolean(mValue.mBoolean.Value());
    8522           0 :       return true;
    8523             :       break;
    8524             :     }
    8525             :     default: {
    8526           0 :       return false;
    8527             :       break;
    8528             :     }
    8529             :   }
    8530             : 
    8531             :   return false;
    8532             : }
    8533             : 
    8534             : void
    8535           0 : OwningObjectOrStringOrBoolean::TraceUnion(JSTracer* trc)
    8536             : {
    8537           0 :   switch (mType) {
    8538             :     case eObject: {
    8539           0 :       JS::UnsafeTraceRoot(trc, &mValue.mObject.Value(), "mValue.mObject");
    8540           0 :       break;
    8541             :     }
    8542             :     default: {
    8543           0 :       break;
    8544             :     }
    8545             :   }
    8546           0 : }
    8547             : 
    8548             : JSObject*&
    8549           0 : OwningObjectOrStringOrLong::RawSetAsObject()
    8550             : {
    8551           0 :   if (mType == eObject) {
    8552           0 :     return mValue.mObject.Value();
    8553             :   }
    8554           0 :   MOZ_ASSERT(mType == eUninitialized);
    8555           0 :   mType = eObject;
    8556           0 :   return mValue.mObject.SetValue();
    8557             : }
    8558             : 
    8559             : JSObject*&
    8560           0 : OwningObjectOrStringOrLong::SetAsObject()
    8561             : {
    8562           0 :   if (mType == eObject) {
    8563           0 :     return mValue.mObject.Value();
    8564             :   }
    8565           0 :   Uninit();
    8566           0 :   mType = eObject;
    8567           0 :   return mValue.mObject.SetValue();
    8568             : }
    8569             : 
    8570             : 
    8571             : void
    8572           0 : OwningObjectOrStringOrLong::DestroyObject()
    8573             : {
    8574           0 :   MOZ_ASSERT(IsObject(), "Wrong type!");
    8575           0 :   mValue.mObject.Destroy();
    8576           0 :   mType = eUninitialized;
    8577           0 : }
    8578             : 
    8579             : 
    8580             : 
    8581             : 
    8582             : nsString&
    8583           0 : OwningObjectOrStringOrLong::RawSetAsString()
    8584             : {
    8585           0 :   if (mType == eString) {
    8586           0 :     return mValue.mString.Value();
    8587             :   }
    8588           0 :   MOZ_ASSERT(mType == eUninitialized);
    8589           0 :   mType = eString;
    8590           0 :   return mValue.mString.SetValue();
    8591             : }
    8592             : 
    8593             : nsString&
    8594           0 : OwningObjectOrStringOrLong::SetAsString()
    8595             : {
    8596           0 :   if (mType == eString) {
    8597           0 :     return mValue.mString.Value();
    8598             :   }
    8599           0 :   Uninit();
    8600           0 :   mType = eString;
    8601           0 :   return mValue.mString.SetValue();
    8602             : }
    8603             : 
    8604             : bool
    8605           0 : OwningObjectOrStringOrLong::TrySetToString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    8606             : {
    8607           0 :   tryNext = false;
    8608             :   { // scope for memberSlot
    8609           0 :     nsString& memberSlot = RawSetAsString();
    8610           0 :     if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
    8611           0 :       return false;
    8612             :     }
    8613             :   }
    8614           0 :   return true;
    8615             : }
    8616             : 
    8617             : 
    8618             : void
    8619           0 : OwningObjectOrStringOrLong::DestroyString()
    8620             : {
    8621           0 :   MOZ_ASSERT(IsString(), "Wrong type!");
    8622           0 :   mValue.mString.Destroy();
    8623           0 :   mType = eUninitialized;
    8624           0 : }
    8625             : 
    8626             : 
    8627             : 
    8628             : 
    8629             : int32_t&
    8630           0 : OwningObjectOrStringOrLong::RawSetAsLong()
    8631             : {
    8632           0 :   if (mType == eLong) {
    8633           0 :     return mValue.mLong.Value();
    8634             :   }
    8635           0 :   MOZ_ASSERT(mType == eUninitialized);
    8636           0 :   mType = eLong;
    8637           0 :   return mValue.mLong.SetValue();
    8638             : }
    8639             : 
    8640             : int32_t&
    8641           0 : OwningObjectOrStringOrLong::SetAsLong()
    8642             : {
    8643           0 :   if (mType == eLong) {
    8644           0 :     return mValue.mLong.Value();
    8645             :   }
    8646           0 :   Uninit();
    8647           0 :   mType = eLong;
    8648           0 :   return mValue.mLong.SetValue();
    8649             : }
    8650             : 
    8651             : bool
    8652           0 : OwningObjectOrStringOrLong::TrySetToLong(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    8653             : {
    8654           0 :   tryNext = false;
    8655             :   { // scope for memberSlot
    8656           0 :     int32_t& memberSlot = RawSetAsLong();
    8657           0 :     if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
    8658           0 :       return false;
    8659             :     }
    8660             :   }
    8661           0 :   return true;
    8662             : }
    8663             : 
    8664             : void
    8665           0 : OwningObjectOrStringOrLong::DestroyLong()
    8666             : {
    8667           0 :   MOZ_ASSERT(IsLong(), "Wrong type!");
    8668           0 :   mValue.mLong.Destroy();
    8669           0 :   mType = eUninitialized;
    8670           0 : }
    8671             : 
    8672             : 
    8673             : 
    8674             : 
    8675             : void
    8676           0 : OwningObjectOrStringOrLong::Uninit()
    8677             : {
    8678           0 :   switch (mType) {
    8679             :     case eUninitialized: {
    8680           0 :       break;
    8681             :     }
    8682             :     case eObject: {
    8683           0 :       DestroyObject();
    8684           0 :       break;
    8685             :     }
    8686             :     case eString: {
    8687           0 :       DestroyString();
    8688           0 :       break;
    8689             :     }
    8690             :     case eLong: {
    8691           0 :       DestroyLong();
    8692           0 :       break;
    8693             :     }
    8694             :   }
    8695           0 : }
    8696             : 
    8697             : bool
    8698           0 : OwningObjectOrStringOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    8699             : {
    8700           0 :   switch (mType) {
    8701             :     case eUninitialized: {
    8702           0 :       return false;
    8703             :       break;
    8704             :     }
    8705             :     case eObject: {
    8706           0 :       JS::ExposeObjectToActiveJS(mValue.mObject.Value());
    8707           0 :       rval.setObject(*mValue.mObject.Value());
    8708           0 :       if (!MaybeWrapObjectValue(cx, rval)) {
    8709           0 :         return false;
    8710             :       }
    8711           0 :       return true;
    8712             :       break;
    8713             :     }
    8714             :     case eString: {
    8715           0 :       if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) {
    8716           0 :         return false;
    8717             :       }
    8718           0 :       return true;
    8719             :       break;
    8720             :     }
    8721             :     case eLong: {
    8722           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    8723           0 :       return true;
    8724             :       break;
    8725             :     }
    8726             :     default: {
    8727           0 :       return false;
    8728             :       break;
    8729             :     }
    8730             :   }
    8731             : 
    8732             :   return false;
    8733             : }
    8734             : 
    8735             : void
    8736           0 : OwningObjectOrStringOrLong::TraceUnion(JSTracer* trc)
    8737             : {
    8738           0 :   switch (mType) {
    8739             :     case eObject: {
    8740           0 :       JS::UnsafeTraceRoot(trc, &mValue.mObject.Value(), "mValue.mObject");
    8741           0 :       break;
    8742             :     }
    8743             :     default: {
    8744           0 :       break;
    8745             :     }
    8746             :   }
    8747           0 : }
    8748             : 
    8749             : JSObject*&
    8750           0 : OwningObjectOrStringOrLongOrBoolean::RawSetAsObject()
    8751             : {
    8752           0 :   if (mType == eObject) {
    8753           0 :     return mValue.mObject.Value();
    8754             :   }
    8755           0 :   MOZ_ASSERT(mType == eUninitialized);
    8756           0 :   mType = eObject;
    8757           0 :   return mValue.mObject.SetValue();
    8758             : }
    8759             : 
    8760             : JSObject*&
    8761           0 : OwningObjectOrStringOrLongOrBoolean::SetAsObject()
    8762             : {
    8763           0 :   if (mType == eObject) {
    8764           0 :     return mValue.mObject.Value();
    8765             :   }
    8766           0 :   Uninit();
    8767           0 :   mType = eObject;
    8768           0 :   return mValue.mObject.SetValue();
    8769             : }
    8770             : 
    8771             : 
    8772             : void
    8773           0 : OwningObjectOrStringOrLongOrBoolean::DestroyObject()
    8774             : {
    8775           0 :   MOZ_ASSERT(IsObject(), "Wrong type!");
    8776           0 :   mValue.mObject.Destroy();
    8777           0 :   mType = eUninitialized;
    8778           0 : }
    8779             : 
    8780             : 
    8781             : 
    8782             : 
    8783             : nsString&
    8784           0 : OwningObjectOrStringOrLongOrBoolean::RawSetAsString()
    8785             : {
    8786           0 :   if (mType == eString) {
    8787           0 :     return mValue.mString.Value();
    8788             :   }
    8789           0 :   MOZ_ASSERT(mType == eUninitialized);
    8790           0 :   mType = eString;
    8791           0 :   return mValue.mString.SetValue();
    8792             : }
    8793             : 
    8794             : nsString&
    8795           0 : OwningObjectOrStringOrLongOrBoolean::SetAsString()
    8796             : {
    8797           0 :   if (mType == eString) {
    8798           0 :     return mValue.mString.Value();
    8799             :   }
    8800           0 :   Uninit();
    8801           0 :   mType = eString;
    8802           0 :   return mValue.mString.SetValue();
    8803             : }
    8804             : 
    8805             : bool
    8806           0 : OwningObjectOrStringOrLongOrBoolean::TrySetToString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    8807             : {
    8808           0 :   tryNext = false;
    8809             :   { // scope for memberSlot
    8810           0 :     nsString& memberSlot = RawSetAsString();
    8811           0 :     if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
    8812           0 :       return false;
    8813             :     }
    8814             :   }
    8815           0 :   return true;
    8816             : }
    8817             : 
    8818             : 
    8819             : void
    8820           0 : OwningObjectOrStringOrLongOrBoolean::DestroyString()
    8821             : {
    8822           0 :   MOZ_ASSERT(IsString(), "Wrong type!");
    8823           0 :   mValue.mString.Destroy();
    8824           0 :   mType = eUninitialized;
    8825           0 : }
    8826             : 
    8827             : 
    8828             : 
    8829             : 
    8830             : int32_t&
    8831           0 : OwningObjectOrStringOrLongOrBoolean::RawSetAsLong()
    8832             : {
    8833           0 :   if (mType == eLong) {
    8834           0 :     return mValue.mLong.Value();
    8835             :   }
    8836           0 :   MOZ_ASSERT(mType == eUninitialized);
    8837           0 :   mType = eLong;
    8838           0 :   return mValue.mLong.SetValue();
    8839             : }
    8840             : 
    8841             : int32_t&
    8842           0 : OwningObjectOrStringOrLongOrBoolean::SetAsLong()
    8843             : {
    8844           0 :   if (mType == eLong) {
    8845           0 :     return mValue.mLong.Value();
    8846             :   }
    8847           0 :   Uninit();
    8848           0 :   mType = eLong;
    8849           0 :   return mValue.mLong.SetValue();
    8850             : }
    8851             : 
    8852             : bool
    8853           0 : OwningObjectOrStringOrLongOrBoolean::TrySetToLong(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    8854             : {
    8855           0 :   tryNext = false;
    8856             :   { // scope for memberSlot
    8857           0 :     int32_t& memberSlot = RawSetAsLong();
    8858           0 :     if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
    8859           0 :       return false;
    8860             :     }
    8861             :   }
    8862           0 :   return true;
    8863             : }
    8864             : 
    8865             : void
    8866           0 : OwningObjectOrStringOrLongOrBoolean::DestroyLong()
    8867             : {
    8868           0 :   MOZ_ASSERT(IsLong(), "Wrong type!");
    8869           0 :   mValue.mLong.Destroy();
    8870           0 :   mType = eUninitialized;
    8871           0 : }
    8872             : 
    8873             : 
    8874             : 
    8875             : 
    8876             : bool&
    8877           0 : OwningObjectOrStringOrLongOrBoolean::RawSetAsBoolean()
    8878             : {
    8879           0 :   if (mType == eBoolean) {
    8880           0 :     return mValue.mBoolean.Value();
    8881             :   }
    8882           0 :   MOZ_ASSERT(mType == eUninitialized);
    8883           0 :   mType = eBoolean;
    8884           0 :   return mValue.mBoolean.SetValue();
    8885             : }
    8886             : 
    8887             : bool&
    8888           0 : OwningObjectOrStringOrLongOrBoolean::SetAsBoolean()
    8889             : {
    8890           0 :   if (mType == eBoolean) {
    8891           0 :     return mValue.mBoolean.Value();
    8892             :   }
    8893           0 :   Uninit();
    8894           0 :   mType = eBoolean;
    8895           0 :   return mValue.mBoolean.SetValue();
    8896             : }
    8897             : 
    8898             : bool
    8899           0 : OwningObjectOrStringOrLongOrBoolean::TrySetToBoolean(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    8900             : {
    8901           0 :   tryNext = false;
    8902             :   { // scope for memberSlot
    8903           0 :     bool& memberSlot = RawSetAsBoolean();
    8904           0 :     if (!ValueToPrimitive<bool, eDefault>(cx, value, &memberSlot)) {
    8905           0 :       return false;
    8906             :     }
    8907             :   }
    8908           0 :   return true;
    8909             : }
    8910             : 
    8911             : void
    8912           0 : OwningObjectOrStringOrLongOrBoolean::DestroyBoolean()
    8913             : {
    8914           0 :   MOZ_ASSERT(IsBoolean(), "Wrong type!");
    8915           0 :   mValue.mBoolean.Destroy();
    8916           0 :   mType = eUninitialized;
    8917           0 : }
    8918             : 
    8919             : 
    8920             : 
    8921             : 
    8922             : void
    8923           0 : OwningObjectOrStringOrLongOrBoolean::Uninit()
    8924             : {
    8925           0 :   switch (mType) {
    8926             :     case eUninitialized: {
    8927           0 :       break;
    8928             :     }
    8929             :     case eObject: {
    8930           0 :       DestroyObject();
    8931           0 :       break;
    8932             :     }
    8933             :     case eString: {
    8934           0 :       DestroyString();
    8935           0 :       break;
    8936             :     }
    8937             :     case eLong: {
    8938           0 :       DestroyLong();
    8939           0 :       break;
    8940             :     }
    8941             :     case eBoolean: {
    8942           0 :       DestroyBoolean();
    8943           0 :       break;
    8944             :     }
    8945             :   }
    8946           0 : }
    8947             : 
    8948             : bool
    8949           0 : OwningObjectOrStringOrLongOrBoolean::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    8950             : {
    8951           0 :   switch (mType) {
    8952             :     case eUninitialized: {
    8953           0 :       return false;
    8954             :       break;
    8955             :     }
    8956             :     case eObject: {
    8957           0 :       JS::ExposeObjectToActiveJS(mValue.mObject.Value());
    8958           0 :       rval.setObject(*mValue.mObject.Value());
    8959           0 :       if (!MaybeWrapObjectValue(cx, rval)) {
    8960           0 :         return false;
    8961             :       }
    8962           0 :       return true;
    8963             :       break;
    8964             :     }
    8965             :     case eString: {
    8966           0 :       if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) {
    8967           0 :         return false;
    8968             :       }
    8969           0 :       return true;
    8970             :       break;
    8971             :     }
    8972             :     case eLong: {
    8973           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    8974           0 :       return true;
    8975             :       break;
    8976             :     }
    8977             :     case eBoolean: {
    8978           0 :       rval.setBoolean(mValue.mBoolean.Value());
    8979           0 :       return true;
    8980             :       break;
    8981             :     }
    8982             :     default: {
    8983           0 :       return false;
    8984             :       break;
    8985             :     }
    8986             :   }
    8987             : 
    8988             :   return false;
    8989             : }
    8990             : 
    8991             : void
    8992           0 : OwningObjectOrStringOrLongOrBoolean::TraceUnion(JSTracer* trc)
    8993             : {
    8994           0 :   switch (mType) {
    8995             :     case eObject: {
    8996           0 :       JS::UnsafeTraceRoot(trc, &mValue.mObject.Value(), "mValue.mObject");
    8997           0 :       break;
    8998             :     }
    8999             :     default: {
    9000           0 :       break;
    9001             :     }
    9002             :   }
    9003           0 : }
    9004             : 
    9005             : Sequence<JSObject*>&
    9006           0 : OwningObjectSequenceOrLong::RawSetAsObjectSequence()
    9007             : {
    9008           0 :   if (mType == eObjectSequence) {
    9009           0 :     return mValue.mObjectSequence.Value();
    9010             :   }
    9011           0 :   MOZ_ASSERT(mType == eUninitialized);
    9012           0 :   mType = eObjectSequence;
    9013           0 :   return mValue.mObjectSequence.SetValue();
    9014             : }
    9015             : 
    9016             : Sequence<JSObject*>&
    9017           0 : OwningObjectSequenceOrLong::SetAsObjectSequence()
    9018             : {
    9019           0 :   if (mType == eObjectSequence) {
    9020           0 :     return mValue.mObjectSequence.Value();
    9021             :   }
    9022           0 :   Uninit();
    9023           0 :   mType = eObjectSequence;
    9024           0 :   return mValue.mObjectSequence.SetValue();
    9025             : }
    9026             : 
    9027             : bool
    9028           0 : OwningObjectSequenceOrLong::TrySetToObjectSequence(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    9029             : {
    9030           0 :   tryNext = false;
    9031             :   { // scope for memberSlot
    9032           0 :     Sequence<JSObject*>& memberSlot = RawSetAsObjectSequence();
    9033           0 :     JS::ForOfIterator iter(cx);
    9034           0 :     if (!iter.init(value, JS::ForOfIterator::AllowNonIterable)) {
    9035           0 :       return false;
    9036             :     }
    9037           0 :     if (!iter.valueIsIterable()) {
    9038           0 :       DestroyObjectSequence();
    9039           0 :       tryNext = true;
    9040           0 :       return true;
    9041             :     }
    9042           0 :     Sequence<JSObject*> &arr = memberSlot;
    9043           0 :     JS::Rooted<JS::Value> temp(cx);
    9044             :     while (true) {
    9045             :       bool done;
    9046           0 :       if (!iter.next(&temp, &done)) {
    9047           0 :         return false;
    9048             :       }
    9049           0 :       if (done) {
    9050           0 :         break;
    9051             :       }
    9052           0 :       JSObject** slotPtr = arr.AppendElement(mozilla::fallible);
    9053           0 :       if (!slotPtr) {
    9054           0 :         JS_ReportOutOfMemory(cx);
    9055           0 :         return false;
    9056             :       }
    9057           0 :       JSObject*& slot = *slotPtr;
    9058           0 :       if (temp.isObject()) {
    9059             : #ifdef __clang__
    9060             : #pragma clang diagnostic push
    9061             : #pragma clang diagnostic ignored "-Wunreachable-code"
    9062             : #pragma clang diagnostic ignored "-Wunreachable-code-return"
    9063             : #endif // __clang__
    9064           0 :         if ((passedToJSImpl) && !CallerSubsumes(temp)) {
    9065           0 :           ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "element of member of ObjectSequenceOrLong");
    9066           0 :           return false;
    9067             :         }
    9068             : #ifdef __clang__
    9069             : #pragma clang diagnostic pop
    9070             : #endif // __clang__
    9071           0 :         slot = &temp.toObject();
    9072             :       } else {
    9073           0 :         ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of member of ObjectSequenceOrLong");
    9074           0 :         return false;
    9075             :       }
    9076           0 :     }
    9077             :   }
    9078           0 :   return true;
    9079             : }
    9080             : 
    9081             : void
    9082           0 : OwningObjectSequenceOrLong::DestroyObjectSequence()
    9083             : {
    9084           0 :   MOZ_ASSERT(IsObjectSequence(), "Wrong type!");
    9085           0 :   mValue.mObjectSequence.Destroy();
    9086           0 :   mType = eUninitialized;
    9087           0 : }
    9088             : 
    9089             : 
    9090             : 
    9091             : 
    9092             : int32_t&
    9093           0 : OwningObjectSequenceOrLong::RawSetAsLong()
    9094             : {
    9095           0 :   if (mType == eLong) {
    9096           0 :     return mValue.mLong.Value();
    9097             :   }
    9098           0 :   MOZ_ASSERT(mType == eUninitialized);
    9099           0 :   mType = eLong;
    9100           0 :   return mValue.mLong.SetValue();
    9101             : }
    9102             : 
    9103             : int32_t&
    9104           0 : OwningObjectSequenceOrLong::SetAsLong()
    9105             : {
    9106           0 :   if (mType == eLong) {
    9107           0 :     return mValue.mLong.Value();
    9108             :   }
    9109           0 :   Uninit();
    9110           0 :   mType = eLong;
    9111           0 :   return mValue.mLong.SetValue();
    9112             : }
    9113             : 
    9114             : bool
    9115           0 : OwningObjectSequenceOrLong::TrySetToLong(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    9116             : {
    9117           0 :   tryNext = false;
    9118             :   { // scope for memberSlot
    9119           0 :     int32_t& memberSlot = RawSetAsLong();
    9120           0 :     if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
    9121           0 :       return false;
    9122             :     }
    9123             :   }
    9124           0 :   return true;
    9125             : }
    9126             : 
    9127             : void
    9128           0 : OwningObjectSequenceOrLong::DestroyLong()
    9129             : {
    9130           0 :   MOZ_ASSERT(IsLong(), "Wrong type!");
    9131           0 :   mValue.mLong.Destroy();
    9132           0 :   mType = eUninitialized;
    9133           0 : }
    9134             : 
    9135             : 
    9136             : 
    9137             : 
    9138             : void
    9139           0 : OwningObjectSequenceOrLong::Uninit()
    9140             : {
    9141           0 :   switch (mType) {
    9142             :     case eUninitialized: {
    9143           0 :       break;
    9144             :     }
    9145             :     case eObjectSequence: {
    9146           0 :       DestroyObjectSequence();
    9147           0 :       break;
    9148             :     }
    9149             :     case eLong: {
    9150           0 :       DestroyLong();
    9151           0 :       break;
    9152             :     }
    9153             :   }
    9154           0 : }
    9155             : 
    9156             : bool
    9157           0 : OwningObjectSequenceOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    9158             : {
    9159           0 :   switch (mType) {
    9160             :     case eUninitialized: {
    9161           0 :       return false;
    9162             :       break;
    9163             :     }
    9164             :     case eObjectSequence: {
    9165             : 
    9166           0 :       uint32_t length = mValue.mObjectSequence.Value().Length();
    9167           0 :       JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
    9168           0 :       if (!returnArray) {
    9169           0 :         return false;
    9170             :       }
    9171             :       // Scope for 'tmp'
    9172             :       {
    9173           0 :         JS::Rooted<JS::Value> tmp(cx);
    9174           0 :         for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
    9175             :           // Control block to let us common up the JS_DefineElement calls when there
    9176             :           // are different ways to succeed at wrapping the object.
    9177             :           do {
    9178           0 :             JS::ExposeObjectToActiveJS(mValue.mObjectSequence.Value()[sequenceIdx0]);
    9179           0 :             tmp.setObject(*mValue.mObjectSequence.Value()[sequenceIdx0]);
    9180           0 :             if (!MaybeWrapObjectValue(cx, &tmp)) {
    9181           0 :               return false;
    9182             :             }
    9183           0 :             break;
    9184             :           } while (0);
    9185           0 :           if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
    9186             :                                 JSPROP_ENUMERATE)) {
    9187           0 :             return false;
    9188             :           }
    9189             :         }
    9190             :       }
    9191           0 :       rval.setObject(*returnArray);
    9192           0 :       return true;
    9193             :       break;
    9194             :     }
    9195             :     case eLong: {
    9196           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    9197           0 :       return true;
    9198             :       break;
    9199             :     }
    9200             :     default: {
    9201           0 :       return false;
    9202             :       break;
    9203             :     }
    9204             :   }
    9205             : 
    9206             :   return false;
    9207             : }
    9208             : 
    9209             : void
    9210           0 : OwningObjectSequenceOrLong::TraceUnion(JSTracer* trc)
    9211             : {
    9212           0 :   switch (mType) {
    9213             :     case eObjectSequence: {
    9214           0 :       DoTraceSequence(trc, mValue.mObjectSequence.Value());
    9215           0 :       break;
    9216             :     }
    9217             :     default: {
    9218           0 :       break;
    9219             :     }
    9220             :   }
    9221           0 : }
    9222             : 
    9223             : Record<nsString, int32_t>&
    9224           0 : OwningStringLongRecordOrLong::RawSetAsStringLongRecord()
    9225             : {
    9226           0 :   if (mType == eStringLongRecord) {
    9227           0 :     return mValue.mStringLongRecord.Value();
    9228             :   }
    9229           0 :   MOZ_ASSERT(mType == eUninitialized);
    9230           0 :   mType = eStringLongRecord;
    9231           0 :   return mValue.mStringLongRecord.SetValue();
    9232             : }
    9233             : 
    9234             : Record<nsString, int32_t>&
    9235           0 : OwningStringLongRecordOrLong::SetAsStringLongRecord()
    9236             : {
    9237           0 :   if (mType == eStringLongRecord) {
    9238           0 :     return mValue.mStringLongRecord.Value();
    9239             :   }
    9240           0 :   Uninit();
    9241           0 :   mType = eStringLongRecord;
    9242           0 :   return mValue.mStringLongRecord.SetValue();
    9243             : }
    9244             : 
    9245             : bool
    9246           0 : OwningStringLongRecordOrLong::TrySetToStringLongRecord(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    9247             : {
    9248           0 :   tryNext = false;
    9249             :   { // scope for memberSlot
    9250           0 :     Record<nsString, int32_t>& memberSlot = RawSetAsStringLongRecord();
    9251           0 :     auto& recordEntries = memberSlot.Entries();
    9252             : 
    9253           0 :     JS::Rooted<JSObject*> recordObj(cx, &value.toObject());
    9254           0 :     JS::AutoIdVector ids(cx);
    9255           0 :     if (!js::GetPropertyKeys(cx, recordObj,
    9256             :                              JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS, &ids)) {
    9257           0 :       return false;
    9258             :     }
    9259           0 :     if (!recordEntries.SetCapacity(ids.length(), mozilla::fallible)) {
    9260           0 :       JS_ReportOutOfMemory(cx);
    9261           0 :       return false;
    9262             :     }
    9263           0 :     JS::Rooted<JS::Value> propNameValue(cx);
    9264           0 :     JS::Rooted<JS::Value> temp(cx);
    9265           0 :     JS::Rooted<jsid> curId(cx);
    9266           0 :     JS::Rooted<JS::Value> idVal(cx);
    9267             :     // Use a hashset to keep track of ids seen, to avoid
    9268             :     // introducing nasty O(N^2) behavior scanning for them all the
    9269             :     // time.  Ideally we'd use a data structure with O(1) lookup
    9270             :     // _and_ ordering for the MozMap, but we don't have one lying
    9271             :     // around.
    9272           0 :     nsTHashtable<nsStringHashKey> idsSeen;
    9273           0 :     for (size_t i = 0; i < ids.length(); ++i) {
    9274           0 :       curId = ids[i];
    9275             : 
    9276           0 :       JS::Rooted<JS::PropertyDescriptor> desc(cx);
    9277           0 :       if (!JS_GetOwnPropertyDescriptorById(cx, recordObj, curId,
    9278             :                                            &desc)) {
    9279           0 :         return false;
    9280             :       }
    9281             : 
    9282           0 :       if (!desc.object() /* == undefined in spec terms */ ||
    9283           0 :           !desc.enumerable()) {
    9284           0 :         continue;
    9285             :       }
    9286             : 
    9287           0 :       idVal = js::IdToValue(curId);
    9288           0 :       nsString propName;
    9289             :       // This will just throw if idVal is a Symbol, like the spec says
    9290             :       // to do.
    9291           0 :       if (!ConvertJSValueToString(cx, idVal, propName)) {
    9292           0 :         return false;
    9293             :       }
    9294             : 
    9295           0 :       if (!JS_GetPropertyById(cx, recordObj, curId, &temp)) {
    9296           0 :         return false;
    9297             :       }
    9298             : 
    9299             :       Record<nsString, int32_t>::EntryType* entry;
    9300           0 :       if (!idsSeen.EnsureInserted(propName)) {
    9301             :         // Find the existing entry.
    9302           0 :         auto idx = recordEntries.IndexOf(propName);
    9303           0 :         MOZ_ASSERT(idx != recordEntries.NoIndex,
    9304             :                    "Why is it not found?");
    9305             :         // Now blow it away to make it look like it was just added
    9306             :         // to the array, because it's not obvious that it's
    9307             :         // safe to write to its already-initialized mValue via our
    9308             :         // normal codegen conversions.  For example, the value
    9309             :         // could be a union and this would change its type, but
    9310             :         // codegen assumes we won't do that.
    9311           0 :         entry = recordEntries.ReconstructElementAt(idx);
    9312             :       } else {
    9313             :         // Safe to do an infallible append here, because we did a
    9314             :         // SetCapacity above to the right capacity.
    9315           0 :         entry = recordEntries.AppendElement();
    9316             :       }
    9317           0 :       entry->mKey = propName;
    9318           0 :       int32_t& slot = entry->mValue;
    9319           0 :       if (!ValueToPrimitive<int32_t, eDefault>(cx, temp, &slot)) {
    9320           0 :         return false;
    9321             :       }
    9322             :     }
    9323             :   }
    9324           0 :   return true;
    9325             : }
    9326             : 
    9327             : void
    9328           0 : OwningStringLongRecordOrLong::DestroyStringLongRecord()
    9329             : {
    9330           0 :   MOZ_ASSERT(IsStringLongRecord(), "Wrong type!");
    9331           0 :   mValue.mStringLongRecord.Destroy();
    9332           0 :   mType = eUninitialized;
    9333           0 : }
    9334             : 
    9335             : 
    9336             : 
    9337             : 
    9338             : int32_t&
    9339           0 : OwningStringLongRecordOrLong::RawSetAsLong()
    9340             : {
    9341           0 :   if (mType == eLong) {
    9342           0 :     return mValue.mLong.Value();
    9343             :   }
    9344           0 :   MOZ_ASSERT(mType == eUninitialized);
    9345           0 :   mType = eLong;
    9346           0 :   return mValue.mLong.SetValue();
    9347             : }
    9348             : 
    9349             : int32_t&
    9350           0 : OwningStringLongRecordOrLong::SetAsLong()
    9351             : {
    9352           0 :   if (mType == eLong) {
    9353           0 :     return mValue.mLong.Value();
    9354             :   }
    9355           0 :   Uninit();
    9356           0 :   mType = eLong;
    9357           0 :   return mValue.mLong.SetValue();
    9358             : }
    9359             : 
    9360             : bool
    9361           0 : OwningStringLongRecordOrLong::TrySetToLong(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    9362             : {
    9363           0 :   tryNext = false;
    9364             :   { // scope for memberSlot
    9365           0 :     int32_t& memberSlot = RawSetAsLong();
    9366           0 :     if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
    9367           0 :       return false;
    9368             :     }
    9369             :   }
    9370           0 :   return true;
    9371             : }
    9372             : 
    9373             : void
    9374           0 : OwningStringLongRecordOrLong::DestroyLong()
    9375             : {
    9376           0 :   MOZ_ASSERT(IsLong(), "Wrong type!");
    9377           0 :   mValue.mLong.Destroy();
    9378           0 :   mType = eUninitialized;
    9379           0 : }
    9380             : 
    9381             : 
    9382             : 
    9383             : 
    9384             : void
    9385           0 : OwningStringLongRecordOrLong::Uninit()
    9386             : {
    9387           0 :   switch (mType) {
    9388             :     case eUninitialized: {
    9389           0 :       break;
    9390             :     }
    9391             :     case eStringLongRecord: {
    9392           0 :       DestroyStringLongRecord();
    9393           0 :       break;
    9394             :     }
    9395             :     case eLong: {
    9396           0 :       DestroyLong();
    9397           0 :       break;
    9398             :     }
    9399             :   }
    9400           0 : }
    9401             : 
    9402             : bool
    9403           0 : OwningStringLongRecordOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    9404             : {
    9405           0 :   switch (mType) {
    9406             :     case eUninitialized: {
    9407           0 :       return false;
    9408             :       break;
    9409             :     }
    9410             :     case eStringLongRecord: {
    9411             : 
    9412           0 :       JS::Rooted<JSObject*> returnObj(cx, JS_NewPlainObject(cx));
    9413           0 :       if (!returnObj) {
    9414           0 :         return false;
    9415             :       }
    9416             :       // Scope for 'tmp'
    9417             :       {
    9418           0 :         JS::Rooted<JS::Value> tmp(cx);
    9419           0 :         for (auto& entry : mValue.mStringLongRecord.Value().Entries()) {
    9420           0 :           auto& recordValue0 = entry.mValue;
    9421             :           // Control block to let us common up the JS_DefineUCProperty calls when there
    9422             :           // are different ways to succeed at wrapping the value.
    9423             :           do {
    9424           0 :             tmp.setInt32(int32_t(recordValue0));
    9425           0 :             break;
    9426             :           } while (0);
    9427           0 :           if (!JS_DefineUCProperty(cx, returnObj,
    9428             :                                    entry.mKey.BeginReading(),
    9429           0 :                                    entry.mKey.Length(), tmp,
    9430             :                                    JSPROP_ENUMERATE)) {
    9431           0 :             return false;
    9432             :           }
    9433             :         }
    9434             :       }
    9435           0 :       rval.setObject(*returnObj);
    9436           0 :       return true;
    9437             :       break;
    9438             :     }
    9439             :     case eLong: {
    9440           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    9441           0 :       return true;
    9442             :       break;
    9443             :     }
    9444             :     default: {
    9445           0 :       return false;
    9446             :       break;
    9447             :     }
    9448             :   }
    9449             : 
    9450             :   return false;
    9451             : }
    9452             : 
    9453             : void
    9454           0 : OwningStringLongRecordOrLong::TraceUnion(JSTracer* trc)
    9455             : {
    9456           0 : }
    9457             : 
    9458             : Record<nsString, JSObject*>&
    9459           0 : OwningStringObjectRecordOrLong::RawSetAsStringObjectRecord()
    9460             : {
    9461           0 :   if (mType == eStringObjectRecord) {
    9462           0 :     return mValue.mStringObjectRecord.Value();
    9463             :   }
    9464           0 :   MOZ_ASSERT(mType == eUninitialized);
    9465           0 :   mType = eStringObjectRecord;
    9466           0 :   return mValue.mStringObjectRecord.SetValue();
    9467             : }
    9468             : 
    9469             : Record<nsString, JSObject*>&
    9470           0 : OwningStringObjectRecordOrLong::SetAsStringObjectRecord()
    9471             : {
    9472           0 :   if (mType == eStringObjectRecord) {
    9473           0 :     return mValue.mStringObjectRecord.Value();
    9474             :   }
    9475           0 :   Uninit();
    9476           0 :   mType = eStringObjectRecord;
    9477           0 :   return mValue.mStringObjectRecord.SetValue();
    9478             : }
    9479             : 
    9480             : bool
    9481           0 : OwningStringObjectRecordOrLong::TrySetToStringObjectRecord(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    9482             : {
    9483           0 :   tryNext = false;
    9484             :   { // scope for memberSlot
    9485           0 :     Record<nsString, JSObject*>& memberSlot = RawSetAsStringObjectRecord();
    9486           0 :     auto& recordEntries = memberSlot.Entries();
    9487             : 
    9488           0 :     JS::Rooted<JSObject*> recordObj(cx, &value.toObject());
    9489           0 :     JS::AutoIdVector ids(cx);
    9490           0 :     if (!js::GetPropertyKeys(cx, recordObj,
    9491             :                              JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS, &ids)) {
    9492           0 :       return false;
    9493             :     }
    9494           0 :     if (!recordEntries.SetCapacity(ids.length(), mozilla::fallible)) {
    9495           0 :       JS_ReportOutOfMemory(cx);
    9496           0 :       return false;
    9497             :     }
    9498           0 :     JS::Rooted<JS::Value> propNameValue(cx);
    9499           0 :     JS::Rooted<JS::Value> temp(cx);
    9500           0 :     JS::Rooted<jsid> curId(cx);
    9501           0 :     JS::Rooted<JS::Value> idVal(cx);
    9502             :     // Use a hashset to keep track of ids seen, to avoid
    9503             :     // introducing nasty O(N^2) behavior scanning for them all the
    9504             :     // time.  Ideally we'd use a data structure with O(1) lookup
    9505             :     // _and_ ordering for the MozMap, but we don't have one lying
    9506             :     // around.
    9507           0 :     nsTHashtable<nsStringHashKey> idsSeen;
    9508           0 :     for (size_t i = 0; i < ids.length(); ++i) {
    9509           0 :       curId = ids[i];
    9510             : 
    9511           0 :       JS::Rooted<JS::PropertyDescriptor> desc(cx);
    9512           0 :       if (!JS_GetOwnPropertyDescriptorById(cx, recordObj, curId,
    9513             :                                            &desc)) {
    9514           0 :         return false;
    9515             :       }
    9516             : 
    9517           0 :       if (!desc.object() /* == undefined in spec terms */ ||
    9518           0 :           !desc.enumerable()) {
    9519           0 :         continue;
    9520             :       }
    9521             : 
    9522           0 :       idVal = js::IdToValue(curId);
    9523           0 :       nsString propName;
    9524             :       // This will just throw if idVal is a Symbol, like the spec says
    9525             :       // to do.
    9526           0 :       if (!ConvertJSValueToString(cx, idVal, propName)) {
    9527           0 :         return false;
    9528             :       }
    9529             : 
    9530           0 :       if (!JS_GetPropertyById(cx, recordObj, curId, &temp)) {
    9531           0 :         return false;
    9532             :       }
    9533             : 
    9534             :       Record<nsString, JSObject*>::EntryType* entry;
    9535           0 :       if (!idsSeen.EnsureInserted(propName)) {
    9536             :         // Find the existing entry.
    9537           0 :         auto idx = recordEntries.IndexOf(propName);
    9538           0 :         MOZ_ASSERT(idx != recordEntries.NoIndex,
    9539             :                    "Why is it not found?");
    9540             :         // Now blow it away to make it look like it was just added
    9541             :         // to the array, because it's not obvious that it's
    9542             :         // safe to write to its already-initialized mValue via our
    9543             :         // normal codegen conversions.  For example, the value
    9544             :         // could be a union and this would change its type, but
    9545             :         // codegen assumes we won't do that.
    9546           0 :         entry = recordEntries.ReconstructElementAt(idx);
    9547             :       } else {
    9548             :         // Safe to do an infallible append here, because we did a
    9549             :         // SetCapacity above to the right capacity.
    9550           0 :         entry = recordEntries.AppendElement();
    9551             :       }
    9552           0 :       entry->mKey = propName;
    9553           0 :       JSObject*& slot = entry->mValue;
    9554           0 :       if (temp.isObject()) {
    9555             : #ifdef __clang__
    9556             : #pragma clang diagnostic push
    9557             : #pragma clang diagnostic ignored "-Wunreachable-code"
    9558             : #pragma clang diagnostic ignored "-Wunreachable-code-return"
    9559             : #endif // __clang__
    9560           0 :         if ((passedToJSImpl) && !CallerSubsumes(temp)) {
    9561           0 :           ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "value in member of StringObjectRecordOrLong");
    9562           0 :           return false;
    9563             :         }
    9564             : #ifdef __clang__
    9565             : #pragma clang diagnostic pop
    9566             : #endif // __clang__
    9567           0 :         slot = &temp.toObject();
    9568             :       } else {
    9569           0 :         ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Value in member of StringObjectRecordOrLong");
    9570           0 :         return false;
    9571             :       }
    9572             :     }
    9573             :   }
    9574           0 :   return true;
    9575             : }
    9576             : 
    9577             : void
    9578           0 : OwningStringObjectRecordOrLong::DestroyStringObjectRecord()
    9579             : {
    9580           0 :   MOZ_ASSERT(IsStringObjectRecord(), "Wrong type!");
    9581           0 :   mValue.mStringObjectRecord.Destroy();
    9582           0 :   mType = eUninitialized;
    9583           0 : }
    9584             : 
    9585             : 
    9586             : 
    9587             : 
    9588             : int32_t&
    9589           0 : OwningStringObjectRecordOrLong::RawSetAsLong()
    9590             : {
    9591           0 :   if (mType == eLong) {
    9592           0 :     return mValue.mLong.Value();
    9593             :   }
    9594           0 :   MOZ_ASSERT(mType == eUninitialized);
    9595           0 :   mType = eLong;
    9596           0 :   return mValue.mLong.SetValue();
    9597             : }
    9598             : 
    9599             : int32_t&
    9600           0 : OwningStringObjectRecordOrLong::SetAsLong()
    9601             : {
    9602           0 :   if (mType == eLong) {
    9603           0 :     return mValue.mLong.Value();
    9604             :   }
    9605           0 :   Uninit();
    9606           0 :   mType = eLong;
    9607           0 :   return mValue.mLong.SetValue();
    9608             : }
    9609             : 
    9610             : bool
    9611           0 : OwningStringObjectRecordOrLong::TrySetToLong(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    9612             : {
    9613           0 :   tryNext = false;
    9614             :   { // scope for memberSlot
    9615           0 :     int32_t& memberSlot = RawSetAsLong();
    9616           0 :     if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
    9617           0 :       return false;
    9618             :     }
    9619             :   }
    9620           0 :   return true;
    9621             : }
    9622             : 
    9623             : void
    9624           0 : OwningStringObjectRecordOrLong::DestroyLong()
    9625             : {
    9626           0 :   MOZ_ASSERT(IsLong(), "Wrong type!");
    9627           0 :   mValue.mLong.Destroy();
    9628           0 :   mType = eUninitialized;
    9629           0 : }
    9630             : 
    9631             : 
    9632             : 
    9633             : 
    9634             : void
    9635           0 : OwningStringObjectRecordOrLong::Uninit()
    9636             : {
    9637           0 :   switch (mType) {
    9638             :     case eUninitialized: {
    9639           0 :       break;
    9640             :     }
    9641             :     case eStringObjectRecord: {
    9642           0 :       DestroyStringObjectRecord();
    9643           0 :       break;
    9644             :     }
    9645             :     case eLong: {
    9646           0 :       DestroyLong();
    9647           0 :       break;
    9648             :     }
    9649             :   }
    9650           0 : }
    9651             : 
    9652             : bool
    9653           0 : OwningStringObjectRecordOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    9654             : {
    9655           0 :   switch (mType) {
    9656             :     case eUninitialized: {
    9657           0 :       return false;
    9658             :       break;
    9659             :     }
    9660             :     case eStringObjectRecord: {
    9661             : 
    9662           0 :       JS::Rooted<JSObject*> returnObj(cx, JS_NewPlainObject(cx));
    9663           0 :       if (!returnObj) {
    9664           0 :         return false;
    9665             :       }
    9666             :       // Scope for 'tmp'
    9667             :       {
    9668           0 :         JS::Rooted<JS::Value> tmp(cx);
    9669           0 :         for (auto& entry : mValue.mStringObjectRecord.Value().Entries()) {
    9670           0 :           auto& recordValue0 = entry.mValue;
    9671             :           // Control block to let us common up the JS_DefineUCProperty calls when there
    9672             :           // are different ways to succeed at wrapping the value.
    9673             :           do {
    9674           0 :             JS::ExposeObjectToActiveJS(recordValue0);
    9675           0 :             tmp.setObject(*recordValue0);
    9676           0 :             if (!MaybeWrapObjectValue(cx, &tmp)) {
    9677           0 :               return false;
    9678             :             }
    9679           0 :             break;
    9680             :           } while (0);
    9681           0 :           if (!JS_DefineUCProperty(cx, returnObj,
    9682             :                                    entry.mKey.BeginReading(),
    9683           0 :                                    entry.mKey.Length(), tmp,
    9684             :                                    JSPROP_ENUMERATE)) {
    9685           0 :             return false;
    9686             :           }
    9687             :         }
    9688             :       }
    9689           0 :       rval.setObject(*returnObj);
    9690           0 :       return true;
    9691             :       break;
    9692             :     }
    9693             :     case eLong: {
    9694           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
    9695           0 :       return true;
    9696             :       break;
    9697             :     }
    9698             :     default: {
    9699           0 :       return false;
    9700             :       break;
    9701             :     }
    9702             :   }
    9703             : 
    9704             :   return false;
    9705             : }
    9706             : 
    9707             : void
    9708           0 : OwningStringObjectRecordOrLong::TraceUnion(JSTracer* trc)
    9709             : {
    9710           0 :   switch (mType) {
    9711             :     case eStringObjectRecord: {
    9712           0 :       TraceRecord(trc, mValue.mStringObjectRecord.Value());
    9713           0 :       break;
    9714             :     }
    9715             :     default: {
    9716           0 :       break;
    9717             :     }
    9718             :   }
    9719           0 : }
    9720             : 
    9721             : nsString&
    9722           0 : OwningStringOrObject::RawSetAsString()
    9723             : {
    9724           0 :   if (mType == eString) {
    9725           0 :     return mValue.mString.Value();
    9726             :   }
    9727           0 :   MOZ_ASSERT(mType == eUninitialized);
    9728           0 :   mType = eString;
    9729           0 :   return mValue.mString.SetValue();
    9730             : }
    9731             : 
    9732             : nsString&
    9733           0 : OwningStringOrObject::SetAsString()
    9734             : {
    9735           0 :   if (mType == eString) {
    9736           0 :     return mValue.mString.Value();
    9737             :   }
    9738           0 :   Uninit();
    9739           0 :   mType = eString;
    9740           0 :   return mValue.mString.SetValue();
    9741             : }
    9742             : 
    9743             : bool
    9744           0 : OwningStringOrObject::TrySetToString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    9745             : {
    9746           0 :   tryNext = false;
    9747             :   { // scope for memberSlot
    9748           0 :     nsString& memberSlot = RawSetAsString();
    9749           0 :     if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
    9750           0 :       return false;
    9751             :     }
    9752             :   }
    9753           0 :   return true;
    9754             : }
    9755             : 
    9756             : 
    9757             : void
    9758           0 : OwningStringOrObject::DestroyString()
    9759             : {
    9760           0 :   MOZ_ASSERT(IsString(), "Wrong type!");
    9761           0 :   mValue.mString.Destroy();
    9762           0 :   mType = eUninitialized;
    9763           0 : }
    9764             : 
    9765             : 
    9766             : 
    9767             : 
    9768             : JSObject*&
    9769           0 : OwningStringOrObject::RawSetAsObject()
    9770             : {
    9771           0 :   if (mType == eObject) {
    9772           0 :     return mValue.mObject.Value();
    9773             :   }
    9774           0 :   MOZ_ASSERT(mType == eUninitialized);
    9775           0 :   mType = eObject;
    9776           0 :   return mValue.mObject.SetValue();
    9777             : }
    9778             : 
    9779             : JSObject*&
    9780           0 : OwningStringOrObject::SetAsObject()
    9781             : {
    9782           0 :   if (mType == eObject) {
    9783           0 :     return mValue.mObject.Value();
    9784             :   }
    9785           0 :   Uninit();
    9786           0 :   mType = eObject;
    9787           0 :   return mValue.mObject.SetValue();
    9788             : }
    9789             : 
    9790             : 
    9791             : void
    9792           0 : OwningStringOrObject::DestroyObject()
    9793             : {
    9794           0 :   MOZ_ASSERT(IsObject(), "Wrong type!");
    9795           0 :   mValue.mObject.Destroy();
    9796           0 :   mType = eUninitialized;
    9797           0 : }
    9798             : 
    9799             : 
    9800             : 
    9801             : 
    9802             : void
    9803           0 : OwningStringOrObject::Uninit()
    9804             : {
    9805           0 :   switch (mType) {
    9806             :     case eUninitialized: {
    9807           0 :       break;
    9808             :     }
    9809             :     case eString: {
    9810           0 :       DestroyString();
    9811           0 :       break;
    9812             :     }
    9813             :     case eObject: {
    9814           0 :       DestroyObject();
    9815           0 :       break;
    9816             :     }
    9817             :   }
    9818           0 : }
    9819             : 
    9820             : bool
    9821           0 : OwningStringOrObject::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
    9822             : {
    9823           0 :   switch (mType) {
    9824             :     case eUninitialized: {
    9825           0 :       return false;
    9826             :       break;
    9827             :     }
    9828             :     case eString: {
    9829           0 :       if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) {
    9830           0 :         return false;
    9831             :       }
    9832           0 :       return true;
    9833             :       break;
    9834             :     }
    9835             :     case eObject: {
    9836           0 :       JS::ExposeObjectToActiveJS(mValue.mObject.Value());
    9837           0 :       rval.setObject(*mValue.mObject.Value());
    9838           0 :       if (!MaybeWrapObjectValue(cx, rval)) {
    9839           0 :         return false;
    9840             :       }
    9841           0 :       return true;
    9842             :       break;
    9843             :     }
    9844             :     default: {
    9845           0 :       return false;
    9846             :       break;
    9847             :     }
    9848             :   }
    9849             : 
    9850             :   return false;
    9851             : }
    9852             : 
    9853             : void
    9854           0 : OwningStringOrObject::TraceUnion(JSTracer* trc)
    9855             : {
    9856           0 :   switch (mType) {
    9857             :     case eObject: {
    9858           0 :       JS::UnsafeTraceRoot(trc, &mValue.mObject.Value(), "mValue.mObject");
    9859           0 :       break;
    9860             :     }
    9861             :     default: {
    9862           0 :       break;
    9863             :     }
    9864             :   }
    9865           0 : }
    9866             : 
    9867             : nsString&
    9868           0 : OwningStringOrStringSequence::RawSetAsString()
    9869             : {
    9870           0 :   if (mType == eString) {
    9871           0 :     return mValue.mString.Value();
    9872             :   }
    9873           0 :   MOZ_ASSERT(mType == eUninitialized);
    9874           0 :   mType = eString;
    9875           0 :   return mValue.mString.SetValue();
    9876             : }
    9877             : 
    9878             : nsString&
    9879           0 : OwningStringOrStringSequence::SetAsString()
    9880             : {
    9881           0 :   if (mType == eString) {
    9882           0 :     return mValue.mString.Value();
    9883             :   }
    9884           0 :   Uninit();
    9885           0 :   mType = eString;
    9886           0 :   return mValue.mString.SetValue();
    9887             : }
    9888             : 
    9889             : bool
    9890           0 : OwningStringOrStringSequence::TrySetToString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    9891             : {
    9892           0 :   tryNext = false;
    9893             :   { // scope for memberSlot
    9894           0 :     nsString& memberSlot = RawSetAsString();
    9895           0 :     if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
    9896           0 :       return false;
    9897             :     }
    9898             :   }
    9899           0 :   return true;
    9900             : }
    9901             : 
    9902             : 
    9903             : void
    9904           0 : OwningStringOrStringSequence::DestroyString()
    9905             : {
    9906           0 :   MOZ_ASSERT(IsString(), "Wrong type!");
    9907           0 :   mValue.mString.Destroy();
    9908           0 :   mType = eUninitialized;
    9909           0 : }
    9910             : 
    9911             : 
    9912             : 
    9913             : 
    9914             : Sequence<nsString>&
    9915           0 : OwningStringOrStringSequence::RawSetAsStringSequence()
    9916             : {
    9917           0 :   if (mType == eStringSequence) {
    9918           0 :     return mValue.mStringSequence.Value();
    9919             :   }
    9920           0 :   MOZ_ASSERT(mType == eUninitialized);
    9921           0 :   mType = eStringSequence;
    9922           0 :   return mValue.mStringSequence.SetValue();
    9923             : }
    9924             : 
    9925             : Sequence<nsString>&
    9926           0 : OwningStringOrStringSequence::SetAsStringSequence()
    9927             : {
    9928           0 :   if (mType == eStringSequence) {
    9929           0 :     return mValue.mStringSequence.Value();
    9930             :   }
    9931           0 :   Uninit();
    9932           0 :   mType = eStringSequence;
    9933           0 :   return mValue.mStringSequence.SetValue();
    9934             : }
    9935             : 
    9936             : bool
    9937           0 : OwningStringOrStringSequence::TrySetToStringSequence(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
    9938             : {
    9939           0 :   tryNext = false;
    9940             :   { // scope for memberSlot
    9941           0 :     Sequence<nsString>& memberSlot = RawSetAsStringSequence();
    9942           0 :     JS::ForOfIterator iter(cx);
    9943           0 :     if (!iter.init(value, JS::ForOfIterator::AllowNonIterable)) {
    9944           0 :       return false;
    9945             :     }
    9946           0 :     if (!iter.valueIsIterable()) {
    9947           0 :       DestroyStringSequence();
    9948           0 :       tryNext = true;
    9949           0 :       return true;
    9950             :     }
    9951           0 :     Sequence<nsString> &arr = memberSlot;
    9952           0 :     JS::Rooted<JS::Value> temp(cx);
    9953             :     while (true) {
    9954             :       bool done;
    9955           0 :       if (!iter.next(&temp, &done)) {
    9956           0 :         return false;
    9957             :       }
    9958           0 :       if (done) {
    9959           0 :         break;
    9960             :       }
    9961           0 :       nsString* slotPtr = arr.AppendElement(mozilla::fallible);
    9962           0 :       if (!slotPtr) {
    9963           0 :         JS_ReportOutOfMemory(cx);
    9964           0 :         return false;
    9965             :       }
    9966           0 :       nsString& slot = *slotPtr;
    9967           0 :       if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
    9968           0 :         return false;
    9969             :       }
    9970           0 :     }
    9971             :   }
    9972           0 :   return true;
    9973             : }
    9974             : 
    9975             : void
    9976           0 : OwningStringOrStringSequence::DestroyStringSequence()
    9977             : {
    9978           0 :   MOZ_ASSERT(IsStringSequence(), "Wrong type!");
    9979           0 :   mValue.mStringSequence.Destroy();
    9980           0 :   mType = eUninitialized;
    9981           0 : }
    9982             : 
    9983             : 
    9984             : 
    9985             : 
    9986             : void
    9987           0 : OwningStringOrStringSequence::Uninit()
    9988             : {
    9989           0 :   switch (mType) {
    9990             :     case eUninitialized: {
    9991           0 :       break;
    9992             :     }
    9993             :     case eString: {
    9994           0 :       DestroyString();
    9995           0 :       break;
    9996             :     }
    9997             :     case eStringSequence: {
    9998           0 :       DestroyStringSequence();
    9999           0 :       break;
   10000             :     }
   10001             :   }
   10002           0 : }
   10003             : 
   10004             : bool
   10005           0 : OwningStringOrStringSequence::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
   10006             : {
   10007           0 :   switch (mType) {
   10008             :     case eUninitialized: {
   10009           0 :       return false;
   10010             :       break;
   10011             :     }
   10012             :     case eString: {
   10013           0 :       if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) {
   10014           0 :         return false;
   10015             :       }
   10016           0 :       return true;
   10017             :       break;
   10018             :     }
   10019             :     case eStringSequence: {
   10020             : 
   10021           0 :       uint32_t length = mValue.mStringSequence.Value().Length();
   10022           0 :       JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
   10023           0 :       if (!returnArray) {
   10024           0 :         return false;
   10025             :       }
   10026             :       // Scope for 'tmp'
   10027             :       {
   10028           0 :         JS::Rooted<JS::Value> tmp(cx);
   10029           0 :         for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
   10030             :           // Control block to let us common up the JS_DefineElement calls when there
   10031             :           // are different ways to succeed at wrapping the object.
   10032             :           do {
   10033           0 :             if (!xpc::NonVoidStringToJsval(cx, mValue.mStringSequence.Value()[sequenceIdx0], &tmp)) {
   10034           0 :               return false;
   10035             :             }
   10036           0 :             break;
   10037             :           } while (0);
   10038           0 :           if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
   10039             :                                 JSPROP_ENUMERATE)) {
   10040           0 :             return false;
   10041             :           }
   10042             :         }
   10043             :       }
   10044           0 :       rval.setObject(*returnArray);
   10045           0 :       return true;
   10046             :       break;
   10047             :     }
   10048             :     default: {
   10049           0 :       return false;
   10050             :       break;
   10051             :     }
   10052             :   }
   10053             : 
   10054             :   return false;
   10055             : }
   10056             : 
   10057             : void
   10058           0 : OwningStringOrStringSequence::TraceUnion(JSTracer* trc)
   10059             : {
   10060           0 : }
   10061             : 
   10062             : OwningStringOrStringSequence&
   10063           0 : OwningStringOrStringSequence::operator=(const OwningStringOrStringSequence& aOther)
   10064             : {
   10065           0 :   switch (aOther.mType) {
   10066             :     case eUninitialized: {
   10067           0 :       MOZ_ASSERT(mType == eUninitialized,
   10068             :                  "We need to destroy ourselves?");
   10069           0 :       break;
   10070             :     }
   10071             :     case eString: {
   10072           0 :       SetAsString() = aOther.GetAsString();
   10073           0 :       break;
   10074             :     }
   10075             :     case eStringSequence: {
   10076           0 :       SetAsStringSequence() = aOther.GetAsStringSequence();
   10077           0 :       break;
   10078             :     }
   10079             :   }
   10080           0 :   return *this;
   10081             : }
   10082             : 
   10083             : Sequence<nsString>&
   10084           0 : OwningStringSequenceOrEventInit::RawSetAsStringSequence()
   10085             : {
   10086           0 :   if (mType == eStringSequence) {
   10087           0 :     return mValue.mStringSequence.Value();
   10088             :   }
   10089           0 :   MOZ_ASSERT(mType == eUninitialized);
   10090           0 :   mType = eStringSequence;
   10091           0 :   return mValue.mStringSequence.SetValue();
   10092             : }
   10093             : 
   10094             : Sequence<nsString>&
   10095           0 : OwningStringSequenceOrEventInit::SetAsStringSequence()
   10096             : {
   10097           0 :   if (mType == eStringSequence) {
   10098           0 :     return mValue.mStringSequence.Value();
   10099             :   }
   10100           0 :   Uninit();
   10101           0 :   mType = eStringSequence;
   10102           0 :   return mValue.mStringSequence.SetValue();
   10103             : }
   10104             : 
   10105             : bool
   10106           0 : OwningStringSequenceOrEventInit::TrySetToStringSequence(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
   10107             : {
   10108           0 :   tryNext = false;
   10109             :   { // scope for memberSlot
   10110           0 :     Sequence<nsString>& memberSlot = RawSetAsStringSequence();
   10111           0 :     JS::ForOfIterator iter(cx);
   10112           0 :     if (!iter.init(value, JS::ForOfIterator::AllowNonIterable)) {
   10113           0 :       return false;
   10114             :     }
   10115           0 :     if (!iter.valueIsIterable()) {
   10116           0 :       DestroyStringSequence();
   10117           0 :       tryNext = true;
   10118           0 :       return true;
   10119             :     }
   10120           0 :     Sequence<nsString> &arr = memberSlot;
   10121           0 :     JS::Rooted<JS::Value> temp(cx);
   10122             :     while (true) {
   10123             :       bool done;
   10124           0 :       if (!iter.next(&temp, &done)) {
   10125           0 :         return false;
   10126             :       }
   10127           0 :       if (done) {
   10128           0 :         break;
   10129             :       }
   10130           0 :       nsString* slotPtr = arr.AppendElement(mozilla::fallible);
   10131           0 :       if (!slotPtr) {
   10132           0 :         JS_ReportOutOfMemory(cx);
   10133           0 :         return false;
   10134             :       }
   10135           0 :       nsString& slot = *slotPtr;
   10136           0 :       if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
   10137           0 :         return false;
   10138             :       }
   10139           0 :     }
   10140             :   }
   10141           0 :   return true;
   10142             : }
   10143             : 
   10144             : void
   10145           0 : OwningStringSequenceOrEventInit::DestroyStringSequence()
   10146             : {
   10147           0 :   MOZ_ASSERT(IsStringSequence(), "Wrong type!");
   10148           0 :   mValue.mStringSequence.Destroy();
   10149           0 :   mType = eUninitialized;
   10150           0 : }
   10151             : 
   10152             : 
   10153             : 
   10154             : 
   10155             : EventInit&
   10156           0 : OwningStringSequenceOrEventInit::RawSetAsEventInit()
   10157             : {
   10158           0 :   if (mType == eEventInit) {
   10159           0 :     return mValue.mEventInit.Value();
   10160             :   }
   10161           0 :   MOZ_ASSERT(mType == eUninitialized);
   10162           0 :   mType = eEventInit;
   10163           0 :   return mValue.mEventInit.SetValue();
   10164             : }
   10165             : 
   10166             : EventInit&
   10167           0 : OwningStringSequenceOrEventInit::SetAsEventInit()
   10168             : {
   10169           0 :   if (mType == eEventInit) {
   10170           0 :     return mValue.mEventInit.Value();
   10171             :   }
   10172           0 :   Uninit();
   10173           0 :   mType = eEventInit;
   10174           0 :   return mValue.mEventInit.SetValue();
   10175             : }
   10176             : 
   10177             : bool
   10178           0 : OwningStringSequenceOrEventInit::TrySetToEventInit(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
   10179             : {
   10180           0 :   tryNext = false;
   10181             :   { // scope for memberSlot
   10182           0 :     EventInit& memberSlot = RawSetAsEventInit();
   10183           0 :     if (!IsConvertibleToDictionary(value)) {
   10184           0 :       DestroyEventInit();
   10185           0 :       tryNext = true;
   10186           0 :       return true;
   10187             :     }
   10188           0 :     if (!memberSlot.Init(cx, value,  "Member of StringSequenceOrEventInit", passedToJSImpl)) {
   10189           0 :       return false;
   10190             :     }
   10191             :   }
   10192           0 :   return true;
   10193             : }
   10194             : 
   10195             : void
   10196           0 : OwningStringSequenceOrEventInit::DestroyEventInit()
   10197             : {
   10198           0 :   MOZ_ASSERT(IsEventInit(), "Wrong type!");
   10199           0 :   mValue.mEventInit.Destroy();
   10200           0 :   mType = eUninitialized;
   10201           0 : }
   10202             : 
   10203             : 
   10204             : 
   10205             : 
   10206             : void
   10207           0 : OwningStringSequenceOrEventInit::Uninit()
   10208             : {
   10209           0 :   switch (mType) {
   10210             :     case eUninitialized: {
   10211           0 :       break;
   10212             :     }
   10213             :     case eStringSequence: {
   10214           0 :       DestroyStringSequence();
   10215           0 :       break;
   10216             :     }
   10217             :     case eEventInit: {
   10218           0 :       DestroyEventInit();
   10219           0 :       break;
   10220             :     }
   10221             :   }
   10222           0 : }
   10223             : 
   10224             : bool
   10225           0 : OwningStringSequenceOrEventInit::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
   10226             : {
   10227           0 :   switch (mType) {
   10228             :     case eUninitialized: {
   10229           0 :       return false;
   10230             :       break;
   10231             :     }
   10232             :     case eStringSequence: {
   10233             : 
   10234           0 :       uint32_t length = mValue.mStringSequence.Value().Length();
   10235           0 :       JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
   10236           0 :       if (!returnArray) {
   10237           0 :         return false;
   10238             :       }
   10239             :       // Scope for 'tmp'
   10240             :       {
   10241           0 :         JS::Rooted<JS::Value> tmp(cx);
   10242           0 :         for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
   10243             :           // Control block to let us common up the JS_DefineElement calls when there
   10244             :           // are different ways to succeed at wrapping the object.
   10245             :           do {
   10246           0 :             if (!xpc::NonVoidStringToJsval(cx, mValue.mStringSequence.Value()[sequenceIdx0], &tmp)) {
   10247           0 :               return false;
   10248             :             }
   10249           0 :             break;
   10250             :           } while (0);
   10251           0 :           if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
   10252             :                                 JSPROP_ENUMERATE)) {
   10253           0 :             return false;
   10254             :           }
   10255             :         }
   10256             :       }
   10257           0 :       rval.setObject(*returnArray);
   10258           0 :       return true;
   10259             :       break;
   10260             :     }
   10261             :     case eEventInit: {
   10262           0 :       if (!mValue.mEventInit.Value().ToObjectInternal(cx, rval)) {
   10263           0 :         return false;
   10264             :       }
   10265           0 :       return true;
   10266             :       break;
   10267             :     }
   10268             :     default: {
   10269           0 :       return false;
   10270             :       break;
   10271             :     }
   10272             :   }
   10273             : 
   10274             :   return false;
   10275             : }
   10276             : 
   10277             : void
   10278           0 : OwningStringSequenceOrEventInit::TraceUnion(JSTracer* trc)
   10279             : {
   10280           0 : }
   10281             : 
   10282             : OwningStringSequenceOrEventInit&
   10283           0 : OwningStringSequenceOrEventInit::operator=(const OwningStringSequenceOrEventInit& aOther)
   10284             : {
   10285           0 :   switch (aOther.mType) {
   10286             :     case eUninitialized: {
   10287           0 :       MOZ_ASSERT(mType == eUninitialized,
   10288             :                  "We need to destroy ourselves?");
   10289           0 :       break;
   10290             :     }
   10291             :     case eStringSequence: {
   10292           0 :       SetAsStringSequence() = aOther.GetAsStringSequence();
   10293           0 :       break;
   10294             :     }
   10295             :     case eEventInit: {
   10296           0 :       SetAsEventInit() = aOther.GetAsEventInit();
   10297           0 :       break;
   10298             :     }
   10299             :   }
   10300           0 :   return *this;
   10301             : }
   10302             : 
   10303             : Sequence<nsString>&
   10304           0 : OwningStringSequenceOrStringStringRecord::RawSetAsStringSequence()
   10305             : {
   10306           0 :   if (mType == eStringSequence) {
   10307           0 :     return mValue.mStringSequence.Value();
   10308             :   }
   10309           0 :   MOZ_ASSERT(mType == eUninitialized);
   10310           0 :   mType = eStringSequence;
   10311           0 :   return mValue.mStringSequence.SetValue();
   10312             : }
   10313             : 
   10314             : Sequence<nsString>&
   10315           0 : OwningStringSequenceOrStringStringRecord::SetAsStringSequence()
   10316             : {
   10317           0 :   if (mType == eStringSequence) {
   10318           0 :     return mValue.mStringSequence.Value();
   10319             :   }
   10320           0 :   Uninit();
   10321           0 :   mType = eStringSequence;
   10322           0 :   return mValue.mStringSequence.SetValue();
   10323             : }
   10324             : 
   10325             : bool
   10326           0 : OwningStringSequenceOrStringStringRecord::TrySetToStringSequence(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
   10327             : {
   10328           0 :   tryNext = false;
   10329             :   { // scope for memberSlot
   10330           0 :     Sequence<nsString>& memberSlot = RawSetAsStringSequence();
   10331           0 :     JS::ForOfIterator iter(cx);
   10332           0 :     if (!iter.init(value, JS::ForOfIterator::AllowNonIterable)) {
   10333           0 :       return false;
   10334             :     }
   10335           0 :     if (!iter.valueIsIterable()) {
   10336           0 :       DestroyStringSequence();
   10337           0 :       tryNext = true;
   10338           0 :       return true;
   10339             :     }
   10340           0 :     Sequence<nsString> &arr = memberSlot;
   10341           0 :     JS::Rooted<JS::Value> temp(cx);
   10342             :     while (true) {
   10343             :       bool done;
   10344           0 :       if (!iter.next(&temp, &done)) {
   10345           0 :         return false;
   10346             :       }
   10347           0 :       if (done) {
   10348           0 :         break;
   10349             :       }
   10350           0 :       nsString* slotPtr = arr.AppendElement(mozilla::fallible);
   10351           0 :       if (!slotPtr) {
   10352           0 :         JS_ReportOutOfMemory(cx);
   10353           0 :         return false;
   10354             :       }
   10355           0 :       nsString& slot = *slotPtr;
   10356           0 :       if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
   10357           0 :         return false;
   10358             :       }
   10359           0 :     }
   10360             :   }
   10361           0 :   return true;
   10362             : }
   10363             : 
   10364             : void
   10365           0 : OwningStringSequenceOrStringStringRecord::DestroyStringSequence()
   10366             : {
   10367           0 :   MOZ_ASSERT(IsStringSequence(), "Wrong type!");
   10368           0 :   mValue.mStringSequence.Destroy();
   10369           0 :   mType = eUninitialized;
   10370           0 : }
   10371             : 
   10372             : 
   10373             : 
   10374             : 
   10375             : Record<nsString, nsString>&
   10376           0 : OwningStringSequenceOrStringStringRecord::RawSetAsStringStringRecord()
   10377             : {
   10378           0 :   if (mType == eStringStringRecord) {
   10379           0 :     return mValue.mStringStringRecord.Value();
   10380             :   }
   10381           0 :   MOZ_ASSERT(mType == eUninitialized);
   10382           0 :   mType = eStringStringRecord;
   10383           0 :   return mValue.mStringStringRecord.SetValue();
   10384             : }
   10385             : 
   10386             : Record<nsString, nsString>&
   10387           0 : OwningStringSequenceOrStringStringRecord::SetAsStringStringRecord()
   10388             : {
   10389           0 :   if (mType == eStringStringRecord) {
   10390           0 :     return mValue.mStringStringRecord.Value();
   10391             :   }
   10392           0 :   Uninit();
   10393           0 :   mType = eStringStringRecord;
   10394           0 :   return mValue.mStringStringRecord.SetValue();
   10395             : }
   10396             : 
   10397             : bool
   10398           0 : OwningStringSequenceOrStringStringRecord::TrySetToStringStringRecord(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
   10399             : {
   10400           0 :   tryNext = false;
   10401             :   { // scope for memberSlot
   10402           0 :     Record<nsString, nsString>& memberSlot = RawSetAsStringStringRecord();
   10403           0 :     auto& recordEntries = memberSlot.Entries();
   10404             : 
   10405           0 :     JS::Rooted<JSObject*> recordObj(cx, &value.toObject());
   10406           0 :     JS::AutoIdVector ids(cx);
   10407           0 :     if (!js::GetPropertyKeys(cx, recordObj,
   10408             :                              JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS, &ids)) {
   10409           0 :       return false;
   10410             :     }
   10411           0 :     if (!recordEntries.SetCapacity(ids.length(), mozilla::fallible)) {
   10412           0 :       JS_ReportOutOfMemory(cx);
   10413           0 :       return false;
   10414             :     }
   10415           0 :     JS::Rooted<JS::Value> propNameValue(cx);
   10416           0 :     JS::Rooted<JS::Value> temp(cx);
   10417           0 :     JS::Rooted<jsid> curId(cx);
   10418           0 :     JS::Rooted<JS::Value> idVal(cx);
   10419             :     // Use a hashset to keep track of ids seen, to avoid
   10420             :     // introducing nasty O(N^2) behavior scanning for them all the
   10421             :     // time.  Ideally we'd use a data structure with O(1) lookup
   10422             :     // _and_ ordering for the MozMap, but we don't have one lying
   10423             :     // around.
   10424           0 :     nsTHashtable<nsStringHashKey> idsSeen;
   10425           0 :     for (size_t i = 0; i < ids.length(); ++i) {
   10426           0 :       curId = ids[i];
   10427             : 
   10428           0 :       JS::Rooted<JS::PropertyDescriptor> desc(cx);
   10429           0 :       if (!JS_GetOwnPropertyDescriptorById(cx, recordObj, curId,
   10430             :                                            &desc)) {
   10431           0 :         return false;
   10432             :       }
   10433             : 
   10434           0 :       if (!desc.object() /* == undefined in spec terms */ ||
   10435           0 :           !desc.enumerable()) {
   10436           0 :         continue;
   10437             :       }
   10438             : 
   10439           0 :       idVal = js::IdToValue(curId);
   10440           0 :       nsString propName;
   10441             :       // This will just throw if idVal is a Symbol, like the spec says
   10442             :       // to do.
   10443           0 :       if (!ConvertJSValueToString(cx, idVal, propName)) {
   10444           0 :         return false;
   10445             :       }
   10446             : 
   10447           0 :       if (!JS_GetPropertyById(cx, recordObj, curId, &temp)) {
   10448           0 :         return false;
   10449             :       }
   10450             : 
   10451             :       Record<nsString, nsString>::EntryType* entry;
   10452           0 :       if (!idsSeen.EnsureInserted(propName)) {
   10453             :         // Find the existing entry.
   10454           0 :         auto idx = recordEntries.IndexOf(propName);
   10455           0 :         MOZ_ASSERT(idx != recordEntries.NoIndex,
   10456             :                    "Why is it not found?");
   10457             :         // Now blow it away to make it look like it was just added
   10458             :         // to the array, because it's not obvious that it's
   10459             :         // safe to write to its already-initialized mValue via our
   10460             :         // normal codegen conversions.  For example, the value
   10461             :         // could be a union and this would change its type, but
   10462             :         // codegen assumes we won't do that.
   10463           0 :         entry = recordEntries.ReconstructElementAt(idx);
   10464             :       } else {
   10465             :         // Safe to do an infallible append here, because we did a
   10466             :         // SetCapacity above to the right capacity.
   10467           0 :         entry = recordEntries.AppendElement();
   10468             :       }
   10469           0 :       entry->mKey = propName;
   10470           0 :       nsString& slot = entry->mValue;
   10471           0 :       if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
   10472           0 :         return false;
   10473             :       }
   10474             :     }
   10475             :   }
   10476           0 :   return true;
   10477             : }
   10478             : 
   10479             : void
   10480           0 : OwningStringSequenceOrStringStringRecord::DestroyStringStringRecord()
   10481             : {
   10482           0 :   MOZ_ASSERT(IsStringStringRecord(), "Wrong type!");
   10483           0 :   mValue.mStringStringRecord.Destroy();
   10484           0 :   mType = eUninitialized;
   10485           0 : }
   10486             : 
   10487             : 
   10488             : 
   10489             : 
   10490             : void
   10491           0 : OwningStringSequenceOrStringStringRecord::Uninit()
   10492             : {
   10493           0 :   switch (mType) {
   10494             :     case eUninitialized: {
   10495           0 :       break;
   10496             :     }
   10497             :     case eStringSequence: {
   10498           0 :       DestroyStringSequence();
   10499           0 :       break;
   10500             :     }
   10501             :     case eStringStringRecord: {
   10502           0 :       DestroyStringStringRecord();
   10503           0 :       break;
   10504             :     }
   10505             :   }
   10506           0 : }
   10507             : 
   10508             : bool
   10509           0 : OwningStringSequenceOrStringStringRecord::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
   10510             : {
   10511           0 :   switch (mType) {
   10512             :     case eUninitialized: {
   10513           0 :       return false;
   10514             :       break;
   10515             :     }
   10516             :     case eStringSequence: {
   10517             : 
   10518           0 :       uint32_t length = mValue.mStringSequence.Value().Length();
   10519           0 :       JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
   10520           0 :       if (!returnArray) {
   10521           0 :         return false;
   10522             :       }
   10523             :       // Scope for 'tmp'
   10524             :       {
   10525           0 :         JS::Rooted<JS::Value> tmp(cx);
   10526           0 :         for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
   10527             :           // Control block to let us common up the JS_DefineElement calls when there
   10528             :           // are different ways to succeed at wrapping the object.
   10529             :           do {
   10530           0 :             if (!xpc::NonVoidStringToJsval(cx, mValue.mStringSequence.Value()[sequenceIdx0], &tmp)) {
   10531           0 :               return false;
   10532             :             }
   10533           0 :             break;
   10534             :           } while (0);
   10535           0 :           if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
   10536             :                                 JSPROP_ENUMERATE)) {
   10537           0 :             return false;
   10538             :           }
   10539             :         }
   10540             :       }
   10541           0 :       rval.setObject(*returnArray);
   10542           0 :       return true;
   10543             :       break;
   10544             :     }
   10545             :     case eStringStringRecord: {
   10546             : 
   10547           0 :       JS::Rooted<JSObject*> returnObj(cx, JS_NewPlainObject(cx));
   10548           0 :       if (!returnObj) {
   10549           0 :         return false;
   10550             :       }
   10551             :       // Scope for 'tmp'
   10552             :       {
   10553           0 :         JS::Rooted<JS::Value> tmp(cx);
   10554           0 :         for (auto& entry : mValue.mStringStringRecord.Value().Entries()) {
   10555           0 :           auto& recordValue0 = entry.mValue;
   10556             :           // Control block to let us common up the JS_DefineUCProperty calls when there
   10557             :           // are different ways to succeed at wrapping the value.
   10558             :           do {
   10559           0 :             if (!xpc::NonVoidStringToJsval(cx, recordValue0, &tmp)) {
   10560           0 :               return false;
   10561             :             }
   10562           0 :             break;
   10563             :           } while (0);
   10564           0 :           if (!JS_DefineUCProperty(cx, returnObj,
   10565             :                                    entry.mKey.BeginReading(),
   10566           0 :                                    entry.mKey.Length(), tmp,
   10567             :                                    JSPROP_ENUMERATE)) {
   10568           0 :             return false;
   10569             :           }
   10570             :         }
   10571             :       }
   10572           0 :       rval.setObject(*returnObj);
   10573           0 :       return true;
   10574             :       break;
   10575             :     }
   10576             :     default: {
   10577           0 :       return false;
   10578             :       break;
   10579             :     }
   10580             :   }
   10581             : 
   10582             :   return false;
   10583             : }
   10584             : 
   10585             : void
   10586           0 : OwningStringSequenceOrStringStringRecord::TraceUnion(JSTracer* trc)
   10587             : {
   10588           0 : }
   10589             : 
   10590             : Record<nsString, nsString>&
   10591           0 : OwningStringStringRecordOrString::RawSetAsStringStringRecord()
   10592             : {
   10593           0 :   if (mType == eStringStringRecord) {
   10594           0 :     return mValue.mStringStringRecord.Value();
   10595             :   }
   10596           0 :   MOZ_ASSERT(mType == eUninitialized);
   10597           0 :   mType = eStringStringRecord;
   10598           0 :   return mValue.mStringStringRecord.SetValue();
   10599             : }
   10600             : 
   10601             : Record<nsString, nsString>&
   10602           0 : OwningStringStringRecordOrString::SetAsStringStringRecord()
   10603             : {
   10604           0 :   if (mType == eStringStringRecord) {
   10605           0 :     return mValue.mStringStringRecord.Value();
   10606             :   }
   10607           0 :   Uninit();
   10608           0 :   mType = eStringStringRecord;
   10609           0 :   return mValue.mStringStringRecord.SetValue();
   10610             : }
   10611             : 
   10612             : bool
   10613           0 : OwningStringStringRecordOrString::TrySetToStringStringRecord(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
   10614             : {
   10615           0 :   tryNext = false;
   10616             :   { // scope for memberSlot
   10617           0 :     Record<nsString, nsString>& memberSlot = RawSetAsStringStringRecord();
   10618           0 :     auto& recordEntries = memberSlot.Entries();
   10619             : 
   10620           0 :     JS::Rooted<JSObject*> recordObj(cx, &value.toObject());
   10621           0 :     JS::AutoIdVector ids(cx);
   10622           0 :     if (!js::GetPropertyKeys(cx, recordObj,
   10623             :                              JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS, &ids)) {
   10624           0 :       return false;
   10625             :     }
   10626           0 :     if (!recordEntries.SetCapacity(ids.length(), mozilla::fallible)) {
   10627           0 :       JS_ReportOutOfMemory(cx);
   10628           0 :       return false;
   10629             :     }
   10630           0 :     JS::Rooted<JS::Value> propNameValue(cx);
   10631           0 :     JS::Rooted<JS::Value> temp(cx);
   10632           0 :     JS::Rooted<jsid> curId(cx);
   10633           0 :     JS::Rooted<JS::Value> idVal(cx);
   10634             :     // Use a hashset to keep track of ids seen, to avoid
   10635             :     // introducing nasty O(N^2) behavior scanning for them all the
   10636             :     // time.  Ideally we'd use a data structure with O(1) lookup
   10637             :     // _and_ ordering for the MozMap, but we don't have one lying
   10638             :     // around.
   10639           0 :     nsTHashtable<nsStringHashKey> idsSeen;
   10640           0 :     for (size_t i = 0; i < ids.length(); ++i) {
   10641           0 :       curId = ids[i];
   10642             : 
   10643           0 :       JS::Rooted<JS::PropertyDescriptor> desc(cx);
   10644           0 :       if (!JS_GetOwnPropertyDescriptorById(cx, recordObj, curId,
   10645             :                                            &desc)) {
   10646           0 :         return false;
   10647             :       }
   10648             : 
   10649           0 :       if (!desc.object() /* == undefined in spec terms */ ||
   10650           0 :           !desc.enumerable()) {
   10651           0 :         continue;
   10652             :       }
   10653             : 
   10654           0 :       idVal = js::IdToValue(curId);
   10655           0 :       nsString propName;
   10656             :       // This will just throw if idVal is a Symbol, like the spec says
   10657             :       // to do.
   10658           0 :       if (!ConvertJSValueToString(cx, idVal, propName)) {
   10659           0 :         return false;
   10660             :       }
   10661             : 
   10662           0 :       if (!JS_GetPropertyById(cx, recordObj, curId, &temp)) {
   10663           0 :         return false;
   10664             :       }
   10665             : 
   10666             :       Record<nsString, nsString>::EntryType* entry;
   10667           0 :       if (!idsSeen.EnsureInserted(propName)) {
   10668             :         // Find the existing entry.
   10669           0 :         auto idx = recordEntries.IndexOf(propName);
   10670           0 :         MOZ_ASSERT(idx != recordEntries.NoIndex,
   10671             :                    "Why is it not found?");
   10672             :         // Now blow it away to make it look like it was just added
   10673             :         // to the array, because it's not obvious that it's
   10674             :         // safe to write to its already-initialized mValue via our
   10675             :         // normal codegen conversions.  For example, the value
   10676             :         // could be a union and this would change its type, but
   10677             :         // codegen assumes we won't do that.
   10678           0 :         entry = recordEntries.ReconstructElementAt(idx);
   10679             :       } else {
   10680             :         // Safe to do an infallible append here, because we did a
   10681             :         // SetCapacity above to the right capacity.
   10682           0 :         entry = recordEntries.AppendElement();
   10683             :       }
   10684           0 :       entry->mKey = propName;
   10685           0 :       nsString& slot = entry->mValue;
   10686           0 :       if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
   10687           0 :         return false;
   10688             :       }
   10689             :     }
   10690             :   }
   10691           0 :   return true;
   10692             : }
   10693             : 
   10694             : void
   10695           0 : OwningStringStringRecordOrString::DestroyStringStringRecord()
   10696             : {
   10697           0 :   MOZ_ASSERT(IsStringStringRecord(), "Wrong type!");
   10698           0 :   mValue.mStringStringRecord.Destroy();
   10699           0 :   mType = eUninitialized;
   10700           0 : }
   10701             : 
   10702             : 
   10703             : 
   10704             : 
   10705             : nsString&
   10706           0 : OwningStringStringRecordOrString::RawSetAsString()
   10707             : {
   10708           0 :   if (mType == eString) {
   10709           0 :     return mValue.mString.Value();
   10710             :   }
   10711           0 :   MOZ_ASSERT(mType == eUninitialized);
   10712           0 :   mType = eString;
   10713           0 :   return mValue.mString.SetValue();
   10714             : }
   10715             : 
   10716             : nsString&
   10717           0 : OwningStringStringRecordOrString::SetAsString()
   10718             : {
   10719           0 :   if (mType == eString) {
   10720           0 :     return mValue.mString.Value();
   10721             :   }
   10722           0 :   Uninit();
   10723           0 :   mType = eString;
   10724           0 :   return mValue.mString.SetValue();
   10725             : }
   10726             : 
   10727             : bool
   10728           0 : OwningStringStringRecordOrString::TrySetToString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
   10729             : {
   10730           0 :   tryNext = false;
   10731             :   { // scope for memberSlot
   10732           0 :     nsString& memberSlot = RawSetAsString();
   10733           0 :     if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
   10734           0 :       return false;
   10735             :     }
   10736             :   }
   10737           0 :   return true;
   10738             : }
   10739             : 
   10740             : 
   10741             : void
   10742           0 : OwningStringStringRecordOrString::DestroyString()
   10743             : {
   10744           0 :   MOZ_ASSERT(IsString(), "Wrong type!");
   10745           0 :   mValue.mString.Destroy();
   10746           0 :   mType = eUninitialized;
   10747           0 : }
   10748             : 
   10749             : 
   10750             : 
   10751             : 
   10752             : void
   10753           0 : OwningStringStringRecordOrString::Uninit()
   10754             : {
   10755           0 :   switch (mType) {
   10756             :     case eUninitialized: {
   10757           0 :       break;
   10758             :     }
   10759             :     case eStringStringRecord: {
   10760           0 :       DestroyStringStringRecord();
   10761           0 :       break;
   10762             :     }
   10763             :     case eString: {
   10764           0 :       DestroyString();
   10765           0 :       break;
   10766             :     }
   10767             :   }
   10768           0 : }
   10769             : 
   10770             : bool
   10771           0 : OwningStringStringRecordOrString::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
   10772             : {
   10773           0 :   switch (mType) {
   10774             :     case eUninitialized: {
   10775           0 :       return false;
   10776             :       break;
   10777             :     }
   10778             :     case eStringStringRecord: {
   10779             : 
   10780           0 :       JS::Rooted<JSObject*> returnObj(cx, JS_NewPlainObject(cx));
   10781           0 :       if (!returnObj) {
   10782           0 :         return false;
   10783             :       }
   10784             :       // Scope for 'tmp'
   10785             :       {
   10786           0 :         JS::Rooted<JS::Value> tmp(cx);
   10787           0 :         for (auto& entry : mValue.mStringStringRecord.Value().Entries()) {
   10788           0 :           auto& recordValue0 = entry.mValue;
   10789             :           // Control block to let us common up the JS_DefineUCProperty calls when there
   10790             :           // are different ways to succeed at wrapping the value.
   10791             :           do {
   10792           0 :             if (!xpc::NonVoidStringToJsval(cx, recordValue0, &tmp)) {
   10793           0 :               return false;
   10794             :             }
   10795           0 :             break;
   10796             :           } while (0);
   10797           0 :           if (!JS_DefineUCProperty(cx, returnObj,
   10798             :                                    entry.mKey.BeginReading(),
   10799           0 :                                    entry.mKey.Length(), tmp,
   10800             :                                    JSPROP_ENUMERATE)) {
   10801           0 :             return false;
   10802             :           }
   10803             :         }
   10804             :       }
   10805           0 :       rval.setObject(*returnObj);
   10806           0 :       return true;
   10807             :       break;
   10808             :     }
   10809             :     case eString: {
   10810           0 :       if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) {
   10811           0 :         return false;
   10812             :       }
   10813           0 :       return true;
   10814             :       break;
   10815             :     }
   10816             :     default: {
   10817           0 :       return false;
   10818             :       break;
   10819             :     }
   10820             :   }
   10821             : 
   10822             :   return false;
   10823             : }
   10824             : 
   10825             : void
   10826           0 : OwningStringStringRecordOrString::TraceUnion(JSTracer* trc)
   10827             : {
   10828           0 : }
   10829             : 
   10830             : Record<nsString, nsString>&
   10831           0 : OwningStringStringRecordOrStringSequence::RawSetAsStringStringRecord()
   10832             : {
   10833           0 :   if (mType == eStringStringRecord) {
   10834           0 :     return mValue.mStringStringRecord.Value();
   10835             :   }
   10836           0 :   MOZ_ASSERT(mType == eUninitialized);
   10837           0 :   mType = eStringStringRecord;
   10838           0 :   return mValue.mStringStringRecord.SetValue();
   10839             : }
   10840             : 
   10841             : Record<nsString, nsString>&
   10842           0 : OwningStringStringRecordOrStringSequence::SetAsStringStringRecord()
   10843             : {
   10844           0 :   if (mType == eStringStringRecord) {
   10845           0 :     return mValue.mStringStringRecord.Value();
   10846             :   }
   10847           0 :   Uninit();
   10848           0 :   mType = eStringStringRecord;
   10849           0 :   return mValue.mStringStringRecord.SetValue();
   10850             : }
   10851             : 
   10852             : bool
   10853           0 : OwningStringStringRecordOrStringSequence::TrySetToStringStringRecord(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
   10854             : {
   10855           0 :   tryNext = false;
   10856             :   { // scope for memberSlot
   10857           0 :     Record<nsString, nsString>& memberSlot = RawSetAsStringStringRecord();
   10858           0 :     auto& recordEntries = memberSlot.Entries();
   10859             : 
   10860           0 :     JS::Rooted<JSObject*> recordObj(cx, &value.toObject());
   10861           0 :     JS::AutoIdVector ids(cx);
   10862           0 :     if (!js::GetPropertyKeys(cx, recordObj,
   10863             :                              JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS, &ids)) {
   10864           0 :       return false;
   10865             :     }
   10866           0 :     if (!recordEntries.SetCapacity(ids.length(), mozilla::fallible)) {
   10867           0 :       JS_ReportOutOfMemory(cx);
   10868           0 :       return false;
   10869             :     }
   10870           0 :     JS::Rooted<JS::Value> propNameValue(cx);
   10871           0 :     JS::Rooted<JS::Value> temp(cx);
   10872           0 :     JS::Rooted<jsid> curId(cx);
   10873           0 :     JS::Rooted<JS::Value> idVal(cx);
   10874             :     // Use a hashset to keep track of ids seen, to avoid
   10875             :     // introducing nasty O(N^2) behavior scanning for them all the
   10876             :     // time.  Ideally we'd use a data structure with O(1) lookup
   10877             :     // _and_ ordering for the MozMap, but we don't have one lying
   10878             :     // around.
   10879           0 :     nsTHashtable<nsStringHashKey> idsSeen;
   10880           0 :     for (size_t i = 0; i < ids.length(); ++i) {
   10881           0 :       curId = ids[i];
   10882             : 
   10883           0 :       JS::Rooted<JS::PropertyDescriptor> desc(cx);
   10884           0 :       if (!JS_GetOwnPropertyDescriptorById(cx, recordObj, curId,
   10885             :                                            &desc)) {
   10886           0 :         return false;
   10887             :       }
   10888             : 
   10889           0 :       if (!desc.object() /* == undefined in spec terms */ ||
   10890           0 :           !desc.enumerable()) {
   10891           0 :         continue;
   10892             :       }
   10893             : 
   10894           0 :       idVal = js::IdToValue(curId);
   10895           0 :       nsString propName;
   10896             :       // This will just throw if idVal is a Symbol, like the spec says
   10897             :       // to do.
   10898           0 :       if (!ConvertJSValueToString(cx, idVal, propName)) {
   10899           0 :         return false;
   10900             :       }
   10901             : 
   10902           0 :       if (!JS_GetPropertyById(cx, recordObj, curId, &temp)) {
   10903           0 :         return false;
   10904             :       }
   10905             : 
   10906             :       Record<nsString, nsString>::EntryType* entry;
   10907           0 :       if (!idsSeen.EnsureInserted(propName)) {
   10908             :         // Find the existing entry.
   10909           0 :         auto idx = recordEntries.IndexOf(propName);
   10910           0 :         MOZ_ASSERT(idx != recordEntries.NoIndex,
   10911             :                    "Why is it not found?");
   10912             :         // Now blow it away to make it look like it was just added
   10913             :         // to the array, because it's not obvious that it's
   10914             :         // safe to write to its already-initialized mValue via our
   10915             :         // normal codegen conversions.  For example, the value
   10916             :         // could be a union and this would change its type, but
   10917             :         // codegen assumes we won't do that.
   10918           0 :         entry = recordEntries.ReconstructElementAt(idx);
   10919             :       } else {
   10920             :         // Safe to do an infallible append here, because we did a
   10921             :         // SetCapacity above to the right capacity.
   10922           0 :         entry = recordEntries.AppendElement();
   10923             :       }
   10924           0 :       entry->mKey = propName;
   10925           0 :       nsString& slot = entry->mValue;
   10926           0 :       if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
   10927           0 :         return false;
   10928             :       }
   10929             :     }
   10930             :   }
   10931           0 :   return true;
   10932             : }
   10933             : 
   10934             : void
   10935           0 : OwningStringStringRecordOrStringSequence::DestroyStringStringRecord()
   10936             : {
   10937           0 :   MOZ_ASSERT(IsStringStringRecord(), "Wrong type!");
   10938           0 :   mValue.mStringStringRecord.Destroy();
   10939           0 :   mType = eUninitialized;
   10940           0 : }
   10941             : 
   10942             : 
   10943             : 
   10944             : 
   10945             : Sequence<nsString>&
   10946           0 : OwningStringStringRecordOrStringSequence::RawSetAsStringSequence()
   10947             : {
   10948           0 :   if (mType == eStringSequence) {
   10949           0 :     return mValue.mStringSequence.Value();
   10950             :   }
   10951           0 :   MOZ_ASSERT(mType == eUninitialized);
   10952           0 :   mType = eStringSequence;
   10953           0 :   return mValue.mStringSequence.SetValue();
   10954             : }
   10955             : 
   10956             : Sequence<nsString>&
   10957           0 : OwningStringStringRecordOrStringSequence::SetAsStringSequence()
   10958             : {
   10959           0 :   if (mType == eStringSequence) {
   10960           0 :     return mValue.mStringSequence.Value();
   10961             :   }
   10962           0 :   Uninit();
   10963           0 :   mType = eStringSequence;
   10964           0 :   return mValue.mStringSequence.SetValue();
   10965             : }
   10966             : 
   10967             : bool
   10968           0 : OwningStringStringRecordOrStringSequence::TrySetToStringSequence(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
   10969             : {
   10970           0 :   tryNext = false;
   10971             :   { // scope for memberSlot
   10972           0 :     Sequence<nsString>& memberSlot = RawSetAsStringSequence();
   10973           0 :     JS::ForOfIterator iter(cx);
   10974           0 :     if (!iter.init(value, JS::ForOfIterator::AllowNonIterable)) {
   10975           0 :       return false;
   10976             :     }
   10977           0 :     if (!iter.valueIsIterable()) {
   10978           0 :       DestroyStringSequence();
   10979           0 :       tryNext = true;
   10980           0 :       return true;
   10981             :     }
   10982           0 :     Sequence<nsString> &arr = memberSlot;
   10983           0 :     JS::Rooted<JS::Value> temp(cx);
   10984             :     while (true) {
   10985             :       bool done;
   10986           0 :       if (!iter.next(&temp, &done)) {
   10987           0 :         return false;
   10988             :       }
   10989           0 :       if (done) {
   10990           0 :         break;
   10991             :       }
   10992           0 :       nsString* slotPtr = arr.AppendElement(mozilla::fallible);
   10993           0 :       if (!slotPtr) {
   10994           0 :         JS_ReportOutOfMemory(cx);
   10995           0 :         return false;
   10996             :       }
   10997           0 :       nsString& slot = *slotPtr;
   10998           0 :       if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
   10999           0 :         return false;
   11000             :       }
   11001           0 :     }
   11002             :   }
   11003           0 :   return true;
   11004             : }
   11005             : 
   11006             : void
   11007           0 : OwningStringStringRecordOrStringSequence::DestroyStringSequence()
   11008             : {
   11009           0 :   MOZ_ASSERT(IsStringSequence(), "Wrong type!");
   11010           0 :   mValue.mStringSequence.Destroy();
   11011           0 :   mType = eUninitialized;
   11012           0 : }
   11013             : 
   11014             : 
   11015             : 
   11016             : 
   11017             : void
   11018           0 : OwningStringStringRecordOrStringSequence::Uninit()
   11019             : {
   11020           0 :   switch (mType) {
   11021             :     case eUninitialized: {
   11022           0 :       break;
   11023             :     }
   11024             :     case eStringStringRecord: {
   11025           0 :       DestroyStringStringRecord();
   11026           0 :       break;
   11027             :     }
   11028             :     case eStringSequence: {
   11029           0 :       DestroyStringSequence();
   11030           0 :       break;
   11031             :     }
   11032             :   }
   11033           0 : }
   11034             : 
   11035             : bool
   11036           0 : OwningStringStringRecordOrStringSequence::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
   11037             : {
   11038           0 :   switch (mType) {
   11039             :     case eUninitialized: {
   11040           0 :       return false;
   11041             :       break;
   11042             :     }
   11043             :     case eStringStringRecord: {
   11044             : 
   11045           0 :       JS::Rooted<JSObject*> returnObj(cx, JS_NewPlainObject(cx));
   11046           0 :       if (!returnObj) {
   11047           0 :         return false;
   11048             :       }
   11049             :       // Scope for 'tmp'
   11050             :       {
   11051           0 :         JS::Rooted<JS::Value> tmp(cx);
   11052           0 :         for (auto& entry : mValue.mStringStringRecord.Value().Entries()) {
   11053           0 :           auto& recordValue0 = entry.mValue;
   11054             :           // Control block to let us common up the JS_DefineUCProperty calls when there
   11055             :           // are different ways to succeed at wrapping the value.
   11056             :           do {
   11057           0 :             if (!xpc::NonVoidStringToJsval(cx, recordValue0, &tmp)) {
   11058           0 :               return false;
   11059             :             }
   11060           0 :             break;
   11061             :           } while (0);
   11062           0 :           if (!JS_DefineUCProperty(cx, returnObj,
   11063             :                                    entry.mKey.BeginReading(),
   11064           0 :                                    entry.mKey.Length(), tmp,
   11065             :                                    JSPROP_ENUMERATE)) {
   11066           0 :             return false;
   11067             :           }
   11068             :         }
   11069             :       }
   11070           0 :       rval.setObject(*returnObj);
   11071           0 :       return true;
   11072             :       break;
   11073             :     }
   11074             :     case eStringSequence: {
   11075             : 
   11076           0 :       uint32_t length = mValue.mStringSequence.Value().Length();
   11077           0 :       JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
   11078           0 :       if (!returnArray) {
   11079           0 :         return false;
   11080             :       }
   11081             :       // Scope for 'tmp'
   11082             :       {
   11083           0 :         JS::Rooted<JS::Value> tmp(cx);
   11084           0 :         for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
   11085             :           // Control block to let us common up the JS_DefineElement calls when there
   11086             :           // are different ways to succeed at wrapping the object.
   11087             :           do {
   11088           0 :             if (!xpc::NonVoidStringToJsval(cx, mValue.mStringSequence.Value()[sequenceIdx0], &tmp)) {
   11089           0 :               return false;
   11090             :             }
   11091           0 :             break;
   11092             :           } while (0);
   11093           0 :           if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
   11094             :                                 JSPROP_ENUMERATE)) {
   11095           0 :             return false;
   11096             :           }
   11097             :         }
   11098             :       }
   11099           0 :       rval.setObject(*returnArray);
   11100           0 :       return true;
   11101             :       break;
   11102             :     }
   11103             :     default: {
   11104           0 :       return false;
   11105             :       break;
   11106             :     }
   11107             :   }
   11108             : 
   11109             :   return false;
   11110             : }
   11111             : 
   11112             : void
   11113           0 : OwningStringStringRecordOrStringSequence::TraceUnion(JSTracer* trc)
   11114             : {
   11115           0 : }
   11116             : 
   11117             : SupportedType&
   11118           0 : OwningSupportedTypeOrObject::RawSetAsSupportedType()
   11119             : {
   11120           0 :   if (mType == eSupportedType) {
   11121           0 :     return mValue.mSupportedType.Value();
   11122             :   }
   11123           0 :   MOZ_ASSERT(mType == eUninitialized);
   11124           0 :   mType = eSupportedType;
   11125           0 :   return mValue.mSupportedType.SetValue();
   11126             : }
   11127             : 
   11128             : SupportedType&
   11129           0 : OwningSupportedTypeOrObject::SetAsSupportedType()
   11130             : {
   11131           0 :   if (mType == eSupportedType) {
   11132           0 :     return mValue.mSupportedType.Value();
   11133             :   }
   11134           0 :   Uninit();
   11135           0 :   mType = eSupportedType;
   11136           0 :   return mValue.mSupportedType.SetValue();
   11137             : }
   11138             : 
   11139             : bool
   11140           0 : OwningSupportedTypeOrObject::TrySetToSupportedType(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
   11141             : {
   11142           0 :   tryNext = false;
   11143             :   { // scope for memberSlot
   11144           0 :     SupportedType& memberSlot = RawSetAsSupportedType();
   11145             :     {
   11146             :       int index;
   11147           0 :       if (!FindEnumStringIndex<true>(cx, value, SupportedTypeValues::strings, "SupportedType", "Member of SupportedTypeOrObject", &index)) {
   11148           0 :         return false;
   11149             :       }
   11150           0 :       MOZ_ASSERT(index >= 0);
   11151           0 :       memberSlot = static_cast<SupportedType>(index);
   11152             :     }
   11153             :   }
   11154           0 :   return true;
   11155             : }
   11156             : 
   11157             : void
   11158           0 : OwningSupportedTypeOrObject::DestroySupportedType()
   11159             : {
   11160           0 :   MOZ_ASSERT(IsSupportedType(), "Wrong type!");
   11161           0 :   mValue.mSupportedType.Destroy();
   11162           0 :   mType = eUninitialized;
   11163           0 : }
   11164             : 
   11165             : 
   11166             : 
   11167             : 
   11168             : JSObject*&
   11169           0 : OwningSupportedTypeOrObject::RawSetAsObject()
   11170             : {
   11171           0 :   if (mType == eObject) {
   11172           0 :     return mValue.mObject.Value();
   11173             :   }
   11174           0 :   MOZ_ASSERT(mType == eUninitialized);
   11175           0 :   mType = eObject;
   11176           0 :   return mValue.mObject.SetValue();
   11177             : }
   11178             : 
   11179             : JSObject*&
   11180           0 : OwningSupportedTypeOrObject::SetAsObject()
   11181             : {
   11182           0 :   if (mType == eObject) {
   11183           0 :     return mValue.mObject.Value();
   11184             :   }
   11185           0 :   Uninit();
   11186           0 :   mType = eObject;
   11187           0 :   return mValue.mObject.SetValue();
   11188             : }
   11189             : 
   11190             : 
   11191             : void
   11192           0 : OwningSupportedTypeOrObject::DestroyObject()
   11193             : {
   11194           0 :   MOZ_ASSERT(IsObject(), "Wrong type!");
   11195           0 :   mValue.mObject.Destroy();
   11196           0 :   mType = eUninitialized;
   11197           0 : }
   11198             : 
   11199             : 
   11200             : 
   11201             : 
   11202             : void
   11203           0 : OwningSupportedTypeOrObject::Uninit()
   11204             : {
   11205           0 :   switch (mType) {
   11206             :     case eUninitialized: {
   11207           0 :       break;
   11208             :     }
   11209             :     case eSupportedType: {
   11210           0 :       DestroySupportedType();
   11211           0 :       break;
   11212             :     }
   11213             :     case eObject: {
   11214           0 :       DestroyObject();
   11215           0 :       break;
   11216             :     }
   11217             :   }
   11218           0 : }
   11219             : 
   11220             : bool
   11221           0 : OwningSupportedTypeOrObject::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
   11222             : {
   11223           0 :   switch (mType) {
   11224             :     case eUninitialized: {
   11225           0 :       return false;
   11226             :       break;
   11227             :     }
   11228             :     case eSupportedType: {
   11229           0 :       if (!ToJSValue(cx, mValue.mSupportedType.Value(), rval)) {
   11230           0 :         return false;
   11231             :       }
   11232           0 :       return true;
   11233             :       break;
   11234             :     }
   11235             :     case eObject: {
   11236           0 :       JS::ExposeObjectToActiveJS(mValue.mObject.Value());
   11237           0 :       rval.setObject(*mValue.mObject.Value());
   11238           0 :       if (!MaybeWrapObjectValue(cx, rval)) {
   11239           0 :         return false;
   11240             :       }
   11241           0 :       return true;
   11242             :       break;
   11243             :     }
   11244             :     default: {
   11245           0 :       return false;
   11246             :       break;
   11247             :     }
   11248             :   }
   11249             : 
   11250             :   return false;
   11251             : }
   11252             : 
   11253             : void
   11254           0 : OwningSupportedTypeOrObject::TraceUnion(JSTracer* trc)
   11255             : {
   11256           0 :   switch (mType) {
   11257             :     case eObject: {
   11258           0 :       JS::UnsafeTraceRoot(trc, &mValue.mObject.Value(), "mValue.mObject");
   11259           0 :       break;
   11260             :     }
   11261             :     default: {
   11262           0 :       break;
   11263             :     }
   11264             :   }
   11265           0 : }
   11266             : 
   11267             : nsString&
   11268           0 : OwningUSVStringOrLong::RawSetAsUSVString()
   11269             : {
   11270           0 :   if (mType == eUSVString) {
   11271           0 :     return mValue.mUSVString.Value();
   11272             :   }
   11273           0 :   MOZ_ASSERT(mType == eUninitialized);
   11274           0 :   mType = eUSVString;
   11275           0 :   return mValue.mUSVString.SetValue();
   11276             : }
   11277             : 
   11278             : nsString&
   11279           0 : OwningUSVStringOrLong::SetAsUSVString()
   11280             : {
   11281           0 :   if (mType == eUSVString) {
   11282           0 :     return mValue.mUSVString.Value();
   11283             :   }
   11284           0 :   Uninit();
   11285           0 :   mType = eUSVString;
   11286           0 :   return mValue.mUSVString.SetValue();
   11287             : }
   11288             : 
   11289             : bool
   11290           0 : OwningUSVStringOrLong::TrySetToUSVString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
   11291             : {
   11292           0 :   tryNext = false;
   11293             :   { // scope for memberSlot
   11294           0 :     nsString& memberSlot = RawSetAsUSVString();
   11295           0 :     if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
   11296           0 :       return false;
   11297             :     }
   11298           0 :     NormalizeUSVString(memberSlot);
   11299             :   }
   11300           0 :   return true;
   11301             : }
   11302             : 
   11303             : 
   11304             : void
   11305           0 : OwningUSVStringOrLong::DestroyUSVString()
   11306             : {
   11307           0 :   MOZ_ASSERT(IsUSVString(), "Wrong type!");
   11308           0 :   mValue.mUSVString.Destroy();
   11309           0 :   mType = eUninitialized;
   11310           0 : }
   11311             : 
   11312             : 
   11313             : 
   11314             : 
   11315             : int32_t&
   11316           0 : OwningUSVStringOrLong::RawSetAsLong()
   11317             : {
   11318           0 :   if (mType == eLong) {
   11319           0 :     return mValue.mLong.Value();
   11320             :   }
   11321           0 :   MOZ_ASSERT(mType == eUninitialized);
   11322           0 :   mType = eLong;
   11323           0 :   return mValue.mLong.SetValue();
   11324             : }
   11325             : 
   11326             : int32_t&
   11327           0 : OwningUSVStringOrLong::SetAsLong()
   11328             : {
   11329           0 :   if (mType == eLong) {
   11330           0 :     return mValue.mLong.Value();
   11331             :   }
   11332           0 :   Uninit();
   11333           0 :   mType = eLong;
   11334           0 :   return mValue.mLong.SetValue();
   11335             : }
   11336             : 
   11337             : bool
   11338           0 : OwningUSVStringOrLong::TrySetToLong(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
   11339             : {
   11340           0 :   tryNext = false;
   11341             :   { // scope for memberSlot
   11342           0 :     int32_t& memberSlot = RawSetAsLong();
   11343           0 :     if (!ValueToPrimitive<int32_t, eDefault>(cx, value, &memberSlot)) {
   11344           0 :       return false;
   11345             :     }
   11346             :   }
   11347           0 :   return true;
   11348             : }
   11349             : 
   11350             : void
   11351           0 : OwningUSVStringOrLong::DestroyLong()
   11352             : {
   11353           0 :   MOZ_ASSERT(IsLong(), "Wrong type!");
   11354           0 :   mValue.mLong.Destroy();
   11355           0 :   mType = eUninitialized;
   11356           0 : }
   11357             : 
   11358             : 
   11359             : 
   11360             : 
   11361             : void
   11362           0 : OwningUSVStringOrLong::Uninit()
   11363             : {
   11364           0 :   switch (mType) {
   11365             :     case eUninitialized: {
   11366           0 :       break;
   11367             :     }
   11368             :     case eUSVString: {
   11369           0 :       DestroyUSVString();
   11370           0 :       break;
   11371             :     }
   11372             :     case eLong: {
   11373           0 :       DestroyLong();
   11374           0 :       break;
   11375             :     }
   11376             :   }
   11377           0 : }
   11378             : 
   11379             : bool
   11380           0 : OwningUSVStringOrLong::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
   11381             : {
   11382           0 :   switch (mType) {
   11383             :     case eUninitialized: {
   11384           0 :       return false;
   11385             :       break;
   11386             :     }
   11387             :     case eUSVString: {
   11388           0 :       if (!xpc::NonVoidStringToJsval(cx, mValue.mUSVString.Value(), rval)) {
   11389           0 :         return false;
   11390             :       }
   11391           0 :       return true;
   11392             :       break;
   11393             :     }
   11394             :     case eLong: {
   11395           0 :       rval.setInt32(int32_t(mValue.mLong.Value()));
   11396           0 :       return true;
   11397             :       break;
   11398             :     }
   11399             :     default: {
   11400           0 :       return false;
   11401             :       break;
   11402             :     }
   11403             :   }
   11404             : 
   11405             :   return false;
   11406             : }
   11407             : 
   11408             : void
   11409           0 : OwningUSVStringOrLong::TraceUnion(JSTracer* trc)
   11410             : {
   11411           0 : }
   11412             : 
   11413             : OwningUSVStringOrLong&
   11414           0 : OwningUSVStringOrLong::operator=(const OwningUSVStringOrLong& aOther)
   11415             : {
   11416           0 :   switch (aOther.mType) {
   11417             :     case eUninitialized: {
   11418           0 :       MOZ_ASSERT(mType == eUninitialized,
   11419             :                  "We need to destroy ourselves?");
   11420           0 :       break;
   11421             :     }
   11422             :     case eUSVString: {
   11423           0 :       SetAsUSVString() = aOther.GetAsUSVString();
   11424           0 :       break;
   11425             :     }
   11426             :     case eLong: {
   11427           0 :       SetAsLong() = aOther.GetAsLong();
   11428           0 :       break;
   11429             :     }
   11430             :   }
   11431           0 :   return *this;
   11432             : }
   11433             : 
   11434             : double&
   11435           0 : OwningUnrestrictedDoubleOrString::RawSetAsUnrestrictedDouble()
   11436             : {
   11437           0 :   if (mType == eUnrestrictedDouble) {
   11438           0 :     return mValue.mUnrestrictedDouble.Value();
   11439             :   }
   11440           0 :   MOZ_ASSERT(mType == eUninitialized);
   11441           0 :   mType = eUnrestrictedDouble;
   11442           0 :   return mValue.mUnrestrictedDouble.SetValue();
   11443             : }
   11444             : 
   11445             : double&
   11446           0 : OwningUnrestrictedDoubleOrString::SetAsUnrestrictedDouble()
   11447             : {
   11448           0 :   if (mType == eUnrestrictedDouble) {
   11449           0 :     return mValue.mUnrestrictedDouble.Value();
   11450             :   }
   11451           0 :   Uninit();
   11452           0 :   mType = eUnrestrictedDouble;
   11453           0 :   return mValue.mUnrestrictedDouble.SetValue();
   11454             : }
   11455             : 
   11456             : bool
   11457           0 : OwningUnrestrictedDoubleOrString::TrySetToUnrestrictedDouble(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
   11458             : {
   11459           0 :   tryNext = false;
   11460             :   { // scope for memberSlot
   11461           0 :     double& memberSlot = RawSetAsUnrestrictedDouble();
   11462           0 :     if (!ValueToPrimitive<double, eDefault>(cx, value, &memberSlot)) {
   11463           0 :       return false;
   11464             :     }
   11465             :   }
   11466           0 :   return true;
   11467             : }
   11468             : 
   11469             : void
   11470           0 : OwningUnrestrictedDoubleOrString::DestroyUnrestrictedDouble()
   11471             : {
   11472           0 :   MOZ_ASSERT(IsUnrestrictedDouble(), "Wrong type!");
   11473           0 :   mValue.mUnrestrictedDouble.Destroy();
   11474           0 :   mType = eUninitialized;
   11475           0 : }
   11476             : 
   11477             : 
   11478             : 
   11479             : 
   11480             : nsString&
   11481           0 : OwningUnrestrictedDoubleOrString::RawSetAsString()
   11482             : {
   11483           0 :   if (mType == eString) {
   11484           0 :     return mValue.mString.Value();
   11485             :   }
   11486           0 :   MOZ_ASSERT(mType == eUninitialized);
   11487           0 :   mType = eString;
   11488           0 :   return mValue.mString.SetValue();
   11489             : }
   11490             : 
   11491             : nsString&
   11492           0 : OwningUnrestrictedDoubleOrString::SetAsString()
   11493             : {
   11494           0 :   if (mType == eString) {
   11495           0 :     return mValue.mString.Value();
   11496             :   }
   11497           0 :   Uninit();
   11498           0 :   mType = eString;
   11499           0 :   return mValue.mString.SetValue();
   11500             : }
   11501             : 
   11502             : bool
   11503           0 : OwningUnrestrictedDoubleOrString::TrySetToString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
   11504             : {
   11505           0 :   tryNext = false;
   11506             :   { // scope for memberSlot
   11507           0 :     nsString& memberSlot = RawSetAsString();
   11508           0 :     if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
   11509           0 :       return false;
   11510             :     }
   11511             :   }
   11512           0 :   return true;
   11513             : }
   11514             : 
   11515             : 
   11516             : void
   11517           0 : OwningUnrestrictedDoubleOrString::DestroyString()
   11518             : {
   11519           0 :   MOZ_ASSERT(IsString(), "Wrong type!");
   11520           0 :   mValue.mString.Destroy();
   11521           0 :   mType = eUninitialized;
   11522           0 : }
   11523             : 
   11524             : 
   11525             : 
   11526             : 
   11527             : void
   11528           0 : OwningUnrestrictedDoubleOrString::Uninit()
   11529             : {
   11530           0 :   switch (mType) {
   11531             :     case eUninitialized: {
   11532           0 :       break;
   11533             :     }
   11534             :     case eUnrestrictedDouble: {
   11535           0 :       DestroyUnrestrictedDouble();
   11536           0 :       break;
   11537             :     }
   11538             :     case eString: {
   11539           0 :       DestroyString();
   11540           0 :       break;
   11541             :     }
   11542             :   }
   11543           0 : }
   11544             : 
   11545             : bool
   11546           0 : OwningUnrestrictedDoubleOrString::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
   11547             : {
   11548           0 :   switch (mType) {
   11549             :     case eUninitialized: {
   11550           0 :       return false;
   11551             :       break;
   11552             :     }
   11553             :     case eUnrestrictedDouble: {
   11554           0 :       rval.set(JS_NumberValue(double(mValue.mUnrestrictedDouble.Value())));
   11555           0 :       return true;
   11556             :       break;
   11557             :     }
   11558             :     case eString: {
   11559           0 :       if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) {
   11560           0 :         return false;
   11561             :       }
   11562           0 :       return true;
   11563             :       break;
   11564             :     }
   11565             :     default: {
   11566           0 :       return false;
   11567             :       break;
   11568             :     }
   11569             :   }
   11570             : 
   11571             :   return false;
   11572             : }
   11573             : 
   11574             : void
   11575           0 : OwningUnrestrictedDoubleOrString::TraceUnion(JSTracer* trc)
   11576             : {
   11577           0 : }
   11578             : 
   11579             : OwningUnrestrictedDoubleOrString&
   11580           0 : OwningUnrestrictedDoubleOrString::operator=(const OwningUnrestrictedDoubleOrString& aOther)
   11581             : {
   11582           0 :   switch (aOther.mType) {
   11583             :     case eUninitialized: {
   11584           0 :       MOZ_ASSERT(mType == eUninitialized,
   11585             :                  "We need to destroy ourselves?");
   11586           0 :       break;
   11587             :     }
   11588             :     case eUnrestrictedDouble: {
   11589           0 :       SetAsUnrestrictedDouble() = aOther.GetAsUnrestrictedDouble();
   11590           0 :       break;
   11591             :     }
   11592             :     case eString: {
   11593           0 :       SetAsString() = aOther.GetAsString();
   11594           0 :       break;
   11595             :     }
   11596             :   }
   11597           0 :   return *this;
   11598             : }
   11599             : 
   11600             : float&
   11601           0 : OwningUnrestrictedFloatOrString::RawSetAsUnrestrictedFloat()
   11602             : {
   11603           0 :   if (mType == eUnrestrictedFloat) {
   11604           0 :     return mValue.mUnrestrictedFloat.Value();
   11605             :   }
   11606           0 :   MOZ_ASSERT(mType == eUninitialized);
   11607           0 :   mType = eUnrestrictedFloat;
   11608           0 :   return mValue.mUnrestrictedFloat.SetValue();
   11609             : }
   11610             : 
   11611             : float&
   11612           0 : OwningUnrestrictedFloatOrString::SetAsUnrestrictedFloat()
   11613             : {
   11614           0 :   if (mType == eUnrestrictedFloat) {
   11615           0 :     return mValue.mUnrestrictedFloat.Value();
   11616             :   }
   11617           0 :   Uninit();
   11618           0 :   mType = eUnrestrictedFloat;
   11619           0 :   return mValue.mUnrestrictedFloat.SetValue();
   11620             : }
   11621             : 
   11622             : bool
   11623           0 : OwningUnrestrictedFloatOrString::TrySetToUnrestrictedFloat(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
   11624             : {
   11625           0 :   tryNext = false;
   11626             :   { // scope for memberSlot
   11627           0 :     float& memberSlot = RawSetAsUnrestrictedFloat();
   11628           0 :     if (!ValueToPrimitive<float, eDefault>(cx, value, &memberSlot)) {
   11629           0 :       return false;
   11630             :     }
   11631             :   }
   11632           0 :   return true;
   11633             : }
   11634             : 
   11635             : void
   11636           0 : OwningUnrestrictedFloatOrString::DestroyUnrestrictedFloat()
   11637             : {
   11638           0 :   MOZ_ASSERT(IsUnrestrictedFloat(), "Wrong type!");
   11639           0 :   mValue.mUnrestrictedFloat.Destroy();
   11640           0 :   mType = eUninitialized;
   11641           0 : }
   11642             : 
   11643             : 
   11644             : 
   11645             : 
   11646             : nsString&
   11647           0 : OwningUnrestrictedFloatOrString::RawSetAsString()
   11648             : {
   11649           0 :   if (mType == eString) {
   11650           0 :     return mValue.mString.Value();
   11651             :   }
   11652           0 :   MOZ_ASSERT(mType == eUninitialized);
   11653           0 :   mType = eString;
   11654           0 :   return mValue.mString.SetValue();
   11655             : }
   11656             : 
   11657             : nsString&
   11658           0 : OwningUnrestrictedFloatOrString::SetAsString()
   11659             : {
   11660           0 :   if (mType == eString) {
   11661           0 :     return mValue.mString.Value();
   11662             :   }
   11663           0 :   Uninit();
   11664           0 :   mType = eString;
   11665           0 :   return mValue.mString.SetValue();
   11666             : }
   11667             : 
   11668             : bool
   11669           0 : OwningUnrestrictedFloatOrString::TrySetToString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
   11670             : {
   11671           0 :   tryNext = false;
   11672             :   { // scope for memberSlot
   11673           0 :     nsString& memberSlot = RawSetAsString();
   11674           0 :     if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
   11675           0 :       return false;
   11676             :     }
   11677             :   }
   11678           0 :   return true;
   11679             : }
   11680             : 
   11681             : 
   11682             : void
   11683           0 : OwningUnrestrictedFloatOrString::DestroyString()
   11684             : {
   11685           0 :   MOZ_ASSERT(IsString(), "Wrong type!");
   11686           0 :   mValue.mString.Destroy();
   11687           0 :   mType = eUninitialized;
   11688           0 : }
   11689             : 
   11690             : 
   11691             : 
   11692             : 
   11693             : void
   11694           0 : OwningUnrestrictedFloatOrString::Uninit()
   11695             : {
   11696           0 :   switch (mType) {
   11697             :     case eUninitialized: {
   11698           0 :       break;
   11699             :     }
   11700             :     case eUnrestrictedFloat: {
   11701           0 :       DestroyUnrestrictedFloat();
   11702           0 :       break;
   11703             :     }
   11704             :     case eString: {
   11705           0 :       DestroyString();
   11706           0 :       break;
   11707             :     }
   11708             :   }
   11709           0 : }
   11710             : 
   11711             : bool
   11712           0 : OwningUnrestrictedFloatOrString::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
   11713             : {
   11714           0 :   switch (mType) {
   11715             :     case eUninitialized: {
   11716           0 :       return false;
   11717             :       break;
   11718             :     }
   11719             :     case eUnrestrictedFloat: {
   11720           0 :       rval.set(JS_NumberValue(double(mValue.mUnrestrictedFloat.Value())));
   11721           0 :       return true;
   11722             :       break;
   11723             :     }
   11724             :     case eString: {
   11725           0 :       if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) {
   11726           0 :         return false;
   11727             :       }
   11728           0 :       return true;
   11729             :       break;
   11730             :     }
   11731             :     default: {
   11732           0 :       return false;
   11733             :       break;
   11734             :     }
   11735             :   }
   11736             : 
   11737             :   return false;
   11738             : }
   11739             : 
   11740             : void
   11741           0 : OwningUnrestrictedFloatOrString::TraceUnion(JSTracer* trc)
   11742             : {
   11743           0 : }
   11744             : 
   11745             : OwningUnrestrictedFloatOrString&
   11746           0 : OwningUnrestrictedFloatOrString::operator=(const OwningUnrestrictedFloatOrString& aOther)
   11747             : {
   11748           0 :   switch (aOther.mType) {
   11749             :     case eUninitialized: {
   11750           0 :       MOZ_ASSERT(mType == eUninitialized,
   11751             :                  "We need to destroy ourselves?");
   11752           0 :       break;
   11753             :     }
   11754             :     case eUnrestrictedFloat: {
   11755           0 :       SetAsUnrestrictedFloat() = aOther.GetAsUnrestrictedFloat();
   11756           0 :       break;
   11757             :     }
   11758             :     case eString: {
   11759           0 :       SetAsString() = aOther.GetAsString();
   11760           0 :       break;
   11761             :     }
   11762             :   }
   11763           0 :   return *this;
   11764             : }
   11765             : } // namespace dom
   11766             : } // namespace mozilla
   11767             : 

Generated by: LCOV version 1.13