mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-07 08:18:41 +09:00
Issue #1587 Part 11 (followup 1): Implement multithreaded signals for workers.
This commit is contained in:
parent
95c5a64b1f
commit
1ae6431766
13 changed files with 823 additions and 728 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue