Bug 1602222 - Add HasModuleGoal flag to js::BaseScript. r=jandem
authorTed Campbell <tcampbell@mozilla.com>
Mon, 16 Dec 2019 13:48:19 +0000
changeset 507111 42f003a501505ba037fea0fac75559d1a7bb1928
parent 507110 709cb020572064b32f88c24a644478572e1d0009
child 507112 887237f5f3e076dd6b0f319f7ea853649772f5d9
push id36923
push userccoroiu@mozilla.com
push dateMon, 16 Dec 2019 21:47:33 +0000
treeherdermozilla-central@c238b47d7d57 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1602222
milestone73.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1602222 - Add HasModuleGoal flag to js::BaseScript. r=jandem Lazy scripts were using the IsModule flag with different semantics than compiled scripts and so this patch adds a new flag instead. The flag is initialized from non-lazy scripts for consistency. Differential Revision: https://phabricator.services.mozilla.com/D57220
js/src/frontend/BytecodeCompiler.cpp
js/src/vm/JSScript.cpp
js/src/vm/JSScript.h
--- a/js/src/frontend/BytecodeCompiler.cpp
+++ b/js/src/frontend/BytecodeCompiler.cpp
@@ -1032,16 +1032,17 @@ static bool CompileLazyFunctionImpl(JSCo
     return false;
   }
 
   if (!bce.emitFunctionScript(pn, BytecodeEmitter::TopLevelFunction::Yes)) {
     return false;
   }
 
   MOZ_ASSERT(lazy->hasDirectEval() == script->hasDirectEval());
+  MOZ_ASSERT(lazy->hasModuleGoal() == script->hasModuleGoal());
 
   delazificationCompletion.complete();
   assertException.reset();
   return true;
 }
 
 bool frontend::CompileLazyFunction(JSContext* cx, Handle<LazyScript*> lazy,
                                    const char16_t* units, size_t length) {
--- a/js/src/vm/JSScript.cpp
+++ b/js/src/vm/JSScript.cpp
@@ -4510,16 +4510,18 @@ bool JSScript::fullyInitFromEmitter(JSCo
   script->setFlag(ImmutableFlags::HasCallSiteObj, bce->hasCallSiteObj);
   script->setFlag(ImmutableFlags::IsForEval, bce->sc->isEvalContext());
   script->setFlag(ImmutableFlags::IsModule, bce->sc->isModuleContext());
   script->setFlag(ImmutableFlags::IsFunction, bce->sc->isFunctionBox());
   script->setFlag(ImmutableFlags::HasNonSyntacticScope,
                   bce->outermostScope().hasOnChain(ScopeKind::NonSyntactic));
   script->setFlag(ImmutableFlags::NeedsFunctionEnvironmentObjects,
                   NeedsFunctionEnvironmentObjects(bce));
+  script->setFlag(ImmutableFlags::HasModuleGoal,
+                  bce->outermostScope().hasOnChain(ScopeKind::Module));
 
   // Initialize script flags from FunctionBox
   if (bce->sc->isFunctionBox()) {
     script->initFromFunctionBox(bce->sc->asFunctionBox());
   }
 
   // Create and initialize PrivateScriptData
   if (!PrivateScriptData::InitFromEmitter(cx, script, bce)) {
@@ -5650,17 +5652,17 @@ LazyScript* LazyScript::Create(
 
   LazyScript* lazy = LazyScript::CreateRaw(
       cx, ngcthings, fun, sourceObject, sourceStart, sourceEnd, toStringStart,
       toStringEnd, lineno, column);
   if (!lazy) {
     return nullptr;
   }
 
-  lazy->setFlag(ImmutableFlags::IsModule,
+  lazy->setFlag(ImmutableFlags::HasModuleGoal,
                 (parseGoal == frontend::ParseGoal::Module));
   lazy->setFlag(ImmutableFlags::HasInnerFunctions, !innerFunctionBoxes.empty());
 
   // Fill in gcthing data with inner functions followed by binding data.
   mozilla::Span<JS::GCCellPtr> gcThings =
       lazy->data_ ? lazy->data_->gcthings() : mozilla::Span<JS::GCCellPtr>();
   auto iter = gcThings.begin();
 
--- a/js/src/vm/JSScript.h
+++ b/js/src/vm/JSScript.h
@@ -1722,17 +1722,19 @@ class BaseScript : public gc::TenuredCel
     // See FunctionBox.
     BindingsAccessedDynamically = 1 << 5,
     FunHasExtensibleScope = 1 << 6,
 
     // Bytecode contains JSOP_CALLSITEOBJ
     // (We don't relazify functions with template strings, due to observability)
     HasCallSiteObj = 1 << 7,
 
-    // (1 << 8) is unused.
+    // Script is parsed with a top-level goal of Module. This may be a top-level
+    // or an inner-function script.
+    HasModuleGoal = 1 << 8,
 
     FunctionHasThisBinding = 1 << 9,
     FunctionHasExtraBodyVarScope = 1 << 10,
 
     // Whether the arguments object for this script, if it needs one, should be
     // mapped (alias formal parameters).
     HasMappedArgsObj = 1 << 11,
 
@@ -1998,16 +2000,17 @@ setterLevel:                            
   IMMUTABLE_FLAG_GETTER(noScriptRval, NoScriptRval)
   IMMUTABLE_FLAG_GETTER_SETTER_PUBLIC(strict, Strict)
   IMMUTABLE_FLAG_GETTER(hasNonSyntacticScope, HasNonSyntacticScope)
   IMMUTABLE_FLAG_GETTER(selfHosted, SelfHosted)
   IMMUTABLE_FLAG_GETTER_SETTER_PUBLIC(bindingsAccessedDynamically,
                                       BindingsAccessedDynamically)
   IMMUTABLE_FLAG_GETTER(funHasExtensibleScope, FunHasExtensibleScope)
   IMMUTABLE_FLAG_GETTER(hasCallSiteObj, HasCallSiteObj)
+  IMMUTABLE_FLAG_GETTER(hasModuleGoal, HasModuleGoal)
   IMMUTABLE_FLAG_GETTER_SETTER(functionHasThisBinding, FunctionHasThisBinding)
   // Alternate shorter name used throughout the codebase
   IMMUTABLE_FLAG_GETTER_SETTER_CUSTOM_PUBLIC(FunctionHasThisBinding,
                                              hasThisBinding, HasThisBinding)
   // FunctionHasExtraBodyVarScope: custom logic below.
   IMMUTABLE_FLAG_GETTER(hasMappedArgsObj, HasMappedArgsObj)
   IMMUTABLE_FLAG_GETTER_SETTER(hasInnerFunctions, HasInnerFunctions)
   IMMUTABLE_FLAG_GETTER_SETTER_PUBLIC(needsHomeObject, NeedsHomeObject)
@@ -3401,17 +3404,17 @@ class LazyScript : public BaseScript {
 
   JSScript* maybeScript() { return script_; }
   const JSScript* maybeScriptUnbarriered() const {
     return script_.unbarrieredGet();
   }
   bool hasScript() const { return bool(script_); }
 
   frontend::ParseGoal parseGoal() const {
-    if (hasFlag(ImmutableFlags::IsModule)) {
+    if (hasFlag(ImmutableFlags::HasModuleGoal)) {
       return frontend::ParseGoal::Module;
     }
     return frontend::ParseGoal::Script;
   }
 
   // Returns true if the enclosing script has ever been compiled.
   // Once the enclosing script is compiled, the scope chain is created.
   // This LazyScript is delazify-able as long as it has the enclosing scope,