Skip to content

Commit

Permalink
Make the animationend event listener do not assume that it's always…
Browse files Browse the repository at this point in the history
… fired for `<dir

According to MDN, `animationend` event is never fired if the event target (`<dir>` in this case)
is removed.  If it's slow environment, `<dir>` element may be removed before the listener receives
the event for it.  Therefore, it should not assume that it always comes.

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

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1839265
gecko-commit: 8cc85121d9b7c49b9def06d8556709ce75354933
gecko-reviewers: m_kato
  • Loading branch information
masayuki-nakano authored and moz-wptsync-bot committed Jun 28, 2023
1 parent 81a8e52 commit 1b03e56
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions editing/crashtests/remove-editing-host-during-forwarddelete.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,22 @@
</style>
<script>
document.addEventListener("DOMContentLoaded", async () => {
const dir = document.querySelector("dir");
const waitForAnimationEnd = new Promise(resolve => {
let count = 0;
function onAnimationEnd() {
window.find("AAAAAAAAAA");
document.execCommand("forwardDelete");
if (++count == 2) {
count++;
function getRemainingEventCount() {
if (count >= 2) {
return 0;
}
// If `animationend` is delayed and `<dir>` has already been removed,
// `animationend` for it is never fired anymore.
return !dir.isConnected ? 0 : 1;
}
if (!getRemainingEventCount()) {
window.removeEventListener("animationend", onAnimationEnd);
resolve();
}
Expand All @@ -27,7 +37,6 @@
});
window.find("A");
document.execCommand("insertHTML", false, "AAAAAAAAAAAAAAAA");
const dir = document.querySelector("dir");
dir.addEventListener("DOMNodeRemoved", event => {
dir.remove();
});
Expand Down

0 comments on commit 1b03e56

Please sign in to comment.