<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>18540</bug_id>
          
          <creation_ts>2012-08-12 20:15:23 +0000</creation_ts>
          <short_desc>Proposal for a new acceptNode() return value for TreeWalker.</short_desc>
          <delta_ts>2016-03-14 13:07:37 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebAppsWG</product>
          <component>DOM</component>
          <version>unspecified</version>
          <rep_platform>All</rep_platform>
          <op_sys>Windows 3.1</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>WONTFIX</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard>blocked on implementers weighing in</status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Ms2ger">Ms2ger</reporter>
          <assigned_to name="Anne">annevk</assigned_to>
          <cc>ajvincent</cc>
    
    <cc>bzbarsky</cc>
    
    <cc>jonas</cc>
    
    <cc>kennyluck</cc>
    
    <cc>mike</cc>
    
    <cc>myst.dg</cc>
    
    <cc>www-dom</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>72089</commentid>
    <comment_count>0</comment_count>
    <who name="Ms2ger">Ms2ger</who>
    <bug_when>2012-08-12 20:15:23 +0000</bug_when>
    <thetext>See &lt;http://lists.w3.org/Archives/Public/www-dom/2012JulSep/0033.html&gt;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>74200</commentid>
    <comment_count>1</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2012-09-21 10:31:17 +0000</bug_when>
    <thetext>It would be nice to have some kind of data how often TreeWalker code is invoked in browsers on average. (And maybe make sure to not count Acid3 runs.) We can make logical additions, but if nobody uses it there is no point.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>77182</commentid>
    <comment_count>2</comment_count>
    <who name="Alex Vincent">ajvincent</who>
    <bug_when>2012-10-27 08:46:48 +0000</bug_when>
    <thetext>+1 for me.  More than once I&apos;ve written a RejectChildrenFilter specifically to allow for a node to be accepted but for its children to be rejected.  It&apos;s historically been the first thing I think about when it comes to TreeWalker.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>83441</commentid>
    <comment_count>3</comment_count>
    <who name="Jonas Sicking (Not reading bugmail)">jonas</who>
    <bug_when>2013-02-20 23:42:26 +0000</bug_when>
    <thetext>Note that this would be a pretty different implementation-wise (and to some extent behavior-wise) from he current filters.

The current filters are implemented by calling the filter function for each node as we scan the tree trying to figure out which node to return. Once we have found a node we set the currentNode and return it. No state is used during the scanning and no state is retained from the scanning. Next time we need to scan for a new node to walk to, the only input into that algorithm is the currentNode that is used as a starting point for the scanning.

In order to implement this new proposed value we would need to either remember the fact that the current node returned FILTER_NO_CHILDREN. Or we would need to re-test the currentNode when we start a new scan.

Put it another way. How would you expect the following to behave:

DOM:
&lt;html&gt;
  &lt;body&gt;
    &lt;div&gt;
      text here
    &lt;/div&gt;
  &lt;/body&gt;
&lt;/html&gt;


JS:
walker = document.createTreeWalker(document.documentElement, SHOW_ELEMENT, function(node) {
  if (node.dataset.hideChildren)
    return FILTER_NO_CHILDREN;
  return FILTER_ACCEPT;
});

walker.firstChild();
assert(walker.currentNode == document.body); // true
document.body.dataset.hideChildren = &quot;true&quot;;
walker.nextNode();

What is walker.currentNode at this point?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>84129</commentid>
    <comment_count>4</comment_count>
    <who name="Leo Deng">myst.dg</who>
    <bug_when>2013-03-08 18:45:09 +0000</bug_when>
    <thetext>(In reply to comment #1)
&gt; It would be nice to have some kind of data how often TreeWalker code is
&gt; invoked in browsers on average. (And maybe make sure to not count Acid3
&gt; runs.) We can make logical additions, but if nobody uses it there is no
&gt; point.

Actually this proposal is brought by two posts on my blog that talk of an interview quiz for front-end web developers: how to filter DOM nodes on given condition (written in Chinese, don&apos;t know whether you could read).

http://forcefront.com/2012/an-interview-quiz-filtered-dom-selector/
http://forcefront.com/2012/an-interview-quiz-filtered-dom-selector-continued/

As professional developers, we are encouraged to find various solutions so as to choose the best one and make websites better. Well yes, I don&apos;t see anyone using TreeWalker or NodeIterator. Why? Because they suck! TreeWalker is the slowest one among five solutions I provided. The best one is ten time faster than it!

And by the way, I don&apos;t think whether to fix a bug in spec depends on the number of people facing it. That&apos;s browser vendors&apos; job. Since W3C focuses on delivering standards, the primary consideration should be &quot;whether it is a bug or not&quot;.

&quot;Oh, since nobody&apos;s using, so be it.&quot; There&apos;s an old saying in China: smash a pot to pieces just because it&apos;s cracked, which means to write oneself off as hopeless and act recklessly.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>84254</commentid>
    <comment_count>5</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-03-11 17:04:32 +0000</bug_when>
    <thetext>&gt; In order to implement this new proposed value we would need to either remember
&gt; the fact that the current node returned FILTER_NO_CHILDREN.

Right.  That doesn&apos;t seem too terrible to me, for what it&apos;s worth....</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>84287</commentid>
    <comment_count>6</comment_count>
    <who name="Jonas Sicking (Not reading bugmail)">jonas</who>
    <bug_when>2013-03-12 05:12:19 +0000</bug_when>
    <thetext>It would result in somewhat awkward behavior in the example in comment 3, but I agree it&apos;s probably the best solution.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>106645</commentid>
    <comment_count>7</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-05-22 13:46:02 +0000</bug_when>
    <thetext>If someone implements this we&apos;ll add it to the standard.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>125461</commentid>
    <comment_count>8</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2016-03-14 13:07:37 +0000</bug_when>
    <thetext>Given the lack of interest in two years closing this as WONTFIX. Please let me know if you find two browsers willing to implement this. (Probably best reported as a new issue on GitHub.)</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>