Skip to content

Commit

Permalink
Bug 1679204 - Consider to add signal to addEventListener, r=edgar
Browse files Browse the repository at this point in the history
This passes the tests which are in web-platform-tests/wpt#26472

Because of complications in #include handling, AbortFollower needs to be in a different
header file than AbortSignal, yet AbortSignalImpl needs to be available when AbortFollower is used.
Another option would have been to make DOMEventTargetHelper.h a bit different and uninline some hot methods
there or move them to another file, but that would have been equally bad and Abort* is used way less often.
AbortFollower and AbortSignalImpl are thus just moved to a new header.

Memory management is such that Listener in EventListenerManager owns the possible ListenerSignalFollower
instance which follows the relevant signal. In order to be able remove event listener,
ListenerSignalFollower has many similar fields as Listener.
ListenerSignalFollower can't easily have just a pointer to Listener* since Listener isn't stored as a pointer
in EventListenerManager.
ListenerSignalFollower is cycle collectable so that Listener->ListenerSignalFollower can be traversed/unlinked
and also strong pointers in ListenerSignalFollower itself can be traversed/unlinked.

There is an XXX in the .webidl, since nullability of signal is unclear in the spec pr.
Whether or not it ends up being nullable shouldn't change the actual C++ implementation.

Differential Revision: https://phabricator.services.mozilla.com/D97938

UltraBlame original commit: b3d0fba5fd8d624b5abf53df196aedae5e83a269
  • Loading branch information
marco-c committed Dec 18, 2020
1 parent 25c746f commit 5a7a141
Show file tree
Hide file tree
Showing 8 changed files with 983 additions and 489 deletions.
472 changes: 472 additions & 0 deletions dom/abort/AbortFollower.h

Large diffs are not rendered by default.

330 changes: 6 additions & 324 deletions dom/abort/AbortSignal.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,21 +125,18 @@ include
"
mozilla
/
DOMEventTargetHelper
.
h
"
#
include
"
nsISupportsImpl
dom
/
AbortFollower
.
h
"
#
include
"
nsTObserverArray
mozilla
/
DOMEventTargetHelper
.
h
"
Expand All @@ -149,321 +146,6 @@ mozilla
namespace
dom
{
class
AbortSignal
;
class
AbortSignalImpl
;
/
/
This
class
must
be
implemented
by
objects
who
want
to
follow
an
/
/
AbortSignalImpl
.
class
AbortFollower
:
public
nsISupports
{
public
:
virtual
void
RunAbortAlgorithm
(
)
=
0
;
void
Follow
(
AbortSignalImpl
*
aSignal
)
;
void
Unfollow
(
)
;
bool
IsFollowing
(
)
const
;
AbortSignalImpl
*
Signal
(
)
const
{
return
mFollowingSignal
;
}
protected
:
/
/
Subclasses
of
this
class
must
call
these
Traverse
and
Unlink
functions
/
/
during
corresponding
cycle
collection
operations
.
static
void
Traverse
(
AbortFollower
*
aFollower
nsCycleCollectionTraversalCallback
&
cb
)
;
static
void
Unlink
(
AbortFollower
*
aFollower
)
{
aFollower
-
>
Unfollow
(
)
;
}
virtual
~
AbortFollower
(
)
;
friend
class
AbortSignalImpl
;
RefPtr
<
AbortSignalImpl
>
mFollowingSignal
;
}
;
class
AbortSignalImpl
:
public
nsISupports
{
public
:
explicit
AbortSignalImpl
(
bool
aAborted
)
;
bool
Aborted
(
)
const
;
virtual
void
SignalAbort
(
)
;
protected
:
/
/
Subclasses
of
this
class
must
call
these
Traverse
and
Unlink
functions
/
/
during
corresponding
cycle
collection
operations
.
static
void
Traverse
(
AbortSignalImpl
*
aSignal
nsCycleCollectionTraversalCallback
&
cb
)
;
static
void
Unlink
(
AbortSignalImpl
*
aSignal
)
{
/
/
To
be
filled
in
shortly
.
}
virtual
~
AbortSignalImpl
(
)
=
default
;
private
:
friend
class
AbortFollower
;
/
/
Raw
pointers
.
|
AbortFollower
:
:
Follow
|
adds
to
this
array
and
/
/
|
AbortFollower
:
:
Unfollow
|
(
also
callbed
by
the
destructor
)
will
remove
/
/
from
this
array
.
Finally
calling
|
SignalAbort
(
)
|
will
(
after
running
all
/
/
abort
algorithms
)
empty
this
and
make
all
contained
followers
|
Unfollow
(
)
|
.
nsTObserverArray
<
AbortFollower
*
>
mFollowers
;
bool
mAborted
;
}
;
/
/
AbortSignal
Expand Down
5 changes: 5 additions & 0 deletions dom/abort/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ AbortController
h
"
"
AbortFollower
.
h
"
"
AbortSignal
.
h
Expand Down
9 changes: 9 additions & 0 deletions dom/events/DOMEventTargetHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,15 @@ include
"
mozilla
/
EventListenerManager
.
h
"
#
include
"
mozilla
/
Likely
.
h
Expand Down
Loading

0 comments on commit 5a7a141

Please sign in to comment.