Skip to content

Commit

Permalink
Bug 1620776 - Make ImmutableFlags::HasNonSyntacticScope an input flag…
Browse files Browse the repository at this point in the history
…. r=tcampbell

Differential Revision: https://phabricator.services.mozilla.com/D72491
  • Loading branch information
carolinecullen committed Apr 28, 2020
1 parent 885b51f commit c698e71
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 62 deletions.
4 changes: 4 additions & 0 deletions js/src/builtin/Eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ static bool EvalKernel(JSContext* cx, HandleValue v, EvalType evalType,
options.setFileAndLine("eval", 1);
options.setIntroductionType("eval");
}
options.setNonSyntacticScope(
enclosing->hasOnChain(ScopeKind::NonSyntactic));

AutoStableStringChars linearChars(cx);
if (!linearChars.initTwoByte(cx, linearStr)) {
Expand Down Expand Up @@ -411,6 +413,8 @@ bool js::DirectEvalStringFromIon(JSContext* cx, HandleObject env,
options.setFileAndLine("eval", 1);
options.setIntroductionType("eval");
}
options.setNonSyntacticScope(
enclosing->hasOnChain(ScopeKind::NonSyntactic));

AutoStableStringChars linearChars(cx);
if (!linearChars.initTwoByte(cx, linearStr)) {
Expand Down
1 change: 1 addition & 0 deletions js/src/debugger/Frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,7 @@ static bool EvaluateInEnv(JSContext* cx, Handle<Env*> env,
scopeKind = ScopeKind::Global;
} else {
scopeKind = ScopeKind::NonSyntactic;
options.setNonSyntacticScope(true);
}

if (frame) {
Expand Down
6 changes: 2 additions & 4 deletions js/src/frontend/BCEScriptStencil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ void BCEScriptStencil::init(BytecodeEmitter& bce,

immutableFlags = bce.sc->immutableFlags();

// Update the flags generated by BCE.
immutableFlags.setFlag(
ImmutableFlags::HasNonSyntacticScope,
bce.outermostScope().hasOnChain(ScopeKind::NonSyntactic));
MOZ_ASSERT(bce.outermostScope().hasOnChain(ScopeKind::NonSyntactic) ==
immutableFlags.hasFlag(ImmutableFlags::HasNonSyntacticScope));

gcThings = bce.perScriptData().gcThingList().stealGCThings();

Expand Down
27 changes: 7 additions & 20 deletions js/src/frontend/BytecodeCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -927,23 +927,6 @@ ModuleObject* frontend::CompileModule(JSContext* cx,
return CreateModule(cx, options, srcBuf);
}

static void CheckFlagsOnDelazification(uint32_t lazy, uint32_t nonLazy) {
#ifdef DEBUG
// These flags are expect to be unset for lazy scripts and are only valid
// after a script has been compiled with the full parser.
//
// NOTE: Keep in sync with JSScript::relazify().
constexpr uint32_t NonLazyFlagsMask =
uint32_t(BaseScript::ImmutableFlags::HasNonSyntacticScope);

// These flags are expected to match between lazy and full parsing.
constexpr uint32_t MatchedFlagsMask = ~NonLazyFlagsMask;

MOZ_ASSERT((lazy & NonLazyFlagsMask) == 0);
MOZ_ASSERT((lazy & MatchedFlagsMask) == (nonLazy & MatchedFlagsMask));
#endif // DEBUG
}

template <typename Unit>
static bool CompileLazyFunctionImpl(JSContext* cx, Handle<BaseScript*> lazy,
const Unit* units, size_t length) {
Expand Down Expand Up @@ -1007,7 +990,8 @@ static bool CompileLazyFunctionImpl(JSContext* cx, Handle<BaseScript*> lazy,
return false;
}

uint32_t lazyFlags = lazy->immutableFlags();
mozilla::DebugOnly<uint32_t> lazyFlags =
static_cast<uint32_t>(lazy->immutableFlags());

BytecodeEmitter bce(/* parent = */ nullptr, &parser, pn->funbox(),
compilationInfo, BytecodeEmitter::LazyFunction);
Expand All @@ -1019,8 +1003,11 @@ static bool CompileLazyFunctionImpl(JSContext* cx, Handle<BaseScript*> lazy,
return false;
}

CheckFlagsOnDelazification(lazyFlags,
bce.getResultScript()->immutableFlags());
MOZ_ASSERT(lazyFlags == bce.getResultScript()->immutableFlags());
MOZ_ASSERT(bce.getResultScript()->outermostScope()->hasOnChain(
ScopeKind::NonSyntactic) ==
bce.getResultScript()->immutableFlags().hasFlag(
JSScript::ImmutableFlags::HasNonSyntacticScope));

assertException.reset();
return true;
Expand Down
35 changes: 35 additions & 0 deletions js/src/frontend/SharedContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,41 @@
namespace js {
namespace frontend {

SharedContext::SharedContext(JSContext* cx, Kind kind,
CompilationInfo& compilationInfo,
Directives directives, SourceExtent extent,
ImmutableScriptFlags immutableFlags)
: cx_(cx),
kind_(kind),
compilationInfo_(compilationInfo),
thisBinding_(ThisBinding::Global),
extent(extent),
allowNewTarget_(false),
allowSuperProperty_(false),
allowSuperCall_(false),
allowArguments_(true),
inWith_(false),
needsThisTDZChecks_(false),
localStrict(false),
hasExplicitUseStrict_(false),
immutableFlags_(immutableFlags) {
if (kind_ == Kind::FunctionBox) {
immutableFlags_.setFlag(ImmutableFlags::IsFunction);
} else if (kind_ == Kind::Module) {
MOZ_ASSERT(!compilationInfo.options.nonSyntacticScope);
immutableFlags_.setFlag(ImmutableFlags::IsModule);
} else if (kind_ == Kind::Eval) {
immutableFlags_.setFlag(ImmutableFlags::IsForEval);
} else {
MOZ_ASSERT(kind_ == Kind::Global);
}

immutableFlags_.setFlag(ImmutableFlags::Strict, directives.strict());

immutableFlags_.setFlag(ImmutableFlags::HasNonSyntacticScope,
compilationInfo.options.nonSyntacticScope);
}

void SharedContext::computeAllowSyntax(Scope* scope) {
for (ScopeIter si(scope); si; si++) {
if (si.kind() == ScopeKind::Function) {
Expand Down
28 changes: 1 addition & 27 deletions js/src/frontend/SharedContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,33 +150,7 @@ class SharedContext {
public:
SharedContext(JSContext* cx, Kind kind, CompilationInfo& compilationInfo,
Directives directives, SourceExtent extent,
ImmutableScriptFlags immutableFlags = {})
: cx_(cx),
kind_(kind),
compilationInfo_(compilationInfo),
thisBinding_(ThisBinding::Global),
extent(extent),
allowNewTarget_(false),
allowSuperProperty_(false),
allowSuperCall_(false),
allowArguments_(true),
inWith_(false),
needsThisTDZChecks_(false),
localStrict(false),
hasExplicitUseStrict_(false),
immutableFlags_(immutableFlags) {
if (kind_ == Kind::FunctionBox) {
immutableFlags_.setFlag(ImmutableFlags::IsFunction);
} else if (kind_ == Kind::Module) {
immutableFlags_.setFlag(ImmutableFlags::IsModule);
} else if (kind_ == Kind::Eval) {
immutableFlags_.setFlag(ImmutableFlags::IsForEval);
} else {
MOZ_ASSERT(kind_ == Kind::Global);
}

immutableFlags_.setFlag(ImmutableFlags::Strict, directives.strict());
}
ImmutableScriptFlags immutableFlags = {});

// If this is the outermost SharedContext, the Scope that encloses
// it. Otherwise nullptr.
Expand Down
8 changes: 7 additions & 1 deletion js/src/vm/CompilationAndEvaluation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ class FunctionCompiler {
}

JSFunction* finish(HandleObjectVector envChain,
const ReadOnlyCompileOptions& options) {
const ReadOnlyCompileOptions& optionsArg) {
if (!funStr_.append(FunctionConstructorFinalBrace)) {
return nullptr;
}
Expand Down Expand Up @@ -302,6 +302,10 @@ class FunctionCompiler {
MOZ_ASSERT_IF(!IsGlobalLexicalEnvironment(enclosingEnv),
enclosingScope->hasOnChain(ScopeKind::NonSyntactic));

CompileOptions options(cx_, optionsArg);
options.setNonSyntacticScope(
enclosingScope->hasOnChain(ScopeKind::NonSyntactic));

if (!js::frontend::CompileStandaloneFunction(
cx_, &fun, options, newSrcBuf, mozilla::Some(parameterListEnd_),
enclosingScope)) {
Expand Down Expand Up @@ -474,6 +478,8 @@ static bool EvaluateSourceBuffer(JSContext* cx, ScopeKind scopeKind,
cx->check(env);
MOZ_ASSERT_IF(!IsGlobalLexicalEnvironment(env),
scopeKind == ScopeKind::NonSyntactic);
MOZ_ASSERT_IF(scopeKind == ScopeKind::NonSyntactic,
options.nonSyntacticScope);

options.setIsRunOnce(true);

Expand Down
15 changes: 5 additions & 10 deletions js/src/vm/JSScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4043,12 +4043,6 @@ void JSScript::relazify(JSRuntime* rt) {
swapData(scriptData);
freeSharedData();

// Clear flags that are only set by the BytecodeEmitter. This ensures that
// CheckFlagsOnDelazification is still valid on next compile.
//
// NOTE: Keep in sync with CheckFlagsOnDelazification.
clearFlag(ImmutableFlags::HasNonSyntacticScope);

// We should not still be in any side-tables for the debugger or
// code-coverage. The finalizer will not be able to clean them up once
// bytecode is released. We check in JSFunction::maybeRelazify() for these
Expand Down Expand Up @@ -4873,16 +4867,17 @@ static JSScript* CopyScriptImpl(JSContext* cx, HandleScript src,
// Some embeddings are not careful to use ExposeObjectToActiveJS as needed.
JS::AssertObjectIsNotGray(sourceObject);

ImmutableScriptFlags flags = src->immutableFlags();
flags.setFlag(JSScript::ImmutableFlags::HasNonSyntacticScope,
scopes[0]->hasOnChain(ScopeKind::NonSyntactic));

// Create a new JSScript to fill in.
RootedScript dst(cx, JSScript::Create(cx, functionOrGlobal, sourceObject,
src->extent(), src->immutableFlags()));
src->extent(), flags));
if (!dst) {
return nullptr;
}

dst->setFlag(JSScript::ImmutableFlags::HasNonSyntacticScope,
scopes[0]->hasOnChain(ScopeKind::NonSyntactic));

// Reset the mutable flags to request arguments analysis as needed.
dst->resetArgsUsageAnalysis();

Expand Down

0 comments on commit c698e71

Please sign in to comment.