diff options
author | Moonchild <moonchild@palemoon.org> | 2020-07-24 11:09:54 +0000 |
---|---|---|
committer | Moonchild <moonchild@palemoon.org> | 2020-07-24 11:09:54 +0000 |
commit | 84cb854842cb4aecc2a3bee93c7a2698715643c8 (patch) | |
tree | f28ffddfafdd5da6139e8a33151c8358e35d6b86 /dom/fetch/Fetch.cpp | |
parent | 1e0bb1d355ffd55311f9544b35cff2a58b0340a8 (diff) | |
download | UXP-84cb854842cb4aecc2a3bee93c7a2698715643c8.tar UXP-84cb854842cb4aecc2a3bee93c7a2698715643c8.tar.gz UXP-84cb854842cb4aecc2a3bee93c7a2698715643c8.tar.lz UXP-84cb854842cb4aecc2a3bee93c7a2698715643c8.tar.xz UXP-84cb854842cb4aecc2a3bee93c7a2698715643c8.zip |
Issue #1587 Part 11 (followup 1): Implement multithreaded signals for workers.
Diffstat (limited to 'dom/fetch/Fetch.cpp')
-rw-r--r-- | dom/fetch/Fetch.cpp | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/dom/fetch/Fetch.cpp b/dom/fetch/Fetch.cpp index 191f4cfc3..f0350fbce 100644 --- a/dom/fetch/Fetch.cpp +++ b/dom/fetch/Fetch.cpp @@ -111,6 +111,12 @@ public: return mSignalMainThread; } + AbortSignal* + GetSignalForTargetThread() + { + return mFollowingSignal; + } + void Shutdown() { @@ -161,7 +167,7 @@ public: } AbortSignal* - GetAbortSignal() + GetAbortSignalForMainThread() { MOZ_ASSERT(NS_IsMainThread()); @@ -172,6 +178,18 @@ public: return mSignalProxy->GetOrCreateSignalForMainThread(); } + AbortSignal* + GetAbortSignalForTargetThread() + { + mPromiseProxy->GetWorkerPrivate()->AssertIsOnWorkerThread(); + + if (!mSignalProxy) { + return nullptr; + } + + return mSignalProxy->GetSignalForTargetThread(); + } + void OnResponseAvailableInternal(InternalResponse* aResponse) override; @@ -205,14 +223,16 @@ class MainThreadFetchResolver final : public FetchDriverObserver RefPtr<Promise> mPromise; RefPtr<Response> mResponse; RefPtr<FetchObserver> mFetchObserver; + RefPtr<AbortSignal> mSignal; nsCOMPtr<nsIDocument> mDocument; NS_DECL_OWNINGTHREAD public: - MainThreadFetchResolver(Promise* aPromise, FetchObserver* aObserver) + MainThreadFetchResolver(Promise* aPromise, FetchObserver* aObserver, AbortSignal* aSignal) : mPromise(aPromise) , mFetchObserver(aObserver) + , mSignal(aSignal) {} void @@ -287,7 +307,7 @@ public: fetch->SetWorkerScript(spec); } - RefPtr<AbortSignal> signal = mResolver->GetAbortSignal(); + RefPtr<AbortSignal> signal = mResolver->GetAbortSignalForMainThread(); // ...but release it before calling Fetch, because mResolver's callback can // be called synchronously and they want the mutex, too. @@ -329,10 +349,7 @@ FetchRequest(nsIGlobalObject* aGlobal, const RequestOrUSVString& aInput, RefPtr<InternalRequest> r = request->GetInternalRequest(); - RefPtr<AbortSignal> signal; - if (aInit.mSignal.WasPassed()) { - signal = &aInit.mSignal.Value(); - } + RefPtr<AbortSignal> signal = request->GetSignal(); if (signal && signal->Aborted()) { // An already aborted signal should reject immediately. @@ -373,7 +390,7 @@ FetchRequest(nsIGlobalObject* aGlobal, const RequestOrUSVString& aInput, } RefPtr<MainThreadFetchResolver> resolver = - new MainThreadFetchResolver(p, observer); + new MainThreadFetchResolver(p, observer, signal); RefPtr<FetchDriver> fetch = new FetchDriver(r, principal, loadGroup); fetch->SetDocument(doc); resolver->SetDocument(doc); @@ -416,7 +433,7 @@ MainThreadFetchResolver::OnResponseAvailableInternal(InternalResponse* aResponse } nsCOMPtr<nsIGlobalObject> go = mPromise->GetParentObject(); - mResponse = new Response(go, aResponse); + mResponse = new Response(go, aResponse, mSignal); mPromise->MaybeResolve(mResponse); } else { if (mFetchObserver) { @@ -479,7 +496,7 @@ public: } RefPtr<nsIGlobalObject> global = aWorkerPrivate->GlobalScope(); - RefPtr<Response> response = new Response(global, mInternalResponse); + RefPtr<Response> response = new Response(global, mInternalResponse, mResolver->GetAbortSignalForTargetThread()); promise->MaybeResolve(response); } else { if (mResolver->mFetchObserver) { @@ -926,6 +943,12 @@ template <class Derived> already_AddRefed<Promise> FetchBody<Derived>::ConsumeBody(FetchConsumeType aType, ErrorResult& aRv) { + RefPtr<AbortSignal> signal = DerivedClass()->GetSignal(); + if (signal && signal->Aborted()) { + aRv.Throw(NS_ERROR_DOM_ABORT_ERR); + return nullptr; + } + if (BodyUsed()) { aRv.ThrowTypeError<MSG_FETCH_BODY_CONSUMED_ERROR>(); return nullptr; @@ -935,7 +958,7 @@ FetchBody<Derived>::ConsumeBody(FetchConsumeType aType, ErrorResult& aRv) RefPtr<Promise> promise = FetchBodyConsumer<Derived>::Create(DerivedClass()->GetParentObject(), - this, aType, aRv); + this, signal, aType, aRv); if (NS_WARN_IF(aRv.Failed())) { return nullptr; } |