Bug 1275945. Move the AutoJSContext use in nsNodeUtils::CloneAndAdopt to where it's really needed. r=mrbkap
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 26 May 2016 19:43:42 -0400
changeset 323710 72ea7eafc5e5887724e201ce4f0e71611026a1fa
parent 323709 85d98afa234a770651ef4bca1ad643c63bdcb107
child 323711 85f5fe4d8e3058ece7d8d17a9dda9abc1b77a101
push id9671
push userraliiev@mozilla.com
push dateMon, 06 Jun 2016 20:27:52 +0000
treeherdermozilla-aurora@cea65ca3d0bd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap
bugs1275945
milestone49.0a1
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.
dom/base/nsNodeUtils.cpp
--- 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);