LCOV - code coverage report
Current view: top level - obj-x86_64-pc-linux-gnu/dom/bindings - OffscreenCanvasBinding.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 2 213 0.9 %
Date: 2017-07-14 16:53:18 Functions: 1 20 5.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.13