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

          Line data    Source code
       1             : /* THIS FILE IS AUTOGENERATED FROM CredentialManagement.webidl BY Codegen.py - DO NOT EDIT */
       2             : 
       3             : #include "AtomList.h"
       4             : #include "CredentialManagementBinding.h"
       5             : #include "WrapperFactory.h"
       6             : #include "mozilla/OwningNonNull.h"
       7             : #include "mozilla/Preferences.h"
       8             : #include "mozilla/dom/BindingUtils.h"
       9             : #include "mozilla/dom/Credential.h"
      10             : #include "mozilla/dom/CredentialsContainer.h"
      11             : #include "mozilla/dom/DOMJSClass.h"
      12             : #include "mozilla/dom/NonRefcountedDOMObject.h"
      13             : #include "mozilla/dom/Promise.h"
      14             : #include "mozilla/dom/ScriptSettings.h"
      15             : #include "mozilla/dom/ToJSValue.h"
      16             : #include "mozilla/dom/XrayExpandoClass.h"
      17             : 
      18             : namespace mozilla {
      19             : namespace dom {
      20             : 
      21             : 
      22           0 : CredentialCreationOptions::CredentialCreationOptions()
      23           0 :   : mPublicKey(FastDictionaryInitializer())
      24             : {
      25             :   // Safe to pass a null context if we pass a null value
      26           0 :   Init(nullptr, JS::NullHandleValue);
      27           0 : }
      28             : 
      29             : 
      30             : bool
      31           0 : CredentialCreationOptions::InitIds(JSContext* cx, CredentialCreationOptionsAtoms* 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->publicKey_id.init(cx, "publicKey")) {
      38           0 :     return false;
      39             :   }
      40           0 :   return true;
      41             : }
      42             : 
      43             : bool
      44           0 : CredentialCreationOptions::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
      45             : {
      46             :   // Passing a null JSContext is OK only if we're initing from null,
      47             :   // Since in that case we will not have to do any property gets
      48             :   // Also evaluate isNullOrUndefined in order to avoid false-positive
      49             :   // checkers by static analysis tools
      50           0 :   MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
      51           0 :   CredentialCreationOptionsAtoms* atomsCache = nullptr;
      52           0 :   if (cx) {
      53           0 :     atomsCache = GetAtomCache<CredentialCreationOptionsAtoms>(cx);
      54           0 :     if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
      55           0 :       return false;
      56             :     }
      57             :   }
      58             : 
      59           0 :   if (!IsConvertibleToDictionary(val)) {
      60           0 :     return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
      61             :   }
      62             : 
      63           0 :   bool isNull = val.isNullOrUndefined();
      64             :   // We only need these if !isNull, in which case we have |cx|.
      65           0 :   Maybe<JS::Rooted<JSObject *> > object;
      66           0 :   Maybe<JS::Rooted<JS::Value> > temp;
      67           0 :   if (!isNull) {
      68           0 :     MOZ_ASSERT(cx);
      69           0 :     object.emplace(cx, &val.toObject());
      70           0 :     temp.emplace(cx);
      71             :   }
      72           0 :   if (!isNull) {
      73           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->publicKey_id, temp.ptr())) {
      74           0 :       return false;
      75             :     }
      76             :   }
      77           0 :   if (!mPublicKey.Init(cx, (!isNull && !temp->isUndefined()) ? temp.ref() : JS::NullHandleValue,  "'publicKey' member of CredentialCreationOptions", passedToJSImpl)) {
      78           0 :     return false;
      79             :   }
      80           0 :   mIsAnyMemberPresent = true;
      81           0 :   return true;
      82             : }
      83             : 
      84             : bool
      85           0 : CredentialCreationOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
      86             : {
      87           0 :   CredentialCreationOptionsAtoms* atomsCache = GetAtomCache<CredentialCreationOptionsAtoms>(cx);
      88           0 :   if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
      89           0 :     return false;
      90             :   }
      91             : 
      92           0 :   JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
      93           0 :   if (!obj) {
      94           0 :     return false;
      95             :   }
      96           0 :   rval.set(JS::ObjectValue(*obj));
      97             : 
      98             :   do {
      99             :     // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     100           0 :     JS::Rooted<JS::Value> temp(cx);
     101           0 :     MakeCredentialOptions const & currentValue = mPublicKey;
     102           0 :     if (!currentValue.ToObjectInternal(cx, &temp)) {
     103           0 :       return false;
     104             :     }
     105           0 :     if (!JS_DefinePropertyById(cx, obj, atomsCache->publicKey_id, temp, JSPROP_ENUMERATE)) {
     106           0 :       return false;
     107             :     }
     108           0 :     break;
     109             :   } while(0);
     110             : 
     111           0 :   return true;
     112             : }
     113             : 
     114             : void
     115           0 : CredentialCreationOptions::TraceDictionary(JSTracer* trc)
     116             : {
     117           0 :   mPublicKey.TraceDictionary(trc);
     118           0 : }
     119             : 
     120             : namespace binding_detail {
     121             : } // namespace binding_detail
     122             : 
     123             : 
     124             : 
     125           0 : CredentialRequestOptions::CredentialRequestOptions()
     126           0 :   : mPublicKey(FastDictionaryInitializer())
     127             : {
     128             :   // Safe to pass a null context if we pass a null value
     129           0 :   Init(nullptr, JS::NullHandleValue);
     130           0 : }
     131             : 
     132             : 
     133             : bool
     134           0 : CredentialRequestOptions::InitIds(JSContext* cx, CredentialRequestOptionsAtoms* atomsCache)
     135             : {
     136           0 :   MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
     137             : 
     138             :   // Initialize these in reverse order so that any failure leaves the first one
     139             :   // uninitialized.
     140           0 :   if (!atomsCache->publicKey_id.init(cx, "publicKey")) {
     141           0 :     return false;
     142             :   }
     143           0 :   return true;
     144             : }
     145             : 
     146             : bool
     147           0 : CredentialRequestOptions::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
     148             : {
     149             :   // Passing a null JSContext is OK only if we're initing from null,
     150             :   // Since in that case we will not have to do any property gets
     151             :   // Also evaluate isNullOrUndefined in order to avoid false-positive
     152             :   // checkers by static analysis tools
     153           0 :   MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
     154           0 :   CredentialRequestOptionsAtoms* atomsCache = nullptr;
     155           0 :   if (cx) {
     156           0 :     atomsCache = GetAtomCache<CredentialRequestOptionsAtoms>(cx);
     157           0 :     if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
     158           0 :       return false;
     159             :     }
     160             :   }
     161             : 
     162           0 :   if (!IsConvertibleToDictionary(val)) {
     163           0 :     return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
     164             :   }
     165             : 
     166           0 :   bool isNull = val.isNullOrUndefined();
     167             :   // We only need these if !isNull, in which case we have |cx|.
     168           0 :   Maybe<JS::Rooted<JSObject *> > object;
     169           0 :   Maybe<JS::Rooted<JS::Value> > temp;
     170           0 :   if (!isNull) {
     171           0 :     MOZ_ASSERT(cx);
     172           0 :     object.emplace(cx, &val.toObject());
     173           0 :     temp.emplace(cx);
     174             :   }
     175           0 :   if (!isNull) {
     176           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->publicKey_id, temp.ptr())) {
     177           0 :       return false;
     178             :     }
     179             :   }
     180           0 :   if (!mPublicKey.Init(cx, (!isNull && !temp->isUndefined()) ? temp.ref() : JS::NullHandleValue,  "'publicKey' member of CredentialRequestOptions", passedToJSImpl)) {
     181           0 :     return false;
     182             :   }
     183           0 :   mIsAnyMemberPresent = true;
     184           0 :   return true;
     185             : }
     186             : 
     187             : bool
     188           0 : CredentialRequestOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
     189             : {
     190           0 :   CredentialRequestOptionsAtoms* atomsCache = GetAtomCache<CredentialRequestOptionsAtoms>(cx);
     191           0 :   if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
     192           0 :     return false;
     193             :   }
     194             : 
     195           0 :   JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
     196           0 :   if (!obj) {
     197           0 :     return false;
     198             :   }
     199           0 :   rval.set(JS::ObjectValue(*obj));
     200             : 
     201             :   do {
     202             :     // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     203           0 :     JS::Rooted<JS::Value> temp(cx);
     204           0 :     PublicKeyCredentialRequestOptions const & currentValue = mPublicKey;
     205           0 :     if (!currentValue.ToObjectInternal(cx, &temp)) {
     206           0 :       return false;
     207             :     }
     208           0 :     if (!JS_DefinePropertyById(cx, obj, atomsCache->publicKey_id, temp, JSPROP_ENUMERATE)) {
     209           0 :       return false;
     210             :     }
     211           0 :     break;
     212             :   } while(0);
     213             : 
     214           0 :   return true;
     215             : }
     216             : 
     217             : void
     218           0 : CredentialRequestOptions::TraceDictionary(JSTracer* trc)
     219             : {
     220           0 :   mPublicKey.TraceDictionary(trc);
     221           0 : }
     222             : 
     223             : namespace binding_detail {
     224             : } // namespace binding_detail
     225             : 
     226             : 
     227             : namespace CredentialBinding {
     228             : 
     229             : static bool
     230           0 : get_id(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Credential* self, JSJitGetterCallArgs args)
     231             : {
     232           0 :   DOMString result;
     233           0 :   self->GetId(result);
     234           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     235           0 :   if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
     236           0 :     return false;
     237             :   }
     238           0 :   return true;
     239             : }
     240             : 
     241             : static const JSJitInfo id_getterinfo = {
     242             :   { (JSJitGetterOp)get_id },
     243             :   { prototypes::id::Credential },
     244             :   { PrototypeTraits<prototypes::id::Credential>::Depth },
     245             :   JSJitInfo::Getter,
     246             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     247             :   JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
     248             :   false,  /* isInfallible. False in setters. */
     249             :   false,  /* isMovable.  Not relevant for setters. */
     250             :   false, /* isEliminatable.  Not relevant for setters. */
     251             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     252             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     253             :   false,  /* isTypedMethod.  Only relevant for methods. */
     254             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     255             : };
     256             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     257             : static_assert(0 < 1, "There is no slot for us");
     258             : 
     259             : static bool
     260           0 : get_type(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Credential* self, JSJitGetterCallArgs args)
     261             : {
     262           0 :   DOMString result;
     263           0 :   self->GetType(result);
     264           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     265           0 :   if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
     266           0 :     return false;
     267             :   }
     268           0 :   return true;
     269             : }
     270             : 
     271             : static const JSJitInfo type_getterinfo = {
     272             :   { (JSJitGetterOp)get_type },
     273             :   { prototypes::id::Credential },
     274             :   { PrototypeTraits<prototypes::id::Credential>::Depth },
     275             :   JSJitInfo::Getter,
     276             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     277             :   JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
     278             :   false,  /* isInfallible. False in setters. */
     279             :   false,  /* isMovable.  Not relevant for setters. */
     280             :   false, /* isEliminatable.  Not relevant for setters. */
     281             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     282             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     283             :   false,  /* isTypedMethod.  Only relevant for methods. */
     284             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     285             : };
     286             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     287             : static_assert(0 < 1, "There is no slot for us");
     288             : 
     289             : static bool
     290           0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
     291             : {
     292           0 :   mozilla::dom::Credential* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Credential>(obj);
     293             :   // We don't want to preserve if we don't have a wrapper, and we
     294             :   // obviously can't preserve if we're not initialized.
     295           0 :   if (self && self->GetWrapperPreserveColor()) {
     296           0 :     PreserveWrapper(self);
     297             :   }
     298           0 :   return true;
     299             : }
     300             : 
     301             : static void
     302           0 : _finalize(js::FreeOp* fop, JSObject* obj)
     303             : {
     304           0 :   mozilla::dom::Credential* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Credential>(obj);
     305           0 :   if (self) {
     306           0 :     ClearWrapper(self, self, obj);
     307           0 :     AddForDeferredFinalization<mozilla::dom::Credential>(self);
     308             :   }
     309           0 : }
     310             : 
     311             : static void
     312           0 : _objectMoved(JSObject* obj, const JSObject* old)
     313             : {
     314           0 :   mozilla::dom::Credential* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Credential>(obj);
     315           0 :   if (self) {
     316           0 :     UpdateWrapper(self, self, obj, old);
     317             :   }
     318           0 : }
     319             : 
     320             : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
     321             : #if defined(__clang__)
     322             : #pragma clang diagnostic push
     323             : #pragma clang diagnostic ignored "-Wmissing-braces"
     324             : #endif
     325             : static const JSPropertySpec sAttributes_specs[] = {
     326             :   { "id", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &id_getterinfo, nullptr, nullptr },
     327             :   { "type", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &type_getterinfo, nullptr, nullptr },
     328             :   { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
     329             : };
     330             : #if defined(__clang__)
     331             : #pragma clang diagnostic pop
     332             : #endif
     333             : 
     334             : static PrefableDisablers sAttributes_disablers0 = {
     335             :   true, true, 0, nullptr
     336             : };
     337             : 
     338             : // Can't be const because the pref-enabled boolean needs to be writable
     339             : static Prefable<const JSPropertySpec> sAttributes[] = {
     340             :   { &sAttributes_disablers0, &sAttributes_specs[0] },
     341             :   { nullptr, nullptr }
     342             : };
     343             : 
     344             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
     345             :     "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
     346             : static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
     347             :     "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
     348             : 
     349             : 
     350             : static uint16_t sNativeProperties_sortedPropertyIndices[2];
     351             : static PropertyInfo sNativeProperties_propertyInfos[2];
     352             : 
     353             : static const NativePropertiesN<1> sNativeProperties = {
     354             :   false, 0,
     355             :   false, 0,
     356             :   false, 0,
     357             :   true,  0 /* sAttributes */,
     358             :   false, 0,
     359             :   false, 0,
     360             :   false, 0,
     361             :   -1,
     362             :   2,
     363             :   sNativeProperties_sortedPropertyIndices,
     364             :   {
     365             :     { sAttributes, &sNativeProperties_propertyInfos[0] }
     366             :   }
     367             : };
     368             : static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
     369             :     "We have a property info count that is oversized");
     370             : 
     371             : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
     372             :   {
     373             :     "Function",
     374             :     JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
     375             :     &sBoringInterfaceObjectClassClassOps,
     376             :     JS_NULL_CLASS_SPEC,
     377             :     JS_NULL_CLASS_EXT,
     378             :     &sInterfaceObjectClassObjectOps
     379             :   },
     380             :   eInterface,
     381             :   true,
     382             :   prototypes::id::Credential,
     383             :   PrototypeTraits<prototypes::id::Credential>::Depth,
     384             :   sNativePropertyHooks,
     385             :   "function Credential() {\n    [native code]\n}",
     386             :   JS::GetRealmFunctionPrototype
     387             : };
     388             : 
     389             : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
     390             :   {
     391             :     "CredentialPrototype",
     392             :     JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
     393             :     JS_NULL_CLASS_OPS,
     394             :     JS_NULL_CLASS_SPEC,
     395             :     JS_NULL_CLASS_EXT,
     396             :     JS_NULL_OBJECT_OPS
     397             :   },
     398             :   eInterfacePrototype,
     399             :   false,
     400             :   prototypes::id::Credential,
     401             :   PrototypeTraits<prototypes::id::Credential>::Depth,
     402             :   sNativePropertyHooks,
     403             :   "[object CredentialPrototype]",
     404             :   JS::GetRealmObjectPrototype
     405             : };
     406             : 
     407             : bool
     408           0 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
     409             : {
     410             :   static bool sPrefValue;
     411             :   static bool sPrefCacheSetUp = false;
     412           0 :   if (!sPrefCacheSetUp) {
     413           0 :     sPrefCacheSetUp = true;
     414           0 :     Preferences::AddBoolVarCache(&sPrefValue, "security.webauth.webauthn");
     415             :   }
     416             : 
     417           0 :   return sPrefValue &&
     418           0 :          mozilla::dom::IsSecureContextOrObjectIsFromSecureContext(aCx, aObj);
     419             : }
     420             : 
     421             : JSObject*
     422           0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
     423             : {
     424           0 :   return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
     425             : }
     426             : 
     427             : static const js::ClassOps sClassOps = {
     428             :   _addProperty, /* addProperty */
     429             :   nullptr,               /* delProperty */
     430             :   nullptr,               /* getProperty */
     431             :   nullptr,               /* setProperty */
     432             :   nullptr,               /* enumerate */
     433             :   nullptr, /* newEnumerate */
     434             :   nullptr, /* resolve */
     435             :   nullptr, /* mayResolve */
     436             :   _finalize, /* finalize */
     437             :   nullptr, /* call */
     438             :   nullptr,               /* hasInstance */
     439             :   nullptr,               /* construct */
     440             :   nullptr, /* trace */
     441             : };
     442             : 
     443             : static const js::ClassExtension sClassExtension = {
     444             :   nullptr, /* weakmapKeyDelegateOp */
     445             :   _objectMoved /* objectMovedOp */
     446             : };
     447             : 
     448             : static const DOMJSClass sClass = {
     449             :   { "Credential",
     450             :     JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
     451             :     &sClassOps,
     452             :     JS_NULL_CLASS_SPEC,
     453             :     &sClassExtension,
     454             :     JS_NULL_OBJECT_OPS
     455             :   },
     456             :   { prototypes::id::Credential, 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 },
     457             :   IsBaseOf<nsISupports, mozilla::dom::Credential >::value,
     458             :   sNativePropertyHooks,
     459             :   FindAssociatedGlobalForNative<mozilla::dom::Credential>::Get,
     460             :   GetProtoObjectHandle,
     461             :   GetCCParticipant<mozilla::dom::Credential>::Get()
     462             : };
     463             : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
     464             :               "Must have the right minimal number of reserved slots.");
     465             : static_assert(1 >= 1,
     466             :               "Must have enough reserved slots.");
     467             : 
     468             : const JSClass*
     469           0 : GetJSClass()
     470             : {
     471           0 :   return sClass.ToJSClass();
     472             : }
     473             : 
     474             : bool
     475           0 : Wrap(JSContext* aCx, mozilla::dom::Credential* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
     476             : {
     477             :   MOZ_ASSERT(static_cast<mozilla::dom::Credential*>(aObject) ==
     478             :              reinterpret_cast<mozilla::dom::Credential*>(aObject),
     479             :              "Multiple inheritance for mozilla::dom::Credential is broken.");
     480           0 :   MOZ_ASSERT(ToSupportsIsCorrect(aObject));
     481           0 :   MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
     482           0 :   MOZ_ASSERT(!aCache->GetWrapper(),
     483             :              "You should probably not be using Wrap() directly; use "
     484             :              "GetOrCreateDOMReflector instead");
     485             : 
     486           0 :   MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
     487             :              "nsISupports must be on our primary inheritance chain");
     488             : 
     489           0 :   JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
     490           0 :   if (!global) {
     491           0 :     return false;
     492             :   }
     493           0 :   MOZ_ASSERT(JS_IsGlobalObject(global));
     494           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(global));
     495             : 
     496             :   // That might have ended up wrapping us already, due to the wonders
     497             :   // of XBL.  Check for that, and bail out as needed.
     498           0 :   aReflector.set(aCache->GetWrapper());
     499           0 :   if (aReflector) {
     500             : #ifdef DEBUG
     501           0 :     binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
     502             : #endif // DEBUG
     503           0 :     return true;
     504             :   }
     505             : 
     506           0 :   JSAutoCompartment ac(aCx, global);
     507           0 :   JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
     508           0 :   if (!canonicalProto) {
     509           0 :     return false;
     510             :   }
     511           0 :   JS::Rooted<JSObject*> proto(aCx);
     512           0 :   if (aGivenProto) {
     513           0 :     proto = aGivenProto;
     514             :     // Unfortunately, while aGivenProto was in the compartment of aCx
     515             :     // coming in, we changed compartments to that of "parent" so may need
     516             :     // to wrap the proto here.
     517           0 :     if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
     518           0 :       if (!JS_WrapObject(aCx, &proto)) {
     519           0 :         return false;
     520             :       }
     521             :     }
     522             :   } else {
     523           0 :     proto = canonicalProto;
     524             :   }
     525             : 
     526           0 :   BindingJSObjectCreator<mozilla::dom::Credential> creator(aCx);
     527           0 :   creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
     528           0 :   if (!aReflector) {
     529           0 :     return false;
     530             :   }
     531             : 
     532           0 :   aCache->SetWrapper(aReflector);
     533           0 :   creator.InitializationSucceeded();
     534             : 
     535           0 :   MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
     536             :              aCache->GetWrapperPreserveColor() == aReflector);
     537             :   // If proto != canonicalProto, we have to preserve our wrapper;
     538             :   // otherwise we won't be able to properly recreate it later, since
     539             :   // we won't know what proto to use.  Note that we don't check
     540             :   // aGivenProto here, since it's entirely possible (and even
     541             :   // somewhat common) to have a non-null aGivenProto which is the
     542             :   // same as canonicalProto.
     543           0 :   if (proto != canonicalProto) {
     544           0 :     PreserveWrapper(aObject);
     545             :   }
     546             : 
     547           0 :   return true;
     548             : }
     549             : 
     550             : const NativePropertyHooks sNativePropertyHooks[] = { {
     551             :   nullptr,
     552             :   nullptr,
     553             :   nullptr,
     554             :   { sNativeProperties.Upcast(), nullptr },
     555             :   prototypes::id::Credential,
     556             :   constructors::id::Credential,
     557             :   nullptr,
     558             :   &DefaultXrayExpandoObjectClass
     559             : } };
     560             : 
     561             : void
     562           0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
     563             : {
     564           0 :   JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
     565           0 :   if (!parentProto) {
     566           0 :     return;
     567             :   }
     568             : 
     569           0 :   JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
     570           0 :   if (!constructorProto) {
     571           0 :     return;
     572             :   }
     573             : 
     574             :   static bool sIdsInited = false;
     575           0 :   if (!sIdsInited && NS_IsMainThread()) {
     576           0 :     if (!InitIds(aCx, sNativeProperties.Upcast())) {
     577           0 :       return;
     578             :     }
     579           0 :     sIdsInited = true;
     580             :   }
     581             : 
     582           0 :   JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::Credential);
     583           0 :   JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::Credential);
     584           0 :   dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
     585             :                               &sPrototypeClass.mBase, protoCache,
     586             :                               constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
     587             :                               interfaceCache,
     588             :                               sNativeProperties.Upcast(),
     589             :                               nullptr,
     590             :                               "Credential", aDefineOnGlobal,
     591             :                               nullptr,
     592           0 :                               false);
     593             : }
     594             : 
     595             : JS::Handle<JSObject*>
     596           0 : GetProtoObjectHandle(JSContext* aCx)
     597             : {
     598             :   /* Get the interface prototype object for this class.  This will create the
     599             :      object as needed. */
     600           0 :   bool aDefineOnGlobal = true;
     601             : 
     602             :   /* Make sure our global is sane.  Hopefully we can remove this sometime */
     603           0 :   JSObject* global = JS::CurrentGlobalOrNull(aCx);
     604           0 :   if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
     605           0 :     return nullptr;
     606             :   }
     607             : 
     608             :   /* Check to see whether the interface objects are already installed */
     609           0 :   ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
     610           0 :   if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::Credential)) {
     611           0 :     JS::Rooted<JSObject*> rootedGlobal(aCx, global);
     612           0 :     CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
     613             :   }
     614             : 
     615             :   /*
     616             :    * The object might _still_ be null, but that's OK.
     617             :    *
     618             :    * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
     619             :    * traced by TraceProtoAndIfaceCache() and its contents are never
     620             :    * changed after they have been set.
     621             :    *
     622             :    * Calling address() avoids the read read barrier that does gray
     623             :    * unmarking, but it's not possible for the object to be gray here.
     624             :    */
     625             : 
     626           0 :   const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::Credential);
     627           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
     628           0 :   return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
     629             : }
     630             : 
     631             : JSObject*
     632           0 : GetProtoObject(JSContext* aCx)
     633             : {
     634           0 :   return GetProtoObjectHandle(aCx);
     635             : }
     636             : 
     637             : JS::Handle<JSObject*>
     638           0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
     639             : {
     640             :   /* Get the interface object for this class.  This will create the object as
     641             :      needed. */
     642             : 
     643             :   /* Make sure our global is sane.  Hopefully we can remove this sometime */
     644           0 :   JSObject* global = JS::CurrentGlobalOrNull(aCx);
     645           0 :   if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
     646           0 :     return nullptr;
     647             :   }
     648             : 
     649             :   /* Check to see whether the interface objects are already installed */
     650           0 :   ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
     651           0 :   if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::Credential)) {
     652           0 :     JS::Rooted<JSObject*> rootedGlobal(aCx, global);
     653           0 :     CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
     654             :   }
     655             : 
     656             :   /*
     657             :    * The object might _still_ be null, but that's OK.
     658             :    *
     659             :    * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
     660             :    * traced by TraceProtoAndIfaceCache() and its contents are never
     661             :    * changed after they have been set.
     662             :    *
     663             :    * Calling address() avoids the read read barrier that does gray
     664             :    * unmarking, but it's not possible for the object to be gray here.
     665             :    */
     666             : 
     667           0 :   const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::Credential);
     668           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
     669           0 :   return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
     670             : }
     671             : 
     672             : JSObject*
     673           0 : GetConstructorObject(JSContext* aCx)
     674             : {
     675           0 :   return GetConstructorObjectHandle(aCx);
     676             : }
     677             : 
     678             : } // namespace CredentialBinding
     679             : 
     680             : 
     681             : 
     682             : namespace CredentialsContainerBinding {
     683             : 
     684             : static bool
     685           0 : get(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::CredentialsContainer* self, const JSJitMethodCallArgs& args)
     686             : {
     687           0 :   RootedDictionary<binding_detail::FastCredentialRequestOptions> arg0(cx);
     688           0 :   if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue,  "Argument 1 of CredentialsContainer.get", false)) {
     689           0 :     return false;
     690             :   }
     691           0 :   auto result(StrongOrRawPtr<Promise>(self->Get(Constify(arg0))));
     692           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     693           0 :   if (!ToJSValue(cx, result, args.rval())) {
     694           0 :     return false;
     695             :   }
     696           0 :   return true;
     697             : }
     698             : 
     699             : static bool
     700           0 : get_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::CredentialsContainer* self, const JSJitMethodCallArgs& args)
     701             : {
     702             :   // Make sure to save the callee before someone maybe messes
     703             :   // with rval().
     704           0 :   JS::Rooted<JSObject*> callee(cx, &args.callee());
     705           0 :   bool ok = get(cx, obj, self, args);
     706           0 :   if (ok) {
     707           0 :     return true;
     708             :   }
     709           0 :   return ConvertExceptionToPromise(cx, xpc::XrayAwareCalleeGlobal(callee),
     710           0 :                                    args.rval());
     711             : }
     712             : 
     713             : static const JSJitInfo get_methodinfo = {
     714             :   { (JSJitGetterOp)get_promiseWrapper },
     715             :   { prototypes::id::CredentialsContainer },
     716             :   { PrototypeTraits<prototypes::id::CredentialsContainer>::Depth },
     717             :   JSJitInfo::Method,
     718             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     719             :   JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
     720             :   false,  /* isInfallible. False in setters. */
     721             :   false,  /* isMovable.  Not relevant for setters. */
     722             :   false, /* isEliminatable.  Not relevant for setters. */
     723             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     724             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     725             :   false,  /* isTypedMethod.  Only relevant for methods. */
     726             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     727             : };
     728             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     729             : static_assert(0 < 1, "There is no slot for us");
     730             : 
     731             : static bool
     732           0 : create(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::CredentialsContainer* self, const JSJitMethodCallArgs& args)
     733             : {
     734           0 :   RootedDictionary<binding_detail::FastCredentialCreationOptions> arg0(cx);
     735           0 :   if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue,  "Argument 1 of CredentialsContainer.create", false)) {
     736           0 :     return false;
     737             :   }
     738           0 :   auto result(StrongOrRawPtr<Promise>(self->Create(Constify(arg0))));
     739           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     740           0 :   if (!ToJSValue(cx, result, args.rval())) {
     741           0 :     return false;
     742             :   }
     743           0 :   return true;
     744             : }
     745             : 
     746             : static bool
     747           0 : create_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::CredentialsContainer* self, const JSJitMethodCallArgs& args)
     748             : {
     749             :   // Make sure to save the callee before someone maybe messes
     750             :   // with rval().
     751           0 :   JS::Rooted<JSObject*> callee(cx, &args.callee());
     752           0 :   bool ok = create(cx, obj, self, args);
     753           0 :   if (ok) {
     754           0 :     return true;
     755             :   }
     756           0 :   return ConvertExceptionToPromise(cx, xpc::XrayAwareCalleeGlobal(callee),
     757           0 :                                    args.rval());
     758             : }
     759             : 
     760             : static const JSJitInfo create_methodinfo = {
     761             :   { (JSJitGetterOp)create_promiseWrapper },
     762             :   { prototypes::id::CredentialsContainer },
     763             :   { PrototypeTraits<prototypes::id::CredentialsContainer>::Depth },
     764             :   JSJitInfo::Method,
     765             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     766             :   JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
     767             :   false,  /* isInfallible. False in setters. */
     768             :   false,  /* isMovable.  Not relevant for setters. */
     769             :   false, /* isEliminatable.  Not relevant for setters. */
     770             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     771             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     772             :   false,  /* isTypedMethod.  Only relevant for methods. */
     773             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     774             : };
     775             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     776             : static_assert(0 < 1, "There is no slot for us");
     777             : 
     778             : static bool
     779           0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
     780             : {
     781           0 :   mozilla::dom::CredentialsContainer* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::CredentialsContainer>(obj);
     782             :   // We don't want to preserve if we don't have a wrapper, and we
     783             :   // obviously can't preserve if we're not initialized.
     784           0 :   if (self && self->GetWrapperPreserveColor()) {
     785           0 :     PreserveWrapper(self);
     786             :   }
     787           0 :   return true;
     788             : }
     789             : 
     790             : static void
     791           0 : _finalize(js::FreeOp* fop, JSObject* obj)
     792             : {
     793           0 :   mozilla::dom::CredentialsContainer* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::CredentialsContainer>(obj);
     794           0 :   if (self) {
     795           0 :     ClearWrapper(self, self, obj);
     796           0 :     AddForDeferredFinalization<mozilla::dom::CredentialsContainer>(self);
     797             :   }
     798           0 : }
     799             : 
     800             : static void
     801           0 : _objectMoved(JSObject* obj, const JSObject* old)
     802             : {
     803           0 :   mozilla::dom::CredentialsContainer* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::CredentialsContainer>(obj);
     804           0 :   if (self) {
     805           0 :     UpdateWrapper(self, self, obj, old);
     806             :   }
     807           0 : }
     808             : 
     809             : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
     810             : #if defined(__clang__)
     811             : #pragma clang diagnostic push
     812             : #pragma clang diagnostic ignored "-Wmissing-braces"
     813             : #endif
     814             : static const JSFunctionSpec sMethods_specs[] = {
     815             :   JS_FNSPEC("get", GenericPromiseReturningBindingMethod, reinterpret_cast<const JSJitInfo*>(&get_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
     816             :   JS_FNSPEC("create", GenericPromiseReturningBindingMethod, reinterpret_cast<const JSJitInfo*>(&create_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
     817             :   JS_FS_END
     818             : };
     819             : #if defined(__clang__)
     820             : #pragma clang diagnostic pop
     821             : #endif
     822             : 
     823             : static PrefableDisablers sMethods_disablers0 = {
     824             :   true, true, 0, nullptr
     825             : };
     826             : 
     827             : // Can't be const because the pref-enabled boolean needs to be writable
     828             : static Prefable<const JSFunctionSpec> sMethods[] = {
     829             :   { &sMethods_disablers0, &sMethods_specs[0] },
     830             :   { nullptr, nullptr }
     831             : };
     832             : 
     833             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
     834             :     "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
     835             : static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
     836             :     "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
     837             : 
     838             : 
     839             : static uint16_t sNativeProperties_sortedPropertyIndices[2];
     840             : static PropertyInfo sNativeProperties_propertyInfos[2];
     841             : 
     842             : static const NativePropertiesN<1> sNativeProperties = {
     843             :   false, 0,
     844             :   false, 0,
     845             :   true,  0 /* sMethods */,
     846             :   false, 0,
     847             :   false, 0,
     848             :   false, 0,
     849             :   false, 0,
     850             :   -1,
     851             :   2,
     852             :   sNativeProperties_sortedPropertyIndices,
     853             :   {
     854             :     { sMethods, &sNativeProperties_propertyInfos[0] }
     855             :   }
     856             : };
     857             : static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
     858             :     "We have a property info count that is oversized");
     859             : 
     860             : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
     861             :   {
     862             :     "Function",
     863             :     JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
     864             :     &sBoringInterfaceObjectClassClassOps,
     865             :     JS_NULL_CLASS_SPEC,
     866             :     JS_NULL_CLASS_EXT,
     867             :     &sInterfaceObjectClassObjectOps
     868             :   },
     869             :   eInterface,
     870             :   true,
     871             :   prototypes::id::CredentialsContainer,
     872             :   PrototypeTraits<prototypes::id::CredentialsContainer>::Depth,
     873             :   sNativePropertyHooks,
     874             :   "function CredentialsContainer() {\n    [native code]\n}",
     875             :   JS::GetRealmFunctionPrototype
     876             : };
     877             : 
     878             : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
     879             :   {
     880             :     "CredentialsContainerPrototype",
     881             :     JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
     882             :     JS_NULL_CLASS_OPS,
     883             :     JS_NULL_CLASS_SPEC,
     884             :     JS_NULL_CLASS_EXT,
     885             :     JS_NULL_OBJECT_OPS
     886             :   },
     887             :   eInterfacePrototype,
     888             :   false,
     889             :   prototypes::id::CredentialsContainer,
     890             :   PrototypeTraits<prototypes::id::CredentialsContainer>::Depth,
     891             :   sNativePropertyHooks,
     892             :   "[object CredentialsContainerPrototype]",
     893             :   JS::GetRealmObjectPrototype
     894             : };
     895             : 
     896             : bool
     897           0 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
     898             : {
     899             :   static bool sPrefValue;
     900             :   static bool sPrefCacheSetUp = false;
     901           0 :   if (!sPrefCacheSetUp) {
     902           0 :     sPrefCacheSetUp = true;
     903           0 :     Preferences::AddBoolVarCache(&sPrefValue, "security.webauth.webauthn");
     904             :   }
     905             : 
     906           0 :   return sPrefValue &&
     907           0 :          mozilla::dom::IsSecureContextOrObjectIsFromSecureContext(aCx, aObj);
     908             : }
     909             : 
     910             : JSObject*
     911           0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
     912             : {
     913           0 :   return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
     914             : }
     915             : 
     916             : static const js::ClassOps sClassOps = {
     917             :   _addProperty, /* addProperty */
     918             :   nullptr,               /* delProperty */
     919             :   nullptr,               /* getProperty */
     920             :   nullptr,               /* setProperty */
     921             :   nullptr,               /* enumerate */
     922             :   nullptr, /* newEnumerate */
     923             :   nullptr, /* resolve */
     924             :   nullptr, /* mayResolve */
     925             :   _finalize, /* finalize */
     926             :   nullptr, /* call */
     927             :   nullptr,               /* hasInstance */
     928             :   nullptr,               /* construct */
     929             :   nullptr, /* trace */
     930             : };
     931             : 
     932             : static const js::ClassExtension sClassExtension = {
     933             :   nullptr, /* weakmapKeyDelegateOp */
     934             :   _objectMoved /* objectMovedOp */
     935             : };
     936             : 
     937             : static const DOMJSClass sClass = {
     938             :   { "CredentialsContainer",
     939             :     JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
     940             :     &sClassOps,
     941             :     JS_NULL_CLASS_SPEC,
     942             :     &sClassExtension,
     943             :     JS_NULL_OBJECT_OPS
     944             :   },
     945             :   { prototypes::id::CredentialsContainer, 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 },
     946             :   IsBaseOf<nsISupports, mozilla::dom::CredentialsContainer >::value,
     947             :   sNativePropertyHooks,
     948             :   FindAssociatedGlobalForNative<mozilla::dom::CredentialsContainer>::Get,
     949             :   GetProtoObjectHandle,
     950             :   GetCCParticipant<mozilla::dom::CredentialsContainer>::Get()
     951             : };
     952             : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
     953             :               "Must have the right minimal number of reserved slots.");
     954             : static_assert(1 >= 1,
     955             :               "Must have enough reserved slots.");
     956             : 
     957             : const JSClass*
     958           0 : GetJSClass()
     959             : {
     960           0 :   return sClass.ToJSClass();
     961             : }
     962             : 
     963             : bool
     964           0 : Wrap(JSContext* aCx, mozilla::dom::CredentialsContainer* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
     965             : {
     966             :   MOZ_ASSERT(static_cast<mozilla::dom::CredentialsContainer*>(aObject) ==
     967             :              reinterpret_cast<mozilla::dom::CredentialsContainer*>(aObject),
     968             :              "Multiple inheritance for mozilla::dom::CredentialsContainer is broken.");
     969           0 :   MOZ_ASSERT(ToSupportsIsCorrect(aObject));
     970           0 :   MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
     971           0 :   MOZ_ASSERT(!aCache->GetWrapper(),
     972             :              "You should probably not be using Wrap() directly; use "
     973             :              "GetOrCreateDOMReflector instead");
     974             : 
     975           0 :   MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
     976             :              "nsISupports must be on our primary inheritance chain");
     977             : 
     978           0 :   JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
     979           0 :   if (!global) {
     980           0 :     return false;
     981             :   }
     982           0 :   MOZ_ASSERT(JS_IsGlobalObject(global));
     983           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(global));
     984             : 
     985             :   // That might have ended up wrapping us already, due to the wonders
     986             :   // of XBL.  Check for that, and bail out as needed.
     987           0 :   aReflector.set(aCache->GetWrapper());
     988           0 :   if (aReflector) {
     989             : #ifdef DEBUG
     990           0 :     binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
     991             : #endif // DEBUG
     992           0 :     return true;
     993             :   }
     994             : 
     995           0 :   JSAutoCompartment ac(aCx, global);
     996           0 :   JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
     997           0 :   if (!canonicalProto) {
     998           0 :     return false;
     999             :   }
    1000           0 :   JS::Rooted<JSObject*> proto(aCx);
    1001           0 :   if (aGivenProto) {
    1002           0 :     proto = aGivenProto;
    1003             :     // Unfortunately, while aGivenProto was in the compartment of aCx
    1004             :     // coming in, we changed compartments to that of "parent" so may need
    1005             :     // to wrap the proto here.
    1006           0 :     if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
    1007           0 :       if (!JS_WrapObject(aCx, &proto)) {
    1008           0 :         return false;
    1009             :       }
    1010             :     }
    1011             :   } else {
    1012           0 :     proto = canonicalProto;
    1013             :   }
    1014             : 
    1015           0 :   BindingJSObjectCreator<mozilla::dom::CredentialsContainer> creator(aCx);
    1016           0 :   creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
    1017           0 :   if (!aReflector) {
    1018           0 :     return false;
    1019             :   }
    1020             : 
    1021           0 :   aCache->SetWrapper(aReflector);
    1022           0 :   creator.InitializationSucceeded();
    1023             : 
    1024           0 :   MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
    1025             :              aCache->GetWrapperPreserveColor() == aReflector);
    1026             :   // If proto != canonicalProto, we have to preserve our wrapper;
    1027             :   // otherwise we won't be able to properly recreate it later, since
    1028             :   // we won't know what proto to use.  Note that we don't check
    1029             :   // aGivenProto here, since it's entirely possible (and even
    1030             :   // somewhat common) to have a non-null aGivenProto which is the
    1031             :   // same as canonicalProto.
    1032           0 :   if (proto != canonicalProto) {
    1033           0 :     PreserveWrapper(aObject);
    1034             :   }
    1035             : 
    1036           0 :   return true;
    1037             : }
    1038             : 
    1039             : const NativePropertyHooks sNativePropertyHooks[] = { {
    1040             :   nullptr,
    1041             :   nullptr,
    1042             :   nullptr,
    1043             :   { sNativeProperties.Upcast(), nullptr },
    1044             :   prototypes::id::CredentialsContainer,
    1045             :   constructors::id::CredentialsContainer,
    1046             :   nullptr,
    1047             :   &DefaultXrayExpandoObjectClass
    1048             : } };
    1049             : 
    1050             : void
    1051           0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
    1052             : {
    1053           0 :   JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
    1054           0 :   if (!parentProto) {
    1055           0 :     return;
    1056             :   }
    1057             : 
    1058           0 :   JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
    1059           0 :   if (!constructorProto) {
    1060           0 :     return;
    1061             :   }
    1062             : 
    1063             :   static bool sIdsInited = false;
    1064           0 :   if (!sIdsInited && NS_IsMainThread()) {
    1065           0 :     if (!InitIds(aCx, sNativeProperties.Upcast())) {
    1066           0 :       return;
    1067             :     }
    1068           0 :     sIdsInited = true;
    1069             :   }
    1070             : 
    1071           0 :   JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::CredentialsContainer);
    1072           0 :   JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::CredentialsContainer);
    1073           0 :   dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
    1074             :                               &sPrototypeClass.mBase, protoCache,
    1075             :                               constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
    1076             :                               interfaceCache,
    1077             :                               sNativeProperties.Upcast(),
    1078             :                               nullptr,
    1079             :                               "CredentialsContainer", aDefineOnGlobal,
    1080             :                               nullptr,
    1081           0 :                               false);
    1082             : }
    1083             : 
    1084             : JS::Handle<JSObject*>
    1085           0 : GetProtoObjectHandle(JSContext* aCx)
    1086             : {
    1087             :   /* Get the interface prototype object for this class.  This will create the
    1088             :      object as needed. */
    1089           0 :   bool aDefineOnGlobal = true;
    1090             : 
    1091             :   /* Make sure our global is sane.  Hopefully we can remove this sometime */
    1092           0 :   JSObject* global = JS::CurrentGlobalOrNull(aCx);
    1093           0 :   if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
    1094           0 :     return nullptr;
    1095             :   }
    1096             : 
    1097             :   /* Check to see whether the interface objects are already installed */
    1098           0 :   ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
    1099           0 :   if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::CredentialsContainer)) {
    1100           0 :     JS::Rooted<JSObject*> rootedGlobal(aCx, global);
    1101           0 :     CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
    1102             :   }
    1103             : 
    1104             :   /*
    1105             :    * The object might _still_ be null, but that's OK.
    1106             :    *
    1107             :    * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
    1108             :    * traced by TraceProtoAndIfaceCache() and its contents are never
    1109             :    * changed after they have been set.
    1110             :    *
    1111             :    * Calling address() avoids the read read barrier that does gray
    1112             :    * unmarking, but it's not possible for the object to be gray here.
    1113             :    */
    1114             : 
    1115           0 :   const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::CredentialsContainer);
    1116           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
    1117           0 :   return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
    1118             : }
    1119             : 
    1120             : JS::Handle<JSObject*>
    1121           0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
    1122             : {
    1123             :   /* Get the interface object for this class.  This will create the object as
    1124             :      needed. */
    1125             : 
    1126             :   /* Make sure our global is sane.  Hopefully we can remove this sometime */
    1127           0 :   JSObject* global = JS::CurrentGlobalOrNull(aCx);
    1128           0 :   if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
    1129           0 :     return nullptr;
    1130             :   }
    1131             : 
    1132             :   /* Check to see whether the interface objects are already installed */
    1133           0 :   ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
    1134           0 :   if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::CredentialsContainer)) {
    1135           0 :     JS::Rooted<JSObject*> rootedGlobal(aCx, global);
    1136           0 :     CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
    1137             :   }
    1138             : 
    1139             :   /*
    1140             :    * The object might _still_ be null, but that's OK.
    1141             :    *
    1142             :    * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
    1143             :    * traced by TraceProtoAndIfaceCache() and its contents are never
    1144             :    * changed after they have been set.
    1145             :    *
    1146             :    * Calling address() avoids the read read barrier that does gray
    1147             :    * unmarking, but it's not possible for the object to be gray here.
    1148             :    */
    1149             : 
    1150           0 :   const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::CredentialsContainer);
    1151           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
    1152           0 :   return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
    1153             : }
    1154             : 
    1155             : JSObject*
    1156           0 : GetConstructorObject(JSContext* aCx)
    1157             : {
    1158           0 :   return GetConstructorObjectHandle(aCx);
    1159             : }
    1160             : 
    1161             : } // namespace CredentialsContainerBinding
    1162             : 
    1163             : 
    1164             : 
    1165             : } // namespace dom
    1166             : } // namespace mozilla

Generated by: LCOV version 1.13