Bug 1282253 - Get rid of XHR::ResponseTypeEnum, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Mon, 27 Jun 2016 19:13:41 +0200
changeset 381537 9f1e2864e569ced540dbc6dc75d7709a7c47fade
parent 381536 155012d3d3731e10e085ae0841d308ca0515a35c
child 381538 3e53a0aae914100d4b5cb290098f37039317083d
push id21504
push userbmo:npang@mozilla.com
push dateMon, 27 Jun 2016 18:10:09 +0000
reviewerssmaug
bugs1282253
milestone50.0a1
Bug 1282253 - Get rid of XHR::ResponseTypeEnum, r=smaug
dom/xhr/XMLHttpRequestMainThread.cpp
dom/xhr/XMLHttpRequestMainThread.h
--- a/dom/xhr/XMLHttpRequestMainThread.cpp
+++ b/dom/xhr/XMLHttpRequestMainThread.cpp
@@ -174,17 +174,17 @@ static void AddLoadFlags(nsIRequest *req
 //
 /////////////////////////////////////////////
 
 bool
 XMLHttpRequestMainThread::sDontWarnAboutSyncXHR = false;
 
 XMLHttpRequestMainThread::XMLHttpRequestMainThread()
   : mResponseBodyDecodedPos(0),
-    mResponseType(XML_HTTP_RESPONSE_TYPE_DEFAULT),
+    mResponseType(XMLHttpRequestResponseType::_empty),
     mRequestObserver(nullptr),
     mState(XML_HTTP_REQUEST_UNSENT | XML_HTTP_REQUEST_ASYNC),
     mUploadTransferred(0), mUploadTotal(0), mUploadComplete(true),
     mProgressSinceLastProgressEvent(false),
     mRequestSentTime(0), mTimeoutMilliseconds(0),
     mErrorLoad(false), mWaitingForOnStopRequest(false),
     mProgressTimerIsActive(false),
     mIsHtml(false),
@@ -194,19 +194,16 @@ XMLHttpRequestMainThread::XMLHttpRequest
     mIsAnon(false),
     mFirstStartRequestSeen(false),
     mInLoadProgressEvent(false),
     mResultJSON(JS::UndefinedValue()),
     mResultArrayBuffer(nullptr),
     mIsMappedArrayBuffer(false),
     mXPCOMifier(nullptr)
 {
-#ifdef DEBUG
-  StaticAssertions();
-#endif
 }
 
 XMLHttpRequestMainThread::~XMLHttpRequestMainThread()
 {
   mState |= XML_HTTP_REQUEST_DELETED;
 
   if (mState & (XML_HTTP_REQUEST_SENT |
                 XML_HTTP_REQUEST_LOADING)) {
@@ -486,18 +483,18 @@ XMLHttpRequestMainThread::GetResponseXML
   }
 
   return CallQueryInterface(responseXML, aResponseXML);
 }
 
 nsIDocument*
 XMLHttpRequestMainThread::GetResponseXML(ErrorResult& aRv)
 {
-  if (mResponseType != XML_HTTP_RESPONSE_TYPE_DEFAULT &&
-      mResponseType != XML_HTTP_RESPONSE_TYPE_DOCUMENT) {
+  if (mResponseType != XMLHttpRequestResponseType::_empty &&
+      mResponseType != XMLHttpRequestResponseType::Document) {
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     return nullptr;
   }
   if (mWarnAboutSyncHtml) {
     mWarnAboutSyncHtml = false;
     LogMessage("HTMLSyncXHRWarning", GetOwner());
   }
   if (!(XML_HTTP_REQUEST_DONE & mState)) {
@@ -511,33 +508,33 @@ XMLHttpRequestMainThread::GetResponseXML
  * from HTTP headers.
  */
 nsresult
 XMLHttpRequestMainThread::DetectCharset()
 {
   mResponseCharset.Truncate();
   mDecoder = nullptr;
 
-  if (mResponseType != XML_HTTP_RESPONSE_TYPE_DEFAULT &&
-      mResponseType != XML_HTTP_RESPONSE_TYPE_TEXT &&
-      mResponseType != XML_HTTP_RESPONSE_TYPE_JSON &&
-      mResponseType != XML_HTTP_RESPONSE_TYPE_CHUNKED_TEXT) {
+  if (mResponseType != XMLHttpRequestResponseType::_empty &&
+      mResponseType != XMLHttpRequestResponseType::Text &&
+      mResponseType != XMLHttpRequestResponseType::Json &&
+      mResponseType != XMLHttpRequestResponseType::Moz_chunked_text) {
     return NS_OK;
   }
 
   nsAutoCString charsetVal;
   bool ok = mChannel &&
             NS_SUCCEEDED(mChannel->GetContentCharset(charsetVal)) &&
             EncodingUtils::FindEncodingForLabel(charsetVal, mResponseCharset);
   if (!ok || mResponseCharset.IsEmpty()) {
     // MS documentation states UTF-8 is default for responseText
     mResponseCharset.AssignLiteral("UTF-8");
   }
 
-  if (mResponseType == XML_HTTP_RESPONSE_TYPE_JSON &&
+  if (mResponseType == XMLHttpRequestResponseType::Json &&
       !mResponseCharset.EqualsLiteral("UTF-8")) {
     // The XHR spec says only UTF-8 is supported for responseType == "json"
     LogMessage("JSONCharsetWarning", GetOwner());
     mResponseCharset.AssignLiteral("UTF-8");
   }
 
   mDecoder = EncodingUtils::DecoderForEncoding(mResponseCharset);
 
@@ -598,24 +595,24 @@ XMLHttpRequestMainThread::GetResponseTex
 }
 
 void
 XMLHttpRequestMainThread::GetResponseText(nsAString& aResponseText,
                                           ErrorResult& aRv)
 {
   aResponseText.Truncate();
 
-  if (mResponseType != XML_HTTP_RESPONSE_TYPE_DEFAULT &&
-      mResponseType != XML_HTTP_RESPONSE_TYPE_TEXT &&
-      mResponseType != XML_HTTP_RESPONSE_TYPE_CHUNKED_TEXT) {
+  if (mResponseType != XMLHttpRequestResponseType::_empty &&
+      mResponseType != XMLHttpRequestResponseType::Text &&
+      mResponseType != XMLHttpRequestResponseType::Moz_chunked_text) {
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     return;
   }
 
-  if (mResponseType == XML_HTTP_RESPONSE_TYPE_CHUNKED_TEXT &&
+  if (mResponseType == XMLHttpRequestResponseType::Moz_chunked_text &&
       !mInLoadProgressEvent) {
     aResponseText.SetIsVoid(true);
     return;
   }
 
   if (!(mState & (XML_HTTP_REQUEST_DONE | XML_HTTP_REQUEST_LOADING))) {
     return;
   }
@@ -701,113 +698,40 @@ XMLHttpRequestMainThread::CreatePartialB
     mChannel->GetContentType(contentType);
   }
 
   mResponseBlob = mBlobSet->GetBlobInternal(GetOwner(), contentType, aRv);
 }
 
 NS_IMETHODIMP XMLHttpRequestMainThread::GetResponseType(nsAString& aResponseType)
 {
-  switch (mResponseType) {
-  case XML_HTTP_RESPONSE_TYPE_DEFAULT:
-    aResponseType.Truncate();
-    break;
-  case XML_HTTP_RESPONSE_TYPE_ARRAYBUFFER:
-    aResponseType.AssignLiteral("arraybuffer");
-    break;
-  case XML_HTTP_RESPONSE_TYPE_BLOB:
-    aResponseType.AssignLiteral("blob");
-    break;
-  case XML_HTTP_RESPONSE_TYPE_DOCUMENT:
-    aResponseType.AssignLiteral("document");
-    break;
-  case XML_HTTP_RESPONSE_TYPE_TEXT:
-    aResponseType.AssignLiteral("text");
-    break;
-  case XML_HTTP_RESPONSE_TYPE_JSON:
-    aResponseType.AssignLiteral("json");
-    break;
-  case XML_HTTP_RESPONSE_TYPE_CHUNKED_TEXT:
-    aResponseType.AssignLiteral("moz-chunked-text");
-    break;
-  case XML_HTTP_RESPONSE_TYPE_CHUNKED_ARRAYBUFFER:
-    aResponseType.AssignLiteral("moz-chunked-arraybuffer");
-    break;
-  case XML_HTTP_RESPONSE_TYPE_MOZ_BLOB:
-    aResponseType.AssignLiteral("moz-blob");
-    break;
-  default:
-    NS_ERROR("Should not happen");
+  MOZ_ASSERT(mResponseType < XMLHttpRequestResponseType::EndGuard_);
+  const EnumEntry& entry =
+    XMLHttpRequestResponseTypeValues::strings[static_cast<uint32_t>(mResponseType)];
+  aResponseType.AssignASCII(entry.value, entry.length);
+  return NS_OK;
+}
+
+NS_IMETHODIMP XMLHttpRequestMainThread::SetResponseType(const nsAString& aResponseType)
+{
+  uint32_t i = 0;
+  for (const EnumEntry* entry = XMLHttpRequestResponseTypeValues::strings;
+       entry->value; ++entry, ++i) {
+    if (aResponseType.EqualsASCII(entry->value, entry->length)) {
+      ErrorResult rv;
+      SetResponseType(static_cast<XMLHttpRequestResponseType>(i), rv);
+      return rv.StealNSResult();
+    }
   }
 
   return NS_OK;
 }
 
-#ifdef DEBUG
 void
-XMLHttpRequestMainThread::StaticAssertions()
-{
-#define ASSERT_ENUM_EQUAL(_lc, _uc) \
-  static_assert(\
-    static_cast<int>(XMLHttpRequestResponseType::_lc)  \
-    == XML_HTTP_RESPONSE_TYPE_ ## _uc, \
-    #_uc " should match")
-
-  ASSERT_ENUM_EQUAL(_empty, DEFAULT);
-  ASSERT_ENUM_EQUAL(Arraybuffer, ARRAYBUFFER);
-  ASSERT_ENUM_EQUAL(Blob, BLOB);
-  ASSERT_ENUM_EQUAL(Document, DOCUMENT);
-  ASSERT_ENUM_EQUAL(Json, JSON);
-  ASSERT_ENUM_EQUAL(Text, TEXT);
-  ASSERT_ENUM_EQUAL(Moz_chunked_text, CHUNKED_TEXT);
-  ASSERT_ENUM_EQUAL(Moz_chunked_arraybuffer, CHUNKED_ARRAYBUFFER);
-  ASSERT_ENUM_EQUAL(Moz_blob, MOZ_BLOB);
-#undef ASSERT_ENUM_EQUAL
-}
-#endif
-
-NS_IMETHODIMP XMLHttpRequestMainThread::SetResponseType(const nsAString& aResponseType)
-{
-  XMLHttpRequestMainThread::ResponseTypeEnum responseType;
-  if (aResponseType.IsEmpty()) {
-    responseType = XML_HTTP_RESPONSE_TYPE_DEFAULT;
-  } else if (aResponseType.EqualsLiteral("arraybuffer")) {
-    responseType = XML_HTTP_RESPONSE_TYPE_ARRAYBUFFER;
-  } else if (aResponseType.EqualsLiteral("blob")) {
-    responseType = XML_HTTP_RESPONSE_TYPE_BLOB;
-  } else if (aResponseType.EqualsLiteral("document")) {
-    responseType = XML_HTTP_RESPONSE_TYPE_DOCUMENT;
-  } else if (aResponseType.EqualsLiteral("text")) {
-    responseType = XML_HTTP_RESPONSE_TYPE_TEXT;
-  } else if (aResponseType.EqualsLiteral("json")) {
-    responseType = XML_HTTP_RESPONSE_TYPE_JSON;
-  } else if (aResponseType.EqualsLiteral("moz-chunked-text")) {
-    responseType = XML_HTTP_RESPONSE_TYPE_CHUNKED_TEXT;
-  } else if (aResponseType.EqualsLiteral("moz-chunked-arraybuffer")) {
-    responseType = XML_HTTP_RESPONSE_TYPE_CHUNKED_ARRAYBUFFER;
-  } else if (aResponseType.EqualsLiteral("moz-blob")) {
-    responseType = XML_HTTP_RESPONSE_TYPE_MOZ_BLOB;
-  } else {
-    return NS_OK;
-  }
-
-  ErrorResult rv;
-  SetResponseType(responseType, rv);
-  return rv.StealNSResult();
-}
-
-void
-XMLHttpRequestMainThread::SetResponseType(XMLHttpRequestResponseType aType,
-                                          ErrorResult& aRv)
-{
-  SetResponseType(ResponseTypeEnum(static_cast<int>(aType)), aRv);
-}
-
-void
-XMLHttpRequestMainThread::SetResponseType(XMLHttpRequestMainThread::ResponseTypeEnum aResponseType,
+XMLHttpRequestMainThread::SetResponseType(XMLHttpRequestResponseType aResponseType,
                                           ErrorResult& aRv)
 {
   // If the state is LOADING or DONE raise an INVALID_STATE_ERR exception
   // and terminate these steps.
   if ((mState & (XML_HTTP_REQUEST_LOADING | XML_HTTP_REQUEST_DONE))) {
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     return;
   }
@@ -816,62 +740,61 @@ XMLHttpRequestMainThread::SetResponseTyp
   if (HasOrHasHadOwner() &&
       !(mState & (XML_HTTP_REQUEST_UNSENT | XML_HTTP_REQUEST_ASYNC))) {
     LogMessage("ResponseTypeSyncXHRWarning", GetOwner());
     aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
     return;
   }
 
   if (!(mState & XML_HTTP_REQUEST_ASYNC) &&
-      (aResponseType == XML_HTTP_RESPONSE_TYPE_CHUNKED_TEXT ||
-       aResponseType == XML_HTTP_RESPONSE_TYPE_CHUNKED_ARRAYBUFFER)) {
+      (aResponseType == XMLHttpRequestResponseType::Moz_chunked_text ||
+       aResponseType == XMLHttpRequestResponseType::Moz_chunked_arraybuffer)) {
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     return;
   }
 
   // Set the responseType attribute's value to the given value.
   mResponseType = aResponseType;
-
 }
 
 NS_IMETHODIMP
 XMLHttpRequestMainThread::GetResponse(JSContext *aCx, JS::MutableHandle<JS::Value> aResult)
 {
   ErrorResult rv;
   GetResponse(aCx, aResult, rv);
   return rv.StealNSResult();
 }
 
 void
 XMLHttpRequestMainThread::GetResponse(JSContext* aCx,
                                       JS::MutableHandle<JS::Value> aResponse,
                                       ErrorResult& aRv)
 {
   switch (mResponseType) {
-  case XML_HTTP_RESPONSE_TYPE_DEFAULT:
-  case XML_HTTP_RESPONSE_TYPE_TEXT:
-  case XML_HTTP_RESPONSE_TYPE_CHUNKED_TEXT:
+  case XMLHttpRequestResponseType::_empty:
+  case XMLHttpRequestResponseType::Text:
+  case XMLHttpRequestResponseType::Moz_chunked_text:
   {
     nsString str;
     aRv = GetResponseText(str);
     if (aRv.Failed()) {
       return;
     }
     if (!xpc::StringToJsval(aCx, str, aResponse)) {
       aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
     }
     return;
   }
 
-  case XML_HTTP_RESPONSE_TYPE_ARRAYBUFFER:
-  case XML_HTTP_RESPONSE_TYPE_CHUNKED_ARRAYBUFFER:
+  case XMLHttpRequestResponseType::Arraybuffer:
+  case XMLHttpRequestResponseType::Moz_chunked_arraybuffer:
   {
-    if (!(mResponseType == XML_HTTP_RESPONSE_TYPE_ARRAYBUFFER &&
+    if (!(mResponseType == XMLHttpRequestResponseType::Arraybuffer &&
           mState & XML_HTTP_REQUEST_DONE) &&
-        !(mResponseType == XML_HTTP_RESPONSE_TYPE_CHUNKED_ARRAYBUFFER &&
+        !(mResponseType == XMLHttpRequestResponseType::Moz_chunked_arraybuffer &&
           mInLoadProgressEvent)) {
       aResponse.setNull();
       return;
     }
 
     if (!mResultArrayBuffer) {
       RootJSResultObjects();
 
@@ -880,21 +803,21 @@ XMLHttpRequestMainThread::GetResponse(JS
         aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
         return;
       }
     }
     JS::ExposeObjectToActiveJS(mResultArrayBuffer);
     aResponse.setObject(*mResultArrayBuffer);
     return;
   }
-  case XML_HTTP_RESPONSE_TYPE_BLOB:
-  case XML_HTTP_RESPONSE_TYPE_MOZ_BLOB:
+  case XMLHttpRequestResponseType::Blob:
+  case XMLHttpRequestResponseType::Moz_blob:
   {
     if (!(mState & XML_HTTP_REQUEST_DONE)) {
-      if (mResponseType != XML_HTTP_RESPONSE_TYPE_MOZ_BLOB) {
+      if (mResponseType != XMLHttpRequestResponseType::Moz_blob) {
         aResponse.setNull();
         return;
       }
 
       if (!mResponseBlob) {
         CreatePartialBlob(aRv);
       }
     }
@@ -902,27 +825,27 @@ XMLHttpRequestMainThread::GetResponse(JS
     if (!mResponseBlob) {
       aResponse.setNull();
       return;
     }
 
     GetOrCreateDOMReflector(aCx, mResponseBlob, aResponse);
     return;
   }
-  case XML_HTTP_RESPONSE_TYPE_DOCUMENT:
+  case XMLHttpRequestResponseType::Document:
   {
     if (!(mState & XML_HTTP_REQUEST_DONE) || !mResponseXML) {
       aResponse.setNull();
       return;
     }
 
     aRv = nsContentUtils::WrapNative(aCx, mResponseXML, aResponse);
     return;
   }
-  case XML_HTTP_RESPONSE_TYPE_JSON:
+  case XMLHttpRequestResponseType::Json:
   {
     if (!(mState & XML_HTTP_REQUEST_DONE)) {
       aResponse.setNull();
       return;
     }
 
     if (mResultJSON.isUndefined()) {
       aRv = CreateResponseParsedJSON(aCx);
@@ -1479,21 +1402,21 @@ XMLHttpRequestMainThread::Open(const nsA
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // sync request is not allowed to use responseType or timeout
   // in window context
   if (!async && HasOrHasHadOwner() &&
       (mTimeoutMilliseconds ||
-       mResponseType != XML_HTTP_RESPONSE_TYPE_DEFAULT)) {
+       mResponseType != XMLHttpRequestResponseType::_empty)) {
     if (mTimeoutMilliseconds) {
       LogMessage("TimeoutSyncXHRWarning", GetOwner());
     }
-    if (mResponseType != XML_HTTP_RESPONSE_TYPE_DEFAULT) {
+    if (mResponseType != XMLHttpRequestResponseType::_empty) {
       LogMessage("ResponseTypeSyncXHRWarning", GetOwner());
     }
     return NS_ERROR_DOM_INVALID_ACCESS_ERR;
   }
 
   nsCOMPtr<nsIURI> uri;
 
   if (mState & (XML_HTTP_REQUEST_OPENED |
@@ -1669,48 +1592,48 @@ XMLHttpRequestMainThread::StreamReaderFu
   XMLHttpRequestMainThread* xmlHttpRequest = static_cast<XMLHttpRequestMainThread*>(closure);
   if (!xmlHttpRequest || !writeCount) {
     NS_WARNING("XMLHttpRequest cannot read from stream: no closure or writeCount");
     return NS_ERROR_FAILURE;
   }
 
   nsresult rv = NS_OK;
 
-  if (xmlHttpRequest->mResponseType == XML_HTTP_RESPONSE_TYPE_BLOB ||
-      xmlHttpRequest->mResponseType == XML_HTTP_RESPONSE_TYPE_MOZ_BLOB) {
+  if (xmlHttpRequest->mResponseType == XMLHttpRequestResponseType::Blob ||
+      xmlHttpRequest->mResponseType == XMLHttpRequestResponseType::Moz_blob) {
     if (!xmlHttpRequest->mDOMBlob) {
       if (!xmlHttpRequest->mBlobSet) {
         xmlHttpRequest->mBlobSet = new BlobSet();
       }
       rv = xmlHttpRequest->mBlobSet->AppendVoidPtr(fromRawSegment, count);
     }
     // Clear the cache so that the blob size is updated.
-    if (xmlHttpRequest->mResponseType == XML_HTTP_RESPONSE_TYPE_MOZ_BLOB) {
+    if (xmlHttpRequest->mResponseType == XMLHttpRequestResponseType::Moz_blob) {
       xmlHttpRequest->mResponseBlob = nullptr;
     }
-  } else if ((xmlHttpRequest->mResponseType == XML_HTTP_RESPONSE_TYPE_ARRAYBUFFER &&
+  } else if ((xmlHttpRequest->mResponseType == XMLHttpRequestResponseType::Arraybuffer &&
               !xmlHttpRequest->mIsMappedArrayBuffer) ||
-             xmlHttpRequest->mResponseType == XML_HTTP_RESPONSE_TYPE_CHUNKED_ARRAYBUFFER) {
+             xmlHttpRequest->mResponseType == XMLHttpRequestResponseType::Moz_chunked_arraybuffer) {
     // get the initial capacity to something reasonable to avoid a bunch of reallocs right
     // at the start
     if (xmlHttpRequest->mArrayBufferBuilder.capacity() == 0)
       xmlHttpRequest->mArrayBufferBuilder.setCapacity(PR_MAX(count, XML_HTTP_REQUEST_ARRAYBUFFER_MIN_SIZE));
 
     xmlHttpRequest->mArrayBufferBuilder.append(reinterpret_cast<const uint8_t*>(fromRawSegment), count,
                                                XML_HTTP_REQUEST_ARRAYBUFFER_MAX_GROWTH);
-  } else if (xmlHttpRequest->mResponseType == XML_HTTP_RESPONSE_TYPE_DEFAULT &&
+  } else if (xmlHttpRequest->mResponseType == XMLHttpRequestResponseType::_empty &&
              xmlHttpRequest->mResponseXML) {
     // Copy for our own use
     if (!xmlHttpRequest->mResponseBody.Append(fromRawSegment, count, fallible)) {
       return NS_ERROR_OUT_OF_MEMORY;
     }
-  } else if (xmlHttpRequest->mResponseType == XML_HTTP_RESPONSE_TYPE_DEFAULT ||
-             xmlHttpRequest->mResponseType == XML_HTTP_RESPONSE_TYPE_TEXT ||
-             xmlHttpRequest->mResponseType == XML_HTTP_RESPONSE_TYPE_JSON ||
-             xmlHttpRequest->mResponseType == XML_HTTP_RESPONSE_TYPE_CHUNKED_TEXT) {
+  } else if (xmlHttpRequest->mResponseType == XMLHttpRequestResponseType::_empty ||
+             xmlHttpRequest->mResponseType == XMLHttpRequestResponseType::Text ||
+             xmlHttpRequest->mResponseType == XMLHttpRequestResponseType::Json ||
+             xmlHttpRequest->mResponseType == XMLHttpRequestResponseType::Moz_chunked_text) {
     NS_ASSERTION(!xmlHttpRequest->mResponseXML,
                  "We shouldn't be parsing a doc here");
     xmlHttpRequest->AppendToResponseText(fromRawSegment, count);
   }
 
   if (xmlHttpRequest->mState & XML_HTTP_REQUEST_PARSEBODY) {
     // Give the same data to the parser.
 
@@ -1775,18 +1698,18 @@ XMLHttpRequestMainThread::OnDataAvailabl
 {
   NS_ENSURE_ARG_POINTER(inStr);
 
   MOZ_ASSERT(mContext.get() == ctxt,"start context different from OnDataAvailable context");
 
   mProgressSinceLastProgressEvent = true;
 
   bool cancelable = false;
-  if ((mResponseType == XML_HTTP_RESPONSE_TYPE_BLOB ||
-       mResponseType == XML_HTTP_RESPONSE_TYPE_MOZ_BLOB) && !mDOMBlob) {
+  if ((mResponseType == XMLHttpRequestResponseType::Blob ||
+       mResponseType == XMLHttpRequestResponseType::Moz_blob) && !mDOMBlob) {
     cancelable = CreateDOMBlob(request);
     // The nsIStreamListener contract mandates us
     // to read from the stream before returning.
   }
 
   uint32_t totalRead;
   nsresult rv = inStr->ReadSegments(XMLHttpRequestMainThread::StreamReaderFunc,
                                     (void*)this, count, &totalRead);
@@ -1879,17 +1802,18 @@ XMLHttpRequestMainThread::OnStartRequest
 
   if (!mOverrideMimeType.IsEmpty()) {
     channel->SetContentType(NS_ConvertUTF16toUTF8(mOverrideMimeType));
   }
 
   DetectCharset();
 
   // Set up arraybuffer
-  if (mResponseType == XML_HTTP_RESPONSE_TYPE_ARRAYBUFFER && NS_SUCCEEDED(status)) {
+  if (mResponseType == XMLHttpRequestResponseType::Arraybuffer &&
+      NS_SUCCEEDED(status)) {
     if (mIsMappedArrayBuffer) {
       nsCOMPtr<nsIJARChannel> jarChannel = do_QueryInterface(channel);
       if (jarChannel) {
         nsCOMPtr<nsIURI> uri;
         rv = channel->GetURI(getter_AddRefs(uri));
         if (NS_SUCCEEDED(rv)) {
           nsAutoCString file;
           nsAutoCString scheme;
@@ -1928,18 +1852,18 @@ XMLHttpRequestMainThread::OnStartRequest
           contentLength > 0 &&
           contentLength < XML_HTTP_REQUEST_MAX_CONTENT_LENGTH_PREALLOCATE) {
         mArrayBufferBuilder.setCapacity(static_cast<int32_t>(contentLength));
       }
     }
   }
 
   // Set up responseXML
-  bool parseBody = mResponseType == XML_HTTP_RESPONSE_TYPE_DEFAULT ||
-                     mResponseType == XML_HTTP_RESPONSE_TYPE_DOCUMENT;
+  bool parseBody = mResponseType == XMLHttpRequestResponseType::_empty ||
+                   mResponseType == XMLHttpRequestResponseType::Document;
   nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(mChannel));
   if (parseBody && httpChannel) {
     nsAutoCString method;
     httpChannel->GetRequestMethod(method);
     parseBody = !method.EqualsLiteral("HEAD");
   }
 
   mIsHtml = false;
@@ -1947,17 +1871,17 @@ XMLHttpRequestMainThread::OnStartRequest
   if (parseBody && NS_SUCCEEDED(status)) {
     // We can gain a huge performance win by not even trying to
     // parse non-XML data. This also protects us from the situation
     // where we have an XML document and sink, but HTML (or other)
     // parser, which can produce unreliable results.
     nsAutoCString type;
     channel->GetContentType(type);
 
-    if ((mResponseType == XML_HTTP_RESPONSE_TYPE_DOCUMENT) &&
+    if ((mResponseType == XMLHttpRequestResponseType::Document) &&
         type.EqualsLiteral("text/html")) {
       // HTML parsing is only supported for responseType == "document" to
       // avoid running the parser and, worse, populating responseXML for
       // legacy users of XHR who use responseType == "" for retrieving the
       // responseText of text/html resources. This legacy case is so common
       // that it's not useful to emit a warning about it.
       if (!(mState & XML_HTTP_REQUEST_ASYNC)) {
         // We don't make cool new features available in the bad synchronous
@@ -2098,18 +2022,18 @@ XMLHttpRequestMainThread::OnStopRequest(
   // If we're received data since the last progress event, make sure to fire
   // an event for it, except in the HTML case, defer the last progress event
   // until the parser is done.
   if (!mIsHtml) {
     MaybeDispatchProgressEvents(true);
   }
 
   if (NS_SUCCEEDED(status) &&
-      (mResponseType == XML_HTTP_RESPONSE_TYPE_BLOB ||
-       mResponseType == XML_HTTP_RESPONSE_TYPE_MOZ_BLOB)) {
+      (mResponseType == XMLHttpRequestResponseType::Blob ||
+       mResponseType == XMLHttpRequestResponseType::Moz_blob)) {
     if (!mDOMBlob) {
       CreateDOMBlob(request);
     }
     if (mDOMBlob) {
       mResponseBlob = mDOMBlob;
       mDOMBlob = nullptr;
     } else {
       // mBlobSet can be null if the channel is non-file non-cacheable
@@ -2128,19 +2052,19 @@ XMLHttpRequestMainThread::OnStopRequest(
 
       if (NS_WARN_IF(rv.Failed())) {
         return rv.StealNSResult();
       }
     }
     NS_ASSERTION(mResponseBody.IsEmpty(), "mResponseBody should be empty");
     NS_ASSERTION(mResponseText.IsEmpty(), "mResponseText should be empty");
   } else if (NS_SUCCEEDED(status) &&
-             ((mResponseType == XML_HTTP_RESPONSE_TYPE_ARRAYBUFFER &&
+             ((mResponseType == XMLHttpRequestResponseType::Arraybuffer &&
                !mIsMappedArrayBuffer) ||
-              mResponseType == XML_HTTP_RESPONSE_TYPE_CHUNKED_ARRAYBUFFER)) {
+              mResponseType == XMLHttpRequestResponseType::Moz_chunked_arraybuffer)) {
     // set the capacity down to the actual length, to realloc back
     // down to the actual size
     if (!mArrayBufferBuilder.setCapacity(mArrayBufferBuilder.length())) {
       // this should never happen!
       status = NS_ERROR_UNEXPECTED;
     }
   }
 
@@ -2798,17 +2722,17 @@ XMLHttpRequestMainThread::Send(nsIVarian
   // Set up the preflight if needed
   if (!IsSystemXHR()) {
     nsCOMPtr<nsILoadInfo> loadInfo = mChannel->GetLoadInfo();
     loadInfo->SetCorsPreflightInfo(mCORSUnsafeHeaders,
                                    mState & XML_HTTP_REQUEST_HAD_UPLOAD_LISTENERS_ON_SEND);
   }
 
   mIsMappedArrayBuffer = false;
-  if (mResponseType == XML_HTTP_RESPONSE_TYPE_ARRAYBUFFER &&
+  if (mResponseType == XMLHttpRequestResponseType::Arraybuffer &&
       Preferences::GetBool("dom.mapped_arraybuffer.enabled", false)) {
     nsCOMPtr<nsIURI> uri;
     nsAutoCString scheme;
 
     rv = mChannel->GetURI(getter_AddRefs(uri));
     if (NS_SUCCEEDED(rv)) {
       uri->GetScheme(scheme);
       if (scheme.LowerCaseEqualsLiteral("app") ||
@@ -3337,18 +3261,18 @@ XMLHttpRequestMainThread::MaybeDispatchP
     if (aFinalProgress) {
       mLoadTotal = mLoadTransferred;
     }
     mInLoadProgressEvent = true;
     DispatchProgressEvent(this, NS_LITERAL_STRING(PROGRESS_STR),
                           mLoadLengthComputable, mLoadTransferred,
                           mLoadTotal);
     mInLoadProgressEvent = false;
-    if (mResponseType == XML_HTTP_RESPONSE_TYPE_CHUNKED_TEXT ||
-        mResponseType == XML_HTTP_RESPONSE_TYPE_CHUNKED_ARRAYBUFFER) {
+    if (mResponseType == XMLHttpRequestResponseType::Moz_chunked_text ||
+        mResponseType == XMLHttpRequestResponseType::Moz_chunked_arraybuffer) {
       mResponseBody.Truncate();
       mResponseText.Truncate();
       mResultArrayBuffer = nullptr;
       mArrayBufferBuilder.reset();
     }
   }
 
   mProgressSinceLastProgressEvent = false;
--- a/dom/xhr/XMLHttpRequestMainThread.h
+++ b/dom/xhr/XMLHttpRequestMainThread.h
@@ -177,20 +177,16 @@ public:
   NS_DECL_NSITIMERCALLBACK
 
   // nsISizeOfEventTarget
   virtual size_t
     SizeOfEventTargetIncludingThis(MallocSizeOf aMallocSizeOf) const override;
 
   NS_REALLY_FORWARD_NSIDOMEVENTTARGET(XMLHttpRequestEventTarget)
 
-#ifdef DEBUG
-  void StaticAssertions();
-#endif
-
   // states
   virtual uint16_t ReadyState() const override;
 
   // request
   virtual void
   Open(const nsACString& aMethod, const nsAString& aUrl,
        ErrorResult& aRv) override
   {
@@ -631,32 +627,17 @@ protected:
   // In cases where we've only received half a surrogate, the decoder itself
   // carries the state to remember this. Next time we receive more data we
   // simply feed the new data into the decoder which will handle the second
   // part of the surrogate.
   nsCOMPtr<nsIUnicodeDecoder> mDecoder;
 
   nsCString mResponseCharset;
 
-  enum ResponseTypeEnum {
-    XML_HTTP_RESPONSE_TYPE_DEFAULT,
-    XML_HTTP_RESPONSE_TYPE_ARRAYBUFFER,
-    XML_HTTP_RESPONSE_TYPE_BLOB,
-    XML_HTTP_RESPONSE_TYPE_DOCUMENT,
-    XML_HTTP_RESPONSE_TYPE_JSON,
-    XML_HTTP_RESPONSE_TYPE_TEXT,
-    XML_HTTP_RESPONSE_TYPE_CHUNKED_TEXT,
-    XML_HTTP_RESPONSE_TYPE_CHUNKED_ARRAYBUFFER,
-    XML_HTTP_RESPONSE_TYPE_MOZ_BLOB
-  };
-
-  void SetResponseType(XMLHttpRequestMainThread::ResponseTypeEnum aType,
-                       ErrorResult& aRv);
-
-  ResponseTypeEnum mResponseType;
+  XMLHttpRequestResponseType mResponseType;
 
   // It is either a cached blob-response from the last call to GetResponse,
   // but is also explicitly set in OnStopRequest.
   RefPtr<Blob> mResponseBlob;
   // Non-null only when we are able to get a os-file representation of the
   // response, i.e. when loading from a file.
   RefPtr<Blob> mDOMBlob;
   // We stream data to mBlobSet when response type is "blob" or "moz-blob"