Backed out changeset 8275594fe235 (bug 1360807)
authorCarsten "Tomcat" Book <cbook@mozilla.com>
Thu, 04 May 2017 16:39:16 +0200
changeset 572805 41d2a49c6b5fe49caf448cfa9acd491b6b47bce1
parent 572804 146f3b415f6c94f9834b22e302b719265037ba5a
child 572806 ff08391ef68f1584d25800679f0500302d96b0ce
push id57195
push userbmo:rbarker@mozilla.com
push dateThu, 04 May 2017 20:08:56 +0000
bugs1360807
milestone55.0a1
backs out8275594fe23583a6360062d4b03d6bf58a23ad6a
Backed out changeset 8275594fe235 (bug 1360807)
dom/workers/FileReaderSync.cpp
dom/workers/FileReaderSync.h
--- a/dom/workers/FileReaderSync.cpp
+++ b/dom/workers/FileReaderSync.cpp
@@ -73,17 +73,17 @@ FileReaderSync::ReadAsArrayBuffer(JSCont
 
   nsCOMPtr<nsIInputStream> stream;
   aBlob.GetInternalStream(getter_AddRefs(stream), aRv);
   if (NS_WARN_IF(aRv.Failed())) {
     return;
   }
 
   uint32_t numRead;
-  aRv = SyncRead(stream, bufferData.get(), blobSize, &numRead);
+  aRv = Read(stream, bufferData.get(), blobSize, &numRead);
   if (NS_WARN_IF(aRv.Failed())) {
     return;
   }
   NS_ASSERTION(numRead == blobSize, "failed to read data");
 
   JSObject* arrayBuffer = JS_NewArrayBufferWithContents(aCx, blobSize, bufferData.get());
   if (!arrayBuffer) {
     aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
@@ -105,17 +105,17 @@ FileReaderSync::ReadAsBinaryString(Blob&
   aBlob.GetInternalStream(getter_AddRefs(stream), aRv);
   if (NS_WARN_IF(aRv.Failed())) {
     return;
   }
 
   uint32_t numRead;
   do {
     char readBuf[4096];
-    aRv = SyncRead(stream, readBuf, sizeof(readBuf), &numRead);
+    aRv = Read(stream, readBuf, sizeof(readBuf), &numRead);
     if (NS_WARN_IF(aRv.Failed())) {
       return;
     }
 
     uint32_t oldLength = aResult.Length();
     AppendASCIItoUTF16(Substring(readBuf, readBuf + numRead), aResult);
     if (aResult.Length() - oldLength != numRead) {
       aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
@@ -140,17 +140,17 @@ FileReaderSync::ReadAsText(Blob& aBlob,
 
   nsCString sniffBuf;
   if (!sniffBuf.SetLength(3, fallible)) {
     aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
     return;
   }
 
   uint32_t numRead = 0;
-  aRv = SyncRead(stream, sniffBuf.BeginWriting(), sniffBuf.Length(), &numRead);
+  aRv = Read(stream, sniffBuf.BeginWriting(), sniffBuf.Length(), &numRead);
   if (NS_WARN_IF(aRv.Failed())) {
     return;
   }
 
   // The BOM sniffing is baked into the "decode" part of the Encoding
   // Standard, which the File API references.
   if (!nsContentUtils::CheckForBOM((const unsigned char*)sniffBuf.BeginReading(),
                                    numRead, encoding)) {
@@ -356,53 +356,29 @@ NS_IMPL_RELEASE(ReadCallback);
 NS_INTERFACE_MAP_BEGIN(ReadCallback)
   NS_INTERFACE_MAP_ENTRY(nsIInputStreamCallback)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIInputStreamCallback)
 NS_INTERFACE_MAP_END
 
 } // anonymous
 
 nsresult
-FileReaderSync::SyncRead(nsIInputStream* aStream, char* aBuffer,
-                         uint32_t aBufferSize, uint32_t* aRead)
+FileReaderSync::Read(nsIInputStream* aStream, char* aBuffer, uint32_t aBufferSize,
+                     uint32_t* aRead)
 {
   MOZ_ASSERT(aStream);
   MOZ_ASSERT(aBuffer);
   MOZ_ASSERT(aRead);
 
   // Let's try to read, directly.
   nsresult rv = aStream->Read(aBuffer, aBufferSize, aRead);
-
-  // Nothing else to read.
-  if (rv == NS_BASE_STREAM_CLOSED ||
-      (NS_SUCCEEDED(rv) && *aRead == 0)) {
-    return NS_OK;
-  }
-
-  // An error.
-  if (NS_FAILED(rv) && rv != NS_BASE_STREAM_WOULD_BLOCK) {
+  if (NS_SUCCEEDED(rv) || rv != NS_BASE_STREAM_WOULD_BLOCK) {
     return rv;
   }
 
-  // All good.
-  if (NS_SUCCEEDED(rv)) {
-    // Not enough data, let's read recursively.
-    if (*aRead != aBufferSize) {
-      uint32_t byteRead = 0;
-      rv = SyncRead(aStream, aBuffer + *aRead, aBufferSize - *aRead, &byteRead);
-      if (NS_WARN_IF(NS_FAILED(rv))) {
-        return rv;
-      }
-
-      *aRead += byteRead;
-    }
-
-    return NS_OK;
-  }
-
   // We need to proceed async.
   nsCOMPtr<nsIAsyncInputStream> asyncStream = do_QueryInterface(aStream);
   if (!asyncStream) {
     return rv;
   }
 
   WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
   MOZ_ASSERT(workerPrivate);
@@ -427,10 +403,10 @@ FileReaderSync::SyncRead(nsIInputStream*
     return rv;
   }
 
   if (!syncLoop.Run()) {
     return NS_ERROR_DOM_INVALID_STATE_ERR;
   }
 
   // Now, we can try to read again.
-  return SyncRead(aStream, aBuffer, aBufferSize, aRead);
+  return Read(aStream, aBuffer, aBufferSize, aRead);
 }
--- a/dom/workers/FileReaderSync.h
+++ b/dom/workers/FileReaderSync.h
@@ -27,18 +27,18 @@ private:
   // Private destructor, to discourage deletion outside of Release():
   ~FileReaderSync()
   {
   }
 
   nsresult ConvertStream(nsIInputStream *aStream, const char *aCharset,
                          nsAString &aResult);
 
-  nsresult SyncRead(nsIInputStream* aStream, char* aBuffer,
-                    uint32_t aBufferSize, uint32_t* aRead);
+  nsresult Read(nsIInputStream* aStream, char* aBuffer, uint32_t aBufferSize,
+                uint32_t* aRead);
 
 public:
   static already_AddRefed<FileReaderSync>
   Constructor(const GlobalObject& aGlobal, ErrorResult& aRv);
 
   bool WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector);
 
   void ReadAsArrayBuffer(JSContext* aCx, JS::Handle<JSObject*> aScopeObj,