@@ -278,7 +278,11 @@ function imgFetched(ev) {
278
278
<a>Event listeners</a> can be removed
279
279
by utilizing the
280
280
{{EventTarget/removeEventListener()}}
281
- method, passing the same arguments.
281
+ method passing the same arguments.
282
+
283
+ Alternatively, <a>event listeners</a> can be removed by passing an {{AbortSignal}} to
284
+ {{EventTarget/addEventListener()}} and calling {{AbortController/abort()}} on the controller
285
+ owning the signal.
282
286
283
287
<a>Events</a> are objects too and implement the
284
288
{{Event}} interface (or a derived interface). In the example above
@@ -962,6 +966,7 @@ dictionary EventListenerOptions {
962
966
dictionary AddEventListenerOptions : EventListenerOptions {
963
967
boolean passive = false;
964
968
boolean once = false;
969
+ AbortSignal signal;
965
970
};
966
971
</pre>
967
972
@@ -981,6 +986,7 @@ when something has occurred.
981
986
<li> <dfn for="event listener">capture</dfn> (a boolean, initially false)
982
987
<li> <dfn for="event listener">passive</dfn> (a boolean, initially false)
983
988
<li> <dfn for="event listener">once</dfn> (a boolean, initially false)
989
+ <li> <dfn for="event listener">signal</dfn> (null or an {{AbortSignal}} object)
984
990
<li> <dfn for="event listener">removed</dfn> (a boolean for bookkeeping purposes, initially false)
985
991
</ul>
986
992
@@ -1042,6 +1048,9 @@ are not to be used for anything else. [[!HTML]]
1042
1048
<a for="event listener">callback</a> will only be invoked once after which the event listener will
1043
1049
be removed.
1044
1050
1051
+ <p> If an {{AbortSignal}} is passed for <var> options</var> 's {{AddEventListenerOptions/signal}} ,
1052
+ then the event listener will be removed when signal is aborted.
1053
+
1045
1054
<p> The <a>event listener</a> is appended to <var> target</var> 's
1046
1055
<a for=EventTarget>event listener list</a> and is not appended if it has the same
1047
1056
<a for="event listener">type</a> , <a for="event listener">callback</a> , and
@@ -1064,7 +1073,7 @@ steps:
1064
1073
<ol>
1065
1074
<li><p> If <var> options</var> is a boolean, then return <var> options</var> .
1066
1075
1067
- <li><p> Return <var> options</var> 's <code> {{EventListenerOptions/capture}} </code> .
1076
+ <li><p> Return | options| [" {{EventListenerOptions/capture}}"] .
1068
1077
</ol>
1069
1078
1070
1079
<p> To <dfn export for=Event>flatten more</dfn> <!-- sorry --> <var> options</var> , run these
@@ -1075,11 +1084,20 @@ steps:
1075
1084
1076
1085
<li><p> Let <var> once</var> and <var> passive</var> be false.
1077
1086
1078
- <li><p> If <var> options</var> is a dictionary, then set <var> passive</var> to <var> options</var> 's
1079
- <code> {{AddEventListenerOptions/passive}} </code> and <var> once</var> to <var> options</var> 's
1080
- <code> {{AddEventListenerOptions/once}} </code> .
1087
+ <li><p> Let |signal| be null.
1088
+
1089
+ <li>
1090
+ <p> If |options| is a dictionary, then:
1091
+
1092
+ <ol>
1093
+ <li><p> Set |passive| to |options|["{{AddEventListenerOptions/passive}}"] and |once| to
1094
+ |options|["{{AddEventListenerOptions/once}}"] .
1095
+
1096
+ <li><p> If |options|["{{AddEventListenerOptions/signal}}"] [=map/exists=] , then set |signal| to
1097
+ |options|["{{AddEventListenerOptions/signal}}"] .
1098
+ </ol>
1081
1099
1082
- <li><p> Return <var> capture</var> , <var> passive</var> , and <var> once </var> .
1100
+ <li><p> Return <var> capture</var> , <var> passive</var> , <var> once </var> , and <var> signal </var> .
1083
1101
</ol>
1084
1102
1085
1103
<p> The <dfn constructor for=EventTarget><code>EventTarget()</code></dfn> constructor, when invoked,
@@ -1105,6 +1123,9 @@ participate in a tree structure.</p>
1105
1123
<a>service worker events</a> , then <a>report a warning to the console</a> that this might not give
1106
1124
the expected results. [[!SERVICE-WORKERS]]
1107
1125
1126
+ <li><p> If <a for="event listener">signal</a> is not null and its [=AbortSignal/aborted flag=] is
1127
+ set, then return.
1128
+
1108
1129
<li><p> If <var> listener</var> 's <a for="event listener">callback</a> is null, then return.
1109
1130
1110
1131
<li><p> If <var> eventTarget</var> 's <a>event listener list</a> does not <a for=list>contain</a> an
@@ -1113,6 +1134,14 @@ participate in a tree structure.</p>
1113
1134
<a for="event listener">callback</a> , and <a for="event listener">capture</a> is
1114
1135
<var> listener</var> 's <a for="event listener">capture</a> , then <a for=list>append</a>
1115
1136
<var> listener</var> to <var> eventTarget</var> 's <a>event listener list</a> .
1137
+
1138
+ <li>
1139
+ <p> If <var> listener</var> 's <a for="event listener">signal</a> is not null, then
1140
+ <a for=AbortSignal lt=add>add the following</a> abort steps to it:
1141
+
1142
+ <ol>
1143
+ <li> <a>Remove an event listener</a> with <var> eventTarget</var> and <var> listener</var> .
1144
+ </ol>
1116
1145
</ol>
1117
1146
1118
1147
<p class=note> The <a>add an event listener</a> concept exists to ensure <a>event handlers</a> use
@@ -1129,8 +1158,8 @@ method, when invoked, must run these steps:
1129
1158
<li><p> <a>Add an event listener</a> with <a>this</a> and an <a>event listener</a> whose
1130
1159
<a for="event listener">type</a> is <var> type</var> , <a for="event listener">callback</a> is
1131
1160
<var> callback</var> , <a for="event listener">capture</a> is <var> capture</var> ,
1132
- <a for="event listener">passive</a> is <var> passive</var> , and <a for="event listener">once</a> is
1133
- <var> once</var> .
1161
+ <a for="event listener">passive</a> is <var> passive</var> , <a for="event listener">once</a> is
1162
+ <var> once</var> , and <a for="event listener">signal</a> is <var> signal </var> .
1134
1163
</ol>
1135
1164
1136
1165
<p> To <dfn export>remove an event listener</dfn> , given an {{EventTarget}} object
@@ -9959,6 +9988,7 @@ Anthony Ramine,
9959
9988
Arkadiusz Michalski,
9960
9989
Arnaud Le Hors,
9961
9990
Arun Ranganathan,
9991
+ Benjamin Gruenbaum,
9962
9992
Björn Höhrmann,
9963
9993
Boris Zbarsky,
9964
9994
Brandon Payton,
0 commit comments