From a80267e9e88b3dcebf7f8f1f6f10931a99ddf2ca Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Thu, 5 Jul 2018 13:04:44 +0200 Subject: Bug 604026 - Sync event loops in workers should be created only if compatible with the worker shutdown status --- dom/xhr/XMLHttpRequestWorker.cpp | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'dom/xhr/XMLHttpRequestWorker.cpp') diff --git a/dom/xhr/XMLHttpRequestWorker.cpp b/dom/xhr/XMLHttpRequestWorker.cpp index e7193a279..b5f853a50 100644 --- a/dom/xhr/XMLHttpRequestWorker.cpp +++ b/dom/xhr/XMLHttpRequestWorker.cpp @@ -208,9 +208,9 @@ public: } void - Dispatch(ErrorResult& aRv) + Dispatch(Status aFailStatus, ErrorResult& aRv) { - WorkerMainThreadRunnable::Dispatch(aRv); + WorkerMainThreadRunnable::Dispatch(aFailStatus, aRv); if (NS_WARN_IF(aRv.Failed())) { return; } @@ -1634,7 +1634,8 @@ XMLHttpRequestWorker::ReleaseProxy(ReleaseType aType) mProxy = nullptr; ErrorResult forAssertionsOnly; - runnable->Dispatch(forAssertionsOnly); + // This runnable _must_ be executed. + runnable->Dispatch(Killing, forAssertionsOnly); if (forAssertionsOnly.Failed()) { NS_ERROR("Failed to dispatch teardown runnable!"); } @@ -1804,8 +1805,12 @@ XMLHttpRequestWorker::SendInternal(SendRunnable* aRunnable, nsCOMPtr syncLoopTarget; bool isSyncXHR = mProxy->mIsSyncXHR; if (isSyncXHR) { - autoSyncLoop.emplace(mWorkerPrivate); - syncLoopTarget = autoSyncLoop->EventTarget(); + autoSyncLoop.emplace(mWorkerPrivate, Terminating); + syncLoopTarget = autoSyncLoop->GetEventTarget(); + if (!syncLoopTarget) { + aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); + return; + } } mProxy->mOuterChannelId++; @@ -1815,7 +1820,7 @@ XMLHttpRequestWorker::SendInternal(SendRunnable* aRunnable, mStateData.mFlagSend = true; - aRunnable->Dispatch(aRv); + aRunnable->Dispatch(Terminating, aRv); if (aRv.Failed()) { // Dispatch() may have spun the event loop and we may have already unrooted. // If so we don't want autoUnpin to try again. @@ -1889,7 +1894,7 @@ XMLHttpRequestWorker::Open(const nsACString& aMethod, mTimeout, mResponseType); ++mProxy->mOpenCount; - runnable->Dispatch(aRv); + runnable->Dispatch(Terminating, aRv); if (aRv.Failed()) { if (mProxy && !--mProxy->mOpenCount) { ReleaseProxy(); @@ -1926,7 +1931,7 @@ XMLHttpRequestWorker::SetRequestHeader(const nsACString& aHeader, RefPtr runnable = new SetRequestHeaderRunnable(mWorkerPrivate, mProxy, aHeader, aValue); - runnable->Dispatch(aRv); + runnable->Dispatch(Terminating, aRv); } void @@ -1949,7 +1954,7 @@ XMLHttpRequestWorker::SetTimeout(uint32_t aTimeout, ErrorResult& aRv) RefPtr runnable = new SetTimeoutRunnable(mWorkerPrivate, mProxy, aTimeout); - runnable->Dispatch(aRv); + runnable->Dispatch(Terminating, aRv); } void @@ -1972,7 +1977,7 @@ XMLHttpRequestWorker::SetWithCredentials(bool aWithCredentials, ErrorResult& aRv RefPtr runnable = new SetWithCredentialsRunnable(mWorkerPrivate, mProxy, aWithCredentials); - runnable->Dispatch(aRv); + runnable->Dispatch(Terminating, aRv); } void @@ -1997,7 +2002,7 @@ XMLHttpRequestWorker::SetMozBackgroundRequest(bool aBackgroundRequest, RefPtr runnable = new SetBackgroundRequestRunnable(mWorkerPrivate, mProxy, aBackgroundRequest); - runnable->Dispatch(aRv); + runnable->Dispatch(Terminating, aRv); } XMLHttpRequestUpload* @@ -2265,7 +2270,7 @@ XMLHttpRequestWorker::Abort(ErrorResult& aRv) mProxy->mOuterEventStreamId++; RefPtr runnable = new AbortRunnable(mWorkerPrivate, mProxy); - runnable->Dispatch(aRv); + runnable->Dispatch(Terminating, aRv); } void @@ -2288,7 +2293,7 @@ XMLHttpRequestWorker::GetResponseHeader(const nsACString& aHeader, RefPtr runnable = new GetResponseHeaderRunnable(mWorkerPrivate, mProxy, aHeader, responseHeader); - runnable->Dispatch(aRv); + runnable->Dispatch(Terminating, aRv); if (aRv.Failed()) { return; } @@ -2314,7 +2319,7 @@ XMLHttpRequestWorker::GetAllResponseHeaders(nsACString& aResponseHeaders, nsCString responseHeaders; RefPtr runnable = new GetAllResponseHeadersRunnable(mWorkerPrivate, mProxy, responseHeaders); - runnable->Dispatch(aRv); + runnable->Dispatch(Terminating, aRv); if (aRv.Failed()) { return; } @@ -2346,7 +2351,7 @@ XMLHttpRequestWorker::OverrideMimeType(const nsAString& aMimeType, ErrorResult& RefPtr runnable = new OverrideMimeTypeRunnable(mWorkerPrivate, mProxy, aMimeType); - runnable->Dispatch(aRv); + runnable->Dispatch(Terminating, aRv); } void @@ -2382,7 +2387,7 @@ XMLHttpRequestWorker::SetResponseType(XMLHttpRequestResponseType aResponseType, RefPtr runnable = new SetResponseTypeRunnable(mWorkerPrivate, mProxy, aResponseType); - runnable->Dispatch(aRv); + runnable->Dispatch(Terminating, aRv); if (aRv.Failed()) { return; } -- cgit v1.2.3