Bug 1642193 - Add new flags to see if premature abort events are already dispatched r=baku
☠☠ backed out by fca2a64739b1 ☠ ☠
authorKershaw Chang <kershaw@mozilla.com>
Tue, 09 Jun 2020 16:09:07 +0000
changeset 534861 d5c26d99978e5ffd72406a9a55795eddd03a47c9
parent 534860 f8faae6114e00d12dcfbb3ed07b6fbd89c400944
child 534862 4745600e205afdc49a08e5fb5bc93119e561c76a
push id118586
push userkjang@mozilla.com
push dateWed, 10 Jun 2020 11:35:46 +0000
treeherderautoland@d5c26d99978e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1642193
milestone79.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 1642193 - Add new flags to see if premature abort events are already dispatched r=baku Differential Revision: https://phabricator.services.mozilla.com/D78901
dom/xhr/XMLHttpRequestWorker.cpp
testing/web-platform/meta/xhr/abort-upload-event-abort.any.js.ini
testing/web-platform/meta/xhr/abort-upload-event-loadend.any.js.ini
testing/web-platform/meta/xhr/event-timeout-order.any.js.ini
--- a/dom/xhr/XMLHttpRequestWorker.cpp
+++ b/dom/xhr/XMLHttpRequestWorker.cpp
@@ -115,16 +115,18 @@ class Proxy final : public nsIDOMEventLi
   uint64_t mLastTotal;
   uint64_t mLastUploadLoaded;
   uint64_t mLastUploadTotal;
   bool mIsSyncXHR;
   bool mLastLengthComputable;
   bool mLastUploadLengthComputable;
   bool mSeenLoadStart;
   bool mSeenUploadLoadStart;
+  bool mDispatchPrematureAbortEvent;
+  bool mDispatchPrematureAbortEventToUpload;
 
   // Only touched on the main thread.
   bool mUploadEventListenersAttached;
   bool mMainThreadSeenLoadStart;
   bool mInOpen;
 
  public:
   Proxy(XMLHttpRequestWorker* aXHRPrivate, const ClientInfo& aClientInfo,
@@ -146,16 +148,18 @@ class Proxy final : public nsIDOMEventLi
         mLastTotal(0),
         mLastUploadLoaded(0),
         mLastUploadTotal(0),
         mIsSyncXHR(false),
         mLastLengthComputable(false),
         mLastUploadLengthComputable(false),
         mSeenLoadStart(false),
         mSeenUploadLoadStart(false),
+        mDispatchPrematureAbortEvent(false),
+        mDispatchPrematureAbortEventToUpload(false),
         mUploadEventListenersAttached(false),
         mMainThreadSeenLoadStart(false),
         mInOpen(false) {}
 
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIDOMEVENTLISTENER
 
   bool Init();
@@ -257,40 +261,40 @@ namespace {
 
 enum {
   STRING_abort = 0,
   STRING_error,
   STRING_load,
   STRING_loadstart,
   STRING_progress,
   STRING_timeout,
+  STRING_loadend,
   STRING_readystatechange,
-  STRING_loadend,
 
   STRING_COUNT,
 
-  STRING_LAST_XHR = STRING_loadend,
-  STRING_LAST_EVENTTARGET = STRING_timeout
+  STRING_LAST_XHR = STRING_readystatechange,
+  STRING_LAST_EVENTTARGET = STRING_loadend
 };
 
 static_assert(STRING_LAST_XHR >= STRING_LAST_EVENTTARGET, "Bad string setup!");
 static_assert(STRING_LAST_XHR == STRING_COUNT - 1, "Bad string setup!");
 
 const char* const sEventStrings[] = {
     // XMLHttpRequestEventTarget event types, supported by both XHR and Upload.
     "abort",
     "error",
     "load",
     "loadstart",
     "progress",
     "timeout",
+    "loadend",
 
     // XMLHttpRequest event types, supported only by XHR.
     "readystatechange",
-    "loadend",
 };
 
 static_assert(MOZ_ARRAY_LENGTH(sEventStrings) == STRING_COUNT,
               "Bad string count!");
 
 class MainThreadProxyRunnable : public MainThreadWorkerSyncRunnable {
  protected:
   RefPtr<Proxy> mProxy;
@@ -1065,26 +1069,30 @@ bool EventRunnable::WorkerRun(JSContext*
     if (mUploadEvent) {
       mProxy->mSeenUploadLoadStart = true;
     } else {
       mProxy->mSeenLoadStart = true;
     }
   } else if (mType.EqualsASCII(sEventStrings[STRING_loadend])) {
     if (mUploadEvent) {
       mProxy->mSeenUploadLoadStart = false;
-    } else {
-      if (!mProxy->mSeenLoadStart) {
+      if (mProxy->mDispatchPrematureAbortEventToUpload) {
         // We've already dispatched premature abort events.
         return true;
       }
+    } else {
       mProxy->mSeenLoadStart = false;
+      if (mProxy->mDispatchPrematureAbortEvent) {
+        // We've already dispatched premature abort events.
+        return true;
+      }
     }
   } else if (mType.EqualsASCII(sEventStrings[STRING_abort])) {
-    if ((mUploadEvent && !mProxy->mSeenUploadLoadStart) ||
-        (!mUploadEvent && !mProxy->mSeenLoadStart)) {
+    if ((mUploadEvent && mProxy->mDispatchPrematureAbortEventToUpload) ||
+        (!mUploadEvent && mProxy->mDispatchPrematureAbortEvent)) {
       // We've already dispatched premature abort events.
       return true;
     }
   }
 
   if (mProgressEvent) {
     // Cache these for premature abort events.
     if (mUploadEvent) {
@@ -1493,16 +1501,17 @@ void XMLHttpRequestWorker::MaybeDispatch
 
     // Similarly to null check in ::Open, mProxy may have been cleared here.
     if (!mProxy) {
       aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
       return;
     }
 
     mProxy->mSeenUploadLoadStart = false;
+    mProxy->mDispatchPrematureAbortEventToUpload = true;
   }
 
   if (mProxy->mSeenLoadStart) {
     if (isStateChanged) {
       DispatchPrematureAbortEvent(this, NS_LITERAL_STRING("readystatechange"),
                                   false, aRv);
       if (aRv.Failed()) {
         return;
@@ -1521,16 +1530,17 @@ void XMLHttpRequestWorker::MaybeDispatch
 
     // Similarly to null check in ::Open, mProxy may have been cleared here.
     if (!mProxy) {
       aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
       return;
     }
 
     mProxy->mSeenLoadStart = false;
+    mProxy->mDispatchPrematureAbortEvent = true;
   }
 }
 
 void XMLHttpRequestWorker::DispatchPrematureAbortEvent(
     EventTarget* aTarget, const nsAString& aEventType, bool aUploadTarget,
     ErrorResult& aRv) {
   mWorkerPrivate->AssertIsOnWorkerThread();
   MOZ_ASSERT(aTarget);
@@ -1638,16 +1648,18 @@ void XMLHttpRequestWorker::SendInternal(
     syncLoopTarget = autoSyncLoop->GetEventTarget();
     if (!syncLoopTarget) {
       aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
       return;
     }
   }
 
   mProxy->mOuterChannelId++;
+  mProxy->mDispatchPrematureAbortEvent = false;
+  mProxy->mDispatchPrematureAbortEventToUpload = false;
 
   sendRunnable->SetSyncLoopTarget(syncLoopTarget);
   sendRunnable->SetHaveUploadListeners(hasUploadListeners);
 
   mStateData->mFlagSend = true;
 
   sendRunnable->Dispatch(Canceling, aRv);
   if (aRv.Failed()) {
deleted file mode 100644
--- a/testing/web-platform/meta/xhr/abort-upload-event-abort.any.js.ini
+++ /dev/null
@@ -1,7 +0,0 @@
-[abort-upload-event-abort.any.worker.html]
-  expected: TIMEOUT
-  [XMLHttpRequest: The abort() method: Fire a progress event named abort on the XMLHttpRequestUpload object]
-    expected: TIMEOUT
-
-
-[abort-upload-event-abort.any.html]
deleted file mode 100644
--- a/testing/web-platform/meta/xhr/abort-upload-event-loadend.any.js.ini
+++ /dev/null
@@ -1,7 +0,0 @@
-[abort-upload-event-loadend.any.html]
-
-[abort-upload-event-loadend.any.worker.html]
-  expected: TIMEOUT
-  [XMLHttpRequest: The abort() method: Fire a progress event named loadend on the XMLHttpRequestUpload object]
-    expected: TIMEOUT
-
deleted file mode 100644
--- a/testing/web-platform/meta/xhr/event-timeout-order.any.js.ini
+++ /dev/null
@@ -1,6 +0,0 @@
-[event-timeout-order.any.html]
-
-[event-timeout-order.any.worker.html]
-  [XMLHttpRequest: event - timeout (order of events)]
-    expected: FAIL
-