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 338234 72ea7eafc5e5887724e201ce4f0e71611026a1fa
parent 338233 85d98afa234a770651ef4bca1ad643c63bdcb107
child 338235 85f5fe4d8e3058ece7d8d17a9dda9abc1b77a101
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap
bugs1275945
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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);