Part 1 of fix for bug 518669 (Remove a QI and AddRef/Release from nsNodeUtils::CloneAndAdopt). r=bz.

--HG--
extra : rebase_source : 27c23cc1871c5fe6152fc6dba14f4c1c7c54338a
This commit is contained in:
Peter Van der Beken 2009-09-28 22:33:29 +02:00
Родитель f2b726b34b
Коммит 6334f0eefc
2 изменённых файлов: 41 добавлений и 21 удалений

Просмотреть файл

@ -501,7 +501,7 @@ AdoptFunc(nsAttrHashKey::KeyType aKey, nsIDOMNode *aData, void* aUserArg)
data->mCx, data->mOldScope,
data->mNewScope,
data->mNodesWithProperties,
nsnull, getter_AddRefs(node));
getter_AddRefs(node));
if (NS_SUCCEEDED(rv) && clone) {
nsCOMPtr<nsIDOMAttr> dummy, attribute = do_QueryInterface(node, &rv);
@ -520,14 +520,14 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNode, PRBool aClone, PRBool aDeep,
JSContext *aCx, JSObject *aOldScope,
JSObject *aNewScope,
nsCOMArray<nsINode> &aNodesWithProperties,
nsINode *aParent, nsIDOMNode **aResult)
nsINode *aParent, nsINode **aResult)
{
NS_PRECONDITION((!aClone && aNewNodeInfoManager) || !aCx,
"If cloning or not getting a new nodeinfo we shouldn't "
"rewrap");
NS_PRECONDITION(!aCx || (aOldScope && aNewScope), "Must have scopes");
NS_PRECONDITION(!aParent || !aNode->IsNodeOfType(nsINode::eDOCUMENT),
"Can't insert document nodes into a parent");
NS_PRECONDITION(!aParent || aNode->IsNodeOfType(nsINode::eCONTENT),
"Can't insert document or attribute nodes into a parent");
*aResult = nsnull;
@ -578,10 +578,8 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNode, PRBool aClone, PRBool aDeep,
if (aParent) {
// If we're cloning we need to insert the cloned children into the cloned
// parent.
nsCOMPtr<nsIContent> cloneContent = do_QueryInterface(clone, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = aParent->AppendChildTo(cloneContent, PR_FALSE);
rv = aParent->AppendChildTo(static_cast<nsIContent*>(clone.get()),
PR_FALSE);
NS_ENSURE_SUCCESS(rv, rv);
}
else if (aDeep && clone->IsNodeOfType(nsINode::eDOCUMENT)) {
@ -685,17 +683,17 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNode, PRBool aClone, PRBool aDeep,
// aNode's children.
PRUint32 i, length = aNode->GetChildCount();
for (i = 0; i < length; ++i) {
nsCOMPtr<nsIDOMNode> child;
nsCOMPtr<nsINode> child;
rv = CloneAndAdopt(aNode->GetChildAt(i), aClone, PR_TRUE, nodeInfoManager,
aCx, aOldScope, aNewScope, aNodesWithProperties,
clone, getter_AddRefs(child));
NS_ENSURE_SUCCESS(rv, rv);
if (isDeepDocumentClone) {
nsCOMPtr<nsIContent> content = do_QueryInterface(child);
if (content) {
static_cast<nsDocument*>(clone.get())->
RegisterNamedItems(content);
}
NS_ASSERTION(child->IsNodeOfType(nsINode::eCONTENT),
"A clone of a child of a node is not nsIContent?");
nsIContent* content = static_cast<nsIContent*>(child.get());
static_cast<nsDocument*>(clone.get())->RegisterNamedItems(content);
}
}
}
@ -729,7 +727,9 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNode, PRBool aClone, PRBool aDeep,
NS_ENSURE_TRUE(ok, NS_ERROR_OUT_OF_MEMORY);
}
return clone ? CallQueryInterface(clone, aResult) : NS_OK;
clone.forget(aResult);
return NS_OK;
}

Просмотреть файл

@ -167,8 +167,7 @@ public:
nsIDOMNode **aResult)
{
return CloneAndAdopt(aNode, PR_TRUE, aDeep, aNewNodeInfoManager, nsnull,
nsnull, nsnull, aNodesWithProperties, nsnull,
aResult);
nsnull, nsnull, aNodesWithProperties, aResult);
}
/**
@ -199,7 +198,7 @@ public:
nsCOMPtr<nsIDOMNode> dummy;
return CloneAndAdopt(aNode, PR_FALSE, PR_TRUE, aNewNodeInfoManager, aCx,
aOldScope, aNewScope, aNodesWithProperties,
nsnull, getter_AddRefs(dummy));
getter_AddRefs(dummy));
}
/**
@ -312,8 +311,6 @@ private:
* descendants) with properties. If aClone is
* PR_TRUE every node will be followed by its
* clone.
* @param aParent If aClone is PR_TRUE the cloned node will be appended to
* aParent's children. May be null.
* @param aResult *aResult will contain the cloned node (if aClone is
* PR_TRUE).
*/
@ -322,7 +319,30 @@ private:
JSContext *aCx, JSObject *aOldScope,
JSObject *aNewScope,
nsCOMArray<nsINode> &aNodesWithProperties,
nsINode *aParent, nsIDOMNode **aResult);
nsIDOMNode **aResult)
{
nsCOMPtr<nsINode> clone;
nsresult rv = CloneAndAdopt(aNode, aClone, aDeep, aNewNodeInfoManager,
aCx, aOldScope, aNewScope, aNodesWithProperties,
nsnull, getter_AddRefs(clone));
NS_ENSURE_SUCCESS(rv, rv);
return clone ? CallQueryInterface(clone, aResult) : NS_OK;
}
/**
* See above for arguments that aren't described here.
*
* @param aParent If aClone is PR_TRUE the cloned node will be appended to
* aParent's children. May be null. If not null then aNode
* must be an nsIContent.
*/
static nsresult CloneAndAdopt(nsINode *aNode, PRBool aClone, PRBool aDeep,
nsNodeInfoManager *aNewNodeInfoManager,
JSContext *aCx, JSObject *aOldScope,
JSObject *aNewScope,
nsCOMArray<nsINode> &aNodesWithProperties,
nsINode *aParent, nsINode **aResult);
};
#endif // nsNodeUtils_h___