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

          Line data    Source code
       1             : /* THIS FILE IS AUTOGENERATED FROM InstallTrigger.webidl BY Codegen.py - DO NOT EDIT */
       2             : 
       3             : #include "AtomList.h"
       4             : #include "InstallTriggerBinding.h"
       5             : #include "WrapperFactory.h"
       6             : #include "mozilla/OwningNonNull.h"
       7             : #include "mozilla/dom/BindingUtils.h"
       8             : #include "mozilla/dom/DOMJSClass.h"
       9             : #include "mozilla/dom/NonRefcountedDOMObject.h"
      10             : #include "mozilla/dom/PrimitiveConversions.h"
      11             : #include "mozilla/dom/ScriptSettings.h"
      12             : #include "mozilla/dom/SimpleGlobalObject.h"
      13             : #include "mozilla/dom/UnionConversions.h"
      14             : #include "mozilla/dom/XrayExpandoClass.h"
      15             : #include "nsContentUtils.h"
      16             : #include "nsIGlobalObject.h"
      17             : 
      18             : namespace mozilla {
      19             : namespace dom {
      20             : 
      21             : 
      22           0 : InstallTriggerData::InstallTriggerData()
      23             : {
      24             :   // Safe to pass a null context if we pass a null value
      25           0 :   Init(nullptr, JS::NullHandleValue);
      26           0 : }
      27             : 
      28             : 
      29             : 
      30             : bool
      31           0 : InstallTriggerData::InitIds(JSContext* cx, InstallTriggerDataAtoms* atomsCache)
      32             : {
      33           0 :   MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
      34             : 
      35             :   // Initialize these in reverse order so that any failure leaves the first one
      36             :   // uninitialized.
      37           0 :   if (!atomsCache->URL_id.init(cx, "URL") ||
      38           0 :       !atomsCache->IconURL_id.init(cx, "IconURL") ||
      39           0 :       !atomsCache->Hash_id.init(cx, "Hash")) {
      40           0 :     return false;
      41             :   }
      42           0 :   return true;
      43             : }
      44             : 
      45             : bool
      46           0 : InstallTriggerData::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
      47             : {
      48             :   // Passing a null JSContext is OK only if we're initing from null,
      49             :   // Since in that case we will not have to do any property gets
      50             :   // Also evaluate isNullOrUndefined in order to avoid false-positive
      51             :   // checkers by static analysis tools
      52           0 :   MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
      53           0 :   InstallTriggerDataAtoms* atomsCache = nullptr;
      54           0 :   if (cx) {
      55           0 :     atomsCache = GetAtomCache<InstallTriggerDataAtoms>(cx);
      56           0 :     if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
      57           0 :       return false;
      58             :     }
      59             :   }
      60             : 
      61           0 :   if (!IsConvertibleToDictionary(val)) {
      62           0 :     return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
      63             :   }
      64             : 
      65           0 :   bool isNull = val.isNullOrUndefined();
      66             :   // We only need these if !isNull, in which case we have |cx|.
      67           0 :   Maybe<JS::Rooted<JSObject *> > object;
      68           0 :   Maybe<JS::Rooted<JS::Value> > temp;
      69           0 :   if (!isNull) {
      70           0 :     MOZ_ASSERT(cx);
      71           0 :     object.emplace(cx, &val.toObject());
      72           0 :     temp.emplace(cx);
      73             :   }
      74           0 :   if (!isNull) {
      75           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->Hash_id, temp.ptr())) {
      76           0 :       return false;
      77             :     }
      78             :   }
      79           0 :   if (!isNull && !temp->isUndefined()) {
      80           0 :     mHash.Construct();
      81           0 :     if (!ConvertJSValueToString(cx, temp.ref(), eNull, eNull, (mHash.Value()))) {
      82           0 :       return false;
      83             :     }
      84           0 :     mIsAnyMemberPresent = true;
      85             :   }
      86             : 
      87           0 :   if (!isNull) {
      88           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->IconURL_id, temp.ptr())) {
      89           0 :       return false;
      90             :     }
      91             :   }
      92           0 :   if (!isNull && !temp->isUndefined()) {
      93           0 :     mIconURL.Construct();
      94           0 :     if (!ConvertJSValueToString(cx, temp.ref(), eNull, eNull, (mIconURL.Value()))) {
      95           0 :       return false;
      96             :     }
      97           0 :     mIsAnyMemberPresent = true;
      98             :   }
      99             : 
     100           0 :   if (!isNull) {
     101           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->URL_id, temp.ptr())) {
     102           0 :       return false;
     103             :     }
     104             :   }
     105           0 :   if (!isNull && !temp->isUndefined()) {
     106           0 :     mURL.Construct();
     107           0 :     if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mURL.Value()))) {
     108           0 :       return false;
     109             :     }
     110           0 :     mIsAnyMemberPresent = true;
     111             :   }
     112           0 :   return true;
     113             : }
     114             : 
     115             : bool
     116           0 : InstallTriggerData::Init(const nsAString& aJSON)
     117             : {
     118           0 :   AutoJSAPI jsapi;
     119           0 :   JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
     120           0 :   if (!cleanGlobal) {
     121           0 :     return false;
     122             :   }
     123           0 :   if (!jsapi.Init(cleanGlobal)) {
     124           0 :     return false;
     125             :   }
     126           0 :   JSContext* cx = jsapi.cx();
     127           0 :   JS::Rooted<JS::Value> json(cx);
     128           0 :   bool ok = ParseJSON(cx, aJSON, &json);
     129           0 :   NS_ENSURE_TRUE(ok, false);
     130           0 :   return Init(cx, json);
     131             : }
     132             : 
     133             : bool
     134           0 : InstallTriggerData::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
     135             : {
     136           0 :   InstallTriggerDataAtoms* atomsCache = GetAtomCache<InstallTriggerDataAtoms>(cx);
     137           0 :   if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
     138           0 :     return false;
     139             :   }
     140             : 
     141           0 :   JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
     142           0 :   if (!obj) {
     143           0 :     return false;
     144             :   }
     145           0 :   rval.set(JS::ObjectValue(*obj));
     146             : 
     147           0 :   if (mHash.WasPassed()) {
     148             :     do {
     149             :       // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     150           0 :       JS::Rooted<JS::Value> temp(cx);
     151           0 :       nsString const & currentValue = mHash.InternalValue();
     152           0 :       if (!xpc::StringToJsval(cx, currentValue, &temp)) {
     153           0 :         return false;
     154             :       }
     155           0 :       if (!JS_DefinePropertyById(cx, obj, atomsCache->Hash_id, temp, JSPROP_ENUMERATE)) {
     156           0 :         return false;
     157             :       }
     158           0 :       break;
     159             :     } while(0);
     160             :   }
     161             : 
     162           0 :   if (mIconURL.WasPassed()) {
     163             :     do {
     164             :       // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     165           0 :       JS::Rooted<JS::Value> temp(cx);
     166           0 :       nsString const & currentValue = mIconURL.InternalValue();
     167           0 :       if (!xpc::StringToJsval(cx, currentValue, &temp)) {
     168           0 :         return false;
     169             :       }
     170           0 :       if (!JS_DefinePropertyById(cx, obj, atomsCache->IconURL_id, temp, JSPROP_ENUMERATE)) {
     171           0 :         return false;
     172             :       }
     173           0 :       break;
     174             :     } while(0);
     175             :   }
     176             : 
     177           0 :   if (mURL.WasPassed()) {
     178             :     do {
     179             :       // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     180           0 :       JS::Rooted<JS::Value> temp(cx);
     181           0 :       nsString const & currentValue = mURL.InternalValue();
     182           0 :       if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
     183           0 :         return false;
     184             :       }
     185           0 :       if (!JS_DefinePropertyById(cx, obj, atomsCache->URL_id, temp, JSPROP_ENUMERATE)) {
     186           0 :         return false;
     187             :       }
     188           0 :       break;
     189             :     } while(0);
     190             :   }
     191             : 
     192           0 :   return true;
     193             : }
     194             : 
     195             : bool
     196           0 : InstallTriggerData::ToJSON(nsAString& aJSON) const
     197             : {
     198           0 :   AutoJSAPI jsapi;
     199           0 :   jsapi.Init();
     200           0 :   JSContext *cx = jsapi.cx();
     201             :   // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
     202             :   // because we'll only be creating objects, in ways that have no
     203             :   // side-effects, followed by a call to JS::ToJSONMaybeSafely,
     204             :   // which likewise guarantees no side-effects for the sorts of
     205             :   // things we will pass it.
     206           0 :   JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
     207           0 :   JS::Rooted<JS::Value> val(cx);
     208           0 :   if (!ToObjectInternal(cx, &val)) {
     209           0 :     return false;
     210             :   }
     211           0 :   JS::Rooted<JSObject*> obj(cx, &val.toObject());
     212           0 :   return StringifyToJSON(cx, obj, aJSON);
     213             : }
     214             : 
     215             : void
     216           0 : InstallTriggerData::TraceDictionary(JSTracer* trc)
     217             : {
     218           0 : }
     219             : 
     220             : InstallTriggerData&
     221           0 : InstallTriggerData::operator=(const InstallTriggerData& aOther)
     222             : {
     223           0 :   mHash.Reset();
     224           0 :   if (aOther.mHash.WasPassed()) {
     225           0 :     mHash.Construct(aOther.mHash.Value());
     226             :   }
     227           0 :   mIconURL.Reset();
     228           0 :   if (aOther.mIconURL.WasPassed()) {
     229           0 :     mIconURL.Construct(aOther.mIconURL.Value());
     230             :   }
     231           0 :   mURL.Reset();
     232           0 :   if (aOther.mURL.WasPassed()) {
     233           0 :     mURL.Construct(aOther.mURL.Value());
     234             :   }
     235           0 :   return *this;
     236             : }
     237             : 
     238             : namespace binding_detail {
     239             : } // namespace binding_detail
     240             : 
     241             : 
     242             : bool
     243           0 : StringOrInstallTriggerData::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
     244             : {
     245           0 :   switch (mType) {
     246             :     case eUninitialized: {
     247           0 :       return false;
     248             :       break;
     249             :     }
     250             :     case eString: {
     251           0 :       if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) {
     252           0 :         return false;
     253             :       }
     254           0 :       return true;
     255             :       break;
     256             :     }
     257             :     case eInstallTriggerData: {
     258           0 :       if (!mValue.mInstallTriggerData.Value().ToObjectInternal(cx, rval)) {
     259           0 :         return false;
     260             :       }
     261           0 :       return true;
     262             :       break;
     263             :     }
     264             :     default: {
     265           0 :       return false;
     266             :       break;
     267             :     }
     268             :   }
     269             : 
     270             :   return false;
     271             : }
     272             : 
     273             : 
     274             : nsString&
     275           0 : OwningStringOrInstallTriggerData::RawSetAsString()
     276             : {
     277           0 :   if (mType == eString) {
     278           0 :     return mValue.mString.Value();
     279             :   }
     280           0 :   MOZ_ASSERT(mType == eUninitialized);
     281           0 :   mType = eString;
     282           0 :   return mValue.mString.SetValue();
     283             : }
     284             : 
     285             : nsString&
     286           0 : OwningStringOrInstallTriggerData::SetAsString()
     287             : {
     288           0 :   if (mType == eString) {
     289           0 :     return mValue.mString.Value();
     290             :   }
     291           0 :   Uninit();
     292           0 :   mType = eString;
     293           0 :   return mValue.mString.SetValue();
     294             : }
     295             : 
     296             : bool
     297           0 : OwningStringOrInstallTriggerData::TrySetToString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
     298             : {
     299           0 :   tryNext = false;
     300             :   { // scope for memberSlot
     301           0 :     nsString& memberSlot = RawSetAsString();
     302           0 :     if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
     303           0 :       return false;
     304             :     }
     305             :   }
     306           0 :   return true;
     307             : }
     308             : 
     309             : 
     310             : void
     311           0 : OwningStringOrInstallTriggerData::DestroyString()
     312             : {
     313           0 :   MOZ_ASSERT(IsString(), "Wrong type!");
     314           0 :   mValue.mString.Destroy();
     315           0 :   mType = eUninitialized;
     316           0 : }
     317             : 
     318             : 
     319             : 
     320             : 
     321             : InstallTriggerData&
     322           0 : OwningStringOrInstallTriggerData::RawSetAsInstallTriggerData()
     323             : {
     324           0 :   if (mType == eInstallTriggerData) {
     325           0 :     return mValue.mInstallTriggerData.Value();
     326             :   }
     327           0 :   MOZ_ASSERT(mType == eUninitialized);
     328           0 :   mType = eInstallTriggerData;
     329           0 :   return mValue.mInstallTriggerData.SetValue();
     330             : }
     331             : 
     332             : InstallTriggerData&
     333           0 : OwningStringOrInstallTriggerData::SetAsInstallTriggerData()
     334             : {
     335           0 :   if (mType == eInstallTriggerData) {
     336           0 :     return mValue.mInstallTriggerData.Value();
     337             :   }
     338           0 :   Uninit();
     339           0 :   mType = eInstallTriggerData;
     340           0 :   return mValue.mInstallTriggerData.SetValue();
     341             : }
     342             : 
     343             : bool
     344           0 : OwningStringOrInstallTriggerData::TrySetToInstallTriggerData(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
     345             : {
     346           0 :   tryNext = false;
     347             :   { // scope for memberSlot
     348           0 :     InstallTriggerData& memberSlot = RawSetAsInstallTriggerData();
     349           0 :     if (!IsConvertibleToDictionary(value)) {
     350           0 :       DestroyInstallTriggerData();
     351           0 :       tryNext = true;
     352           0 :       return true;
     353             :     }
     354           0 :     if (!memberSlot.Init(cx, value,  "Member of StringOrInstallTriggerData", passedToJSImpl)) {
     355           0 :       return false;
     356             :     }
     357             :   }
     358           0 :   return true;
     359             : }
     360             : 
     361             : void
     362           0 : OwningStringOrInstallTriggerData::DestroyInstallTriggerData()
     363             : {
     364           0 :   MOZ_ASSERT(IsInstallTriggerData(), "Wrong type!");
     365           0 :   mValue.mInstallTriggerData.Destroy();
     366           0 :   mType = eUninitialized;
     367           0 : }
     368             : 
     369             : 
     370             : 
     371             : 
     372             : void
     373           0 : OwningStringOrInstallTriggerData::Uninit()
     374             : {
     375           0 :   switch (mType) {
     376             :     case eUninitialized: {
     377           0 :       break;
     378             :     }
     379             :     case eString: {
     380           0 :       DestroyString();
     381           0 :       break;
     382             :     }
     383             :     case eInstallTriggerData: {
     384           0 :       DestroyInstallTriggerData();
     385           0 :       break;
     386             :     }
     387             :   }
     388           0 : }
     389             : 
     390             : bool
     391           0 : OwningStringOrInstallTriggerData::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
     392             : {
     393           0 :   switch (mType) {
     394             :     case eUninitialized: {
     395           0 :       return false;
     396             :       break;
     397             :     }
     398             :     case eString: {
     399           0 :       if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) {
     400           0 :         return false;
     401             :       }
     402           0 :       return true;
     403             :       break;
     404             :     }
     405             :     case eInstallTriggerData: {
     406           0 :       if (!mValue.mInstallTriggerData.Value().ToObjectInternal(cx, rval)) {
     407           0 :         return false;
     408             :       }
     409           0 :       return true;
     410             :       break;
     411             :     }
     412             :     default: {
     413           0 :       return false;
     414             :       break;
     415             :     }
     416             :   }
     417             : 
     418             :   return false;
     419             : }
     420             : 
     421             : void
     422           0 : OwningStringOrInstallTriggerData::TraceUnion(JSTracer* trc)
     423             : {
     424           0 : }
     425             : 
     426             : OwningStringOrInstallTriggerData&
     427           0 : OwningStringOrInstallTriggerData::operator=(const OwningStringOrInstallTriggerData& aOther)
     428             : {
     429           0 :   switch (aOther.mType) {
     430             :     case eUninitialized: {
     431           0 :       MOZ_ASSERT(mType == eUninitialized,
     432             :                  "We need to destroy ourselves?");
     433           0 :       break;
     434             :     }
     435             :     case eString: {
     436           0 :       SetAsString() = aOther.GetAsString();
     437           0 :       break;
     438             :     }
     439             :     case eInstallTriggerData: {
     440           0 :       SetAsInstallTriggerData() = aOther.GetAsInstallTriggerData();
     441           0 :       break;
     442             :     }
     443             :   }
     444           0 :   return *this;
     445             : }
     446             : 
     447             : 
     448             : void
     449           0 : InstallTriggerCallback::Call(JSContext* cx, JS::Handle<JS::Value> aThisVal, const nsAString& url, int16_t status, ErrorResult& aRv)
     450             : {
     451           0 :   JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
     452           0 :   JS::AutoValueVector argv(cx);
     453           0 :   if (!argv.resize(2)) {
     454           0 :     aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
     455           0 :     return;
     456             :   }
     457           0 :   unsigned argc = 2;
     458             : 
     459             :   do {
     460           0 :     argv[1].setInt32(int32_t(status));
     461           0 :     break;
     462             :   } while (0);
     463             : 
     464             :   do {
     465           0 :     nsString mutableStr(url);
     466           0 :     if (!xpc::NonVoidStringToJsval(cx, mutableStr, argv[0])) {
     467           0 :       aRv.Throw(NS_ERROR_UNEXPECTED);
     468           0 :       return;
     469             :     }
     470           0 :     break;
     471             :   } while (0);
     472             : 
     473           0 :   JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback));
     474           0 :   if (!JS::Call(cx, aThisVal, callable,
     475           0 :                 JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
     476           0 :     aRv.NoteJSContextException(cx);
     477           0 :     return;
     478             :   }
     479             : }
     480             : 
     481             : 
     482             : 
     483             : namespace binding_detail {
     484             : } // namespace binding_detail
     485             : 
     486             : 
     487             : namespace InstallTriggerImplBinding {
     488             : 
     489             : static bool
     490           0 : enabled(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::InstallTriggerImpl* self, const JSJitMethodCallArgs& args)
     491             : {
     492           0 :   Maybe<JS::Rooted<JSObject*> > unwrappedObj;
     493           0 :   bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
     494           0 :   if (objIsXray) {
     495           0 :     unwrappedObj.emplace(cx, obj);
     496             :   }
     497           0 :   if (objIsXray) {
     498           0 :     unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
     499           0 :     if (!unwrappedObj.ref()) {
     500           0 :       return false;
     501             :     }
     502             :   }
     503           0 :   binding_detail::FastErrorResult rv;
     504           0 :   bool result(self->Enabled(rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj)));
     505           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     506           0 :     return false;
     507             :   }
     508           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     509           0 :   args.rval().setBoolean(result);
     510           0 :   return true;
     511             : }
     512             : 
     513             : static const JSJitInfo enabled_methodinfo = {
     514             :   { (JSJitGetterOp)enabled },
     515             :   { prototypes::id::InstallTriggerImpl },
     516             :   { PrototypeTraits<prototypes::id::InstallTriggerImpl>::Depth },
     517             :   JSJitInfo::Method,
     518             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     519             :   JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
     520             :   false,  /* isInfallible. False in setters. */
     521             :   false,  /* isMovable.  Not relevant for setters. */
     522             :   false, /* isEliminatable.  Not relevant for setters. */
     523             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     524             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     525             :   false,  /* isTypedMethod.  Only relevant for methods. */
     526             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     527             : };
     528             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     529             : static_assert(0 < 1, "There is no slot for us");
     530             : 
     531             : static bool
     532           0 : updateEnabled(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::InstallTriggerImpl* self, const JSJitMethodCallArgs& args)
     533             : {
     534           0 :   Maybe<JS::Rooted<JSObject*> > unwrappedObj;
     535           0 :   bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
     536           0 :   if (objIsXray) {
     537           0 :     unwrappedObj.emplace(cx, obj);
     538             :   }
     539           0 :   if (objIsXray) {
     540           0 :     unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
     541           0 :     if (!unwrappedObj.ref()) {
     542           0 :       return false;
     543             :     }
     544             :   }
     545           0 :   binding_detail::FastErrorResult rv;
     546           0 :   bool result(self->UpdateEnabled(rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj)));
     547           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     548           0 :     return false;
     549             :   }
     550           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     551           0 :   args.rval().setBoolean(result);
     552           0 :   return true;
     553             : }
     554             : 
     555             : static const JSJitInfo updateEnabled_methodinfo = {
     556             :   { (JSJitGetterOp)updateEnabled },
     557             :   { prototypes::id::InstallTriggerImpl },
     558             :   { PrototypeTraits<prototypes::id::InstallTriggerImpl>::Depth },
     559             :   JSJitInfo::Method,
     560             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     561             :   JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
     562             :   false,  /* isInfallible. False in setters. */
     563             :   false,  /* isMovable.  Not relevant for setters. */
     564             :   false, /* isEliminatable.  Not relevant for setters. */
     565             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     566             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     567             :   false,  /* isTypedMethod.  Only relevant for methods. */
     568             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     569             : };
     570             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     571             : static_assert(0 < 1, "There is no slot for us");
     572             : 
     573             : static bool
     574           0 : install(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::InstallTriggerImpl* self, const JSJitMethodCallArgs& args)
     575             : {
     576           0 :   if (MOZ_UNLIKELY(args.length() < 1)) {
     577           0 :     return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "InstallTriggerImpl.install");
     578             :   }
     579           0 :   Maybe<JS::Rooted<JSObject*> > unwrappedObj;
     580           0 :   bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
     581           0 :   if (objIsXray) {
     582           0 :     unwrappedObj.emplace(cx, obj);
     583             :   }
     584           0 :   Record<nsString, OwningStringOrInstallTriggerData> arg0;
     585           0 :   if (args[0].isObject()) {
     586           0 :     auto& recordEntries = arg0.Entries();
     587             : 
     588           0 :     JS::Rooted<JSObject*> recordObj(cx, &args[0].toObject());
     589           0 :     JS::AutoIdVector ids(cx);
     590           0 :     if (!js::GetPropertyKeys(cx, recordObj,
     591             :                              JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS, &ids)) {
     592           0 :       return false;
     593             :     }
     594           0 :     if (!recordEntries.SetCapacity(ids.length(), mozilla::fallible)) {
     595           0 :       JS_ReportOutOfMemory(cx);
     596           0 :       return false;
     597             :     }
     598           0 :     JS::Rooted<JS::Value> propNameValue(cx);
     599           0 :     JS::Rooted<JS::Value> temp(cx);
     600           0 :     JS::Rooted<jsid> curId(cx);
     601           0 :     JS::Rooted<JS::Value> idVal(cx);
     602             :     // Use a hashset to keep track of ids seen, to avoid
     603             :     // introducing nasty O(N^2) behavior scanning for them all the
     604             :     // time.  Ideally we'd use a data structure with O(1) lookup
     605             :     // _and_ ordering for the MozMap, but we don't have one lying
     606             :     // around.
     607           0 :     nsTHashtable<nsStringHashKey> idsSeen;
     608           0 :     for (size_t i = 0; i < ids.length(); ++i) {
     609           0 :       curId = ids[i];
     610             : 
     611           0 :       JS::Rooted<JS::PropertyDescriptor> desc(cx);
     612           0 :       if (!JS_GetOwnPropertyDescriptorById(cx, recordObj, curId,
     613             :                                            &desc)) {
     614           0 :         return false;
     615             :       }
     616             : 
     617           0 :       if (!desc.object() /* == undefined in spec terms */ ||
     618           0 :           !desc.enumerable()) {
     619           0 :         continue;
     620             :       }
     621             : 
     622           0 :       idVal = js::IdToValue(curId);
     623           0 :       nsString propName;
     624             :       // This will just throw if idVal is a Symbol, like the spec says
     625             :       // to do.
     626           0 :       if (!ConvertJSValueToString(cx, idVal, propName)) {
     627           0 :         return false;
     628             :       }
     629             : 
     630           0 :       if (!JS_GetPropertyById(cx, recordObj, curId, &temp)) {
     631           0 :         return false;
     632             :       }
     633             : 
     634             :       Record<nsString, OwningStringOrInstallTriggerData>::EntryType* entry;
     635           0 :       if (!idsSeen.EnsureInserted(propName)) {
     636             :         // Find the existing entry.
     637           0 :         auto idx = recordEntries.IndexOf(propName);
     638           0 :         MOZ_ASSERT(idx != recordEntries.NoIndex,
     639             :                    "Why is it not found?");
     640             :         // Now blow it away to make it look like it was just added
     641             :         // to the array, because it's not obvious that it's
     642             :         // safe to write to its already-initialized mValue via our
     643             :         // normal codegen conversions.  For example, the value
     644             :         // could be a union and this would change its type, but
     645             :         // codegen assumes we won't do that.
     646           0 :         entry = recordEntries.ReconstructElementAt(idx);
     647             :       } else {
     648             :         // Safe to do an infallible append here, because we did a
     649             :         // SetCapacity above to the right capacity.
     650           0 :         entry = recordEntries.AppendElement();
     651             :       }
     652           0 :       entry->mKey = propName;
     653           0 :       OwningStringOrInstallTriggerData& slot = entry->mValue;
     654             :       {
     655           0 :         bool done = false, failed = false, tryNext;
     656           0 :         if (!done) {
     657           0 :           done = (failed = !slot.TrySetToInstallTriggerData(cx, temp, tryNext, true)) || !tryNext;
     658             :         }
     659           0 :         if (!done) {
     660             :           do {
     661           0 :             done = (failed = !slot.TrySetToString(cx, temp, tryNext)) || !tryNext;
     662           0 :             break;
     663             :           } while (0);
     664             :         }
     665           0 :         if (failed) {
     666           0 :           return false;
     667             :         }
     668           0 :         if (!done) {
     669           0 :           ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "Value in argument 1 of InstallTriggerImpl.install", "InstallTriggerData");
     670           0 :           return false;
     671             :         }
     672             :       }
     673             :     }
     674             :   } else {
     675           0 :     ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of InstallTriggerImpl.install");
     676           0 :     return false;
     677             :   }
     678           0 :   Optional<OwningNonNull<InstallTriggerCallback>> arg1;
     679           0 :   if (args.hasDefined(1)) {
     680           0 :     arg1.Construct();
     681           0 :     if (args[1].isObject()) {
     682           0 :       if (JS::IsCallable(&args[1].toObject())) {
     683             :       { // scope for tempRoot
     684           0 :         JS::Rooted<JSObject*> tempRoot(cx, &args[1].toObject());
     685           0 :         arg1.Value() = new InstallTriggerCallback(cx, tempRoot, GetIncumbentGlobal());
     686             :       }
     687             :       } else {
     688           0 :         ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 2 of InstallTriggerImpl.install");
     689           0 :         return false;
     690             :       }
     691             :     } else {
     692           0 :       ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of InstallTriggerImpl.install");
     693           0 :       return false;
     694             :     }
     695             :   }
     696           0 :   if (objIsXray) {
     697           0 :     unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
     698           0 :     if (!unwrappedObj.ref()) {
     699           0 :       return false;
     700             :     }
     701             :   }
     702           0 :   binding_detail::FastErrorResult rv;
     703           0 :   bool result(self->Install(Constify(arg0), NonNullHelper(Constify(arg1)), rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj)));
     704           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     705           0 :     return false;
     706             :   }
     707           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     708           0 :   args.rval().setBoolean(result);
     709           0 :   return true;
     710             : }
     711             : 
     712             : static const JSJitInfo install_methodinfo = {
     713             :   { (JSJitGetterOp)install },
     714             :   { prototypes::id::InstallTriggerImpl },
     715             :   { PrototypeTraits<prototypes::id::InstallTriggerImpl>::Depth },
     716             :   JSJitInfo::Method,
     717             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     718             :   JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
     719             :   false,  /* isInfallible. False in setters. */
     720             :   false,  /* isMovable.  Not relevant for setters. */
     721             :   false, /* isEliminatable.  Not relevant for setters. */
     722             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     723             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     724             :   false,  /* isTypedMethod.  Only relevant for methods. */
     725             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     726             : };
     727             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     728             : static_assert(0 < 1, "There is no slot for us");
     729             : 
     730             : static bool
     731           0 : installChrome(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::InstallTriggerImpl* self, const JSJitMethodCallArgs& args)
     732             : {
     733           0 :   if (MOZ_UNLIKELY(args.length() < 3)) {
     734           0 :     return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "InstallTriggerImpl.installChrome");
     735             :   }
     736           0 :   Maybe<JS::Rooted<JSObject*> > unwrappedObj;
     737           0 :   bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
     738           0 :   if (objIsXray) {
     739           0 :     unwrappedObj.emplace(cx, obj);
     740             :   }
     741             :   uint16_t arg0;
     742           0 :   if (!ValueToPrimitive<uint16_t, eDefault>(cx, args[0], &arg0)) {
     743           0 :     return false;
     744             :   }
     745           0 :   binding_detail::FakeString arg1;
     746           0 :   if (!ConvertJSValueToString(cx, args[1], eStringify, eStringify, arg1)) {
     747           0 :     return false;
     748             :   }
     749           0 :   binding_detail::FakeString arg2;
     750           0 :   if (!ConvertJSValueToString(cx, args[2], eStringify, eStringify, arg2)) {
     751           0 :     return false;
     752             :   }
     753           0 :   if (objIsXray) {
     754           0 :     unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
     755           0 :     if (!unwrappedObj.ref()) {
     756           0 :       return false;
     757             :     }
     758             :   }
     759           0 :   binding_detail::FastErrorResult rv;
     760           0 :   bool result(self->InstallChrome(arg0, NonNullHelper(Constify(arg1)), NonNullHelper(Constify(arg2)), rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj)));
     761           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     762           0 :     return false;
     763             :   }
     764           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     765           0 :   args.rval().setBoolean(result);
     766           0 :   return true;
     767             : }
     768             : 
     769             : static const JSJitInfo installChrome_methodinfo = {
     770             :   { (JSJitGetterOp)installChrome },
     771             :   { prototypes::id::InstallTriggerImpl },
     772             :   { PrototypeTraits<prototypes::id::InstallTriggerImpl>::Depth },
     773             :   JSJitInfo::Method,
     774             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     775             :   JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
     776             :   false,  /* isInfallible. False in setters. */
     777             :   false,  /* isMovable.  Not relevant for setters. */
     778             :   false, /* isEliminatable.  Not relevant for setters. */
     779             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     780             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     781             :   false,  /* isTypedMethod.  Only relevant for methods. */
     782             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     783             : };
     784             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     785             : static_assert(0 < 1, "There is no slot for us");
     786             : 
     787             : static bool
     788           0 : startSoftwareUpdate(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::InstallTriggerImpl* self, const JSJitMethodCallArgs& args)
     789             : {
     790           0 :   if (MOZ_UNLIKELY(args.length() < 1)) {
     791           0 :     return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "InstallTriggerImpl.startSoftwareUpdate");
     792             :   }
     793           0 :   Maybe<JS::Rooted<JSObject*> > unwrappedObj;
     794           0 :   bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
     795           0 :   if (objIsXray) {
     796           0 :     unwrappedObj.emplace(cx, obj);
     797             :   }
     798           0 :   binding_detail::FakeString arg0;
     799           0 :   if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
     800           0 :     return false;
     801             :   }
     802           0 :   Optional<uint16_t> arg1;
     803           0 :   if (args.hasDefined(1)) {
     804           0 :     arg1.Construct();
     805           0 :     if (!ValueToPrimitive<uint16_t, eDefault>(cx, args[1], &arg1.Value())) {
     806           0 :       return false;
     807             :     }
     808             :   }
     809           0 :   if (objIsXray) {
     810           0 :     unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
     811           0 :     if (!unwrappedObj.ref()) {
     812           0 :       return false;
     813             :     }
     814             :   }
     815           0 :   binding_detail::FastErrorResult rv;
     816           0 :   bool result(self->StartSoftwareUpdate(NonNullHelper(Constify(arg0)), Constify(arg1), rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj)));
     817           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     818           0 :     return false;
     819             :   }
     820           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     821           0 :   args.rval().setBoolean(result);
     822           0 :   return true;
     823             : }
     824             : 
     825             : static const JSJitInfo startSoftwareUpdate_methodinfo = {
     826             :   { (JSJitGetterOp)startSoftwareUpdate },
     827             :   { prototypes::id::InstallTriggerImpl },
     828             :   { PrototypeTraits<prototypes::id::InstallTriggerImpl>::Depth },
     829             :   JSJitInfo::Method,
     830             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     831             :   JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
     832             :   false,  /* isInfallible. False in setters. */
     833             :   false,  /* isMovable.  Not relevant for setters. */
     834             :   false, /* isEliminatable.  Not relevant for setters. */
     835             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     836             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     837             :   false,  /* isTypedMethod.  Only relevant for methods. */
     838             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     839             : };
     840             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     841             : static_assert(0 < 1, "There is no slot for us");
     842             : 
     843             : static bool
     844           0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
     845             : {
     846           0 :   mozilla::dom::InstallTriggerImpl* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::InstallTriggerImpl>(obj);
     847             :   // We don't want to preserve if we don't have a wrapper, and we
     848             :   // obviously can't preserve if we're not initialized.
     849           0 :   if (self && self->GetWrapperPreserveColor()) {
     850           0 :     PreserveWrapper(self);
     851             :   }
     852           0 :   return true;
     853             : }
     854             : 
     855             : static void
     856           0 : _finalize(js::FreeOp* fop, JSObject* obj)
     857             : {
     858           0 :   mozilla::dom::InstallTriggerImpl* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::InstallTriggerImpl>(obj);
     859           0 :   if (self) {
     860           0 :     ClearWrapper(self, self, obj);
     861           0 :     AddForDeferredFinalization<mozilla::dom::InstallTriggerImpl>(self);
     862             :   }
     863           0 : }
     864             : 
     865             : static void
     866           0 : _objectMoved(JSObject* obj, const JSObject* old)
     867             : {
     868           0 :   mozilla::dom::InstallTriggerImpl* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::InstallTriggerImpl>(obj);
     869           0 :   if (self) {
     870           0 :     UpdateWrapper(self, self, obj, old);
     871             :   }
     872           0 : }
     873             : 
     874             : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
     875             : #if defined(__clang__)
     876             : #pragma clang diagnostic push
     877             : #pragma clang diagnostic ignored "-Wmissing-braces"
     878             : #endif
     879             : static const JSFunctionSpec sChromeStaticMethods_specs[] = {
     880             :   JS_FNSPEC("_create", InstallTriggerImpl::_Create, nullptr, 2, 0, nullptr),
     881             :   JS_FS_END
     882             : };
     883             : #if defined(__clang__)
     884             : #pragma clang diagnostic pop
     885             : #endif
     886             : 
     887             : 
     888             : // Can't be const because the pref-enabled boolean needs to be writable
     889             : static Prefable<const JSFunctionSpec> sChromeStaticMethods[] = {
     890             :   { nullptr, &sChromeStaticMethods_specs[0] },
     891             :   { nullptr, nullptr }
     892             : };
     893             : 
     894             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
     895             :     "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
     896             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
     897             :     "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
     898             : 
     899             : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
     900             : #if defined(__clang__)
     901             : #pragma clang diagnostic push
     902             : #pragma clang diagnostic ignored "-Wmissing-braces"
     903             : #endif
     904             : static const JSFunctionSpec sMethods_specs[] = {
     905             :   JS_FNSPEC("enabled", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&enabled_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
     906             :   JS_FNSPEC("updateEnabled", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&updateEnabled_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
     907             :   JS_FNSPEC("install", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&install_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
     908             :   JS_FNSPEC("installChrome", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&installChrome_methodinfo), 3, JSPROP_ENUMERATE, nullptr),
     909             :   JS_FNSPEC("startSoftwareUpdate", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&startSoftwareUpdate_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
     910             :   JS_FS_END
     911             : };
     912             : #if defined(__clang__)
     913             : #pragma clang diagnostic pop
     914             : #endif
     915             : 
     916             : 
     917             : // Can't be const because the pref-enabled boolean needs to be writable
     918             : static Prefable<const JSFunctionSpec> sMethods[] = {
     919             :   { nullptr, &sMethods_specs[0] },
     920             :   { nullptr, nullptr }
     921             : };
     922             : 
     923             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
     924             :     "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
     925             : static_assert(5 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
     926             :     "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
     927             : 
     928             : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
     929             : #if defined(__clang__)
     930             : #pragma clang diagnostic push
     931             : #pragma clang diagnostic ignored "-Wmissing-braces"
     932             : #endif
     933             : static const ConstantSpec sConstants_specs[] = {
     934             :   { "SKIN", JS::Int32Value(1) },
     935             :   { "LOCALE", JS::Int32Value(2) },
     936             :   { "CONTENT", JS::Int32Value(4) },
     937             :   { "PACKAGE", JS::Int32Value(7) },
     938             :   { 0, JS::UndefinedValue() }
     939             : };
     940             : #if defined(__clang__)
     941             : #pragma clang diagnostic pop
     942             : #endif
     943             : 
     944             : 
     945             : // Can't be const because the pref-enabled boolean needs to be writable
     946             : static Prefable<const ConstantSpec> sConstants[] = {
     947             :   { nullptr, &sConstants_specs[0] },
     948             :   { nullptr, nullptr }
     949             : };
     950             : 
     951             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
     952             :     "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
     953             : static_assert(4 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
     954             :     "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
     955             : 
     956             : 
     957             : static uint16_t sNativeProperties_sortedPropertyIndices[9];
     958             : static PropertyInfo sNativeProperties_propertyInfos[9];
     959             : 
     960             : static const NativePropertiesN<2> sNativeProperties = {
     961             :   false, 0,
     962             :   false, 0,
     963             :   true,  0 /* sMethods */,
     964             :   false, 0,
     965             :   false, 0,
     966             :   false, 0,
     967             :   true,  1 /* sConstants */,
     968             :   -1,
     969             :   9,
     970             :   sNativeProperties_sortedPropertyIndices,
     971             :   {
     972             :     { sMethods, &sNativeProperties_propertyInfos[0] },
     973             :     { sConstants, &sNativeProperties_propertyInfos[5] }
     974             :   }
     975             : };
     976             : static_assert(9 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
     977             :     "We have a property info count that is oversized");
     978             : 
     979             : static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[1];
     980             : static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[1];
     981             : 
     982             : static const NativePropertiesN<1> sChromeOnlyNativeProperties = {
     983             :   true,  0 /* sChromeStaticMethods */,
     984             :   false, 0,
     985             :   false, 0,
     986             :   false, 0,
     987             :   false, 0,
     988             :   false, 0,
     989             :   false, 0,
     990             :   -1,
     991             :   1,
     992             :   sChromeOnlyNativeProperties_sortedPropertyIndices,
     993             :   {
     994             :     { sChromeStaticMethods, &sChromeOnlyNativeProperties_propertyInfos[0] }
     995             :   }
     996             : };
     997             : static_assert(1 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount),
     998             :     "We have a property info count that is oversized");
     999             : 
    1000             : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
    1001             :   {
    1002             :     "Function",
    1003             :     JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
    1004             :     &sBoringInterfaceObjectClassClassOps,
    1005             :     JS_NULL_CLASS_SPEC,
    1006             :     JS_NULL_CLASS_EXT,
    1007             :     &sInterfaceObjectClassObjectOps
    1008             :   },
    1009             :   eInterface,
    1010             :   true,
    1011             :   prototypes::id::InstallTriggerImpl,
    1012             :   PrototypeTraits<prototypes::id::InstallTriggerImpl>::Depth,
    1013             :   sNativePropertyHooks,
    1014             :   "function InstallTriggerImpl() {\n    [native code]\n}",
    1015             :   JS::GetRealmFunctionPrototype
    1016             : };
    1017             : 
    1018             : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
    1019             :   {
    1020             :     "InstallTriggerImplPrototype",
    1021             :     JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
    1022             :     JS_NULL_CLASS_OPS,
    1023             :     JS_NULL_CLASS_SPEC,
    1024             :     JS_NULL_CLASS_EXT,
    1025             :     JS_NULL_OBJECT_OPS
    1026             :   },
    1027             :   eInterfacePrototype,
    1028             :   false,
    1029             :   prototypes::id::InstallTriggerImpl,
    1030             :   PrototypeTraits<prototypes::id::InstallTriggerImpl>::Depth,
    1031             :   sNativePropertyHooks,
    1032             :   "[object InstallTriggerImplPrototype]",
    1033             :   JS::GetRealmObjectPrototype
    1034             : };
    1035             : 
    1036             : bool
    1037           0 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
    1038             : {
    1039           0 :   return nsContentUtils::ThreadsafeIsSystemCaller(aCx);
    1040             : }
    1041             : 
    1042             : JSObject*
    1043           0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
    1044             : {
    1045           0 :   return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
    1046             : }
    1047             : 
    1048             : static const js::ClassOps sClassOps = {
    1049             :   _addProperty, /* addProperty */
    1050             :   nullptr,               /* delProperty */
    1051             :   nullptr,               /* getProperty */
    1052             :   nullptr,               /* setProperty */
    1053             :   nullptr,               /* enumerate */
    1054             :   nullptr, /* newEnumerate */
    1055             :   nullptr, /* resolve */
    1056             :   nullptr, /* mayResolve */
    1057             :   _finalize, /* finalize */
    1058             :   nullptr, /* call */
    1059             :   nullptr,               /* hasInstance */
    1060             :   nullptr,               /* construct */
    1061             :   nullptr, /* trace */
    1062             : };
    1063             : 
    1064             : static const js::ClassExtension sClassExtension = {
    1065             :   nullptr, /* weakmapKeyDelegateOp */
    1066             :   _objectMoved /* objectMovedOp */
    1067             : };
    1068             : 
    1069             : static const DOMJSClass sClass = {
    1070             :   { "InstallTriggerImpl",
    1071             :     JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
    1072             :     &sClassOps,
    1073             :     JS_NULL_CLASS_SPEC,
    1074             :     &sClassExtension,
    1075             :     JS_NULL_OBJECT_OPS
    1076             :   },
    1077             :   { prototypes::id::InstallTriggerImpl, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
    1078             :   IsBaseOf<nsISupports, mozilla::dom::InstallTriggerImpl >::value,
    1079             :   sNativePropertyHooks,
    1080             :   FindAssociatedGlobalForNative<mozilla::dom::InstallTriggerImpl>::Get,
    1081             :   GetProtoObjectHandle,
    1082             :   GetCCParticipant<mozilla::dom::InstallTriggerImpl>::Get()
    1083             : };
    1084             : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
    1085             :               "Must have the right minimal number of reserved slots.");
    1086             : static_assert(1 >= 1,
    1087             :               "Must have enough reserved slots.");
    1088             : 
    1089             : const JSClass*
    1090           0 : GetJSClass()
    1091             : {
    1092           0 :   return sClass.ToJSClass();
    1093             : }
    1094             : 
    1095             : bool
    1096           0 : Wrap(JSContext* aCx, mozilla::dom::InstallTriggerImpl* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
    1097             : {
    1098             :   MOZ_ASSERT(static_cast<mozilla::dom::InstallTriggerImpl*>(aObject) ==
    1099             :              reinterpret_cast<mozilla::dom::InstallTriggerImpl*>(aObject),
    1100             :              "Multiple inheritance for mozilla::dom::InstallTriggerImpl is broken.");
    1101           0 :   MOZ_ASSERT(ToSupportsIsCorrect(aObject));
    1102           0 :   MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
    1103           0 :   MOZ_ASSERT(!aCache->GetWrapper(),
    1104             :              "You should probably not be using Wrap() directly; use "
    1105             :              "GetOrCreateDOMReflector instead");
    1106             : 
    1107           0 :   MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
    1108             :              "nsISupports must be on our primary inheritance chain");
    1109             : 
    1110           0 :   JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
    1111           0 :   if (!global) {
    1112           0 :     return false;
    1113             :   }
    1114           0 :   MOZ_ASSERT(JS_IsGlobalObject(global));
    1115           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(global));
    1116             : 
    1117             :   // That might have ended up wrapping us already, due to the wonders
    1118             :   // of XBL.  Check for that, and bail out as needed.
    1119           0 :   aReflector.set(aCache->GetWrapper());
    1120           0 :   if (aReflector) {
    1121             : #ifdef DEBUG
    1122           0 :     binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
    1123             : #endif // DEBUG
    1124           0 :     return true;
    1125             :   }
    1126             : 
    1127           0 :   JSAutoCompartment ac(aCx, global);
    1128           0 :   JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
    1129           0 :   if (!canonicalProto) {
    1130           0 :     return false;
    1131             :   }
    1132           0 :   JS::Rooted<JSObject*> proto(aCx);
    1133           0 :   if (aGivenProto) {
    1134           0 :     proto = aGivenProto;
    1135             :     // Unfortunately, while aGivenProto was in the compartment of aCx
    1136             :     // coming in, we changed compartments to that of "parent" so may need
    1137             :     // to wrap the proto here.
    1138           0 :     if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
    1139           0 :       if (!JS_WrapObject(aCx, &proto)) {
    1140           0 :         return false;
    1141             :       }
    1142             :     }
    1143             :   } else {
    1144           0 :     proto = canonicalProto;
    1145             :   }
    1146             : 
    1147           0 :   BindingJSObjectCreator<mozilla::dom::InstallTriggerImpl> creator(aCx);
    1148           0 :   creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
    1149           0 :   if (!aReflector) {
    1150           0 :     return false;
    1151             :   }
    1152             : 
    1153           0 :   aCache->SetWrapper(aReflector);
    1154           0 :   creator.InitializationSucceeded();
    1155             : 
    1156           0 :   MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
    1157             :              aCache->GetWrapperPreserveColor() == aReflector);
    1158             :   // If proto != canonicalProto, we have to preserve our wrapper;
    1159             :   // otherwise we won't be able to properly recreate it later, since
    1160             :   // we won't know what proto to use.  Note that we don't check
    1161             :   // aGivenProto here, since it's entirely possible (and even
    1162             :   // somewhat common) to have a non-null aGivenProto which is the
    1163             :   // same as canonicalProto.
    1164           0 :   if (proto != canonicalProto) {
    1165           0 :     PreserveWrapper(aObject);
    1166             :   }
    1167             : 
    1168           0 :   return true;
    1169             : }
    1170             : 
    1171             : const NativePropertyHooks sNativePropertyHooks[] = { {
    1172             :   nullptr,
    1173             :   nullptr,
    1174             :   nullptr,
    1175             :   { sNativeProperties.Upcast(), sChromeOnlyNativeProperties.Upcast() },
    1176             :   prototypes::id::InstallTriggerImpl,
    1177             :   constructors::id::InstallTriggerImpl,
    1178             :   nullptr,
    1179             :   &DefaultXrayExpandoObjectClass
    1180             : } };
    1181             : 
    1182             : void
    1183           0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
    1184             : {
    1185           0 :   JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
    1186           0 :   if (!parentProto) {
    1187           0 :     return;
    1188             :   }
    1189             : 
    1190           0 :   JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
    1191           0 :   if (!constructorProto) {
    1192           0 :     return;
    1193             :   }
    1194             : 
    1195             :   static bool sIdsInited = false;
    1196           0 :   if (!sIdsInited && NS_IsMainThread()) {
    1197           0 :     if (!InitIds(aCx, sNativeProperties.Upcast())) {
    1198           0 :       return;
    1199             :     }
    1200           0 :     if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) {
    1201           0 :       return;
    1202             :     }
    1203           0 :     sIdsInited = true;
    1204             :   }
    1205             : 
    1206           0 :   JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::InstallTriggerImpl);
    1207           0 :   JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::InstallTriggerImpl);
    1208           0 :   dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
    1209             :                               &sPrototypeClass.mBase, protoCache,
    1210             :                               constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
    1211             :                               interfaceCache,
    1212             :                               sNativeProperties.Upcast(),
    1213           0 :                               nsContentUtils::ThreadsafeIsSystemCaller(aCx) ? sChromeOnlyNativeProperties.Upcast() : nullptr,
    1214             :                               "InstallTriggerImpl", aDefineOnGlobal,
    1215             :                               nullptr,
    1216           0 :                               false);
    1217             : }
    1218             : 
    1219             : JS::Handle<JSObject*>
    1220           0 : GetProtoObjectHandle(JSContext* aCx)
    1221             : {
    1222             :   /* Get the interface prototype object for this class.  This will create the
    1223             :      object as needed. */
    1224           0 :   bool aDefineOnGlobal = true;
    1225             : 
    1226             :   /* Make sure our global is sane.  Hopefully we can remove this sometime */
    1227           0 :   JSObject* global = JS::CurrentGlobalOrNull(aCx);
    1228           0 :   if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
    1229           0 :     return nullptr;
    1230             :   }
    1231             : 
    1232             :   /* Check to see whether the interface objects are already installed */
    1233           0 :   ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
    1234           0 :   if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::InstallTriggerImpl)) {
    1235           0 :     JS::Rooted<JSObject*> rootedGlobal(aCx, global);
    1236           0 :     CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
    1237             :   }
    1238             : 
    1239             :   /*
    1240             :    * The object might _still_ be null, but that's OK.
    1241             :    *
    1242             :    * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
    1243             :    * traced by TraceProtoAndIfaceCache() and its contents are never
    1244             :    * changed after they have been set.
    1245             :    *
    1246             :    * Calling address() avoids the read read barrier that does gray
    1247             :    * unmarking, but it's not possible for the object to be gray here.
    1248             :    */
    1249             : 
    1250           0 :   const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::InstallTriggerImpl);
    1251           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
    1252           0 :   return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
    1253             : }
    1254             : 
    1255             : JS::Handle<JSObject*>
    1256           0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
    1257             : {
    1258             :   /* Get the interface object for this class.  This will create the object as
    1259             :      needed. */
    1260             : 
    1261             :   /* Make sure our global is sane.  Hopefully we can remove this sometime */
    1262           0 :   JSObject* global = JS::CurrentGlobalOrNull(aCx);
    1263           0 :   if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
    1264           0 :     return nullptr;
    1265             :   }
    1266             : 
    1267             :   /* Check to see whether the interface objects are already installed */
    1268           0 :   ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
    1269           0 :   if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::InstallTriggerImpl)) {
    1270           0 :     JS::Rooted<JSObject*> rootedGlobal(aCx, global);
    1271           0 :     CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
    1272             :   }
    1273             : 
    1274             :   /*
    1275             :    * The object might _still_ be null, but that's OK.
    1276             :    *
    1277             :    * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
    1278             :    * traced by TraceProtoAndIfaceCache() and its contents are never
    1279             :    * changed after they have been set.
    1280             :    *
    1281             :    * Calling address() avoids the read read barrier that does gray
    1282             :    * unmarking, but it's not possible for the object to be gray here.
    1283             :    */
    1284             : 
    1285           0 :   const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::InstallTriggerImpl);
    1286           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
    1287           0 :   return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
    1288             : }
    1289             : 
    1290             : JSObject*
    1291           0 : GetConstructorObject(JSContext* aCx)
    1292             : {
    1293           0 :   return GetConstructorObjectHandle(aCx);
    1294             : }
    1295             : 
    1296             : } // namespace InstallTriggerImplBinding
    1297             : 
    1298             : 
    1299             : 
    1300             : bool
    1301           0 : InstallTriggerImplJSImpl::Enabled(ErrorResult& aRv, JSCompartment* aCompartment)
    1302             : {
    1303           0 :   CallSetup s(this, aRv, "InstallTriggerImpl.enabled", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
    1304           0 :   JSContext* cx = s.GetContext();
    1305           0 :   if (!cx) {
    1306           0 :     MOZ_ASSERT(aRv.Failed());
    1307           0 :     return bool(0);
    1308             :   }
    1309           0 :   JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
    1310             : 
    1311           0 :   JS::Rooted<JS::Value> callable(cx);
    1312           0 :   InstallTriggerImplAtoms* atomsCache = GetAtomCache<InstallTriggerImplAtoms>(cx);
    1313           0 :   if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
    1314           0 :       !GetCallableProperty(cx, atomsCache->enabled_id, &callable)) {
    1315           0 :     aRv.Throw(NS_ERROR_UNEXPECTED);
    1316           0 :     return bool(0);
    1317             :   }
    1318           0 :   JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
    1319           0 :   if (!JS::Call(cx, thisValue, callable,
    1320           0 :                 JS::HandleValueArray::empty(), &rval)) {
    1321           0 :     aRv.NoteJSContextException(cx);
    1322           0 :     return bool(0);
    1323             :   }
    1324             :   bool rvalDecl;
    1325           0 :   if (!ValueToPrimitive<bool, eDefault>(cx, rval, &rvalDecl)) {
    1326           0 :     aRv.Throw(NS_ERROR_UNEXPECTED);
    1327           0 :     return bool(0);
    1328             :   }
    1329           0 :   return rvalDecl;
    1330             : }
    1331             : 
    1332             : bool
    1333           0 : InstallTriggerImplJSImpl::UpdateEnabled(ErrorResult& aRv, JSCompartment* aCompartment)
    1334             : {
    1335           0 :   CallSetup s(this, aRv, "InstallTriggerImpl.updateEnabled", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
    1336           0 :   JSContext* cx = s.GetContext();
    1337           0 :   if (!cx) {
    1338           0 :     MOZ_ASSERT(aRv.Failed());
    1339           0 :     return bool(0);
    1340             :   }
    1341           0 :   JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
    1342             : 
    1343           0 :   JS::Rooted<JS::Value> callable(cx);
    1344           0 :   InstallTriggerImplAtoms* atomsCache = GetAtomCache<InstallTriggerImplAtoms>(cx);
    1345           0 :   if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
    1346           0 :       !GetCallableProperty(cx, atomsCache->updateEnabled_id, &callable)) {
    1347           0 :     aRv.Throw(NS_ERROR_UNEXPECTED);
    1348           0 :     return bool(0);
    1349             :   }
    1350           0 :   JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
    1351           0 :   if (!JS::Call(cx, thisValue, callable,
    1352           0 :                 JS::HandleValueArray::empty(), &rval)) {
    1353           0 :     aRv.NoteJSContextException(cx);
    1354           0 :     return bool(0);
    1355             :   }
    1356             :   bool rvalDecl;
    1357           0 :   if (!ValueToPrimitive<bool, eDefault>(cx, rval, &rvalDecl)) {
    1358           0 :     aRv.Throw(NS_ERROR_UNEXPECTED);
    1359           0 :     return bool(0);
    1360             :   }
    1361           0 :   return rvalDecl;
    1362             : }
    1363             : 
    1364             : bool
    1365           0 : InstallTriggerImplJSImpl::Install(const Record<nsString, OwningStringOrInstallTriggerData>& installs, const Optional<OwningNonNull<InstallTriggerCallback>>& callback, ErrorResult& aRv, JSCompartment* aCompartment)
    1366             : {
    1367           0 :   CallSetup s(this, aRv, "InstallTriggerImpl.install", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
    1368           0 :   JSContext* cx = s.GetContext();
    1369           0 :   if (!cx) {
    1370           0 :     MOZ_ASSERT(aRv.Failed());
    1371           0 :     return bool(0);
    1372             :   }
    1373           0 :   JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
    1374           0 :   JS::AutoValueVector argv(cx);
    1375           0 :   if (!argv.resize(2)) {
    1376           0 :     aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
    1377           0 :     return bool(0);
    1378             :   }
    1379           0 :   unsigned argc = 2;
    1380             : 
    1381             :   do {
    1382           0 :     if (callback.WasPassed()) {
    1383           0 :       argv[1].setObjectOrNull(GetCallbackFromCallbackObject(callback.Value()));
    1384           0 :       if (!MaybeWrapObjectValue(cx, argv[1])) {
    1385           0 :         aRv.Throw(NS_ERROR_UNEXPECTED);
    1386           0 :         return bool(0);
    1387             :       }
    1388           0 :       break;
    1389           0 :     } else if (argc == 2) {
    1390             :       // This is our current trailing argument; reduce argc
    1391           0 :       --argc;
    1392             :     } else {
    1393           0 :       argv[1].setUndefined();
    1394             :     }
    1395             :   } while (0);
    1396             : 
    1397             :   do {
    1398             : 
    1399           0 :     JS::Rooted<JSObject*> returnObj(cx, JS_NewPlainObject(cx));
    1400           0 :     if (!returnObj) {
    1401           0 :       aRv.Throw(NS_ERROR_UNEXPECTED);
    1402           0 :       return bool(0);
    1403             :     }
    1404             :     // Scope for 'tmp'
    1405             :     {
    1406           0 :       JS::Rooted<JS::Value> tmp(cx);
    1407           0 :       for (auto& entry : installs.Entries()) {
    1408           0 :         auto& recordValue0 = entry.mValue;
    1409             :         // Control block to let us common up the JS_DefineUCProperty calls when there
    1410             :         // are different ways to succeed at wrapping the value.
    1411             :         do {
    1412           0 :           if (!recordValue0.ToJSVal(cx, returnObj, &tmp)) {
    1413           0 :             aRv.Throw(NS_ERROR_UNEXPECTED);
    1414           0 :             return bool(0);
    1415             :           }
    1416           0 :           break;
    1417             :         } while (0);
    1418           0 :         if (!JS_DefineUCProperty(cx, returnObj,
    1419             :                                  entry.mKey.BeginReading(),
    1420           0 :                                  entry.mKey.Length(), tmp,
    1421             :                                  JSPROP_ENUMERATE)) {
    1422           0 :           aRv.Throw(NS_ERROR_UNEXPECTED);
    1423           0 :           return bool(0);
    1424             :         }
    1425             :       }
    1426             :     }
    1427           0 :     argv[0].setObject(*returnObj);
    1428           0 :     break;
    1429             :   } while (0);
    1430             : 
    1431           0 :   JS::Rooted<JS::Value> callable(cx);
    1432           0 :   InstallTriggerImplAtoms* atomsCache = GetAtomCache<InstallTriggerImplAtoms>(cx);
    1433           0 :   if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
    1434           0 :       !GetCallableProperty(cx, atomsCache->install_id, &callable)) {
    1435           0 :     aRv.Throw(NS_ERROR_UNEXPECTED);
    1436           0 :     return bool(0);
    1437             :   }
    1438           0 :   JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
    1439           0 :   if (!JS::Call(cx, thisValue, callable,
    1440           0 :                 JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
    1441           0 :     aRv.NoteJSContextException(cx);
    1442           0 :     return bool(0);
    1443             :   }
    1444             :   bool rvalDecl;
    1445           0 :   if (!ValueToPrimitive<bool, eDefault>(cx, rval, &rvalDecl)) {
    1446           0 :     aRv.Throw(NS_ERROR_UNEXPECTED);
    1447           0 :     return bool(0);
    1448             :   }
    1449           0 :   return rvalDecl;
    1450             : }
    1451             : 
    1452             : bool
    1453           0 : InstallTriggerImplJSImpl::InstallChrome(uint16_t type, const nsAString& url, const nsAString& skin, ErrorResult& aRv, JSCompartment* aCompartment)
    1454             : {
    1455           0 :   CallSetup s(this, aRv, "InstallTriggerImpl.installChrome", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
    1456           0 :   JSContext* cx = s.GetContext();
    1457           0 :   if (!cx) {
    1458           0 :     MOZ_ASSERT(aRv.Failed());
    1459           0 :     return bool(0);
    1460             :   }
    1461           0 :   JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
    1462           0 :   JS::AutoValueVector argv(cx);
    1463           0 :   if (!argv.resize(3)) {
    1464           0 :     aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
    1465           0 :     return bool(0);
    1466             :   }
    1467           0 :   unsigned argc = 3;
    1468             : 
    1469             :   do {
    1470           0 :     nsString mutableStr(skin);
    1471           0 :     if (!xpc::NonVoidStringToJsval(cx, mutableStr, argv[2])) {
    1472           0 :       aRv.Throw(NS_ERROR_UNEXPECTED);
    1473           0 :       return bool(0);
    1474             :     }
    1475           0 :     break;
    1476             :   } while (0);
    1477             : 
    1478             :   do {
    1479           0 :     nsString mutableStr(url);
    1480           0 :     if (!xpc::NonVoidStringToJsval(cx, mutableStr, argv[1])) {
    1481           0 :       aRv.Throw(NS_ERROR_UNEXPECTED);
    1482           0 :       return bool(0);
    1483             :     }
    1484           0 :     break;
    1485             :   } while (0);
    1486             : 
    1487             :   do {
    1488           0 :     argv[0].setInt32(int32_t(type));
    1489           0 :     break;
    1490             :   } while (0);
    1491             : 
    1492           0 :   JS::Rooted<JS::Value> callable(cx);
    1493           0 :   InstallTriggerImplAtoms* atomsCache = GetAtomCache<InstallTriggerImplAtoms>(cx);
    1494           0 :   if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
    1495           0 :       !GetCallableProperty(cx, atomsCache->installChrome_id, &callable)) {
    1496           0 :     aRv.Throw(NS_ERROR_UNEXPECTED);
    1497           0 :     return bool(0);
    1498             :   }
    1499           0 :   JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
    1500           0 :   if (!JS::Call(cx, thisValue, callable,
    1501           0 :                 JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
    1502           0 :     aRv.NoteJSContextException(cx);
    1503           0 :     return bool(0);
    1504             :   }
    1505             :   bool rvalDecl;
    1506           0 :   if (!ValueToPrimitive<bool, eDefault>(cx, rval, &rvalDecl)) {
    1507           0 :     aRv.Throw(NS_ERROR_UNEXPECTED);
    1508           0 :     return bool(0);
    1509             :   }
    1510           0 :   return rvalDecl;
    1511             : }
    1512             : 
    1513             : bool
    1514           0 : InstallTriggerImplJSImpl::StartSoftwareUpdate(const nsAString& url, const Optional<uint16_t>& flags, ErrorResult& aRv, JSCompartment* aCompartment)
    1515             : {
    1516           0 :   CallSetup s(this, aRv, "InstallTriggerImpl.startSoftwareUpdate", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
    1517           0 :   JSContext* cx = s.GetContext();
    1518           0 :   if (!cx) {
    1519           0 :     MOZ_ASSERT(aRv.Failed());
    1520           0 :     return bool(0);
    1521             :   }
    1522           0 :   JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
    1523           0 :   JS::AutoValueVector argv(cx);
    1524           0 :   if (!argv.resize(2)) {
    1525           0 :     aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
    1526           0 :     return bool(0);
    1527             :   }
    1528           0 :   unsigned argc = 2;
    1529             : 
    1530             :   do {
    1531           0 :     if (flags.WasPassed()) {
    1532           0 :       argv[1].setInt32(int32_t(flags.Value()));
    1533           0 :       break;
    1534           0 :     } else if (argc == 2) {
    1535             :       // This is our current trailing argument; reduce argc
    1536           0 :       --argc;
    1537             :     } else {
    1538           0 :       argv[1].setUndefined();
    1539             :     }
    1540             :   } while (0);
    1541             : 
    1542             :   do {
    1543           0 :     nsString mutableStr(url);
    1544           0 :     if (!xpc::NonVoidStringToJsval(cx, mutableStr, argv[0])) {
    1545           0 :       aRv.Throw(NS_ERROR_UNEXPECTED);
    1546           0 :       return bool(0);
    1547             :     }
    1548           0 :     break;
    1549             :   } while (0);
    1550             : 
    1551           0 :   JS::Rooted<JS::Value> callable(cx);
    1552           0 :   InstallTriggerImplAtoms* atomsCache = GetAtomCache<InstallTriggerImplAtoms>(cx);
    1553           0 :   if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
    1554           0 :       !GetCallableProperty(cx, atomsCache->startSoftwareUpdate_id, &callable)) {
    1555           0 :     aRv.Throw(NS_ERROR_UNEXPECTED);
    1556           0 :     return bool(0);
    1557             :   }
    1558           0 :   JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
    1559           0 :   if (!JS::Call(cx, thisValue, callable,
    1560           0 :                 JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
    1561           0 :     aRv.NoteJSContextException(cx);
    1562           0 :     return bool(0);
    1563             :   }
    1564             :   bool rvalDecl;
    1565           0 :   if (!ValueToPrimitive<bool, eDefault>(cx, rval, &rvalDecl)) {
    1566           0 :     aRv.Throw(NS_ERROR_UNEXPECTED);
    1567           0 :     return bool(0);
    1568             :   }
    1569           0 :   return rvalDecl;
    1570             : }
    1571             : 
    1572             : bool
    1573           0 : InstallTriggerImplJSImpl::InitIds(JSContext* cx, InstallTriggerImplAtoms* atomsCache)
    1574             : {
    1575           0 :   MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
    1576             : 
    1577             :   // Initialize these in reverse order so that any failure leaves the first one
    1578             :   // uninitialized.
    1579           0 :   if (!atomsCache->startSoftwareUpdate_id.init(cx, "startSoftwareUpdate") ||
    1580           0 :       !atomsCache->installChrome_id.init(cx, "installChrome") ||
    1581           0 :       !atomsCache->install_id.init(cx, "install") ||
    1582           0 :       !atomsCache->updateEnabled_id.init(cx, "updateEnabled") ||
    1583           0 :       !atomsCache->enabled_id.init(cx, "enabled")) {
    1584           0 :     return false;
    1585             :   }
    1586           0 :   return true;
    1587             : }
    1588             : 
    1589             : 
    1590             : 
    1591             : NS_IMPL_CYCLE_COLLECTION_CLASS(InstallTriggerImpl)
    1592           0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(InstallTriggerImpl)
    1593           0 :   NS_IMPL_CYCLE_COLLECTION_UNLINK(mImpl)
    1594           0 :   NS_IMPL_CYCLE_COLLECTION_UNLINK(mParent)
    1595           0 :   NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
    1596           0 :   tmp->ClearWeakReferences();
    1597           0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_END
    1598           0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(InstallTriggerImpl)
    1599           0 :   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mImpl)
    1600           0 :   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mParent)
    1601           0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
    1602           0 : NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(InstallTriggerImpl)
    1603           0 : NS_IMPL_CYCLE_COLLECTING_ADDREF(InstallTriggerImpl)
    1604           0 : NS_IMPL_CYCLE_COLLECTING_RELEASE(InstallTriggerImpl)
    1605           0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(InstallTriggerImpl)
    1606           0 :   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
    1607           0 :   NS_INTERFACE_MAP_ENTRY(nsISupports)
    1608           0 :   NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
    1609           0 : NS_INTERFACE_MAP_END
    1610             : 
    1611           0 : InstallTriggerImpl::InstallTriggerImpl(JS::Handle<JSObject*> aJSImplObject, nsIGlobalObject* aParent)
    1612           0 :   : mImpl(new InstallTriggerImplJSImpl(nullptr, aJSImplObject, /* aIncumbentGlobal = */ nullptr)),
    1613           0 :     mParent(aParent)
    1614             : {
    1615           0 : }
    1616             : 
    1617             : 
    1618           0 : InstallTriggerImpl::~InstallTriggerImpl()
    1619             : {
    1620           0 : }
    1621             : 
    1622             : nsISupports*
    1623           0 : InstallTriggerImpl::GetParentObject() const
    1624             : {
    1625           0 :   return mParent;
    1626             : }
    1627             : 
    1628             : JSObject*
    1629           0 : InstallTriggerImpl::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
    1630             : {
    1631           0 :   JS::Rooted<JSObject*> obj(aCx, InstallTriggerImplBinding::Wrap(aCx, this, aGivenProto));
    1632           0 :   if (!obj) {
    1633           0 :     return nullptr;
    1634             :   }
    1635             : 
    1636             :   // Now define it on our chrome object
    1637           0 :   JSAutoCompartment ac(aCx, mImpl->CallbackOrNull());
    1638           0 :   if (!JS_WrapObject(aCx, &obj)) {
    1639           0 :     return nullptr;
    1640             :   }
    1641           0 :   if (!JS_DefineProperty(aCx, mImpl->CallbackOrNull(), "__DOM_IMPL__", obj, 0)) {
    1642           0 :     return nullptr;
    1643             :   }
    1644           0 :   return obj;
    1645             : }
    1646             : 
    1647             : bool
    1648           0 : InstallTriggerImpl::Enabled(ErrorResult& aRv, JSCompartment* aCompartment)
    1649             : {
    1650           0 :   return mImpl->Enabled(aRv, aCompartment);
    1651             : }
    1652             : 
    1653             : bool
    1654           0 : InstallTriggerImpl::UpdateEnabled(ErrorResult& aRv, JSCompartment* aCompartment)
    1655             : {
    1656           0 :   return mImpl->UpdateEnabled(aRv, aCompartment);
    1657             : }
    1658             : 
    1659             : bool
    1660           0 : InstallTriggerImpl::Install(const Record<nsString, OwningStringOrInstallTriggerData>& installs, const Optional<OwningNonNull<InstallTriggerCallback>>& callback, ErrorResult& aRv, JSCompartment* aCompartment)
    1661             : {
    1662           0 :   return mImpl->Install(installs, callback, aRv, aCompartment);
    1663             : }
    1664             : 
    1665             : bool
    1666           0 : InstallTriggerImpl::InstallChrome(uint16_t type, const nsAString& url, const nsAString& skin, ErrorResult& aRv, JSCompartment* aCompartment)
    1667             : {
    1668           0 :   return mImpl->InstallChrome(type, url, skin, aRv, aCompartment);
    1669             : }
    1670             : 
    1671             : bool
    1672           0 : InstallTriggerImpl::StartSoftwareUpdate(const nsAString& url, const Optional<uint16_t>& flags, ErrorResult& aRv, JSCompartment* aCompartment)
    1673             : {
    1674           0 :   return mImpl->StartSoftwareUpdate(url, flags, aRv, aCompartment);
    1675             : }
    1676             : 
    1677             : bool
    1678           0 : InstallTriggerImpl::_Create(JSContext* cx, unsigned argc, JS::Value* vp)
    1679             : {
    1680           0 :   JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
    1681           0 :   if (args.length() < 2) {
    1682           0 :     return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "InstallTriggerImpl._create");
    1683             :   }
    1684           0 :   if (!args[0].isObject()) {
    1685           0 :     return ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of InstallTriggerImpl._create");
    1686             :   }
    1687           0 :   if (!args[1].isObject()) {
    1688           0 :     return ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of InstallTriggerImpl._create");
    1689             :   }
    1690             : 
    1691             :   // GlobalObject will go through wrappers as needed for us, and
    1692             :   // is simpler than the right UnwrapArg incantation.
    1693           0 :   GlobalObject global(cx, &args[0].toObject());
    1694           0 :   if (global.Failed()) {
    1695           0 :     return false;
    1696             :   }
    1697           0 :   nsCOMPtr<nsIGlobalObject> globalHolder = do_QueryInterface(global.GetAsSupports());
    1698           0 :   MOZ_ASSERT(globalHolder);
    1699           0 :   JS::Rooted<JSObject*> arg(cx, &args[1].toObject());
    1700           0 :   RefPtr<InstallTriggerImpl> impl = new InstallTriggerImpl(arg, globalHolder);
    1701           0 :   MOZ_ASSERT(js::IsObjectInContextCompartment(arg, cx));
    1702           0 :   return GetOrCreateDOMReflector(cx, impl, args.rval());
    1703             : }
    1704             : 
    1705             : 
    1706             : } // namespace dom
    1707             : } // namespace mozilla

Generated by: LCOV version 1.13