Bug 839467 - Remove aCx parameter to CloneAndAdopt. r=mrbkap

Right now it has to be kept in sync with the nullness of aNewScope. Let's just
rely on the cx stack here and kill the param.
This commit is contained in:
Bobby Holley 2013-04-08 10:24:21 -07:00
parent c00d101063
commit 9fe04dbfa2
3 changed files with 22 additions and 28 deletions

View File

@ -6635,9 +6635,6 @@ nsIDocument::AdoptNode(nsINode& aAdoptedNode, ErrorResult& rv)
nsCOMArray<nsINode> nodesWithProperties;
rv = nsNodeUtils::Adopt(adoptedNode, sameDocument ? nullptr : mNodeInfoManager,
// The nsNodeUtils API requires that cx be non-null iff
// newscope is non-null.
newScope ? (JSContext*) cx : nullptr,
newScope, nodesWithProperties);
if (rv.Failed()) {
// Disconnect all nodes from their parents, since some have the old document

View File

@ -34,6 +34,7 @@
#include "mozilla/dom/HTMLTemplateElement.h"
using namespace mozilla::dom;
using mozilla::AutoJSContext;
// This macro expects the ownerDocument of content_ to be in scope as
// |nsIDocument* doc|
@ -383,14 +384,13 @@ nsNodeUtils::CloneNodeImpl(nsINode *aNode, bool aDeep,
nsresult
nsNodeUtils::CloneAndAdopt(nsINode *aNode, bool aClone, bool aDeep,
nsNodeInfoManager *aNewNodeInfoManager,
JSContext *aCx, JSObject *aNewScope,
JSObject *aReparentScope,
nsCOMArray<nsINode> &aNodesWithProperties,
nsINode *aParent, nsINode **aResult)
{
NS_PRECONDITION((!aClone && aNewNodeInfoManager) || !aCx,
NS_PRECONDITION((!aClone && aNewNodeInfoManager) || !aReparentScope,
"If cloning or not getting a new nodeinfo we shouldn't "
"rewrap");
NS_PRECONDITION(!aCx || aNewScope, "Must have new scope");
NS_PRECONDITION(!aParent || aNode->IsNodeOfType(nsINode::eCONTENT),
"Can't insert document or attribute nodes into a parent");
@ -400,12 +400,13 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNode, bool aClone, bool aDeep,
// if aDeep is true, deal with aNode's children (and recurse into their
// attributes and children).
AutoJSContext cx;
nsresult rv;
JSObject *wrapper;
bool isDOMBinding;
if (aCx && (wrapper = aNode->GetWrapper()) &&
if (aReparentScope && (wrapper = aNode->GetWrapper()) &&
!(isDOMBinding = IsDOMObject(wrapper))) {
rv = xpc_MorphSlimWrapper(aCx, aNode);
rv = xpc_MorphSlimWrapper(cx, aNode);
NS_ENSURE_SUCCESS(rv, rv);
}
@ -528,13 +529,13 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNode, bool aClone, bool aDeep,
elem->RecompileScriptEventListeners();
}
if (aCx && wrapper) {
if (aReparentScope && wrapper) {
if (isDOMBinding) {
rv = ReparentWrapper(aCx, wrapper);
rv = ReparentWrapper(cx, wrapper);
} else {
nsIXPConnect *xpc = nsContentUtils::XPConnect();
if (xpc) {
rv = xpc->ReparentWrappedNativeIfFound(aCx, wrapper, aNewScope, aNode);
rv = xpc->ReparentWrappedNativeIfFound(cx, wrapper, aReparentScope, aNode);
}
}
if (NS_FAILED(rv)) {
@ -557,7 +558,7 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNode, bool aClone, bool aDeep,
cloneChild = cloneChild->GetNextSibling()) {
nsCOMPtr<nsINode> child;
rv = CloneAndAdopt(cloneChild, aClone, true, nodeInfoManager,
aCx, aNewScope, aNodesWithProperties, clone,
aReparentScope, aNodesWithProperties, clone,
getter_AddRefs(child));
NS_ENSURE_SUCCESS(rv, rv);
}
@ -580,7 +581,7 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNode, bool aClone, bool aDeep,
cloneChild = cloneChild->GetNextSibling()) {
nsCOMPtr<nsINode> child;
rv = CloneAndAdopt(cloneChild, aClone, aDeep, ownerNodeInfoManager,
aCx, aNewScope, aNodesWithProperties, cloneContent,
aReparentScope, aNodesWithProperties, cloneContent,
getter_AddRefs(child));
NS_ENSURE_SUCCESS(rv, rv);
}

View File

@ -152,7 +152,7 @@ public:
nsCOMArray<nsINode> &aNodesWithProperties,
nsINode **aResult)
{
return CloneAndAdopt(aNode, true, aDeep, aNewNodeInfoManager, nullptr,
return CloneAndAdopt(aNode, true, aDeep, aNewNodeInfoManager,
nullptr, aNodesWithProperties, nullptr, aResult);
}
@ -162,14 +162,14 @@ public:
static nsresult Clone(nsINode *aNode, bool aDeep, nsINode **aResult)
{
nsCOMArray<nsINode> dummyNodeWithProperties;
return CloneAndAdopt(aNode, true, aDeep, nullptr, nullptr, nullptr,
return CloneAndAdopt(aNode, true, aDeep, nullptr, nullptr,
dummyNodeWithProperties, aNode->GetParent(), aResult);
}
/**
* Walks aNode, its attributes and descendant nodes. If aNewNodeInfoManager is
* not null, it is used to create new nodeinfos for the nodes. Also reparents
* the XPConnect wrappers for the nodes in aNewScope if aCx is not null.
* the XPConnect wrappers for the nodes into aReparentScope if non-null.
* aNodesWithProperties will be filled with all the nodes that have
* properties.
*
@ -178,20 +178,18 @@ public:
* nodeinfos for aNode and its attributes and
* descendants. May be null if the nodeinfos
* shouldn't be changed.
* @param aCx Context to use for reparenting the wrappers, or null if no
* reparenting should be done. Must be null if aNewNodeInfoManager
* is null.
* @param aNewScope New scope for the wrappers. May be null if aCx is null.
* @param aReparentScope New scope for the wrappers, or null if no reparenting
* should be done.
* @param aNodesWithProperties All nodes (from amongst aNode and its
* descendants) with properties.
*/
static nsresult Adopt(nsINode *aNode, nsNodeInfoManager *aNewNodeInfoManager,
JSContext *aCx, JSObject *aNewScope,
JSObject *aReparentScope,
nsCOMArray<nsINode> &aNodesWithProperties)
{
nsCOMPtr<nsINode> node;
nsresult rv = CloneAndAdopt(aNode, false, true, aNewNodeInfoManager,
aCx, aNewScope, aNodesWithProperties,
aReparentScope, aNodesWithProperties,
nullptr, getter_AddRefs(node));
nsMutationGuard::DidMutate();
@ -269,7 +267,7 @@ private:
* Walks aNode, its attributes and, if aDeep is true, its descendant nodes.
* If aClone is true the nodes will be cloned. If aNewNodeInfoManager is
* not null, it is used to create new nodeinfos for the nodes. Also reparents
* the XPConnect wrappers for the nodes in aNewScope if aCx is not null.
* the XPConnect wrappers for the nodes into aReparentScope if non-null.
* aNodesWithProperties will be filled with all the nodes that have
* properties.
*
@ -282,10 +280,8 @@ private:
* nodeinfos for aNode and its attributes and
* descendants. May be null if the nodeinfos
* shouldn't be changed.
* @param aCx Context to use for reparenting the wrappers, or null if no
* reparenting should be done. Must be null if aClone is true or
* if aNewNodeInfoManager is null.
* @param aNewScope New scope for the wrappers. May be null if aCx is null.
* @param aReparentScope Scope into which wrappers should be reparented, or
* null if no reparenting should be done.
* @param aNodesWithProperties All nodes (from amongst aNode and its
* descendants) with properties. If aClone is
* true every node will be followed by its
@ -298,7 +294,7 @@ private:
*/
static nsresult CloneAndAdopt(nsINode *aNode, bool aClone, bool aDeep,
nsNodeInfoManager *aNewNodeInfoManager,
JSContext *aCx, JSObject *aNewScope,
JSObject *aReparentScope,
nsCOMArray<nsINode> &aNodesWithProperties,
nsINode *aParent, nsINode **aResult);
};