Bug 1342101 - Move canonicalFunction.init before Scope::create in case create fails. r=jandem, a=jcristau
authorShu-yu Guo <shu@rfrn.org>
Mon, 20 Mar 2017 18:34:10 -0400
changeset 355445 16772200ad6ff3f36592582ff5801d6505bdb400
parent 355444 512604631b2328794a05a711592814d1f452f45e
child 355446 c744e9d57250fdae8e8c84c88a4f7c6cab5a6f4a
push id6975
push userryanvm@gmail.com
push dateFri, 24 Mar 2017 21:24:58 +0000
treeherdermozilla-esr52@62df7046e959 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem, jcristau
bugs1342101
milestone52.0.2
Bug 1342101 - Move canonicalFunction.init before Scope::create in case create fails. r=jandem, a=jcristau
js/src/vm/Scope.cpp
--- a/js/src/vm/Scope.cpp
+++ b/js/src/vm/Scope.cpp
@@ -596,16 +596,17 @@ FunctionScope::create(ExclusiveContext* 
         // The data that's passed in may be from the frontend and LifoAlloc'd.
         // Copy it now that we're creating a permanent VM scope.
         RootedShape envShape(cx);
         Rooted<UniquePtr<Data>> copy(cx, copyData(cx, data, hasParameterExprs, &envShape));
         if (!copy)
             return nullptr;
 
         copy->hasParameterExprs = hasParameterExprs;
+        copy->canonicalFunction.init(fun);
 
         // An environment may be needed regardless of existence of any closed over
         // bindings:
         //   - Extensible scopes (i.e., due to direct eval)
         //   - Needing a home object
         //   - Being a derived class constructor
         //   - Being a generator
         if (!envShape && needsEnvironment) {
@@ -613,18 +614,16 @@ FunctionScope::create(ExclusiveContext* 
             if (!envShape)
                 return nullptr;
         }
 
         Scope* scope = Scope::create(cx, ScopeKind::Function, enclosing, envShape);
         if (!scope)
             return nullptr;
 
-        copy->canonicalFunction.init(fun);
-
         funScope = &scope->as<FunctionScope>();
         funScope->initData(Move(copy.get()));
     }
 
     return funScope;
 }
 
 JSScript*
@@ -659,22 +658,22 @@ FunctionScope::clone(JSContext* cx, Hand
                 return nullptr;
         }
 
         Rooted<Data*> dataOriginal(cx, &scope->as<FunctionScope>().data());
         Rooted<UniquePtr<Data>> dataClone(cx, CopyScopeData<FunctionScope>(cx, dataOriginal));
         if (!dataClone)
             return nullptr;
 
-        Scope* scopeClone= Scope::create(cx, scope->kind(), enclosing, envShape);
+        dataClone->canonicalFunction.init(fun);
+
+        Scope* scopeClone = Scope::create(cx, scope->kind(), enclosing, envShape);
         if (!scopeClone)
             return nullptr;
 
-        dataClone->canonicalFunction.init(fun);
-
         funScopeClone = &scopeClone->as<FunctionScope>();
         funScopeClone->initData(Move(dataClone.get()));
     }
 
     return funScopeClone;
 }
 
 template <XDRMode mode>