Bug 218753 - Support AbortSignal in addEventListenerOptions to unsubscribe from events
Summary: Support AbortSignal in addEventListenerOptions to unsubscribe from events
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL: https://dom.spec.whatwg.org/#add-an-e...
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-11-10 08:19 PST by Benjamin Gruenbaum
Modified: 2021-01-25 12:06 PST (History)
46 users (show)

See Also:


Attachments
Patch (81.77 KB, patch)
2021-01-22 15:26 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (81.85 KB, patch)
2021-01-22 15:30 PST, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (82.44 KB, patch)
2021-01-22 16:33 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (82.96 KB, patch)
2021-01-22 17:59 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (82.95 KB, patch)
2021-01-25 09:07 PST, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Benjamin Gruenbaum 2020-11-10 08:19:29 PST
See https://github.com/whatwg/dom/issues/911 and the spec PR https://github.com/whatwg/dom/pull/919 

I am working on adding support for AbortController in various web APIs. One of those is adding support for passing `AbortSignal`s to `addEventListener` and have an easy way to remove a lot of listeners.

As per the WHATWG process - I am filing a WebKit bug.

Please feel free to ask any questions or make suggestions regarding this.

I will follow up with WPTs in that PR.
Comment 1 Radar WebKit Bug Importer 2020-11-10 15:34:28 PST
<rdar://problem/71258012>
Comment 2 Chris Dumez 2021-01-22 15:26:04 PST
Created attachment 418185 [details]
Patch
Comment 3 Chris Dumez 2021-01-22 15:30:03 PST
Created attachment 418187 [details]
Patch
Comment 4 Chris Dumez 2021-01-22 16:33:20 PST
Created attachment 418199 [details]
Patch
Comment 5 EWS Watchlist 2021-01-22 16:34:32 PST
Thanks for the patch. If this patch contains new public API please make sure it follows the guidelines for new WebKit2 GTK+ API. See https://trac.webkit.org/wiki/WebKitGTK/AddingNewWebKit2API
Comment 6 Chris Dumez 2021-01-22 17:59:37 PST
Created attachment 418202 [details]
Patch
Comment 7 Darin Adler 2021-01-23 12:22:01 PST
Comment on attachment 418202 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=418202&action=review

> Source/WebCore/dom/AddEventListenerOptions.h:41
> +    AddEventListenerOptions(bool capture = false, Optional<bool> passive = WTF::nullopt, bool once = false, RefPtr<AbortSignal>&& signal = nullptr)
> +        : EventListenerOptions(capture)
> +        , passive(passive)
> +        , once(once)
> +        , signal(WTFMove(signal))
> +    {
> +    }

It’s nice to have structs with default values but without constructors when we can. I guess there is code that depends on this?

> Source/WebCore/dom/EventListener.h:37
> +class EventListener : public RefCounted<EventListener>, public CanMakeWeakPtr<EventListener> {

I’m assuming there are not cases where an EventListener was:

1) not already doing the weak pointer thing
2) a small object allocated many, many times

But I didn’t audit all the uses the way I often would when asking myself a question like that.

> Source/WebCore/dom/EventListenerOptions.h:33
> +    EventListenerOptions(bool capture = false)
> +        : capture(capture)
> +    { }

It’s nice to have structs with default values but without constructors when we can. I guess there is code that depends on this?
Comment 8 Chris Dumez 2021-01-25 08:58:15 PST
Comment on attachment 418202 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=418202&action=review

>> Source/WebCore/dom/AddEventListenerOptions.h:41
>> +    }
> 
> It’s nice to have structs with default values but without constructors when we can. I guess there is code that depends on this?

There are call sites that call addEventListener with a simple boolean like so:
addEventListener(type, listener, true)

Using struct initialization here would be a bit awkward here I think, especially considering it involves struct inheritance.
Comment 9 Chris Dumez 2021-01-25 09:07:30 PST
Created attachment 418299 [details]
Patch
Comment 10 EWS 2021-01-25 12:06:31 PST
Committed r271806: <https://trac.webkit.org/changeset/271806>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 418299 [details].