Bug 1321525 - FileReader.readAs* should throw if called nested, r=smaug
☠☠ backed out by 1464a199a2a5 ☠ ☠
authorAndrea Marchesini <amarchesini@mozilla.com>
Thu, 01 Dec 2016 15:57:02 +0100
changeset 325026 8c4dcbaa44b92fe8248c8aac2c6191c15fc91b1d
parent 325025 0c212b76bca625813bae097ff2b8765b07261895
child 325027 9e5cd2bf4d66a602b934235f9071ff2247a66d94
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewerssmaug
bugs1321525
milestone53.0a1
Bug 1321525 - FileReader.readAs* should throw if called nested, r=smaug
dom/file/FileReader.cpp
dom/file/tests/test_fileapi.html
testing/web-platform/meta/FileAPI/reading-data-section/FileReader-multiple-reads.html.ini
--- a/dom/file/FileReader.cpp
+++ b/dom/file/FileReader.cpp
@@ -344,31 +344,28 @@ FileReader::DoReadData(uint64_t aCount)
 // Helper methods
 
 void
 FileReader::ReadFileContent(Blob& aBlob,
                             const nsAString &aCharset,
                             eDataFormat aDataFormat,
                             ErrorResult& aRv)
 {
-  //Implicit abort to clear any other activity going on
-  ErrorResult error;
-  Abort(error);
-  error.SuppressException();
-
   if (mReadyState == LOADING) {
-    // A nested ReadAsSomething() as been called during one of the events
-    // dispatched by Abort(). We have to terminate this operation in order to
-    // continue the nested one.
-    aRv.Throw(NS_ERROR_ABORT);
+    aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     return;
   }
 
   mError = nullptr;
+
   SetDOMStringToNull(mResult);
+  mResultArrayBuffer = nullptr;
+
+  mAsyncStream = nullptr;
+
   mTransferred = 0;
   mTotal = 0;
   mReadyState = EMPTY;
   FreeFileData();
 
   mBlob = &aBlob;
   mDataFormat = aDataFormat;
   CopyUTF16toUTF8(aCharset, mCharset);
--- a/dom/file/tests/test_fileapi.html
+++ b/dom/file/tests/test_fileapi.html
@@ -351,28 +351,36 @@ function onFilesOpened(message) {
   r = new FileReader();
   r.onabort = function (event) {
     is(reuseAbortHasRun, false, "abort should only fire once");
     reuseAbortHasRun = true;
     is(event.target.readyState, FileReader.DONE, "should be DONE while firing onabort");
     is(event.target.error.name, "AbortError", "error set to AbortError for aborted reads");
     is(event.target.result, null, "file data should be null on aborted reads");
   }
-  r.onload = function() { ok(false, "load should not fire for aborted reads") };
+  r.onload = function() { ok(false, "load should fire for nested reads"); }'
+
   var abortThrew = false;
   try {
     r.abort();
   } catch(e) {
     abortThrew = true;
   }
   is(abortThrew, true, "abort() must throw if not loading");
   is(reuseAbortHasRun, false, "abort() is a no-op unless loading");
   r.readAsText(asciiFile);
-  r.readAsText(asciiFile);
-  is(reuseAbortHasRun, true, "abort should fire sync");
+
+  var readThrew = false;
+  try {
+    r.readAsText(asciiFile);
+  } catch(e) {
+    readThrew = true;
+  }
+  is(readThrew, true, "readAsText() must throw if loading");
+  is(reuseAbortHasRun, false, "abort should not fire");
   r.onload = getLoadHandler(testASCIIData, testASCIIData.length, "reuse-as-abort reading");
   expectedTestCount++;
 
 
   // Test reading from nonexistent files
   r = new FileReader();
   var didThrow = false;
   r.onerror = function (event) {
--- a/testing/web-platform/meta/FileAPI/reading-data-section/FileReader-multiple-reads.html.ini
+++ b/testing/web-platform/meta/FileAPI/reading-data-section/FileReader-multiple-reads.html.ini
@@ -1,17 +1,5 @@
 [FileReader-multiple-reads.html]
   type: testharness
-  [test FileReader InvalidStateError exception for readAsText]
-    expected: FAIL
-
-  [test FileReader InvalidStateError exception for readAsDataURL]
-    expected: FAIL
-
-  [test FileReader InvalidStateError exception for readAsArrayBuffer]
-    expected: FAIL
-
-  [test FileReader InvalidStateError exception in onloadstart event for readAsArrayBuffer]
-    expected: FAIL
-
   [test FileReader no InvalidStateError exception in onloadstart event for readAsArrayBuffer]
     expected: FAIL