зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1502403 - FileReader should dispatch loadstart asynchronously, r=smaug
This commit is contained in:
Родитель
7c298c2176
Коммит
c549894865
|
@ -88,6 +88,33 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
class FileReader::AsyncWaitRunnable final : public CancelableRunnable
|
||||
{
|
||||
public:
|
||||
explicit AsyncWaitRunnable(FileReader* aReader)
|
||||
: CancelableRunnable("FileReader::AsyncWaitRunnable")
|
||||
, mReader(aReader)
|
||||
{}
|
||||
|
||||
NS_IMETHOD
|
||||
Run() override
|
||||
{
|
||||
if (mReader) {
|
||||
mReader->InitialAsyncWait();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
Abort()
|
||||
{
|
||||
mReader = nullptr;
|
||||
}
|
||||
|
||||
public:
|
||||
RefPtr<FileReader> mReader;
|
||||
};
|
||||
|
||||
void
|
||||
FileReader::RootResultArrayBuffer()
|
||||
{
|
||||
|
@ -446,7 +473,8 @@ FileReader::ReadFileContent(Blob& aBlob,
|
|||
}
|
||||
}
|
||||
|
||||
aRv = DoAsyncWait();
|
||||
mAsyncWaitRunnable = new AsyncWaitRunnable(this);
|
||||
aRv = NS_DispatchToCurrentThread(mAsyncWaitRunnable);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
FreeFileData();
|
||||
return;
|
||||
|
@ -454,6 +482,20 @@ FileReader::ReadFileContent(Blob& aBlob,
|
|||
|
||||
//FileReader should be in loading state here
|
||||
mReadyState = LOADING;
|
||||
}
|
||||
|
||||
void
|
||||
FileReader::InitialAsyncWait()
|
||||
{
|
||||
mAsyncWaitRunnable = nullptr;
|
||||
|
||||
nsresult rv = DoAsyncWait();
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
mReadyState = EMPTY;
|
||||
FreeFileData();
|
||||
return;
|
||||
}
|
||||
|
||||
DispatchProgressEvent(NS_LITERAL_STRING(LOADSTART_STR));
|
||||
}
|
||||
|
||||
|
@ -774,6 +816,11 @@ FileReader::Abort()
|
|||
|
||||
ClearProgressEventTimer();
|
||||
|
||||
if (mAsyncWaitRunnable) {
|
||||
mAsyncWaitRunnable->Abort();
|
||||
mAsyncWaitRunnable = nullptr;
|
||||
}
|
||||
|
||||
mReadyState = DONE;
|
||||
|
||||
// XXX The spec doesn't say this
|
||||
|
@ -783,7 +830,19 @@ FileReader::Abort()
|
|||
SetDOMStringToNull(mResult);
|
||||
mResultArrayBuffer = nullptr;
|
||||
|
||||
mAsyncStream = nullptr;
|
||||
if (mAsyncStream) {
|
||||
if (mBusyCount) {
|
||||
// This will abort any pending reading. See nsIAsyncInputStream.idl.
|
||||
mAsyncStream->AsyncWait(/* callback */ nullptr,
|
||||
/* aFlags*/ 0,
|
||||
/* aRequestedCount */ 0,
|
||||
mTarget);
|
||||
DecreaseBusyCounter();
|
||||
MOZ_ASSERT(mBusyCount == 0);
|
||||
}
|
||||
mAsyncStream = nullptr;
|
||||
}
|
||||
|
||||
mBlob = nullptr;
|
||||
|
||||
//Clean up memory buffer
|
||||
|
@ -831,6 +890,11 @@ FileReader::Shutdown()
|
|||
{
|
||||
mReadyState = DONE;
|
||||
|
||||
if (mAsyncWaitRunnable) {
|
||||
mAsyncWaitRunnable->Abort();
|
||||
mAsyncWaitRunnable = nullptr;
|
||||
}
|
||||
|
||||
if (mAsyncStream) {
|
||||
mAsyncStream->Close();
|
||||
mAsyncStream = nullptr;
|
||||
|
|
|
@ -128,6 +128,8 @@ public:
|
|||
eDataFormat DataFormat() const { return mDataFormat; }
|
||||
const nsString& Result() const { return mResult; }
|
||||
|
||||
void InitialAsyncWait();
|
||||
|
||||
private:
|
||||
virtual ~FileReader();
|
||||
|
||||
|
@ -207,6 +209,10 @@ private:
|
|||
// This value is set when the reading starts in order to keep the worker alive
|
||||
// during the process.
|
||||
RefPtr<StrongWorkerRef> mStrongWorkerRef;
|
||||
|
||||
// Runnable to start the reading asynchronous.
|
||||
class AsyncWaitRunnable;
|
||||
RefPtr<AsyncWaitRunnable> mAsyncWaitRunnable;
|
||||
};
|
||||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(FileReader, FILEREADER_ID)
|
||||
|
|
|
@ -257,7 +257,7 @@ function test_readAsText(blob, text) {
|
|||
|
||||
is(r.readyState, FileReader.LOADING, "correct loading text readyState");
|
||||
is(onloadHasRun, false, "text loading must be async");
|
||||
is(onloadStartHasRun, true, "text loadstart should fire sync");
|
||||
is(onloadStartHasRun, false, "text loadstart should fire async");
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -280,7 +280,7 @@ function test_readAsBinaryString(blob, text) {
|
|||
|
||||
is(r.readyState, FileReader.LOADING, "correct loading binary readyState");
|
||||
is(onloadHasRun, false, "binary loading must be async");
|
||||
is(onloadStartHasRun, true, "binary loadstart should fire sync");
|
||||
is(onloadStartHasRun, false, "binary loadstart should fire async");
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -303,7 +303,7 @@ function test_readAsArrayBuffer(blob, text) {
|
|||
|
||||
is(r.readyState, FileReader.LOADING, "correct loading arrayBuffer readyState");
|
||||
is(onloadHasRun, false, "arrayBuffer loading must be async");
|
||||
is(onloadStartHasRun, true, "arrayBuffer loadstart should fire sync");
|
||||
is(onloadStartHasRun, false, "arrayBuffer loadstart should fire sync");
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
[filereader_abort.html]
|
||||
[Aborting after read]
|
||||
expected: FAIL
|
||||
|
Загрузка…
Ссылка в новой задаче