[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

simon.fraser at apple.com simon.fraser at apple.com
Wed Dec 22 12:26:20 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit b522d0eed2311df411b7b8c59702bd5a5ec34cdd
Author: simon.fraser at apple.com <simon.fraser at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Mon Aug 23 19:22:48 2010 +0000

    2010-08-23  Simon Fraser  <simon.fraser at apple.com>
    
            Reviewed by Alexey Proskuryakov.
    
            TreeWalker is not calling acceptNode function in filter object
            https://bugs.webkit.org/show_bug.cgi?id=35296
    
            We only accepted raw functions as the NodeFilter on TreeWalker. Fix this to
            look for an 'acceptNode' function on the filter object, and use that if present.
            Also throw an exception if the filter object does not have an acceptNode function.
    
            Test: fast/dom/TreeWalker/acceptNode-filter.html
    
            * bindings/js/JSNodeFilterCondition.cpp:
            (WebCore::JSNodeFilterCondition::acceptNode):
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@65824 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 6e08695..1e301e1 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,16 @@
+2010-08-23  Simon Fraser  <simon.fraser at apple.com>
+
+        Reviewed by Alexey Proskuryakov.
+
+        TreeWalker is not calling acceptNode function in filter object
+        https://bugs.webkit.org/show_bug.cgi?id=35296
+        
+        Testcase with various types of NodeFilters on a TreeWalker.
+
+        * fast/dom/TreeWalker/acceptNode-filter-expected.txt: Added.
+        * fast/dom/TreeWalker/acceptNode-filter.html: Added.
+        * fast/dom/TreeWalker/script-tests/acceptNode-filter.js: Added.
+
 2010-08-23  Sheriff Bot  <webkit.review.bot at gmail.com>
 
         Unreviewed, rolling out r65814.
diff --git a/LayoutTests/fast/dom/TreeWalker/acceptNode-filter-expected.txt b/LayoutTests/fast/dom/TreeWalker/acceptNode-filter-expected.txt
new file mode 100644
index 0000000..48abae4
--- /dev/null
+++ b/LayoutTests/fast/dom/TreeWalker/acceptNode-filter-expected.txt
@@ -0,0 +1,46 @@
+Test JS objects as NodeFilters.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Testing with raw function filter
+ filtering node A1
+PASS walker.firstChild(); walker.currentNode.id is 'A1'
+ filtering node B1
+ filtering node B2
+PASS walker.nextNode(); walker.currentNode.id is 'B2'
+
+Testing with object filter
+ filtering node A1
+PASS walker.firstChild(); walker.currentNode.id is 'A1'
+ filtering node B1
+ filtering node B2
+PASS walker.nextNode(); walker.currentNode.id is 'B2'
+
+Testing with null filter
+PASS walker.firstChild(); walker.currentNode.id is 'A1'
+PASS walker.nextNode(); walker.currentNode.id is 'B1'
+
+Testing with undefined filter
+PASS walker.firstChild(); walker.currentNode.id is 'A1'
+PASS walker.nextNode(); walker.currentNode.id is 'B1'
+
+Testing with object lacking acceptNode property
+PASS walker.firstChild(); threw exception TypeError: NodeFilter object does not have an acceptNode function.
+PASS walker.currentNode.id; is 'root'
+PASS walker.nextNode(); threw exception TypeError: NodeFilter object does not have an acceptNode function.
+PASS walker.currentNode.id; is 'root'
+
+Testing with object with non-function acceptNode property
+PASS walker.firstChild(); threw exception TypeError: NodeFilter object does not have an acceptNode function.
+PASS walker.currentNode.id; is 'root'
+PASS walker.nextNode(); threw exception TypeError: NodeFilter object does not have an acceptNode function.
+PASS walker.currentNode.id; is 'root'
+
+Testing with function having acceptNode function
+PASS walker.firstChild(); walker.currentNode.id is 'A1'
+PASS walker.nextNode(); walker.currentNode.id is 'B1'
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/dom/TreeWalker/acceptNode-filter.html b/LayoutTests/fast/dom/TreeWalker/acceptNode-filter.html
new file mode 100644
index 0000000..a6398f9
--- /dev/null
+++ b/LayoutTests/fast/dom/TreeWalker/acceptNode-filter.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+<head>
+<link rel="stylesheet" href="../../js/resources/js-test-style.css">
+<script src="../../js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="script-tests/acceptNode-filter.js"></script>
+<script src="../../js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/dom/TreeWalker/script-tests/acceptNode-filter.js b/LayoutTests/fast/dom/TreeWalker/script-tests/acceptNode-filter.js
new file mode 100644
index 0000000..cac24a2
--- /dev/null
+++ b/LayoutTests/fast/dom/TreeWalker/script-tests/acceptNode-filter.js
@@ -0,0 +1,70 @@
+description('Test JS objects as NodeFilters.');
+
+var walker;
+var testElement = document.createElement("div");
+testElement.id = 'root';
+testElement.innerHTML='<div id="A1"><div id="B1"></div><div id="B2"></div></div>';
+
+function filter(node)
+{
+    debug(" filtering node " + node.id);
+    if (node.id == "B1")
+        return NodeFilter.FILTER_SKIP;
+    return NodeFilter.FILTER_ACCEPT;
+}
+
+debug("Testing with raw function filter");
+walker = document.createTreeWalker(testElement, NodeFilter.SHOW_ELEMENT, filter, false);
+shouldBe("walker.firstChild(); walker.currentNode.id", "'A1'");
+shouldBe("walker.nextNode(); walker.currentNode.id", "'B2'");
+
+debug("<br>Testing with object filter");
+walker = document.createTreeWalker(testElement, NodeFilter.SHOW_ELEMENT, {
+    acceptNode : function(node) {
+      debug(" filtering node " + node.id);
+      if (node.id == "B1")
+          return NodeFilter.FILTER_SKIP;
+      return NodeFilter.FILTER_ACCEPT;
+    }
+  }, false);
+
+shouldBe("walker.firstChild(); walker.currentNode.id", "'A1'");
+shouldBe("walker.nextNode(); walker.currentNode.id", "'B2'");
+
+debug("<br>Testing with null filter");
+walker = document.createTreeWalker(testElement, NodeFilter.SHOW_ELEMENT, null, false);
+
+shouldBe("walker.firstChild(); walker.currentNode.id", "'A1'");
+shouldBe("walker.nextNode(); walker.currentNode.id", "'B1'");
+
+debug("<br>Testing with undefined filter");
+walker = document.createTreeWalker(testElement, NodeFilter.SHOW_ELEMENT, undefined, false);
+
+shouldBe("walker.firstChild(); walker.currentNode.id", "'A1'");
+shouldBe("walker.nextNode(); walker.currentNode.id", "'B1'");
+
+debug("<br>Testing with object lacking acceptNode property");
+walker = document.createTreeWalker(testElement, NodeFilter.SHOW_ELEMENT, {}, false);
+
+shouldThrow("walker.firstChild();");
+shouldBe("walker.currentNode.id;", "'root'");
+shouldThrow("walker.nextNode();");
+shouldBe("walker.currentNode.id;", "'root'");
+
+debug("<br>Testing with object with non-function acceptNode property");
+walker = document.createTreeWalker(testElement, NodeFilter.SHOW_ELEMENT, { acceptNode: "foo" }, false);
+
+shouldThrow("walker.firstChild();");
+shouldBe("walker.currentNode.id;", "'root'");
+shouldThrow("walker.nextNode();");
+shouldBe("walker.currentNode.id;", "'root'");
+
+debug("<br>Testing with function having acceptNode function");
+var filter = function() { return NodeFilter.FILTER_ACCEPT; };
+filter.acceptNode = function(node) { return NodeFilter.FILTER_SKIP; };
+walker = document.createTreeWalker(testElement, NodeFilter.SHOW_ELEMENT, filter, false);
+
+shouldBe("walker.firstChild(); walker.currentNode.id", "'A1'");
+shouldBe("walker.nextNode(); walker.currentNode.id", "'B1'");
+
+var successfullyParsed = true;
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 18b0bc1..87cb914 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,19 @@
+2010-08-23  Simon Fraser  <simon.fraser at apple.com>
+
+        Reviewed by Alexey Proskuryakov.
+
+        TreeWalker is not calling acceptNode function in filter object
+        https://bugs.webkit.org/show_bug.cgi?id=35296
+        
+        We only accepted raw functions as the NodeFilter on TreeWalker. Fix this to
+        look for an 'acceptNode' function on the filter object, and use that if present.
+        Also throw an exception if the filter object does not have an acceptNode function.
+
+        Test: fast/dom/TreeWalker/acceptNode-filter.html
+
+        * bindings/js/JSNodeFilterCondition.cpp:
+        (WebCore::JSNodeFilterCondition::acceptNode):
+
 2010-08-23  Sheriff Bot  <webkit.review.bot at gmail.com>
 
         Unreviewed, rolling out r65814.
diff --git a/WebCore/bindings/js/JSNodeFilterCondition.cpp b/WebCore/bindings/js/JSNodeFilterCondition.cpp
index b723286..9e0cdc9 100644
--- a/WebCore/bindings/js/JSNodeFilterCondition.cpp
+++ b/WebCore/bindings/js/JSNodeFilterCondition.cpp
@@ -23,6 +23,7 @@
 #include "JSNode.h"
 #include "JSNodeFilter.h"
 #include "NodeFilter.h"
+#include <runtime/Error.h>
 #include <runtime/JSLock.h>
 
 namespace WebCore {
@@ -45,9 +46,7 @@ short JSNodeFilterCondition::acceptNode(JSC::ExecState* exec, Node* filterNode)
 {
     JSLock lock(SilenceAssertionsOnly);
 
-    CallData callData;
-    CallType callType = getCallData(m_filter, callData);
-    if (callType == CallTypeNone)
+    if (!m_filter.isObject())
         return NodeFilter::FILTER_ACCEPT;
 
    // The exec argument here should only be null if this was called from a
@@ -59,6 +58,18 @@ short JSNodeFilterCondition::acceptNode(JSC::ExecState* exec, Node* filterNode)
     if (!exec)
         return NodeFilter::FILTER_REJECT;
 
+    JSValue function = m_filter;
+    CallData callData;
+    CallType callType = getCallData(function, callData);
+    if (callType == CallTypeNone) {
+        JSValue function = m_filter.get(exec, Identifier(exec, "acceptNode"));
+        callType = getCallData(function, callData);
+        if (callType == CallTypeNone) {
+            throwError(exec, createTypeError(exec, "NodeFilter object does not have an acceptNode function"));
+            return NodeFilter::FILTER_REJECT;
+        }
+    }
+
     MarkedArgumentBuffer args;
     // FIXME: The node should have the prototype chain that came from its document, not
     // whatever prototype chain might be on the window this filter came from. Bug 27662
@@ -66,7 +77,7 @@ short JSNodeFilterCondition::acceptNode(JSC::ExecState* exec, Node* filterNode)
     if (exec->hadException())
         return NodeFilter::FILTER_REJECT;
 
-    JSValue result = JSC::call(exec, m_filter, callType, callData, m_filter, args);
+    JSValue result = JSC::call(exec, function, callType, callData, m_filter, args);
     if (exec->hadException())
         return NodeFilter::FILTER_REJECT;
 

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list