Skip to content

Commit

Permalink
TreeWalker nextNode() and previousNode() had bugs too.
Browse files Browse the repository at this point in the history
Thanks @Krinkle! (Also the last copypasta commit was wrong as it had
previous and next reversed, this fixes that too.)
  • Loading branch information
annevk committed Dec 20, 2012
1 parent 743aa5f commit 4b60feb
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 180 deletions.
152 changes: 62 additions & 90 deletions Overview.src.html
Expand Up @@ -7823,7 +7823,7 @@ <h3>Interface <code>TreeWalker</code></h3>
<li><p>Return null.
</ol>

<p>To <dfn title=concept-traverse-children>traverse children</dfn> of
<p>To <dfn title=concept-traverse-children>traverse children</dfn> of type
<var title>type</var>, run these steps:

<ol>
Expand All @@ -7832,7 +7832,7 @@ <h3>Interface <code>TreeWalker</code></h3>

<li><p>Set <var title>node</var> to <var title>node</var>'s
<span title=concept-tree-first-child>first child</span> if
<var title>type</var> is first, and to <var title>node</var>'s
<var title>type</var> is first, and <var title>node</var>'s
<span title=concept-tree-last-child>last child</span> if
<var title>type</var> is last.

Expand All @@ -7858,7 +7858,7 @@ <h3>Interface <code>TreeWalker</code></h3>
<ol>
<li><p>Let <var title>child</var> be <var title>node</var>'s
<span title=concept-tree-first-child>first child</span> if
<var title>type</var> is first, and to <var title>node</var>'s
<var title>type</var> is first, and <var title>node</var>'s
<span title=concept-tree-last-child>last child</span> if
<var title>type</var> is last.

Expand All @@ -7872,9 +7872,9 @@ <h3>Interface <code>TreeWalker</code></h3>

<ol>
<li><p>Let <var title>sibling</var> be <var title>node</var>'s
<span title=concept-tree-previous-sibling>previous sibling</span> if
<var title>type</var> is first, and to <var title>node</var>'s
<span title=concept-tree-next-sibling>next sibling</span> if
<var title>type</var> is first, and <var title>node</var>'s
<span title=concept-tree-previous-sibling>previous sibling</span> if
<var title>type</var> is last.

<li><p>If <var title>sibling</var> is not null, set
Expand Down Expand Up @@ -7912,27 +7912,20 @@ <h3>Interface <code>TreeWalker</code></h3>
<code title=dom-TreeWalker-currentNode>currentNode</code> attribute.

<li><p>If <var title>node</var> is
<span title=concept-traversal-root>root</span> return null and terminate
these steps.
<span title=concept-traversal-root>root</span>, return null.

<li>
<p>Run these substeps:

<ol>
<li>
<dl class=switch>
<dt>If type is next
<dd><p>Let <var title>sibling</var> be the
<span title=concept-tree-next-sibling>next sibling</span> of
<var title>node</var>.
<dt>If type is previous
<dd><p>Let <var title>sibling</var> be the
<span title=concept-tree-previous-sibling>previous sibling</span> of
<var title>node</var>.
</dl>
<li><p>Let <var title>sibling</var> be <var title>node</var>'s
<span title=concept-tree-next-sibling>next sibling</span> if
<var title>type</var> is next, and <var title>node</var>'s
<span title=concept-tree-previous-sibling>previous sibling</span> if
<var title>type</var> is previous.

<li>
<p>While <var title>sibling</var> is not null run these inner substeps:
<p>While <var title>sibling</var> is not null, run these subsubsteps:

<ol>
<li><p>Set <var title>node</var> to <var title>sibling</var>.
Expand All @@ -7944,50 +7937,34 @@ <h3>Interface <code>TreeWalker</code></h3>
<li><p>If <var title>result</var> is
<code title=dom-NodeFilter-FILTER_ACCEPT>FILTER_ACCEPT</code>, then set
the <code title=dom-TreeWalker-currentNode>currentNode</code>
attribute to <var title>node</var>, return <var title>node</var>, and
terminate these steps.

<li>
<dl class=switch>
<dt>If type is next
<dd><p>Let <var title>sibling</var> be the
<span title=concept-tree-first-child>first child</span> of
<var title>node</var>.
<dt>If type is previous
<dd><p>Let <var title>sibling</var> be the
<span title=concept-tree-last-child>last child</span> of
<var title>node</var>.
</dl>

<li>
<p>If <var title>result</var> is
<code title=dom-NodeFilter-FILTER_REJECT>FILTER_REJECT</code> or
<var title>sibling</var> is null, then set <var title>sibling</var> as
follows:

<dl class=switch>
<dt>If type is next
<dd><p>Let <var title>sibling</var> be the
<span title=concept-tree-next-sibling>next sibling</span> of
<var title>node</var>.
<dt>If type is previous
<dd><p>Let <var title>sibling</var> be the
<span title=concept-tree-previous-sibling>previous sibling</span> of
<var title>node</var>.
</dl>
attribute to <var title>node</var> and return <var title>node</var>.

<li><p>Set <var title>sibling</var> to <var title>node</var>'s
<span title=concept-tree-first-child>first child</span> if
<var title>type</var> is next, and <var title>node</var>'s
<span title=concept-tree-last-child>last child</span> if
<var title>type</var> is previous.

<li><p>If <var title>result</var> is
<code title=dom-NodeFilter-FILTER_REJECT>FILTER_REJECT</code> or
<var title>sibling</var> is null, then set <var title>sibling</var> to
<var title>node</var>'s
<span title=concept-tree-next-sibling>next sibling</span> if
<var title>type</var> is next, and <var title>node</var>'s
<span title=concept-tree-previous-sibling>previous sibling</span> if
<var title>type</var> is previous.
</ol>

<li><p>Set <var title>node</var> to its
<span title=concept-tree-parent>parent</span>.

<li><p>If <var title>node</var> is null or is
<span title=concept-traversal-root>root</span> return null and terminate
these steps.
<span title=concept-traversal-root>root</span>, return null.

<li><p><span title=concept-node-filter>Filter</span>
<var title>node</var> and if the return value is
<code title=dom-NodeFilter-FILTER_ACCEPT>FILTER_ACCEPT</code>, then
return null and terminate these steps.
return null.
<!-- XXX WTF? -->

<li><p>Run these substeps again.
Expand All @@ -8014,15 +7991,15 @@ <h3>Interface <code>TreeWalker</code></h3>

<li>
<p>While <var title>node</var> is not
<span title=concept-traversal-root>root</span> run these substeps:
<span title=concept-traversal-root>root</span>, run these substeps:

<ol>
<li><p>Let <var title>sibling</var> be the
<span title=concept-tree-previous-sibling>previous sibling</span> of
<var title>node</var>.

<li>
<p>While <var title>sibling</var> is not null run these inner substeps:
<p>While <var title>sibling</var> is not null, run these subsubsteps:

<ol>
<li><p>Set <var title>node</var> to <var title>sibling</var>.
Expand All @@ -8031,33 +8008,23 @@ <h3>Interface <code>TreeWalker</code></h3>
<var title>node</var> and let <var title>result</var> be the return
value.

<li>
<p>While <var title>result</var> is not
<code title=dom-NodeFilter-FILTER_REJECT>FILTER_REJECT</code> and
<var title>node</var> has a
<span title=concept-tree-child>child</span>, run these innermost
substeps:

<ol>
<li><p>Set <var title>node</var> to its
<span title=concept-tree-last-child>last child</span>.

<li><p><span title=concept-node-filter>Filter</span>
<var title>node</var> and set <var title>result</var> to the return
value.
</ol>
<li><p>While <var title>result</var> is not
<code title=dom-NodeFilter-FILTER_REJECT>FILTER_REJECT</code> and
<var title>node</var> has a
<span title=concept-tree-child>child</span>, set <var title>node</var>
to its <span title=concept-tree-last-child>last child</span> and then
<span title=concept-node-filter>filter</span> <var title>node</var> and
set <var title>result</var> to the return value.

<li><p>If <var title>result</var> is
<code title=dom-NodeFilter-FILTER_ACCEPT>FILTER_ACCEPT</code>, then set
the <code title=dom-TreeWalker-currentNode>currentNode</code>
attribute to <var title>node</var>, return <var title>node</var>, and
terminate these steps.
attribute to <var title>node</var> and return <var title>node</var>.
</ol>

<li><p>If <var title>node</var> is
<span title=concept-traversal-root>root</span> or has no
<span title=concept-tree-parent>parent</span>, return null and terminate
these steps.
<span title=concept-traversal-root>root</span> or <var title>node</var>'s
<span title=concept-tree-parent>parent</span> is null, return null.

<li><p>Set <var title>node</var> to its
<span title=concept-tree-parent>parent</span>.
Expand All @@ -8066,9 +8033,10 @@ <h3>Interface <code>TreeWalker</code></h3>
<var title>node</var> and if the return value is
<code title=dom-NodeFilter-FILTER_ACCEPT>FILTER_ACCEPT</code>, then set
the <code title=dom-TreeWalker-currentNode>currentNode</code> attribute
to <var title>node</var>, return <var title>node</var>, and terminate
these steps.
to <var title>node</var> and return <var title>node</var>.
</ol>

<li><p>Return null.
</ol>

<p>The <dfn title=dom-TreeWalker-nextNode><code>nextNode()</code></dfn>
Expand All @@ -8087,23 +8055,22 @@ <h3>Interface <code>TreeWalker</code></h3>
<ol>
<li>
<p>While <var title>result</var> is not
<code title=dom-NodeFilter-FILTER_ACCEPT>FILTER_ACCEPT</code> and
<code title=dom-NodeFilter-FILTER_REJECT>FILTER_REJECT</code> and
<var title>node</var> has a <span title=concept-tree-child>child</span>,
run these inner substeps:
run these subsubsteps:

<ol>
<li><p>Set <var title>node</var> to its
<span title=concept-tree-first-child>first child</span>
<span title=concept-tree-first-child>first child</span>.

<li><p><span title=concept-node-filter>Filter</span>
<var title>node</var> and let <var title>result</var> be the return
<var title>node</var> and set <var title>result</var> to the return
value.

<li><p>If <var title>result</var> is
<code title=dom-NodeFilter-FILTER_ACCEPT>FILTER_ACCEPT</code>, then set
the <code title=dom-TreeWalker-currentNode>currentNode</code> attribute
to <var title>node</var>, return <var title>node</var>, and terminate
these steps.
to <var title>node</var> and return <var title>node</var>.
</ol>

<li>
Expand All @@ -8114,15 +8081,19 @@ <h3>Interface <code>TreeWalker</code></h3>
<span title=concept-traversal-root>root</span>, set
<var title>node</var> to the first such
<span title=concept-node>node</span>.
<p>Otherwise, run these substeps again (skipping the next step).
<!-- Implemented as iterating over parent/nextSibling in Gecko -->
<p>Otherwise, return null.
<!-- Implemented as iterating over parent/nextSibling -->

<li><p><span title=concept-node-filter>Filter</span>
<var title>node</var> and if the return value is
<var title>node</var> and set <var title>result</var> to the return
value.

<li><p>If <var title>result</var> is
<code title=dom-NodeFilter-FILTER_ACCEPT>FILTER_ACCEPT</code>, then set
the <code title=dom-TreeWalker-currentNode>currentNode</code> attribute
to <var title>node</var>, return <var title>node</var>, and terminate
these steps.
to <var title>node</var> and return <var title>node</var>.

<li><p>Run these substeps again.
</ol>
</ol>

Expand Down Expand Up @@ -8868,8 +8839,8 @@ <h3>DOM Traversal</h3>
with user agents.

<p><code title=dom-NodeIterator-nextNode>nextNode()</code> and
<code title=dom-NodeIterator-previousNode>previousNode()</code> node now
throw when invoked from a <code>NodeFilter</code> to align with user agents.
<code title=dom-NodeIterator-previousNode>previousNode()</code> now throw
when invoked from a <code>NodeFilter</code> to align with user agents.


<h2 class=no-num>References</h2>
Expand Down Expand Up @@ -8916,6 +8887,7 @@ <h2 class=no-num>Acknowledgments</h2>
Shiki Okasaka,
Stig Halvorsen,
Tab Atkins,
Timo Tijhof,
Travis Leithead, and
Zack Weinberg

Expand Down

0 comments on commit 4b60feb

Please sign in to comment.