Bug 958172 - Only set the environment while cloning a JSFunction. r=jorendorff

This commit is contained in:
Nicolas B. Pierron 2014-02-20 07:09:34 -08:00
parent bf34cdd211
commit 7dee273c57
2 changed files with 10 additions and 6 deletions

View File

@ -1247,17 +1247,13 @@ Parser<ParseHandler>::newFunction(GenericParseContext *pc, HandleAtom atom,
while (pc->parent)
pc = pc->parent;
RootedObject parent(context);
if (!pc->sc->isFunctionBox() && options().compileAndGo)
parent = pc->sc->asGlobalSharedContext()->scopeChain();
RootedFunction fun(context);
JSFunction::Flags flags = (kind == Expression)
? JSFunction::INTERPRETED_LAMBDA
: (kind == Arrow)
? JSFunction::INTERPRETED_LAMBDA_ARROW
: JSFunction::INTERPRETED;
fun = NewFunctionWithProto(context, NullPtr(), nullptr, 0, flags, parent, atom, proto,
fun = NewFunctionWithProto(context, NullPtr(), nullptr, 0, flags, NullPtr(), atom, proto,
JSFunction::FinalizeKind, MaybeSingletonObject);
if (!fun)
return nullptr;

View File

@ -409,6 +409,13 @@ js::XDRInterpretedFunction(XDRState<mode> *xdr, HandleObject enclosingScope, Han
atom = fun->displayAtom();
flagsword = (fun->nargs() << 16) | fun->flags();
// The environment of any function which is not reused will always be
// null, it is later defined when a function is cloned or reused to
// mirror the scope chain.
JS_ASSERT_IF(fun->hasSingletonType() &&
!((lazy && lazy->hasBeenCloned()) || (script && script->hasBeenCloned())),
fun->environment() == nullptr);
}
if (!xdr->codeUint32(&firstword))
@ -421,8 +428,9 @@ js::XDRInterpretedFunction(XDRState<mode> *xdr, HandleObject enclosingScope, Han
if (!proto)
return false;
}
fun = NewFunctionWithProto(cx, NullPtr(), nullptr, 0, JSFunction::INTERPRETED,
NullPtr(), NullPtr(), proto,
/* parent = */ NullPtr(), NullPtr(), proto,
JSFunction::FinalizeKind, TenuredObject);
if (!fun)
return false;