Default value for createNodeIterator() / createTreeWalker()'s whatToShow parameter...
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 20 Aug 2015 22:32:10 +0000 (22:32 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 20 Aug 2015 22:32:10 +0000 (22:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=148238

Reviewed by Ryosuke Niwa.

Source/WebCore:

Default value for createNodeIterator() / createTreeWalker()'s whatToShow
parameter should be 0xFFFFFFFF as per the specification:
- http://w3c-test.org/dom/traversal/NodeIterator.html
- http://w3c-test.org/dom/traversal/TreeWalker.html

Firefox and Chrome conform to the specification. However, WebKit was
using 0 as default value.

We still don't behave as expected in some cases, as visible from
the checks that are still failing in the new layout tests. Those
will be addressed separately.

Tests: fast/dom/createNodeIterator-parameters.html
       fast/dom/createTreeWalker-parameters.html

* dom/Document.cpp:
(WebCore::Document::createNodeIterator):
(WebCore::Document::createTreeWalker):
(WebCore::Document::scheduleForcedStyleRecalc): Deleted.
(WebCore::Document::scheduleStyleRecalc): Deleted.
* dom/Document.h:
* dom/Document.idl:
* dom/NodeIterator.cpp:
(WebCore::NodeIterator::NodeIterator):
* dom/NodeIterator.h:
(WebCore::NodeIterator::create):
* dom/Traversal.cpp:
(WebCore::NodeIteratorBase::NodeIteratorBase):
* dom/Traversal.h:
(WebCore::NodeIteratorBase::whatToShow):
* dom/TreeWalker.cpp:
(WebCore::TreeWalker::TreeWalker):
* dom/TreeWalker.h:
(WebCore::TreeWalker::create):

LayoutTests:

Add tests for createNodeIterator() / createTreeWalker() parameters.
Some of the checks are still failing.

* fast/dom/createNodeIterator-parameters-expected.txt: Added.
* fast/dom/createNodeIterator-parameters.html: Added.
* fast/dom/createTreeWalker-parameters-expected.txt: Added.
* fast/dom/createTreeWalker-parameters.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@188711 268f45cc-cd09-0410-ab3c-d52691b4dbfc

15 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/dom/createNodeIterator-parameters-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/createNodeIterator-parameters.html [new file with mode: 0644]
LayoutTests/fast/dom/createTreeWalker-parameters-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/createTreeWalker-parameters.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/dom/Document.idl
Source/WebCore/dom/NodeIterator.cpp
Source/WebCore/dom/NodeIterator.h
Source/WebCore/dom/Traversal.cpp
Source/WebCore/dom/Traversal.h
Source/WebCore/dom/TreeWalker.cpp
Source/WebCore/dom/TreeWalker.h

index 5ebffbd..95a2fd4 100644 (file)
@@ -1,3 +1,18 @@
+2015-08-20  Chris Dumez  <cdumez@apple.com>
+
+        Default value for createNodeIterator() / createTreeWalker()'s whatToShow parameter should be 0xFFFFFFFF
+        https://bugs.webkit.org/show_bug.cgi?id=148238
+
+        Reviewed by Ryosuke Niwa.
+
+        Add tests for createNodeIterator() / createTreeWalker() parameters.
+        Some of the checks are still failing.
+
+        * fast/dom/createNodeIterator-parameters-expected.txt: Added.
+        * fast/dom/createNodeIterator-parameters.html: Added.
+        * fast/dom/createTreeWalker-parameters-expected.txt: Added.
+        * fast/dom/createTreeWalker-parameters.html: Added.
+
 2015-08-20  Nan Wang  <n_wang@apple.com>
 
         AX: Re-enable aria-checked-mixed-value.html test for mac
diff --git a/LayoutTests/fast/dom/createNodeIterator-parameters-expected.txt b/LayoutTests/fast/dom/createNodeIterator-parameters-expected.txt
new file mode 100644 (file)
index 0000000..3deb741
--- /dev/null
@@ -0,0 +1,35 @@
+Tests parameters of document.createNodeIterator() API.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+* No parameters
+PASS document.createNodeIterator() threw exception TypeError: Not enough arguments.
+
+Default parameters
+iterator = document.createNodeIterator(document)
+PASS iterator.root is document
+PASS iterator.referenceNode is document
+PASS iterator.whatToShow is 0xFFFFFFFF
+PASS iterator.filter is null
+PASS iterator.pointerBeforeReferenceNode is true
+
+Passing null for optional parameters
+iterator = document.createNodeIterator(document, null, null)
+PASS iterator.root is document
+PASS iterator.referenceNode is document
+PASS iterator.whatToShow is 0
+FAIL iterator.filter should be null. Was [object NodeFilter].
+PASS iterator.pointerBeforeReferenceNode is true
+
+Passing undefined for optional parameters
+iterator = document.createNodeIterator(document, undefined, undefined)
+PASS iterator.root is document
+PASS iterator.referenceNode is document
+FAIL iterator.whatToShow should be 4294967295. Was 0.
+FAIL iterator.filter should be null. Was [object NodeFilter].
+PASS iterator.pointerBeforeReferenceNode is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/dom/createNodeIterator-parameters.html b/LayoutTests/fast/dom/createNodeIterator-parameters.html
new file mode 100644 (file)
index 0000000..412b38a
--- /dev/null
@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src="../../resources/js-test-pre.js"></script>
+<script>
+description("Tests parameters of document.createNodeIterator() API.");
+
+debug("* No parameters");
+shouldThrow("document.createNodeIterator()", "'TypeError: Not enough arguments'");
+
+debug("");
+debug("Default parameters");
+evalAndLog("iterator = document.createNodeIterator(document)");
+shouldBe("iterator.root", "document");
+shouldBe("iterator.referenceNode", "document");
+shouldBe("iterator.whatToShow", "0xFFFFFFFF");
+shouldBeNull("iterator.filter");
+shouldBeTrue("iterator.pointerBeforeReferenceNode");
+
+debug("");
+debug("Passing null for optional parameters");
+evalAndLog("iterator = document.createNodeIterator(document, null, null)");
+shouldBe("iterator.root", "document");
+shouldBe("iterator.referenceNode", "document");
+shouldBe("iterator.whatToShow", "0");
+shouldBeNull("iterator.filter");
+shouldBeTrue("iterator.pointerBeforeReferenceNode");
+
+debug("");
+debug("Passing undefined for optional parameters");
+evalAndLog("iterator = document.createNodeIterator(document, undefined, undefined)");
+shouldBe("iterator.root", "document");
+shouldBe("iterator.referenceNode", "document");
+shouldBe("iterator.whatToShow", "0xFFFFFFFF");
+shouldBeNull("iterator.filter");
+shouldBeTrue("iterator.pointerBeforeReferenceNode");
+
+</script>
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/dom/createTreeWalker-parameters-expected.txt b/LayoutTests/fast/dom/createTreeWalker-parameters-expected.txt
new file mode 100644 (file)
index 0000000..328755d
--- /dev/null
@@ -0,0 +1,32 @@
+Tests parameters of document.createTreeWalker() API.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+* No parameters
+PASS document.createTreeWalker() threw exception TypeError: Not enough arguments.
+
+Default parameters
+walker = document.createTreeWalker(document)
+PASS walker.root is document
+PASS walker.currentNode is document
+PASS walker.whatToShow is 0xFFFFFFFF
+PASS walker.filter is null
+
+Passing null for optional parameters
+walker = document.createTreeWalker(document, null, null)
+PASS walker.root is document
+PASS walker.currentNode is document
+PASS walker.whatToShow is 0
+FAIL walker.filter should be null. Was [object NodeFilter].
+
+Passing undefined for optional parameters
+walker = document.createTreeWalker(document, undefined, undefined)
+PASS walker.root is document
+PASS walker.currentNode is document
+FAIL walker.whatToShow should be 4294967295. Was 0.
+FAIL walker.filter should be null. Was [object NodeFilter].
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/dom/createTreeWalker-parameters.html b/LayoutTests/fast/dom/createTreeWalker-parameters.html
new file mode 100644 (file)
index 0000000..13d4a4e
--- /dev/null
@@ -0,0 +1,38 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src="../../resources/js-test-pre.js"></script>
+<script>
+description("Tests parameters of document.createTreeWalker() API.");
+
+debug("* No parameters");
+shouldThrow("document.createTreeWalker()", "'TypeError: Not enough arguments'");
+
+debug("");
+debug("Default parameters");
+evalAndLog("walker = document.createTreeWalker(document)");
+shouldBe("walker.root", "document");
+shouldBe("walker.currentNode", "document");
+shouldBe("walker.whatToShow", "0xFFFFFFFF");
+shouldBeNull("walker.filter");
+
+debug("");
+debug("Passing null for optional parameters");
+evalAndLog("walker = document.createTreeWalker(document, null, null)");
+shouldBe("walker.root", "document");
+shouldBe("walker.currentNode", "document");
+shouldBe("walker.whatToShow", "0");
+shouldBeNull("walker.filter");
+
+debug("");
+debug("Passing undefined for optional parameters");
+evalAndLog("walker = document.createTreeWalker(document, undefined, undefined)");
+shouldBe("walker.root", "document");
+shouldBe("walker.currentNode", "document");
+shouldBe("walker.whatToShow", "0xFFFFFFFF");
+shouldBeNull("walker.filter");
+
+</script>
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
index a64e35a..e695464 100644 (file)
@@ -1,3 +1,45 @@
+2015-08-20  Chris Dumez  <cdumez@apple.com>
+
+        Default value for createNodeIterator() / createTreeWalker()'s whatToShow parameter should be 0xFFFFFFFF
+        https://bugs.webkit.org/show_bug.cgi?id=148238
+
+        Reviewed by Ryosuke Niwa.
+
+        Default value for createNodeIterator() / createTreeWalker()'s whatToShow
+        parameter should be 0xFFFFFFFF as per the specification:
+        - http://w3c-test.org/dom/traversal/NodeIterator.html
+        - http://w3c-test.org/dom/traversal/TreeWalker.html
+
+        Firefox and Chrome conform to the specification. However, WebKit was
+        using 0 as default value.
+
+        We still don't behave as expected in some cases, as visible from
+        the checks that are still failing in the new layout tests. Those
+        will be addressed separately.
+
+        Tests: fast/dom/createNodeIterator-parameters.html
+               fast/dom/createTreeWalker-parameters.html
+
+        * dom/Document.cpp:
+        (WebCore::Document::createNodeIterator):
+        (WebCore::Document::createTreeWalker):
+        (WebCore::Document::scheduleForcedStyleRecalc): Deleted.
+        (WebCore::Document::scheduleStyleRecalc): Deleted.
+        * dom/Document.h:
+        * dom/Document.idl:
+        * dom/NodeIterator.cpp:
+        (WebCore::NodeIterator::NodeIterator):
+        * dom/NodeIterator.h:
+        (WebCore::NodeIterator::create):
+        * dom/Traversal.cpp:
+        (WebCore::NodeIteratorBase::NodeIteratorBase):
+        * dom/Traversal.h:
+        (WebCore::NodeIteratorBase::whatToShow):
+        * dom/TreeWalker.cpp:
+        (WebCore::TreeWalker::TreeWalker):
+        * dom/TreeWalker.h:
+        (WebCore::TreeWalker::create):
+
 2015-08-20  Anders Carlsson  <andersca@apple.com>
 
         Stop using cancelCallOnMainThread in MediaPlayerPrivateAVFoundation
index d128a21..ba2520f 100644 (file)
@@ -1694,23 +1694,13 @@ Ref<Range> Document::createRange()
     return Range::create(*this);
 }
 
-RefPtr<NodeIterator> Document::createNodeIterator(Node* root, unsigned whatToShow, 
-    PassRefPtr<NodeFilter> filter, bool expandEntityReferences, ExceptionCode& ec)
+RefPtr<NodeIterator> Document::createNodeIterator(Node* root, unsigned long whatToShow, PassRefPtr<NodeFilter> filter, bool expandEntityReferences)
 {
-    if (!root) {
-        ec = NOT_SUPPORTED_ERR;
-        return nullptr;
-    }
     return NodeIterator::create(root, whatToShow, filter, expandEntityReferences);
 }
 
-RefPtr<TreeWalker> Document::createTreeWalker(Node* root, unsigned whatToShow, 
-    PassRefPtr<NodeFilter> filter, bool expandEntityReferences, ExceptionCode& ec)
+RefPtr<TreeWalker> Document::createTreeWalker(Node* root, unsigned long whatToShow, PassRefPtr<NodeFilter> filter, bool expandEntityReferences)
 {
-    if (!root) {
-        ec = NOT_SUPPORTED_ERR;
-        return nullptr;
-    }
     return TreeWalker::create(root, whatToShow, filter, expandEntityReferences);
 }
 
index e53bf3e..89d3d08 100644 (file)
@@ -536,11 +536,9 @@ public:
 
     WEBCORE_EXPORT Ref<Range> createRange();
 
-    RefPtr<NodeIterator> createNodeIterator(Node* root, unsigned whatToShow,
-        PassRefPtr<NodeFilter>, bool expandEntityReferences, ExceptionCode&);
+    RefPtr<NodeIterator> createNodeIterator(Node* root, unsigned long whatToShow = 0xFFFFFFFF, PassRefPtr<NodeFilter> = nullptr, bool expandEntityReferences = false);
 
-    RefPtr<TreeWalker> createTreeWalker(Node* root, unsigned whatToShow,
-        PassRefPtr<NodeFilter>, bool expandEntityReferences, ExceptionCode&);
+    RefPtr<TreeWalker> createTreeWalker(Node* root, unsigned long whatToShow = 0xFFFFFFFF, PassRefPtr<NodeFilter> = nullptr, bool expandEntityReferences = false);
 
     // Special support for editing
     Ref<CSSStyleDeclaration> createCSSStyleDeclaration();
index 2bb3208..62336da 100644 (file)
 
     // DOM Level 2 Tranversal and Range (DocumentTraversal interface)
 
-    [ObjCLegacyUnnamedParameters, RaisesException] NodeIterator createNodeIterator([Default=Undefined] optional Node root,
-                                                   [Default=Undefined] optional unsigned long whatToShow,
-                                                   [Default=Undefined] optional NodeFilter filter,
-                                                   [Default=Undefined] optional boolean expandEntityReferences);
-    [ObjCLegacyUnnamedParameters, RaisesException] TreeWalker createTreeWalker([Default=Undefined] optional Node root,
-                                               [Default=Undefined] optional unsigned long whatToShow,
-                                               [Default=Undefined] optional NodeFilter filter,
-                                               [Default=Undefined] optional boolean expandEntityReferences);
+    [ObjCLegacyUnnamedParameters] NodeIterator createNodeIterator(Node root,
+        optional unsigned long whatToShow,
+        optional NodeFilter? filter,
+        optional boolean expandEntityReferences);
+    [ObjCLegacyUnnamedParameters] TreeWalker createTreeWalker(Node root,
+        optional unsigned long whatToShow,
+        optional NodeFilter? filter,
+        optional boolean expandEntityReferences);
 
     // DOM Level 2 Abstract Views (DocumentView interface)
 
index 61ae28f..e8701ee 100644 (file)
@@ -76,7 +76,7 @@ bool NodeIterator::NodePointer::moveToPrevious(Node* root)
     return node;
 }
 
-NodeIterator::NodeIterator(PassRefPtr<Node> rootNode, unsigned whatToShow, PassRefPtr<NodeFilter> filter, bool expandEntityReferences)
+NodeIterator::NodeIterator(PassRefPtr<Node> rootNode, unsigned long whatToShow, PassRefPtr<NodeFilter> filter, bool expandEntityReferences)
     : NodeIteratorBase(rootNode, whatToShow, filter, expandEntityReferences)
     , m_referenceNode(root(), true)
     , m_detached(false)
index acf1cd6..5f89e62 100644 (file)
@@ -37,7 +37,7 @@ namespace WebCore {
 
     class NodeIterator : public ScriptWrappable, public RefCounted<NodeIterator>, public NodeIteratorBase {
     public:
-        static Ref<NodeIterator> create(PassRefPtr<Node> rootNode, unsigned whatToShow, PassRefPtr<NodeFilter> filter, bool expandEntityReferences)
+        static Ref<NodeIterator> create(PassRefPtr<Node> rootNode, unsigned long whatToShow, PassRefPtr<NodeFilter> filter, bool expandEntityReferences)
         {
             return adoptRef(*new NodeIterator(rootNode, whatToShow, filter, expandEntityReferences));
         }
@@ -59,7 +59,7 @@ namespace WebCore {
         PassRefPtr<Node> previousNode(ExceptionCode& ec) { return previousNode(execStateFromNode(mainThreadNormalWorld(), referenceNode()), ec); }
 
     private:
-        NodeIterator(PassRefPtr<Node>, unsigned whatToShow, PassRefPtr<NodeFilter>, bool expandEntityReferences);
+        NodeIterator(PassRefPtr<Node>, unsigned long whatToShow, PassRefPtr<NodeFilter>, bool expandEntityReferences);
 
         struct NodePointer {
             RefPtr<Node> node;
index a0ec377..1c22705 100644 (file)
@@ -30,7 +30,7 @@
 
 namespace WebCore {
 
-NodeIteratorBase::NodeIteratorBase(PassRefPtr<Node> rootNode, unsigned whatToShow, PassRefPtr<NodeFilter> nodeFilter, bool expandEntityReferences)
+NodeIteratorBase::NodeIteratorBase(PassRefPtr<Node> rootNode, unsigned long whatToShow, PassRefPtr<NodeFilter> nodeFilter, bool expandEntityReferences)
     : m_root(rootNode)
     , m_whatToShow(whatToShow)
     , m_filter(nodeFilter)
index e980a7d..15f09e2 100644 (file)
@@ -36,17 +36,17 @@ namespace WebCore {
     class NodeIteratorBase {
     public:
         Node* root() const { return m_root.get(); }
-        unsigned whatToShow() const { return m_whatToShow; }
+        unsigned long whatToShow() const { return m_whatToShow; }
         NodeFilter* filter() const { return m_filter.get(); }
         bool expandEntityReferences() const { return m_expandEntityReferences; }
 
     protected:
-        NodeIteratorBase(PassRefPtr<Node>, unsigned whatToShow, PassRefPtr<NodeFilter>, bool expandEntityReferences);
+        NodeIteratorBase(PassRefPtr<Node>, unsigned long whatToShow, PassRefPtr<NodeFilter>, bool expandEntityReferences);
         short acceptNode(JSC::ExecState*, Node*) const;
 
     private:
         RefPtr<Node> m_root;
-        unsigned m_whatToShow;
+        unsigned long m_whatToShow;
         RefPtr<NodeFilter> m_filter;
         bool m_expandEntityReferences;
     };
index 4cb2ebb..df034b1 100644 (file)
@@ -33,7 +33,7 @@
 
 namespace WebCore {
 
-TreeWalker::TreeWalker(PassRefPtr<Node> rootNode, unsigned whatToShow, PassRefPtr<NodeFilter> filter, bool expandEntityReferences)
+TreeWalker::TreeWalker(PassRefPtr<Node> rootNode, unsigned long whatToShow, PassRefPtr<NodeFilter> filter, bool expandEntityReferences)
     : NodeIteratorBase(rootNode, whatToShow, filter, expandEntityReferences)
     , m_current(root())
 {
index 5f42ced..c440c29 100644 (file)
@@ -37,7 +37,7 @@ namespace WebCore {
 
     class TreeWalker : public ScriptWrappable, public RefCounted<TreeWalker>, public NodeIteratorBase {
     public:
-        static Ref<TreeWalker> create(PassRefPtr<Node> rootNode, unsigned whatToShow, PassRefPtr<NodeFilter> filter, bool expandEntityReferences)
+        static Ref<TreeWalker> create(PassRefPtr<Node> rootNode, unsigned long whatToShow, PassRefPtr<NodeFilter> filter, bool expandEntityReferences)
         {
             return adoptRef(*new TreeWalker(rootNode, whatToShow, filter, expandEntityReferences));
         }                            
@@ -64,7 +64,7 @@ namespace WebCore {
         Node* nextNode() { return nextNode(execStateFromNode(mainThreadNormalWorld(), m_current.get())); }
 
     private:
-        TreeWalker(PassRefPtr<Node>, unsigned whatToShow, PassRefPtr<NodeFilter>, bool expandEntityReferences);
+        TreeWalker(PassRefPtr<Node>, unsigned long whatToShow, PassRefPtr<NodeFilter>, bool expandEntityReferences);
         
         Node* setCurrent(PassRefPtr<Node>);