Skip to content

Commit

Permalink
Bug 1378342 - AbortSignal/AbortController - part 9 - Request.signal s…
Browse files Browse the repository at this point in the history
…hould not be a reference of RequestInit.signal, r=bkelly
  • Loading branch information
bakulf committed Aug 29, 2017
1 parent de7116d commit 86e892d
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 61 deletions.
16 changes: 8 additions & 8 deletions dom/abort/AbortSignal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ AbortSignal::Abort()

// Let's inform the followers.
for (uint32_t i = 0; i < mFollowers.Length(); ++i) {
mFollowers[i]->Aborted();
mFollowers[i]->Abort();
}

EventInit init;
Expand All @@ -76,7 +76,7 @@ AbortSignal::Abort()
}

void
AbortSignal::AddFollower(AbortSignal::Follower* aFollower)
AbortSignal::AddFollower(AbortFollower* aFollower)
{
MOZ_DIAGNOSTIC_ASSERT(aFollower);
if (!mFollowers.Contains(aFollower)) {
Expand All @@ -85,22 +85,22 @@ AbortSignal::AddFollower(AbortSignal::Follower* aFollower)
}

void
AbortSignal::RemoveFollower(AbortSignal::Follower* aFollower)
AbortSignal::RemoveFollower(AbortFollower* aFollower)
{
MOZ_DIAGNOSTIC_ASSERT(aFollower);
mFollowers.RemoveElement(aFollower);
}

// AbortSignal::Follower
// AbortFollower
// ----------------------------------------------------------------------------

AbortSignal::Follower::~Follower()
AbortFollower::~AbortFollower()
{
Unfollow();
}

void
AbortSignal::Follower::Follow(AbortSignal* aSignal)
AbortFollower::Follow(AbortSignal* aSignal)
{
MOZ_DIAGNOSTIC_ASSERT(aSignal);

Expand All @@ -111,7 +111,7 @@ AbortSignal::Follower::Follow(AbortSignal* aSignal)
}

void
AbortSignal::Follower::Unfollow()
AbortFollower::Unfollow()
{
if (mFollowingSignal) {
mFollowingSignal->RemoveFollower(this);
Expand All @@ -120,7 +120,7 @@ AbortSignal::Follower::Unfollow()
}

bool
AbortSignal::Follower::IsFollowing() const
AbortFollower::IsFollowing() const
{
return !!mFollowingSignal;
}
Expand Down
43 changes: 22 additions & 21 deletions dom/abort/AbortSignal.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,31 @@ namespace dom {
class AbortController;
class AbortSignal;

class AbortSignal final : public DOMEventTargetHelper
// This class must be implemented by objects who want to follow a AbortSignal.
class AbortFollower
{
public:
// This class must be implemented by objects who want to follow a AbortSignal.
class Follower
{
public:
virtual void Aborted() = 0;
virtual void Abort() = 0;

protected:
virtual ~Follower();
void
Follow(AbortSignal* aSignal);

void
Follow(AbortSignal* aSignal);
void
Unfollow();

void
Unfollow();
bool
IsFollowing() const;

bool
IsFollowing() const;
protected:
virtual ~AbortFollower();

RefPtr<AbortSignal> mFollowingSignal;
};
RefPtr<AbortSignal> mFollowingSignal;
};

class AbortSignal final : public DOMEventTargetHelper
, public AbortFollower
{
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AbortSignal, DOMEventTargetHelper)

Expand All @@ -52,23 +53,23 @@ class AbortSignal final : public DOMEventTargetHelper
Aborted() const;

void
Abort();
Abort() override;

IMPL_EVENT_HANDLER(abort);

void
AddFollower(Follower* aFollower);
AddFollower(AbortFollower* aFollower);

void
RemoveFollower(Follower* aFollower);
RemoveFollower(AbortFollower* aFollower);

private:
~AbortSignal() = default;

RefPtr<AbortController> mController;

// Raw pointers. Follower unregisters itself in the DTOR.
nsTArray<Follower*> mFollowers;
// Raw pointers. AbortFollower unregisters itself in the DTOR.
nsTArray<AbortFollower*> mFollowers;

bool mAborted;
};
Expand Down
10 changes: 5 additions & 5 deletions dom/fetch/Fetch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ AbortStream(JSContext* aCx, JS::Handle<JSObject*> aStream)
} // anonymous

// This class helps the proxying of AbortSignal changes cross threads.
class AbortSignalProxy final : public AbortSignal::Follower
class AbortSignalProxy final : public AbortFollower
{
// This is created and released on the main-thread.
RefPtr<AbortSignal> mSignalMainThread;
Expand Down Expand Up @@ -124,7 +124,7 @@ class AbortSignalProxy final : public AbortSignal::Follower
}

void
Aborted() override
Abort() override
{
RefPtr<AbortSignalProxyRunnable> runnable =
new AbortSignalProxyRunnable(this);
Expand Down Expand Up @@ -1315,7 +1315,7 @@ FetchBody<Response>::MaybeTeeReadableStreamBody(JSContext* aCx,

template <class Derived>
void
FetchBody<Derived>::Aborted()
FetchBody<Derived>::Abort()
{
MOZ_ASSERT(mReadableStreamBody);

Expand All @@ -1332,11 +1332,11 @@ FetchBody<Derived>::Aborted()

template
void
FetchBody<Request>::Aborted();
FetchBody<Request>::Abort();

template
void
FetchBody<Response>::Aborted();
FetchBody<Response>::Abort();

} // namespace dom
} // namespace mozilla
6 changes: 3 additions & 3 deletions dom/fetch/Fetch.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class FetchStreamHolder
*/
template <class Derived>
class FetchBody : public FetchStreamHolder
, public AbortSignal::Follower
, public AbortFollower
{
public:
friend class FetchBodyConsumer<Derived>;
Expand Down Expand Up @@ -235,9 +235,9 @@ class FetchBody : public FetchStreamHolder
virtual AbortSignal*
GetSignal() const = 0;

// AbortSignal::Follower
// AbortFollower
void
Aborted() override;
Abort() override;

protected:
nsCOMPtr<nsIGlobalObject> mOwner;
Expand Down
2 changes: 1 addition & 1 deletion dom/fetch/FetchConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ FetchBodyConsumer<Derived>::Observe(nsISupports* aSubject,

template <class Derived>
void
FetchBodyConsumer<Derived>::Aborted()
FetchBodyConsumer<Derived>::Abort()
{
AssertIsOnTargetThread();
ContinueConsumeBody(NS_ERROR_DOM_ABORT_ERR, 0, nullptr);
Expand Down
6 changes: 3 additions & 3 deletions dom/fetch/FetchConsumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ template <class Derived> class FetchBody;
template <class Derived>
class FetchBodyConsumer final : public nsIObserver
, public nsSupportsWeakReference
, public AbortSignal::Follower
, public AbortFollower
{
public:
NS_DECL_THREADSAFE_ISUPPORTS
Expand Down Expand Up @@ -79,8 +79,8 @@ class FetchBodyConsumer final : public nsIObserver
mConsumeBodyPump = nullptr;
}

// AbortSignal::Follower
void Aborted() override;
// AbortFollower
void Abort() override;

private:
FetchBodyConsumer(nsIEventTarget* aMainThreadEventTarget,
Expand Down
4 changes: 2 additions & 2 deletions dom/fetch/FetchDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ FetchDriver::Fetch(AbortSignal* aSignal, FetchDriverObserver* aObserver)
// the operation.
if (aSignal) {
if (aSignal->Aborted()) {
Aborted();
Abort();
return NS_OK;
}

Expand Down Expand Up @@ -967,7 +967,7 @@ FetchDriver::SetRequestHeaders(nsIHttpChannel* aChannel) const
}

void
FetchDriver::Aborted()
FetchDriver::Abort()
{
if (mObserver) {
#ifdef DEBUG
Expand Down
7 changes: 3 additions & 4 deletions dom/fetch/FetchDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class FetchDriver final : public nsIStreamListener,
public nsIChannelEventSink,
public nsIInterfaceRequestor,
public nsIThreadRetargetableStreamListener,
public AbortSignal::Follower
public AbortFollower
{
public:
NS_DECL_ISUPPORTS
Expand Down Expand Up @@ -114,10 +114,9 @@ class FetchDriver final : public nsIStreamListener,
mWorkerScript = aWorkerScirpt;
}

// AbortSignal::Follower

// AbortFollower
void
Aborted() override;
Abort() override;

private:
nsCOMPtr<nsIPrincipal> mPrincipal;
Expand Down
2 changes: 1 addition & 1 deletion dom/fetch/FetchObserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ FetchObserver::State() const
}

void
FetchObserver::Aborted()
FetchObserver::Abort()
{
SetState(FetchState::Aborted);
}
Expand Down
4 changes: 2 additions & 2 deletions dom/fetch/FetchObserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace mozilla {
namespace dom {

class FetchObserver final : public DOMEventTargetHelper
, public AbortSignal::Follower
, public AbortFollower
{
public:
NS_DECL_ISUPPORTS_INHERITED
Expand All @@ -37,7 +37,7 @@ class FetchObserver final : public DOMEventTargetHelper
IMPL_EVENT_HANDLER(responseprogress);

void
Aborted() override;
Abort() override;

void
SetState(FetchState aState);
Expand Down
10 changes: 8 additions & 2 deletions dom/fetch/Request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,20 @@ Request::Request(nsIGlobalObject* aOwner, InternalRequest* aRequest,
AbortSignal* aSignal)
: FetchBody<Request>(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.
if (aSignal) {
// If we don't have a signal as argument, we will create it when required by
// content, otherwise the Request's signal must follow what has been passed.
mSignal = new AbortSignal(aSignal->Aborted());
if (!mSignal->Aborted()) {
mSignal->Follow(aSignal);
}
}
}

Request::~Request()
Expand Down
9 changes: 0 additions & 9 deletions testing/web-platform/meta/fetch/api/abort/general.html.ini
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[general.html]
type: testharness
expected: TIMEOUT
[Window: Signal on request object]
expected: FAIL

[Window: Signal removed by setting to null]
expected: FAIL

Expand All @@ -13,9 +10,6 @@
[Window: Readable stream synchronously cancels with AbortError if aborted before reading]
expected: FAIL
[DedicatedWorkerGlobalScope: Signal on request object]
expected: FAIL
[DedicatedWorkerGlobalScope: Signal removed by setting to null]
expected: FAIL
Expand All @@ -28,9 +22,6 @@
[DedicatedWorkerGlobalScope: Readable stream synchronously cancels with AbortError if aborted before reading]
expected: FAIL

[SharedWorkerGlobalScope: Signal on request object]
expected: FAIL

[SharedWorkerGlobalScope: Signal removed by setting to null]
expected: FAIL

Expand Down

0 comments on commit 86e892d

Please sign in to comment.