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

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

Generated by: LCOV version 1.13