Bug 1533003 - Split JSScript::initFromFunctionBox r=jandem
authorTed Campbell <tcampbell@mozilla.com>
Wed, 06 Mar 2019 18:12:30 +0000
changeset 520618 ba3dfc81120d01a3e931697d72e6bd95dad09582
parent 520617 6da5f14c500507c525e9b7bc18bbdc4f2b924c84
child 520651 a6f8093bf1a2a2705bf5b24f21df7c6f140e136d
child 520652 c5482772d73a8bea6946498f9f16ec9fdd9f9164
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 - Split JSScript::initFromFunctionBox r=jandem Split into one part for JSScript internal initialization of flags and a second part for linking the JSFunction and JSScript only after the script is fully initialized. Depends on D22322 Differential Revision: https://phabricator.services.mozilla.com/D22323
js/src/vm/JSScript.cpp
js/src/vm/JSScript.h
--- a/js/src/vm/JSScript.cpp
+++ b/js/src/vm/JSScript.cpp
@@ -3520,55 +3520,40 @@ static bool NeedsFunctionEnvironmentObje
     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);
-  }
-
-  script->setFlag(ImmutableFlags::FunHasExtensibleScope,
-                  funbox->hasExtensibleScope());
-  script->setFlag(ImmutableFlags::NeedsHomeObject, funbox->needsHomeObject());
-  script->setFlag(ImmutableFlags::IsDerivedClassConstructor,
-                  funbox->isDerivedClassConstructor());
+void JSScript::initFromFunctionBox(frontend::FunctionBox* funbox) {
+  funLength_ = funbox->length;
+
+  setFlag(ImmutableFlags::FunHasExtensibleScope, funbox->hasExtensibleScope());
+  setFlag(ImmutableFlags::NeedsHomeObject, funbox->needsHomeObject());
+  setFlag(ImmutableFlags::IsDerivedClassConstructor,
+          funbox->isDerivedClassConstructor());
+  setFlag(ImmutableFlags::HasMappedArgsObj, funbox->hasMappedArgsObj());
+  setFlag(ImmutableFlags::FunctionHasThisBinding, funbox->hasThisBinding());
+  setFlag(ImmutableFlags::FunctionHasExtraBodyVarScope,
+          funbox->hasExtraBodyVarScope());
+  setFlag(ImmutableFlags::IsGenerator, funbox->isGenerator());
+  setFlag(ImmutableFlags::IsAsync, funbox->isAsync());
+  setFlag(ImmutableFlags::HasRest, funbox->hasRest());
+  setFlag(ImmutableFlags::HasInnerFunctions, funbox->hasInnerFunctions());
 
   if (funbox->argumentsHasLocalBinding()) {
-    script->setArgumentsHasVarBinding();
+    setArgumentsHasVarBinding();
     if (funbox->definitelyNeedsArgsObj()) {
-      script->setNeedsArgsObj(true);
+      setNeedsArgsObj(true);
     }
   } else {
     MOZ_ASSERT(!funbox->definitelyNeedsArgsObj());
   }
-  script->setFlag(ImmutableFlags::HasMappedArgsObj, funbox->hasMappedArgsObj());
-
-  script->setFlag(ImmutableFlags::FunctionHasThisBinding,
-                  funbox->hasThisBinding());
-  script->setFlag(ImmutableFlags::FunctionHasExtraBodyVarScope,
-                  funbox->hasExtraBodyVarScope());
-
-  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());
 }
 
 /* static */
 bool JSScript::fullyInitFromEmitter(JSContext* cx, HandleScript script,
                                     frontend::BytecodeEmitter* bce) {
   MOZ_ASSERT(!script->data_, "JSScript already initialized");
 
   // If initialization fails, we must call JSScript::freeScriptData in order to
@@ -3607,34 +3592,44 @@ bool JSScript::fullyInitFromEmitter(JSCo
   script->setFlag(ImmutableFlags::IsModule, bce->sc->isModuleContext());
   script->setFlag(ImmutableFlags::HasNonSyntacticScope,
                   bce->outermostScope()->hasOnChain(ScopeKind::NonSyntactic));
   script->setFlag(ImmutableFlags::FunHasAnyAliasedFormal,
                   HasAnyAliasedFormal(bce));
   script->setFlag(ImmutableFlags::NeedsFunctionEnvironmentObjects,
                   NeedsFunctionEnvironmentObjects(bce));
 
+  // Initialize script flags from FunctionBox
+  if (bce->sc->isFunctionBox()) {
+    script->initFromFunctionBox(bce->sc->asFunctionBox());
+  }
+
   // Create and initialize PrivateScriptData
   if (!PrivateScriptData::InitFromEmitter(cx, script, bce)) {
     return false;
   }
 
   // Create and initialize SharedScriptData
   if (!SharedScriptData::InitFromEmitter(cx, script, bce)) {
     return false;
   }
   if (!script->shareScriptData(cx)) {
     return false;
   }
 
-  // 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.
+  // NOTE: JSScript is now constructed and should be linked in.
+
+  // Link JSFunction to this JSScript.
   if (bce->sc->isFunctionBox()) {
-    initFromFunctionBox(script, bce->sc->asFunctionBox());
+    JSFunction* fun = bce->sc->asFunctionBox()->function();
+    if (fun->isInterpretedLazy()) {
+      fun->setUnlazifiedScript(script);
+    } else {
+      fun->setScript(script);
+    }
   }
 
   // Part of the parse result – the scope containing each inner function – must
   // be stored in the inner function itself. Do this now that compilation is
   // complete and can no longer fail.
   bce->objectList.finishInnerFunctions();
 
 #ifdef JS_STRUCTURED_SPEW
--- a/js/src/vm/JSScript.h
+++ b/js/src/vm/JSScript.h
@@ -1905,18 +1905,17 @@ class JSScript : public js::gc::TenuredC
   static bool createPrivateScriptData(JSContext* cx,
                                       JS::Handle<JSScript*> script,
                                       uint32_t nscopes, uint32_t nconsts,
                                       uint32_t nobjects, uint32_t ntrynotes,
                                       uint32_t nscopenotes,
                                       uint32_t nresumeoffsets);
 
  private:
-  static void initFromFunctionBox(js::HandleScript script,
-                                  js::frontend::FunctionBox* funbox);
+  void initFromFunctionBox(js::frontend::FunctionBox* funbox);
 
  public:
   static bool fullyInitFromEmitter(JSContext* cx, js::HandleScript script,
                                    js::frontend::BytecodeEmitter* bce);
 
   // Initialize the Function.prototype script.
   static bool initFunctionPrototype(JSContext* cx, js::HandleScript script,
                                     JS::HandleFunction functionProto);