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

          Line data    Source code
       1             : /* THIS FILE IS AUTOGENERATED FROM SecureElementManager.webidl BY Codegen.py - DO NOT EDIT */
       2             : 
       3             : #include "AtomList.h"
       4             : #include "SecureElementManagerBinding.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/DOMJSClass.h"
      10             : #include "mozilla/dom/NonRefcountedDOMObject.h"
      11             : #include "mozilla/dom/Promise.h"
      12             : #include "mozilla/dom/ToJSValue.h"
      13             : #include "mozilla/dom/XrayExpandoClass.h"
      14             : #include "nsContentUtils.h"
      15             : #include "nsIGlobalObject.h"
      16             : 
      17             : namespace mozilla {
      18             : namespace dom {
      19             : 
      20             : namespace SEManagerBinding {
      21             : 
      22             : static bool
      23           0 : getSEReaders(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SEManager* self, const JSJitMethodCallArgs& args)
      24             : {
      25           0 :   Maybe<JS::Rooted<JSObject*> > unwrappedObj;
      26           0 :   bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
      27           0 :   if (objIsXray) {
      28           0 :     unwrappedObj.emplace(cx, obj);
      29             :   }
      30           0 :   if (objIsXray) {
      31           0 :     unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
      32           0 :     if (!unwrappedObj.ref()) {
      33           0 :       return false;
      34             :     }
      35             :   }
      36           0 :   binding_detail::FastErrorResult rv;
      37           0 :   auto result(StrongOrRawPtr<Promise>(self->GetSEReaders(rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj))));
      38           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
      39           0 :     return false;
      40             :   }
      41           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
      42           0 :   if (!ToJSValue(cx, result, args.rval())) {
      43           0 :     return false;
      44             :   }
      45           0 :   return true;
      46             : }
      47             : 
      48             : static bool
      49           0 : getSEReaders_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SEManager* self, const JSJitMethodCallArgs& args)
      50             : {
      51             :   // Make sure to save the callee before someone maybe messes
      52             :   // with rval().
      53           0 :   JS::Rooted<JSObject*> callee(cx, &args.callee());
      54           0 :   bool ok = getSEReaders(cx, obj, self, args);
      55           0 :   if (ok) {
      56           0 :     return true;
      57             :   }
      58           0 :   return ConvertExceptionToPromise(cx, xpc::XrayAwareCalleeGlobal(callee),
      59           0 :                                    args.rval());
      60             : }
      61             : 
      62             : static const JSJitInfo getSEReaders_methodinfo = {
      63             :   { (JSJitGetterOp)getSEReaders_promiseWrapper },
      64             :   { prototypes::id::SEManager },
      65             :   { PrototypeTraits<prototypes::id::SEManager>::Depth },
      66             :   JSJitInfo::Method,
      67             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
      68             :   JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
      69             :   false,  /* isInfallible. False in setters. */
      70             :   false,  /* isMovable.  Not relevant for setters. */
      71             :   false, /* isEliminatable.  Not relevant for setters. */
      72             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
      73             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
      74             :   false,  /* isTypedMethod.  Only relevant for methods. */
      75             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
      76             : };
      77             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
      78             : static_assert(0 < 1, "There is no slot for us");
      79             : 
      80             : already_AddRefed<SEManager>
      81           0 : ConstructNavigatorObject(JSContext* cx, JS::Handle<JSObject*> obj, ErrorResult& aRv)
      82             : {
      83           0 :   GlobalObject global(cx, obj);
      84           0 :   if (global.Failed()) {
      85           0 :     aRv.Throw(NS_ERROR_FAILURE);
      86           0 :     return nullptr;
      87             :   }
      88           0 :   JS::Rooted<JSObject*> jsImplObj(cx);
      89             :   nsCOMPtr<nsIGlobalObject> globalHolder =
      90           0 :     ConstructJSImplementation("@mozilla.org/secureelement/manager;1", global, &jsImplObj, aRv);
      91           0 :   if (aRv.Failed()) {
      92           0 :     return nullptr;
      93             :   }
      94             :   // Build the C++ implementation.
      95           0 :   RefPtr<SEManager> impl = new SEManager(jsImplObj, globalHolder);
      96           0 :   return impl.forget();
      97             : }
      98             : 
      99             : static bool
     100           0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
     101             : {
     102           0 :   mozilla::dom::SEManager* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::SEManager>(obj);
     103             :   // We don't want to preserve if we don't have a wrapper, and we
     104             :   // obviously can't preserve if we're not initialized.
     105           0 :   if (self && self->GetWrapperPreserveColor()) {
     106           0 :     PreserveWrapper(self);
     107             :   }
     108           0 :   return true;
     109             : }
     110             : 
     111             : static void
     112           0 : _finalize(js::FreeOp* fop, JSObject* obj)
     113             : {
     114           0 :   mozilla::dom::SEManager* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::SEManager>(obj);
     115           0 :   if (self) {
     116           0 :     ClearWrapper(self, self, obj);
     117           0 :     AddForDeferredFinalization<mozilla::dom::SEManager>(self);
     118             :   }
     119           0 : }
     120             : 
     121             : static void
     122           0 : _objectMoved(JSObject* obj, const JSObject* old)
     123             : {
     124           0 :   mozilla::dom::SEManager* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::SEManager>(obj);
     125           0 :   if (self) {
     126           0 :     UpdateWrapper(self, self, obj, old);
     127             :   }
     128           0 : }
     129             : 
     130             : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
     131             : #if defined(__clang__)
     132             : #pragma clang diagnostic push
     133             : #pragma clang diagnostic ignored "-Wmissing-braces"
     134             : #endif
     135             : static const JSFunctionSpec sMethods_specs[] = {
     136             :   JS_FNSPEC("getSEReaders", GenericPromiseReturningBindingMethod, reinterpret_cast<const JSJitInfo*>(&getSEReaders_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
     137             :   JS_FS_END
     138             : };
     139             : #if defined(__clang__)
     140             : #pragma clang diagnostic pop
     141             : #endif
     142             : 
     143             : 
     144             : // Can't be const because the pref-enabled boolean needs to be writable
     145             : static Prefable<const JSFunctionSpec> sMethods[] = {
     146             :   { nullptr, &sMethods_specs[0] },
     147             :   { nullptr, nullptr }
     148             : };
     149             : 
     150             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
     151             :     "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
     152             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
     153             :     "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
     154             : 
     155             : 
     156             : static uint16_t sNativeProperties_sortedPropertyIndices[1];
     157             : static PropertyInfo sNativeProperties_propertyInfos[1];
     158             : 
     159             : static const NativePropertiesN<1> sNativeProperties = {
     160             :   false, 0,
     161             :   false, 0,
     162             :   true,  0 /* sMethods */,
     163             :   false, 0,
     164             :   false, 0,
     165             :   false, 0,
     166             :   false, 0,
     167             :   -1,
     168             :   1,
     169             :   sNativeProperties_sortedPropertyIndices,
     170             :   {
     171             :     { sMethods, &sNativeProperties_propertyInfos[0] }
     172             :   }
     173             : };
     174             : static_assert(1 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
     175             :     "We have a property info count that is oversized");
     176             : 
     177             : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
     178             :   {
     179             :     "SEManagerPrototype",
     180             :     JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
     181             :     JS_NULL_CLASS_OPS,
     182             :     JS_NULL_CLASS_SPEC,
     183             :     JS_NULL_CLASS_EXT,
     184             :     JS_NULL_OBJECT_OPS
     185             :   },
     186             :   eInterfacePrototype,
     187             :   false,
     188             :   prototypes::id::SEManager,
     189             :   PrototypeTraits<prototypes::id::SEManager>::Depth,
     190             :   sNativePropertyHooks,
     191             :   "[object SEManagerPrototype]",
     192             :   JS::GetRealmObjectPrototype
     193             : };
     194             : 
     195             : bool
     196           0 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
     197             : {
     198             :   static bool sPrefValue;
     199             :   static bool sPrefCacheSetUp = false;
     200           0 :   if (!sPrefCacheSetUp) {
     201           0 :     sPrefCacheSetUp = true;
     202           0 :     Preferences::AddBoolVarCache(&sPrefValue, "dom.secureelement.enabled");
     203             :   }
     204             : 
     205           0 :   return sPrefValue &&
     206           0 :          nsContentUtils::ThreadsafeIsSystemCaller(aCx);
     207             : }
     208             : 
     209             : static const js::ClassOps sClassOps = {
     210             :   _addProperty, /* addProperty */
     211             :   nullptr,               /* delProperty */
     212             :   nullptr,               /* getProperty */
     213             :   nullptr,               /* setProperty */
     214             :   nullptr,               /* enumerate */
     215             :   nullptr, /* newEnumerate */
     216             :   nullptr, /* resolve */
     217             :   nullptr, /* mayResolve */
     218             :   _finalize, /* finalize */
     219             :   nullptr, /* call */
     220             :   nullptr,               /* hasInstance */
     221             :   nullptr,               /* construct */
     222             :   nullptr, /* trace */
     223             : };
     224             : 
     225             : static const js::ClassExtension sClassExtension = {
     226             :   nullptr, /* weakmapKeyDelegateOp */
     227             :   _objectMoved /* objectMovedOp */
     228             : };
     229             : 
     230             : static const DOMJSClass sClass = {
     231             :   { "SEManager",
     232             :     JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
     233             :     &sClassOps,
     234             :     JS_NULL_CLASS_SPEC,
     235             :     &sClassExtension,
     236             :     JS_NULL_OBJECT_OPS
     237             :   },
     238             :   { prototypes::id::SEManager, 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 },
     239             :   IsBaseOf<nsISupports, mozilla::dom::SEManager >::value,
     240             :   sNativePropertyHooks,
     241             :   FindAssociatedGlobalForNative<mozilla::dom::SEManager>::Get,
     242             :   GetProtoObjectHandle,
     243             :   GetCCParticipant<mozilla::dom::SEManager>::Get()
     244             : };
     245             : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
     246             :               "Must have the right minimal number of reserved slots.");
     247             : static_assert(1 >= 1,
     248             :               "Must have enough reserved slots.");
     249             : 
     250             : const JSClass*
     251           0 : GetJSClass()
     252             : {
     253           0 :   return sClass.ToJSClass();
     254             : }
     255             : 
     256             : bool
     257           0 : Wrap(JSContext* aCx, mozilla::dom::SEManager* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
     258             : {
     259             :   MOZ_ASSERT(static_cast<mozilla::dom::SEManager*>(aObject) ==
     260             :              reinterpret_cast<mozilla::dom::SEManager*>(aObject),
     261             :              "Multiple inheritance for mozilla::dom::SEManager is broken.");
     262           0 :   MOZ_ASSERT(ToSupportsIsCorrect(aObject));
     263           0 :   MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
     264           0 :   MOZ_ASSERT(!aCache->GetWrapper(),
     265             :              "You should probably not be using Wrap() directly; use "
     266             :              "GetOrCreateDOMReflector instead");
     267             : 
     268           0 :   MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
     269             :              "nsISupports must be on our primary inheritance chain");
     270             : 
     271           0 :   JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
     272           0 :   if (!global) {
     273           0 :     return false;
     274             :   }
     275           0 :   MOZ_ASSERT(JS_IsGlobalObject(global));
     276           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(global));
     277             : 
     278             :   // That might have ended up wrapping us already, due to the wonders
     279             :   // of XBL.  Check for that, and bail out as needed.
     280           0 :   aReflector.set(aCache->GetWrapper());
     281           0 :   if (aReflector) {
     282             : #ifdef DEBUG
     283           0 :     binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
     284             : #endif // DEBUG
     285           0 :     return true;
     286             :   }
     287             : 
     288           0 :   JSAutoCompartment ac(aCx, global);
     289           0 :   JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
     290           0 :   if (!canonicalProto) {
     291           0 :     return false;
     292             :   }
     293           0 :   JS::Rooted<JSObject*> proto(aCx);
     294           0 :   if (aGivenProto) {
     295           0 :     proto = aGivenProto;
     296             :     // Unfortunately, while aGivenProto was in the compartment of aCx
     297             :     // coming in, we changed compartments to that of "parent" so may need
     298             :     // to wrap the proto here.
     299           0 :     if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
     300           0 :       if (!JS_WrapObject(aCx, &proto)) {
     301           0 :         return false;
     302             :       }
     303             :     }
     304             :   } else {
     305           0 :     proto = canonicalProto;
     306             :   }
     307             : 
     308           0 :   BindingJSObjectCreator<mozilla::dom::SEManager> creator(aCx);
     309           0 :   creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
     310           0 :   if (!aReflector) {
     311           0 :     return false;
     312             :   }
     313             : 
     314           0 :   aCache->SetWrapper(aReflector);
     315           0 :   creator.InitializationSucceeded();
     316             : 
     317           0 :   MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
     318             :              aCache->GetWrapperPreserveColor() == aReflector);
     319             :   // If proto != canonicalProto, we have to preserve our wrapper;
     320             :   // otherwise we won't be able to properly recreate it later, since
     321             :   // we won't know what proto to use.  Note that we don't check
     322             :   // aGivenProto here, since it's entirely possible (and even
     323             :   // somewhat common) to have a non-null aGivenProto which is the
     324             :   // same as canonicalProto.
     325           0 :   if (proto != canonicalProto) {
     326           0 :     PreserveWrapper(aObject);
     327             :   }
     328             : 
     329           0 :   return true;
     330             : }
     331             : 
     332             : const NativePropertyHooks sNativePropertyHooks[] = { {
     333             :   nullptr,
     334             :   nullptr,
     335             :   nullptr,
     336             :   { sNativeProperties.Upcast(), nullptr },
     337             :   prototypes::id::SEManager,
     338             :   constructors::id::_ID_Count,
     339             :   nullptr,
     340             :   &DefaultXrayExpandoObjectClass
     341             : } };
     342             : 
     343             : void
     344           0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
     345             : {
     346           0 :   JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
     347           0 :   if (!parentProto) {
     348           0 :     return;
     349             :   }
     350             : 
     351             :   static bool sIdsInited = false;
     352           0 :   if (!sIdsInited && NS_IsMainThread()) {
     353           0 :     if (!InitIds(aCx, sNativeProperties.Upcast())) {
     354           0 :       return;
     355             :     }
     356           0 :     sIdsInited = true;
     357             :   }
     358             : 
     359           0 :   JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::SEManager);
     360           0 :   JS::Heap<JSObject*>* interfaceCache = nullptr;
     361           0 :   dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
     362             :                               &sPrototypeClass.mBase, protoCache,
     363             :                               nullptr, nullptr, 0, nullptr,
     364             :                               interfaceCache,
     365             :                               sNativeProperties.Upcast(),
     366             :                               nullptr,
     367             :                               nullptr, aDefineOnGlobal,
     368             :                               nullptr,
     369           0 :                               false);
     370             : }
     371             : 
     372             : JS::Handle<JSObject*>
     373           0 : GetProtoObjectHandle(JSContext* aCx)
     374             : {
     375             :   /* Get the interface prototype object for this class.  This will create the
     376             :      object as needed. */
     377           0 :   bool aDefineOnGlobal = true;
     378             : 
     379             :   /* Make sure our global is sane.  Hopefully we can remove this sometime */
     380           0 :   JSObject* global = JS::CurrentGlobalOrNull(aCx);
     381           0 :   if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
     382           0 :     return nullptr;
     383             :   }
     384             : 
     385             :   /* Check to see whether the interface objects are already installed */
     386           0 :   ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
     387           0 :   if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::SEManager)) {
     388           0 :     JS::Rooted<JSObject*> rootedGlobal(aCx, global);
     389           0 :     CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
     390             :   }
     391             : 
     392             :   /*
     393             :    * The object might _still_ be null, but that's OK.
     394             :    *
     395             :    * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
     396             :    * traced by TraceProtoAndIfaceCache() and its contents are never
     397             :    * changed after they have been set.
     398             :    *
     399             :    * Calling address() avoids the read read barrier that does gray
     400             :    * unmarking, but it's not possible for the object to be gray here.
     401             :    */
     402             : 
     403           0 :   const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::SEManager);
     404           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
     405           0 :   return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
     406             : }
     407             : 
     408             : } // namespace SEManagerBinding
     409             : 
     410             : 
     411             : 
     412             : already_AddRefed<Promise>
     413           0 : SEManagerJSImpl::GetSEReaders(ErrorResult& aRv, JSCompartment* aCompartment)
     414             : {
     415           0 :   CallSetup s(this, aRv, "SEManager.getSEReaders", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
     416           0 :   JSContext* cx = s.GetContext();
     417           0 :   if (!cx) {
     418           0 :     MOZ_ASSERT(aRv.Failed());
     419           0 :     return nullptr;
     420             :   }
     421           0 :   JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
     422             : 
     423           0 :   JS::Rooted<JS::Value> callable(cx);
     424           0 :   SEManagerAtoms* atomsCache = GetAtomCache<SEManagerAtoms>(cx);
     425           0 :   if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
     426           0 :       !GetCallableProperty(cx, atomsCache->getSEReaders_id, &callable)) {
     427           0 :     aRv.Throw(NS_ERROR_UNEXPECTED);
     428           0 :     return nullptr;
     429             :   }
     430           0 :   JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
     431           0 :   if (!JS::Call(cx, thisValue, callable,
     432           0 :                 JS::HandleValueArray::empty(), &rval)) {
     433           0 :     aRv.NoteJSContextException(cx);
     434           0 :     return nullptr;
     435             :   }
     436           0 :   RefPtr<Promise> rvalDecl;
     437             :   { // Scope for our GlobalObject, FastErrorResult, JSAutoCompartment,
     438             :     // etc.
     439             : 
     440           0 :     JS::Rooted<JSObject*> globalObj(cx, JS::CurrentGlobalOrNull(cx));
     441           0 :     if (!rval.isObject()) {
     442           0 :       aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of SEManager.getSEReaders"));
     443           0 :       return nullptr;
     444             :     }
     445           0 :     JSObject* unwrappedVal = js::CheckedUnwrap(&rval.toObject());
     446           0 :     if (!unwrappedVal) {
     447             :       // A slight lie, but not much of one, for a dead object wrapper.
     448           0 :       aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("return value of SEManager.getSEReaders"));
     449           0 :       return nullptr;
     450             :     }
     451           0 :     globalObj = js::GetGlobalForObjectCrossCompartment(unwrappedVal);
     452           0 :     JSAutoCompartment ac(cx, globalObj);
     453           0 :     GlobalObject promiseGlobal(cx, globalObj);
     454           0 :     if (promiseGlobal.Failed()) {
     455           0 :       aRv.Throw(NS_ERROR_UNEXPECTED);
     456           0 :       return nullptr;
     457             :     }
     458             : 
     459           0 :     JS::Rooted<JS::Value> valueToResolve(cx, rval);
     460           0 :     if (!JS_WrapValue(cx, &valueToResolve)) {
     461           0 :       aRv.Throw(NS_ERROR_UNEXPECTED);
     462           0 :       return nullptr;
     463             :     }
     464           0 :     binding_detail::FastErrorResult promiseRv;
     465             :     nsCOMPtr<nsIGlobalObject> global =
     466           0 :       do_QueryInterface(promiseGlobal.GetAsSupports());
     467           0 :     if (!global) {
     468           0 :       promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED);
     469           0 :       MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
     470           0 :       aRv.Throw(NS_ERROR_UNEXPECTED);
     471           0 :       return nullptr;
     472             :     }
     473           0 :     rvalDecl = Promise::Resolve(global, cx, valueToResolve,
     474           0 :                                     promiseRv);
     475           0 :     if (promiseRv.MaybeSetPendingException(cx)) {
     476           0 :       aRv.Throw(NS_ERROR_UNEXPECTED);
     477           0 :       return nullptr;
     478             :     }
     479             :   }
     480           0 :   return rvalDecl.forget();
     481             : }
     482             : 
     483             : bool
     484           0 : SEManagerJSImpl::InitIds(JSContext* cx, SEManagerAtoms* atomsCache)
     485             : {
     486           0 :   MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
     487             : 
     488             :   // Initialize these in reverse order so that any failure leaves the first one
     489             :   // uninitialized.
     490           0 :   if (!atomsCache->getSEReaders_id.init(cx, "getSEReaders")) {
     491           0 :     return false;
     492             :   }
     493           0 :   return true;
     494             : }
     495             : 
     496             : 
     497             : 
     498             : NS_IMPL_CYCLE_COLLECTION_CLASS(SEManager)
     499           0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(SEManager)
     500           0 :   NS_IMPL_CYCLE_COLLECTION_UNLINK(mImpl)
     501           0 :   NS_IMPL_CYCLE_COLLECTION_UNLINK(mParent)
     502           0 :   NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
     503           0 :   tmp->ClearWeakReferences();
     504           0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_END
     505           0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(SEManager)
     506           0 :   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mImpl)
     507           0 :   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mParent)
     508           0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
     509           0 : NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(SEManager)
     510           0 : NS_IMPL_CYCLE_COLLECTING_ADDREF(SEManager)
     511           0 : NS_IMPL_CYCLE_COLLECTING_RELEASE(SEManager)
     512           0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SEManager)
     513           0 :   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
     514           0 :   NS_INTERFACE_MAP_ENTRY(nsISupports)
     515           0 :   NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
     516           0 : NS_INTERFACE_MAP_END
     517             : 
     518           0 : SEManager::SEManager(JS::Handle<JSObject*> aJSImplObject, nsIGlobalObject* aParent)
     519           0 :   : mImpl(new SEManagerJSImpl(nullptr, aJSImplObject, /* aIncumbentGlobal = */ nullptr)),
     520           0 :     mParent(aParent)
     521             : {
     522           0 : }
     523             : 
     524             : 
     525           0 : SEManager::~SEManager()
     526             : {
     527           0 : }
     528             : 
     529             : nsISupports*
     530           0 : SEManager::GetParentObject() const
     531             : {
     532           0 :   return mParent;
     533             : }
     534             : 
     535             : JSObject*
     536           0 : SEManager::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
     537             : {
     538           0 :   JS::Rooted<JSObject*> obj(aCx, SEManagerBinding::Wrap(aCx, this, aGivenProto));
     539           0 :   if (!obj) {
     540           0 :     return nullptr;
     541             :   }
     542             : 
     543             :   // Now define it on our chrome object
     544           0 :   JSAutoCompartment ac(aCx, mImpl->CallbackOrNull());
     545           0 :   if (!JS_WrapObject(aCx, &obj)) {
     546           0 :     return nullptr;
     547             :   }
     548           0 :   if (!JS_DefineProperty(aCx, mImpl->CallbackOrNull(), "__DOM_IMPL__", obj, 0)) {
     549           0 :     return nullptr;
     550             :   }
     551           0 :   return obj;
     552             : }
     553             : 
     554             : // Return a raw pointer here to avoid refcounting, but make sure it's safe (the object should be kept alive by the callee).
     555             : already_AddRefed<Promise>
     556           0 : SEManager::GetSEReaders(ErrorResult& aRv, JSCompartment* aCompartment)
     557             : {
     558           0 :   return mImpl->GetSEReaders(aRv, aCompartment);
     559             : }
     560             : 
     561             : bool
     562           0 : SEManager::_Create(JSContext* cx, unsigned argc, JS::Value* vp)
     563             : {
     564           0 :   JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
     565           0 :   if (args.length() < 2) {
     566           0 :     return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "SEManager._create");
     567             :   }
     568           0 :   if (!args[0].isObject()) {
     569           0 :     return ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of SEManager._create");
     570             :   }
     571           0 :   if (!args[1].isObject()) {
     572           0 :     return ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of SEManager._create");
     573             :   }
     574             : 
     575             :   // GlobalObject will go through wrappers as needed for us, and
     576             :   // is simpler than the right UnwrapArg incantation.
     577           0 :   GlobalObject global(cx, &args[0].toObject());
     578           0 :   if (global.Failed()) {
     579           0 :     return false;
     580             :   }
     581           0 :   nsCOMPtr<nsIGlobalObject> globalHolder = do_QueryInterface(global.GetAsSupports());
     582           0 :   MOZ_ASSERT(globalHolder);
     583           0 :   JS::Rooted<JSObject*> arg(cx, &args[1].toObject());
     584           0 :   RefPtr<SEManager> impl = new SEManager(arg, globalHolder);
     585           0 :   MOZ_ASSERT(js::IsObjectInContextCompartment(arg, cx));
     586           0 :   return GetOrCreateDOMReflector(cx, impl, args.rval());
     587             : }
     588             : 
     589             : 
     590             : } // namespace dom
     591             : } // namespace mozilla

Generated by: LCOV version 1.13