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