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 348483 514a06ddb08ca52e552124f6d23d2f053c4f7e13
parent 348482 5ef67e15fd88a16025632e31ec1bb6519d2f4441
child 348484 c9812b88b9ed45fa80e0c45a8e80cf89c66d4c8f
push id88244
push userryanvm@gmail.com
push dateMon, 20 Mar 2017 22:35:09 +0000
treeherdermozilla-inbound@514a06ddb08c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1342101
milestone55.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 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>