Bug 1342101 - Move canonicalFunction.init before Scope::create in case create fails. r=jandem a=gchang
authorShu-yu Guo <shu@rfrn.org>
Mon, 20 Mar 2017 18:34:10 -0400
changeset 395267 44cf8184d1a69aba9af5d40fd453277fd4b6b0e5
parent 395266 154ed63f43f6c693d55c397ed757380f7404573b
child 395268 f264eb5dd1eb960acdd908255ec34648466df010
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem, gchang
bugs1342101
milestone54.0a2
Bug 1342101 - Move canonicalFunction.init before Scope::create in case create fails. r=jandem a=gchang
js/src/vm/Scope.cpp
--- a/js/src/vm/Scope.cpp
+++ b/js/src/vm/Scope.cpp
@@ -625,16 +625,17 @@ FunctionScope::create(JSContext* cx, Han
         // 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) {
@@ -642,18 +643,16 @@ FunctionScope::create(JSContext* cx, Han
             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*
@@ -696,22 +695,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>