LCOV - code coverage report
Current view: top level - obj-x86_64-pc-linux-gnu/dom/bindings - CryptoBinding.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 22 123 17.9 %
Date: 2017-07-14 16:53:18 Functions: 3 12 25.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* THIS FILE IS AUTOGENERATED FROM Crypto.webidl BY Codegen.py - DO NOT EDIT */
       2             : 
       3             : #include "Crypto.h"
       4             : #include "CryptoBinding.h"
       5             : #include "WrapperFactory.h"
       6             : #include "jsfriendapi.h"
       7             : #include "mozilla/OwningNonNull.h"
       8             : #include "mozilla/dom/BindingUtils.h"
       9             : #include "mozilla/dom/DOMJSClass.h"
      10             : #include "mozilla/dom/NonRefcountedDOMObject.h"
      11             : #include "mozilla/dom/SubtleCrypto.h"
      12             : #include "mozilla/dom/TypedArray.h"
      13             : #include "mozilla/dom/XrayExpandoClass.h"
      14             : #include "nsISupports.h"
      15             : #include "xpcjsid.h"
      16             : 
      17             : namespace mozilla {
      18             : namespace dom {
      19             : 
      20             : namespace CryptoBinding {
      21             : 
      22             : static bool
      23           0 : get_subtle(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Crypto* self, JSJitGetterCallArgs args)
      24             : {
      25           0 :   auto result(StrongOrRawPtr<mozilla::dom::SubtleCrypto>(self->Subtle()));
      26           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
      27           0 :   if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
      28           0 :     MOZ_ASSERT(true || JS_IsExceptionPending(cx));
      29           0 :     return false;
      30             :   }
      31           0 :   return true;
      32             : }
      33             : 
      34             : static const JSJitInfo subtle_getterinfo = {
      35             :   { (JSJitGetterOp)get_subtle },
      36             :   { prototypes::id::Crypto },
      37             :   { PrototypeTraits<prototypes::id::Crypto>::Depth },
      38             :   JSJitInfo::Getter,
      39             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
      40             :   JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
      41             :   false,  /* isInfallible. False in setters. */
      42             :   false,  /* isMovable.  Not relevant for setters. */
      43             :   false, /* isEliminatable.  Not relevant for setters. */
      44             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
      45             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
      46             :   false,  /* isTypedMethod.  Only relevant for methods. */
      47             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
      48             : };
      49             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
      50             : static_assert(0 < 1, "There is no slot for us");
      51             : 
      52             : static bool
      53           0 : getRandomValues(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Crypto* self, const JSJitMethodCallArgs& args)
      54             : {
      55           0 :   if (MOZ_UNLIKELY(args.length() < 1)) {
      56           0 :     return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "Crypto.getRandomValues");
      57             :   }
      58           0 :   RootedTypedArray<ArrayBufferView> arg0(cx);
      59           0 :   if (args[0].isObject()) {
      60           0 :     if (!arg0.Init(&args[0].toObject())) {
      61           0 :       ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of Crypto.getRandomValues", "ArrayBufferView");
      62           0 :       return false;
      63             :     }
      64             :   } else {
      65           0 :     ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of Crypto.getRandomValues");
      66           0 :     return false;
      67             :   }
      68           0 :   binding_detail::FastErrorResult rv;
      69           0 :   JS::Rooted<JSObject*> result(cx);
      70           0 :   self->GetRandomValues(cx, Constify(arg0), &result, rv);
      71           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
      72           0 :     return false;
      73             :   }
      74           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
      75           0 :   JS::ExposeObjectToActiveJS(result);
      76           0 :   args.rval().setObject(*result);
      77           0 :   if (!MaybeWrapNonDOMObjectValue(cx, args.rval())) {
      78           0 :     return false;
      79             :   }
      80           0 :   return true;
      81             : }
      82             : 
      83             : static const JSJitInfo getRandomValues_methodinfo = {
      84             :   { (JSJitGetterOp)getRandomValues },
      85             :   { prototypes::id::Crypto },
      86             :   { PrototypeTraits<prototypes::id::Crypto>::Depth },
      87             :   JSJitInfo::Method,
      88             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
      89             :   JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
      90             :   false,  /* isInfallible. False in setters. */
      91             :   false,  /* isMovable.  Not relevant for setters. */
      92             :   false, /* isEliminatable.  Not relevant for setters. */
      93             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
      94             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
      95             :   false,  /* isTypedMethod.  Only relevant for methods. */
      96             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
      97             : };
      98             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
      99             : static_assert(0 < 1, "There is no slot for us");
     100             : 
     101             : static bool
     102           0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
     103             : {
     104           0 :   mozilla::dom::Crypto* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Crypto>(obj);
     105             :   // We don't want to preserve if we don't have a wrapper, and we
     106             :   // obviously can't preserve if we're not initialized.
     107           0 :   if (self && self->GetWrapperPreserveColor()) {
     108           0 :     PreserveWrapper(self);
     109             :   }
     110           0 :   return true;
     111             : }
     112             : 
     113             : static void
     114           0 : _finalize(js::FreeOp* fop, JSObject* obj)
     115             : {
     116           0 :   mozilla::dom::Crypto* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Crypto>(obj);
     117           0 :   if (self) {
     118           0 :     ClearWrapper(self, self, obj);
     119           0 :     AddForDeferredFinalization<mozilla::dom::Crypto>(self);
     120             :   }
     121           0 : }
     122             : 
     123             : static void
     124           0 : _objectMoved(JSObject* obj, const JSObject* old)
     125             : {
     126           0 :   mozilla::dom::Crypto* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Crypto>(obj);
     127           0 :   if (self) {
     128           0 :     UpdateWrapper(self, self, obj, old);
     129             :   }
     130           0 : }
     131             : 
     132             : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
     133             : #if defined(__clang__)
     134             : #pragma clang diagnostic push
     135             : #pragma clang diagnostic ignored "-Wmissing-braces"
     136             : #endif
     137             : static const JSFunctionSpec sMethods_specs[] = {
     138             :   JS_FNSPEC("getRandomValues", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&getRandomValues_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
     139             :   JS_FS_END,
     140             :   JS_FNSPEC("QueryInterface", QueryInterface, nullptr, 1, 0, nullptr),
     141             :   JS_FS_END
     142             : };
     143             : #if defined(__clang__)
     144             : #pragma clang diagnostic pop
     145             : #endif
     146             : 
     147             : static PrefableDisablers sMethods_disablers2 = {
     148             :   true, false, 0, &WantsQueryInterface<mozilla::dom::Crypto>::Enabled
     149             : };
     150             : 
     151             : // Can't be const because the pref-enabled boolean needs to be writable
     152             : static Prefable<const JSFunctionSpec> sMethods[] = {
     153             :   { nullptr, &sMethods_specs[0] },
     154             :   { &sMethods_disablers2, &sMethods_specs[2] },
     155             :   { nullptr, nullptr }
     156             : };
     157             : 
     158             : static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
     159             :     "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
     160             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
     161             :     "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
     162             : 
     163             : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
     164             : #if defined(__clang__)
     165             : #pragma clang diagnostic push
     166             : #pragma clang diagnostic ignored "-Wmissing-braces"
     167             : #endif
     168             : static const JSPropertySpec sAttributes_specs[] = {
     169             :   { "subtle", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &subtle_getterinfo, nullptr, nullptr },
     170             :   { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
     171             : };
     172             : #if defined(__clang__)
     173             : #pragma clang diagnostic pop
     174             : #endif
     175             : 
     176             : 
     177             : // Can't be const because the pref-enabled boolean needs to be writable
     178             : static Prefable<const JSPropertySpec> sAttributes[] = {
     179             :   { nullptr, &sAttributes_specs[0] },
     180             :   { nullptr, nullptr }
     181             : };
     182             : 
     183             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
     184             :     "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
     185             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
     186             :     "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
     187             : 
     188             : 
     189             : static uint16_t sNativeProperties_sortedPropertyIndices[3];
     190             : static PropertyInfo sNativeProperties_propertyInfos[3];
     191             : 
     192             : static const NativePropertiesN<2> sNativeProperties = {
     193             :   false, 0,
     194             :   false, 0,
     195             :   true,  0 /* sMethods */,
     196             :   true,  1 /* sAttributes */,
     197             :   false, 0,
     198             :   false, 0,
     199             :   false, 0,
     200             :   -1,
     201             :   3,
     202             :   sNativeProperties_sortedPropertyIndices,
     203             :   {
     204             :     { sMethods, &sNativeProperties_propertyInfos[0] },
     205             :     { sAttributes, &sNativeProperties_propertyInfos[2] }
     206             :   }
     207             : };
     208             : static_assert(3 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
     209             :     "We have a property info count that is oversized");
     210             : 
     211             : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
     212             :   {
     213             :     "Function",
     214             :     JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
     215             :     &sBoringInterfaceObjectClassClassOps,
     216             :     JS_NULL_CLASS_SPEC,
     217             :     JS_NULL_CLASS_EXT,
     218             :     &sInterfaceObjectClassObjectOps
     219             :   },
     220             :   eInterface,
     221             :   true,
     222             :   prototypes::id::Crypto,
     223             :   PrototypeTraits<prototypes::id::Crypto>::Depth,
     224             :   sNativePropertyHooks,
     225             :   "function Crypto() {\n    [native code]\n}",
     226             :   JS::GetRealmFunctionPrototype
     227             : };
     228             : 
     229             : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
     230             :   {
     231             :     "CryptoPrototype",
     232             :     JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
     233             :     JS_NULL_CLASS_OPS,
     234             :     JS_NULL_CLASS_SPEC,
     235             :     JS_NULL_CLASS_EXT,
     236             :     JS_NULL_OBJECT_OPS
     237             :   },
     238             :   eInterfacePrototype,
     239             :   false,
     240             :   prototypes::id::Crypto,
     241             :   PrototypeTraits<prototypes::id::Crypto>::Depth,
     242             :   sNativePropertyHooks,
     243             :   "[object CryptoPrototype]",
     244             :   JS::GetRealmObjectPrototype
     245             : };
     246             : 
     247             : JSObject*
     248           0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
     249             : {
     250           0 :   return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
     251             : }
     252             : 
     253             : static const js::ClassOps sClassOps = {
     254             :   _addProperty, /* addProperty */
     255             :   nullptr,               /* delProperty */
     256             :   nullptr,               /* getProperty */
     257             :   nullptr,               /* setProperty */
     258             :   nullptr,               /* enumerate */
     259             :   nullptr, /* newEnumerate */
     260             :   nullptr, /* resolve */
     261             :   nullptr, /* mayResolve */
     262             :   _finalize, /* finalize */
     263             :   nullptr, /* call */
     264             :   nullptr,               /* hasInstance */
     265             :   nullptr,               /* construct */
     266             :   nullptr, /* trace */
     267             : };
     268             : 
     269             : static const js::ClassExtension sClassExtension = {
     270             :   nullptr, /* weakmapKeyDelegateOp */
     271             :   _objectMoved /* objectMovedOp */
     272             : };
     273             : 
     274             : static const DOMJSClass sClass = {
     275             :   { "Crypto",
     276             :     JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
     277             :     &sClassOps,
     278             :     JS_NULL_CLASS_SPEC,
     279             :     &sClassExtension,
     280             :     JS_NULL_OBJECT_OPS
     281             :   },
     282             :   { prototypes::id::Crypto, 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 },
     283             :   IsBaseOf<nsISupports, mozilla::dom::Crypto >::value,
     284             :   sNativePropertyHooks,
     285             :   FindAssociatedGlobalForNative<mozilla::dom::Crypto>::Get,
     286             :   GetProtoObjectHandle,
     287             :   GetCCParticipant<mozilla::dom::Crypto>::Get()
     288             : };
     289             : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
     290             :               "Must have the right minimal number of reserved slots.");
     291             : static_assert(1 >= 1,
     292             :               "Must have enough reserved slots.");
     293             : 
     294             : const JSClass*
     295           0 : GetJSClass()
     296             : {
     297           0 :   return sClass.ToJSClass();
     298             : }
     299             : 
     300             : bool
     301           0 : Wrap(JSContext* aCx, mozilla::dom::Crypto* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
     302             : {
     303             :   MOZ_ASSERT(static_cast<mozilla::dom::Crypto*>(aObject) ==
     304             :              reinterpret_cast<mozilla::dom::Crypto*>(aObject),
     305             :              "Multiple inheritance for mozilla::dom::Crypto is broken.");
     306           0 :   MOZ_ASSERT(ToSupportsIsCorrect(aObject));
     307           0 :   MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
     308           0 :   MOZ_ASSERT(!aCache->GetWrapper(),
     309             :              "You should probably not be using Wrap() directly; use "
     310             :              "GetOrCreateDOMReflector instead");
     311             : 
     312           0 :   MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
     313             :              "nsISupports must be on our primary inheritance chain");
     314             : 
     315           0 :   JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
     316           0 :   if (!global) {
     317           0 :     return false;
     318             :   }
     319           0 :   MOZ_ASSERT(JS_IsGlobalObject(global));
     320           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(global));
     321             : 
     322             :   // That might have ended up wrapping us already, due to the wonders
     323             :   // of XBL.  Check for that, and bail out as needed.
     324           0 :   aReflector.set(aCache->GetWrapper());
     325           0 :   if (aReflector) {
     326             : #ifdef DEBUG
     327           0 :     binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
     328             : #endif // DEBUG
     329           0 :     return true;
     330             :   }
     331             : 
     332           0 :   JSAutoCompartment ac(aCx, global);
     333           0 :   JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
     334           0 :   if (!canonicalProto) {
     335           0 :     return false;
     336             :   }
     337           0 :   JS::Rooted<JSObject*> proto(aCx);
     338           0 :   if (aGivenProto) {
     339           0 :     proto = aGivenProto;
     340             :     // Unfortunately, while aGivenProto was in the compartment of aCx
     341             :     // coming in, we changed compartments to that of "parent" so may need
     342             :     // to wrap the proto here.
     343           0 :     if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
     344           0 :       if (!JS_WrapObject(aCx, &proto)) {
     345           0 :         return false;
     346             :       }
     347             :     }
     348             :   } else {
     349           0 :     proto = canonicalProto;
     350             :   }
     351             : 
     352           0 :   BindingJSObjectCreator<mozilla::dom::Crypto> creator(aCx);
     353           0 :   creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
     354           0 :   if (!aReflector) {
     355           0 :     return false;
     356             :   }
     357             : 
     358           0 :   aCache->SetWrapper(aReflector);
     359           0 :   creator.InitializationSucceeded();
     360             : 
     361           0 :   MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
     362             :              aCache->GetWrapperPreserveColor() == aReflector);
     363             :   // If proto != canonicalProto, we have to preserve our wrapper;
     364             :   // otherwise we won't be able to properly recreate it later, since
     365             :   // we won't know what proto to use.  Note that we don't check
     366             :   // aGivenProto here, since it's entirely possible (and even
     367             :   // somewhat common) to have a non-null aGivenProto which is the
     368             :   // same as canonicalProto.
     369           0 :   if (proto != canonicalProto) {
     370           0 :     PreserveWrapper(aObject);
     371             :   }
     372             : 
     373           0 :   return true;
     374             : }
     375             : 
     376             : const NativePropertyHooks sNativePropertyHooks[] = { {
     377             :   nullptr,
     378             :   nullptr,
     379             :   nullptr,
     380             :   { sNativeProperties.Upcast(), nullptr },
     381             :   prototypes::id::Crypto,
     382             :   constructors::id::Crypto,
     383             :   nullptr,
     384             :   &DefaultXrayExpandoObjectClass
     385             : } };
     386             : 
     387             : void
     388           1 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
     389             : {
     390           2 :   JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
     391           1 :   if (!parentProto) {
     392           0 :     return;
     393             :   }
     394             : 
     395           2 :   JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
     396           1 :   if (!constructorProto) {
     397           0 :     return;
     398             :   }
     399             : 
     400             :   static bool sIdsInited = false;
     401           1 :   if (!sIdsInited && NS_IsMainThread()) {
     402           0 :     if (!InitIds(aCx, sNativeProperties.Upcast())) {
     403           0 :       return;
     404             :     }
     405           0 :     sIdsInited = true;
     406             :   }
     407             : 
     408           1 :   JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::Crypto);
     409           1 :   JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::Crypto);
     410           2 :   dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
     411             :                               &sPrototypeClass.mBase, protoCache,
     412             :                               constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
     413             :                               interfaceCache,
     414             :                               sNativeProperties.Upcast(),
     415             :                               nullptr,
     416             :                               "Crypto", aDefineOnGlobal,
     417             :                               nullptr,
     418           1 :                               false);
     419             : }
     420             : 
     421             : JS::Handle<JSObject*>
     422           0 : GetProtoObjectHandle(JSContext* aCx)
     423             : {
     424             :   /* Get the interface prototype object for this class.  This will create the
     425             :      object as needed. */
     426           0 :   bool aDefineOnGlobal = true;
     427             : 
     428             :   /* Make sure our global is sane.  Hopefully we can remove this sometime */
     429           0 :   JSObject* global = JS::CurrentGlobalOrNull(aCx);
     430           0 :   if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
     431           0 :     return nullptr;
     432             :   }
     433             : 
     434             :   /* Check to see whether the interface objects are already installed */
     435           0 :   ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
     436           0 :   if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::Crypto)) {
     437           0 :     JS::Rooted<JSObject*> rootedGlobal(aCx, global);
     438           0 :     CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
     439             :   }
     440             : 
     441             :   /*
     442             :    * The object might _still_ be null, but that's OK.
     443             :    *
     444             :    * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
     445             :    * traced by TraceProtoAndIfaceCache() and its contents are never
     446             :    * changed after they have been set.
     447             :    *
     448             :    * Calling address() avoids the read read barrier that does gray
     449             :    * unmarking, but it's not possible for the object to be gray here.
     450             :    */
     451             : 
     452           0 :   const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::Crypto);
     453           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
     454           0 :   return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
     455             : }
     456             : 
     457             : JS::Handle<JSObject*>
     458           1 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
     459             : {
     460             :   /* Get the interface object for this class.  This will create the object as
     461             :      needed. */
     462             : 
     463             :   /* Make sure our global is sane.  Hopefully we can remove this sometime */
     464           1 :   JSObject* global = JS::CurrentGlobalOrNull(aCx);
     465           1 :   if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
     466           0 :     return nullptr;
     467             :   }
     468             : 
     469             :   /* Check to see whether the interface objects are already installed */
     470           1 :   ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
     471           1 :   if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::Crypto)) {
     472           2 :     JS::Rooted<JSObject*> rootedGlobal(aCx, global);
     473           1 :     CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
     474             :   }
     475             : 
     476             :   /*
     477             :    * The object might _still_ be null, but that's OK.
     478             :    *
     479             :    * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
     480             :    * traced by TraceProtoAndIfaceCache() and its contents are never
     481             :    * changed after they have been set.
     482             :    *
     483             :    * Calling address() avoids the read read barrier that does gray
     484             :    * unmarking, but it's not possible for the object to be gray here.
     485             :    */
     486             : 
     487           1 :   const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::Crypto);
     488           1 :   MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
     489           1 :   return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
     490             : }
     491             : 
     492             : JSObject*
     493           1 : GetConstructorObject(JSContext* aCx)
     494             : {
     495           1 :   return GetConstructorObjectHandle(aCx);
     496             : }
     497             : 
     498             : } // namespace CryptoBinding
     499             : 
     500             : 
     501             : 
     502             : } // namespace dom
     503             : } // namespace mozilla

Generated by: LCOV version 1.13