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

Test addEventListener abort signal #26472

Merged

Conversation

benjamingr
Copy link
Contributor

@benjamingr benjamingr commented Nov 10, 2020

Tests for whatwg/dom#919

@benjamingr
Copy link
Contributor Author

I think the WPTs are ready for review :]

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 writing these, looks like a good start!

If you want to test interaction with once/capture it seems you should also check the event listener is still correctly invoked for them.

We should also test passing the signal to multiple listeners, both with different event names and the same event name. And there also check what happens if you abort from one of the listeners (which listeners will still get invoked and which will not).

You might also want to consider https://web-platform-tests.org/writing-tests/testharness.html#tests-for-other-or-multiple-globals-any-js to reduce the boilerplate and make these tests even more reusable across JavaScript hosts.

const et = new EventTarget();
const controller = new AbortController();
et.addEventListener('test', handler, { signal: controller.signal, once: true });
controller.abort();
Copy link
Member

Choose a reason for hiding this comment

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

Why would this not remove it already? I'm not sure how this test works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This would remove it already, this test checks that even if I add an event listener with once, passing a signal and aborting the controller removes it :]

Copy link
Member

Choose a reason for hiding this comment

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

I see, that makes sense. We should also test the inverse, that once still removes it if you pass a signal in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add tests for that and cases you mentioned as well.

Copy link
Member

Choose a reason for hiding this comment

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

It seems there's still no test that tests once itself. I.e., dispatch an event twice and only bring count up to 1?

@benjamingr benjamingr changed the title initial addEventListener signal tests Test addEventListener abort signal Nov 16, 2020
@benjamingr
Copy link
Contributor Author

Done, thanks for the review please take a look :]

@annevk
Copy link
Member

annevk commented Nov 16, 2020

I think there should be more coverage for the multiple listener scenarios. E.g., multiple listeners for the same name and signal, but different handlers. And then one of the handlers aborts. The remaining handlers should not run (due to the removed field of their event listener being set).

@benjamingr
Copy link
Contributor Author

@annevk

, multiple listeners for the same name and signal, but different handlers. And then one of the handlers aborts.

Is that not this test?

@smaug----
Copy link
Contributor

I'd like to see tests where one listener adds another listener with signal and then aborts it.
And similar but with nested event dispatch.

@benjamingr
Copy link
Contributor Author

@smaug---- thanks! I've added a test for your first suggestion (and rebased) . I'm not sure what you mean by "similar but with nested event dispatch".

@benjamingr
Copy link
Contributor Author

Just updating that I've added the "nested event dispatch" test after talking about it with @smaug---- and Anne on #whatwg

@annevk
Copy link
Member

annevk commented Nov 30, 2020

Should we remove the test added in #26462 as part of this or incorporate it? If we keep it as-is we should remove .tentative from the filename.

@benjamingr
Copy link
Contributor Author

@annevk likely remove since it's tested in https://github.com/web-platform-tests/wpt/pull/26472/files#diff-96216b6e1d920cc33c8560820458aeb2f57e707edcc1c290bf642163398aabd4R15-R17 but there might be merit in a simpler tests that test a more basic use case?

@annevk
Copy link
Member

annevk commented Dec 1, 2020

Not that I know of; let's remove it as part of this PR.

cc @josepharhar

@benjamingr
Copy link
Contributor Author

Done

@annevk annevk merged commit 625e131 into web-platform-tests:master Dec 3, 2020
annevk pushed a commit to whatwg/dom that referenced this pull request Dec 3, 2020
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Dec 15, 2020
This passes the tests which are in web-platform-tests/wpt#26472

Because of complications in #include handling, AbortFollower needs to be in a different
header file than AbortSignal, yet AbortSignalImpl needs to be available when AbortFollower is used.
Another option would have been to make DOMEventTargetHelper.h a bit different and uninline some hot methods
there or move them to another file, but that would have been equally bad and Abort* is used way less often.
AbortFollower and AbortSignalImpl are thus just moved to a new header.

Memory management is such that Listener in EventListenerManager owns the possible ListenerSignalFollower
instance which follows the relevant signal. In order to be able remove event listener,
ListenerSignalFollower has many similar fields as Listener.
ListenerSignalFollower can't easily have just a pointer to Listener* since Listener isn't stored as a pointer
in EventListenerManager.
ListenerSignalFollower is cycle collectable so that Listener->ListenerSignalFollower can be traversed/unlinked
and also strong pointers in ListenerSignalFollower itself can be traversed/unlinked.

There is an XXX in the .webidl, since nullability of signal is unclear in the spec pr.
Whether or not it ends up being nullable shouldn't change the actual C++ implementation.

Differential Revision: https://phabricator.services.mozilla.com/D97938
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this pull request Dec 18, 2020
This passes the tests which are in web-platform-tests/wpt#26472

Because of complications in #include handling, AbortFollower needs to be in a different
header file than AbortSignal, yet AbortSignalImpl needs to be available when AbortFollower is used.
Another option would have been to make DOMEventTargetHelper.h a bit different and uninline some hot methods
there or move them to another file, but that would have been equally bad and Abort* is used way less often.
AbortFollower and AbortSignalImpl are thus just moved to a new header.

Memory management is such that Listener in EventListenerManager owns the possible ListenerSignalFollower
instance which follows the relevant signal. In order to be able remove event listener,
ListenerSignalFollower has many similar fields as Listener.
ListenerSignalFollower can't easily have just a pointer to Listener* since Listener isn't stored as a pointer
in EventListenerManager.
ListenerSignalFollower is cycle collectable so that Listener->ListenerSignalFollower can be traversed/unlinked
and also strong pointers in ListenerSignalFollower itself can be traversed/unlinked.

There is an XXX in the .webidl, since nullability of signal is unclear in the spec pr.
Whether or not it ends up being nullable shouldn't change the actual C++ implementation.

Differential Revision: https://phabricator.services.mozilla.com/D97938

UltraBlame original commit: b3d0fba5fd8d624b5abf53df196aedae5e83a269
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this pull request Dec 18, 2020
This passes the tests which are in web-platform-tests/wpt#26472

Because of complications in #include handling, AbortFollower needs to be in a different
header file than AbortSignal, yet AbortSignalImpl needs to be available when AbortFollower is used.
Another option would have been to make DOMEventTargetHelper.h a bit different and uninline some hot methods
there or move them to another file, but that would have been equally bad and Abort* is used way less often.
AbortFollower and AbortSignalImpl are thus just moved to a new header.

Memory management is such that Listener in EventListenerManager owns the possible ListenerSignalFollower
instance which follows the relevant signal. In order to be able remove event listener,
ListenerSignalFollower has many similar fields as Listener.
ListenerSignalFollower can't easily have just a pointer to Listener* since Listener isn't stored as a pointer
in EventListenerManager.
ListenerSignalFollower is cycle collectable so that Listener->ListenerSignalFollower can be traversed/unlinked
and also strong pointers in ListenerSignalFollower itself can be traversed/unlinked.

There is an XXX in the .webidl, since nullability of signal is unclear in the spec pr.
Whether or not it ends up being nullable shouldn't change the actual C++ implementation.

Differential Revision: https://phabricator.services.mozilla.com/D97938

UltraBlame original commit: b3d0fba5fd8d624b5abf53df196aedae5e83a269
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this pull request Dec 18, 2020
This passes the tests which are in web-platform-tests/wpt#26472

Because of complications in #include handling, AbortFollower needs to be in a different
header file than AbortSignal, yet AbortSignalImpl needs to be available when AbortFollower is used.
Another option would have been to make DOMEventTargetHelper.h a bit different and uninline some hot methods
there or move them to another file, but that would have been equally bad and Abort* is used way less often.
AbortFollower and AbortSignalImpl are thus just moved to a new header.

Memory management is such that Listener in EventListenerManager owns the possible ListenerSignalFollower
instance which follows the relevant signal. In order to be able remove event listener,
ListenerSignalFollower has many similar fields as Listener.
ListenerSignalFollower can't easily have just a pointer to Listener* since Listener isn't stored as a pointer
in EventListenerManager.
ListenerSignalFollower is cycle collectable so that Listener->ListenerSignalFollower can be traversed/unlinked
and also strong pointers in ListenerSignalFollower itself can be traversed/unlinked.

There is an XXX in the .webidl, since nullability of signal is unclear in the spec pr.
Whether or not it ends up being nullable shouldn't change the actual C++ implementation.

Differential Revision: https://phabricator.services.mozilla.com/D97938

UltraBlame original commit: b3d0fba5fd8d624b5abf53df196aedae5e83a269
aosmond pushed a commit to aosmond/gecko that referenced this pull request Nov 27, 2021
This passes the tests which are in web-platform-tests/wpt#26472

Because of complications in #include handling, AbortFollower needs to be in a different
header file than AbortSignal, yet AbortSignalImpl needs to be available when AbortFollower is used.
Another option would have been to make DOMEventTargetHelper.h a bit different and uninline some hot methods
there or move them to another file, but that would have been equally bad and Abort* is used way less often.
AbortFollower and AbortSignalImpl are thus just moved to a new header.

Memory management is such that Listener in EventListenerManager owns the possible ListenerSignalFollower
instance which follows the relevant signal. In order to be able remove event listener,
ListenerSignalFollower has many similar fields as Listener.
ListenerSignalFollower can't easily have just a pointer to Listener* since Listener isn't stored as a pointer
in EventListenerManager.
ListenerSignalFollower is cycle collectable so that Listener->ListenerSignalFollower can be traversed/unlinked
and also strong pointers in ListenerSignalFollower itself can be traversed/unlinked.

There is an XXX in the .webidl, since nullability of signal is unclear in the spec pr.
Whether or not it ends up being nullable shouldn't change the actual C++ implementation.

Differential Revision: https://phabricator.services.mozilla.com/D97938
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants