Skip to content

Commit 23ec642

Browse files
authored
Fix composedPath() once more
The existing algorithm exposed nodes in shadow trees that should remain hidden. (This wasn't noticed in #535.) This roughly matches the approach taken by jsdom to solve this issue and unlike #696 requires no downstream changes. Tests: shadow-dom/event-composed-path.html in wpt. Fixes #684. Closes #696.
1 parent 15e2f41 commit 23ec642

File tree

1 file changed

+80
-17
lines changed

1 file changed

+80
-17
lines changed

dom.bs

Lines changed: 80 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -587,38 +587,101 @@ was initialized to. When an <a>event</a> is created the attribute must be initia
587587
steps:
588588

589589
<ol>
590-
<li><p>Let <var>reversedComposedPath</var> be an empty <a for=/>list</a>.
590+
<li><p>Let <var>composedPath</var> be an empty <a for=/>list</a>.
591591

592-
<li><p>Let <var>hiddenSubtreeLevel</var> be 0.
592+
<li><p>Let <var>path</var> be the <a>context object</a>'s <a for=Event>path</a>.
593593

594-
<li><p>Let <var>hasSeenCurrentTarget</var> be false.
594+
<li><p>If <var>path</var> <a for=list>is empty</a>, then return <var>composedPath</var>.
595595

596596
<li><p>Let <var>currentTarget</var> be the <a>context object</a>'s {{Event/currentTarget}}
597597
attribute value.
598598

599-
<li><p>Let <var>reversedPath</var> be the <a>context object</a>'s <a for=Event>path</a>, in reverse
600-
order.
599+
<li><p><a for=list>Append</a> <var>currentTarget</var> to <var>composedPath</var>.
600+
601+
<li><p>Let <var>currentTargetIndex</var> be 0.
602+
603+
<li><p>Let <var>currentTargetHiddenSubtreeLevel</var> be 0.
604+
605+
<li><p>Let <var>index</var> be <var>path</var>'s <a for=list>size</a> &minus; 1.
606+
607+
<li>
608+
<p>While <var>index</var> is greater than or equal to 0:
609+
610+
<ol>
611+
<li><p>If <var>path</var>[<var>index</var>]'s <a for=Event/path>root-of-closed-tree</a> is true,
612+
then increase <var>currentTargetHiddenSubtreeLevel</var> by 1.
613+
614+
<li><p>If <var>path</var>[<var>index</var>]'s <a for=Event/path>item</a> is
615+
<var>currentTarget</var>, then set <var>currentTargetIndex</var> to <var>index</var> and
616+
<a for=iteration>break</a>.
617+
618+
<li><p>If <var>path</var>[<var>index</var>]'s <a for=Event/path>slot-in-closed-tree</a> is true,
619+
then decrease <var>currentTargetHiddenSubtreeLevel</var> by 1.
620+
621+
<li><p>Decrease <var>index</var> by 1.
622+
</ol>
623+
624+
<li><p>Let <var>currentHiddenLevel</var> and <var>maxHiddenLevel</var> be
625+
<var>currentTargetHiddenSubtreeLevel</var>.
626+
627+
<li><p>Set <var>index</var> to <var>currentTargetIndex</var> &minus; 1.
628+
629+
<li>
630+
<p>While <var>index</var> is greater than or equal to 0:
631+
632+
<ol>
633+
<li><p>If <var>path</var>[<var>index</var>]'s <a for=Event/path>root-of-closed-tree</a> is true,
634+
then increase <var>currentHiddenLevel</var> by 1.
635+
636+
<li><p>If <var>currentHiddenLevel</var> is less than <var>maxHiddenLevel</var>, then
637+
<a for=list>prepend</a> <var>path</var>[<var>index</var>]'s <a for=Event/path>item</a> to
638+
<var>composedPath</var>.
639+
640+
<li>
641+
<p>If <var>path</var>[<var>index</var>]'s <a for=Event/path>slot-in-closed-tree</a> is true,
642+
then:
643+
644+
<ol>
645+
<li><p>Decrease <var>currentHiddenLevel</var> by 1.
646+
647+
<li><p>If <var>currentHiddenLevel</var> is less than <var>maxHiddenLevel</var>, then set
648+
<var>maxHiddenLevel</var> to <var>currentHiddenLevel</var>.
649+
</ol>
650+
651+
<li><p>Decrease <var>index</var> by 1.
652+
</ol>
653+
654+
<li><p>Set <var>currentHiddenLevel</var> and <var>maxHiddenLevel</var> to
655+
<var>currentTargetHiddenSubtreeLevel</var>.
656+
657+
<li><p>Set <var>index</var> to <var>currentTargetIndex</var> + 1.
601658

602659
<li>
603-
<p><a for=list>For each</a> <var>struct</var> in <var>reversedPath</var>:
660+
<p>While <var>index</var> is less than <var>path</var>'s <a for=list>size</a>:
604661

605662
<ol>
606-
<li><p>If <var>struct</var>'s <a for=Event/path>item</a> is <var>currentTarget</var>, then set
607-
<var>hasSeenCurrentTarget</var> to true.
663+
<li><p>If <var>path</var>[<var>index</var>]'s <a for=Event/path>slot-in-closed-tree</a> is true,
664+
then increase <var>currentHiddenLevel</var> by 1.
608665

609-
<li><p>Otherwise, if <var>hasSeenCurrentTarget</var> is true and <var>struct</var>'s
610-
<a for=Event/path>root-of-closed-tree</a> is true, then increase <var>hiddenSubtreeLevel</var> by
611-
1.
666+
<li><p>If <var>currentHiddenLevel</var> is less than or equal to <var>maxHiddenLevel</var>, then
667+
<a for=list>append</a> <var>path</var>[<var>index</var>]'s <a for=Event/path>item</a> to
668+
<var>composedPath</var>.
612669

613-
<li><p>If <var>hiddenSubtreeLevel</var> is 0, then <a for=list>append</a> <var>struct</var>'s
614-
<a for=Event/path>item</a> to <var>reversedComposedPath</var>.
670+
<li>
671+
<p>If <var>path</var>[<var>index</var>]'s <a for=Event/path>root-of-closed-tree</a> is true,
672+
then:
673+
674+
<ol>
675+
<li><p>Decrease <var>currentHiddenLevel</var> by 1.
676+
677+
<li><p>If <var>currentHiddenLevel</var> is less than <var>maxHiddenLevel</var>, then set
678+
<var>maxHiddenLevel</var> to <var>currentHiddenLevel</var>.
679+
</ol>
615680

616-
<li><p>If <var>struct</var>'s <a for=Event/path>slot-in-closed-tree</a> is true and
617-
<var>hiddenSubtreeLevel</var> is greater than 0, then decrease <var>hiddenSubtreeLevel</var> by
618-
1.
681+
<li><p>Increase <var>index</var> by 1.
619682
</ol>
620683

621-
<li><p>Return <var>reversedComposedPath</var>, in reverse order.
684+
<li><p>Return <var>composedPath</var>.
622685
</ol>
623686

624687
<p>The <dfn attribute for=Event><code>eventPhase</code></dfn> attribute must return the value it was

0 commit comments

Comments
 (0)