Bug 218638

Summary: Event targets should be cleared after dispatch if target pointed to a shadow tree
Product: WebKit Reporter: Chris Dumez <cdumez>
Component: DOMAssignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: annevk, darin, esprehn+autocc, ews-watchlist, ggaren, kangil.han, ravi.jayaramappa, rniwa, sam, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 148695    
Attachments:
Description Flags
Patch
none
Patch
ews-feeder: commit-queue-
Patch
none
Patch
none
Patch
ews-feeder: commit-queue-
Patch
none
Patch none

Chris Dumez
Reported 2020-11-05 16:32:16 PST
Event target should be cleared after dispatch if target pointed to a shadow tree: - https://dom.spec.whatwg.org/#concept-event-dispatch (Steps 5.10, 5.11 and 10)
Attachments
Patch (16.34 KB, patch)
2020-11-05 16:33 PST, Chris Dumez
no flags
Patch (8.02 KB, patch)
2020-11-05 16:48 PST, Chris Dumez
ews-feeder: commit-queue-
Patch (8.29 KB, patch)
2020-11-05 16:53 PST, Chris Dumez
no flags
Patch (8.28 KB, patch)
2020-11-05 16:54 PST, Chris Dumez
no flags
Patch (12.95 KB, patch)
2020-11-06 07:44 PST, Chris Dumez
ews-feeder: commit-queue-
Patch (17.75 KB, patch)
2020-11-06 11:33 PST, Chris Dumez
no flags
Patch (20.48 KB, patch)
2020-11-06 12:28 PST, Chris Dumez
no flags
Chris Dumez
Comment 1 2020-11-05 16:33:37 PST
Chris Dumez
Comment 2 2020-11-05 16:48:15 PST
Chris Dumez
Comment 3 2020-11-05 16:53:42 PST
Chris Dumez
Comment 4 2020-11-05 16:54:43 PST
Chris Dumez
Comment 5 2020-11-06 07:44:35 PST
Darin Adler
Comment 6 2020-11-06 09:01:52 PST
Comment on attachment 413429 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=413429&action=review > Source/WebCore/dom/EventDispatcher.cpp:91 > + shouldClearTargetsAfterDispatch = isInShadowTree(eventContext.target()) || isInShadowTree(eventContext.relatedTarget()); Is it important to do this shadow tree check before dispatching?
Chris Dumez
Comment 7 2020-11-06 09:10:56 PST
Comment on attachment 413429 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=413429&action=review >> Source/WebCore/dom/EventDispatcher.cpp:91 >> + shouldClearTargetsAfterDispatch = isInShadowTree(eventContext.target()) || isInShadowTree(eventContext.relatedTarget()); > > Is it important to do this shadow tree check before dispatching? Yes, I believe it is to match the specification, especially because the event handlers could remove the node from the shadow tree.
Darin Adler
Comment 8 2020-11-06 09:19:08 PST
Comment on attachment 413429 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=413429&action=review >>> Source/WebCore/dom/EventDispatcher.cpp:91 >>> + shouldClearTargetsAfterDispatch = isInShadowTree(eventContext.target()) || isInShadowTree(eventContext.relatedTarget()); >> >> Is it important to do this shadow tree check before dispatching? > > Yes, I believe it is to match the specification, especially because the event handlers could remove the node from the shadow tree. OK. Do we have test cases for the converse where event handles move a node into a shadow tree to check that it does not get cleared in that case?
Chris Dumez
Comment 9 2020-11-06 09:21:35 PST
(In reply to Darin Adler from comment #8) > Comment on attachment 413429 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=413429&action=review > > >>> Source/WebCore/dom/EventDispatcher.cpp:91 > >>> + shouldClearTargetsAfterDispatch = isInShadowTree(eventContext.target()) || isInShadowTree(eventContext.relatedTarget()); > >> > >> Is it important to do this shadow tree check before dispatching? > > > > Yes, I believe it is to match the specification, especially because the event handlers could remove the node from the shadow tree. > > OK. Do we have test cases for the converse where event handles move a node > into a shadow tree to check that it does not get cleared in that case? I will check. If not, I will add one.
Chris Dumez
Comment 10 2020-11-06 11:33:06 PST
Chris Dumez
Comment 11 2020-11-06 11:33:41 PST
(In reply to Chris Dumez from comment #9) > (In reply to Darin Adler from comment #8) > > Comment on attachment 413429 [details] > > Patch > > > > View in context: > > https://bugs.webkit.org/attachment.cgi?id=413429&action=review > > > > >>> Source/WebCore/dom/EventDispatcher.cpp:91 > > >>> + shouldClearTargetsAfterDispatch = isInShadowTree(eventContext.target()) || isInShadowTree(eventContext.relatedTarget()); > > >> > > >> Is it important to do this shadow tree check before dispatching? > > > > > > Yes, I believe it is to match the specification, especially because the event handlers could remove the node from the shadow tree. > > > > OK. Do we have test cases for the converse where event handles move a node > > into a shadow tree to check that it does not get cleared in that case? > > I will check. If not, I will add one. As promised, I have added test coverage for this particular case. I have also verified that our behavior is consistent with Blink and Gecko here.
Darin Adler
Comment 12 2020-11-06 12:06:11 PST
(In reply to Chris Dumez from comment #11) > As promised, I have added test coverage for this particular case. I have > also verified that our behavior is consistent with Blink and Gecko here. Which test covers nodes that are moved *into* a shadow tree by an event handler?
Chris Dumez
Comment 13 2020-11-06 12:08:03 PST
(In reply to Darin Adler from comment #12) > (In reply to Chris Dumez from comment #11) > > As promised, I have added test coverage for this particular case. I have > > also verified that our behavior is consistent with Blink and Gecko here. > > Which test covers nodes that are moved *into* a shadow tree by an event > handler? Oh, I indeed this not cover this case. I will add one more test then.
Chris Dumez
Comment 14 2020-11-06 12:26:21 PST
(In reply to Chris Dumez from comment #13) > (In reply to Darin Adler from comment #12) > > (In reply to Chris Dumez from comment #11) > > > As promised, I have added test coverage for this particular case. I have > > > also verified that our behavior is consistent with Blink and Gecko here. > > > > Which test covers nodes that are moved *into* a shadow tree by an event > > handler? > > Oh, I indeed this not cover this case. I will add one more test then. I added this test. One thing to note that is this new test passes in Safari and Firefox but fails in Chrome. Chrome DOES clear the event targets if the node is initially outside the shadow tree but gets moved to a shadow tree by an event listener. I am not inclined to match Chrome though since we have the specification and Firefox on our side.
Chris Dumez
Comment 15 2020-11-06 12:28:13 PST
Darin Adler
Comment 16 2020-11-06 13:56:27 PST
I presume consistency is our goal so that we get interoperability. If so, then we should make sure WPT tests cover this so Chrome knows they have it wrong. Outside of consistency, I’m not clear on how important these semantics are, and what motivated either rule. Seems arbitrary that we clear these pointers based on them being in shadow tree in *some* cases but not in others: does not create an invariant.
Chris Dumez
Comment 17 2020-11-06 15:15:21 PST
(In reply to Darin Adler from comment #16) > I presume consistency is our goal so that we get interoperability. If so, > then we should make sure WPT tests cover this so Chrome knows they have it > wrong. > > Outside of consistency, I’m not clear on how important these semantics are, > and what motivated either rule. Seems arbitrary that we clear these pointers > based on them being in shadow tree in *some* cases but not in others: does > not create an invariant. I agree, here is the WPT PR: https://github.com/web-platform-tests/wpt/pull/26440
EWS
Comment 18 2020-11-06 15:29:06 PST
Committed r269546: <https://trac.webkit.org/changeset/269546> All reviewed patches have been landed. Closing bug and clearing flags on attachment 413466 [details].
Radar WebKit Bug Importer
Comment 19 2020-11-06 15:30:45 PST
Chris Dumez
Comment 21 2020-11-09 08:48:44 PST
*** Bug 206374 has been marked as a duplicate of this bug. ***
Chris Dumez
Comment 22 2020-11-09 08:50:34 PST
*** Bug 184079 has been marked as a duplicate of this bug. ***
Note You need to log in before you can comment on or make changes to this bug.