Bug 16759 - TreeWalker change to forbid leaving the subtree (bug 16758) regressed us on Acid3
Summary: TreeWalker change to forbid leaving the subtree (bug 16758) regressed us on A...
Status: RESOLVED DUPLICATE of bug 3492
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: Mac OS X 10.4
: P2 Normal
Assignee: Darin Adler
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-01-05 19:03 PST by Eric Seidel (no email)
Modified: 2019-02-06 09:03 PST (History)
3 users (show)

See Also:


Attachments
fix (11.74 KB, patch)
2008-01-06 15:54 PST, Sam Weinig
eric: review-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Seidel (no email) 2008-01-05 19:03:52 PST
I think bug 16758 regressed us on the Acid3

We added a failure:
Test 10: FAIL (failed to handle regrafting correctly)

    function () {
      // test 10: walking outside a tree
      var doc = getTestDocument();
      var p = doc.createElement('p');
      doc.body.appendChild(p);
      var b = doc.body;
      var w = document.createTreeWalker(b, 0xFFFFFFFF, null, true);
      assert(w.currentNode == b, "basic use of TreeWalker failed: currentNode");
      assert(w.lastChild() == p, "basic use of TreeWalker failed: lastChild()");
      assert(w.previousNode() == b, "basic use of TreeWalker failed: previousNode()");
      doc.documentElement.removeChild(b);
      assert(w.lastChild() == p, "TreeWalker failed after removing the current node from the tree");
      assert(w.nextNode() == null, "failed to walk into the end of a subtree");
      doc.documentElement.appendChild(p);
      assert(w.previousNode() == doc.getElementsByTagName('title')[0], "failed to handle regrafting correctly");
      p.appendChild(b);
      assert(w.nextNode() == p, "couldn't retrace steps");
      assert(w.nextNode() == b, "couldn't step back into root");
      assert(w.previousNode() == null, "root didn't retake its rootish position");
      return 1;
    },
Comment 1 Sam Weinig 2008-01-05 20:25:04 PST
I believe I introduced this issue by explicitly checking that the returned node of the TreeWalker methods isDescendantOf(rootNode).  Therefore, if the rootNode is removed and currentNode is re-inserted, this check will always fail and cause null to be returned.  I am not sure what the correct behavior is however.
Comment 2 Ian 'Hixie' Hickson 2008-01-05 22:53:26 PST
TreeWalkers are exclusively dependent on their currentNode (unlike Ranges, which are dependent just on the Document/DocumentFragment/Attr they were originally bound to). You can TreeWalk right from one Document to another, if the Node in question is adopt()ed in between, for instance. You can similarly keep walking even if the node is removed from the root and made an orphan, and keep walking if the node is grafted above it, or whatever.
Comment 3 Sam Weinig 2008-01-06 15:54:33 PST
Created attachment 18306 [details]
fix
Comment 4 Eric Seidel (no email) 2008-01-06 16:22:07 PST
Comment on attachment 18306 [details]
fix

Sam said he would post a few more tests.

For example:
- what about walking between documents (adopting a node during the walk)
- what about tree manipulations during the walk?
- should firstChild/lastChild/or previousSibling ever be able to walk "past" the root?

It's really the test which I care about more than the patch.  The patch looks fine.  The question is just if we have and are testing the correct behavior.
Comment 5 Eric Seidel (no email) 2008-01-06 20:36:08 PST
Comment on attachment 18306 [details]
fix

r- until the additional test cases are posted.  We could land this, but it's best to wait.
Comment 6 Darin Adler 2008-01-09 13:05:40 PST
My patch in bug 3492 fixes this. I didn't find this bug because I searched for TreeWalker in bug titles only.
Comment 7 Darin Adler 2008-01-09 14:31:53 PST
I think this is effectively a duplicate of bug 3492.

*** This bug has been marked as a duplicate of 3492 ***
Comment 8 Lucas Forschler 2019-02-06 09:03:29 PST
Mass moving XML DOM bugs to the "DOM" Component.