Bug 218638 - Event targets should be cleared after dispatch if target pointed to a shadow tree
Summary: Event targets should be cleared after dispatch if target pointed to a shadow ...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar
: 184079 206374 (view as bug list)
Depends on:
Blocks: 148695
  Show dependency treegraph
 
Reported: 2020-11-05 16:32 PST by Chris Dumez
Modified: 2020-11-09 08:50 PST (History)
10 users (show)

See Also:


Attachments
Patch (16.34 KB, patch)
2020-11-05 16:33 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (8.02 KB, patch)
2020-11-05 16:48 PST, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (8.29 KB, patch)
2020-11-05 16:53 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (8.28 KB, patch)
2020-11-05 16:54 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (12.95 KB, patch)
2020-11-06 07:44 PST, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (17.75 KB, patch)
2020-11-06 11:33 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (20.48 KB, patch)
2020-11-06 12:28 PST, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 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)
Comment 1 Chris Dumez 2020-11-05 16:33:37 PST
Created attachment 413368 [details]
Patch
Comment 2 Chris Dumez 2020-11-05 16:48:15 PST
Created attachment 413372 [details]
Patch
Comment 3 Chris Dumez 2020-11-05 16:53:42 PST
Created attachment 413373 [details]
Patch
Comment 4 Chris Dumez 2020-11-05 16:54:43 PST
Created attachment 413374 [details]
Patch
Comment 5 Chris Dumez 2020-11-06 07:44:35 PST
Created attachment 413429 [details]
Patch
Comment 6 Darin Adler 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?
Comment 7 Chris Dumez 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.
Comment 8 Darin Adler 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?
Comment 9 Chris Dumez 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.
Comment 10 Chris Dumez 2020-11-06 11:33:06 PST
Created attachment 413452 [details]
Patch
Comment 11 Chris Dumez 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.
Comment 12 Darin Adler 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?
Comment 13 Chris Dumez 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.
Comment 14 Chris Dumez 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.
Comment 15 Chris Dumez 2020-11-06 12:28:13 PST
Created attachment 413466 [details]
Patch
Comment 16 Darin Adler 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.
Comment 17 Chris Dumez 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
Comment 18 EWS 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].
Comment 19 Radar WebKit Bug Importer 2020-11-06 15:30:45 PST
<rdar://problem/71135539>
Comment 21 Chris Dumez 2020-11-09 08:48:44 PST
*** Bug 206374 has been marked as a duplicate of this bug. ***
Comment 22 Chris Dumez 2020-11-09 08:50:34 PST
*** Bug 184079 has been marked as a duplicate of this bug. ***