Bug 20445 - TreeWalker: Specified workflow stuck at root node
Summary: TreeWalker: Specified workflow stuck at root node
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: DOM (show other bugs)
Version: unspecified
Hardware: All All
: P2 normal
Target Milestone: ---
Assignee: Anne
QA Contact: public-webapps-bugzilla
Whiteboard: needs test
Depends on:
Reported: 2012-12-19 08:24 UTC by Krinkle
Modified: 2012-12-19 20:38 UTC (History)
4 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Krinkle 2012-12-19 08:24:54 UTC
While taking this API apart to implement in javascript (as exercise to learn how to read specs) I noticed that methods like firstChild() and lastChild() are stuck on the root node when implementing the specification.

For example:
> tw = document.createTreeWalker(document.body, NodeFilter.SHOW_ALL).firstChild()

In Chrome this returns document.body.firstChild.

However when following the spec:

| document.createTreeWalker( Node root, .. )
| * http://dom.spec.whatwg.org/#dom-document-createtreewalker
| > currentNode = root
| TreeWalker::firstChild()
| * http://dom.spec.whatwg.org/#concept-traverse-children
| > node = current = tw.currentNode
| - Filter
| - * http://dom.spec.whatwg.org/#concept-node-filter
| - > node's nodeType is accepted through NodeFilter.SHOW_ALL
| > tw.currentNode = node; // unaltered
| > return node;

Unless it was intended this way, I appears the spec is missing something in either the Filter or the "Traverse children" subsets to get it off the root.

PS: I've looked at all three of these but since I noticed no significant differences in this regard I've only linked to the last one above
* http://www.w3.org/TR/2012/WD-dom-20120105/#interface-treewalker
* http://www.w3.org/TR/dom/#interface-treewalker
* http://dom.spec.whatwg.org/#interface-treewalker
Comment 1 Anne 2012-12-19 12:09:26 UTC
Thanks, should be fixed: https://github.com/whatwg/dom/commit/ff9acf95c68efe5c6fbc718f814da31b4a891a6a

I suspect there may be similar bugs elsewhere in Traversal. I guess I should give it all a second look and rewrite some of it.

How would you like to be listed in the acknowledgments?
Comment 2 Krinkle 2012-12-19 19:59:34 UTC
@Anne: Sure, that'd be splendid!

And thanks for the quick fix. Much appreciated :)
Comment 3 Krinkle 2012-12-19 20:02:03 UTC
For name you may use "Timo Tijhof".

-- Timo (aka Krinkle)