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

ojan at chromium.org ojan at chromium.org
Wed Dec 22 12:51:19 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit d079f3ef433d59a3a867a09c10a5c2f0f173491a
Author: ojan at chromium.org <ojan at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Aug 31 18:22:24 2010 +0000

    2010-08-31  Ojan Vafai  <ojan at chromium.org>
    
            Reviewed by Tony Chang.
    
            deduplicate code from Node::checkReplaceChild and Node::checkAddChild
            https://bugs.webkit.org/show_bug.cgi?id=44962
    
            Remove duplicate code in preparation for fixing https://bugs.webkit.org/show_bug.cgi?id=19524
            No new tests since there is no change in functionality.
    
            * dom/Node.cpp:
            (WebCore::isChildTypeAllowed):
            (WebCore::Node::canReplaceChild):
            (WebCore::checkAcceptChild):
            (WebCore::transferOwnerDocument):
            (WebCore::Node::checkReplaceChild):
            (WebCore::Node::checkAddChild):
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@66511 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index ad066db..5b21543 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,21 @@
+2010-08-31  Ojan Vafai  <ojan at chromium.org>
+
+        Reviewed by Tony Chang.
+
+        deduplicate code from Node::checkReplaceChild and Node::checkAddChild
+        https://bugs.webkit.org/show_bug.cgi?id=44962
+
+        Remove duplicate code in preparation for fixing https://bugs.webkit.org/show_bug.cgi?id=19524
+        No new tests since there is no change in functionality.
+
+        * dom/Node.cpp:
+        (WebCore::isChildTypeAllowed):
+        (WebCore::Node::canReplaceChild):
+        (WebCore::checkAcceptChild):
+        (WebCore::transferOwnerDocument):
+        (WebCore::Node::checkReplaceChild):
+        (WebCore::Node::checkAddChild):
+
 2010-08-30  Zhenyao Mo  <zmo at google.com>
 
         Reviewed by Kenneth Russell.
diff --git a/WebCore/dom/Node.cpp b/WebCore/dom/Node.cpp
index bf24b58..f6554de 100644
--- a/WebCore/dom/Node.cpp
+++ b/WebCore/dom/Node.cpp
@@ -1071,21 +1071,27 @@ void Node::checkSetPrefix(const AtomicString& prefix, ExceptionCode& ec)
     // Attribute-specific checks are in Attr::setPrefix().
 }
 
-bool Node::canReplaceChild(Node* newChild, Node*)
+static bool isChildTypeAllowed(Node* newParent, Node* child)
 {
-    if (newChild->nodeType() != DOCUMENT_FRAGMENT_NODE) {
-        if (!childTypeAllowed(newChild->nodeType()))
+    if (child->nodeType() != Node::DOCUMENT_FRAGMENT_NODE) {
+        if (!newParent->childTypeAllowed(child->nodeType()))
             return false;
-    } else {
-        for (Node *n = newChild->firstChild(); n; n = n->nextSibling()) {
-            if (!childTypeAllowed(n->nodeType())) 
-                return false;
-        }
     }
+    
+    for (Node *n = child->firstChild(); n; n = n->nextSibling()) {
+        if (!newParent->childTypeAllowed(n->nodeType()))
+            return false;
+    }
+
     return true;
 }
 
-void Node::checkReplaceChild(Node* newChild, Node* oldChild, ExceptionCode& ec)
+bool Node::canReplaceChild(Node* newChild, Node*)
+{
+    return isChildTypeAllowed(this, newChild);
+}
+
+static void checkAcceptChild(Node* newParent, Node* newChild, ExceptionCode& ec)
 {
     // Perform error checking as required by spec for adding a new child. Used by replaceChild().
     
@@ -1096,113 +1102,69 @@ void Node::checkReplaceChild(Node* newChild, Node* oldChild, ExceptionCode& ec)
     }
     
     // NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly
-    if (isReadOnlyNode()) {
+    if (newParent->isReadOnlyNode()) {
         ec = NO_MODIFICATION_ALLOWED_ERR;
         return;
     }
     
-    bool shouldAdoptChild = false;
-    
     // WRONG_DOCUMENT_ERR: Raised if newChild was created from a different document than the one that
     // created this node.
     // We assume that if newChild is a DocumentFragment, all children are created from the same document
     // as the fragment itself (otherwise they could not have been added as children)
-    if (newChild->document() != document()) {
+    if (newChild->document() != newParent->document() && newChild->inDocument()) {
         // but if the child is not in a document yet then loosen the
         // restriction, so that e.g. creating an element with the Option()
         // constructor and then adding it to a different document works,
         // as it does in Mozilla and Mac IE.
-        if (!newChild->inDocument()) {
-            shouldAdoptChild = true;
-        } else {
-            ec = WRONG_DOCUMENT_ERR;
-            return;
-        }
+        ec = WRONG_DOCUMENT_ERR;
+        return;
     }
     
     // HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not allow children of the type of the
     // newChild node, or if the node to append is one of this node's ancestors.
-    
+
     // check for ancestor/same node
-    if (newChild == this || isDescendantOf(newChild)) {
+    if (newChild == newParent || newParent->isDescendantOf(newChild)) {
         ec = HIERARCHY_REQUEST_ERR;
         return;
     }
-    
-    if (!canReplaceChild(newChild, oldChild)) {
-        ec = HIERARCHY_REQUEST_ERR;
-        return;
-    }
-       
-    // change the document pointer of newChild and all of its children to be the new document
-    if (shouldAdoptChild)
-        for (Node* node = newChild; node; node = node->traverseNextNode(newChild))
-            node->setDocument(document());
 }
 
-void Node::checkAddChild(Node *newChild, ExceptionCode& ec)
+static void transferOwnerDocument(Document* newDocument, Node* root)
 {
-    // Perform error checking as required by spec for adding a new child. Used by appendChild() and insertBefore().
-
-    // Not mentioned in spec: throw NOT_FOUND_ERR if newChild is null
-    if (!newChild) {
-        ec = NOT_FOUND_ERR;
-        return;
+    // FIXME: To match Gecko, we should do this for nodes that are already in the document as well.
+    if (root->document() != newDocument && !root->inDocument()) {
+        for (Node* node = root; node; node = node->traverseNextNode(root))
+            node->setDocument(newDocument);
     }
+}
 
-    // NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly
-    if (isReadOnlyNode()) {
-        ec = NO_MODIFICATION_ALLOWED_ERR;
+void Node::checkReplaceChild(Node* newChild, Node* oldChild, ExceptionCode& ec)
+{
+    checkAcceptChild(this, newChild, ec);
+    if (ec)
         return;
-    }
-
-    bool shouldAdoptChild = false;
 
-    // WRONG_DOCUMENT_ERR: Raised if newChild was created from a different document than the one that
-    // created this node.
-    // We assume that if newChild is a DocumentFragment, all children are created from the same document
-    // as the fragment itself (otherwise they could not have been added as children)
-    if (newChild->document() != document()) {
-        // but if the child is not in a document yet then loosen the
-        // restriction, so that e.g. creating an element with the Option()
-        // constructor and then adding it to a different document works,
-        // as it does in Mozilla and Mac IE.
-        if (!newChild->inDocument()) {
-            shouldAdoptChild = true;
-        } else {
-            ec = WRONG_DOCUMENT_ERR;
-            return;
-        }
+    if (!canReplaceChild(newChild, oldChild)) {
+        ec = HIERARCHY_REQUEST_ERR;
+        return;
     }
 
-    // HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not allow children of the type of the
-    // newChild node, or if the node to append is one of this node's ancestors.
+    transferOwnerDocument(document(), newChild);
+}
 
-    // check for ancestor/same node
-    if (newChild == this || isDescendantOf(newChild)) {
-        ec = HIERARCHY_REQUEST_ERR;
+void Node::checkAddChild(Node *newChild, ExceptionCode& ec)
+{
+    checkAcceptChild(this, newChild, ec);
+    if (ec)
         return;
-    }
     
-    if (newChild->nodeType() != DOCUMENT_FRAGMENT_NODE) {
-        if (!childTypeAllowed(newChild->nodeType())) {
-            ec = HIERARCHY_REQUEST_ERR;
-            return;
-        }
-    }
-    else {
-        for (Node *n = newChild->firstChild(); n; n = n->nextSibling()) {
-            if (!childTypeAllowed(n->nodeType())) {
-                ec = HIERARCHY_REQUEST_ERR;
-                return;
-            }
-        }
+    if (!isChildTypeAllowed(this, newChild)) {
+        ec = HIERARCHY_REQUEST_ERR;
+        return;
     }
-    
-    // change the document pointer of newChild and all of its children to be the new document
-    if (shouldAdoptChild)
-        for (Node* node = newChild; node; node = node->traverseNextNode(newChild))
-            node->setDocument(document());
+
+    transferOwnerDocument(document(), newChild);
 }
 
 bool Node::isDescendantOf(const Node *other) const

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list