Bug 1584649 - Support putting field initializers inside the LazyScriptCreationData r=tcampbell
authorMatthew Gaudet <mgaudet@mozilla.com>
Mon, 30 Sep 2019 20:06:05 +0000
changeset 495729 95fa040657ec85461ea36a25efbe94baf25b44b6
parent 495728 ac1436cdbaed91ac6169272767b1a2107032fc85
child 495730 7414831ed19d70d3b168a9a26078c49ff6766581
push id114140
push userdvarga@mozilla.com
push dateWed, 02 Oct 2019 18:04:51 +0000
treeherdermozilla-inbound@32eb0ea893f3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstcampbell
bugs1584649
milestone71.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 1584649 - Support putting field initializers inside the LazyScriptCreationData r=tcampbell Note, the deferred code paths are unused until we move publication -after- bytecode emission Differential Revision: https://phabricator.services.mozilla.com/D47659
js/src/frontend/BytecodeEmitter.cpp
js/src/frontend/Parser.cpp
js/src/frontend/SharedContext.h
--- a/js/src/frontend/BytecodeEmitter.cpp
+++ b/js/src/frontend/BytecodeEmitter.cpp
@@ -5710,17 +5710,17 @@ MOZ_NEVER_INLINE bool BytecodeEmitter::e
   if (fun->isInterpreted()) {
     if (fun->isInterpretedLazy()) {
       if (!fe.emitLazy()) {
         //          [stack] FUN?
         return false;
       }
 
       if (classContentsIfConstructor) {
-        fun->lazyScript()->setFieldInitializers(
+        funbox->setFieldInitializers(
             setupFieldInitializers(classContentsIfConstructor));
       }
 
       return true;
     }
 
     if (!fe.prepareForNonLazy()) {
       //            [stack]
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -1887,16 +1887,20 @@ static bool EmitLazyScript(JSContext* cx
 
   // Flags that need to copied back into the parser when we do the full
   // parse.
   PropagateTransitiveParseFlags(funbox, lazy);
 
   function->initLazyScript(lazy);
   funbox->setIsInterpretedLazy(true);
 
+  if (data.fieldInitializers) {
+    lazy->setFieldInitializers(*data.fieldInitializers);
+  }
+
   // In order to allow asserting that we published all lazy script data,
   // reset the lazyScriptData here, now that it's no longer needed.
   funbox->lazyScriptData().reset();
   return true;
 }
 
 static YieldHandling GetYieldHandling(GeneratorKind generatorKind) {
   if (generatorKind == GeneratorKind::NotGenerator) {
--- a/js/src/frontend/SharedContext.h
+++ b/js/src/frontend/SharedContext.h
@@ -274,18 +274,23 @@ enum class HasHeritage : bool { No, Yes 
 // Data used to instantiate the lazy script before script emission.
 struct LazyScriptCreationData {
   frontend::AtomVector closedOverBindings;
 
   // This is traced by the functionbox which owns this LazyScriptCreationData
   FunctionBoxVector innerFunctionBoxes;
   bool strict;
 
+  mozilla::Maybe<FieldInitializers> fieldInitializers;
+
   explicit LazyScriptCreationData(JSContext* cx)
-      : closedOverBindings(), innerFunctionBoxes(cx), strict(false) {}
+      : closedOverBindings(),
+        innerFunctionBoxes(cx),
+        strict(false),
+        fieldInitializers() {}
 
   bool init(JSContext* cx, const frontend::AtomVector& COB,
             FunctionBoxVector& innerBoxes, bool isStrict) {
     strict = isStrict;
     // Copy out of the stack allocated vectors.
     if (!innerFunctionBoxes.appendAll(innerBoxes)) {
       return false;
     }
@@ -722,16 +727,26 @@ class FunctionBox : public ObjectBox, pu
   // Flush the acquired argCount to the associated function.
   // If the function doesn't exist yet, this of course isn't necessary;
   void synchronizeArgCount() {
     if (hasObject()) {
       function()->setArgCount(nargs_);
     }
   }
 
+  void setFieldInitializers(FieldInitializers fi) {
+    if (hasObject()) {
+      MOZ_ASSERT(function()->lazyScript());
+      function()->lazyScript()->setFieldInitializers(std::move(fi));
+      return;
+    }
+    MOZ_ASSERT(lazyScriptData());
+    lazyScriptData()->fieldInitializers.emplace(std::move(fi));
+  }
+
   void trace(JSTracer* trc) override;
 };
 
 inline FunctionBox* SharedContext::asFunctionBox() {
   MOZ_ASSERT(isFunctionBox());
   return static_cast<FunctionBox*>(this);
 }