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

          Line data    Source code
       1             : /* THIS FILE IS AUTOGENERATED FROM TCPSocket.webidl BY Codegen.py - DO NOT EDIT */
       2             : 
       3             : #include "AtomList.h"
       4             : #include "EventHandlerBinding.h"
       5             : #include "EventTargetBinding.h"
       6             : #include "TCPServerSocketBinding.h"
       7             : #include "TCPSocket.h"
       8             : #include "TCPSocketBinding.h"
       9             : #include "WrapperFactory.h"
      10             : #include "jsapi.h"
      11             : #include "jsfriendapi.h"
      12             : #include "mozilla/OwningNonNull.h"
      13             : #include "mozilla/dom/BindingUtils.h"
      14             : #include "mozilla/dom/DOMJSClass.h"
      15             : #include "mozilla/dom/NonRefcountedDOMObject.h"
      16             : #include "mozilla/dom/Nullable.h"
      17             : #include "mozilla/dom/PrimitiveConversions.h"
      18             : #include "mozilla/dom/ScriptSettings.h"
      19             : #include "mozilla/dom/SimpleGlobalObject.h"
      20             : #include "mozilla/dom/TCPServerSocket.h"
      21             : #include "mozilla/dom/TCPSocket.h"
      22             : #include "mozilla/dom/TypedArray.h"
      23             : #include "mozilla/dom/XrayExpandoClass.h"
      24             : #include "nsContentUtils.h"
      25             : 
      26             : namespace mozilla {
      27             : namespace dom {
      28             : 
      29             : namespace TCPSocketBinaryTypeValues {
      30             : extern const EnumEntry strings[3] = {
      31             :   {"arraybuffer", 11},
      32             :   {"string", 6},
      33             :   { nullptr, 0 }
      34             : };
      35             : } // namespace TCPSocketBinaryTypeValues
      36             : 
      37             : bool
      38           0 : ToJSValue(JSContext* aCx, TCPSocketBinaryType aArgument, JS::MutableHandle<JS::Value> aValue)
      39             : {
      40           0 :   MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(TCPSocketBinaryTypeValues::strings));
      41             :   JSString* resultStr =
      42           0 :     JS_NewStringCopyN(aCx, TCPSocketBinaryTypeValues::strings[uint32_t(aArgument)].value,
      43           0 :                       TCPSocketBinaryTypeValues::strings[uint32_t(aArgument)].length);
      44           0 :   if (!resultStr) {
      45           0 :     return false;
      46             :   }
      47           0 :   aValue.setString(resultStr);
      48           0 :   return true;
      49             : }
      50             : 
      51             : 
      52             : namespace TCPReadyStateValues {
      53             : extern const EnumEntry strings[5] = {
      54             :   {"connecting", 10},
      55             :   {"open", 4},
      56             :   {"closing", 7},
      57             :   {"closed", 6},
      58             :   { nullptr, 0 }
      59             : };
      60             : } // namespace TCPReadyStateValues
      61             : 
      62             : bool
      63           0 : ToJSValue(JSContext* aCx, TCPReadyState aArgument, JS::MutableHandle<JS::Value> aValue)
      64             : {
      65           0 :   MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(TCPReadyStateValues::strings));
      66             :   JSString* resultStr =
      67           0 :     JS_NewStringCopyN(aCx, TCPReadyStateValues::strings[uint32_t(aArgument)].value,
      68           0 :                       TCPReadyStateValues::strings[uint32_t(aArgument)].length);
      69           0 :   if (!resultStr) {
      70           0 :     return false;
      71             :   }
      72           0 :   aValue.setString(resultStr);
      73           0 :   return true;
      74             : }
      75             : 
      76             : 
      77             : 
      78           0 : SocketOptions::SocketOptions()
      79             : {
      80             :   // Safe to pass a null context if we pass a null value
      81           0 :   Init(nullptr, JS::NullHandleValue);
      82           0 : }
      83             : 
      84             : 
      85             : 
      86             : bool
      87           0 : SocketOptions::InitIds(JSContext* cx, SocketOptionsAtoms* atomsCache)
      88             : {
      89           0 :   MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
      90             : 
      91             :   // Initialize these in reverse order so that any failure leaves the first one
      92             :   // uninitialized.
      93           0 :   if (!atomsCache->useSecureTransport_id.init(cx, "useSecureTransport") ||
      94           0 :       !atomsCache->binaryType_id.init(cx, "binaryType")) {
      95           0 :     return false;
      96             :   }
      97           0 :   return true;
      98             : }
      99             : 
     100             : bool
     101           0 : SocketOptions::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
     102             : {
     103             :   // Passing a null JSContext is OK only if we're initing from null,
     104             :   // Since in that case we will not have to do any property gets
     105             :   // Also evaluate isNullOrUndefined in order to avoid false-positive
     106             :   // checkers by static analysis tools
     107           0 :   MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
     108           0 :   SocketOptionsAtoms* atomsCache = nullptr;
     109           0 :   if (cx) {
     110           0 :     atomsCache = GetAtomCache<SocketOptionsAtoms>(cx);
     111           0 :     if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
     112           0 :       return false;
     113             :     }
     114             :   }
     115             : 
     116           0 :   if (!IsConvertibleToDictionary(val)) {
     117           0 :     return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
     118             :   }
     119             : 
     120           0 :   bool isNull = val.isNullOrUndefined();
     121             :   // We only need these if !isNull, in which case we have |cx|.
     122           0 :   Maybe<JS::Rooted<JSObject *> > object;
     123           0 :   Maybe<JS::Rooted<JS::Value> > temp;
     124           0 :   if (!isNull) {
     125           0 :     MOZ_ASSERT(cx);
     126           0 :     object.emplace(cx, &val.toObject());
     127           0 :     temp.emplace(cx);
     128             :   }
     129           0 :   if (!isNull) {
     130           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->binaryType_id, temp.ptr())) {
     131           0 :       return false;
     132             :     }
     133             :   }
     134           0 :   if (!isNull && !temp->isUndefined()) {
     135             :     {
     136             :       int index;
     137           0 :       if (!FindEnumStringIndex<true>(cx, temp.ref(), TCPSocketBinaryTypeValues::strings, "TCPSocketBinaryType", "'binaryType' member of SocketOptions", &index)) {
     138           0 :         return false;
     139             :       }
     140           0 :       MOZ_ASSERT(index >= 0);
     141           0 :       mBinaryType = static_cast<TCPSocketBinaryType>(index);
     142             :     }
     143             :   } else {
     144           0 :     mBinaryType = TCPSocketBinaryType::String;
     145             :   }
     146           0 :   mIsAnyMemberPresent = true;
     147             : 
     148           0 :   if (!isNull) {
     149           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->useSecureTransport_id, temp.ptr())) {
     150           0 :       return false;
     151             :     }
     152             :   }
     153           0 :   if (!isNull && !temp->isUndefined()) {
     154           0 :     if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mUseSecureTransport)) {
     155           0 :       return false;
     156             :     }
     157             :   } else {
     158           0 :     mUseSecureTransport = false;
     159             :   }
     160           0 :   mIsAnyMemberPresent = true;
     161           0 :   return true;
     162             : }
     163             : 
     164             : bool
     165           0 : SocketOptions::Init(const nsAString& aJSON)
     166             : {
     167           0 :   AutoJSAPI jsapi;
     168           0 :   JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
     169           0 :   if (!cleanGlobal) {
     170           0 :     return false;
     171             :   }
     172           0 :   if (!jsapi.Init(cleanGlobal)) {
     173           0 :     return false;
     174             :   }
     175           0 :   JSContext* cx = jsapi.cx();
     176           0 :   JS::Rooted<JS::Value> json(cx);
     177           0 :   bool ok = ParseJSON(cx, aJSON, &json);
     178           0 :   NS_ENSURE_TRUE(ok, false);
     179           0 :   return Init(cx, json);
     180             : }
     181             : 
     182             : bool
     183           0 : SocketOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
     184             : {
     185           0 :   SocketOptionsAtoms* atomsCache = GetAtomCache<SocketOptionsAtoms>(cx);
     186           0 :   if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
     187           0 :     return false;
     188             :   }
     189             : 
     190           0 :   JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
     191           0 :   if (!obj) {
     192           0 :     return false;
     193             :   }
     194           0 :   rval.set(JS::ObjectValue(*obj));
     195             : 
     196             :   do {
     197             :     // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     198           0 :     JS::Rooted<JS::Value> temp(cx);
     199           0 :     TCPSocketBinaryType const & currentValue = mBinaryType;
     200           0 :     if (!ToJSValue(cx, currentValue, &temp)) {
     201           0 :       return false;
     202             :     }
     203           0 :     if (!JS_DefinePropertyById(cx, obj, atomsCache->binaryType_id, temp, JSPROP_ENUMERATE)) {
     204           0 :       return false;
     205             :     }
     206           0 :     break;
     207             :   } while(0);
     208             : 
     209             :   do {
     210             :     // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     211           0 :     JS::Rooted<JS::Value> temp(cx);
     212           0 :     bool const & currentValue = mUseSecureTransport;
     213           0 :     temp.setBoolean(currentValue);
     214           0 :     if (!JS_DefinePropertyById(cx, obj, atomsCache->useSecureTransport_id, temp, JSPROP_ENUMERATE)) {
     215           0 :       return false;
     216             :     }
     217           0 :     break;
     218             :   } while(0);
     219             : 
     220           0 :   return true;
     221             : }
     222             : 
     223             : bool
     224           0 : SocketOptions::ToJSON(nsAString& aJSON) const
     225             : {
     226           0 :   AutoJSAPI jsapi;
     227           0 :   jsapi.Init();
     228           0 :   JSContext *cx = jsapi.cx();
     229             :   // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
     230             :   // because we'll only be creating objects, in ways that have no
     231             :   // side-effects, followed by a call to JS::ToJSONMaybeSafely,
     232             :   // which likewise guarantees no side-effects for the sorts of
     233             :   // things we will pass it.
     234           0 :   JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
     235           0 :   JS::Rooted<JS::Value> val(cx);
     236           0 :   if (!ToObjectInternal(cx, &val)) {
     237           0 :     return false;
     238             :   }
     239           0 :   JS::Rooted<JSObject*> obj(cx, &val.toObject());
     240           0 :   return StringifyToJSON(cx, obj, aJSON);
     241             : }
     242             : 
     243             : void
     244           0 : SocketOptions::TraceDictionary(JSTracer* trc)
     245             : {
     246           0 : }
     247             : 
     248             : SocketOptions&
     249           0 : SocketOptions::operator=(const SocketOptions& aOther)
     250             : {
     251           0 :   mBinaryType = aOther.mBinaryType;
     252           0 :   mUseSecureTransport = aOther.mUseSecureTransport;
     253           0 :   return *this;
     254             : }
     255             : 
     256             : namespace binding_detail {
     257             : } // namespace binding_detail
     258             : 
     259             : 
     260             : namespace LegacyMozTCPSocketBinding {
     261             : 
     262             : static bool
     263           0 : open(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::LegacyMozTCPSocket* self, const JSJitMethodCallArgs& args)
     264             : {
     265           0 :   if (MOZ_UNLIKELY(args.length() < 2)) {
     266           0 :     return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "LegacyMozTCPSocket.open");
     267             :   }
     268           0 :   binding_detail::FakeString arg0;
     269           0 :   if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
     270           0 :     return false;
     271             :   }
     272             :   uint16_t arg1;
     273           0 :   if (!ValueToPrimitive<uint16_t, eDefault>(cx, args[1], &arg1)) {
     274           0 :     return false;
     275             :   }
     276           0 :   binding_detail::FastSocketOptions arg2;
     277           0 :   if (!arg2.Init(cx, (args.hasDefined(2)) ? args[2] : JS::NullHandleValue,  "Argument 3 of LegacyMozTCPSocket.open", false)) {
     278           0 :     return false;
     279             :   }
     280           0 :   binding_detail::FastErrorResult rv;
     281           0 :   auto result(StrongOrRawPtr<mozilla::dom::TCPSocket>(self->Open(NonNullHelper(Constify(arg0)), arg1, Constify(arg2), rv)));
     282           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     283           0 :     return false;
     284             :   }
     285           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     286           0 :   if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
     287           0 :     MOZ_ASSERT(true || JS_IsExceptionPending(cx));
     288           0 :     return false;
     289             :   }
     290           0 :   return true;
     291             : }
     292             : 
     293             : static const JSJitInfo open_methodinfo = {
     294             :   { (JSJitGetterOp)open },
     295             :   { prototypes::id::LegacyMozTCPSocket },
     296             :   { PrototypeTraits<prototypes::id::LegacyMozTCPSocket>::Depth },
     297             :   JSJitInfo::Method,
     298             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     299             :   JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
     300             :   false,  /* isInfallible. False in setters. */
     301             :   false,  /* isMovable.  Not relevant for setters. */
     302             :   false, /* isEliminatable.  Not relevant for setters. */
     303             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     304             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     305             :   false,  /* isTypedMethod.  Only relevant for methods. */
     306             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     307             : };
     308             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     309             : static_assert(0 < 1, "There is no slot for us");
     310             : 
     311             : static bool
     312           0 : listen(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::LegacyMozTCPSocket* self, const JSJitMethodCallArgs& args)
     313             : {
     314           0 :   if (MOZ_UNLIKELY(args.length() < 1)) {
     315           0 :     return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "LegacyMozTCPSocket.listen");
     316             :   }
     317             :   uint16_t arg0;
     318           0 :   if (!ValueToPrimitive<uint16_t, eDefault>(cx, args[0], &arg0)) {
     319           0 :     return false;
     320             :   }
     321           0 :   binding_detail::FastServerSocketOptions arg1;
     322           0 :   if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue,  "Argument 2 of LegacyMozTCPSocket.listen", false)) {
     323           0 :     return false;
     324             :   }
     325             :   uint16_t arg2;
     326           0 :   if (args.hasDefined(2)) {
     327           0 :     if (!ValueToPrimitive<uint16_t, eDefault>(cx, args[2], &arg2)) {
     328           0 :       return false;
     329             :     }
     330             :   } else {
     331           0 :     arg2 = 0;
     332             :   }
     333           0 :   binding_detail::FastErrorResult rv;
     334           0 :   auto result(StrongOrRawPtr<mozilla::dom::TCPServerSocket>(self->Listen(arg0, Constify(arg1), arg2, rv)));
     335           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     336           0 :     return false;
     337             :   }
     338           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     339           0 :   if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
     340           0 :     MOZ_ASSERT(true || JS_IsExceptionPending(cx));
     341           0 :     return false;
     342             :   }
     343           0 :   return true;
     344             : }
     345             : 
     346             : static const JSJitInfo listen_methodinfo = {
     347             :   { (JSJitGetterOp)listen },
     348             :   { prototypes::id::LegacyMozTCPSocket },
     349             :   { PrototypeTraits<prototypes::id::LegacyMozTCPSocket>::Depth },
     350             :   JSJitInfo::Method,
     351             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     352             :   JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
     353             :   false,  /* isInfallible. False in setters. */
     354             :   false,  /* isMovable.  Not relevant for setters. */
     355             :   false, /* isEliminatable.  Not relevant for setters. */
     356             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     357             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     358             :   false,  /* isTypedMethod.  Only relevant for methods. */
     359             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     360             : };
     361             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     362             : static_assert(0 < 1, "There is no slot for us");
     363             : 
     364             : static void
     365           0 : _finalize(js::FreeOp* fop, JSObject* obj)
     366             : {
     367           0 :   mozilla::dom::LegacyMozTCPSocket* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::LegacyMozTCPSocket>(obj);
     368           0 :   if (self) {
     369           0 :     AddForDeferredFinalization<mozilla::dom::LegacyMozTCPSocket>(self);
     370             :   }
     371           0 : }
     372             : 
     373             : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
     374             : #if defined(__clang__)
     375             : #pragma clang diagnostic push
     376             : #pragma clang diagnostic ignored "-Wmissing-braces"
     377             : #endif
     378             : static const JSFunctionSpec sMethods_specs[] = {
     379             :   JS_FNSPEC("open", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&open_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
     380             :   JS_FNSPEC("listen", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&listen_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
     381             :   JS_FS_END
     382             : };
     383             : #if defined(__clang__)
     384             : #pragma clang diagnostic pop
     385             : #endif
     386             : 
     387             : 
     388             : // Can't be const because the pref-enabled boolean needs to be writable
     389             : static Prefable<const JSFunctionSpec> sMethods[] = {
     390             :   { nullptr, &sMethods_specs[0] },
     391             :   { nullptr, nullptr }
     392             : };
     393             : 
     394             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
     395             :     "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
     396             : static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
     397             :     "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
     398             : 
     399             : 
     400             : static uint16_t sNativeProperties_sortedPropertyIndices[2];
     401             : static PropertyInfo sNativeProperties_propertyInfos[2];
     402             : 
     403             : static const NativePropertiesN<1> sNativeProperties = {
     404             :   false, 0,
     405             :   false, 0,
     406             :   true,  0 /* sMethods */,
     407             :   false, 0,
     408             :   false, 0,
     409             :   false, 0,
     410             :   false, 0,
     411             :   -1,
     412             :   2,
     413             :   sNativeProperties_sortedPropertyIndices,
     414             :   {
     415             :     { sMethods, &sNativeProperties_propertyInfos[0] }
     416             :   }
     417             : };
     418             : static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
     419             :     "We have a property info count that is oversized");
     420             : 
     421             : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
     422             :   {
     423             :     "LegacyMozTCPSocketPrototype",
     424             :     JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
     425             :     JS_NULL_CLASS_OPS,
     426             :     JS_NULL_CLASS_SPEC,
     427             :     JS_NULL_CLASS_EXT,
     428             :     JS_NULL_OBJECT_OPS
     429             :   },
     430             :   eInterfacePrototype,
     431             :   false,
     432             :   prototypes::id::LegacyMozTCPSocket,
     433             :   PrototypeTraits<prototypes::id::LegacyMozTCPSocket>::Depth,
     434             :   sNativePropertyHooks,
     435             :   "[object LegacyMozTCPSocketPrototype]",
     436             :   JS::GetRealmObjectPrototype
     437             : };
     438             : 
     439             : static const js::ClassOps sClassOps = {
     440             :   nullptr, /* addProperty */
     441             :   nullptr,               /* delProperty */
     442             :   nullptr,               /* getProperty */
     443             :   nullptr,               /* setProperty */
     444             :   nullptr,               /* enumerate */
     445             :   nullptr, /* newEnumerate */
     446             :   nullptr, /* resolve */
     447             :   nullptr, /* mayResolve */
     448             :   _finalize, /* finalize */
     449             :   nullptr, /* call */
     450             :   nullptr,               /* hasInstance */
     451             :   nullptr,               /* construct */
     452             :   nullptr, /* trace */
     453             : };
     454             : 
     455             : static const js::ClassExtension sClassExtension = {
     456             :   nullptr, /* weakmapKeyDelegateOp */
     457             :   nullptr /* objectMovedOp */
     458             : };
     459             : 
     460             : static const DOMJSClass sClass = {
     461             :   { "LegacyMozTCPSocket",
     462             :     JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
     463             :     &sClassOps,
     464             :     JS_NULL_CLASS_SPEC,
     465             :     &sClassExtension,
     466             :     JS_NULL_OBJECT_OPS
     467             :   },
     468             :   { prototypes::id::LegacyMozTCPSocket, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
     469             :   IsBaseOf<nsISupports, mozilla::dom::LegacyMozTCPSocket >::value,
     470             :   sNativePropertyHooks,
     471             :   FindAssociatedGlobalForNative<mozilla::dom::LegacyMozTCPSocket>::Get,
     472             :   GetProtoObjectHandle,
     473             :   GetCCParticipant<mozilla::dom::LegacyMozTCPSocket>::Get()
     474             : };
     475             : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
     476             :               "Must have the right minimal number of reserved slots.");
     477             : static_assert(1 >= 1,
     478             :               "Must have enough reserved slots.");
     479             : 
     480             : const JSClass*
     481           0 : GetJSClass()
     482             : {
     483           0 :   return sClass.ToJSClass();
     484             : }
     485             : 
     486             : bool
     487           0 : Wrap(JSContext* aCx, mozilla::dom::LegacyMozTCPSocket* aObject, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
     488             : {
     489             :   MOZ_ASSERT(static_cast<mozilla::dom::LegacyMozTCPSocket*>(aObject) ==
     490             :              reinterpret_cast<mozilla::dom::LegacyMozTCPSocket*>(aObject),
     491             :              "Multiple inheritance for mozilla::dom::LegacyMozTCPSocket is broken.");
     492           0 :   MOZ_ASSERT(ToSupportsIsCorrect(aObject));
     493           0 :   MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
     494             : 
     495           0 :   JS::Rooted<JSObject*> global(aCx, JS::CurrentGlobalOrNull(aCx));
     496           0 :   JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
     497           0 :   if (!canonicalProto) {
     498           0 :     return false;
     499             :   }
     500           0 :   JS::Rooted<JSObject*> proto(aCx);
     501           0 :   if (aGivenProto) {
     502           0 :     proto = aGivenProto;
     503             :     // Unfortunately, while aGivenProto was in the compartment of aCx
     504             :     // coming in, we changed compartments to that of "parent" so may need
     505             :     // to wrap the proto here.
     506           0 :     if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
     507           0 :       if (!JS_WrapObject(aCx, &proto)) {
     508           0 :         return false;
     509             :       }
     510             :     }
     511             :   } else {
     512           0 :     proto = canonicalProto;
     513             :   }
     514             : 
     515           0 :   BindingJSObjectCreator<mozilla::dom::LegacyMozTCPSocket> creator(aCx);
     516           0 :   creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
     517           0 :   if (!aReflector) {
     518           0 :     return false;
     519             :   }
     520             : 
     521             : 
     522             : 
     523           0 :   creator.InitializationSucceeded();
     524           0 :   return true;
     525             : }
     526             : 
     527             : const NativePropertyHooks sNativePropertyHooks[] = { {
     528             :   nullptr,
     529             :   nullptr,
     530             :   nullptr,
     531             :   { sNativeProperties.Upcast(), nullptr },
     532             :   prototypes::id::LegacyMozTCPSocket,
     533             :   constructors::id::_ID_Count,
     534             :   nullptr,
     535             :   &DefaultXrayExpandoObjectClass
     536             : } };
     537             : 
     538             : void
     539           0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
     540             : {
     541           0 :   JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
     542           0 :   if (!parentProto) {
     543           0 :     return;
     544             :   }
     545             : 
     546             :   static bool sIdsInited = false;
     547           0 :   if (!sIdsInited && NS_IsMainThread()) {
     548           0 :     if (!InitIds(aCx, sNativeProperties.Upcast())) {
     549           0 :       return;
     550             :     }
     551           0 :     sIdsInited = true;
     552             :   }
     553             : 
     554           0 :   JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::LegacyMozTCPSocket);
     555           0 :   JS::Heap<JSObject*>* interfaceCache = nullptr;
     556           0 :   dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
     557             :                               &sPrototypeClass.mBase, protoCache,
     558             :                               nullptr, nullptr, 0, nullptr,
     559             :                               interfaceCache,
     560             :                               sNativeProperties.Upcast(),
     561             :                               nullptr,
     562             :                               nullptr, aDefineOnGlobal,
     563             :                               nullptr,
     564           0 :                               false);
     565             : }
     566             : 
     567             : JS::Handle<JSObject*>
     568           0 : GetProtoObjectHandle(JSContext* aCx)
     569             : {
     570             :   /* Get the interface prototype object for this class.  This will create the
     571             :      object as needed. */
     572           0 :   bool aDefineOnGlobal = true;
     573             : 
     574             :   /* Make sure our global is sane.  Hopefully we can remove this sometime */
     575           0 :   JSObject* global = JS::CurrentGlobalOrNull(aCx);
     576           0 :   if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
     577           0 :     return nullptr;
     578             :   }
     579             : 
     580             :   /* Check to see whether the interface objects are already installed */
     581           0 :   ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
     582           0 :   if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::LegacyMozTCPSocket)) {
     583           0 :     JS::Rooted<JSObject*> rootedGlobal(aCx, global);
     584           0 :     CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
     585             :   }
     586             : 
     587             :   /*
     588             :    * The object might _still_ be null, but that's OK.
     589             :    *
     590             :    * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
     591             :    * traced by TraceProtoAndIfaceCache() and its contents are never
     592             :    * changed after they have been set.
     593             :    *
     594             :    * Calling address() avoids the read read barrier that does gray
     595             :    * unmarking, but it's not possible for the object to be gray here.
     596             :    */
     597             : 
     598           0 :   const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::LegacyMozTCPSocket);
     599           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
     600           0 :   return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
     601             : }
     602             : 
     603             : } // namespace LegacyMozTCPSocketBinding
     604             : 
     605             : 
     606             : 
     607             : namespace TCPSocketBinding {
     608             : 
     609             : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventTargetBinding::NativeType>::value,
     610             :               "Can't inherit from an interface with a different ownership model.");
     611             : 
     612             : static bool
     613           0 : upgradeToSecure(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, const JSJitMethodCallArgs& args)
     614             : {
     615           0 :   binding_detail::FastErrorResult rv;
     616           0 :   self->UpgradeToSecure(rv);
     617           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     618           0 :     return false;
     619             :   }
     620           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     621           0 :   args.rval().setUndefined();
     622           0 :   return true;
     623             : }
     624             : 
     625             : static const JSJitInfo upgradeToSecure_methodinfo = {
     626             :   { (JSJitGetterOp)upgradeToSecure },
     627             :   { prototypes::id::TCPSocket },
     628             :   { PrototypeTraits<prototypes::id::TCPSocket>::Depth },
     629             :   JSJitInfo::Method,
     630             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     631             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
     632             :   false,  /* isInfallible. False in setters. */
     633             :   false,  /* isMovable.  Not relevant for setters. */
     634             :   false, /* isEliminatable.  Not relevant for setters. */
     635             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     636             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     637             :   false,  /* isTypedMethod.  Only relevant for methods. */
     638             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     639             : };
     640             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     641             : static_assert(0 < 1, "There is no slot for us");
     642             : 
     643             : static bool
     644           0 : get_host(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, JSJitGetterCallArgs args)
     645             : {
     646           0 :   DOMString result;
     647           0 :   self->GetHost(result);
     648           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     649           0 :   if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
     650           0 :     return false;
     651             :   }
     652           0 :   return true;
     653             : }
     654             : 
     655             : static const JSJitInfo host_getterinfo = {
     656             :   { (JSJitGetterOp)get_host },
     657             :   { prototypes::id::TCPSocket },
     658             :   { PrototypeTraits<prototypes::id::TCPSocket>::Depth },
     659             :   JSJitInfo::Getter,
     660             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     661             :   JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
     662             :   false,  /* isInfallible. False in setters. */
     663             :   false,  /* isMovable.  Not relevant for setters. */
     664             :   false, /* isEliminatable.  Not relevant for setters. */
     665             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     666             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     667             :   false,  /* isTypedMethod.  Only relevant for methods. */
     668             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     669             : };
     670             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     671             : static_assert(0 < 1, "There is no slot for us");
     672             : 
     673             : static bool
     674           0 : get_port(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, JSJitGetterCallArgs args)
     675             : {
     676           0 :   uint16_t result(self->Port());
     677           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     678           0 :   args.rval().setInt32(int32_t(result));
     679           0 :   return true;
     680             : }
     681             : 
     682             : static const JSJitInfo port_getterinfo = {
     683             :   { (JSJitGetterOp)get_port },
     684             :   { prototypes::id::TCPSocket },
     685             :   { PrototypeTraits<prototypes::id::TCPSocket>::Depth },
     686             :   JSJitInfo::Getter,
     687             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     688             :   JSVAL_TYPE_INT32,  /* returnType.  Not relevant for setters. */
     689             :   true,  /* isInfallible. False in setters. */
     690             :   false,  /* isMovable.  Not relevant for setters. */
     691             :   false, /* isEliminatable.  Not relevant for setters. */
     692             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     693             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     694             :   false,  /* isTypedMethod.  Only relevant for methods. */
     695             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     696             : };
     697             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     698             : static_assert(0 < 1, "There is no slot for us");
     699             : 
     700             : static bool
     701           0 : get_ssl(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, JSJitGetterCallArgs args)
     702             : {
     703           0 :   bool result(self->Ssl());
     704           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     705           0 :   args.rval().setBoolean(result);
     706           0 :   return true;
     707             : }
     708             : 
     709             : static const JSJitInfo ssl_getterinfo = {
     710             :   { (JSJitGetterOp)get_ssl },
     711             :   { prototypes::id::TCPSocket },
     712             :   { PrototypeTraits<prototypes::id::TCPSocket>::Depth },
     713             :   JSJitInfo::Getter,
     714             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     715             :   JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
     716             :   true,  /* isInfallible. False in setters. */
     717             :   false,  /* isMovable.  Not relevant for setters. */
     718             :   false, /* isEliminatable.  Not relevant for setters. */
     719             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     720             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     721             :   false,  /* isTypedMethod.  Only relevant for methods. */
     722             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     723             : };
     724             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     725             : static_assert(0 < 1, "There is no slot for us");
     726             : 
     727             : static bool
     728           0 : get_bufferedAmount(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, JSJitGetterCallArgs args)
     729             : {
     730           0 :   uint64_t result(self->BufferedAmount());
     731           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     732           0 :   args.rval().set(JS_NumberValue(double(result)));
     733           0 :   return true;
     734             : }
     735             : 
     736             : static const JSJitInfo bufferedAmount_getterinfo = {
     737             :   { (JSJitGetterOp)get_bufferedAmount },
     738             :   { prototypes::id::TCPSocket },
     739             :   { PrototypeTraits<prototypes::id::TCPSocket>::Depth },
     740             :   JSJitInfo::Getter,
     741             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     742             :   JSVAL_TYPE_DOUBLE,  /* returnType.  Not relevant for setters. */
     743             :   true,  /* isInfallible. False in setters. */
     744             :   false,  /* isMovable.  Not relevant for setters. */
     745             :   false, /* isEliminatable.  Not relevant for setters. */
     746             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     747             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     748             :   false,  /* isTypedMethod.  Only relevant for methods. */
     749             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     750             : };
     751             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     752             : static_assert(0 < 1, "There is no slot for us");
     753             : 
     754             : static bool
     755           0 : suspend(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, const JSJitMethodCallArgs& args)
     756             : {
     757           0 :   self->Suspend();
     758           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     759           0 :   args.rval().setUndefined();
     760           0 :   return true;
     761             : }
     762             : 
     763             : static const JSJitInfo suspend_methodinfo = {
     764             :   { (JSJitGetterOp)suspend },
     765             :   { prototypes::id::TCPSocket },
     766             :   { PrototypeTraits<prototypes::id::TCPSocket>::Depth },
     767             :   JSJitInfo::Method,
     768             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     769             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
     770             :   true,  /* isInfallible. False in setters. */
     771             :   false,  /* isMovable.  Not relevant for setters. */
     772             :   false, /* isEliminatable.  Not relevant for setters. */
     773             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     774             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     775             :   false,  /* isTypedMethod.  Only relevant for methods. */
     776             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     777             : };
     778             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     779             : static_assert(0 < 1, "There is no slot for us");
     780             : 
     781             : static bool
     782           0 : resume(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, const JSJitMethodCallArgs& args)
     783             : {
     784           0 :   binding_detail::FastErrorResult rv;
     785           0 :   self->Resume(rv);
     786           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     787           0 :     return false;
     788             :   }
     789           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     790           0 :   args.rval().setUndefined();
     791           0 :   return true;
     792             : }
     793             : 
     794             : static const JSJitInfo resume_methodinfo = {
     795             :   { (JSJitGetterOp)resume },
     796             :   { prototypes::id::TCPSocket },
     797             :   { PrototypeTraits<prototypes::id::TCPSocket>::Depth },
     798             :   JSJitInfo::Method,
     799             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     800             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
     801             :   false,  /* isInfallible. False in setters. */
     802             :   false,  /* isMovable.  Not relevant for setters. */
     803             :   false, /* isEliminatable.  Not relevant for setters. */
     804             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     805             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     806             :   false,  /* isTypedMethod.  Only relevant for methods. */
     807             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     808             : };
     809             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     810             : static_assert(0 < 1, "There is no slot for us");
     811             : 
     812             : static bool
     813           0 : close(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, const JSJitMethodCallArgs& args)
     814             : {
     815           0 :   self->Close();
     816           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     817           0 :   args.rval().setUndefined();
     818           0 :   return true;
     819             : }
     820             : 
     821             : static const JSJitInfo close_methodinfo = {
     822             :   { (JSJitGetterOp)close },
     823             :   { prototypes::id::TCPSocket },
     824             :   { PrototypeTraits<prototypes::id::TCPSocket>::Depth },
     825             :   JSJitInfo::Method,
     826             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     827             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
     828             :   true,  /* isInfallible. False in setters. */
     829             :   false,  /* isMovable.  Not relevant for setters. */
     830             :   false, /* isEliminatable.  Not relevant for setters. */
     831             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     832             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     833             :   false,  /* isTypedMethod.  Only relevant for methods. */
     834             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     835             : };
     836             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     837             : static_assert(0 < 1, "There is no slot for us");
     838             : 
     839             : static bool
     840           0 : closeImmediately(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, const JSJitMethodCallArgs& args)
     841             : {
     842           0 :   self->CloseImmediately();
     843           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     844           0 :   args.rval().setUndefined();
     845           0 :   return true;
     846             : }
     847             : 
     848             : static const JSJitInfo closeImmediately_methodinfo = {
     849             :   { (JSJitGetterOp)closeImmediately },
     850             :   { prototypes::id::TCPSocket },
     851             :   { PrototypeTraits<prototypes::id::TCPSocket>::Depth },
     852             :   JSJitInfo::Method,
     853             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     854             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
     855             :   true,  /* isInfallible. False in setters. */
     856             :   false,  /* isMovable.  Not relevant for setters. */
     857             :   false, /* isEliminatable.  Not relevant for setters. */
     858             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     859             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     860             :   false,  /* isTypedMethod.  Only relevant for methods. */
     861             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     862             : };
     863             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     864             : static_assert(0 < 1, "There is no slot for us");
     865             : 
     866             : static bool
     867           0 : send(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, const JSJitMethodCallArgs& args)
     868             : {
     869           0 :   unsigned argcount = std::min(args.length(), 3u);
     870           0 :   switch (argcount) {
     871             :     case 1: {
     872           0 :       if (args[0].isObject()) {
     873             :         do {
     874           0 :           RootedTypedArray<ArrayBuffer> arg0(cx);
     875           0 :           if (!arg0.Init(&args[0].toObject())) {
     876           0 :             break;
     877             :           }
     878             :           uint32_t arg1;
     879           0 :           if (args.hasDefined(1)) {
     880           0 :             if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[1], &arg1)) {
     881           0 :               return false;
     882             :             }
     883             :           } else {
     884           0 :             arg1 = 0U;
     885             :           }
     886           0 :           Optional<uint32_t> arg2;
     887           0 :           if (args.hasDefined(2)) {
     888           0 :             arg2.Construct();
     889           0 :             if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[2], &arg2.Value())) {
     890           0 :               return false;
     891             :             }
     892             :           }
     893           0 :           binding_detail::FastErrorResult rv;
     894           0 :           bool result(self->Send(cx, Constify(arg0), arg1, Constify(arg2), rv));
     895           0 :           if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     896           0 :             return false;
     897             :           }
     898           0 :           MOZ_ASSERT(!JS_IsExceptionPending(cx));
     899           0 :           args.rval().setBoolean(result);
     900           0 :           return true;
     901             :         } while (0);
     902             :       }
     903           0 :       nsCString arg0;
     904           0 :       if (!ConvertJSValueToByteString(cx, args[0], false, arg0)) {
     905           0 :         return false;
     906             :       }
     907           0 :       binding_detail::FastErrorResult rv;
     908           0 :       bool result(self->Send(cx, Constify(arg0), rv));
     909           0 :       if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     910           0 :         return false;
     911             :       }
     912           0 :       MOZ_ASSERT(!JS_IsExceptionPending(cx));
     913           0 :       args.rval().setBoolean(result);
     914           0 :       return true;
     915             :       break;
     916             :     }
     917             :     case 2: {
     918             :       MOZ_FALLTHROUGH;
     919             :     }
     920             :     case 3: {
     921           0 :       RootedTypedArray<ArrayBuffer> arg0(cx);
     922           0 :       if (args[0].isObject()) {
     923           0 :         if (!arg0.Init(&args[0].toObject())) {
     924           0 :           ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of TCPSocket.send", "ArrayBuffer");
     925           0 :           return false;
     926             :         }
     927             :       } else {
     928           0 :         ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of TCPSocket.send");
     929           0 :         return false;
     930             :       }
     931             :       uint32_t arg1;
     932           0 :       if (args.hasDefined(1)) {
     933           0 :         if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[1], &arg1)) {
     934           0 :           return false;
     935             :         }
     936             :       } else {
     937           0 :         arg1 = 0U;
     938             :       }
     939           0 :       Optional<uint32_t> arg2;
     940           0 :       if (args.hasDefined(2)) {
     941           0 :         arg2.Construct();
     942           0 :         if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[2], &arg2.Value())) {
     943           0 :           return false;
     944             :         }
     945             :       }
     946           0 :       binding_detail::FastErrorResult rv;
     947           0 :       bool result(self->Send(cx, Constify(arg0), arg1, Constify(arg2), rv));
     948           0 :       if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     949           0 :         return false;
     950             :       }
     951           0 :       MOZ_ASSERT(!JS_IsExceptionPending(cx));
     952           0 :       args.rval().setBoolean(result);
     953           0 :       return true;
     954             :       break;
     955             :     }
     956             :     default: {
     957           0 :       return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "TCPSocket.send");
     958             :       break;
     959             :     }
     960             :   }
     961             :   MOZ_CRASH("We have an always-returning default case");
     962             :   return false;
     963             : }
     964             : 
     965             : static const JSJitInfo send_methodinfo = {
     966             :   { (JSJitGetterOp)send },
     967             :   { prototypes::id::TCPSocket },
     968             :   { PrototypeTraits<prototypes::id::TCPSocket>::Depth },
     969             :   JSJitInfo::Method,
     970             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     971             :   JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
     972             :   false,  /* isInfallible. False in setters. */
     973             :   false,  /* isMovable.  Not relevant for setters. */
     974             :   false, /* isEliminatable.  Not relevant for setters. */
     975             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     976             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     977             :   false,  /* isTypedMethod.  Only relevant for methods. */
     978             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     979             : };
     980             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     981             : static_assert(0 < 1, "There is no slot for us");
     982             : 
     983             : static bool
     984           0 : get_readyState(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, JSJitGetterCallArgs args)
     985             : {
     986           0 :   TCPReadyState result(self->ReadyState());
     987           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     988           0 :   if (!ToJSValue(cx, result, args.rval())) {
     989           0 :     return false;
     990             :   }
     991           0 :   return true;
     992             : }
     993             : 
     994             : static const JSJitInfo readyState_getterinfo = {
     995             :   { (JSJitGetterOp)get_readyState },
     996             :   { prototypes::id::TCPSocket },
     997             :   { PrototypeTraits<prototypes::id::TCPSocket>::Depth },
     998             :   JSJitInfo::Getter,
     999             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
    1000             :   JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
    1001             :   false,  /* isInfallible. False in setters. */
    1002             :   false,  /* isMovable.  Not relevant for setters. */
    1003             :   false, /* isEliminatable.  Not relevant for setters. */
    1004             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
    1005             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
    1006             :   false,  /* isTypedMethod.  Only relevant for methods. */
    1007             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
    1008             : };
    1009             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
    1010             : static_assert(0 < 1, "There is no slot for us");
    1011             : 
    1012             : static bool
    1013           0 : get_binaryType(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, JSJitGetterCallArgs args)
    1014             : {
    1015           0 :   TCPSocketBinaryType result(self->BinaryType());
    1016           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
    1017           0 :   if (!ToJSValue(cx, result, args.rval())) {
    1018           0 :     return false;
    1019             :   }
    1020           0 :   return true;
    1021             : }
    1022             : 
    1023             : static const JSJitInfo binaryType_getterinfo = {
    1024             :   { (JSJitGetterOp)get_binaryType },
    1025             :   { prototypes::id::TCPSocket },
    1026             :   { PrototypeTraits<prototypes::id::TCPSocket>::Depth },
    1027             :   JSJitInfo::Getter,
    1028             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
    1029             :   JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
    1030             :   false,  /* isInfallible. False in setters. */
    1031             :   false,  /* isMovable.  Not relevant for setters. */
    1032             :   false, /* isEliminatable.  Not relevant for setters. */
    1033             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
    1034             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
    1035             :   false,  /* isTypedMethod.  Only relevant for methods. */
    1036             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
    1037             : };
    1038             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
    1039             : static_assert(0 < 1, "There is no slot for us");
    1040             : 
    1041             : static bool
    1042           0 : get_onopen(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, JSJitGetterCallArgs args)
    1043             : {
    1044           0 :   RefPtr<EventHandlerNonNull> result(self->GetOnopen());
    1045           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
    1046           0 :   if (result) {
    1047           0 :     args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
    1048           0 :     if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
    1049           0 :       return false;
    1050             :     }
    1051           0 :     return true;
    1052             :   } else {
    1053           0 :     args.rval().setNull();
    1054           0 :     return true;
    1055             :   }
    1056             : }
    1057             : 
    1058             : static bool
    1059           0 : set_onopen(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, JSJitSetterCallArgs args)
    1060             : {
    1061           0 :   RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
    1062           0 :   if (args[0].isObject()) {
    1063             :     { // scope for tempRoot
    1064           0 :       JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
    1065           0 :       arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
    1066             :     }
    1067             :   } else {
    1068           0 :     arg0 = nullptr;
    1069             :   }
    1070           0 :   self->SetOnopen(Constify(arg0));
    1071           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
    1072             : 
    1073           0 :   return true;
    1074             : }
    1075             : 
    1076             : static const JSJitInfo onopen_getterinfo = {
    1077             :   { (JSJitGetterOp)get_onopen },
    1078             :   { prototypes::id::TCPSocket },
    1079             :   { PrototypeTraits<prototypes::id::TCPSocket>::Depth },
    1080             :   JSJitInfo::Getter,
    1081             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
    1082             :   JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
    1083             :   false,  /* isInfallible. False in setters. */
    1084             :   false,  /* isMovable.  Not relevant for setters. */
    1085             :   false, /* isEliminatable.  Not relevant for setters. */
    1086             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
    1087             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
    1088             :   false,  /* isTypedMethod.  Only relevant for methods. */
    1089             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
    1090             : };
    1091             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
    1092             : static_assert(0 < 1, "There is no slot for us");
    1093             : static const JSJitInfo onopen_setterinfo = {
    1094             :   { (JSJitGetterOp)set_onopen },
    1095             :   { prototypes::id::TCPSocket },
    1096             :   { PrototypeTraits<prototypes::id::TCPSocket>::Depth },
    1097             :   JSJitInfo::Setter,
    1098             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
    1099             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
    1100             :   false,  /* isInfallible. False in setters. */
    1101             :   false,  /* isMovable.  Not relevant for setters. */
    1102             :   false, /* isEliminatable.  Not relevant for setters. */
    1103             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
    1104             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
    1105             :   false,  /* isTypedMethod.  Only relevant for methods. */
    1106             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
    1107             : };
    1108             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
    1109             : static_assert(0 < 1, "There is no slot for us");
    1110             : 
    1111             : static bool
    1112           0 : get_ondrain(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, JSJitGetterCallArgs args)
    1113             : {
    1114           0 :   RefPtr<EventHandlerNonNull> result(self->GetOndrain());
    1115           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
    1116           0 :   if (result) {
    1117           0 :     args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
    1118           0 :     if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
    1119           0 :       return false;
    1120             :     }
    1121           0 :     return true;
    1122             :   } else {
    1123           0 :     args.rval().setNull();
    1124           0 :     return true;
    1125             :   }
    1126             : }
    1127             : 
    1128             : static bool
    1129           0 : set_ondrain(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, JSJitSetterCallArgs args)
    1130             : {
    1131           0 :   RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
    1132           0 :   if (args[0].isObject()) {
    1133             :     { // scope for tempRoot
    1134           0 :       JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
    1135           0 :       arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
    1136             :     }
    1137             :   } else {
    1138           0 :     arg0 = nullptr;
    1139             :   }
    1140           0 :   self->SetOndrain(Constify(arg0));
    1141           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
    1142             : 
    1143           0 :   return true;
    1144             : }
    1145             : 
    1146             : static const JSJitInfo ondrain_getterinfo = {
    1147             :   { (JSJitGetterOp)get_ondrain },
    1148             :   { prototypes::id::TCPSocket },
    1149             :   { PrototypeTraits<prototypes::id::TCPSocket>::Depth },
    1150             :   JSJitInfo::Getter,
    1151             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
    1152             :   JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
    1153             :   false,  /* isInfallible. False in setters. */
    1154             :   false,  /* isMovable.  Not relevant for setters. */
    1155             :   false, /* isEliminatable.  Not relevant for setters. */
    1156             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
    1157             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
    1158             :   false,  /* isTypedMethod.  Only relevant for methods. */
    1159             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
    1160             : };
    1161             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
    1162             : static_assert(0 < 1, "There is no slot for us");
    1163             : static const JSJitInfo ondrain_setterinfo = {
    1164             :   { (JSJitGetterOp)set_ondrain },
    1165             :   { prototypes::id::TCPSocket },
    1166             :   { PrototypeTraits<prototypes::id::TCPSocket>::Depth },
    1167             :   JSJitInfo::Setter,
    1168             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
    1169             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
    1170             :   false,  /* isInfallible. False in setters. */
    1171             :   false,  /* isMovable.  Not relevant for setters. */
    1172             :   false, /* isEliminatable.  Not relevant for setters. */
    1173             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
    1174             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
    1175             :   false,  /* isTypedMethod.  Only relevant for methods. */
    1176             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
    1177             : };
    1178             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
    1179             : static_assert(0 < 1, "There is no slot for us");
    1180             : 
    1181             : static bool
    1182           0 : get_ondata(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, JSJitGetterCallArgs args)
    1183             : {
    1184           0 :   RefPtr<EventHandlerNonNull> result(self->GetOndata());
    1185           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
    1186           0 :   if (result) {
    1187           0 :     args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
    1188           0 :     if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
    1189           0 :       return false;
    1190             :     }
    1191           0 :     return true;
    1192             :   } else {
    1193           0 :     args.rval().setNull();
    1194           0 :     return true;
    1195             :   }
    1196             : }
    1197             : 
    1198             : static bool
    1199           0 : set_ondata(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, JSJitSetterCallArgs args)
    1200             : {
    1201           0 :   RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
    1202           0 :   if (args[0].isObject()) {
    1203             :     { // scope for tempRoot
    1204           0 :       JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
    1205           0 :       arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
    1206             :     }
    1207             :   } else {
    1208           0 :     arg0 = nullptr;
    1209             :   }
    1210           0 :   self->SetOndata(Constify(arg0));
    1211           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
    1212             : 
    1213           0 :   return true;
    1214             : }
    1215             : 
    1216             : static const JSJitInfo ondata_getterinfo = {
    1217             :   { (JSJitGetterOp)get_ondata },
    1218             :   { prototypes::id::TCPSocket },
    1219             :   { PrototypeTraits<prototypes::id::TCPSocket>::Depth },
    1220             :   JSJitInfo::Getter,
    1221             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
    1222             :   JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
    1223             :   false,  /* isInfallible. False in setters. */
    1224             :   false,  /* isMovable.  Not relevant for setters. */
    1225             :   false, /* isEliminatable.  Not relevant for setters. */
    1226             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
    1227             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
    1228             :   false,  /* isTypedMethod.  Only relevant for methods. */
    1229             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
    1230             : };
    1231             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
    1232             : static_assert(0 < 1, "There is no slot for us");
    1233             : static const JSJitInfo ondata_setterinfo = {
    1234             :   { (JSJitGetterOp)set_ondata },
    1235             :   { prototypes::id::TCPSocket },
    1236             :   { PrototypeTraits<prototypes::id::TCPSocket>::Depth },
    1237             :   JSJitInfo::Setter,
    1238             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
    1239             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
    1240             :   false,  /* isInfallible. False in setters. */
    1241             :   false,  /* isMovable.  Not relevant for setters. */
    1242             :   false, /* isEliminatable.  Not relevant for setters. */
    1243             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
    1244             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
    1245             :   false,  /* isTypedMethod.  Only relevant for methods. */
    1246             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
    1247             : };
    1248             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
    1249             : static_assert(0 < 1, "There is no slot for us");
    1250             : 
    1251             : static bool
    1252           0 : get_onerror(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, JSJitGetterCallArgs args)
    1253             : {
    1254           0 :   RefPtr<EventHandlerNonNull> result(self->GetOnerror());
    1255           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
    1256           0 :   if (result) {
    1257           0 :     args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
    1258           0 :     if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
    1259           0 :       return false;
    1260             :     }
    1261           0 :     return true;
    1262             :   } else {
    1263           0 :     args.rval().setNull();
    1264           0 :     return true;
    1265             :   }
    1266             : }
    1267             : 
    1268             : static bool
    1269           0 : set_onerror(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, JSJitSetterCallArgs args)
    1270             : {
    1271           0 :   RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
    1272           0 :   if (args[0].isObject()) {
    1273             :     { // scope for tempRoot
    1274           0 :       JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
    1275           0 :       arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
    1276             :     }
    1277             :   } else {
    1278           0 :     arg0 = nullptr;
    1279             :   }
    1280           0 :   self->SetOnerror(Constify(arg0));
    1281           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
    1282             : 
    1283           0 :   return true;
    1284             : }
    1285             : 
    1286             : static const JSJitInfo onerror_getterinfo = {
    1287             :   { (JSJitGetterOp)get_onerror },
    1288             :   { prototypes::id::TCPSocket },
    1289             :   { PrototypeTraits<prototypes::id::TCPSocket>::Depth },
    1290             :   JSJitInfo::Getter,
    1291             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
    1292             :   JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
    1293             :   false,  /* isInfallible. False in setters. */
    1294             :   false,  /* isMovable.  Not relevant for setters. */
    1295             :   false, /* isEliminatable.  Not relevant for setters. */
    1296             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
    1297             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
    1298             :   false,  /* isTypedMethod.  Only relevant for methods. */
    1299             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
    1300             : };
    1301             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
    1302             : static_assert(0 < 1, "There is no slot for us");
    1303             : static const JSJitInfo onerror_setterinfo = {
    1304             :   { (JSJitGetterOp)set_onerror },
    1305             :   { prototypes::id::TCPSocket },
    1306             :   { PrototypeTraits<prototypes::id::TCPSocket>::Depth },
    1307             :   JSJitInfo::Setter,
    1308             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
    1309             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
    1310             :   false,  /* isInfallible. False in setters. */
    1311             :   false,  /* isMovable.  Not relevant for setters. */
    1312             :   false, /* isEliminatable.  Not relevant for setters. */
    1313             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
    1314             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
    1315             :   false,  /* isTypedMethod.  Only relevant for methods. */
    1316             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
    1317             : };
    1318             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
    1319             : static_assert(0 < 1, "There is no slot for us");
    1320             : 
    1321             : static bool
    1322           0 : get_onclose(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, JSJitGetterCallArgs args)
    1323             : {
    1324           0 :   RefPtr<EventHandlerNonNull> result(self->GetOnclose());
    1325           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
    1326           0 :   if (result) {
    1327           0 :     args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
    1328           0 :     if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
    1329           0 :       return false;
    1330             :     }
    1331           0 :     return true;
    1332             :   } else {
    1333           0 :     args.rval().setNull();
    1334           0 :     return true;
    1335             :   }
    1336             : }
    1337             : 
    1338             : static bool
    1339           0 : set_onclose(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, JSJitSetterCallArgs args)
    1340             : {
    1341           0 :   RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
    1342           0 :   if (args[0].isObject()) {
    1343             :     { // scope for tempRoot
    1344           0 :       JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
    1345           0 :       arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
    1346             :     }
    1347             :   } else {
    1348           0 :     arg0 = nullptr;
    1349             :   }
    1350           0 :   self->SetOnclose(Constify(arg0));
    1351           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
    1352             : 
    1353           0 :   return true;
    1354             : }
    1355             : 
    1356             : static const JSJitInfo onclose_getterinfo = {
    1357             :   { (JSJitGetterOp)get_onclose },
    1358             :   { prototypes::id::TCPSocket },
    1359             :   { PrototypeTraits<prototypes::id::TCPSocket>::Depth },
    1360             :   JSJitInfo::Getter,
    1361             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
    1362             :   JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
    1363             :   false,  /* isInfallible. False in setters. */
    1364             :   false,  /* isMovable.  Not relevant for setters. */
    1365             :   false, /* isEliminatable.  Not relevant for setters. */
    1366             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
    1367             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
    1368             :   false,  /* isTypedMethod.  Only relevant for methods. */
    1369             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
    1370             : };
    1371             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
    1372             : static_assert(0 < 1, "There is no slot for us");
    1373             : static const JSJitInfo onclose_setterinfo = {
    1374             :   { (JSJitGetterOp)set_onclose },
    1375             :   { prototypes::id::TCPSocket },
    1376             :   { PrototypeTraits<prototypes::id::TCPSocket>::Depth },
    1377             :   JSJitInfo::Setter,
    1378             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
    1379             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
    1380             :   false,  /* isInfallible. False in setters. */
    1381             :   false,  /* isMovable.  Not relevant for setters. */
    1382             :   false, /* isEliminatable.  Not relevant for setters. */
    1383             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
    1384             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
    1385             :   false,  /* isTypedMethod.  Only relevant for methods. */
    1386             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
    1387             : };
    1388             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
    1389             : static_assert(0 < 1, "There is no slot for us");
    1390             : 
    1391             : static bool
    1392           0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
    1393             : {
    1394           0 :   mozilla::dom::TCPSocket* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TCPSocket>(obj);
    1395             :   // We don't want to preserve if we don't have a wrapper, and we
    1396             :   // obviously can't preserve if we're not initialized.
    1397           0 :   if (self && self->GetWrapperPreserveColor()) {
    1398           0 :     PreserveWrapper(self);
    1399             :   }
    1400           0 :   return true;
    1401             : }
    1402             : 
    1403             : static void
    1404           0 : _finalize(js::FreeOp* fop, JSObject* obj)
    1405             : {
    1406           0 :   mozilla::dom::TCPSocket* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TCPSocket>(obj);
    1407           0 :   if (self) {
    1408           0 :     ClearWrapper(self, self, obj);
    1409           0 :     AddForDeferredFinalization<mozilla::dom::TCPSocket>(self);
    1410             :   }
    1411           0 : }
    1412             : 
    1413             : static void
    1414           0 : _objectMoved(JSObject* obj, const JSObject* old)
    1415             : {
    1416           0 :   mozilla::dom::TCPSocket* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TCPSocket>(obj);
    1417           0 :   if (self) {
    1418           0 :     UpdateWrapper(self, self, obj, old);
    1419             :   }
    1420           0 : }
    1421             : 
    1422             : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
    1423             : #if defined(__clang__)
    1424             : #pragma clang diagnostic push
    1425             : #pragma clang diagnostic ignored "-Wmissing-braces"
    1426             : #endif
    1427             : static const JSFunctionSpec sMethods_specs[] = {
    1428             :   JS_FNSPEC("upgradeToSecure", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&upgradeToSecure_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
    1429             :   JS_FNSPEC("suspend", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&suspend_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
    1430             :   JS_FNSPEC("resume", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&resume_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
    1431             :   JS_FNSPEC("close", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&close_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
    1432             :   JS_FNSPEC("send", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&send_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
    1433             :   JS_FS_END
    1434             : };
    1435             : #if defined(__clang__)
    1436             : #pragma clang diagnostic pop
    1437             : #endif
    1438             : 
    1439             : 
    1440             : // Can't be const because the pref-enabled boolean needs to be writable
    1441             : static Prefable<const JSFunctionSpec> sMethods[] = {
    1442             :   { nullptr, &sMethods_specs[0] },
    1443             :   { nullptr, nullptr }
    1444             : };
    1445             : 
    1446             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
    1447             :     "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
    1448             : static_assert(5 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
    1449             :     "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
    1450             : 
    1451             : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
    1452             : #if defined(__clang__)
    1453             : #pragma clang diagnostic push
    1454             : #pragma clang diagnostic ignored "-Wmissing-braces"
    1455             : #endif
    1456             : static const JSFunctionSpec sChromeMethods_specs[] = {
    1457             :   JS_FNSPEC("closeImmediately", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&closeImmediately_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
    1458             :   JS_FS_END
    1459             : };
    1460             : #if defined(__clang__)
    1461             : #pragma clang diagnostic pop
    1462             : #endif
    1463             : 
    1464             : 
    1465             : // Can't be const because the pref-enabled boolean needs to be writable
    1466             : static Prefable<const JSFunctionSpec> sChromeMethods[] = {
    1467             :   { nullptr, &sChromeMethods_specs[0] },
    1468             :   { nullptr, nullptr }
    1469             : };
    1470             : 
    1471             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
    1472             :     "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
    1473             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
    1474             :     "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
    1475             : 
    1476             : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
    1477             : #if defined(__clang__)
    1478             : #pragma clang diagnostic push
    1479             : #pragma clang diagnostic ignored "-Wmissing-braces"
    1480             : #endif
    1481             : static const JSPropertySpec sAttributes_specs[] = {
    1482             :   { "host", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &host_getterinfo, nullptr, nullptr },
    1483             :   { "port", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &port_getterinfo, nullptr, nullptr },
    1484             :   { "ssl", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &ssl_getterinfo, nullptr, nullptr },
    1485             :   { "bufferedAmount", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &bufferedAmount_getterinfo, nullptr, nullptr },
    1486             :   { "readyState", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &readyState_getterinfo, nullptr, nullptr },
    1487             :   { "binaryType", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &binaryType_getterinfo, nullptr, nullptr },
    1488             :   { "onopen", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &onopen_getterinfo, GenericBindingSetter, &onopen_setterinfo },
    1489             :   { "ondrain", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &ondrain_getterinfo, GenericBindingSetter, &ondrain_setterinfo },
    1490             :   { "ondata", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &ondata_getterinfo, GenericBindingSetter, &ondata_setterinfo },
    1491             :   { "onerror", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &onerror_getterinfo, GenericBindingSetter, &onerror_setterinfo },
    1492             :   { "onclose", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &onclose_getterinfo, GenericBindingSetter, &onclose_setterinfo },
    1493             :   { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
    1494             : };
    1495             : #if defined(__clang__)
    1496             : #pragma clang diagnostic pop
    1497             : #endif
    1498             : 
    1499             : 
    1500             : // Can't be const because the pref-enabled boolean needs to be writable
    1501             : static Prefable<const JSPropertySpec> sAttributes[] = {
    1502             :   { nullptr, &sAttributes_specs[0] },
    1503             :   { nullptr, nullptr }
    1504             : };
    1505             : 
    1506             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
    1507             :     "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
    1508             : static_assert(11 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
    1509             :     "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
    1510             : 
    1511             : 
    1512             : static uint16_t sNativeProperties_sortedPropertyIndices[16];
    1513             : static PropertyInfo sNativeProperties_propertyInfos[16];
    1514             : 
    1515             : static const NativePropertiesN<2> sNativeProperties = {
    1516             :   false, 0,
    1517             :   false, 0,
    1518             :   true,  0 /* sMethods */,
    1519             :   true,  1 /* sAttributes */,
    1520             :   false, 0,
    1521             :   false, 0,
    1522             :   false, 0,
    1523             :   -1,
    1524             :   16,
    1525             :   sNativeProperties_sortedPropertyIndices,
    1526             :   {
    1527             :     { sMethods, &sNativeProperties_propertyInfos[0] },
    1528             :     { sAttributes, &sNativeProperties_propertyInfos[5] }
    1529             :   }
    1530             : };
    1531             : static_assert(16 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
    1532             :     "We have a property info count that is oversized");
    1533             : 
    1534             : static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[1];
    1535             : static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[1];
    1536             : 
    1537             : static const NativePropertiesN<1> sChromeOnlyNativeProperties = {
    1538             :   false, 0,
    1539             :   false, 0,
    1540             :   true,  0 /* sChromeMethods */,
    1541             :   false, 0,
    1542             :   false, 0,
    1543             :   false, 0,
    1544             :   false, 0,
    1545             :   -1,
    1546             :   1,
    1547             :   sChromeOnlyNativeProperties_sortedPropertyIndices,
    1548             :   {
    1549             :     { sChromeMethods, &sChromeOnlyNativeProperties_propertyInfos[0] }
    1550             :   }
    1551             : };
    1552             : static_assert(1 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount),
    1553             :     "We have a property info count that is oversized");
    1554             : 
    1555             : static bool
    1556           0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
    1557             : {
    1558           0 :   JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
    1559           0 :   JS::Rooted<JSObject*> obj(cx, &args.callee());
    1560           0 :   if (!args.isConstructing()) {
    1561             :     // XXXbz wish I could get the name from the callee instead of
    1562             :     // Adding more relocations
    1563           0 :     return ThrowConstructorWithoutNew(cx, "TCPSocket");
    1564             :   }
    1565             : 
    1566           0 :   GlobalObject global(cx, obj);
    1567           0 :   if (global.Failed()) {
    1568           0 :     return false;
    1569             :   }
    1570             : 
    1571           0 :   JS::Rooted<JSObject*> desiredProto(cx);
    1572           0 :   if (!GetDesiredProto(cx, args, &desiredProto)) {
    1573           0 :     return false;
    1574             :   }
    1575             : 
    1576           0 :   if (MOZ_UNLIKELY(args.length() < 2)) {
    1577           0 :     return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "TCPSocket");
    1578             :   }
    1579           0 :   bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
    1580           0 :   binding_detail::FakeString arg0;
    1581           0 :   if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
    1582           0 :     return false;
    1583             :   }
    1584             :   uint16_t arg1;
    1585           0 :   if (!ValueToPrimitive<uint16_t, eDefault>(cx, args[1], &arg1)) {
    1586           0 :     return false;
    1587             :   }
    1588           0 :   binding_detail::FastSocketOptions arg2;
    1589           0 :   if (!arg2.Init(cx, (args.hasDefined(2)) ? args[2] : JS::NullHandleValue,  "Argument 3 of TCPSocket.constructor", false)) {
    1590           0 :     return false;
    1591             :   }
    1592           0 :   Maybe<JSAutoCompartment> ac;
    1593           0 :   if (objIsXray) {
    1594           0 :     obj = js::CheckedUnwrap(obj);
    1595           0 :     if (!obj) {
    1596           0 :       return false;
    1597             :     }
    1598           0 :     ac.emplace(cx, obj);
    1599           0 :     if (!JS_WrapObject(cx, &desiredProto)) {
    1600           0 :       return false;
    1601             :     }
    1602             :   }
    1603           0 :   binding_detail::FastErrorResult rv;
    1604           0 :   auto result(StrongOrRawPtr<mozilla::dom::TCPSocket>(mozilla::dom::TCPSocket::Constructor(global, NonNullHelper(Constify(arg0)), arg1, Constify(arg2), rv)));
    1605           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
    1606           0 :     return false;
    1607             :   }
    1608           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
    1609             :   static_assert(!IsPointer<decltype(result)>::value,
    1610             :                 "NewObject implies that we need to keep the object alive with a strong reference.");
    1611           0 :   if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
    1612           0 :     MOZ_ASSERT(true || JS_IsExceptionPending(cx));
    1613           0 :     return false;
    1614             :   }
    1615           0 :   return true;
    1616             : }
    1617             : 
    1618             : static const js::ClassOps sInterfaceObjectClassOps = {
    1619             :     nullptr,               /* addProperty */
    1620             :     nullptr,               /* delProperty */
    1621             :     nullptr,               /* getProperty */
    1622             :     nullptr,               /* setProperty */
    1623             :     nullptr,               /* enumerate */
    1624             :     nullptr,               /* newEnumerate */
    1625             :     nullptr,               /* resolve */
    1626             :     nullptr,               /* mayResolve */
    1627             :     nullptr,               /* finalize */
    1628             :     _constructor, /* call */
    1629             :     nullptr,               /* hasInstance */
    1630             :     _constructor, /* construct */
    1631             :     nullptr,               /* trace */
    1632             : };
    1633             : 
    1634             : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
    1635             :   {
    1636             :     "Function",
    1637             :     JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
    1638             :     &sInterfaceObjectClassOps,
    1639             :     JS_NULL_CLASS_SPEC,
    1640             :     JS_NULL_CLASS_EXT,
    1641             :     &sInterfaceObjectClassObjectOps
    1642             :   },
    1643             :   eInterface,
    1644             :   true,
    1645             :   prototypes::id::TCPSocket,
    1646             :   PrototypeTraits<prototypes::id::TCPSocket>::Depth,
    1647             :   sNativePropertyHooks,
    1648             :   "function TCPSocket() {\n    [native code]\n}",
    1649             :   EventTargetBinding::GetConstructorObject
    1650             : };
    1651             : 
    1652             : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
    1653             :   {
    1654             :     "TCPSocketPrototype",
    1655             :     JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
    1656             :     JS_NULL_CLASS_OPS,
    1657             :     JS_NULL_CLASS_SPEC,
    1658             :     JS_NULL_CLASS_EXT,
    1659             :     JS_NULL_OBJECT_OPS
    1660             :   },
    1661             :   eInterfacePrototype,
    1662             :   false,
    1663             :   prototypes::id::TCPSocket,
    1664             :   PrototypeTraits<prototypes::id::TCPSocket>::Depth,
    1665             :   sNativePropertyHooks,
    1666             :   "[object TCPSocketPrototype]",
    1667             :   EventTargetBinding::GetProtoObject
    1668             : };
    1669             : 
    1670             : bool
    1671           0 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
    1672             : {
    1673           0 :   return mozilla::dom::TCPSocket::ShouldTCPSocketExist(aCx, aObj);
    1674             : }
    1675             : 
    1676             : JSObject*
    1677           0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
    1678             : {
    1679           0 :   return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
    1680             : }
    1681             : 
    1682             : static const js::ClassOps sClassOps = {
    1683             :   _addProperty, /* addProperty */
    1684             :   nullptr,               /* delProperty */
    1685             :   nullptr,               /* getProperty */
    1686             :   nullptr,               /* setProperty */
    1687             :   nullptr,               /* enumerate */
    1688             :   nullptr, /* newEnumerate */
    1689             :   nullptr, /* resolve */
    1690             :   nullptr, /* mayResolve */
    1691             :   _finalize, /* finalize */
    1692             :   nullptr, /* call */
    1693             :   nullptr,               /* hasInstance */
    1694             :   nullptr,               /* construct */
    1695             :   nullptr, /* trace */
    1696             : };
    1697             : 
    1698             : static const js::ClassExtension sClassExtension = {
    1699             :   nullptr, /* weakmapKeyDelegateOp */
    1700             :   _objectMoved /* objectMovedOp */
    1701             : };
    1702             : 
    1703             : static const DOMJSClass sClass = {
    1704             :   { "TCPSocket",
    1705             :     JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
    1706             :     &sClassOps,
    1707             :     JS_NULL_CLASS_SPEC,
    1708             :     &sClassExtension,
    1709             :     JS_NULL_OBJECT_OPS
    1710             :   },
    1711             :   { prototypes::id::EventTarget, prototypes::id::TCPSocket, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
    1712             :   IsBaseOf<nsISupports, mozilla::dom::TCPSocket >::value,
    1713             :   sNativePropertyHooks,
    1714             :   FindAssociatedGlobalForNative<mozilla::dom::TCPSocket>::Get,
    1715             :   GetProtoObjectHandle,
    1716             :   GetCCParticipant<mozilla::dom::TCPSocket>::Get()
    1717             : };
    1718             : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
    1719             :               "Must have the right minimal number of reserved slots.");
    1720             : static_assert(1 >= 1,
    1721             :               "Must have enough reserved slots.");
    1722             : 
    1723             : const JSClass*
    1724           0 : GetJSClass()
    1725             : {
    1726           0 :   return sClass.ToJSClass();
    1727             : }
    1728             : 
    1729             : bool
    1730           0 : Wrap(JSContext* aCx, mozilla::dom::TCPSocket* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
    1731             : {
    1732             :   MOZ_ASSERT(static_cast<mozilla::dom::TCPSocket*>(aObject) ==
    1733             :              reinterpret_cast<mozilla::dom::TCPSocket*>(aObject),
    1734             :              "Multiple inheritance for mozilla::dom::TCPSocket is broken.");
    1735             :   MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
    1736             :              reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
    1737             :              "Multiple inheritance for mozilla::dom::EventTarget is broken.");
    1738           0 :   MOZ_ASSERT(ToSupportsIsCorrect(aObject));
    1739           0 :   MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
    1740           0 :   MOZ_ASSERT(!aCache->GetWrapper(),
    1741             :              "You should probably not be using Wrap() directly; use "
    1742             :              "GetOrCreateDOMReflector instead");
    1743             : 
    1744           0 :   MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
    1745             :              "nsISupports must be on our primary inheritance chain");
    1746             : 
    1747           0 :   JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
    1748           0 :   if (!global) {
    1749           0 :     return false;
    1750             :   }
    1751           0 :   MOZ_ASSERT(JS_IsGlobalObject(global));
    1752           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(global));
    1753             : 
    1754             :   // That might have ended up wrapping us already, due to the wonders
    1755             :   // of XBL.  Check for that, and bail out as needed.
    1756           0 :   aReflector.set(aCache->GetWrapper());
    1757           0 :   if (aReflector) {
    1758             : #ifdef DEBUG
    1759           0 :     binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
    1760             : #endif // DEBUG
    1761           0 :     return true;
    1762             :   }
    1763             : 
    1764           0 :   JSAutoCompartment ac(aCx, global);
    1765           0 :   JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
    1766           0 :   if (!canonicalProto) {
    1767           0 :     return false;
    1768             :   }
    1769           0 :   JS::Rooted<JSObject*> proto(aCx);
    1770           0 :   if (aGivenProto) {
    1771           0 :     proto = aGivenProto;
    1772             :     // Unfortunately, while aGivenProto was in the compartment of aCx
    1773             :     // coming in, we changed compartments to that of "parent" so may need
    1774             :     // to wrap the proto here.
    1775           0 :     if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
    1776           0 :       if (!JS_WrapObject(aCx, &proto)) {
    1777           0 :         return false;
    1778             :       }
    1779             :     }
    1780             :   } else {
    1781           0 :     proto = canonicalProto;
    1782             :   }
    1783             : 
    1784           0 :   BindingJSObjectCreator<mozilla::dom::TCPSocket> creator(aCx);
    1785           0 :   creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
    1786           0 :   if (!aReflector) {
    1787           0 :     return false;
    1788             :   }
    1789             : 
    1790           0 :   aCache->SetWrapper(aReflector);
    1791           0 :   creator.InitializationSucceeded();
    1792             : 
    1793           0 :   MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
    1794             :              aCache->GetWrapperPreserveColor() == aReflector);
    1795             :   // If proto != canonicalProto, we have to preserve our wrapper;
    1796             :   // otherwise we won't be able to properly recreate it later, since
    1797             :   // we won't know what proto to use.  Note that we don't check
    1798             :   // aGivenProto here, since it's entirely possible (and even
    1799             :   // somewhat common) to have a non-null aGivenProto which is the
    1800             :   // same as canonicalProto.
    1801           0 :   if (proto != canonicalProto) {
    1802           0 :     PreserveWrapper(aObject);
    1803             :   }
    1804             : 
    1805           0 :   return true;
    1806             : }
    1807             : 
    1808             : const NativePropertyHooks sNativePropertyHooks[] = { {
    1809             :   nullptr,
    1810             :   nullptr,
    1811             :   nullptr,
    1812             :   { sNativeProperties.Upcast(), sChromeOnlyNativeProperties.Upcast() },
    1813             :   prototypes::id::TCPSocket,
    1814             :   constructors::id::TCPSocket,
    1815             :   EventTargetBinding::sNativePropertyHooks,
    1816             :   &DefaultXrayExpandoObjectClass
    1817             : } };
    1818             : 
    1819             : void
    1820           0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
    1821             : {
    1822           0 :   JS::Handle<JSObject*> parentProto(EventTargetBinding::GetProtoObjectHandle(aCx));
    1823           0 :   if (!parentProto) {
    1824           0 :     return;
    1825             :   }
    1826             : 
    1827           0 :   JS::Handle<JSObject*> constructorProto(EventTargetBinding::GetConstructorObjectHandle(aCx));
    1828           0 :   if (!constructorProto) {
    1829           0 :     return;
    1830             :   }
    1831             : 
    1832             :   static bool sIdsInited = false;
    1833           0 :   if (!sIdsInited && NS_IsMainThread()) {
    1834           0 :     if (!InitIds(aCx, sNativeProperties.Upcast())) {
    1835           0 :       return;
    1836             :     }
    1837           0 :     if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) {
    1838           0 :       return;
    1839             :     }
    1840           0 :     sIdsInited = true;
    1841             :   }
    1842             : 
    1843           0 :   JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::TCPSocket);
    1844           0 :   JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::TCPSocket);
    1845           0 :   dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
    1846             :                               &sPrototypeClass.mBase, protoCache,
    1847             :                               constructorProto, &sInterfaceObjectClass.mBase, 2, nullptr,
    1848             :                               interfaceCache,
    1849             :                               sNativeProperties.Upcast(),
    1850           0 :                               nsContentUtils::ThreadsafeIsSystemCaller(aCx) ? sChromeOnlyNativeProperties.Upcast() : nullptr,
    1851             :                               "TCPSocket", aDefineOnGlobal,
    1852             :                               nullptr,
    1853           0 :                               false);
    1854             : }
    1855             : 
    1856             : JS::Handle<JSObject*>
    1857           0 : GetProtoObjectHandle(JSContext* aCx)
    1858             : {
    1859             :   /* Get the interface prototype object for this class.  This will create the
    1860             :      object as needed. */
    1861           0 :   bool aDefineOnGlobal = true;
    1862             : 
    1863             :   /* Make sure our global is sane.  Hopefully we can remove this sometime */
    1864           0 :   JSObject* global = JS::CurrentGlobalOrNull(aCx);
    1865           0 :   if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
    1866           0 :     return nullptr;
    1867             :   }
    1868             : 
    1869             :   /* Check to see whether the interface objects are already installed */
    1870           0 :   ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
    1871           0 :   if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::TCPSocket)) {
    1872           0 :     JS::Rooted<JSObject*> rootedGlobal(aCx, global);
    1873           0 :     CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
    1874             :   }
    1875             : 
    1876             :   /*
    1877             :    * The object might _still_ be null, but that's OK.
    1878             :    *
    1879             :    * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
    1880             :    * traced by TraceProtoAndIfaceCache() and its contents are never
    1881             :    * changed after they have been set.
    1882             :    *
    1883             :    * Calling address() avoids the read read barrier that does gray
    1884             :    * unmarking, but it's not possible for the object to be gray here.
    1885             :    */
    1886             : 
    1887           0 :   const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::TCPSocket);
    1888           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
    1889           0 :   return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
    1890             : }
    1891             : 
    1892             : JS::Handle<JSObject*>
    1893           0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
    1894             : {
    1895             :   /* Get the interface object for this class.  This will create the object as
    1896             :      needed. */
    1897             : 
    1898             :   /* Make sure our global is sane.  Hopefully we can remove this sometime */
    1899           0 :   JSObject* global = JS::CurrentGlobalOrNull(aCx);
    1900           0 :   if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
    1901           0 :     return nullptr;
    1902             :   }
    1903             : 
    1904             :   /* Check to see whether the interface objects are already installed */
    1905           0 :   ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
    1906           0 :   if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::TCPSocket)) {
    1907           0 :     JS::Rooted<JSObject*> rootedGlobal(aCx, global);
    1908           0 :     CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
    1909             :   }
    1910             : 
    1911             :   /*
    1912             :    * The object might _still_ be null, but that's OK.
    1913             :    *
    1914             :    * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
    1915             :    * traced by TraceProtoAndIfaceCache() and its contents are never
    1916             :    * changed after they have been set.
    1917             :    *
    1918             :    * Calling address() avoids the read read barrier that does gray
    1919             :    * unmarking, but it's not possible for the object to be gray here.
    1920             :    */
    1921             : 
    1922           0 :   const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::TCPSocket);
    1923           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
    1924           0 :   return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
    1925             : }
    1926             : 
    1927             : JSObject*
    1928           0 : GetConstructorObject(JSContext* aCx)
    1929             : {
    1930           0 :   return GetConstructorObjectHandle(aCx);
    1931             : }
    1932             : 
    1933             : } // namespace TCPSocketBinding
    1934             : 
    1935             : 
    1936             : 
    1937             : } // namespace dom
    1938             : } // namespace mozilla

Generated by: LCOV version 1.13