WebCore:
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Feb 2008 10:35:20 +0000 (10:35 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Feb 2008 10:35:20 +0000 (10:35 +0000)
commitb60854198f0491984fdc64ffee75bb45ad1cf439
treeac8a71542347d661fdc05cf936457b63fe32c5bb
parent57978d436f76605bd9f6c12025f352b34452ad62
WebCore:

        Reviewed by Eric.

        - fix http://bugs.webkit.org/show_bug.cgi?id=3492
          TreeWalker implementation needs to be fixed (affects Acid3)
        - fix http://bugs.webkit.org/show_bug.cgi?id=4714
          NodeIterator does not handle exceptions from the filter function (affects Acid3)
        - fix http://bugs.webkit.org/show_bug.cgi?id=4716
          NodeIterator will crash if the filter function removes the current node from the document

        Test: traversal/exception-forwarding.html

        This turned into a near-rewrite of NodeIterator and TreeWalker.

        * bindings/js/JSNodeFilterCondition.h:
        * bindings/js/JSNodeFilterCondition.cpp:
        (WebCore::takeException): Added.
        (WebCore::JSNodeFilterCondition::acceptNode): Added an out parameter to return
        a JavaScript exception.

        * bindings/js/JSNodeFilterCustom.cpp:
        (WebCore::JSNodeFilter::acceptNode): Wrote a custom binding for this that raises
        a JavaScript exception if the out parameter is set.

        * bindings/js/JSNodeIteratorCustom.cpp:
        (WebCore::JSNodeIterator::nextNode): Wrote a custom binding for this that raises
        a JavaScript exception if the out parameter is set.
        (WebCore::JSNodeIterator::previousNode): Ditto.

        * bindings/js/JSTreeWalkerCustom.cpp:
        (WebCore::JSTreeWalker::parentNode): Wrote a custom binding for this that raises
        a JavaScript exception if the out parameter is set.
        (WebCore::JSTreeWalker::firstChild): Ditto.
        (WebCore::JSTreeWalker::lastChild): Ditto.
        (WebCore::JSTreeWalker::nextSibling): Ditto.
        (WebCore::JSTreeWalker::previousSibling): Ditto.
        (WebCore::JSTreeWalker::previousNode): Ditto.
        (WebCore::JSTreeWalker::nextNode): Ditto.

        * bindings/objc/DOM.mm:
        (WebCore::ObjCNodeFilterCondition::acceptNode): Updated to include new exception
        out parameter.
        (-[DOMDocument createNodeIterator:whatToShow:filter:expandEntityReferences:]):
        Use RefPtr to make object lifetimes clearer.
        (-[DOMDocument createTreeWalker:whatToShow:filter:expandEntityReferences:]):
        Ditto.

        * bindings/scripts/CodeGeneratorJS.pm: Added include of NodeFilter.h for
        JSDocument.cpp.

        * dom/Document.h:
        * dom/Document.cpp:
        (WebCore::Document::createNodeIterator): Changed to use PassRefPtr.
        (WebCore::Document::createTreeWalker): Ditto.

        * dom/NodeFilter.h:
        * dom/NodeFilter.cpp:
        (WebCore::NodeFilter::NodeFilter): Changed to use PassRefPtr.
        (WebCore::NodeFilter::acceptNode): Added an out parameter to return
        a JavaScript exception.
        * dom/NodeFilter.idl: Custom binding for acceptNode.

        * dom/NodeFilterCondition.h:
        * dom/NodeFilterCondition.cpp:
        (WebCore::NodeFilterCondition::acceptNode): Added an out parameter to return
        a JavaScript exception.

        * dom/NodeIterator.cpp:
        (WebCore::NodeIterator::NodeIterator): Changed to use PassRefPtr more.
        Eliminated m_doc, using the root node instead, and unnecessary check for
        null -- rootNode must be non-null and all nodes have a non-null document.
        (WebCore::NodeIterator::~NodeIterator): Changed to get document from root.
        (WebCore::NodeIterator::nextNode): Rewrote to use a RefPtr since the
        acceptNode function could do anything, including removing the last
        reference to the current node. Also folded findNextNode into this function
        since it's the only one that needs to call it.
        (WebCore::NodeIterator::previousNode): Same thing, but the other direction.
        (WebCore::NodeIterator::detach): Changed to use the root node as the indication
        that we're detached rather than a separate boolean.
        (WebCore::NodeIterator::notifyBeforeNodeRemoval): Removed some unnneeded
        checks. Removed incorrect use of findNextNode/findPreviousNode -- those
        functions call acceptNode and the DOM standard is quite clear that these
        functions do not take that into account, allowing the current node to become
        one that's not accepted.

        * dom/NodeIterator.h: Changed constructor to use PassRefPtr more. Changed
        nextNode and previousNode to have an out parameter with a JavaScript exception.
        Removed helper functions setReferenceNode, setPointerBeforeReferenceNode,
        detached, setDetached, document, findNextNode, and findPreviousNode. All were
        unnecessary. Removed data member m_doc which was just rootNode()->document().

        * dom/NodeIterator.idl: Custom binding for nextNode and previousNode.

        * dom/Traversal.cpp:
        (WebCore::Traversal::Traversal): Use PassRefPtr more.
        (WebCore::Traversal::acceptNode): Added out parameter for JavaScript exception.
        Also rearranged the function a little bit for clarity.

        * dom/Traversal.h: Changed acceptNode to have an out parameter with a JavaScript
        exception and made it protected, since it's only for use by the derived classes.

        * dom/TreeWalker.cpp:
        (WebCore::TreeWalker::TreeWalker): Updated to use PassRefPtr.
        (WebCore::TreeWalker::setCurrentNode): Updated to use PassRefPtr and deleted
        the overloaded version since it's not needed.
        (WebCore::TreeWalker::parentNode): Rewrote to propagate the exception and also
        to implement rules about when to check things like whether we're in the tree.
        The previous fix where we called isDescendantOf was not entirely correct, because
        the specification allows you to walk outside the tree if you get there somehow.
        What it doesn't allow is walking outside the tree from inside. The new
        implementation handles this correctly.
        (WebCore::TreeWalker::firstChild): Ditto.
        (WebCore::TreeWalker::lastChild): Ditto.
        (WebCore::TreeWalker::previousSibling): Ditto.
        (WebCore::TreeWalker::nextSibling): Ditto.
        (WebCore::TreeWalker::previousNode): Ditto. Because of the need to check the
        acceptNode function on parents, this can't use traversePreviousNode (more's the
        pity, because it's a bit complicated).
        (WebCore::TreeWalker::nextNode): Ditto.

        * dom/TreeWalker.h: Changed constructor and setCurrentNode to use PassRefPtr
        more. Changed the navigation functions to have an out parameter with a JavaScript
        exception. Removed helper functions setCurrentNode and ancestorRejected.

        * dom/TreeWalker.idl: Custom binding for navigation functions.

LayoutTests:

        Reviewed by Eric.

        - test for http://bugs.webkit.org/show_bug.cgi?id=4714
          NodeIterator does not handle exceptions from the filter function (affects Acid3)

        - grabbed NodeIterator and TreeWalker tests from Hixie's site and KHTML

        * traversal/exception-forwarding-expected.txt: Added.
        * traversal/exception-forwarding.html: Added.
        * traversal/resources: Added.
        * traversal/resources/TEMPLATE.html: Copied from LayoutTests/fast/js/resources/TEMPLATE.html.
        * traversal/resources/exception-forwarding.js: Added.

        * traversal/node-iterator-001-expected.txt: Updated to reflect correct results.
        The old results reflected a bug in our NodeIterator.
        * traversal/node-iterator-001.html: Ditto.

        * traversal/node-iterator-006.html: Changed test so there's no whitespace node after
        the <span> elements inside the test root element (a <div>). The old test results were
        incorrect; the new NodeIterator implementation correctly returned the whitespace node
        for this test.

        * traversal/node-iterator-006a.html: Copied from traversal/node-iterator-006.html.
        Preserve the original test, which now has a strange result. But the result is correct,
        so it's worth keeping around.
        * traversal/node-iterator-006a-expected.txt: Added.

        * fast/dom/TreeWalker/TreeWalker-currentNode-expected.txt: Regenerated.
        * fast/dom/TreeWalker/resources/TreeWalker-currentNode.js: Updated test to expect results
        that match the DOM specification.

        * traversal/hixie-node-iterator/001-expected.txt: Added.
        * traversal/hixie-node-iterator/001.xml: Added.
        * traversal/hixie-node-iterator/002-expected.txt: Added.
        * traversal/hixie-node-iterator/002.xml: Added.
        * traversal/hixie-node-iterator/003-expected.txt: Added.
        * traversal/hixie-node-iterator/003.xml: Added.
        * traversal/hixie-node-iterator/004-expected.txt: Added.
        * traversal/hixie-node-iterator/004.xml: Added.
        * traversal/hixie-node-iterator/005-expected.txt: Added.
        * traversal/hixie-node-iterator/005.xml: Added.
        * traversal/hixie-node-iterator/006-expected.txt: Added.
        * traversal/hixie-node-iterator/006.xml: Added.
        * traversal/hixie-node-iterator/007-expected.txt: Added.
        * traversal/hixie-node-iterator/007.xml: Added.
        * traversal/hixie-node-iterator/008-expected.txt: Added.
        * traversal/hixie-node-iterator/008.xml: Added.
        * traversal/hixie-node-iterator/009-expected.txt: Added.
        * traversal/hixie-node-iterator/009.xml: Added.
        * traversal/hixie-node-iterator/010-expected.txt: Added.
        * traversal/hixie-node-iterator/010.xml: Added.
        * traversal/hixie-node-iterator/origin.txt: Added.

        * traversal/tree-walker-filter-1-expected.txt: Added.
        * traversal/tree-walker-filter-1.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@30089 268f45cc-cd09-0410-ab3c-d52691b4dbfc
60 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/dom/TreeWalker/TreeWalker-currentNode-expected.txt
LayoutTests/fast/dom/TreeWalker/resources/TreeWalker-currentNode.js
LayoutTests/traversal/exception-forwarding-expected.txt [new file with mode: 0644]
LayoutTests/traversal/exception-forwarding.html [new file with mode: 0644]
LayoutTests/traversal/hixie-node-iterator/001-expected.txt [new file with mode: 0644]
LayoutTests/traversal/hixie-node-iterator/001.xml [new file with mode: 0644]
LayoutTests/traversal/hixie-node-iterator/002-expected.txt [new file with mode: 0644]
LayoutTests/traversal/hixie-node-iterator/002.xml [new file with mode: 0644]
LayoutTests/traversal/hixie-node-iterator/003-expected.txt [new file with mode: 0644]
LayoutTests/traversal/hixie-node-iterator/003.xml [new file with mode: 0644]
LayoutTests/traversal/hixie-node-iterator/004-expected.txt [new file with mode: 0644]
LayoutTests/traversal/hixie-node-iterator/004.xml [new file with mode: 0644]
LayoutTests/traversal/hixie-node-iterator/005-expected.txt [new file with mode: 0644]
LayoutTests/traversal/hixie-node-iterator/005.xml [new file with mode: 0644]
LayoutTests/traversal/hixie-node-iterator/006-expected.txt [new file with mode: 0644]
LayoutTests/traversal/hixie-node-iterator/006.xml [new file with mode: 0644]
LayoutTests/traversal/hixie-node-iterator/007-expected.txt [new file with mode: 0644]
LayoutTests/traversal/hixie-node-iterator/007.xml [new file with mode: 0644]
LayoutTests/traversal/hixie-node-iterator/008-expected.txt [new file with mode: 0644]
LayoutTests/traversal/hixie-node-iterator/008.xml [new file with mode: 0644]
LayoutTests/traversal/hixie-node-iterator/009-expected.txt [new file with mode: 0644]
LayoutTests/traversal/hixie-node-iterator/009.xml [new file with mode: 0644]
LayoutTests/traversal/hixie-node-iterator/010-expected.txt [new file with mode: 0644]
LayoutTests/traversal/hixie-node-iterator/010.xml [new file with mode: 0644]
LayoutTests/traversal/hixie-node-iterator/origin.txt [new file with mode: 0644]
LayoutTests/traversal/node-iterator-001-expected.txt
LayoutTests/traversal/node-iterator-001.html
LayoutTests/traversal/node-iterator-006.html
LayoutTests/traversal/node-iterator-006a-expected.txt [new file with mode: 0644]
LayoutTests/traversal/node-iterator-006a.html [new file with mode: 0644]
LayoutTests/traversal/resources/TEMPLATE.html [new file with mode: 0644]
LayoutTests/traversal/resources/exception-forwarding.js [new file with mode: 0644]
LayoutTests/traversal/tree-walker-filter-1-expected.txt [new file with mode: 0644]
LayoutTests/traversal/tree-walker-filter-1.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/bindings/js/JSNodeFilterCondition.cpp
WebCore/bindings/js/JSNodeFilterCondition.h
WebCore/bindings/js/JSNodeFilterCustom.cpp
WebCore/bindings/js/JSNodeIteratorCustom.cpp
WebCore/bindings/js/JSTreeWalkerCustom.cpp
WebCore/bindings/objc/DOM.mm
WebCore/bindings/scripts/CodeGeneratorJS.pm
WebCore/dom/Document.cpp
WebCore/dom/Document.h
WebCore/dom/Node.cpp
WebCore/dom/Node.h
WebCore/dom/NodeFilter.cpp
WebCore/dom/NodeFilter.h
WebCore/dom/NodeFilter.idl
WebCore/dom/NodeFilterCondition.cpp
WebCore/dom/NodeFilterCondition.h
WebCore/dom/NodeIterator.cpp
WebCore/dom/NodeIterator.h
WebCore/dom/NodeIterator.idl
WebCore/dom/Traversal.cpp
WebCore/dom/Traversal.h
WebCore/dom/TreeWalker.cpp
WebCore/dom/TreeWalker.h
WebCore/dom/TreeWalker.idl