Bug 1533003 - Compute JSScript::FunHasAnyAliasedFormal directly from BCE r=jandem

Compute this flag directly from BytecodeEmitter data structures instead
of needing to access the partially initialized script while setting its
own flags.

Depends on D22313

Differential Revision: https://phabricator.services.mozilla.com/D22315

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Ted Campbell 2019-03-06 17:42:18 +00:00
Родитель e0eaf32604
Коммит 327f2137b8
4 изменённых файлов: 25 добавлений и 10 удалений

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

@ -349,6 +349,10 @@ struct MOZ_STACK_CLASS BytecodeEmitter {
Scope* outermostScope() const { return scopeList.vector[0]; } Scope* outermostScope() const { return scopeList.vector[0]; }
Scope* innermostScope() const; Scope* innermostScope() const;
Scope* bodyScope() const {
MOZ_ASSERT(bodyScopeIndex < scopeList.length());
return scopeList.vector[bodyScopeIndex];
}
MOZ_ALWAYS_INLINE MOZ_ALWAYS_INLINE
MOZ_MUST_USE bool makeAtomIndex(JSAtom* atom, uint32_t* indexp) { MOZ_MUST_USE bool makeAtomIndex(JSAtom* atom, uint32_t* indexp) {

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

@ -3452,6 +3452,17 @@ static void InitAtomMap(frontend::AtomIndexMap& indices, GCPtrAtom* atoms) {
} }
} }
static bool HasAnyAliasedFormal(frontend::BytecodeEmitter* bce) {
PositionalFormalParameterIter fi(bce->bodyScope());
for (; fi; fi++) {
// Check if the formal parameter is closed over.
if (fi.closedOver()) {
return true;
}
}
return false;
}
/* static */ /* static */
void JSScript::initFromFunctionBox(HandleScript script, void JSScript::initFromFunctionBox(HandleScript script,
frontend::FunctionBox* funbox) { frontend::FunctionBox* funbox) {
@ -3489,12 +3500,6 @@ void JSScript::initFromFunctionBox(HandleScript script,
script->setFlag(ImmutableFlags::IsAsync, funbox->isAsync()); script->setFlag(ImmutableFlags::IsAsync, funbox->isAsync());
script->setFlag(ImmutableFlags::HasRest, funbox->hasRest()); script->setFlag(ImmutableFlags::HasRest, funbox->hasRest());
PositionalFormalParameterIter fi(script);
while (fi && !fi.closedOver()) {
fi++;
}
script->setFlag(ImmutableFlags::FunHasAnyAliasedFormal, !!fi);
script->setFlag(ImmutableFlags::HasInnerFunctions, script->setFlag(ImmutableFlags::HasInnerFunctions,
funbox->hasInnerFunctions()); funbox->hasInnerFunctions());
@ -3586,6 +3591,8 @@ bool JSScript::fullyInitFromEmitter(JSContext* cx, HandleScript script,
script->bodyScopeIndex_ = bce->bodyScopeIndex; script->bodyScopeIndex_ = bce->bodyScopeIndex;
script->setFlag(ImmutableFlags::HasNonSyntacticScope, script->setFlag(ImmutableFlags::HasNonSyntacticScope,
bce->outermostScope()->hasOnChain(ScopeKind::NonSyntactic)); bce->outermostScope()->hasOnChain(ScopeKind::NonSyntactic));
script->setFlag(ImmutableFlags::FunHasAnyAliasedFormal,
HasAnyAliasedFormal(bce));
// There shouldn't be any fallible operation after initFromFunctionBox, // There shouldn't be any fallible operation after initFromFunctionBox,
// JSFunction::hasUncompletedScript relies on the fact that the existence // JSFunction::hasUncompletedScript relies on the fact that the existence

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

@ -1577,15 +1577,18 @@ void BindingIter::init(WasmFunctionScope::Data& data) {
data.trailingNames.start(), data.length); data.trailingNames.start(), data.length);
} }
PositionalFormalParameterIter::PositionalFormalParameterIter(JSScript* script) PositionalFormalParameterIter::PositionalFormalParameterIter(Scope* scope)
: BindingIter(script) { : BindingIter(scope) {
// Reinit with flags = 0, i.e., iterate over all positional parameters. // Reinit with flags = 0, i.e., iterate over all positional parameters.
if (script->bodyScope()->is<FunctionScope>()) { if (scope->is<FunctionScope>()) {
init(script->bodyScope()->as<FunctionScope>().data(), /* flags = */ 0); init(scope->as<FunctionScope>().data(), /* flags = */ 0);
} }
settle(); settle();
} }
PositionalFormalParameterIter::PositionalFormalParameterIter(JSScript* script)
: PositionalFormalParameterIter(script->bodyScope()) { }
void js::DumpBindings(JSContext* cx, Scope* scopeArg) { void js::DumpBindings(JSContext* cx, Scope* scopeArg) {
RootedScope scope(cx, scopeArg); RootedScope scope(cx, scopeArg);
for (Rooted<BindingIter> bi(cx, BindingIter(scope)); bi; bi++) { for (Rooted<BindingIter> bi(cx, BindingIter(scope)); bi; bi++) {

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

@ -1322,6 +1322,7 @@ class PositionalFormalParameterIter : public BindingIter {
} }
public: public:
explicit PositionalFormalParameterIter(Scope* scope);
explicit PositionalFormalParameterIter(JSScript* script); explicit PositionalFormalParameterIter(JSScript* script);
void operator++(int) { void operator++(int) {