Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add signal to addEventListener #919

Merged
merged 5 commits into from
Dec 3, 2020
Merged

Conversation

benjamingr
Copy link
Member

@benjamingr benjamingr commented Nov 9, 2020

An attempt to try and fix #911 and get more familiar with the spec in the process.

I am happy to contribute WPT for this if that would help.

(See WHATWG Working Mode: Changes for more details.)


Preview | Diff

dom.bs Outdated Show resolved Hide resolved
dom.bs Outdated Show resolved Hide resolved
dom.bs Outdated Show resolved Hide resolved
dom.bs Outdated Show resolved Hide resolved
dom.bs Outdated Show resolved Hide resolved
dom.bs Outdated Show resolved Hide resolved
@benjamingr
Copy link
Member Author

Thanks for the feedback @domenic - please take a look :]

@benjamingr
Copy link
Member Author

I am also not sure what "Participation" is and I believe I contributed to whatwg small fixes to repos (like whatwg/fetch) in the past - but just in case I signed https://participate.whatwg.org/submit-agreement since that's what the contribution guide pointed to

@annevk
Copy link
Member

annevk commented Nov 10, 2020

(You contributed to Fetch before WHATWG had an IPR Policy in place.)

@benjamingr
Copy link
Member Author

@annevk thanks, I've signed the agreement.

I'll move this PR from draft - though I am not sure what the next steps to contribute are.

A browser (chrome) has expressed interest in this and opened a crbug and work item for this (yay!).

Do I:

  • Prototype this in Node.js using our own EventTarget? (probably won't count/help right?)
  • Write down WPTs for the feature?
  • Open bugs for other browsers and ask them for feedback?

Sorry if it's a stupid question - feel free to point me towards reading material :]

@annevk
Copy link
Member

annevk commented Nov 10, 2020

All of these seem like good steps to take (and the latter two are required, see https://whatwg.org/working-mode#changes). Node.js wouldn't count on its own indeed, but it might help with persuading implementers and verifying the approach. I'll ping some people internally too.

@benjamingr benjamingr marked this pull request as ready for review November 10, 2020 16:01
@benjamingr
Copy link
Member Author

Great, thanks (appreciate it!).

I've opened https://bugs.webkit.org/show_bug.cgi?id=218753 in WebKit - would it be better if I opened the bug for Firefox or if you did it?

I'll try to follow up with WPTs next week or asap.

@annevk
Copy link
Member

annevk commented Nov 10, 2020

FWIW, I checked and I'm pretty confident that Mozilla is supportive of adding this as well. Maybe wait with filing a bug until the tests and such are there.

@annevk annevk requested a review from domenic November 10, 2020 16:37
@annevk annevk added the topic: aborting AbortController and AbortSignal label Nov 10, 2020
dom.bs Outdated Show resolved Hide resolved
dom.bs Outdated Show resolved Hide resolved
dom.bs Outdated Show resolved Hide resolved
@domenic
Copy link
Member

domenic commented Nov 10, 2020

@benjamingr to confirm on the agreement front, you signed up saying that you do not work in the field of web technologies. Is that correct?

@benjamingr
Copy link
Member Author

@domenic

you signed up saying that you do not work in the field of web technologies. Is that correct?

Correct, my role at Testim.io does not involve working on "creating and influencing web standards and web technologies that could be adopted by the web community" - all of that is my free time though I hope this changes in the future.

I have not (ever) been paid by an employer company or business entity for any of the open source work I do.

@domenic
Copy link
Member

domenic commented Nov 10, 2020

Awesome, thanks for confirming; I'll verify you then.

@benjamingr
Copy link
Member Author

Initial work on WPTs: web-platform-tests/wpt#26472

Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this, found a final set of nits, but it seems this is ready to land soon.

dom.bs Outdated Show resolved Hide resolved
dom.bs Outdated Show resolved Hide resolved
dom.bs Outdated Show resolved Hide resolved
dom.bs Outdated Show resolved Hide resolved
dom.bs Show resolved Hide resolved
Adds support for AbortSignals in EventTarget's addEventListener options
@benjamingr
Copy link
Member Author

Hey, thanks. I've addressed the comments above, rebased and squashed to it's one clear commit. PTAL :]

Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if you want help with the final nits. Since I've done a couple rounds I would appreciate if @domenic could do a final spot check as well and then we can merge.

dom.bs Outdated Show resolved Hide resolved
dom.bs Show resolved Hide resolved
dom.bs Outdated Show resolved Hide resolved
dom.bs Outdated Show resolved Hide resolved
@benjamingr
Copy link
Member Author

I am in no rush to merge this and am happy to improve things. My motivation for working on this was to learn how to contribute better so I am happy to iterate on this more if you have more suggestions. I do want to eventually merge this :)

@annevk annevk requested a review from domenic December 2, 2020 09:37
@benjamingr
Copy link
Member Author

I just landed an implementation of this spec in Node.js as well (with the relevant WPTs) :]

@annevk
Copy link
Member

annevk commented Dec 3, 2020

@benjamingr want to put your name in the Acknowledgments section? I will go ahead and merge the tests as that is the only question blocking this as far as I'm concerned.

annevk pushed a commit to web-platform-tests/wpt that referenced this pull request Dec 3, 2020
@benjamingr
Copy link
Member Author

Sure

@annevk annevk merged commit 83037a1 into whatwg:master Dec 3, 2020
@annevk
Copy link
Member

annevk commented Dec 3, 2020

Congrats @benjamingr on getting this landed! Great work and really cool to see it might be adopted quickly by both browsers and Node.js.

moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Dec 5, 2020
…stonly

Automatic update from web-platform-tests
DOM: signal support for addEventListener()

Tests for whatwg/dom#919.
--

wpt-commits: 625e1310ce19e9dde25b01f9eda0452c6ec274da
wpt-pr: 26472
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Dec 7, 2020
…stonly

Automatic update from web-platform-tests
DOM: signal support for addEventListener()

Tests for whatwg/dom#919.
--

wpt-commits: 625e1310ce19e9dde25b01f9eda0452c6ec274da
wpt-pr: 26472
sidvishnoi pushed a commit to sidvishnoi/gecko-webmonetization that referenced this pull request Dec 10, 2020
…stonly

Automatic update from web-platform-tests
DOM: signal support for addEventListener()

Tests for whatwg/dom#919.
--

wpt-commits: 625e1310ce19e9dde25b01f9eda0452c6ec274da
wpt-pr: 26472
sidvishnoi pushed a commit to sidvishnoi/gecko-webmonetization that referenced this pull request Dec 10, 2020
…stonly

Automatic update from web-platform-tests
DOM: signal support for addEventListener()

Tests for whatwg/dom#919.
--

wpt-commits: 625e1310ce19e9dde25b01f9eda0452c6ec274da
wpt-pr: 26472
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this pull request Dec 14, 2020
…stonly

Automatic update from web-platform-tests
DOM: signal support for addEventListener()

Tests for whatwg/dom#919.
--

wpt-commits: 625e1310ce19e9dde25b01f9eda0452c6ec274da
wpt-pr: 26472

UltraBlame original commit: 56e1a8d30892478277b812e71b2af7467dae595f
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this pull request Dec 14, 2020
…stonly

Automatic update from web-platform-tests
DOM: signal support for addEventListener()

Tests for whatwg/dom#919.
--

wpt-commits: 625e1310ce19e9dde25b01f9eda0452c6ec274da
wpt-pr: 26472

UltraBlame original commit: fa142f3429f24749a5c3d236cf535973c19be0b1
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this pull request Dec 14, 2020
…stonly

Automatic update from web-platform-tests
DOM: signal support for addEventListener()

Tests for whatwg/dom#919.
--

wpt-commits: 625e1310ce19e9dde25b01f9eda0452c6ec274da
wpt-pr: 26472

UltraBlame original commit: 56e1a8d30892478277b812e71b2af7467dae595f
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this pull request Dec 14, 2020
…stonly

Automatic update from web-platform-tests
DOM: signal support for addEventListener()

Tests for whatwg/dom#919.
--

wpt-commits: 625e1310ce19e9dde25b01f9eda0452c6ec274da
wpt-pr: 26472

UltraBlame original commit: fa142f3429f24749a5c3d236cf535973c19be0b1
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this pull request Dec 14, 2020
…stonly

Automatic update from web-platform-tests
DOM: signal support for addEventListener()

Tests for whatwg/dom#919.
--

wpt-commits: 625e1310ce19e9dde25b01f9eda0452c6ec274da
wpt-pr: 26472

UltraBlame original commit: 56e1a8d30892478277b812e71b2af7467dae595f
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this pull request Dec 14, 2020
…stonly

Automatic update from web-platform-tests
DOM: signal support for addEventListener()

Tests for whatwg/dom#919.
--

wpt-commits: 625e1310ce19e9dde25b01f9eda0452c6ec274da
wpt-pr: 26472

UltraBlame original commit: fa142f3429f24749a5c3d236cf535973c19be0b1
webkit-commit-queue pushed a commit to WebKit/WebKit that referenced this pull request Jan 25, 2021
…ents

https://bugs.webkit.org/show_bug.cgi?id=218753
<rdar://problem/71258012>

Reviewed by Darin Adler.

LayoutTests/imported/w3c:
Import test coverage from WPT.

* web-platform-tests/dom/events/AddEventListenerOptions-signal.any-expected.txt: Added.
* web-platform-tests/dom/events/AddEventListenerOptions-signal.any.html: Added.
* web-platform-tests/dom/events/AddEventListenerOptions-signal.any.js: Added.
* web-platform-tests/dom/events/AddEventListenerOptions-signal.any.worker-expected.txt: Added.
* web-platform-tests/dom/events/AddEventListenerOptions-signal.any.worker.html: Added.
* web-platform-tests/dom/events/w3c-import.log:

Source/WebCore:
Support AbortSignal in addEventListenerOptions to unsubscribe from events:
- whatwg/dom#911
- whatwg/dom#919

Blink already added support for this.

Tests: imported/w3c/web-platform-tests/dom/events/AddEventListenerOptions-signal.any.html
       imported/w3c/web-platform-tests/dom/events/AddEventListenerOptions-signal.any.worker.html

* CMakeLists.txt:
* DerivedSources-input.xcfilelist:
* DerivedSources-output.xcfilelist:
* DerivedSources.make:
* Headers.cmake:
* Modules/async-clipboard/Clipboard.h:
* Modules/encryptedmedia/MediaKeySession.h:
* Modules/indexeddb/IDBRequest.h:
* Modules/mediastream/MediaDevices.h:
* Modules/mediastream/RTCPeerConnection.h:
* Modules/paymentrequest/PaymentRequest.h:
* Modules/speech/SpeechRecognition.h:
* Modules/webaudio/BaseAudioContext.h:
* Modules/webgpu/WebGPUDevice.h:
* Modules/webxr/WebXRSystem.h:
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* animation/WebAnimation.h:
* css/MediaQueryList.cpp:
(WebCore::MediaQueryList::addListener):
(WebCore::MediaQueryList::removeListener):
* css/MediaQueryList.h:
* dom/AbortSignal.h:
* dom/AddEventListenerOptions.h: Copied from Source/WebCore/loader/appcache/DOMApplicationCache.h.
(WebCore::AddEventListenerOptions::AddEventListenerOptions):
* dom/AddEventListenerOptions.idl: Copied from Source/WebCore/loader/appcache/DOMApplicationCache.h.
* dom/EventListener.h:
* dom/EventListenerMap.cpp:
* dom/EventListenerOptions.h: Copied from Source/WebCore/loader/appcache/DOMApplicationCache.h.
(WebCore::EventListenerOptions::EventListenerOptions):
* dom/EventListenerOptions.idl: Copied from Source/WebCore/loader/appcache/DOMApplicationCache.h.
* dom/EventTarget.cpp:
(WebCore::EventTarget::addEventListener):
(WebCore::EventTarget::removeEventListenerForBindings):
(WebCore::EventTarget::removeEventListener):
(WebCore::EventTarget::setAttributeEventListener):
(WebCore::EventTarget::innerInvokeEventListeners):
* dom/EventTarget.h:
(WebCore::EventTarget::removeEventListener):
* dom/EventTarget.idl:
* dom/MessagePort.cpp:
(WebCore::MessagePort::MessagePort):
(WebCore::MessagePort::removeEventListener):
* dom/MessagePort.h:
* dom/Node.cpp:
(WebCore::tryAddEventListener):
(WebCore::tryRemoveEventListener):
(WebCore::Node::removeEventListener):
* dom/Node.h:
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::removeEventListener):
* html/HTMLMediaElement.h:
* html/ImageDocument.cpp:
* html/track/TextTrackCue.h:
* inspector/agents/InspectorDOMAgent.cpp:
* loader/appcache/DOMApplicationCache.h:
* page/DOMWindow.cpp:
(WebCore::DOMWindow::removeEventListener):
* page/DOMWindow.h:
* platform/cocoa/PlaybackSessionModelMediaElement.mm:
* platform/cocoa/VideoFullscreenModelVideoElement.mm:
* svg/SVGElement.cpp:
(WebCore::SVGElement::removeEventListener):
* svg/SVGElement.h:
* svg/SVGTRefElement.cpp:
* svg/animation/SVGSMILElement.cpp:
* testing/Internals.cpp:
* workers/service/ServiceWorkerContainer.h:

Source/WebKit:
Minor build fixes.

* WebProcess/Plugins/PDF/PDFPluginAnnotation.mm:

Source/WebKitLegacy/mac:
Minor build fixes.

* DOM/DOMNode.mm:

Source/WTF:
Add initializeWeakPtrFactory() protection function to CanMakeWeakPtr so that a subclass
can eagerly initialize the WeakPtrFactory even if it does not subclass
WeakPtrFactory<T, WeakPtrFactoryInitialization::Eager>. MessagePort used to subclass
WeakPtrFactory<T, WeakPtrFactoryInitialization::Eager> for thread-safety reason but it
now subclasses WeakPtrFactory<T, WeakPtrFactoryInitialization::Lazy> via EventTarget.

* wtf/WeakPtr.h:
(WTF::CanMakeWeakPtr::initializeWeakPtrFactory):


Canonical link: https://commits.webkit.org/233312@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@271806 268f45cc-cd09-0410-ab3c-d52691b4dbfc
bertogg pushed a commit to Igalia/webkit that referenced this pull request Feb 1, 2021
…ents

https://bugs.webkit.org/show_bug.cgi?id=218753
<rdar://problem/71258012>

Reviewed by Darin Adler.

LayoutTests/imported/w3c:
Import test coverage from WPT.

* web-platform-tests/dom/events/AddEventListenerOptions-signal.any-expected.txt: Added.
* web-platform-tests/dom/events/AddEventListenerOptions-signal.any.html: Added.
* web-platform-tests/dom/events/AddEventListenerOptions-signal.any.js: Added.
* web-platform-tests/dom/events/AddEventListenerOptions-signal.any.worker-expected.txt: Added.
* web-platform-tests/dom/events/AddEventListenerOptions-signal.any.worker.html: Added.
* web-platform-tests/dom/events/w3c-import.log:

Source/WebCore:
Support AbortSignal in addEventListenerOptions to unsubscribe from events:
- whatwg/dom#911
- whatwg/dom#919

Blink already added support for this.

Tests: imported/w3c/web-platform-tests/dom/events/AddEventListenerOptions-signal.any.html
       imported/w3c/web-platform-tests/dom/events/AddEventListenerOptions-signal.any.worker.html

* CMakeLists.txt:
* DerivedSources-input.xcfilelist:
* DerivedSources-output.xcfilelist:
* DerivedSources.make:
* Headers.cmake:
* Modules/async-clipboard/Clipboard.h:
* Modules/encryptedmedia/MediaKeySession.h:
* Modules/indexeddb/IDBRequest.h:
* Modules/mediastream/MediaDevices.h:
* Modules/mediastream/RTCPeerConnection.h:
* Modules/paymentrequest/PaymentRequest.h:
* Modules/speech/SpeechRecognition.h:
* Modules/webaudio/BaseAudioContext.h:
* Modules/webgpu/WebGPUDevice.h:
* Modules/webxr/WebXRSystem.h:
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* animation/WebAnimation.h:
* css/MediaQueryList.cpp:
(WebCore::MediaQueryList::addListener):
(WebCore::MediaQueryList::removeListener):
* css/MediaQueryList.h:
* dom/AbortSignal.h:
* dom/AddEventListenerOptions.h: Copied from Source/WebCore/loader/appcache/DOMApplicationCache.h.
(WebCore::AddEventListenerOptions::AddEventListenerOptions):
* dom/AddEventListenerOptions.idl: Copied from Source/WebCore/loader/appcache/DOMApplicationCache.h.
* dom/EventListener.h:
* dom/EventListenerMap.cpp:
* dom/EventListenerOptions.h: Copied from Source/WebCore/loader/appcache/DOMApplicationCache.h.
(WebCore::EventListenerOptions::EventListenerOptions):
* dom/EventListenerOptions.idl: Copied from Source/WebCore/loader/appcache/DOMApplicationCache.h.
* dom/EventTarget.cpp:
(WebCore::EventTarget::addEventListener):
(WebCore::EventTarget::removeEventListenerForBindings):
(WebCore::EventTarget::removeEventListener):
(WebCore::EventTarget::setAttributeEventListener):
(WebCore::EventTarget::innerInvokeEventListeners):
* dom/EventTarget.h:
(WebCore::EventTarget::removeEventListener):
* dom/EventTarget.idl:
* dom/MessagePort.cpp:
(WebCore::MessagePort::MessagePort):
(WebCore::MessagePort::removeEventListener):
* dom/MessagePort.h:
* dom/Node.cpp:
(WebCore::tryAddEventListener):
(WebCore::tryRemoveEventListener):
(WebCore::Node::removeEventListener):
* dom/Node.h:
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::removeEventListener):
* html/HTMLMediaElement.h:
* html/ImageDocument.cpp:
* html/track/TextTrackCue.h:
* inspector/agents/InspectorDOMAgent.cpp:
* loader/appcache/DOMApplicationCache.h:
* page/DOMWindow.cpp:
(WebCore::DOMWindow::removeEventListener):
* page/DOMWindow.h:
* platform/cocoa/PlaybackSessionModelMediaElement.mm:
* platform/cocoa/VideoFullscreenModelVideoElement.mm:
* svg/SVGElement.cpp:
(WebCore::SVGElement::removeEventListener):
* svg/SVGElement.h:
* svg/SVGTRefElement.cpp:
* svg/animation/SVGSMILElement.cpp:
* testing/Internals.cpp:
* workers/service/ServiceWorkerContainer.h:

Source/WebKit:
Minor build fixes.

* WebProcess/Plugins/PDF/PDFPluginAnnotation.mm:

Source/WebKitLegacy/mac:
Minor build fixes.

* DOM/DOMNode.mm:

Source/WTF:
Add initializeWeakPtrFactory() protection function to CanMakeWeakPtr so that a subclass
can eagerly initialize the WeakPtrFactory even if it does not subclass
WeakPtrFactory<T, WeakPtrFactoryInitialization::Eager>. MessagePort used to subclass
WeakPtrFactory<T, WeakPtrFactoryInitialization::Eager> for thread-safety reason but it
now subclasses WeakPtrFactory<T, WeakPtrFactoryInitialization::Lazy> via EventTarget.

* wtf/WeakPtr.h:
(WTF::CanMakeWeakPtr::initializeWeakPtrFactory):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@271806 268f45cc-cd09-0410-ab3c-d52691b4dbfc
@sideshowbarker sideshowbarker added the impacts documentation Used by documentation communities, such as MDN, to track changes that impact documentation label Feb 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
impacts documentation Used by documentation communities, such as MDN, to track changes that impact documentation topic: aborting AbortController and AbortSignal
Development

Successfully merging this pull request may close these issues.

Support AbortSignals in addEventListeners options to unsubscribe from events?
4 participants