Bug 447689 - clean up XMLHttpRequest::Open so XHR readyState=1 events are fired according to spec. r=baku
authorThomas Wisniewski <wisniewskit@gmail.com>
Sat, 16 Jul 2016 13:56:36 -0400
changeset 345738 eb8925e998325aada57232a9b7452726d11e6311
parent 345737 d22b099cf1e312edf24adc27dd23541b37900cfe
child 345739 6afd23d2579fbd3ec7424d1130debc5a0cf380bd
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs447689
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 447689 - clean up XMLHttpRequest::Open so XHR readyState=1 events are fired according to spec. r=baku
dom/xhr/XMLHttpRequestMainThread.cpp
dom/xhr/XMLHttpRequestMainThread.h
dom/xhr/XMLHttpRequestWorker.cpp
testing/web-platform/meta/XMLHttpRequest/open-open-send.htm.ini
testing/web-platform/meta/XMLHttpRequest/open-open-sync-send.htm.ini
testing/web-platform/meta/XMLHttpRequest/open-send-open.htm.ini
testing/web-platform/meta/XMLHttpRequest/open-sync-open-send.htm.ini
--- a/dom/xhr/XMLHttpRequestMainThread.cpp
+++ b/dom/xhr/XMLHttpRequestMainThread.cpp
@@ -999,24 +999,31 @@ XMLHttpRequestMainThread::GetStatusText(
   if (httpChannel) {
     httpChannel->GetResponseStatusText(aStatusText);
   } else {
     aStatusText.AssignLiteral("OK");
   }
 }
 
 void
-XMLHttpRequestMainThread::CloseRequestWithError(const ProgressEventType aType)
+XMLHttpRequestMainThread::CloseRequest()
 {
   if (mChannel) {
     mChannel->Cancel(NS_BINDING_ABORTED);
   }
   if (mTimeoutTimer) {
     mTimeoutTimer->Cancel();
   }
+}
+
+void
+XMLHttpRequestMainThread::CloseRequestWithError(const ProgressEventType aType)
+{
+  CloseRequest();
+
   uint32_t responseLength = mResponseBody.Length();
   ResetResponse();
 
   // If we're in the destructor, don't risk dispatching an event.
   if (mFlagDeleted) {
     mFlagSyncLooping = false;
     return;
   }
@@ -1399,27 +1406,18 @@ XMLHttpRequestMainThread::Open(const nsA
     if (mResponseType != XMLHttpRequestResponseType::_empty) {
       LogMessage("ResponseTypeSyncXHRWarning", GetOwner());
     }
     return NS_ERROR_DOM_INVALID_ACCESS_ERR;
   }
 
   nsCOMPtr<nsIURI> uri;
 
-  if (mState == State::opened || mState == State::headers_received ||
-      mState == State::loading) {
-    // IE aborts as well
-    Abort();
-
-    // XXX We should probably send a warning to the JS console
-    //     that load was aborted and event listeners were cleared
-    //     since this looks like a situation that could happen
-    //     by accident and you could spend a lot of time wondering
-    //     why things didn't work.
-  }
+  CloseRequest(); // spec step 10
+  ResetResponse(); // (part of) spec step 11
 
   mFlagSend = false;
 
   // Unset any pre-existing aborted and timed-out flags.
   mFlagAborted = false;
   mFlagTimedOut = false;
 
   mFlagSynchronous = !async;
@@ -1537,17 +1535,19 @@ XMLHttpRequestMainThread::Open(const nsA
 
     // Set the initiator type
     nsCOMPtr<nsITimedChannel> timedChannel(do_QueryInterface(httpChannel));
     if (timedChannel) {
       timedChannel->SetInitiatorType(kLiteralString_xmlhttprequest);
     }
   }
 
-  ChangeState(State::opened);
+  if (mState != State::opened) {
+    ChangeState(State::opened);
+  }
 
   return NS_OK;
 }
 
 void
 XMLHttpRequestMainThread::PopulateNetworkInterfaceId()
 {
   if (mNetworkInterfaceId.IsEmpty()) {
--- a/dom/xhr/XMLHttpRequestMainThread.h
+++ b/dom/xhr/XMLHttpRequestMainThread.h
@@ -757,16 +757,21 @@ protected:
   bool mIsSystem;
   bool mIsAnon;
 
   // A platform-specific identifer to represent the network interface
   // that this request is associated with.
   nsCString mNetworkInterfaceId;
 
   /**
+   * Close the XMLHttpRequest's channels.
+   */
+  void CloseRequest();
+
+  /**
    * Close the XMLHttpRequest's channels and dispatch appropriate progress
    * events.
    *
    * @param aType The progress event type.
    */
   void CloseRequestWithError(const ProgressEventType aType);
 
   bool mFirstStartRequestSeen;
--- a/dom/xhr/XMLHttpRequestWorker.cpp
+++ b/dom/xhr/XMLHttpRequestWorker.cpp
@@ -1029,17 +1029,16 @@ Proxy::HandleEvent(nsIDOMEvent* aEvent)
       runnable = new EventRunnable(this, !!uploadTarget, type, scope);
     }
 
     runnable->Dispatch();
   }
 
   if (!uploadTarget) {
     if (type.EqualsASCII(sEventStrings[STRING_loadstart])) {
-      NS_ASSERTION(!mMainThreadSeenLoadStart, "Huh?!");
       mMainThreadSeenLoadStart = true;
     }
     else if (mMainThreadSeenLoadStart &&
              type.EqualsASCII(sEventStrings[STRING_loadend])) {
       mMainThreadSeenLoadStart = false;
 
       RefPtr<LoadStartDetectionRunnable> runnable =
         new LoadStartDetectionRunnable(this, mXMLHttpRequestPrivate);
@@ -1483,20 +1482,19 @@ SendRunnable::RunOnMainThread(ErrorResul
 
     if (NS_FAILED(wvariant->SetAsAString(mStringBody))) {
       MOZ_ASSERT(false, "This should never fail!");
     }
 
     variant = wvariant;
   }
 
-  // Send() has been already called.
+  // Send() has been already called, reset the proxy.
   if (mProxy->mWorkerPrivate) {
-    aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
-    return;
+    mProxy->Reset();
   }
 
   mProxy->mWorkerPrivate = mWorkerPrivate;
 
   MOZ_ASSERT(!mProxy->mSyncLoopTarget);
   mProxy->mSyncLoopTarget.swap(mSyncLoopTarget);
 
   if (mHasUploadListeners) {
deleted file mode 100644
--- a/testing/web-platform/meta/XMLHttpRequest/open-open-send.htm.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[open-open-send.htm]
-  type: testharness
-  [XMLHttpRequest: open() - open() - send()]
-    expected: FAIL
-
deleted file mode 100644
--- a/testing/web-platform/meta/XMLHttpRequest/open-open-sync-send.htm.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[open-open-sync-send.htm]
-  type: testharness
-  [XMLHttpRequest: open() - open() (sync) - send()]
-    expected: FAIL
-
deleted file mode 100644
--- a/testing/web-platform/meta/XMLHttpRequest/open-send-open.htm.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[open-send-open.htm]
-  type: testharness
-  [XMLHttpRequest: open() - send() - open()]
-    expected: FAIL
-
deleted file mode 100644
--- a/testing/web-platform/meta/XMLHttpRequest/open-sync-open-send.htm.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[open-sync-open-send.htm]
-  type: testharness
-  [XMLHttpRequest: open() (sync) - send() - open()]
-    expected: FAIL
-