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

          Line data    Source code
       1             : /* THIS FILE IS AUTOGENERATED FROM BrowserFeedWriter.webidl BY Codegen.py - DO NOT EDIT */
       2             : 
       3             : #include "AtomList.h"
       4             : #include "BrowserFeedWriterBinding.h"
       5             : #include "WrapperFactory.h"
       6             : #include "mozilla/FeedWriterEnabled.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/XrayExpandoClass.h"
      12             : #include "nsContentUtils.h"
      13             : #include "nsIGlobalObject.h"
      14             : 
      15             : namespace mozilla {
      16             : namespace dom {
      17             : 
      18             : namespace BrowserFeedWriterBinding {
      19             : 
      20             : static bool
      21           0 : writeContent(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::BrowserFeedWriter* self, const JSJitMethodCallArgs& args)
      22             : {
      23           0 :   Maybe<JS::Rooted<JSObject*> > unwrappedObj;
      24           0 :   bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
      25           0 :   if (objIsXray) {
      26           0 :     unwrappedObj.emplace(cx, obj);
      27             :   }
      28           0 :   if (objIsXray) {
      29           0 :     unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
      30           0 :     if (!unwrappedObj.ref()) {
      31           0 :       return false;
      32             :     }
      33             :   }
      34           0 :   binding_detail::FastErrorResult rv;
      35           0 :   self->WriteContent(rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj));
      36           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
      37           0 :     return false;
      38             :   }
      39           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
      40           0 :   args.rval().setUndefined();
      41           0 :   return true;
      42             : }
      43             : 
      44             : static const JSJitInfo writeContent_methodinfo = {
      45             :   { (JSJitGetterOp)writeContent },
      46             :   { prototypes::id::BrowserFeedWriter },
      47             :   { PrototypeTraits<prototypes::id::BrowserFeedWriter>::Depth },
      48             :   JSJitInfo::Method,
      49             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
      50             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
      51             :   false,  /* isInfallible. False in setters. */
      52             :   false,  /* isMovable.  Not relevant for setters. */
      53             :   false, /* isEliminatable.  Not relevant for setters. */
      54             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
      55             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
      56             :   false,  /* isTypedMethod.  Only relevant for methods. */
      57             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
      58             : };
      59             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
      60             : static_assert(0 < 1, "There is no slot for us");
      61             : 
      62             : static bool
      63           0 : close(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::BrowserFeedWriter* self, const JSJitMethodCallArgs& args)
      64             : {
      65           0 :   Maybe<JS::Rooted<JSObject*> > unwrappedObj;
      66           0 :   bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
      67           0 :   if (objIsXray) {
      68           0 :     unwrappedObj.emplace(cx, obj);
      69             :   }
      70           0 :   if (objIsXray) {
      71           0 :     unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref());
      72           0 :     if (!unwrappedObj.ref()) {
      73           0 :       return false;
      74             :     }
      75             :   }
      76           0 :   binding_detail::FastErrorResult rv;
      77           0 :   self->Close(rv, js::GetObjectCompartment(unwrappedObj ? *unwrappedObj : obj));
      78           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
      79           0 :     return false;
      80             :   }
      81           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
      82           0 :   args.rval().setUndefined();
      83           0 :   return true;
      84             : }
      85             : 
      86             : static const JSJitInfo close_methodinfo = {
      87             :   { (JSJitGetterOp)close },
      88             :   { prototypes::id::BrowserFeedWriter },
      89             :   { PrototypeTraits<prototypes::id::BrowserFeedWriter>::Depth },
      90             :   JSJitInfo::Method,
      91             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
      92             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
      93             :   false,  /* isInfallible. False in setters. */
      94             :   false,  /* isMovable.  Not relevant for setters. */
      95             :   false, /* isEliminatable.  Not relevant for setters. */
      96             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
      97             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
      98             :   false,  /* isTypedMethod.  Only relevant for methods. */
      99             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     100             : };
     101             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     102             : static_assert(0 < 1, "There is no slot for us");
     103             : 
     104             : static bool
     105           0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
     106             : {
     107           0 :   mozilla::dom::BrowserFeedWriter* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::BrowserFeedWriter>(obj);
     108             :   // We don't want to preserve if we don't have a wrapper, and we
     109             :   // obviously can't preserve if we're not initialized.
     110           0 :   if (self && self->GetWrapperPreserveColor()) {
     111           0 :     PreserveWrapper(self);
     112             :   }
     113           0 :   return true;
     114             : }
     115             : 
     116             : static void
     117           0 : _finalize(js::FreeOp* fop, JSObject* obj)
     118             : {
     119           0 :   mozilla::dom::BrowserFeedWriter* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::BrowserFeedWriter>(obj);
     120           0 :   if (self) {
     121           0 :     ClearWrapper(self, self, obj);
     122           0 :     AddForDeferredFinalization<mozilla::dom::BrowserFeedWriter>(self);
     123             :   }
     124           0 : }
     125             : 
     126             : static void
     127           0 : _objectMoved(JSObject* obj, const JSObject* old)
     128             : {
     129           0 :   mozilla::dom::BrowserFeedWriter* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::BrowserFeedWriter>(obj);
     130           0 :   if (self) {
     131           0 :     UpdateWrapper(self, self, obj, old);
     132             :   }
     133           0 : }
     134             : 
     135             : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
     136             : #if defined(__clang__)
     137             : #pragma clang diagnostic push
     138             : #pragma clang diagnostic ignored "-Wmissing-braces"
     139             : #endif
     140             : static const JSFunctionSpec sChromeStaticMethods_specs[] = {
     141             :   JS_FNSPEC("_create", BrowserFeedWriter::_Create, nullptr, 2, 0, nullptr),
     142             :   JS_FS_END
     143             : };
     144             : #if defined(__clang__)
     145             : #pragma clang diagnostic pop
     146             : #endif
     147             : 
     148             : 
     149             : // Can't be const because the pref-enabled boolean needs to be writable
     150             : static Prefable<const JSFunctionSpec> sChromeStaticMethods[] = {
     151             :   { nullptr, &sChromeStaticMethods_specs[0] },
     152             :   { nullptr, nullptr }
     153             : };
     154             : 
     155             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
     156             :     "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
     157             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
     158             :     "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
     159             : 
     160             : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
     161             : #if defined(__clang__)
     162             : #pragma clang diagnostic push
     163             : #pragma clang diagnostic ignored "-Wmissing-braces"
     164             : #endif
     165             : static const JSFunctionSpec sMethods_specs[] = {
     166             :   JS_FNSPEC("writeContent", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&writeContent_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
     167             :   JS_FNSPEC("close", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&close_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
     168             :   JS_FS_END
     169             : };
     170             : #if defined(__clang__)
     171             : #pragma clang diagnostic pop
     172             : #endif
     173             : 
     174             : 
     175             : // Can't be const because the pref-enabled boolean needs to be writable
     176             : static Prefable<const JSFunctionSpec> sMethods[] = {
     177             :   { nullptr, &sMethods_specs[0] },
     178             :   { nullptr, nullptr }
     179             : };
     180             : 
     181             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
     182             :     "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
     183             : static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
     184             :     "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
     185             : 
     186             : 
     187             : static uint16_t sNativeProperties_sortedPropertyIndices[2];
     188             : static PropertyInfo sNativeProperties_propertyInfos[2];
     189             : 
     190             : static const NativePropertiesN<1> sNativeProperties = {
     191             :   false, 0,
     192             :   false, 0,
     193             :   true,  0 /* sMethods */,
     194             :   false, 0,
     195             :   false, 0,
     196             :   false, 0,
     197             :   false, 0,
     198             :   -1,
     199             :   2,
     200             :   sNativeProperties_sortedPropertyIndices,
     201             :   {
     202             :     { sMethods, &sNativeProperties_propertyInfos[0] }
     203             :   }
     204             : };
     205             : static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
     206             :     "We have a property info count that is oversized");
     207             : 
     208             : static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[1];
     209             : static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[1];
     210             : 
     211             : static const NativePropertiesN<1> sChromeOnlyNativeProperties = {
     212             :   true,  0 /* sChromeStaticMethods */,
     213             :   false, 0,
     214             :   false, 0,
     215             :   false, 0,
     216             :   false, 0,
     217             :   false, 0,
     218             :   false, 0,
     219             :   -1,
     220             :   1,
     221             :   sChromeOnlyNativeProperties_sortedPropertyIndices,
     222             :   {
     223             :     { sChromeStaticMethods, &sChromeOnlyNativeProperties_propertyInfos[0] }
     224             :   }
     225             : };
     226             : static_assert(1 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount),
     227             :     "We have a property info count that is oversized");
     228             : 
     229             : static bool
     230           0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
     231             : {
     232           0 :   JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
     233           0 :   JS::Rooted<JSObject*> obj(cx, &args.callee());
     234           0 :   if (!args.isConstructing()) {
     235             :     // XXXbz wish I could get the name from the callee instead of
     236             :     // Adding more relocations
     237           0 :     return ThrowConstructorWithoutNew(cx, "BrowserFeedWriter");
     238             :   }
     239             : 
     240           0 :   GlobalObject global(cx, obj);
     241           0 :   if (global.Failed()) {
     242           0 :     return false;
     243             :   }
     244             : 
     245           0 :   JS::Rooted<JSObject*> desiredProto(cx);
     246           0 :   if (!GetDesiredProto(cx, args, &desiredProto)) {
     247           0 :     return false;
     248             :   }
     249             : 
     250           0 :   bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
     251           0 :   Maybe<JSAutoCompartment> ac;
     252           0 :   if (objIsXray) {
     253           0 :     obj = js::CheckedUnwrap(obj);
     254           0 :     if (!obj) {
     255           0 :       return false;
     256             :     }
     257           0 :     ac.emplace(cx, obj);
     258           0 :     if (!JS_WrapObject(cx, &desiredProto)) {
     259           0 :       return false;
     260             :     }
     261             :   }
     262           0 :   binding_detail::FastErrorResult rv;
     263           0 :   auto result(StrongOrRawPtr<mozilla::dom::BrowserFeedWriter>(mozilla::dom::BrowserFeedWriter::Constructor(global, cx, rv)));
     264           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     265           0 :     return false;
     266             :   }
     267           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     268             :   static_assert(!IsPointer<decltype(result)>::value,
     269             :                 "NewObject implies that we need to keep the object alive with a strong reference.");
     270           0 :   if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
     271           0 :     MOZ_ASSERT(true || JS_IsExceptionPending(cx));
     272           0 :     return false;
     273             :   }
     274           0 :   return true;
     275             : }
     276             : 
     277             : static const js::ClassOps sInterfaceObjectClassOps = {
     278             :     nullptr,               /* addProperty */
     279             :     nullptr,               /* delProperty */
     280             :     nullptr,               /* getProperty */
     281             :     nullptr,               /* setProperty */
     282             :     nullptr,               /* enumerate */
     283             :     nullptr,               /* newEnumerate */
     284             :     nullptr,               /* resolve */
     285             :     nullptr,               /* mayResolve */
     286             :     nullptr,               /* finalize */
     287             :     _constructor, /* call */
     288             :     nullptr,               /* hasInstance */
     289             :     _constructor, /* construct */
     290             :     nullptr,               /* trace */
     291             : };
     292             : 
     293             : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
     294             :   {
     295             :     "Function",
     296             :     JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
     297             :     &sInterfaceObjectClassOps,
     298             :     JS_NULL_CLASS_SPEC,
     299             :     JS_NULL_CLASS_EXT,
     300             :     &sInterfaceObjectClassObjectOps
     301             :   },
     302             :   eInterface,
     303             :   true,
     304             :   prototypes::id::BrowserFeedWriter,
     305             :   PrototypeTraits<prototypes::id::BrowserFeedWriter>::Depth,
     306             :   sNativePropertyHooks,
     307             :   "function BrowserFeedWriter() {\n    [native code]\n}",
     308             :   JS::GetRealmFunctionPrototype
     309             : };
     310             : 
     311             : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
     312             :   {
     313             :     "BrowserFeedWriterPrototype",
     314             :     JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
     315             :     JS_NULL_CLASS_OPS,
     316             :     JS_NULL_CLASS_SPEC,
     317             :     JS_NULL_CLASS_EXT,
     318             :     JS_NULL_OBJECT_OPS
     319             :   },
     320             :   eInterfacePrototype,
     321             :   false,
     322             :   prototypes::id::BrowserFeedWriter,
     323             :   PrototypeTraits<prototypes::id::BrowserFeedWriter>::Depth,
     324             :   sNativePropertyHooks,
     325             :   "[object BrowserFeedWriterPrototype]",
     326             :   JS::GetRealmObjectPrototype
     327             : };
     328             : 
     329             : bool
     330           0 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
     331             : {
     332           0 :   return mozilla::FeedWriterEnabled::IsEnabled(aCx, aObj);
     333             : }
     334             : 
     335             : JSObject*
     336           0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
     337             : {
     338           0 :   return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
     339             : }
     340             : 
     341             : static const js::ClassOps sClassOps = {
     342             :   _addProperty, /* addProperty */
     343             :   nullptr,               /* delProperty */
     344             :   nullptr,               /* getProperty */
     345             :   nullptr,               /* setProperty */
     346             :   nullptr,               /* enumerate */
     347             :   nullptr, /* newEnumerate */
     348             :   nullptr, /* resolve */
     349             :   nullptr, /* mayResolve */
     350             :   _finalize, /* finalize */
     351             :   nullptr, /* call */
     352             :   nullptr,               /* hasInstance */
     353             :   nullptr,               /* construct */
     354             :   nullptr, /* trace */
     355             : };
     356             : 
     357             : static const js::ClassExtension sClassExtension = {
     358             :   nullptr, /* weakmapKeyDelegateOp */
     359             :   _objectMoved /* objectMovedOp */
     360             : };
     361             : 
     362             : static const DOMJSClass sClass = {
     363             :   { "BrowserFeedWriter",
     364             :     JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
     365             :     &sClassOps,
     366             :     JS_NULL_CLASS_SPEC,
     367             :     &sClassExtension,
     368             :     JS_NULL_OBJECT_OPS
     369             :   },
     370             :   { prototypes::id::BrowserFeedWriter, 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 },
     371             :   IsBaseOf<nsISupports, mozilla::dom::BrowserFeedWriter >::value,
     372             :   sNativePropertyHooks,
     373             :   FindAssociatedGlobalForNative<mozilla::dom::BrowserFeedWriter>::Get,
     374             :   GetProtoObjectHandle,
     375             :   GetCCParticipant<mozilla::dom::BrowserFeedWriter>::Get()
     376             : };
     377             : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
     378             :               "Must have the right minimal number of reserved slots.");
     379             : static_assert(1 >= 1,
     380             :               "Must have enough reserved slots.");
     381             : 
     382             : const JSClass*
     383           0 : GetJSClass()
     384             : {
     385           0 :   return sClass.ToJSClass();
     386             : }
     387             : 
     388             : bool
     389           0 : Wrap(JSContext* aCx, mozilla::dom::BrowserFeedWriter* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
     390             : {
     391             :   MOZ_ASSERT(static_cast<mozilla::dom::BrowserFeedWriter*>(aObject) ==
     392             :              reinterpret_cast<mozilla::dom::BrowserFeedWriter*>(aObject),
     393             :              "Multiple inheritance for mozilla::dom::BrowserFeedWriter is broken.");
     394           0 :   MOZ_ASSERT(ToSupportsIsCorrect(aObject));
     395           0 :   MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
     396           0 :   MOZ_ASSERT(!aCache->GetWrapper(),
     397             :              "You should probably not be using Wrap() directly; use "
     398             :              "GetOrCreateDOMReflector instead");
     399             : 
     400           0 :   MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
     401             :              "nsISupports must be on our primary inheritance chain");
     402             : 
     403           0 :   JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
     404           0 :   if (!global) {
     405           0 :     return false;
     406             :   }
     407           0 :   MOZ_ASSERT(JS_IsGlobalObject(global));
     408           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(global));
     409             : 
     410             :   // That might have ended up wrapping us already, due to the wonders
     411             :   // of XBL.  Check for that, and bail out as needed.
     412           0 :   aReflector.set(aCache->GetWrapper());
     413           0 :   if (aReflector) {
     414             : #ifdef DEBUG
     415           0 :     binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
     416             : #endif // DEBUG
     417           0 :     return true;
     418             :   }
     419             : 
     420           0 :   JSAutoCompartment ac(aCx, global);
     421           0 :   JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
     422           0 :   if (!canonicalProto) {
     423           0 :     return false;
     424             :   }
     425           0 :   JS::Rooted<JSObject*> proto(aCx);
     426           0 :   if (aGivenProto) {
     427           0 :     proto = aGivenProto;
     428             :     // Unfortunately, while aGivenProto was in the compartment of aCx
     429             :     // coming in, we changed compartments to that of "parent" so may need
     430             :     // to wrap the proto here.
     431           0 :     if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
     432           0 :       if (!JS_WrapObject(aCx, &proto)) {
     433           0 :         return false;
     434             :       }
     435             :     }
     436             :   } else {
     437           0 :     proto = canonicalProto;
     438             :   }
     439             : 
     440           0 :   BindingJSObjectCreator<mozilla::dom::BrowserFeedWriter> creator(aCx);
     441           0 :   creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
     442           0 :   if (!aReflector) {
     443           0 :     return false;
     444             :   }
     445             : 
     446           0 :   aCache->SetWrapper(aReflector);
     447           0 :   creator.InitializationSucceeded();
     448             : 
     449           0 :   MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
     450             :              aCache->GetWrapperPreserveColor() == aReflector);
     451             :   // If proto != canonicalProto, we have to preserve our wrapper;
     452             :   // otherwise we won't be able to properly recreate it later, since
     453             :   // we won't know what proto to use.  Note that we don't check
     454             :   // aGivenProto here, since it's entirely possible (and even
     455             :   // somewhat common) to have a non-null aGivenProto which is the
     456             :   // same as canonicalProto.
     457           0 :   if (proto != canonicalProto) {
     458           0 :     PreserveWrapper(aObject);
     459             :   }
     460             : 
     461           0 :   return true;
     462             : }
     463             : 
     464             : const NativePropertyHooks sNativePropertyHooks[] = { {
     465             :   nullptr,
     466             :   nullptr,
     467             :   nullptr,
     468             :   { sNativeProperties.Upcast(), sChromeOnlyNativeProperties.Upcast() },
     469             :   prototypes::id::BrowserFeedWriter,
     470             :   constructors::id::BrowserFeedWriter,
     471             :   nullptr,
     472             :   &DefaultXrayExpandoObjectClass
     473             : } };
     474             : 
     475             : void
     476           0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
     477             : {
     478           0 :   JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
     479           0 :   if (!parentProto) {
     480           0 :     return;
     481             :   }
     482             : 
     483           0 :   JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
     484           0 :   if (!constructorProto) {
     485           0 :     return;
     486             :   }
     487             : 
     488             :   static bool sIdsInited = false;
     489           0 :   if (!sIdsInited && NS_IsMainThread()) {
     490           0 :     if (!InitIds(aCx, sNativeProperties.Upcast())) {
     491           0 :       return;
     492             :     }
     493           0 :     if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) {
     494           0 :       return;
     495             :     }
     496           0 :     sIdsInited = true;
     497             :   }
     498             : 
     499           0 :   JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::BrowserFeedWriter);
     500           0 :   JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::BrowserFeedWriter);
     501           0 :   dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
     502             :                               &sPrototypeClass.mBase, protoCache,
     503             :                               constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
     504             :                               interfaceCache,
     505             :                               sNativeProperties.Upcast(),
     506           0 :                               nsContentUtils::ThreadsafeIsSystemCaller(aCx) ? sChromeOnlyNativeProperties.Upcast() : nullptr,
     507             :                               "BrowserFeedWriter", aDefineOnGlobal,
     508             :                               nullptr,
     509           0 :                               false);
     510             : }
     511             : 
     512             : JS::Handle<JSObject*>
     513           0 : GetProtoObjectHandle(JSContext* aCx)
     514             : {
     515             :   /* Get the interface prototype object for this class.  This will create the
     516             :      object as needed. */
     517           0 :   bool aDefineOnGlobal = true;
     518             : 
     519             :   /* Make sure our global is sane.  Hopefully we can remove this sometime */
     520           0 :   JSObject* global = JS::CurrentGlobalOrNull(aCx);
     521           0 :   if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
     522           0 :     return nullptr;
     523             :   }
     524             : 
     525             :   /* Check to see whether the interface objects are already installed */
     526           0 :   ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
     527           0 :   if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::BrowserFeedWriter)) {
     528           0 :     JS::Rooted<JSObject*> rootedGlobal(aCx, global);
     529           0 :     CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
     530             :   }
     531             : 
     532             :   /*
     533             :    * The object might _still_ be null, but that's OK.
     534             :    *
     535             :    * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
     536             :    * traced by TraceProtoAndIfaceCache() and its contents are never
     537             :    * changed after they have been set.
     538             :    *
     539             :    * Calling address() avoids the read read barrier that does gray
     540             :    * unmarking, but it's not possible for the object to be gray here.
     541             :    */
     542             : 
     543           0 :   const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::BrowserFeedWriter);
     544           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
     545           0 :   return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
     546             : }
     547             : 
     548             : JS::Handle<JSObject*>
     549           0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
     550             : {
     551             :   /* Get the interface object for this class.  This will create the object as
     552             :      needed. */
     553             : 
     554             :   /* Make sure our global is sane.  Hopefully we can remove this sometime */
     555           0 :   JSObject* global = JS::CurrentGlobalOrNull(aCx);
     556           0 :   if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
     557           0 :     return nullptr;
     558             :   }
     559             : 
     560             :   /* Check to see whether the interface objects are already installed */
     561           0 :   ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
     562           0 :   if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::BrowserFeedWriter)) {
     563           0 :     JS::Rooted<JSObject*> rootedGlobal(aCx, global);
     564           0 :     CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
     565             :   }
     566             : 
     567             :   /*
     568             :    * The object might _still_ be null, but that's OK.
     569             :    *
     570             :    * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
     571             :    * traced by TraceProtoAndIfaceCache() and its contents are never
     572             :    * changed after they have been set.
     573             :    *
     574             :    * Calling address() avoids the read read barrier that does gray
     575             :    * unmarking, but it's not possible for the object to be gray here.
     576             :    */
     577             : 
     578           0 :   const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::BrowserFeedWriter);
     579           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
     580           0 :   return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
     581             : }
     582             : 
     583             : JSObject*
     584           0 : GetConstructorObject(JSContext* aCx)
     585             : {
     586           0 :   return GetConstructorObjectHandle(aCx);
     587             : }
     588             : 
     589             : } // namespace BrowserFeedWriterBinding
     590             : 
     591             : 
     592             : 
     593             : void
     594           0 : BrowserFeedWriterJSImpl::WriteContent(ErrorResult& aRv, JSCompartment* aCompartment)
     595             : {
     596           0 :   CallSetup s(this, aRv, "BrowserFeedWriter.writeContent", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
     597           0 :   JSContext* cx = s.GetContext();
     598           0 :   if (!cx) {
     599           0 :     MOZ_ASSERT(aRv.Failed());
     600           0 :     return;
     601             :   }
     602           0 :   JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
     603             : 
     604           0 :   JS::Rooted<JS::Value> callable(cx);
     605           0 :   BrowserFeedWriterAtoms* atomsCache = GetAtomCache<BrowserFeedWriterAtoms>(cx);
     606           0 :   if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
     607           0 :       !GetCallableProperty(cx, atomsCache->writeContent_id, &callable)) {
     608           0 :     aRv.Throw(NS_ERROR_UNEXPECTED);
     609           0 :     return;
     610             :   }
     611           0 :   JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
     612           0 :   if (!JS::Call(cx, thisValue, callable,
     613           0 :                 JS::HandleValueArray::empty(), &rval)) {
     614           0 :     aRv.NoteJSContextException(cx);
     615           0 :     return;
     616             :   }
     617             : }
     618             : 
     619             : void
     620           0 : BrowserFeedWriterJSImpl::Close(ErrorResult& aRv, JSCompartment* aCompartment)
     621             : {
     622           0 :   CallSetup s(this, aRv, "BrowserFeedWriter.close", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
     623           0 :   JSContext* cx = s.GetContext();
     624           0 :   if (!cx) {
     625           0 :     MOZ_ASSERT(aRv.Failed());
     626           0 :     return;
     627             :   }
     628           0 :   JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
     629             : 
     630           0 :   JS::Rooted<JS::Value> callable(cx);
     631           0 :   BrowserFeedWriterAtoms* atomsCache = GetAtomCache<BrowserFeedWriterAtoms>(cx);
     632           0 :   if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
     633           0 :       !GetCallableProperty(cx, atomsCache->close_id, &callable)) {
     634           0 :     aRv.Throw(NS_ERROR_UNEXPECTED);
     635           0 :     return;
     636             :   }
     637           0 :   JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
     638           0 :   if (!JS::Call(cx, thisValue, callable,
     639           0 :                 JS::HandleValueArray::empty(), &rval)) {
     640           0 :     aRv.NoteJSContextException(cx);
     641           0 :     return;
     642             :   }
     643             : }
     644             : 
     645             : void
     646           0 : BrowserFeedWriterJSImpl::__Init(ErrorResult& aRv, JSCompartment* aCompartment)
     647             : {
     648           0 :   CallSetup s(this, aRv, "__init", eRethrowContentExceptions, aCompartment, /* aIsJSImplementedWebIDL = */ true);
     649           0 :   JSContext* cx = s.GetContext();
     650           0 :   if (!cx) {
     651           0 :     MOZ_ASSERT(aRv.Failed());
     652           0 :     return;
     653             :   }
     654           0 :   JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
     655             : 
     656           0 :   JS::Rooted<JS::Value> callable(cx);
     657           0 :   BrowserFeedWriterAtoms* atomsCache = GetAtomCache<BrowserFeedWriterAtoms>(cx);
     658           0 :   if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
     659           0 :       !GetCallableProperty(cx, atomsCache->__init_id, &callable)) {
     660           0 :     aRv.Throw(NS_ERROR_UNEXPECTED);
     661           0 :     return;
     662             :   }
     663           0 :   JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
     664           0 :   if (!JS::Call(cx, thisValue, callable,
     665           0 :                 JS::HandleValueArray::empty(), &rval)) {
     666           0 :     aRv.NoteJSContextException(cx);
     667           0 :     return;
     668             :   }
     669             : }
     670             : 
     671             : bool
     672           0 : BrowserFeedWriterJSImpl::InitIds(JSContext* cx, BrowserFeedWriterAtoms* atomsCache)
     673             : {
     674           0 :   MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
     675             : 
     676             :   // Initialize these in reverse order so that any failure leaves the first one
     677             :   // uninitialized.
     678           0 :   if (!atomsCache->__init_id.init(cx, "__init") ||
     679           0 :       !atomsCache->close_id.init(cx, "close") ||
     680           0 :       !atomsCache->writeContent_id.init(cx, "writeContent")) {
     681           0 :     return false;
     682             :   }
     683           0 :   return true;
     684             : }
     685             : 
     686             : 
     687             : 
     688             : NS_IMPL_CYCLE_COLLECTION_CLASS(BrowserFeedWriter)
     689           0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(BrowserFeedWriter)
     690           0 :   NS_IMPL_CYCLE_COLLECTION_UNLINK(mImpl)
     691           0 :   NS_IMPL_CYCLE_COLLECTION_UNLINK(mParent)
     692           0 :   NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
     693           0 :   tmp->ClearWeakReferences();
     694           0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_END
     695           0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(BrowserFeedWriter)
     696           0 :   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mImpl)
     697           0 :   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mParent)
     698           0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
     699           0 : NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(BrowserFeedWriter)
     700           0 : NS_IMPL_CYCLE_COLLECTING_ADDREF(BrowserFeedWriter)
     701           0 : NS_IMPL_CYCLE_COLLECTING_RELEASE(BrowserFeedWriter)
     702           0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(BrowserFeedWriter)
     703           0 :   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
     704           0 :   NS_INTERFACE_MAP_ENTRY(nsISupports)
     705           0 :   NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
     706           0 : NS_INTERFACE_MAP_END
     707             : 
     708           0 : BrowserFeedWriter::BrowserFeedWriter(JS::Handle<JSObject*> aJSImplObject, nsIGlobalObject* aParent)
     709           0 :   : mImpl(new BrowserFeedWriterJSImpl(nullptr, aJSImplObject, /* aIncumbentGlobal = */ nullptr)),
     710           0 :     mParent(aParent)
     711             : {
     712           0 : }
     713             : 
     714             : 
     715           0 : BrowserFeedWriter::~BrowserFeedWriter()
     716             : {
     717           0 : }
     718             : 
     719             : nsISupports*
     720           0 : BrowserFeedWriter::GetParentObject() const
     721             : {
     722           0 :   return mParent;
     723             : }
     724             : 
     725             : JSObject*
     726           0 : BrowserFeedWriter::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
     727             : {
     728           0 :   JS::Rooted<JSObject*> obj(aCx, BrowserFeedWriterBinding::Wrap(aCx, this, aGivenProto));
     729           0 :   if (!obj) {
     730           0 :     return nullptr;
     731             :   }
     732             : 
     733             :   // Now define it on our chrome object
     734           0 :   JSAutoCompartment ac(aCx, mImpl->CallbackOrNull());
     735           0 :   if (!JS_WrapObject(aCx, &obj)) {
     736           0 :     return nullptr;
     737             :   }
     738           0 :   if (!JS_DefineProperty(aCx, mImpl->CallbackOrNull(), "__DOM_IMPL__", obj, 0)) {
     739           0 :     return nullptr;
     740             :   }
     741           0 :   return obj;
     742             : }
     743             : 
     744             : already_AddRefed<BrowserFeedWriter>
     745           0 : BrowserFeedWriter::Constructor(const GlobalObject& global, JSContext* cx, ErrorResult& aRv)
     746             : {
     747           0 :   JS::Rooted<JSObject*> jsImplObj(cx);
     748             :   nsCOMPtr<nsIGlobalObject> globalHolder =
     749           0 :     ConstructJSImplementation("@mozilla.org/browser/feeds/result-writer;1", global, &jsImplObj, aRv);
     750           0 :   if (aRv.Failed()) {
     751           0 :     return nullptr;
     752             :   }
     753             :   // Build the C++ implementation.
     754           0 :   RefPtr<BrowserFeedWriter> impl = new BrowserFeedWriter(jsImplObj, globalHolder);
     755           0 :   return impl.forget();
     756             : }
     757             : 
     758             : void
     759           0 : BrowserFeedWriter::WriteContent(ErrorResult& aRv, JSCompartment* aCompartment)
     760             : {
     761           0 :   return mImpl->WriteContent(aRv, aCompartment);
     762             : }
     763             : 
     764             : void
     765           0 : BrowserFeedWriter::Close(ErrorResult& aRv, JSCompartment* aCompartment)
     766             : {
     767           0 :   return mImpl->Close(aRv, aCompartment);
     768             : }
     769             : 
     770             : bool
     771           0 : BrowserFeedWriter::_Create(JSContext* cx, unsigned argc, JS::Value* vp)
     772             : {
     773           0 :   JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
     774           0 :   if (args.length() < 2) {
     775           0 :     return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "BrowserFeedWriter._create");
     776             :   }
     777           0 :   if (!args[0].isObject()) {
     778           0 :     return ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of BrowserFeedWriter._create");
     779             :   }
     780           0 :   if (!args[1].isObject()) {
     781           0 :     return ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of BrowserFeedWriter._create");
     782             :   }
     783             : 
     784             :   // GlobalObject will go through wrappers as needed for us, and
     785             :   // is simpler than the right UnwrapArg incantation.
     786           0 :   GlobalObject global(cx, &args[0].toObject());
     787           0 :   if (global.Failed()) {
     788           0 :     return false;
     789             :   }
     790           0 :   nsCOMPtr<nsIGlobalObject> globalHolder = do_QueryInterface(global.GetAsSupports());
     791           0 :   MOZ_ASSERT(globalHolder);
     792           0 :   JS::Rooted<JSObject*> arg(cx, &args[1].toObject());
     793           0 :   RefPtr<BrowserFeedWriter> impl = new BrowserFeedWriter(arg, globalHolder);
     794           0 :   MOZ_ASSERT(js::IsObjectInContextCompartment(arg, cx));
     795           0 :   return GetOrCreateDOMReflector(cx, impl, args.rval());
     796             : }
     797             : 
     798             : 
     799             : } // namespace dom
     800             : } // namespace mozilla

Generated by: LCOV version 1.13