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

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

Generated by: LCOV version 1.13