From d67e3350237ec0a6edb426325e67b4620482f81d Mon Sep 17 00:00:00 2001 From: Benjamin Gruenbaum Date: Mon, 9 Nov 2020 19:30:02 +0200 Subject: [PATCH 1/5] add signal to addEventListener Adds support for AbortSignals in EventTarget's addEventListener options --- dom.bs | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/dom.bs b/dom.bs index b6485822..31dc908e 100644 --- a/dom.bs +++ b/dom.bs @@ -278,7 +278,11 @@ function imgFetched(ev) { Event listeners can be removed by utilizing the {{EventTarget/removeEventListener()}} -method, passing the same arguments. +method passing the same arguments. + +Alternatively, event listeners can be removed by passing an {{AbortSignal}} to +{{EventTarget/addEventListener()}} and calling {{AbortController/abort()}} on the controller +owning the signal. Events are objects too and implement the {{Event}} interface (or a derived interface). In the example above @@ -962,6 +966,7 @@ dictionary EventListenerOptions { dictionary AddEventListenerOptions : EventListenerOptions { boolean passive = false; boolean once = false; + AbortSignal signal; }; @@ -981,6 +986,7 @@ when something has occurred.
  • capture (a boolean, initially false)
  • passive (a boolean, initially false)
  • once (a boolean, initially false) +
  • signal (null or an {{AbortSignal}} object)
  • removed (a boolean for bookkeeping purposes, initially false) @@ -1042,6 +1048,9 @@ are not to be used for anything else. [[!HTML]] callback will only be invoked once after which the event listener will be removed. +

    If an {{AbortSignal}} is passed for options's {{AddEventListenerOptions/signal}} + then the event listener will be removed when signal is aborted. +

    The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and @@ -1075,11 +1084,17 @@ steps:

  • Let once and passive be false. +

  • Let signal be null. +

  • If options is a dictionary, then set passive to options's - {{AddEventListenerOptions/passive}} and once to options's + {{AddEventListenerOptions/passive}}, once to options's {{AddEventListenerOptions/once}}. -

  • Return capture, passive, and once. +

  • If |options| is a dictionary and |options|["{{AddEventListenerOptions/signal}}"] [=map/exists=], + then set |signal| to |options|["{{AddEventListenerOptions/signal}}"]. + + +

  • Return capture, passive, once and signal.

    The EventTarget() constructor, when invoked, @@ -1105,6 +1120,9 @@ participate in a tree structure.

    service worker events, then report a warning to the console that this might not give the expected results. [[!SERVICE-WORKERS]] +
  • If signal is not null and its [=AbortSignal/aborted flag=] is + set, then return. +

  • If listener's callback is null, then return.

  • If eventTarget's event listener list does not contain an @@ -1113,6 +1131,12 @@ participate in a tree structure.

    callback, and capture is listener's capture, then append listener to eventTarget's event listener list. + +
  • If signal is not null then add the following + abort steps to it: +

      +
    1. Remove an event listener with eventTarget and listener. +

    The add an event listener concept exists to ensure event handlers use @@ -1129,8 +1153,8 @@ method, when invoked, must run these steps:

  • Add an event listener with this and an event listener whose type is type, callback is callback, capture is capture, - passive is passive, and once is - once. + passive is passive, once is + once, and signal is signal.

    To remove an event listener, given an {{EventTarget}} object From ab05ff3ab7a9150239a42996117ba641d8355a43 Mon Sep 17 00:00:00 2001 From: Benjamin Gruenbaum Date: Tue, 1 Dec 2020 18:58:01 +0200 Subject: [PATCH 2/5] more code review --- dom.bs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dom.bs b/dom.bs index 31dc908e..425a1a2e 100644 --- a/dom.bs +++ b/dom.bs @@ -1087,14 +1087,13 @@ steps:

  • Let signal be null.

  • If options is a dictionary, then set passive to options's - {{AddEventListenerOptions/passive}}, once to options's + {{AddEventListenerOptions/passive}} and once to options's {{AddEventListenerOptions/once}}.

  • If |options| is a dictionary and |options|["{{AddEventListenerOptions/signal}}"] [=map/exists=], then set |signal| to |options|["{{AddEventListenerOptions/signal}}"]. - -

  • Return capture, passive, once and signal. +

  • Return capture, passive, once, and signal.

    The EventTarget() constructor, when invoked, @@ -1132,7 +1131,8 @@ participate in a tree structure.

    listener's capture, then append listener to eventTarget's event listener list. -
  • If signal is not null then add the following +

  • +

    If signal is not null, then add the following abort steps to it:

    1. Remove an event listener with eventTarget and listener. From 5266342d7c312d9cc7678227f3e15fb85e76ca8f Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Wed, 2 Dec 2020 10:33:47 +0100 Subject: [PATCH 3/5] nits --- dom.bs | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/dom.bs b/dom.bs index 425a1a2e..804245dc 100644 --- a/dom.bs +++ b/dom.bs @@ -1048,7 +1048,7 @@ are not to be used for anything else. [[!HTML]] callback will only be invoked once after which the event listener will be removed. -

      If an {{AbortSignal}} is passed for options's {{AddEventListenerOptions/signal}} +

      If an {{AbortSignal}} is passed for options's {{AddEventListenerOptions/signal}}, then the event listener will be removed when signal is aborted.

      The event listener is appended to target's @@ -1084,14 +1084,18 @@ steps:

    2. Let once and passive be false. -

    3. Let signal be null. +

    4. Let |signal| be null. -

    5. If options is a dictionary, then set passive to options's - {{AddEventListenerOptions/passive}} and once to options's - {{AddEventListenerOptions/once}}. +

    6. +

      If |options| is a dictionary, then: + +

        +
      1. Set |passive| to |options|["{{AddEventListenerOptions/passive}}"] and |once| to + |options|["{{AddEventListenerOptions/once}}"]. -

      2. If |options| is a dictionary and |options|["{{AddEventListenerOptions/signal}}"] [=map/exists=], - then set |signal| to |options|["{{AddEventListenerOptions/signal}}"]. +

      3. If |options|["{{AddEventListenerOptions/signal}}"] [=map/exists=], then set |signal| to + |options|["{{AddEventListenerOptions/signal}}"]. +

    7. Return capture, passive, once, and signal.

    @@ -1131,12 +1135,13 @@ participate in a tree structure.

    listener's capture, then append listener to eventTarget's event listener list. -
  • -

    If signal is not null, then add the following - abort steps to it: -

      -
    1. Remove an event listener with eventTarget and listener. -
    +
  • +

    If listener's signal is not null, then + add the following abort steps to it: + +

      +
    1. Remove an event listener with eventTarget and listener. +

    The add an event listener concept exists to ensure event handlers use From b2df711c7660d37b30ae979c15dca76ef731ca32 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Wed, 2 Dec 2020 10:37:13 +0100 Subject: [PATCH 4/5] make the one other event listener dictionary thing consistent --- dom.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dom.bs b/dom.bs index 804245dc..242852d3 100644 --- a/dom.bs +++ b/dom.bs @@ -1073,7 +1073,7 @@ steps:

    1. If options is a boolean, then return options. -

    2. Return options's {{EventListenerOptions/capture}}. +

    3. Return |options|["{{EventListenerOptions/capture}}"].

    To flatten more options, run these From 0699e74487ca4a7aa55fabe3a5c8b934ee570664 Mon Sep 17 00:00:00 2001 From: Benjamin Gruenbaum Date: Thu, 3 Dec 2020 17:59:47 +0200 Subject: [PATCH 5/5] add myself to acks --- dom.bs | 1 + 1 file changed, 1 insertion(+) diff --git a/dom.bs b/dom.bs index 242852d3..634db8ec 100644 --- a/dom.bs +++ b/dom.bs @@ -9988,6 +9988,7 @@ Anthony Ramine, Arkadiusz Michalski, Arnaud Le Hors, Arun Ranganathan, +Benjamin Gruenbaum, Björn Höhrmann, Boris Zbarsky, Brandon Payton,