Bug 1285036 - Part 3: Flip the asynchronous flag to synchronous, to match the spec. r=baku
authorThomas Wisniewski <wisniewskit@gmail.com>
Fri, 08 Jul 2016 12:49:40 -0400
changeset 304427 bf25c8b6af9fe7cabb8421c99fb9845de2810fed
parent 304426 9c7274bdcd99e4bfb5f566975437e27d01b7cc53
child 304428 18a736ed2156f9715d2e2b5725279c2bafc64d8b
push id79321
push usercbook@mozilla.com
push dateMon, 11 Jul 2016 08:42:29 +0000
treeherdermozilla-inbound@21cd5236715f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1285036
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1285036 - Part 3: Flip the asynchronous flag to synchronous, to match the spec. r=baku
dom/xhr/XMLHttpRequestMainThread.cpp
dom/xhr/XMLHttpRequestMainThread.h
--- a/dom/xhr/XMLHttpRequestMainThread.cpp
+++ b/dom/xhr/XMLHttpRequestMainThread.cpp
@@ -156,17 +156,17 @@ static void AddLoadFlags(nsIRequest *req
 bool
 XMLHttpRequestMainThread::sDontWarnAboutSyncXHR = false;
 
 XMLHttpRequestMainThread::XMLHttpRequestMainThread()
   : mResponseBodyDecodedPos(0),
     mResponseType(XMLHttpRequestResponseType::_empty),
     mRequestObserver(nullptr),
     mState(State::unsent),
-    mFlagAsynchronous(true), mFlagAborted(false), mFlagParseBody(false),
+    mFlagSynchronous(false), mFlagAborted(false), mFlagParseBody(false),
     mFlagSyncLooping(false), mFlagBackgroundRequest(false),
     mFlagHadUploadListenersOnSend(false), mFlagACwithCredentials(false),
     mFlagTimedOut(false), mFlagDeleted(false),
     mUploadTransferred(0), mUploadTotal(0), mUploadComplete(true),
     mProgressSinceLastProgressEvent(false),
     mRequestSentTime(0), mTimeoutMilliseconds(0),
     mErrorLoad(false), mWaitingForOnStopRequest(false),
     mProgressTimerIsActive(false),
@@ -714,23 +714,23 @@ XMLHttpRequestMainThread::SetResponseTyp
   // If the state is LOADING or DONE raise an INVALID_STATE_ERR exception
   // and terminate these steps.
   if (mState == State::loading || mState == State::done) {
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     return;
   }
 
   // sync request is not allowed setting responseType in window context
-  if (HasOrHasHadOwner() && mState != State::unsent && !mFlagAsynchronous) {
+  if (HasOrHasHadOwner() && mState != State::unsent && mFlagSynchronous) {
     LogMessage("ResponseTypeSyncXHRWarning", GetOwner());
     aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
     return;
   }
 
-  if (!mFlagAsynchronous &&
+  if (mFlagSynchronous &&
       (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;
@@ -1416,17 +1416,17 @@ XMLHttpRequestMainThread::Open(const nsA
     //     by accident and you could spend a lot of time wondering
     //     why things didn't work.
   }
 
   // Unset any pre-existing aborted and timed-out flags.
   mFlagAborted = false;
   mFlagTimedOut = false;
 
-  mFlagAsynchronous = async;
+  mFlagSynchronous = !async;
 
   nsCOMPtr<nsIDocument> doc = GetDocumentIfCurrent();
   if (!doc) {
     // This could be because we're no longer current or because we're in some
     // non-window context...
     nsresult rv = CheckInnerWindowCorrectness();
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return NS_ERROR_DOM_INVALID_STATE_ERR;
@@ -1754,17 +1754,17 @@ XMLHttpRequestMainThread::OnStartRequest
 
   nsCOMPtr<nsIChannel> channel(do_QueryInterface(request));
   NS_ENSURE_TRUE(channel, NS_ERROR_UNEXPECTED);
 
   nsresult status;
   request->GetStatus(&status);
   mErrorLoad = mErrorLoad || NS_FAILED(status);
 
-  if (mUpload && !mUploadComplete && !mErrorLoad && mFlagAsynchronous) {
+  if (mUpload && !mUploadComplete && !mErrorLoad && !mFlagSynchronous) {
     if (mProgressTimerIsActive) {
       mProgressTimerIsActive = false;
       mProgressNotifier->Cancel();
     }
     if (mUploadTransferred < mUploadTotal) {
       mUploadTransferred = mUploadTotal;
       mProgressSinceLastProgressEvent = true;
       mUploadLengthComputable = true;
@@ -1859,17 +1859,17 @@ XMLHttpRequestMainThread::OnStartRequest
 
     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 (!mFlagAsynchronous) {
+      if (mFlagSynchronous) {
         // We don't make cool new features available in the bad synchronous
         // mode. The synchronous mode is for legacy only.
         mWarnAboutSyncHtml = true;
         mFlagParseBody = false;
       } else {
         mIsHtml = true;
       }
     } else if (!(type.EqualsLiteral("text/xml") ||
@@ -1952,18 +1952,17 @@ XMLHttpRequestMainThread::OnStartRequest
 
     mXMLParserStreamListener = listener;
     rv = mXMLParserStreamListener->OnStartRequest(request, ctxt);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   // We won't get any progress events anyway if we didn't have progress
   // events when starting the request - so maybe no need to start timer here.
-  if (NS_SUCCEEDED(rv) &&
-      mFlagAsynchronous &&
+  if (NS_SUCCEEDED(rv) && !mFlagSynchronous &&
       HasListenersFor(nsGkAtoms::onprogress)) {
     StartProgressEventTimer();
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
@@ -2748,17 +2747,17 @@ XMLHttpRequestMainThread::Send(nsIVarian
     mChannel = nullptr;
 
     return rv;
   }
 
   mWaitingForOnStopRequest = true;
 
   // If we're synchronous, spin an event loop here and wait
-  if (!mFlagAsynchronous) {
+  if (mFlagSynchronous) {
     mFlagSyncLooping = true;
 
     nsCOMPtr<nsIDocument> suspendedDoc;
     nsCOMPtr<nsIRunnable> resumeTimeoutRunnable;
     if (GetOwner()) {
       if (nsCOMPtr<nsPIDOMWindowOuter> topWindow = GetOwner()->GetOuterWindow()->GetTop()) {
         if (nsCOMPtr<nsPIDOMWindowInner> topInner = topWindow->GetCurrentInnerWindow()) {
           suspendedDoc = topWindow->GetExtantDoc();
@@ -2927,17 +2926,17 @@ XMLHttpRequestMainThread::SetTimeout(uin
   ErrorResult rv;
   SetTimeout(aTimeout, rv);
   return rv.StealNSResult();
 }
 
 void
 XMLHttpRequestMainThread::SetTimeout(uint32_t aTimeout, ErrorResult& aRv)
 {
-  if (!mFlagAsynchronous && mState != State::unsent && HasOrHasHadOwner()) {
+  if (mFlagSynchronous && mState != State::unsent && HasOrHasHadOwner()) {
     /* Timeout is not supported for synchronous requests with an owning window,
        per XHR2 spec. */
     LogMessage("TimeoutSyncXHRWarning", GetOwner());
     aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
     return;
   }
 
   mTimeoutMilliseconds = aTimeout;
@@ -3108,17 +3107,17 @@ XMLHttpRequestMainThread::ChangeState(St
       aState != State::headers_received && aState != State::loading) {
     mProgressTimerIsActive = false;
     mProgressNotifier->Cancel();
   }
 
   if (aState != State::sent && // SENT is internal
       !droppingFromSENTtoOPENED && // since SENT is essentially OPENED
       aBroadcast &&
-      (mFlagAsynchronous || aState == State::opened || aState == State::done)) {
+      (!mFlagSynchronous || aState == State::opened || aState == State::done)) {
     nsCOMPtr<nsIDOMEvent> event;
     rv = CreateReadystatechangeEvent(getter_AddRefs(event));
     NS_ENSURE_SUCCESS(rv, rv);
 
     DispatchDOMEvent(nullptr, event, nullptr, nullptr);
   }
 
   return rv;
@@ -3200,17 +3199,17 @@ XMLHttpRequestMainThread::MaybeDispatchP
   if (aFinalProgress && mProgressTimerIsActive) {
     mProgressTimerIsActive = false;
     mProgressNotifier->Cancel();
   }
 
   if (mProgressTimerIsActive ||
       !mProgressSinceLastProgressEvent ||
       mErrorLoad ||
-      !mFlagAsynchronous) {
+      mFlagSynchronous) {
     return;
   }
 
   if (!aFinalProgress) {
     StartProgressEventTimer();
   }
 
   // We're uploading if our state is State::opened or State::sent
--- a/dom/xhr/XMLHttpRequestMainThread.h
+++ b/dom/xhr/XMLHttpRequestMainThread.h
@@ -685,17 +685,17 @@ protected:
 
   nsIRequestObserver* mRequestObserver;
 
   nsCOMPtr<nsIURI> mBaseURI;
   nsCOMPtr<nsILoadGroup> mLoadGroup;
 
   State mState;
 
-  bool mFlagAsynchronous;
+  bool mFlagSynchronous;
   bool mFlagAborted;
   bool mFlagParseBody;
   bool mFlagSyncLooping;
   bool mFlagBackgroundRequest;
   bool mFlagHadUploadListenersOnSend;
   bool mFlagACwithCredentials;
   bool mFlagTimedOut;
   bool mFlagDeleted;