diff options
author | Moonchild <moonchild@palemoon.org> | 2020-07-24 11:09:54 +0000 |
---|---|---|
committer | Moonchild <moonchild@palemoon.org> | 2020-07-28 10:38:04 +0000 |
commit | 71848c23a4d09bbb7eff1b27d2cb28904e35240d (patch) | |
tree | 3ee22a605fd936c5e97ce1c4baf18c33d1f17407 /dom/fetch/Request.cpp | |
parent | 1d321e689e7dcad9cf9519c19e0710c6bf1333a7 (diff) | |
download | UXP-71848c23a4d09bbb7eff1b27d2cb28904e35240d.tar UXP-71848c23a4d09bbb7eff1b27d2cb28904e35240d.tar.gz UXP-71848c23a4d09bbb7eff1b27d2cb28904e35240d.tar.lz UXP-71848c23a4d09bbb7eff1b27d2cb28904e35240d.tar.xz UXP-71848c23a4d09bbb7eff1b27d2cb28904e35240d.zip |
Issue #1587 Part 11 (followup 1): Implement multithreaded signals for workers.
Diffstat (limited to 'dom/fetch/Request.cpp')
-rw-r--r-- | dom/fetch/Request.cpp | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/dom/fetch/Request.cpp b/dom/fetch/Request.cpp index 6a7885b1a..ba268d331 100644 --- a/dom/fetch/Request.cpp +++ b/dom/fetch/Request.cpp @@ -37,15 +37,18 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Request) NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_END -Request::Request(nsIGlobalObject* aOwner, InternalRequest* aRequest) +Request::Request(nsIGlobalObject* aOwner, InternalRequest* aRequest, AbortSignal* aSignal) : FetchBody<Request>() , mOwner(aOwner) , mRequest(aRequest) + , mSignal(aSignal) { MOZ_ASSERT(aRequest->Headers()->Guard() == HeadersGuardEnum::Immutable || aRequest->Headers()->Guard() == HeadersGuardEnum::Request || aRequest->Headers()->Guard() == HeadersGuardEnum::Request_no_cors); SetMimeType(); + + // aSignal can be null. } Request::~Request() @@ -286,6 +289,8 @@ Request::Constructor(const GlobalObject& aGlobal, RefPtr<InternalRequest> request; nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports()); + + RefPtr<AbortSignal> signal; if (aInput.IsRequest()) { RefPtr<Request> inputReq = &aInput.GetAsRequest(); @@ -300,6 +305,7 @@ Request::Constructor(const GlobalObject& aGlobal, } request = inputReq->GetInternalRequest(); + signal = inputReq->GetOrCreateSignal(); } else { // aInput is USVString. // We need to get url before we create a InternalRequest. @@ -418,6 +424,10 @@ Request::Constructor(const GlobalObject& aGlobal, request->SetReferrerPolicy(aInit.mReferrerPolicy.Value()); } + if (aInit.mSignal.WasPassed()) { + signal = &aInit.mSignal.Value(); + } + if (NS_IsMainThread()) { nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(global); if (window) { @@ -579,7 +589,7 @@ Request::Constructor(const GlobalObject& aGlobal, } } - RefPtr<Request> domRequest = new Request(global, request); + RefPtr<Request> domRequest = new Request(global, request, signal); domRequest->SetMimeType(); if (aInput.IsRequest()) { @@ -595,7 +605,7 @@ Request::Constructor(const GlobalObject& aGlobal, } already_AddRefed<Request> -Request::Clone(ErrorResult& aRv) const +Request::Clone(ErrorResult& aRv) { if (BodyUsed()) { aRv.ThrowTypeError<MSG_FETCH_BODY_CONSUMED_ERROR>(); @@ -608,7 +618,7 @@ Request::Clone(ErrorResult& aRv) const return nullptr; } - RefPtr<Request> request = new Request(mOwner, ir); + RefPtr<Request> request = new Request(mOwner, ir, GetOrCreateSignal()); return request.forget(); } @@ -622,5 +632,21 @@ Request::Headers_() return mHeaders; } +AbortSignal* +Request::GetOrCreateSignal() +{ + if (!mSignal) { + mSignal = new AbortSignal(false); + } + + return mSignal; +} + +AbortSignal* +Request::GetSignal() const +{ + return mSignal; +} + } // namespace dom } // namespace mozilla |