Bug 1343481 - Part 1: Remove {JSFunction,JSScript,LazyScript}.isGenerator() method.

Tag #1287
This commit is contained in:
Gaming4JC 2019-12-01 13:34:22 -05:00 • committed by Roy Tam
commit 7eb5d46c11
22 changed files with 133 additions and 64 deletions

View file

@ -3422,10 +3422,10 @@ ASTSerializer::function(ParseNode* pn, ASTType type, MutableHandleValue dst)
RootedFunction func(cx, pn->pn_funbox->function());
GeneratorStyle generatorStyle =
pn->pn_funbox->isGenerator()
? (pn->pn_funbox->isLegacyGenerator()
? GeneratorStyle::Legacy
: GeneratorStyle::ES6)
pn->pn_funbox->isStarGenerator()
? GeneratorStyle::ES6
: pn->pn_funbox->isLegacyGenerator()
? GeneratorStyle::Legacy
: GeneratorStyle::None;
bool isAsync = pn->pn_funbox->isAsync();

View file

@ -389,7 +389,10 @@ class BytecodeEmitter::EmitterScope : public Nestable<BytecodeEmitter::EmitterSc
nextFrameSlot_ = bi.nextFrameSlot();
if (nextFrameSlot_ > bce->maxFixedSlots)
bce->maxFixedSlots = nextFrameSlot_;
MOZ_ASSERT_IF(bce->sc->isFunctionBox() && bce->sc->asFunctionBox()->isGenerator(),
MOZ_ASSERT_IF(bce->sc->isFunctionBox() &&
(bce->sc->asFunctionBox()->isStarGenerator() ||
bce->sc->asFunctionBox()->isLegacyGenerator() ||
bce->sc->asFunctionBox()->isAsync()),
bce->maxFixedSlots == 0);
}
@ -4783,7 +4786,9 @@ BytecodeEmitter::isRunOnceLambda()
FunctionBox* funbox = sc->asFunctionBox();
return !funbox->argumentsHasLocalBinding() &&
!funbox->isGenerator() &&
!funbox->isStarGenerator() &&
!funbox->isLegacyGenerator() &&
!funbox->isAsync() &&
!funbox->function()->explicitName();
}
@ -8478,11 +8483,11 @@ BytecodeEmitter::emitReturn(ParseNode* pn)
*/
ptrdiff_t top = offset();
bool isGenerator = sc->isFunctionBox() && sc->asFunctionBox()->isGenerator();
bool needsFinalYield = sc->isFunctionBox() && sc->asFunctionBox()->needsFinalYield();
bool isDerivedClassConstructor =
sc->isFunctionBox() && sc->asFunctionBox()->isDerivedClassConstructor();
if (!emit1((isGenerator || isDerivedClassConstructor) ? JSOP_SETRVAL : JSOP_RETURN))
if (!emit1((needsFinalYield || isDerivedClassConstructor) ? JSOP_SETRVAL : JSOP_RETURN))
return false;
// Make sure that we emit this before popping the blocks in prepareForNonLocalJump,
@ -8497,7 +8502,7 @@ BytecodeEmitter::emitReturn(ParseNode* pn)
if (!nle.prepareForNonLocalJumpToOutermost())
return false;
if (isGenerator) {
if (needsFinalYield) {
// We know that .generator is on the function scope, as we just exited
// all nested scopes.
NameLocation loc =
@ -10313,7 +10318,7 @@ BytecodeEmitter::emitFunctionBody(ParseNode* funBody)
if (!emitTree(funBody))
return false;
if (funbox->isGenerator()) {
if (funbox->needsFinalYield()) {
// If we fall off the end of a generator, do a final yield.
if (funbox->isStarGenerator() && !emitPrepareIteratorResult())
return false;
@ -10321,7 +10326,7 @@ BytecodeEmitter::emitFunctionBody(ParseNode* funBody)
if (!emit1(JSOP_UNDEFINED))
return false;
if (sc->asFunctionBox()->isStarGenerator() && !emitFinishIteratorResult(true))
if (funbox->isStarGenerator() && !emitFinishIteratorResult(true))
return false;
if (!emit1(JSOP_SETRVAL))

View file

@ -2720,7 +2720,7 @@ Parser<ParseHandler>::functionBody(InHandling inHandling, YieldHandling yieldHan
break;
}
if (pc->isGenerator()) {
if (pc->needsDotGeneratorName()) {
MOZ_ASSERT_IF(!pc->isAsync(), type == StatementListBody);
if (!declareDotGeneratorName())
return null();

View file

@ -496,10 +496,6 @@ class ParseContext : public Nestable<ParseContext>
return sc_->isFunctionBox() ? sc_->asFunctionBox()->generatorKind() : NotGenerator;
}
bool isGenerator() const {
return generatorKind() != NotGenerator;
}
bool isLegacyGenerator() const {
return generatorKind() == LegacyGenerator;
}
@ -512,6 +508,10 @@ class ParseContext : public Nestable<ParseContext>
return sc_->isFunctionBox() && sc_->asFunctionBox()->isAsync();
}
bool needsDotGeneratorName() const {
return isStarGenerator() || isLegacyGenerator() || isAsync();
}
FunctionAsyncKind asyncKind() const {
return isAsync() ? AsyncFunction : SyncFunction;
}
@ -818,7 +818,9 @@ class ParserBase : public StrictModeGetter
// whether it's prohibited due to strictness, JS version, or occurrence
// inside a star generator.
bool yieldExpressionsSupported() {
return (versionNumber() >= JSVERSION_1_7 || pc->isGenerator()) && !pc->isAsync();
return (versionNumber() >= JSVERSION_1_7 && !pc->isAsync()) ||
pc->isStarGenerator() ||
pc->isLegacyGenerator();
}
virtual bool strictMode() { return pc->sc()->strict(); }

View file

@ -520,7 +520,9 @@ class FunctionBox : public ObjectBox, public SharedContext
return hasExtensibleScope() ||
needsHomeObject() ||
isDerivedClassConstructor() ||
isGenerator();
isStarGenerator() ||
isLegacyGenerator() ||
isAsync();
}
bool hasExtraBodyVarScope() const {
@ -531,7 +533,7 @@ class FunctionBox : public ObjectBox, public SharedContext
bool needsExtraBodyVarEnvironmentRegardlessOfBindings() const {
MOZ_ASSERT(hasParameterExprs);
return hasExtensibleScope() || isGenerator();
return hasExtensibleScope() || needsDotGeneratorName();
}
bool isLikelyConstructorWrapper() const {
@ -539,10 +541,17 @@ class FunctionBox : public ObjectBox, public SharedContext
}
GeneratorKind generatorKind() const { return GeneratorKindFromBits(generatorKindBits_); }
bool isGenerator() const { return generatorKind() != NotGenerator; }
bool isLegacyGenerator() const { return generatorKind() == LegacyGenerator; }
bool isStarGenerator() const { return generatorKind() == StarGenerator; }
FunctionAsyncKind asyncKind() const { return AsyncKindFromBits(asyncKindBits_); }
bool needsFinalYield() const {
return isStarGenerator() || isLegacyGenerator() || isAsync();
}
bool needsDotGeneratorName() const {
return isStarGenerator() || isLegacyGenerator() || isAsync();
}
bool isAsync() const { return asyncKind() == AsyncFunction; }
bool isArrow() const { return function()->isArrow(); }
@ -560,7 +569,7 @@ class FunctionBox : public ObjectBox, public SharedContext
// A generator kind can be set at initialization, or when "yield" is
// first seen. In both cases the transition can only happen from
// NotGenerator.
MOZ_ASSERT(!isGenerator());
MOZ_ASSERT(!isStarGenerator() && !isLegacyGenerator());
generatorKindBits_ = GeneratorKindAsBits(kind);
}
@ -655,7 +664,11 @@ SharedContext::asModuleContext()
inline bool
SharedContext::allBindingsClosedOver()
{
return bindingsAccessedDynamically() || (isFunctionBox() && asFunctionBox()->isGenerator());
return bindingsAccessedDynamically() ||
(isFunctionBox() &&
(asFunctionBox()->isStarGenerator() ||
asFunctionBox()->isLegacyGenerator() ||
asFunctionBox()->isAsync()));
}
} // namespace frontend

View file

@ -2320,7 +2320,9 @@ IonCompile(JSContext* cx, JSScript* script,
static bool
CheckFrame(JSContext* cx, BaselineFrame* frame)
{
MOZ_ASSERT(!frame->script()->isGenerator());
MOZ_ASSERT(!frame->script()->isStarGenerator());
MOZ_ASSERT(!frame->script()->isLegacyGenerator());
MOZ_ASSERT(!frame->script()->isAsync());
MOZ_ASSERT(!frame->isDebuggerEvalFrame());
MOZ_ASSERT(!frame->isEvalFrame());
@ -2351,11 +2353,16 @@ CheckScript(JSContext* cx, JSScript* script, bool osr)
return false;
}
if (script->isGenerator()) {
if (script->isStarGenerator() || script->isLegacyGenerator()) {
TrackAndSpewIonAbort(cx, script, "generator script");
return false;
}
if (script->isAsync()) {
TrackAndSpewIonAbort(cx, script, "async script");
return false;
}
if (script->hasNonSyntacticScope() && !script->functionNonDelazifying()) {
// Support functions with a non-syntactic global scope but not other
// scripts. For global scripts, IonBuilder currently uses the global

View file

@ -4402,8 +4402,14 @@ jit::AnalyzeArgumentsUsage(JSContext* cx, JSScript* scriptArg)
// direct eval is present.
//
// FIXME: Don't build arguments for ES6 generator expressions.
if (scriptArg->isDebuggee() || script->isGenerator() || script->bindingsAccessedDynamically())
if (scriptArg->isDebuggee() ||
script->isStarGenerator() ||
script->isLegacyGenerator() ||
script->isAsync() ||
script->bindingsAccessedDynamically())
{
return true;
}
if (!jit::IsIonEnabled(cx))
return true;

View file

@ -131,7 +131,11 @@ IsFunctionInStrictMode(JSFunction* fun)
static bool
IsNewerTypeFunction(JSFunction* fun) {
return fun->isArrow() || fun->isGenerator() || fun->isAsync() || fun->isMethod();
return fun->isArrow() ||
fun->isStarGenerator() ||
fun->isLegacyGenerator() ||
fun->isAsync() ||
fun->isMethod();
}
// Beware: this function can be invoked on *any* function! That includes
@ -442,8 +446,12 @@ fun_resolve(JSContext* cx, HandleObject obj, HandleId id, bool* resolvedp)
* - Arrow functions
* - Function.prototype
*/
if (fun->isBuiltin() || (!fun->isConstructor() && !fun->isGenerator()))
if (fun->isBuiltin())
return true;
if (!fun->isConstructor()) {
if (!fun->isStarGenerator() && !fun->isLegacyGenerator() && !fun->isAsync())
return true;
}
if (!ResolveInterpretedFunctionPrototype(cx, fun, id))
return false;
@ -1556,7 +1564,7 @@ fun_isGenerator(JSContext* cx, unsigned argc, Value* vp)
return true;
}
args.rval().setBoolean(fun->isGenerator());
args.rval().setBoolean(fun->isStarGenerator() || fun->isLegacyGenerator());
return true;
}

View file

@ -146,7 +146,9 @@ class JSFunction : public js::NativeObject
MOZ_ASSERT_IF(nonLazyScript()->funHasExtensibleScope() ||
nonLazyScript()->needsHomeObject() ||
nonLazyScript()->isDerivedClassConstructor() ||
isGenerator(),
isStarGenerator() ||
isLegacyGenerator() ||
isAsync(),
nonLazyScript()->bodyScope()->hasEnvironment());
return nonLazyScript()->bodyScope()->hasEnvironment();
@ -501,8 +503,6 @@ class JSFunction : public js::NativeObject
return js::NotGenerator;
}
bool isGenerator() const { return generatorKind() != js::NotGenerator; }
bool isLegacyGenerator() const { return generatorKind() == js::LegacyGenerator; }
bool isStarGenerator() const { return generatorKind() == js::StarGenerator; }
@ -513,9 +513,9 @@ class JSFunction : public js::NativeObject
bool isAsync() const {
if (isInterpretedLazy())
return lazyScript()->asyncKind() == js::AsyncFunction;
return lazyScript()->isAsync();
if (hasScript())
return nonLazyScript()->asyncKind() == js::AsyncFunction;
return nonLazyScript()->isAsync();
return false;
}

View file

@ -3917,7 +3917,9 @@ JSScript::argumentsOptimizationFailed(JSContext* cx, HandleScript script)
if (script->needsArgsObj())
return true;
MOZ_ASSERT(!script->isGenerator());
MOZ_ASSERT(!script->isStarGenerator());
MOZ_ASSERT(!script->isLegacyGenerator());
MOZ_ASSERT(!script->isAsync());
script->needsArgsObj_ = true;

View file

@ -1327,13 +1327,12 @@ class JSScript : public js::gc::TenuredCell
js::GeneratorKind generatorKind() const {
return js::GeneratorKindFromBits(generatorKindBits_);
}
bool isGenerator() const { return generatorKind() != js::NotGenerator; }
bool isLegacyGenerator() const { return generatorKind() == js::LegacyGenerator; }
bool isStarGenerator() const { return generatorKind() == js::StarGenerator; }
void setGeneratorKind(js::GeneratorKind kind) {
// A script only gets its generator kind set as part of initialization,
// so it can only transition from not being a generator.
MOZ_ASSERT(!isGenerator());
MOZ_ASSERT(!isStarGenerator() && !isLegacyGenerator());
generatorKindBits_ = GeneratorKindAsBits(kind);
}
@ -1341,6 +1340,10 @@ class JSScript : public js::gc::TenuredCell
return isAsync_ ? js::AsyncFunction : js::SyncFunction;
}
bool isAsync() const {
return isAsync_;
}
void setAsyncKind(js::FunctionAsyncKind kind) {
isAsync_ = kind == js::AsyncFunction;
}
@ -1493,7 +1496,8 @@ class JSScript : public js::gc::TenuredCell
bool isRelazifiable() const {
return (selfHosted() || lazyScript) && !hasInnerFunctions_ && !types_ &&
!isGenerator() && !hasBaselineScript() && !hasAnyIonScript() &&
!isStarGenerator() && !isLegacyGenerator() && !isAsync() &&
!hasBaselineScript() && !hasAnyIonScript() &&
!isDefaultClassConstructor() &&
!doNotRelazify_;
}
@ -1695,7 +1699,7 @@ class JSScript : public js::gc::TenuredCell
bool hasObjects() const { return hasArray(OBJECTS); }
bool hasTrynotes() const { return hasArray(TRYNOTES); }
bool hasScopeNotes() const { return hasArray(SCOPENOTES); }
bool hasYieldOffsets() const { return isGenerator(); }
bool hasYieldOffsets() const { return isStarGenerator() || isLegacyGenerator() || isAsync(); }
#define OFF(fooOff, hasFoo, t) (fooOff() + (hasFoo() ? sizeof(t) : 0))
@ -2112,8 +2116,6 @@ class LazyScript : public gc::TenuredCell
GeneratorKind generatorKind() const { return GeneratorKindFromBits(p_.generatorKindBits); }
bool isGenerator() const { return generatorKind() != NotGenerator; }
bool isLegacyGenerator() const { return generatorKind() == LegacyGenerator; }
bool isStarGenerator() const { return generatorKind() == StarGenerator; }
@ -2121,7 +2123,7 @@ class LazyScript : public gc::TenuredCell
void setGeneratorKind(GeneratorKind kind) {
// A script only gets its generator kind set as part of initialization,
// so it can only transition from NotGenerator.
MOZ_ASSERT(!isGenerator());
MOZ_ASSERT(!isStarGenerator() && !isLegacyGenerator());
// Legacy generators cannot currently be lazy.
MOZ_ASSERT(kind != LegacyGenerator);
p_.generatorKindBits = GeneratorKindAsBits(kind);
@ -2131,6 +2133,10 @@ class LazyScript : public gc::TenuredCell
return p_.isAsync ? AsyncFunction : SyncFunction;
}
bool isAsync() const {
return p_.isAsync;
}
void setAsyncKind(FunctionAsyncKind kind) {
p_.isAsync = kind == AsyncFunction;
}

View file

@ -53,9 +53,8 @@ function asyncFunDecl(id, params, body) {
params: params,
defaults: [],
body: body,
generator: true,
async: true,
style: "es6" });
generator: false,
async: true });
}
function varDecl(decls) {
return Pattern({ type: "VariableDeclaration", declarations: decls, kind: "var" });
@ -181,9 +180,8 @@ function asyncFunExpr(id, args, body) {
id: id,
params: args,
body: body,
generator: true,
async: true,
style: "es6" });
generator: false,
async: true });
}
function arrowExpr(args, body) {
return Pattern({ type: "ArrowFunctionExpression",
@ -194,10 +192,9 @@ function asyncArrowExpr(isExpression, args, body) {
return Pattern({ type: "ArrowFunctionExpression",
params: args,
body: body,
generator: true,
generator: false,
async: true,
expression: isExpression,
style: "es6" });
expression: isExpression });
}
function metaProperty(meta, property) {

View file

@ -7356,7 +7356,8 @@ DebuggerFrame::getEnvironment(JSContext* cx, HandleDebuggerFrame frame,
/* static */ bool
DebuggerFrame::getIsGenerator(HandleDebuggerFrame frame)
{
return DebuggerFrame::getReferent(frame).script()->isGenerator();
return DebuggerFrame::getReferent(frame).script()->isStarGenerator() ||
DebuggerFrame::getReferent(frame).script()->isLegacyGenerator();
}
/* static */ bool

View file

@ -2448,7 +2448,9 @@ DebugEnvironments::addDebugEnvironment(JSContext* cx, const EnvironmentIter& ei,
MOZ_ASSERT(cx->compartment() == debugEnv->compartment());
// Generators should always have environments.
MOZ_ASSERT_IF(ei.scope().is<FunctionScope>(),
!ei.scope().as<FunctionScope>().canonicalFunction()->isGenerator());
!ei.scope().as<FunctionScope>().canonicalFunction()->isStarGenerator() &&
!ei.scope().as<FunctionScope>().canonicalFunction()->isLegacyGenerator() &&
!ei.scope().as<FunctionScope>().canonicalFunction()->isAsync());
if (!CanUseDebugEnvironmentMaps(cx))
return true;
@ -2594,8 +2596,11 @@ DebugEnvironments::onPopCall(JSContext* cx, AbstractFramePtr frame)
if (!frame.environmentChain()->is<CallObject>())
return;
if (frame.callee()->isGenerator())
if (frame.callee()->isStarGenerator() || frame.callee()->isLegacyGenerator() ||
frame.callee()->isAsync())
{
return;
}
CallObject& callobj = frame.environmentChain()->as<CallObject>();
envs->liveEnvs.remove(&callobj);
@ -2726,8 +2731,13 @@ DebugEnvironments::updateLiveEnvironments(JSContext* cx)
if (frame.environmentChain()->compartment() != cx->compartment())
continue;
if (frame.isFunctionFrame() && frame.callee()->isGenerator())
continue;
if (frame.isFunctionFrame()) {
if (frame.callee()->isStarGenerator() || frame.callee()->isLegacyGenerator() ||
frame.callee()->isAsync())
{
continue;
}
}
if (!frame.isDebuggee())
continue;
@ -2882,7 +2892,8 @@ GetDebugEnvironmentForMissing(JSContext* cx, const EnvironmentIter& ei)
if (ei.scope().is<FunctionScope>()) {
RootedFunction callee(cx, ei.scope().as<FunctionScope>().canonicalFunction());
// Generators should always reify their scopes.
MOZ_ASSERT(!callee->isGenerator());
MOZ_ASSERT(!callee->isStarGenerator() && !callee->isLegacyGenerator() &&
!callee->isAsync());
JS::ExposeObjectToActiveJS(callee);
Rooted<CallObject*> callobj(cx, CallObject::createHollowForDebug(cx, callee));

View file

@ -19,7 +19,8 @@ using namespace js;
JSObject*
GeneratorObject::create(JSContext* cx, AbstractFramePtr frame)
{
MOZ_ASSERT(frame.script()->isGenerator());
MOZ_ASSERT(frame.script()->isStarGenerator() || frame.script()->isLegacyGenerator() ||
frame.script()->isAsync());
MOZ_ASSERT(frame.script()->nfixed() == 0);
Rooted<GlobalObject*> global(cx, cx->global());

View file

@ -184,7 +184,7 @@ ObjectGroup::useSingletonForNewObject(JSContext* cx, JSScript* script, jsbytecod
* Sub2 lets us continue to distinguish the two subclasses and any extra
* properties added to those prototype objects.
*/
if (script->isGenerator())
if (script->isStarGenerator() || script->isLegacyGenerator() || script->isAsync())
return false;
if (JSOp(*pc) != JSOP_NEW)
return false;

View file

@ -41,7 +41,10 @@ probes::EnterScript(JSContext* cx, JSScript* script, JSFunction* maybeFun,
if (rt->spsProfiler.enabled()) {
if (!rt->spsProfiler.enter(cx, script, maybeFun))
return false;
MOZ_ASSERT_IF(!fp->script()->isGenerator(), !fp->hasPushedSPSFrame());
MOZ_ASSERT_IF(!fp->script()->isStarGenerator() &&
!fp->script()->isLegacyGenerator() &&
!fp->script()->isAsync(),
!fp->hasPushedSPSFrame());
fp->setPushedSPSFrame();
}

View file

@ -3113,7 +3113,8 @@ JSRuntime::cloneSelfHostedFunctionScript(JSContext* cx, HandlePropertyName name,
return false;
// JSFunction::generatorKind can't handle lazy self-hosted functions, so we make sure there
// aren't any.
MOZ_ASSERT(!sourceFun->isGenerator());
MOZ_ASSERT(!sourceFun->isStarGenerator() && !sourceFun->isLegacyGenerator() &&
!sourceFun->isAsync());
MOZ_ASSERT(targetFun->isExtended());
MOZ_ASSERT(targetFun->isInterpretedLazy());
MOZ_ASSERT(targetFun->isSelfHostedBuiltin());

View file

@ -335,7 +335,7 @@ InterpreterStack::resumeGeneratorCallFrame(JSContext* cx, InterpreterRegs& regs,
HandleFunction callee, HandleValue newTarget,
HandleObject envChain)
{
MOZ_ASSERT(callee->isGenerator());
MOZ_ASSERT(callee->isStarGenerator() || callee->isLegacyGenerator() || callee->isAsync());
RootedScript script(cx, JSFunction::getOrCreateScript(cx, callee));
InterpreterFrame* prev = regs.fp();
jsbytecode* prevpc = regs.pc;

View file

@ -270,7 +270,9 @@ InterpreterFrame::epilogue(JSContext* cx, jsbytecode* pc)
UnwindAllEnvironmentsInFrame(cx, ei);
if (isFunctionFrame()) {
if (!callee().isGenerator() &&
if (!callee().isStarGenerator() &&
!callee().isLegacyGenerator() &&
!callee().isAsync() &&
isConstructing() &&
thisArgument().isObject() &&
returnValue().isPrimitive())

View file

@ -693,7 +693,8 @@ class InterpreterFrame
}
void resumeGeneratorFrame(JSObject* envChain) {
MOZ_ASSERT(script()->isGenerator());
MOZ_ASSERT(script()->isStarGenerator() || script()->isLegacyGenerator() ||
script()->isAsync());
MOZ_ASSERT(isFunctionFrame());
flags_ |= HAS_INITIAL_ENV;
envChain_ = envChain;

View file

@ -8608,9 +8608,12 @@ EstablishPreconditions(ExclusiveContext* cx, AsmJSParser& parser)
break;
}
if (parser.pc->isGenerator())
if (parser.pc->isStarGenerator() || parser.pc->isLegacyGenerator())
return Warn(parser, JSMSG_USE_ASM_TYPE_FAIL, "Disabled by generator context");
if (parser.pc->isAsync())
return Warn(parser, JSMSG_USE_ASM_TYPE_FAIL, "Disabled by async context");
if (parser.pc->isArrowFunction())
return Warn(parser, JSMSG_USE_ASM_TYPE_FAIL, "Disabled by arrow function context");