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

          Line data    Source code
       1             : /* THIS FILE IS AUTOGENERATED FROM WebSocket.webidl BY Codegen.py - DO NOT EDIT */
       2             : 
       3             : #include "EventHandlerBinding.h"
       4             : #include "EventTargetBinding.h"
       5             : #include "WebSocketBinding.h"
       6             : #include "WrapperFactory.h"
       7             : #include "jsapi.h"
       8             : #include "jsfriendapi.h"
       9             : #include "mozilla/OwningNonNull.h"
      10             : #include "mozilla/dom/BindingUtils.h"
      11             : #include "mozilla/dom/Blob.h"
      12             : #include "mozilla/dom/DOMJSClass.h"
      13             : #include "mozilla/dom/NonRefcountedDOMObject.h"
      14             : #include "mozilla/dom/Nullable.h"
      15             : #include "mozilla/dom/PrimitiveConversions.h"
      16             : #include "mozilla/dom/TypedArray.h"
      17             : #include "mozilla/dom/WebSocket.h"
      18             : #include "mozilla/dom/XrayExpandoClass.h"
      19             : #include "nsContentUtils.h"
      20             : #include "nsISupports.h"
      21             : #include "nsITransportProvider.h"
      22             : #include "xpcjsid.h"
      23             : 
      24             : namespace mozilla {
      25             : namespace dom {
      26             : 
      27             : namespace BinaryTypeValues {
      28             : extern const EnumEntry strings[3] = {
      29             :   {"blob", 4},
      30             :   {"arraybuffer", 11},
      31             :   { nullptr, 0 }
      32             : };
      33             : } // namespace BinaryTypeValues
      34             : 
      35             : bool
      36           0 : ToJSValue(JSContext* aCx, BinaryType aArgument, JS::MutableHandle<JS::Value> aValue)
      37             : {
      38           0 :   MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(BinaryTypeValues::strings));
      39             :   JSString* resultStr =
      40           0 :     JS_NewStringCopyN(aCx, BinaryTypeValues::strings[uint32_t(aArgument)].value,
      41           0 :                       BinaryTypeValues::strings[uint32_t(aArgument)].length);
      42           0 :   if (!resultStr) {
      43           0 :     return false;
      44             :   }
      45           0 :   aValue.setString(resultStr);
      46           0 :   return true;
      47             : }
      48             : 
      49             : 
      50             : namespace WebSocketBinding {
      51             : 
      52             : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventTargetBinding::NativeType>::value,
      53             :               "Can't inherit from an interface with a different ownership model.");
      54             : 
      55             : static bool
      56           0 : get_url(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WebSocket* self, JSJitGetterCallArgs args)
      57             : {
      58           0 :   DOMString result;
      59           0 :   self->GetUrl(result);
      60           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
      61           0 :   if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
      62           0 :     return false;
      63             :   }
      64           0 :   return true;
      65             : }
      66             : 
      67             : static const JSJitInfo url_getterinfo = {
      68             :   { (JSJitGetterOp)get_url },
      69             :   { prototypes::id::WebSocket },
      70             :   { PrototypeTraits<prototypes::id::WebSocket>::Depth },
      71             :   JSJitInfo::Getter,
      72             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
      73             :   JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
      74             :   false,  /* isInfallible. False in setters. */
      75             :   false,  /* isMovable.  Not relevant for setters. */
      76             :   false, /* isEliminatable.  Not relevant for setters. */
      77             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
      78             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
      79             :   false,  /* isTypedMethod.  Only relevant for methods. */
      80             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
      81             : };
      82             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
      83             : static_assert(0 < 1, "There is no slot for us");
      84             : 
      85             : static bool
      86           0 : get_readyState(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WebSocket* self, JSJitGetterCallArgs args)
      87             : {
      88           0 :   uint16_t result(self->ReadyState());
      89           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
      90           0 :   args.rval().setInt32(int32_t(result));
      91           0 :   return true;
      92             : }
      93             : 
      94             : static const JSJitInfo readyState_getterinfo = {
      95             :   { (JSJitGetterOp)get_readyState },
      96             :   { prototypes::id::WebSocket },
      97             :   { PrototypeTraits<prototypes::id::WebSocket>::Depth },
      98             :   JSJitInfo::Getter,
      99             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     100             :   JSVAL_TYPE_INT32,  /* returnType.  Not relevant for setters. */
     101             :   true,  /* isInfallible. False in setters. */
     102             :   false,  /* isMovable.  Not relevant for setters. */
     103             :   false, /* isEliminatable.  Not relevant for setters. */
     104             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     105             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     106             :   false,  /* isTypedMethod.  Only relevant for methods. */
     107             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     108             : };
     109             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     110             : static_assert(0 < 1, "There is no slot for us");
     111             : 
     112             : static bool
     113           0 : get_bufferedAmount(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WebSocket* self, JSJitGetterCallArgs args)
     114             : {
     115           0 :   uint32_t result(self->BufferedAmount());
     116           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     117           0 :   args.rval().setNumber(result);
     118           0 :   return true;
     119             : }
     120             : 
     121             : static const JSJitInfo bufferedAmount_getterinfo = {
     122             :   { (JSJitGetterOp)get_bufferedAmount },
     123             :   { prototypes::id::WebSocket },
     124             :   { PrototypeTraits<prototypes::id::WebSocket>::Depth },
     125             :   JSJitInfo::Getter,
     126             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     127             :   JSVAL_TYPE_DOUBLE,  /* returnType.  Not relevant for setters. */
     128             :   true,  /* isInfallible. False in setters. */
     129             :   false,  /* isMovable.  Not relevant for setters. */
     130             :   false, /* isEliminatable.  Not relevant for setters. */
     131             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     132             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     133             :   false,  /* isTypedMethod.  Only relevant for methods. */
     134             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     135             : };
     136             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     137             : static_assert(0 < 1, "There is no slot for us");
     138             : 
     139             : static bool
     140           0 : get_onopen(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WebSocket* self, JSJitGetterCallArgs args)
     141             : {
     142           0 :   RefPtr<EventHandlerNonNull> result(self->GetOnopen());
     143           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     144           0 :   if (result) {
     145           0 :     args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
     146           0 :     if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
     147           0 :       return false;
     148             :     }
     149           0 :     return true;
     150             :   } else {
     151           0 :     args.rval().setNull();
     152           0 :     return true;
     153             :   }
     154             : }
     155             : 
     156             : static bool
     157           0 : set_onopen(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WebSocket* self, JSJitSetterCallArgs args)
     158             : {
     159           0 :   RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
     160           0 :   if (args[0].isObject()) {
     161             :     { // scope for tempRoot
     162           0 :       JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
     163           0 :       arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
     164             :     }
     165             :   } else {
     166           0 :     arg0 = nullptr;
     167             :   }
     168           0 :   self->SetOnopen(Constify(arg0));
     169           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     170             : 
     171           0 :   return true;
     172             : }
     173             : 
     174             : static const JSJitInfo onopen_getterinfo = {
     175             :   { (JSJitGetterOp)get_onopen },
     176             :   { prototypes::id::WebSocket },
     177             :   { PrototypeTraits<prototypes::id::WebSocket>::Depth },
     178             :   JSJitInfo::Getter,
     179             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     180             :   JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
     181             :   false,  /* isInfallible. False in setters. */
     182             :   false,  /* isMovable.  Not relevant for setters. */
     183             :   false, /* isEliminatable.  Not relevant for setters. */
     184             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     185             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     186             :   false,  /* isTypedMethod.  Only relevant for methods. */
     187             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     188             : };
     189             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     190             : static_assert(0 < 1, "There is no slot for us");
     191             : static const JSJitInfo onopen_setterinfo = {
     192             :   { (JSJitGetterOp)set_onopen },
     193             :   { prototypes::id::WebSocket },
     194             :   { PrototypeTraits<prototypes::id::WebSocket>::Depth },
     195             :   JSJitInfo::Setter,
     196             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     197             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
     198             :   false,  /* isInfallible. False in setters. */
     199             :   false,  /* isMovable.  Not relevant for setters. */
     200             :   false, /* isEliminatable.  Not relevant for setters. */
     201             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     202             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     203             :   false,  /* isTypedMethod.  Only relevant for methods. */
     204             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     205             : };
     206             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     207             : static_assert(0 < 1, "There is no slot for us");
     208             : 
     209             : static bool
     210           0 : get_onerror(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WebSocket* self, JSJitGetterCallArgs args)
     211             : {
     212           0 :   RefPtr<EventHandlerNonNull> result(self->GetOnerror());
     213           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     214           0 :   if (result) {
     215           0 :     args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
     216           0 :     if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
     217           0 :       return false;
     218             :     }
     219           0 :     return true;
     220             :   } else {
     221           0 :     args.rval().setNull();
     222           0 :     return true;
     223             :   }
     224             : }
     225             : 
     226             : static bool
     227           0 : set_onerror(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WebSocket* self, JSJitSetterCallArgs args)
     228             : {
     229           0 :   RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
     230           0 :   if (args[0].isObject()) {
     231             :     { // scope for tempRoot
     232           0 :       JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
     233           0 :       arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
     234             :     }
     235             :   } else {
     236           0 :     arg0 = nullptr;
     237             :   }
     238           0 :   self->SetOnerror(Constify(arg0));
     239           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     240             : 
     241           0 :   return true;
     242             : }
     243             : 
     244             : static const JSJitInfo onerror_getterinfo = {
     245             :   { (JSJitGetterOp)get_onerror },
     246             :   { prototypes::id::WebSocket },
     247             :   { PrototypeTraits<prototypes::id::WebSocket>::Depth },
     248             :   JSJitInfo::Getter,
     249             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     250             :   JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
     251             :   false,  /* isInfallible. False in setters. */
     252             :   false,  /* isMovable.  Not relevant for setters. */
     253             :   false, /* isEliminatable.  Not relevant for setters. */
     254             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     255             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     256             :   false,  /* isTypedMethod.  Only relevant for methods. */
     257             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     258             : };
     259             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     260             : static_assert(0 < 1, "There is no slot for us");
     261             : static const JSJitInfo onerror_setterinfo = {
     262             :   { (JSJitGetterOp)set_onerror },
     263             :   { prototypes::id::WebSocket },
     264             :   { PrototypeTraits<prototypes::id::WebSocket>::Depth },
     265             :   JSJitInfo::Setter,
     266             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     267             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
     268             :   false,  /* isInfallible. False in setters. */
     269             :   false,  /* isMovable.  Not relevant for setters. */
     270             :   false, /* isEliminatable.  Not relevant for setters. */
     271             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     272             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     273             :   false,  /* isTypedMethod.  Only relevant for methods. */
     274             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     275             : };
     276             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     277             : static_assert(0 < 1, "There is no slot for us");
     278             : 
     279             : static bool
     280           0 : get_onclose(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WebSocket* self, JSJitGetterCallArgs args)
     281             : {
     282           0 :   RefPtr<EventHandlerNonNull> result(self->GetOnclose());
     283           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     284           0 :   if (result) {
     285           0 :     args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
     286           0 :     if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
     287           0 :       return false;
     288             :     }
     289           0 :     return true;
     290             :   } else {
     291           0 :     args.rval().setNull();
     292           0 :     return true;
     293             :   }
     294             : }
     295             : 
     296             : static bool
     297           0 : set_onclose(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WebSocket* self, JSJitSetterCallArgs args)
     298             : {
     299           0 :   RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
     300           0 :   if (args[0].isObject()) {
     301             :     { // scope for tempRoot
     302           0 :       JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
     303           0 :       arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
     304             :     }
     305             :   } else {
     306           0 :     arg0 = nullptr;
     307             :   }
     308           0 :   self->SetOnclose(Constify(arg0));
     309           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     310             : 
     311           0 :   return true;
     312             : }
     313             : 
     314             : static const JSJitInfo onclose_getterinfo = {
     315             :   { (JSJitGetterOp)get_onclose },
     316             :   { prototypes::id::WebSocket },
     317             :   { PrototypeTraits<prototypes::id::WebSocket>::Depth },
     318             :   JSJitInfo::Getter,
     319             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     320             :   JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
     321             :   false,  /* isInfallible. False in setters. */
     322             :   false,  /* isMovable.  Not relevant for setters. */
     323             :   false, /* isEliminatable.  Not relevant for setters. */
     324             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     325             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     326             :   false,  /* isTypedMethod.  Only relevant for methods. */
     327             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     328             : };
     329             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     330             : static_assert(0 < 1, "There is no slot for us");
     331             : static const JSJitInfo onclose_setterinfo = {
     332             :   { (JSJitGetterOp)set_onclose },
     333             :   { prototypes::id::WebSocket },
     334             :   { PrototypeTraits<prototypes::id::WebSocket>::Depth },
     335             :   JSJitInfo::Setter,
     336             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     337             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
     338             :   false,  /* isInfallible. False in setters. */
     339             :   false,  /* isMovable.  Not relevant for setters. */
     340             :   false, /* isEliminatable.  Not relevant for setters. */
     341             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     342             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     343             :   false,  /* isTypedMethod.  Only relevant for methods. */
     344             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     345             : };
     346             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     347             : static_assert(0 < 1, "There is no slot for us");
     348             : 
     349             : static bool
     350           0 : get_extensions(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WebSocket* self, JSJitGetterCallArgs args)
     351             : {
     352           0 :   DOMString result;
     353           0 :   self->GetExtensions(result);
     354           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     355           0 :   if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
     356           0 :     return false;
     357             :   }
     358           0 :   return true;
     359             : }
     360             : 
     361             : static const JSJitInfo extensions_getterinfo = {
     362             :   { (JSJitGetterOp)get_extensions },
     363             :   { prototypes::id::WebSocket },
     364             :   { PrototypeTraits<prototypes::id::WebSocket>::Depth },
     365             :   JSJitInfo::Getter,
     366             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     367             :   JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
     368             :   false,  /* isInfallible. False in setters. */
     369             :   false,  /* isMovable.  Not relevant for setters. */
     370             :   false, /* isEliminatable.  Not relevant for setters. */
     371             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     372             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     373             :   false,  /* isTypedMethod.  Only relevant for methods. */
     374             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     375             : };
     376             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     377             : static_assert(0 < 1, "There is no slot for us");
     378             : 
     379             : static bool
     380           0 : get_protocol(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WebSocket* self, JSJitGetterCallArgs args)
     381             : {
     382           0 :   DOMString result;
     383           0 :   self->GetProtocol(result);
     384           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     385           0 :   if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
     386           0 :     return false;
     387             :   }
     388           0 :   return true;
     389             : }
     390             : 
     391             : static const JSJitInfo protocol_getterinfo = {
     392             :   { (JSJitGetterOp)get_protocol },
     393             :   { prototypes::id::WebSocket },
     394             :   { PrototypeTraits<prototypes::id::WebSocket>::Depth },
     395             :   JSJitInfo::Getter,
     396             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     397             :   JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
     398             :   false,  /* isInfallible. False in setters. */
     399             :   false,  /* isMovable.  Not relevant for setters. */
     400             :   false, /* isEliminatable.  Not relevant for setters. */
     401             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     402             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     403             :   false,  /* isTypedMethod.  Only relevant for methods. */
     404             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     405             : };
     406             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     407             : static_assert(0 < 1, "There is no slot for us");
     408             : 
     409             : static bool
     410           0 : close(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WebSocket* self, const JSJitMethodCallArgs& args)
     411             : {
     412           0 :   Optional<uint16_t> arg0;
     413           0 :   if (args.hasDefined(0)) {
     414           0 :     arg0.Construct();
     415           0 :     if (!ValueToPrimitive<uint16_t, eClamp>(cx, args[0], &arg0.Value())) {
     416           0 :       return false;
     417             :     }
     418             :   }
     419           0 :   Optional<nsAString> arg1;
     420           0 :   binding_detail::FakeString arg1_holder;
     421           0 :   if (args.hasDefined(1)) {
     422           0 :     if (!ConvertJSValueToString(cx, args[1], eStringify, eStringify, arg1_holder)) {
     423           0 :       return false;
     424             :     }
     425           0 :     arg1 = &arg1_holder;
     426             :   }
     427           0 :   binding_detail::FastErrorResult rv;
     428           0 :   self->Close(Constify(arg0), NonNullHelper(Constify(arg1)), rv);
     429           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     430           0 :     return false;
     431             :   }
     432           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     433           0 :   args.rval().setUndefined();
     434           0 :   return true;
     435             : }
     436             : 
     437             : static const JSJitInfo close_methodinfo = {
     438             :   { (JSJitGetterOp)close },
     439             :   { prototypes::id::WebSocket },
     440             :   { PrototypeTraits<prototypes::id::WebSocket>::Depth },
     441             :   JSJitInfo::Method,
     442             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     443             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
     444             :   false,  /* isInfallible. False in setters. */
     445             :   false,  /* isMovable.  Not relevant for setters. */
     446             :   false, /* isEliminatable.  Not relevant for setters. */
     447             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     448             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     449             :   false,  /* isTypedMethod.  Only relevant for methods. */
     450             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     451             : };
     452             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     453             : static_assert(0 < 1, "There is no slot for us");
     454             : 
     455             : static bool
     456           0 : get_onmessage(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WebSocket* self, JSJitGetterCallArgs args)
     457             : {
     458           0 :   RefPtr<EventHandlerNonNull> result(self->GetOnmessage());
     459           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     460           0 :   if (result) {
     461           0 :     args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
     462           0 :     if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
     463           0 :       return false;
     464             :     }
     465           0 :     return true;
     466             :   } else {
     467           0 :     args.rval().setNull();
     468           0 :     return true;
     469             :   }
     470             : }
     471             : 
     472             : static bool
     473           0 : set_onmessage(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WebSocket* self, JSJitSetterCallArgs args)
     474             : {
     475           0 :   RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
     476           0 :   if (args[0].isObject()) {
     477             :     { // scope for tempRoot
     478           0 :       JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
     479           0 :       arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
     480             :     }
     481             :   } else {
     482           0 :     arg0 = nullptr;
     483             :   }
     484           0 :   self->SetOnmessage(Constify(arg0));
     485           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     486             : 
     487           0 :   return true;
     488             : }
     489             : 
     490             : static const JSJitInfo onmessage_getterinfo = {
     491             :   { (JSJitGetterOp)get_onmessage },
     492             :   { prototypes::id::WebSocket },
     493             :   { PrototypeTraits<prototypes::id::WebSocket>::Depth },
     494             :   JSJitInfo::Getter,
     495             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     496             :   JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
     497             :   false,  /* isInfallible. False in setters. */
     498             :   false,  /* isMovable.  Not relevant for setters. */
     499             :   false, /* isEliminatable.  Not relevant for setters. */
     500             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     501             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     502             :   false,  /* isTypedMethod.  Only relevant for methods. */
     503             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     504             : };
     505             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     506             : static_assert(0 < 1, "There is no slot for us");
     507             : static const JSJitInfo onmessage_setterinfo = {
     508             :   { (JSJitGetterOp)set_onmessage },
     509             :   { prototypes::id::WebSocket },
     510             :   { PrototypeTraits<prototypes::id::WebSocket>::Depth },
     511             :   JSJitInfo::Setter,
     512             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     513             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
     514             :   false,  /* isInfallible. False in setters. */
     515             :   false,  /* isMovable.  Not relevant for setters. */
     516             :   false, /* isEliminatable.  Not relevant for setters. */
     517             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     518             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     519             :   false,  /* isTypedMethod.  Only relevant for methods. */
     520             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     521             : };
     522             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     523             : static_assert(0 < 1, "There is no slot for us");
     524             : 
     525             : static bool
     526           0 : get_binaryType(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WebSocket* self, JSJitGetterCallArgs args)
     527             : {
     528           0 :   BinaryType result(self->BinaryType());
     529           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     530           0 :   if (!ToJSValue(cx, result, args.rval())) {
     531           0 :     return false;
     532             :   }
     533           0 :   return true;
     534             : }
     535             : 
     536             : static bool
     537           0 : set_binaryType(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WebSocket* self, JSJitSetterCallArgs args)
     538             : {
     539             :   BinaryType arg0;
     540             :   {
     541             :     int index;
     542           0 :     if (!FindEnumStringIndex<false>(cx, args[0], BinaryTypeValues::strings, "BinaryType", "Value being assigned to WebSocket.binaryType", &index)) {
     543           0 :       return false;
     544             :     }
     545           0 :     if (index < 0) {
     546           0 :       return true;
     547             :     }
     548           0 :     arg0 = static_cast<BinaryType>(index);
     549             :   }
     550           0 :   self->SetBinaryType(arg0);
     551           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     552             : 
     553           0 :   return true;
     554             : }
     555             : 
     556             : static const JSJitInfo binaryType_getterinfo = {
     557             :   { (JSJitGetterOp)get_binaryType },
     558             :   { prototypes::id::WebSocket },
     559             :   { PrototypeTraits<prototypes::id::WebSocket>::Depth },
     560             :   JSJitInfo::Getter,
     561             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     562             :   JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
     563             :   false,  /* isInfallible. False in setters. */
     564             :   false,  /* isMovable.  Not relevant for setters. */
     565             :   false, /* isEliminatable.  Not relevant for setters. */
     566             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     567             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     568             :   false,  /* isTypedMethod.  Only relevant for methods. */
     569             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     570             : };
     571             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     572             : static_assert(0 < 1, "There is no slot for us");
     573             : static const JSJitInfo binaryType_setterinfo = {
     574             :   { (JSJitGetterOp)set_binaryType },
     575             :   { prototypes::id::WebSocket },
     576             :   { PrototypeTraits<prototypes::id::WebSocket>::Depth },
     577             :   JSJitInfo::Setter,
     578             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     579             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
     580             :   false,  /* isInfallible. False in setters. */
     581             :   false,  /* isMovable.  Not relevant for setters. */
     582             :   false, /* isEliminatable.  Not relevant for setters. */
     583             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     584             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     585             :   false,  /* isTypedMethod.  Only relevant for methods. */
     586             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     587             : };
     588             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     589             : static_assert(0 < 1, "There is no slot for us");
     590             : 
     591             : static bool
     592           0 : send(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WebSocket* self, const JSJitMethodCallArgs& args)
     593             : {
     594           0 :   unsigned argcount = std::min(args.length(), 1u);
     595           0 :   switch (argcount) {
     596             :     case 1: {
     597           0 :       if (args[0].isObject()) {
     598             :         do {
     599           0 :           NonNull<mozilla::dom::Blob> arg0;
     600             :           {
     601           0 :             nsresult rv = UnwrapObject<prototypes::id::Blob, mozilla::dom::Blob>(args[0], arg0);
     602           0 :             if (NS_FAILED(rv)) {
     603           0 :               break;
     604             :             }
     605             :           }
     606           0 :           binding_detail::FastErrorResult rv;
     607           0 :           self->Send(NonNullHelper(arg0), rv);
     608           0 :           if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     609           0 :             return false;
     610             :           }
     611           0 :           MOZ_ASSERT(!JS_IsExceptionPending(cx));
     612           0 :           args.rval().setUndefined();
     613           0 :           return true;
     614             :         } while (0);
     615             :         do {
     616           0 :           RootedTypedArray<ArrayBuffer> arg0(cx);
     617           0 :           if (!arg0.Init(&args[0].toObject())) {
     618           0 :             break;
     619             :           }
     620           0 :           binding_detail::FastErrorResult rv;
     621           0 :           self->Send(Constify(arg0), rv);
     622           0 :           if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     623           0 :             return false;
     624             :           }
     625           0 :           MOZ_ASSERT(!JS_IsExceptionPending(cx));
     626           0 :           args.rval().setUndefined();
     627           0 :           return true;
     628             :         } while (0);
     629             :         do {
     630           0 :           RootedTypedArray<ArrayBufferView> arg0(cx);
     631           0 :           if (!arg0.Init(&args[0].toObject())) {
     632           0 :             break;
     633             :           }
     634           0 :           binding_detail::FastErrorResult rv;
     635           0 :           self->Send(Constify(arg0), rv);
     636           0 :           if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     637           0 :             return false;
     638             :           }
     639           0 :           MOZ_ASSERT(!JS_IsExceptionPending(cx));
     640           0 :           args.rval().setUndefined();
     641           0 :           return true;
     642             :         } while (0);
     643             :       }
     644           0 :       binding_detail::FakeString arg0;
     645           0 :       if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
     646           0 :         return false;
     647             :       }
     648           0 :       binding_detail::FastErrorResult rv;
     649           0 :       self->Send(NonNullHelper(Constify(arg0)), rv);
     650           0 :       if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     651           0 :         return false;
     652             :       }
     653           0 :       MOZ_ASSERT(!JS_IsExceptionPending(cx));
     654           0 :       args.rval().setUndefined();
     655           0 :       return true;
     656             :       break;
     657             :     }
     658             :     default: {
     659           0 :       return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WebSocket.send");
     660             :       break;
     661             :     }
     662             :   }
     663             :   MOZ_CRASH("We have an always-returning default case");
     664             :   return false;
     665             : }
     666             : 
     667             : static const JSJitInfo send_methodinfo = {
     668             :   { (JSJitGetterOp)send },
     669             :   { prototypes::id::WebSocket },
     670             :   { PrototypeTraits<prototypes::id::WebSocket>::Depth },
     671             :   JSJitInfo::Method,
     672             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     673             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
     674             :   false,  /* isInfallible. False in setters. */
     675             :   false,  /* isMovable.  Not relevant for setters. */
     676             :   false, /* isEliminatable.  Not relevant for setters. */
     677             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     678             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     679             :   false,  /* isTypedMethod.  Only relevant for methods. */
     680             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     681             : };
     682             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     683             : static_assert(0 < 1, "There is no slot for us");
     684             : 
     685             : static bool
     686           0 : createServerWebSocket(JSContext* cx, unsigned argc, JS::Value* vp)
     687             : {
     688           0 :   JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
     689           0 :   JS::Rooted<JSObject*> obj(cx, &args.callee());
     690             : 
     691           0 :   if (MOZ_UNLIKELY(args.length() < 4)) {
     692           0 :     return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WebSocket.createServerWebSocket");
     693             :   }
     694           0 :   GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
     695           0 :   if (global.Failed()) {
     696           0 :     return false;
     697             :   }
     698             : 
     699           0 :   binding_detail::FakeString arg0;
     700           0 :   if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
     701           0 :     return false;
     702             :   }
     703           0 :   binding_detail::AutoSequence<nsString> arg1;
     704           0 :   if (args[1].isObject()) {
     705           0 :     JS::ForOfIterator iter(cx);
     706           0 :     if (!iter.init(args[1], JS::ForOfIterator::AllowNonIterable)) {
     707           0 :       return false;
     708             :     }
     709           0 :     if (!iter.valueIsIterable()) {
     710           0 :       ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 2 of WebSocket.createServerWebSocket");
     711           0 :       return false;
     712             :     }
     713           0 :     binding_detail::AutoSequence<nsString> &arr = arg1;
     714           0 :     JS::Rooted<JS::Value> temp(cx);
     715             :     while (true) {
     716             :       bool done;
     717           0 :       if (!iter.next(&temp, &done)) {
     718           0 :         return false;
     719             :       }
     720           0 :       if (done) {
     721           0 :         break;
     722             :       }
     723           0 :       nsString* slotPtr = arr.AppendElement(mozilla::fallible);
     724           0 :       if (!slotPtr) {
     725           0 :         JS_ReportOutOfMemory(cx);
     726           0 :         return false;
     727             :       }
     728           0 :       nsString& slot = *slotPtr;
     729           0 :       if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
     730           0 :         return false;
     731             :       }
     732           0 :     }
     733             :   } else {
     734           0 :     ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 2 of WebSocket.createServerWebSocket");
     735           0 :     return false;
     736             :   }
     737             :   nsITransportProvider* arg2;
     738           0 :   RefPtr<nsITransportProvider> arg2_holder;
     739           0 :   if (args[2].isObject()) {
     740           0 :     JS::Rooted<JSObject*> source(cx, &args[2].toObject());
     741           0 :     if (NS_FAILED(UnwrapArg<nsITransportProvider>(cx, source, getter_AddRefs(arg2_holder)))) {
     742           0 :       ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 3 of WebSocket.createServerWebSocket", "nsITransportProvider");
     743           0 :       return false;
     744             :     }
     745           0 :     MOZ_ASSERT(arg2_holder);
     746           0 :     arg2 = arg2_holder;
     747             :   } else {
     748           0 :     ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 3 of WebSocket.createServerWebSocket");
     749           0 :     return false;
     750             :   }
     751           0 :   binding_detail::FakeString arg3;
     752           0 :   if (!ConvertJSValueToString(cx, args[3], eStringify, eStringify, arg3)) {
     753           0 :     return false;
     754             :   }
     755           0 :   binding_detail::FastErrorResult rv;
     756           0 :   auto result(StrongOrRawPtr<mozilla::dom::WebSocket>(mozilla::dom::WebSocket::CreateServerWebSocket(global, NonNullHelper(Constify(arg0)), Constify(arg1), NonNullHelper(arg2), NonNullHelper(Constify(arg3)), rv)));
     757           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     758           0 :     return false;
     759             :   }
     760           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     761             :   static_assert(!IsPointer<decltype(result)>::value,
     762             :                 "NewObject implies that we need to keep the object alive with a strong reference.");
     763           0 :   if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
     764           0 :     MOZ_ASSERT(true || JS_IsExceptionPending(cx));
     765           0 :     return false;
     766             :   }
     767           0 :   return true;
     768             : }
     769             : 
     770             : static bool
     771           0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
     772             : {
     773           0 :   mozilla::dom::WebSocket* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::WebSocket>(obj);
     774             :   // We don't want to preserve if we don't have a wrapper, and we
     775             :   // obviously can't preserve if we're not initialized.
     776           0 :   if (self && self->GetWrapperPreserveColor()) {
     777           0 :     PreserveWrapper(self);
     778             :   }
     779           0 :   return true;
     780             : }
     781             : 
     782             : static void
     783           0 : _finalize(js::FreeOp* fop, JSObject* obj)
     784             : {
     785           0 :   mozilla::dom::WebSocket* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::WebSocket>(obj);
     786           0 :   if (self) {
     787           0 :     ClearWrapper(self, self, obj);
     788           0 :     AddForDeferredFinalization<mozilla::dom::WebSocket>(self);
     789             :   }
     790           0 : }
     791             : 
     792             : static void
     793           0 : _objectMoved(JSObject* obj, const JSObject* old)
     794             : {
     795           0 :   mozilla::dom::WebSocket* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::WebSocket>(obj);
     796           0 :   if (self) {
     797           0 :     UpdateWrapper(self, self, obj, old);
     798             :   }
     799           0 : }
     800             : 
     801             : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
     802             : #if defined(__clang__)
     803             : #pragma clang diagnostic push
     804             : #pragma clang diagnostic ignored "-Wmissing-braces"
     805             : #endif
     806             : static const JSFunctionSpec sChromeStaticMethods_specs[] = {
     807             :   JS_FNSPEC("createServerWebSocket", createServerWebSocket, nullptr, 4, JSPROP_ENUMERATE, nullptr),
     808             :   JS_FS_END
     809             : };
     810             : #if defined(__clang__)
     811             : #pragma clang diagnostic pop
     812             : #endif
     813             : 
     814             : 
     815             : // Can't be const because the pref-enabled boolean needs to be writable
     816             : static Prefable<const JSFunctionSpec> sChromeStaticMethods[] = {
     817             :   { nullptr, &sChromeStaticMethods_specs[0] },
     818             :   { nullptr, nullptr }
     819             : };
     820             : 
     821             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
     822             :     "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
     823             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
     824             :     "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
     825             : 
     826             : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
     827             : #if defined(__clang__)
     828             : #pragma clang diagnostic push
     829             : #pragma clang diagnostic ignored "-Wmissing-braces"
     830             : #endif
     831             : static const JSFunctionSpec sMethods_specs[] = {
     832             :   JS_FNSPEC("close", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&close_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
     833             :   JS_FNSPEC("send", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&send_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
     834             :   JS_FS_END,
     835             :   JS_FNSPEC("QueryInterface", QueryInterface, nullptr, 1, 0, nullptr),
     836             :   JS_FS_END
     837             : };
     838             : #if defined(__clang__)
     839             : #pragma clang diagnostic pop
     840             : #endif
     841             : 
     842             : static PrefableDisablers sMethods_disablers3 = {
     843             :   true, false, 0, &WantsQueryInterface<mozilla::dom::WebSocket>::Enabled
     844             : };
     845             : 
     846             : // Can't be const because the pref-enabled boolean needs to be writable
     847             : static Prefable<const JSFunctionSpec> sMethods[] = {
     848             :   { nullptr, &sMethods_specs[0] },
     849             :   { &sMethods_disablers3, &sMethods_specs[3] },
     850             :   { nullptr, nullptr }
     851             : };
     852             : 
     853             : static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
     854             :     "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
     855             : static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
     856             :     "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
     857             : 
     858             : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
     859             : #if defined(__clang__)
     860             : #pragma clang diagnostic push
     861             : #pragma clang diagnostic ignored "-Wmissing-braces"
     862             : #endif
     863             : static const JSPropertySpec sAttributes_specs[] = {
     864             :   { "url", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &url_getterinfo, nullptr, nullptr },
     865             :   { "readyState", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &readyState_getterinfo, nullptr, nullptr },
     866             :   { "bufferedAmount", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &bufferedAmount_getterinfo, nullptr, nullptr },
     867             :   { "onopen", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &onopen_getterinfo, GenericBindingSetter, &onopen_setterinfo },
     868             :   { "onerror", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &onerror_getterinfo, GenericBindingSetter, &onerror_setterinfo },
     869             :   { "onclose", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &onclose_getterinfo, GenericBindingSetter, &onclose_setterinfo },
     870             :   { "extensions", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &extensions_getterinfo, nullptr, nullptr },
     871             :   { "protocol", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &protocol_getterinfo, nullptr, nullptr },
     872             :   { "onmessage", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &onmessage_getterinfo, GenericBindingSetter, &onmessage_setterinfo },
     873             :   { "binaryType", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &binaryType_getterinfo, GenericBindingSetter, &binaryType_setterinfo },
     874             :   { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
     875             : };
     876             : #if defined(__clang__)
     877             : #pragma clang diagnostic pop
     878             : #endif
     879             : 
     880             : 
     881             : // Can't be const because the pref-enabled boolean needs to be writable
     882             : static Prefable<const JSPropertySpec> sAttributes[] = {
     883             :   { nullptr, &sAttributes_specs[0] },
     884             :   { nullptr, nullptr }
     885             : };
     886             : 
     887             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
     888             :     "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
     889             : static_assert(10 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
     890             :     "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
     891             : 
     892             : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
     893             : #if defined(__clang__)
     894             : #pragma clang diagnostic push
     895             : #pragma clang diagnostic ignored "-Wmissing-braces"
     896             : #endif
     897             : static const ConstantSpec sConstants_specs[] = {
     898             :   { "CONNECTING", JS::Int32Value(0) },
     899             :   { "OPEN", JS::Int32Value(1) },
     900             :   { "CLOSING", JS::Int32Value(2) },
     901             :   { "CLOSED", JS::Int32Value(3) },
     902             :   { 0, JS::UndefinedValue() }
     903             : };
     904             : #if defined(__clang__)
     905             : #pragma clang diagnostic pop
     906             : #endif
     907             : 
     908             : 
     909             : // Can't be const because the pref-enabled boolean needs to be writable
     910             : static Prefable<const ConstantSpec> sConstants[] = {
     911             :   { nullptr, &sConstants_specs[0] },
     912             :   { nullptr, nullptr }
     913             : };
     914             : 
     915             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
     916             :     "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
     917             : static_assert(4 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
     918             :     "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
     919             : 
     920             : 
     921             : static uint16_t sNativeProperties_sortedPropertyIndices[17];
     922             : static PropertyInfo sNativeProperties_propertyInfos[17];
     923             : 
     924             : static const NativePropertiesN<3> sNativeProperties = {
     925             :   false, 0,
     926             :   false, 0,
     927             :   true,  0 /* sMethods */,
     928             :   true,  1 /* sAttributes */,
     929             :   false, 0,
     930             :   false, 0,
     931             :   true,  2 /* sConstants */,
     932             :   -1,
     933             :   17,
     934             :   sNativeProperties_sortedPropertyIndices,
     935             :   {
     936             :     { sMethods, &sNativeProperties_propertyInfos[0] },
     937             :     { sAttributes, &sNativeProperties_propertyInfos[3] },
     938             :     { sConstants, &sNativeProperties_propertyInfos[13] }
     939             :   }
     940             : };
     941             : static_assert(17 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
     942             :     "We have a property info count that is oversized");
     943             : 
     944             : static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[1];
     945             : static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[1];
     946             : 
     947             : static const NativePropertiesN<1> sChromeOnlyNativeProperties = {
     948             :   true,  0 /* sChromeStaticMethods */,
     949             :   false, 0,
     950             :   false, 0,
     951             :   false, 0,
     952             :   false, 0,
     953             :   false, 0,
     954             :   false, 0,
     955             :   -1,
     956             :   1,
     957             :   sChromeOnlyNativeProperties_sortedPropertyIndices,
     958             :   {
     959             :     { sChromeStaticMethods, &sChromeOnlyNativeProperties_propertyInfos[0] }
     960             :   }
     961             : };
     962             : static_assert(1 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount),
     963             :     "We have a property info count that is oversized");
     964             : 
     965             : static bool
     966           0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
     967             : {
     968           0 :   JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
     969           0 :   JS::Rooted<JSObject*> obj(cx, &args.callee());
     970           0 :   if (!args.isConstructing()) {
     971             :     // XXXbz wish I could get the name from the callee instead of
     972             :     // Adding more relocations
     973           0 :     return ThrowConstructorWithoutNew(cx, "WebSocket");
     974             :   }
     975             : 
     976           0 :   GlobalObject global(cx, obj);
     977           0 :   if (global.Failed()) {
     978           0 :     return false;
     979             :   }
     980             : 
     981           0 :   JS::Rooted<JSObject*> desiredProto(cx);
     982           0 :   if (!GetDesiredProto(cx, args, &desiredProto)) {
     983           0 :     return false;
     984             :   }
     985             : 
     986           0 :   unsigned argcount = std::min(args.length(), 2u);
     987           0 :   switch (argcount) {
     988             :     case 1: {
     989           0 :       bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
     990           0 :       binding_detail::FakeString arg0;
     991           0 :       if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
     992           0 :         return false;
     993             :       }
     994           0 :       Maybe<JSAutoCompartment> ac;
     995           0 :       if (objIsXray) {
     996           0 :         obj = js::CheckedUnwrap(obj);
     997           0 :         if (!obj) {
     998           0 :           return false;
     999             :         }
    1000           0 :         ac.emplace(cx, obj);
    1001           0 :         if (!JS_WrapObject(cx, &desiredProto)) {
    1002           0 :           return false;
    1003             :         }
    1004             :       }
    1005           0 :       binding_detail::FastErrorResult rv;
    1006           0 :       auto result(StrongOrRawPtr<mozilla::dom::WebSocket>(mozilla::dom::WebSocket::Constructor(global, NonNullHelper(Constify(arg0)), rv)));
    1007           0 :       if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
    1008           0 :         return false;
    1009             :       }
    1010           0 :       MOZ_ASSERT(!JS_IsExceptionPending(cx));
    1011             :       static_assert(!IsPointer<decltype(result)>::value,
    1012             :                     "NewObject implies that we need to keep the object alive with a strong reference.");
    1013           0 :       if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
    1014           0 :         MOZ_ASSERT(true || JS_IsExceptionPending(cx));
    1015           0 :         return false;
    1016             :       }
    1017           0 :       return true;
    1018             :       break;
    1019             :     }
    1020             :     case 2: {
    1021           0 :       binding_detail::FakeString arg0;
    1022           0 :       if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
    1023           0 :         return false;
    1024             :       }
    1025           0 :       if (args[1].isObject()) {
    1026             :         do {
    1027           0 :           binding_detail::AutoSequence<nsString> arg1;
    1028           0 :           JS::ForOfIterator iter(cx);
    1029           0 :           if (!iter.init(args[1], JS::ForOfIterator::AllowNonIterable)) {
    1030           0 :             return false;
    1031             :           }
    1032           0 :           if (!iter.valueIsIterable()) {
    1033           0 :             break;
    1034             :           }
    1035           0 :           binding_detail::AutoSequence<nsString> &arr = arg1;
    1036           0 :           JS::Rooted<JS::Value> temp(cx);
    1037             :           while (true) {
    1038             :             bool done;
    1039           0 :             if (!iter.next(&temp, &done)) {
    1040           0 :               return false;
    1041             :             }
    1042           0 :             if (done) {
    1043           0 :               break;
    1044             :             }
    1045           0 :             nsString* slotPtr = arr.AppendElement(mozilla::fallible);
    1046           0 :             if (!slotPtr) {
    1047           0 :               JS_ReportOutOfMemory(cx);
    1048           0 :               return false;
    1049             :             }
    1050           0 :             nsString& slot = *slotPtr;
    1051           0 :             if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
    1052           0 :               return false;
    1053             :             }
    1054           0 :           }
    1055           0 :           bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
    1056           0 :           Maybe<JSAutoCompartment> ac;
    1057           0 :           if (objIsXray) {
    1058           0 :             obj = js::CheckedUnwrap(obj);
    1059           0 :             if (!obj) {
    1060           0 :               return false;
    1061             :             }
    1062           0 :             ac.emplace(cx, obj);
    1063           0 :             if (!JS_WrapObject(cx, &desiredProto)) {
    1064           0 :               return false;
    1065             :             }
    1066             :           }
    1067           0 :           binding_detail::FastErrorResult rv;
    1068           0 :           auto result(StrongOrRawPtr<mozilla::dom::WebSocket>(mozilla::dom::WebSocket::Constructor(global, NonNullHelper(Constify(arg0)), Constify(arg1), rv)));
    1069           0 :           if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
    1070           0 :             return false;
    1071             :           }
    1072           0 :           MOZ_ASSERT(!JS_IsExceptionPending(cx));
    1073             :           static_assert(!IsPointer<decltype(result)>::value,
    1074             :                         "NewObject implies that we need to keep the object alive with a strong reference.");
    1075           0 :           if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
    1076           0 :             MOZ_ASSERT(true || JS_IsExceptionPending(cx));
    1077           0 :             return false;
    1078             :           }
    1079           0 :           return true;
    1080             :         } while (0);
    1081             :       }
    1082           0 :       bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
    1083           0 :       binding_detail::FakeString arg1;
    1084           0 :       if (!ConvertJSValueToString(cx, args[1], eStringify, eStringify, arg1)) {
    1085           0 :         return false;
    1086             :       }
    1087           0 :       Maybe<JSAutoCompartment> ac;
    1088           0 :       if (objIsXray) {
    1089           0 :         obj = js::CheckedUnwrap(obj);
    1090           0 :         if (!obj) {
    1091           0 :           return false;
    1092             :         }
    1093           0 :         ac.emplace(cx, obj);
    1094           0 :         if (!JS_WrapObject(cx, &desiredProto)) {
    1095           0 :           return false;
    1096             :         }
    1097             :       }
    1098           0 :       binding_detail::FastErrorResult rv;
    1099           0 :       auto result(StrongOrRawPtr<mozilla::dom::WebSocket>(mozilla::dom::WebSocket::Constructor(global, NonNullHelper(Constify(arg0)), NonNullHelper(Constify(arg1)), rv)));
    1100           0 :       if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
    1101           0 :         return false;
    1102             :       }
    1103           0 :       MOZ_ASSERT(!JS_IsExceptionPending(cx));
    1104             :       static_assert(!IsPointer<decltype(result)>::value,
    1105             :                     "NewObject implies that we need to keep the object alive with a strong reference.");
    1106           0 :       if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
    1107           0 :         MOZ_ASSERT(true || JS_IsExceptionPending(cx));
    1108           0 :         return false;
    1109             :       }
    1110           0 :       return true;
    1111             :       break;
    1112             :     }
    1113             :     default: {
    1114           0 :       return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WebSocket");
    1115             :       break;
    1116             :     }
    1117             :   }
    1118             :   MOZ_CRASH("We have an always-returning default case");
    1119             :   return false;
    1120             : }
    1121             : 
    1122             : static const js::ClassOps sInterfaceObjectClassOps = {
    1123             :     nullptr,               /* addProperty */
    1124             :     nullptr,               /* delProperty */
    1125             :     nullptr,               /* getProperty */
    1126             :     nullptr,               /* setProperty */
    1127             :     nullptr,               /* enumerate */
    1128             :     nullptr,               /* newEnumerate */
    1129             :     nullptr,               /* resolve */
    1130             :     nullptr,               /* mayResolve */
    1131             :     nullptr,               /* finalize */
    1132             :     _constructor, /* call */
    1133             :     nullptr,               /* hasInstance */
    1134             :     _constructor, /* construct */
    1135             :     nullptr,               /* trace */
    1136             : };
    1137             : 
    1138             : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
    1139             :   {
    1140             :     "Function",
    1141             :     JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
    1142             :     &sInterfaceObjectClassOps,
    1143             :     JS_NULL_CLASS_SPEC,
    1144             :     JS_NULL_CLASS_EXT,
    1145             :     &sInterfaceObjectClassObjectOps
    1146             :   },
    1147             :   eInterface,
    1148             :   true,
    1149             :   prototypes::id::WebSocket,
    1150             :   PrototypeTraits<prototypes::id::WebSocket>::Depth,
    1151             :   sNativePropertyHooks,
    1152             :   "function WebSocket() {\n    [native code]\n}",
    1153             :   EventTargetBinding::GetConstructorObject
    1154             : };
    1155             : 
    1156             : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
    1157             :   {
    1158             :     "WebSocketPrototype",
    1159             :     JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
    1160             :     JS_NULL_CLASS_OPS,
    1161             :     JS_NULL_CLASS_SPEC,
    1162             :     JS_NULL_CLASS_EXT,
    1163             :     JS_NULL_OBJECT_OPS
    1164             :   },
    1165             :   eInterfacePrototype,
    1166             :   false,
    1167             :   prototypes::id::WebSocket,
    1168             :   PrototypeTraits<prototypes::id::WebSocket>::Depth,
    1169             :   sNativePropertyHooks,
    1170             :   "[object WebSocketPrototype]",
    1171             :   EventTargetBinding::GetProtoObject
    1172             : };
    1173             : 
    1174             : JSObject*
    1175           0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
    1176             : {
    1177           0 :   return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
    1178             : }
    1179             : 
    1180             : static const js::ClassOps sClassOps = {
    1181             :   _addProperty, /* addProperty */
    1182             :   nullptr,               /* delProperty */
    1183             :   nullptr,               /* getProperty */
    1184             :   nullptr,               /* setProperty */
    1185             :   nullptr,               /* enumerate */
    1186             :   nullptr, /* newEnumerate */
    1187             :   nullptr, /* resolve */
    1188             :   nullptr, /* mayResolve */
    1189             :   _finalize, /* finalize */
    1190             :   nullptr, /* call */
    1191             :   nullptr,               /* hasInstance */
    1192             :   nullptr,               /* construct */
    1193             :   nullptr, /* trace */
    1194             : };
    1195             : 
    1196             : static const js::ClassExtension sClassExtension = {
    1197             :   nullptr, /* weakmapKeyDelegateOp */
    1198             :   _objectMoved /* objectMovedOp */
    1199             : };
    1200             : 
    1201             : static const DOMJSClass sClass = {
    1202             :   { "WebSocket",
    1203             :     JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
    1204             :     &sClassOps,
    1205             :     JS_NULL_CLASS_SPEC,
    1206             :     &sClassExtension,
    1207             :     JS_NULL_OBJECT_OPS
    1208             :   },
    1209             :   { prototypes::id::EventTarget, prototypes::id::WebSocket, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
    1210             :   IsBaseOf<nsISupports, mozilla::dom::WebSocket >::value,
    1211             :   sNativePropertyHooks,
    1212             :   FindAssociatedGlobalForNative<mozilla::dom::WebSocket>::Get,
    1213             :   GetProtoObjectHandle,
    1214             :   GetCCParticipant<mozilla::dom::WebSocket>::Get()
    1215             : };
    1216             : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
    1217             :               "Must have the right minimal number of reserved slots.");
    1218             : static_assert(1 >= 1,
    1219             :               "Must have enough reserved slots.");
    1220             : 
    1221             : const JSClass*
    1222           0 : GetJSClass()
    1223             : {
    1224           0 :   return sClass.ToJSClass();
    1225             : }
    1226             : 
    1227             : bool
    1228           0 : Wrap(JSContext* aCx, mozilla::dom::WebSocket* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
    1229             : {
    1230             :   MOZ_ASSERT(static_cast<mozilla::dom::WebSocket*>(aObject) ==
    1231             :              reinterpret_cast<mozilla::dom::WebSocket*>(aObject),
    1232             :              "Multiple inheritance for mozilla::dom::WebSocket is broken.");
    1233             :   MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
    1234             :              reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
    1235             :              "Multiple inheritance for mozilla::dom::EventTarget is broken.");
    1236           0 :   MOZ_ASSERT(ToSupportsIsCorrect(aObject));
    1237           0 :   MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
    1238           0 :   MOZ_ASSERT(!aCache->GetWrapper(),
    1239             :              "You should probably not be using Wrap() directly; use "
    1240             :              "GetOrCreateDOMReflector instead");
    1241             : 
    1242           0 :   MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
    1243             :              "nsISupports must be on our primary inheritance chain");
    1244             : 
    1245           0 :   JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
    1246           0 :   if (!global) {
    1247           0 :     return false;
    1248             :   }
    1249           0 :   MOZ_ASSERT(JS_IsGlobalObject(global));
    1250           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(global));
    1251             : 
    1252             :   // That might have ended up wrapping us already, due to the wonders
    1253             :   // of XBL.  Check for that, and bail out as needed.
    1254           0 :   aReflector.set(aCache->GetWrapper());
    1255           0 :   if (aReflector) {
    1256             : #ifdef DEBUG
    1257           0 :     binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
    1258             : #endif // DEBUG
    1259           0 :     return true;
    1260             :   }
    1261             : 
    1262           0 :   JSAutoCompartment ac(aCx, global);
    1263           0 :   JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
    1264           0 :   if (!canonicalProto) {
    1265           0 :     return false;
    1266             :   }
    1267           0 :   JS::Rooted<JSObject*> proto(aCx);
    1268           0 :   if (aGivenProto) {
    1269           0 :     proto = aGivenProto;
    1270             :     // Unfortunately, while aGivenProto was in the compartment of aCx
    1271             :     // coming in, we changed compartments to that of "parent" so may need
    1272             :     // to wrap the proto here.
    1273           0 :     if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
    1274           0 :       if (!JS_WrapObject(aCx, &proto)) {
    1275           0 :         return false;
    1276             :       }
    1277             :     }
    1278             :   } else {
    1279           0 :     proto = canonicalProto;
    1280             :   }
    1281             : 
    1282           0 :   BindingJSObjectCreator<mozilla::dom::WebSocket> creator(aCx);
    1283           0 :   creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
    1284           0 :   if (!aReflector) {
    1285           0 :     return false;
    1286             :   }
    1287             : 
    1288           0 :   aCache->SetWrapper(aReflector);
    1289           0 :   creator.InitializationSucceeded();
    1290             : 
    1291           0 :   MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
    1292             :              aCache->GetWrapperPreserveColor() == aReflector);
    1293             :   // If proto != canonicalProto, we have to preserve our wrapper;
    1294             :   // otherwise we won't be able to properly recreate it later, since
    1295             :   // we won't know what proto to use.  Note that we don't check
    1296             :   // aGivenProto here, since it's entirely possible (and even
    1297             :   // somewhat common) to have a non-null aGivenProto which is the
    1298             :   // same as canonicalProto.
    1299           0 :   if (proto != canonicalProto) {
    1300           0 :     PreserveWrapper(aObject);
    1301             :   }
    1302             : 
    1303           0 :   return true;
    1304             : }
    1305             : 
    1306             : const NativePropertyHooks sNativePropertyHooks[] = { {
    1307             :   nullptr,
    1308             :   nullptr,
    1309             :   nullptr,
    1310             :   { sNativeProperties.Upcast(), sChromeOnlyNativeProperties.Upcast() },
    1311             :   prototypes::id::WebSocket,
    1312             :   constructors::id::WebSocket,
    1313             :   EventTargetBinding::sNativePropertyHooks,
    1314             :   &DefaultXrayExpandoObjectClass
    1315             : } };
    1316             : 
    1317             : void
    1318           1 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
    1319             : {
    1320           1 :   JS::Handle<JSObject*> parentProto(EventTargetBinding::GetProtoObjectHandle(aCx));
    1321           1 :   if (!parentProto) {
    1322           0 :     return;
    1323             :   }
    1324             : 
    1325           1 :   JS::Handle<JSObject*> constructorProto(EventTargetBinding::GetConstructorObjectHandle(aCx));
    1326           1 :   if (!constructorProto) {
    1327           0 :     return;
    1328             :   }
    1329             : 
    1330             :   static bool sIdsInited = false;
    1331           1 :   if (!sIdsInited && NS_IsMainThread()) {
    1332           0 :     if (!InitIds(aCx, sNativeProperties.Upcast())) {
    1333           0 :       return;
    1334             :     }
    1335           0 :     if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) {
    1336           0 :       return;
    1337             :     }
    1338           0 :     sIdsInited = true;
    1339             :   }
    1340             : 
    1341           1 :   JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::WebSocket);
    1342           1 :   JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebSocket);
    1343           2 :   dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
    1344             :                               &sPrototypeClass.mBase, protoCache,
    1345             :                               constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr,
    1346             :                               interfaceCache,
    1347             :                               sNativeProperties.Upcast(),
    1348           1 :                               nsContentUtils::ThreadsafeIsSystemCaller(aCx) ? sChromeOnlyNativeProperties.Upcast() : nullptr,
    1349             :                               "WebSocket", aDefineOnGlobal,
    1350             :                               nullptr,
    1351           1 :                               false);
    1352             : }
    1353             : 
    1354             : JS::Handle<JSObject*>
    1355           0 : GetProtoObjectHandle(JSContext* aCx)
    1356             : {
    1357             :   /* Get the interface prototype object for this class.  This will create the
    1358             :      object as needed. */
    1359           0 :   bool aDefineOnGlobal = true;
    1360             : 
    1361             :   /* Make sure our global is sane.  Hopefully we can remove this sometime */
    1362           0 :   JSObject* global = JS::CurrentGlobalOrNull(aCx);
    1363           0 :   if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
    1364           0 :     return nullptr;
    1365             :   }
    1366             : 
    1367             :   /* Check to see whether the interface objects are already installed */
    1368           0 :   ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
    1369           0 :   if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::WebSocket)) {
    1370           0 :     JS::Rooted<JSObject*> rootedGlobal(aCx, global);
    1371           0 :     CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
    1372             :   }
    1373             : 
    1374             :   /*
    1375             :    * The object might _still_ be null, but that's OK.
    1376             :    *
    1377             :    * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
    1378             :    * traced by TraceProtoAndIfaceCache() and its contents are never
    1379             :    * changed after they have been set.
    1380             :    *
    1381             :    * Calling address() avoids the read read barrier that does gray
    1382             :    * unmarking, but it's not possible for the object to be gray here.
    1383             :    */
    1384             : 
    1385           0 :   const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::WebSocket);
    1386           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
    1387           0 :   return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
    1388             : }
    1389             : 
    1390             : JS::Handle<JSObject*>
    1391           1 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
    1392             : {
    1393             :   /* Get the interface object for this class.  This will create the object as
    1394             :      needed. */
    1395             : 
    1396             :   /* Make sure our global is sane.  Hopefully we can remove this sometime */
    1397           1 :   JSObject* global = JS::CurrentGlobalOrNull(aCx);
    1398           1 :   if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
    1399           0 :     return nullptr;
    1400             :   }
    1401             : 
    1402             :   /* Check to see whether the interface objects are already installed */
    1403           1 :   ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
    1404           1 :   if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::WebSocket)) {
    1405           2 :     JS::Rooted<JSObject*> rootedGlobal(aCx, global);
    1406           1 :     CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
    1407             :   }
    1408             : 
    1409             :   /*
    1410             :    * The object might _still_ be null, but that's OK.
    1411             :    *
    1412             :    * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
    1413             :    * traced by TraceProtoAndIfaceCache() and its contents are never
    1414             :    * changed after they have been set.
    1415             :    *
    1416             :    * Calling address() avoids the read read barrier that does gray
    1417             :    * unmarking, but it's not possible for the object to be gray here.
    1418             :    */
    1419             : 
    1420           1 :   const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::WebSocket);
    1421           1 :   MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
    1422           1 :   return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
    1423             : }
    1424             : 
    1425             : JSObject*
    1426           1 : GetConstructorObject(JSContext* aCx)
    1427             : {
    1428           1 :   return GetConstructorObjectHandle(aCx);
    1429             : }
    1430             : 
    1431             : } // namespace WebSocketBinding
    1432             : 
    1433             : 
    1434             : 
    1435             : } // namespace dom
    1436             : } // namespace mozilla

Generated by: LCOV version 1.13