Skip to content

Commit

Permalink
Support AbortSignal in addEventListenerOptions to unsubscribe from ev…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
[email protected] committed Jan 25, 2021
1 parent b408e42 commit ac3e4a9
Show file tree
Hide file tree
Showing 66 changed files with 567 additions and 84 deletions.
17 changes: 17 additions & 0 deletions LayoutTests/imported/w3c/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
2021-01-25 Chris Dumez <[email protected]>

Support AbortSignal in addEventListenerOptions to unsubscribe from events
https://bugs.webkit.org/show_bug.cgi?id=218753
<rdar://problem/71258012>

Reviewed by Darin Adler.

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:

2021-01-25 Sam Weinig <[email protected]>

Import css/css-color tests from WPT
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

PASS Passing an AbortSignal to addEventListener options should allow removing a listener
PASS Passing an AbortSignal to addEventListener does not prevent removeEventListener
PASS Passing an AbortSignal to addEventListener works with the once flag
PASS Removing a once listener works with a passed signal
PASS Passing an AbortSignal to multiple listeners
PASS Passing an AbortSignal to addEventListener works with the capture flag
PASS Aborting from a listener does not call future listeners
PASS Adding then aborting a listener in another listener does not call it
PASS Aborting from a nested listener should remove it

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- This file is required for WebKit test infrastructure to run the templated test -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
'use strict';

test(function() {
let count = 0;
function handler() {
count++;
}
const et = new EventTarget();
const controller = new AbortController();
et.addEventListener('test', handler, { signal: controller.signal });
et.dispatchEvent(new Event('test'));
assert_equals(count, 1, "Adding a signal still adds a listener");
et.dispatchEvent(new Event('test'));
assert_equals(count, 2, "The listener was not added with the once flag");
controller.abort();
et.dispatchEvent(new Event('test'));
assert_equals(count, 2, "Aborting on the controller removes the listener");
et.addEventListener('test', handler, { signal: controller.signal });
et.dispatchEvent(new Event('test'));
assert_equals(count, 2, "Passing an aborted signal never adds the handler");
}, "Passing an AbortSignal to addEventListener options should allow removing a listener");

test(function() {
let count = 0;
function handler() {
count++;
}
const et = new EventTarget();
const controller = new AbortController();
et.addEventListener('test', handler, { signal: controller.signal });
et.removeEventListener('test', handler);
et.dispatchEvent(new Event('test'));
assert_equals(count, 0, "The listener was still removed");
}, "Passing an AbortSignal to addEventListener does not prevent removeEventListener");

test(function() {
let count = 0;
function handler() {
count++;
}
const et = new EventTarget();
const controller = new AbortController();
et.addEventListener('test', handler, { signal: controller.signal, once: true });
controller.abort();
et.dispatchEvent(new Event('test'));
assert_equals(count, 0, "The listener was still removed");
}, "Passing an AbortSignal to addEventListener works with the once flag");

test(function() {
let count = 0;
function handler() {
count++;
}
const et = new EventTarget();
const controller = new AbortController();
et.addEventListener('test', handler, { signal: controller.signal, once: true });
et.removeEventListener('test', handler);
et.dispatchEvent(new Event('test'));
assert_equals(count, 0, "The listener was still removed");
}, "Removing a once listener works with a passed signal");

test(function() {
let count = 0;
function handler() {
count++;
}
const et = new EventTarget();
const controller = new AbortController();
et.addEventListener('first', handler, { signal: controller.signal, once: true });
et.addEventListener('second', handler, { signal: controller.signal, once: true });
controller.abort();
et.dispatchEvent(new Event('first'));
et.dispatchEvent(new Event('second'));
assert_equals(count, 0, "The listener was still removed");
}, "Passing an AbortSignal to multiple listeners");

test(function() {
let count = 0;
function handler() {
count++;
}
const et = new EventTarget();
const controller = new AbortController();
et.addEventListener('test', handler, { signal: controller.signal, capture: true });
controller.abort();
et.dispatchEvent(new Event('test'));
assert_equals(count, 0, "The listener was still removed");
}, "Passing an AbortSignal to addEventListener works with the capture flag");

test(function() {
let count = 0;
function handler() {
count++;
}
const et = new EventTarget();
const controller = new AbortController();
et.addEventListener('test', () => {
controller.abort();
}, { signal: controller.signal });
et.addEventListener('test', handler, { signal: controller.signal });
et.dispatchEvent(new Event('test'));
assert_equals(count, 0, "The listener was still removed");
}, "Aborting from a listener does not call future listeners");

test(function() {
let count = 0;
function handler() {
count++;
}
const et = new EventTarget();
const controller = new AbortController();
et.addEventListener('test', () => {
et.addEventListener('test', handler, { signal: controller.signal });
controller.abort();
}, { signal: controller.signal });
et.dispatchEvent(new Event('test'));
assert_equals(count, 0, "The listener was still removed");
}, "Adding then aborting a listener in another listener does not call it");

test(function() {
const et = new EventTarget();
const ac = new AbortController();
let count = 0;
et.addEventListener('foo', () => {
et.addEventListener('foo', () => {
count++;
if (count > 5) ac.abort();
et.dispatchEvent(new Event('foo'));
}, { signal: ac.signal });
et.dispatchEvent(new Event('foo'));
}, { once: true });
et.dispatchEvent(new Event('foo'));
}, "Aborting from a nested listener should remove it");
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

PASS Passing an AbortSignal to addEventListener options should allow removing a listener
PASS Passing an AbortSignal to addEventListener does not prevent removeEventListener
PASS Passing an AbortSignal to addEventListener works with the once flag
PASS Removing a once listener works with a passed signal
PASS Passing an AbortSignal to multiple listeners
PASS Passing an AbortSignal to addEventListener works with the capture flag
PASS Aborting from a listener does not call future listeners
PASS Adding then aborting a listener in another listener does not call it
PASS Aborting from a nested listener should remove it

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- This file is required for WebKit test infrastructure to run the templated test -->
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ None
List of files:
/LayoutTests/imported/w3c/web-platform-tests/dom/events/AddEventListenerOptions-once.html
/LayoutTests/imported/w3c/web-platform-tests/dom/events/AddEventListenerOptions-passive.html
/LayoutTests/imported/w3c/web-platform-tests/dom/events/AddEventListenerOptions-signal.any.js
/LayoutTests/imported/w3c/web-platform-tests/dom/events/CustomEvent.html
/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-cancelBubble.html
/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-constants.html
Expand Down
17 changes: 17 additions & 0 deletions Source/WTF/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
2021-01-25 Chris Dumez <[email protected]>

Support AbortSignal in addEventListenerOptions to unsubscribe from events
https://bugs.webkit.org/show_bug.cgi?id=218753
<rdar://problem/71258012>

Reviewed by Darin Adler.

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):

2021-01-25 Per Arne Vollan <[email protected]>

[macOS] Fix OS version check for ENABLE_SET_WEBCONTENT_PROCESS_INFORMATION_IN_NETWORK_PROCESS
Expand Down
7 changes: 6 additions & 1 deletion Source/WTF/wtf/WeakPtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,12 @@ template<typename T, WeakPtrFactoryInitialization initializationMode = WeakPtrFa
CanMakeWeakPtr()
{
if (initializationMode == WeakPtrFactoryInitialization::Eager)
m_weakPtrFactory.initializeIfNeeded(static_cast<T&>(*this));
initializeWeakPtrFactory();
}

void initializeWeakPtrFactory()
{
m_weakPtrFactory.initializeIfNeeded(static_cast<T&>(*this));
}

private:
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,7 @@ set(WebCore_NON_SVG_IDL_FILES
dom/AbortController.idl
dom/AbortSignal.idl
dom/AbstractRange.idl
dom/AddEventListenerOptions.idl
dom/AnimationEvent.idl
dom/Attr.idl
dom/BeforeLoadEvent.idl
Expand Down Expand Up @@ -843,6 +844,7 @@ set(WebCore_NON_SVG_IDL_FILES
dom/ErrorEvent.idl
dom/Event.idl
dom/EventInit.idl
dom/EventListenerOptions.idl
dom/EventModifierInit.idl
dom/EventTarget.idl
dom/FocusEvent.idl
Expand Down
86 changes: 86 additions & 0 deletions Source/WebCore/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,89 @@
2021-01-25 Chris Dumez <[email protected]>

Support AbortSignal in addEventListenerOptions to unsubscribe from events
https://bugs.webkit.org/show_bug.cgi?id=218753
<rdar://problem/71258012>

Reviewed by Darin Adler.

Support AbortSignal in addEventListenerOptions to unsubscribe from events:
- https://github.com/whatwg/dom/issues/911
- https://github.com/whatwg/dom/pull/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:

2021-01-25 John Wilander <[email protected]>

PCM: Use different well-known locations for triggering and reporting attribution
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/DerivedSources-input.xcfilelist
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ $(PROJECT_DIR)/dom/AbortAlgorithm.idl
$(PROJECT_DIR)/dom/AbortController.idl
$(PROJECT_DIR)/dom/AbortSignal.idl
$(PROJECT_DIR)/dom/AbstractRange.idl
$(PROJECT_DIR)/dom/AddEventListenerOptions.idl
$(PROJECT_DIR)/dom/AnimationEvent.idl
$(PROJECT_DIR)/dom/Attr.idl
$(PROJECT_DIR)/dom/BeforeLoadEvent.idl
Expand Down Expand Up @@ -760,6 +761,7 @@ $(PROJECT_DIR)/dom/ErrorEvent.idl
$(PROJECT_DIR)/dom/Event.idl
$(PROJECT_DIR)/dom/EventInit.idl
$(PROJECT_DIR)/dom/EventListener.idl
$(PROJECT_DIR)/dom/EventListenerOptions.idl
$(PROJECT_DIR)/dom/EventModifierInit.idl
$(PROJECT_DIR)/dom/EventNames.in
$(PROJECT_DIR)/dom/EventTarget.idl
Expand Down
4 changes: 4 additions & 0 deletions Source/WebCore/DerivedSources-output.xcfilelist
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSAbstractWorker.cpp
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSAbstractWorker.h
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSAccessibilityRole.cpp
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSAccessibilityRole.h
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSAddEventListenerOptions.cpp
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSAddEventListenerOptions.h
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSAddressErrors.cpp
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSAddressErrors.h
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSAesCbcCfbParams.cpp
Expand Down Expand Up @@ -743,6 +745,8 @@ $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSEvent.cpp
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSEvent.h
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSEventInit.cpp
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSEventInit.h
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSEventListenerOptions.cpp
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSEventListenerOptions.h
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSEventModifierInit.cpp
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSEventModifierInit.h
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSEventSource.cpp
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/DerivedSources.make
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ JS_BINDING_IDLS := \
$(WebCore)/dom/AbortController.idl \
$(WebCore)/dom/AbortSignal.idl \
$(WebCore)/dom/AbstractRange.idl \
$(WebCore)/dom/AddEventListenerOptions.idl \
$(WebCore)/dom/AnimationEvent.idl \
$(WebCore)/dom/Attr.idl \
$(WebCore)/dom/BeforeLoadEvent.idl \
Expand Down Expand Up @@ -717,6 +718,7 @@ JS_BINDING_IDLS := \
$(WebCore)/dom/Event.idl \
$(WebCore)/dom/EventInit.idl \
$(WebCore)/dom/EventListener.idl \
$(WebCore)/dom/EventListenerOptions.idl \
$(WebCore)/dom/EventModifierInit.idl \
$(WebCore)/dom/EventTarget.idl \
$(WebCore)/dom/FocusEvent.idl \
Expand Down
Loading

0 comments on commit ac3e4a9

Please sign in to comment.