Bug 1533003 - Compute JSScript::NeedsFunctionEnvironmentObjects directly from BCE r=jandem
authorTed Campbell <tcampbell@mozilla.com>
Wed, 06 Mar 2019 17:55:38 +0000
changeset 520611 a8cbb44ae49bb90f786bce6ee5f3589ee5e13e18
parent 520610 1eb22a2970d35472bedd3372e5f0f3d9400d8dad
child 520612 ce7559041ffa76ffc14a77b6f6e7d730c9fa544d
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1533003
milestone67.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 1533003 - Compute JSScript::NeedsFunctionEnvironmentObjects directly from BCE r=jandem Depends on D22315 Differential Revision: https://phabricator.services.mozilla.com/D22316
js/src/vm/JSScript.cpp
--- a/js/src/vm/JSScript.cpp
+++ b/js/src/vm/JSScript.cpp
@@ -3458,16 +3458,39 @@ static bool HasAnyAliasedFormal(frontend
     // Check if the formal parameter is closed over.
     if (fi.closedOver()) {
       return true;
     }
   }
   return false;
 }
 
+static bool NeedsFunctionEnvironmentObjects(frontend::BytecodeEmitter* bce) {
+  // See JSFunction::needsCallObject()
+  js::Scope* bodyScope = bce->bodyScope();
+  if (bodyScope->kind() == js::ScopeKind::Function) {
+    if (bodyScope->hasEnvironment()) {
+      return true;
+    }
+  }
+
+  // See JSScript::maybeNamedLambdaScope()
+  js::Scope* outerScope = bce->outermostScope();
+  if (outerScope->kind() == js::ScopeKind::NamedLambda ||
+      outerScope->kind() == js::ScopeKind::StrictNamedLambda) {
+    MOZ_ASSERT(bce->sc->asFunctionBox()->function()->isNamedLambda());
+
+    if (outerScope->hasEnvironment()) {
+      return true;
+    }
+  }
+
+  return false;
+}
+
 /* static */
 void JSScript::initFromFunctionBox(HandleScript script,
                                    frontend::FunctionBox* funbox) {
   JSFunction* fun = funbox->function();
   if (fun->isInterpretedLazy()) {
     fun->setUnlazifiedScript(script);
   } else {
     fun->setScript(script);
@@ -3497,20 +3520,16 @@ void JSScript::initFromFunctionBox(Handl
   script->funLength_ = funbox->length;
 
   script->setFlag(ImmutableFlags::IsGenerator, funbox->isGenerator());
   script->setFlag(ImmutableFlags::IsAsync, funbox->isAsync());
   script->setFlag(ImmutableFlags::HasRest, funbox->hasRest());
 
   script->setFlag(ImmutableFlags::HasInnerFunctions,
                   funbox->hasInnerFunctions());
-
-  script->setFlag(
-      ImmutableFlags::NeedsFunctionEnvironmentObjects,
-      (fun->needsCallObject() || fun->needsNamedLambdaEnvironment()));
 }
 
 /* static */
 bool JSScript::fullyInitFromEmitter(JSContext* cx, HandleScript script,
                                     frontend::BytecodeEmitter* bce) {
   /* The counts of indexed things must be checked during code generation. */
   MOZ_ASSERT(bce->atomIndices->count() <= INDEX_LIMIT);
   MOZ_ASSERT(bce->objectList.length <= INDEX_LIMIT);
@@ -3588,16 +3607,18 @@ bool JSScript::fullyInitFromEmitter(JSCo
 
   script->nfixed_ = bce->maxFixedSlots;
   script->nslots_ = nslots;
   script->bodyScopeIndex_ = bce->bodyScopeIndex;
   script->setFlag(ImmutableFlags::HasNonSyntacticScope,
                   bce->outermostScope()->hasOnChain(ScopeKind::NonSyntactic));
   script->setFlag(ImmutableFlags::FunHasAnyAliasedFormal,
                   HasAnyAliasedFormal(bce));
+  script->setFlag(ImmutableFlags::NeedsFunctionEnvironmentObjects,
+                  NeedsFunctionEnvironmentObjects(bce));
 
   // There shouldn't be any fallible operation after initFromFunctionBox,
   // JSFunction::hasUncompletedScript relies on the fact that the existence
   // of the pointer to JSScript means the pointed JSScript is complete.
   if (bce->sc->isFunctionBox()) {
     initFromFunctionBox(script, bce->sc->asFunctionBox());
   }