Bug 1342101 - Move canonicalFunction.init before Scope::create in case create fails. r=jandem

This commit is contained in:
Shu-yu Guo 2017-03-20 18:34:10 -04:00
Родитель 6ae1479eb9
Коммит 48b67cbb5f
1 изменённых файлов: 4 добавлений и 5 удалений

Просмотреть файл

@ -630,6 +630,7 @@ FunctionScope::create(JSContext* cx, Handle<Data*> data,
return nullptr;
copy->hasParameterExprs = hasParameterExprs;
copy->canonicalFunction.init(fun);
// An environment may be needed regardless of existence of any closed over
// bindings:
@ -647,8 +648,6 @@ FunctionScope::create(JSContext* cx, Handle<Data*> data,
if (!scope)
return nullptr;
copy->canonicalFunction.init(fun);
funScope = &scope->as<FunctionScope>();
funScope->initData(Move(copy.get()));
}
@ -701,12 +700,12 @@ FunctionScope::clone(JSContext* cx, Handle<FunctionScope*> scope, HandleFunction
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()));
}