Backed out changeset 203ad2fab9aa (bug 1378342)

This commit is contained in:
Sebastian Hengst 2017-08-29 09:17:15 +02:00
Родитель 12299a2c87
Коммит d71637fab2
6 изменённых файлов: 125 добавлений и 6 удалений

Просмотреть файл

@ -12,7 +12,8 @@
namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(AbortController, mGlobal, mSignal)
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(AbortController, mGlobal, mSignal,
mFollowingSignal)
NS_IMPL_CYCLE_COLLECTING_ADDREF(AbortController)
NS_IMPL_CYCLE_COLLECTING_RELEASE(AbortController)
@ -94,5 +95,33 @@ AbortController::Abort()
}
}
void
AbortController::Follow(AbortSignal& aSignal)
{
AbortSignal::Follower::Follow(&aSignal);
}
void
AbortController::Unfollow(AbortSignal& aSignal)
{
if (mFollowingSignal != &aSignal) {
return;
}
AbortSignal::Follower::Unfollow();
}
AbortSignal*
AbortController::Following() const
{
return mFollowingSignal;
}
void
AbortController::Aborted()
{
Abort();
}
} // dom namespace
} // mozilla namespace

Просмотреть файл

@ -8,19 +8,16 @@
#define mozilla_dom_AbortController_h
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/AbortSignal.h"
#include "nsCycleCollectionParticipant.h"
#include "nsWrapperCache.h"
class nsIGlobalObject;
namespace mozilla {
namespace dom {
class AbortSignal;
class AbortController final : public nsISupports
, public nsWrapperCache
, public AbortSignal::Follower
{
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
@ -46,6 +43,19 @@ public:
void
Abort();
void
Follow(AbortSignal& aSignal);
void
Unfollow(AbortSignal& aSignal);
AbortSignal*
Following() const;
// AbortSignal::Follower
void Aborted() override;
private:
~AbortController() = default;

Просмотреть файл

@ -67,6 +67,8 @@ AbortSignal::Abort()
init.mBubbles = false;
init.mCancelable = false;
// TODO which kind of event should we dispatch here?
RefPtr<Event> event =
Event::Constructor(this, NS_LITERAL_STRING("abort"), init);
event->SetTrusted(true);
@ -91,6 +93,27 @@ AbortSignal::RemoveFollower(AbortSignal::Follower* aFollower)
mFollowers.RemoveElement(aFollower);
}
bool
AbortSignal::CanAcceptFollower(AbortSignal::Follower* aFollower) const
{
MOZ_DIAGNOSTIC_ASSERT(aFollower);
if (!mController) {
return true;
}
if (aFollower == mController) {
return false;
}
AbortSignal* following = mController->Following();
if (!following) {
return true;
}
return following->CanAcceptFollower(aFollower);
}
// AbortSignal::Follower
// ----------------------------------------------------------------------------
@ -104,6 +127,10 @@ AbortSignal::Follower::Follow(AbortSignal* aSignal)
{
MOZ_DIAGNOSTIC_ASSERT(aSignal);
if (!aSignal->CanAcceptFollower(this)) {
return;
}
Unfollow();
mFollowingSignal = aSignal;

Просмотреть файл

@ -59,6 +59,9 @@ public:
void
RemoveFollower(Follower* aFollower);
bool
CanAcceptFollower(Follower* aFollower) const;
private:
~AbortSignal() = default;

Просмотреть файл

@ -32,6 +32,49 @@ function testUpdateData() {
next();
}
function testFollowingOurself() {
// Let's follow ourself
var ac = new AbortController();
ac.follow(ac.signal);
ac.abort();
is(ac.signal.aborted, true, "Signal is aborted");
next();
}
function testFollowingOther() {
// Let's follow another one
var ac1 = new AbortController();
var ac2 = new AbortController();
ac1.follow(ac2.signal);
ac2.abort();
is(ac1.signal.aborted, true, "Signal is aborted");
is(ac2.signal.aborted, true, "Signal is aborted");
next();
}
function testFollowingLoop() {
// ac1 -> ac2 -> ac3 -> ac1
var ac1 = new AbortController();
var ac2 = new AbortController();
var ac3 = new AbortController();
ac1.follow(ac2.signal);
ac2.follow(ac3.signal);
ac3.follow(ac1.signal);
ac3.abort();
is(ac1.signal.aborted, true, "Signal is aborted");
is(ac2.signal.aborted, true, "Signal is aborted");
is(ac3.signal.aborted, true, "Signal is aborted");
next();
}
function testAbortEvent() {
var ac = new AbortController();
ac.signal.onabort = function(e) {
@ -88,6 +131,11 @@ var steps = [
testWebIDL,
testUpdateData,
// Following algorithm
testFollowingOurself,
testFollowingOther,
testFollowingLoop,
// Event propagation
testAbortEvent,

Просмотреть файл

@ -13,4 +13,6 @@ interface AbortController {
readonly attribute AbortSignal signal;
void abort();
void follow(AbortSignal signal);
void unfollow(AbortSignal signal);
};