Bug 1342101 - Move canonicalFunction.init before Scope::create in case create fails. r=jandem
authorShu-yu Guo <shu@rfrn.org>
Mon, 20 Mar 2017 18:34:10 -0400
changeset 501803 514a06ddb08ca52e552124f6d23d2f053c4f7e13
parent 501802 5ef67e15fd88a16025632e31ec1bb6519d2f4441
child 501804 c9812b88b9ed45fa80e0c45a8e80cf89c66d4c8f
push id50127
push userna-g@nostrum.com
push dateTue, 21 Mar 2017 00:09:45 +0000
reviewersjandem
bugs1342101
milestone55.0a1
Bug 1342101 - Move canonicalFunction.init before Scope::create in case create fails. r=jandem
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>