From 9fe04dbfa29f5d35ee36db8d30a8ba16ed7228a0 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Mon, 8 Apr 2013 10:24:21 -0700 Subject: [PATCH] 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. --- content/base/src/nsDocument.cpp | 3 --- content/base/src/nsNodeUtils.cpp | 21 +++++++++++---------- content/base/src/nsNodeUtils.h | 26 +++++++++++--------------- 3 files changed, 22 insertions(+), 28 deletions(-) diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index cd3b1aa4beb8..0a0a95e858aa 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -6635,9 +6635,6 @@ nsIDocument::AdoptNode(nsINode& aAdoptedNode, ErrorResult& rv) nsCOMArray 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 diff --git a/content/base/src/nsNodeUtils.cpp b/content/base/src/nsNodeUtils.cpp index 9a506e1efbb8..b472c8438c04 100644 --- a/content/base/src/nsNodeUtils.cpp +++ b/content/base/src/nsNodeUtils.cpp @@ -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 &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 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 child; rv = CloneAndAdopt(cloneChild, aClone, aDeep, ownerNodeInfoManager, - aCx, aNewScope, aNodesWithProperties, cloneContent, + aReparentScope, aNodesWithProperties, cloneContent, getter_AddRefs(child)); NS_ENSURE_SUCCESS(rv, rv); } diff --git a/content/base/src/nsNodeUtils.h b/content/base/src/nsNodeUtils.h index 528125e85c5b..4143ece696c7 100644 --- a/content/base/src/nsNodeUtils.h +++ b/content/base/src/nsNodeUtils.h @@ -152,7 +152,7 @@ public: nsCOMArray &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 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 &aNodesWithProperties) { nsCOMPtr 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 &aNodesWithProperties, nsINode *aParent, nsINode **aResult); };