Bug 1227035 - Tighten the check in ObjectGroup::useSingletonForClone a bit more. r=bhackett, a=lizzard

This commit is contained in:
Jan de Mooij 2016-03-11 15:21:16 +01:00
parent d73e82310f
commit 8a3912284c
7 changed files with 25 additions and 18 deletions

View File

@ -832,8 +832,8 @@ frontend::CompileLazyFunction(JSContext* cx, Handle<LazyScript*> lazy, const cha
script->bindings = pn->pn_funbox->bindings;
if (lazy->usesArgumentsApplyAndThis())
script->setUsesArgumentsApplyAndThis();
if (lazy->isLikelyConstructorWrapper())
script->setLikelyConstructorWrapper();
if (lazy->hasBeenCloned())
script->setHasBeenCloned();

View File

@ -6432,8 +6432,8 @@ BytecodeEmitter::emitFunction(ParseNode* pn, bool needsProto)
if (!bce2.emitFunctionScript(pn->pn_body))
return false;
if (funbox->usesArguments && funbox->usesApply && funbox->usesThis)
script->setUsesArgumentsApplyAndThis();
if (funbox->isLikelyConstructorWrapper())
script->setLikelyConstructorWrapper();
}
if (outersc->isFunctionBox())
outersc->asFunctionBox()->function()->nonLazyScript()->setHasInnerFunctions(true);

View File

@ -788,6 +788,7 @@ FunctionBox::FunctionBox(ExclusiveContext* cx, ObjectBox* traceListHead, JSFunct
usesArguments(false),
usesApply(false),
usesThis(false),
usesReturn(false),
funCxFlags()
{
// Functions created at parse time may be set singleton after parsing and
@ -2884,8 +2885,8 @@ Parser<SyntaxParseHandler>::finishFunctionDefinition(Node pn, FunctionBox* funbo
if (pc->sc->strict())
lazy->setStrict();
lazy->setGeneratorKind(funbox->generatorKind());
if (funbox->usesArguments && funbox->usesApply && funbox->usesThis)
lazy->setUsesArgumentsApplyAndThis();
if (funbox->isLikelyConstructorWrapper())
lazy->setLikelyConstructorWrapper();
if (funbox->isDerivedClassConstructor())
lazy->setIsDerivedClassConstructor();
if (funbox->needsHomeObject())
@ -6505,6 +6506,7 @@ Parser<ParseHandler>::returnStatement(YieldHandling yieldHandling)
uint32_t begin = pos().begin;
MOZ_ASSERT(pc->sc->isFunctionBox());
pc->sc->asFunctionBox()->usesReturn = true;
// Parse an optional operand.
//

View File

@ -330,6 +330,7 @@ class FunctionBox : public ObjectBox, public SharedContext
bool usesArguments:1; /* contains a free use of 'arguments' */
bool usesApply:1; /* contains an f.apply() call */
bool usesThis:1; /* contains 'this' */
bool usesReturn:1; /* contains a 'return' statement */
FunctionContextFlags funCxFlags;
@ -343,6 +344,10 @@ class FunctionBox : public ObjectBox, public SharedContext
JSObject* staticScope() const override { return function(); }
JSObject* enclosingStaticScope() const { return enclosingStaticScope_; }
bool isLikelyConstructorWrapper() const {
return usesArguments && usesApply && usesThis && !usesReturn;
}
GeneratorKind generatorKind() const { return GeneratorKindFromBits(generatorKindBits_); }
bool isGenerator() const { return generatorKind() != NotGenerator; }
bool isLegacyGenerator() const { return generatorKind() == LegacyGenerator; }

View File

@ -4355,7 +4355,7 @@ LazyScript::CreateRaw(ExclusiveContext* cx, HandleFunction fun,
p.bindingsAccessedDynamically = false;
p.hasDebuggerStatement = false;
p.hasDirectEval = false;
p.usesArgumentsApplyAndThis = false;
p.isLikelyConstructorWrapper = false;
p.isDerivedClassConstructor = false;
p.needsHomeObject = false;

View File

@ -1149,7 +1149,7 @@ class JSScript : public js::gc::TenuredCell
bool isCachedEval_:1;
// 'this', 'arguments' and f.apply() are used. This is likely to be a wrapper.
bool usesArgumentsApplyAndThis_:1;
bool isLikelyConstructorWrapper_:1;
// IonMonkey compilation hints.
bool failedBoundsCheck_:1; /* script has had hoisted bounds checks fail */
@ -1412,10 +1412,10 @@ class JSScript : public js::gc::TenuredCell
void setActiveEval() { isActiveEval_ = true; }
bool usesArgumentsApplyAndThis() const {
return usesArgumentsApplyAndThis_;
bool isLikelyConstructorWrapper() const {
return isLikelyConstructorWrapper_;
}
void setUsesArgumentsApplyAndThis() { usesArgumentsApplyAndThis_ = true; }
void setLikelyConstructorWrapper() { isLikelyConstructorWrapper_ = true; }
bool isGeneratorExp() const { return isGeneratorExp_; }
@ -2179,7 +2179,7 @@ class LazyScript : public gc::TenuredCell
uint32_t bindingsAccessedDynamically : 1;
uint32_t hasDebuggerStatement : 1;
uint32_t hasDirectEval : 1;
uint32_t usesArgumentsApplyAndThis : 1;
uint32_t isLikelyConstructorWrapper : 1;
uint32_t hasBeenCloned : 1;
uint32_t treatAsRunOnce : 1;
uint32_t isDerivedClassConstructor : 1;
@ -2333,11 +2333,11 @@ class LazyScript : public gc::TenuredCell
p_.hasDirectEval = true;
}
bool usesArgumentsApplyAndThis() const {
return p_.usesArgumentsApplyAndThis;
bool isLikelyConstructorWrapper() const {
return p_.isLikelyConstructorWrapper;
}
void setUsesArgumentsApplyAndThis() {
p_.usesArgumentsApplyAndThis = true;
void setLikelyConstructorWrapper() {
p_.isLikelyConstructorWrapper = true;
}
bool hasBeenCloned() const {

View File

@ -149,12 +149,12 @@ ObjectGroup::useSingletonForClone(JSFunction* fun)
uint32_t begin, end;
if (fun->hasScript()) {
if (!fun->nonLazyScript()->usesArgumentsApplyAndThis())
if (!fun->nonLazyScript()->isLikelyConstructorWrapper())
return false;
begin = fun->nonLazyScript()->sourceStart();
end = fun->nonLazyScript()->sourceEnd();
} else {
if (!fun->lazyScript()->usesArgumentsApplyAndThis())
if (!fun->lazyScript()->isLikelyConstructorWrapper())
return false;
begin = fun->lazyScript()->begin();
end = fun->lazyScript()->end();