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

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

Generated by: LCOV version 1.13