Bug 1660555 - Split AbortFollower::Abort into AbortFollower::RunAbortAlgorithm and AbortSignalImpl::SignalAbort functions for readability. r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D92321
This commit is contained in:
Jeff Walden 2020-10-22 07:42:18 +00:00
parent eadce53226
commit e1ed5804d7
13 changed files with 49 additions and 32 deletions

View File

@ -61,7 +61,7 @@ void AbortController::Abort() {
mAborted = true;
if (mSignal) {
mSignal->Abort();
mSignal->SignalAbort();
}
}

View File

@ -19,7 +19,7 @@ AbortSignalImpl::AbortSignalImpl(bool aAborted) : mAborted(aAborted) {}
bool AbortSignalImpl::Aborted() const { return mAborted; }
void AbortSignalImpl::Abort() {
void AbortSignalImpl::SignalAbort() {
if (mAborted) {
return;
}
@ -28,7 +28,7 @@ void AbortSignalImpl::Abort() {
// Let's inform the followers.
for (RefPtr<AbortFollower> follower : mFollowers.ForwardRange()) {
follower->Abort();
follower->RunAbortAlgorithm();
}
}
@ -73,8 +73,8 @@ JSObject* AbortSignal::WrapObject(JSContext* aCx,
return AbortSignal_Binding::Wrap(aCx, this, aGivenProto);
}
void AbortSignal::Abort() {
AbortSignalImpl::Abort();
void AbortSignal::SignalAbort() {
AbortSignalImpl::SignalAbort();
EventInit init;
init.mBubbles = false;

View File

@ -23,7 +23,7 @@ class AbortFollower {
public:
NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
virtual void Abort() = 0;
virtual void RunAbortAlgorithm() = 0;
void Follow(AbortSignalImpl* aSignal);
@ -39,18 +39,13 @@ class AbortFollower {
RefPtr<AbortSignalImpl> mFollowingSignal;
};
// Any subclass of this class must Traverse mFollowingSignal and call
// Unfollow() when Unlinking.
class AbortSignalImpl : public AbortFollower, public nsISupports {
class AbortSignalImpl : public nsISupports {
public:
using nsISupports::AddRef;
using nsISupports::Release;
explicit AbortSignalImpl(bool aAborted);
bool Aborted() const;
void Abort() override;
virtual void SignalAbort();
void AddFollower(AbortFollower* aFollower);
@ -66,7 +61,21 @@ class AbortSignalImpl : public AbortFollower, public nsISupports {
bool mAborted;
};
class AbortSignal final : public DOMEventTargetHelper, public AbortSignalImpl {
// AbortSignal the spec concept includes the concept of a child signal
// "following" a parent signal -- internally, adding abort steps to the parent
// signal that will then signal abort on the child signal -- to propagate
// signaling abort from one signal to another. See
// <https://dom.spec.whatwg.org/#abortsignal-follow>.
//
// This requires that AbortSignal also inherit from AbortFollower.
//
// This ability to follow isn't directly exposed in the DOM; as of this writing
// it appears only to be used internally in the Fetch API. It might be a good
// idea to split AbortSignal into an implementation that can follow, and an
// implementation that can't, to provide this complexity only when it's needed.
class AbortSignal final : public DOMEventTargetHelper,
public AbortSignalImpl,
public AbortFollower {
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AbortSignal, DOMEventTargetHelper)
@ -78,7 +87,11 @@ class AbortSignal final : public DOMEventTargetHelper, public AbortSignalImpl {
IMPL_EVENT_HANDLER(abort);
void Abort() override;
// AbortSignalImpl
void SignalAbort() override;
// AbortFollower
void RunAbortAlgorithm() override { SignalAbort(); }
private:
~AbortSignal() = default;

View File

@ -803,7 +803,7 @@ NS_IMETHODIMP BodyConsumer::Observe(nsISupports* aSubject, const char* aTopic,
return NS_OK;
}
void BodyConsumer::Abort() {
void BodyConsumer::RunAbortAlgorithm() {
AssertIsOnTargetThread();
ShutDownMainThreadConsuming();
ContinueConsumeBody(NS_ERROR_DOM_ABORT_ERR, 0, nullptr);

View File

@ -90,7 +90,7 @@ class BodyConsumer final : public nsIObserver,
}
// AbortFollower
void Abort() override;
void RunAbortAlgorithm() override;
private:
BodyConsumer(nsIEventTarget* aMainThreadEventTarget,

View File

@ -94,11 +94,11 @@ class AbortSignalMainThread final : public AbortSignalImpl {
NS_IMPL_CYCLE_COLLECTION_CLASS(AbortSignalMainThread)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(AbortSignalMainThread)
tmp->Unfollow();
// This is filled with new operations shortly.
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(AbortSignalMainThread)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFollowingSignal)
// This is filled with new operations shortly.
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AbortSignalMainThread)
@ -135,7 +135,7 @@ class AbortSignalProxy final : public AbortFollower {
MOZ_ASSERT(NS_IsMainThread());
AbortSignalImpl* signalImpl =
mProxy->GetOrCreateSignalImplForMainThread();
signalImpl->Abort();
signalImpl->SignalAbort();
return NS_OK;
}
};
@ -151,7 +151,8 @@ class AbortSignalProxy final : public AbortFollower {
Follow(aSignalImpl);
}
void Abort() override {
// AbortFollower
void RunAbortAlgorithm() override {
RefPtr<AbortSignalProxyRunnable> runnable =
new AbortSignalProxyRunnable(this);
mMainThreadEventTarget->Dispatch(runnable.forget(), NS_DISPATCH_NORMAL);
@ -1467,7 +1468,7 @@ template void FetchBody<Response>::MaybeTeeReadableStreamBody(
ErrorResult& aRv);
template <class Derived>
void FetchBody<Derived>::Abort() {
void FetchBody<Derived>::RunAbortAlgorithm() {
if (!mReadableStreamBody) {
return;
}
@ -1484,9 +1485,9 @@ void FetchBody<Derived>::Abort() {
AbortStream(cx, body, result);
}
template void FetchBody<Request>::Abort();
template void FetchBody<Request>::RunAbortAlgorithm();
template void FetchBody<Response>::Abort();
template void FetchBody<Response>::RunAbortAlgorithm();
} // namespace dom
} // namespace mozilla

View File

@ -210,7 +210,7 @@ class FetchBody : public BodyStreamHolder, public AbortFollower {
virtual AbortSignalImpl* GetSignalImpl() const = 0;
// AbortFollower
void Abort() override;
void RunAbortAlgorithm() override;
already_AddRefed<Promise> ConsumeBody(JSContext* aCx,
BodyConsumer::ConsumeType aType,

View File

@ -460,7 +460,7 @@ nsresult FetchDriver::Fetch(AbortSignalImpl* aSignalImpl,
// the operation.
if (aSignalImpl) {
if (aSignalImpl->Aborted()) {
Abort();
RunAbortAlgorithm();
return NS_OK;
}
@ -1579,7 +1579,7 @@ void FetchDriver::SetRequestHeaders(nsIHttpChannel* aChannel,
}
}
void FetchDriver::Abort() {
void FetchDriver::RunAbortAlgorithm() {
MOZ_DIAGNOSTIC_ASSERT(NS_IsMainThread());
if (mObserver) {

View File

@ -126,7 +126,7 @@ class FetchDriver final : public nsIStreamListener,
}
// AbortFollower
void Abort() override;
void RunAbortAlgorithm() override;
private:
nsCOMPtr<nsIPrincipal> mPrincipal;

View File

@ -43,7 +43,7 @@ JSObject* FetchObserver::WrapObject(JSContext* aCx,
FetchState FetchObserver::State() const { return mState; }
void FetchObserver::Abort() { SetState(FetchState::Aborted); }
void FetchObserver::RunAbortAlgorithm() { SetState(FetchState::Aborted); }
void FetchObserver::SetState(FetchState aState) {
MOZ_ASSERT(mState < aState);

View File

@ -30,7 +30,8 @@ class FetchObserver final : public DOMEventTargetHelper, public AbortFollower {
IMPL_EVENT_HANDLER(requestprogress);
IMPL_EVENT_HANDLER(responseprogress);
void Abort() override;
// AbortFollower
void RunAbortAlgorithm() override;
void SetState(FetchState aState);

View File

@ -826,7 +826,9 @@ void WebAuthnManager::RequestAborted(const uint64_t& aTransactionId,
}
}
void WebAuthnManager::Abort() { CancelTransaction(NS_ERROR_DOM_ABORT_ERR); }
void WebAuthnManager::RunAbortAlgorithm() {
CancelTransaction(NS_ERROR_DOM_ABORT_ERR);
}
} // namespace dom
} // namespace mozilla

View File

@ -104,7 +104,7 @@ class WebAuthnManager final : public WebAuthnManagerBase, public AbortFollower {
// AbortFollower
void Abort() override;
void RunAbortAlgorithm() override;
protected:
// Cancels the current transaction (by sending a Cancel message to the