Bug 1275945. Move the AutoJSContext use in nsNodeUtils::CloneAndAdopt to where it's really needed. r=mrbkap
This prevents us from pushing stuff on the JSContext stack unnecessarily when
we're just cloning, not adopting. It's OK that we're doing it in a narrow scope
that doesn't include our recursion into children, because in practice when
aReparentScope is non-null we came from nsIDocument::AdoptNode which already
does AutoJSContext. So we're not going to continuously push/pop the JSContext
stack in that situation, since something already got pushed on it.
--- a/dom/base/nsNodeUtils.cpp
+++ b/dom/base/nsNodeUtils.cpp
@@ -420,17 +420,16 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNod
*aResult = nullptr;
// First deal with aNode and walk its attributes (and their children). Then,
// if aDeep is true, deal with aNode's children (and recurse into their
// attributes and children).
nsAutoScriptBlocker scriptBlocker;
- AutoJSContext cx;
nsresult rv;
nsNodeInfoManager *nodeInfoManager = aNewNodeInfoManager;
// aNode.
NodeInfo *nodeInfo = aNode->mNodeInfo;
RefPtr<NodeInfo> newNodeInfo;
if (nodeInfoManager) {
@@ -559,16 +558,17 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNod
newDoc->SetMayHaveAnimationObservers();
}
if (elem) {
elem->RecompileScriptEventListeners();
}
if (aReparentScope) {
+ AutoJSContext cx;
JS::Rooted<JSObject*> wrapper(cx);
if ((wrapper = aNode->GetWrapper())) {
MOZ_ASSERT(IsDOMObject(wrapper));
JSAutoCompartment ac(cx, wrapper);
rv = ReparentWrapper(cx, wrapper);
if (NS_FAILED(rv)) {
aNode->mNodeInfo.swap(nodeInfo);