Bug 1550616 - Move GeneralTokenStreamChars::setFunctionStart to GeneralParser::setFunctionStartAtCurrentToken in Parser.cpp, eliminating one reason SharedContext.h depends on TokenStream.h. r=tcampbell
authorJeff Walden <jwalden@mit.edu>
Sun, 12 May 2019 22:13:53 +0000
changeset 532374 703783d5484d173508e8a13d41fde8d121149211
parent 532373 e0910edd4fc73cc0ed2932e7c7e2744ae7972e1f
child 532375 c706eab3c639f68720b3f3d634b29424da7f6360
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstcampbell
bugs1550616
milestone68.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 1550616 - Move GeneralTokenStreamChars::setFunctionStart to GeneralParser::setFunctionStartAtCurrentToken in Parser.cpp, eliminating one reason SharedContext.h depends on TokenStream.h. r=tcampbell Differential Revision: https://phabricator.services.mozilla.com/D30574
js/src/frontend/Parser.cpp
js/src/frontend/Parser.h
js/src/frontend/SharedContext.h
js/src/frontend/TokenStream.h
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -2102,16 +2102,27 @@ JSAtom* ParserBase::prefixAccessorName(P
   if (!str) {
     return nullptr;
   }
 
   return AtomizeString(cx_, str);
 }
 
 template <class ParseHandler, typename Unit>
+void GeneralParser<ParseHandler, Unit>::setFunctionStartAtCurrentToken(
+    FunctionBox* funbox) const {
+  uint32_t bufStart = anyChars.currentToken().pos.begin;
+
+  uint32_t startLine, startColumn;
+  tokenStream.computeLineAndColumn(bufStart, &startLine, &startColumn);
+
+  funbox->setStart(bufStart, startLine, startColumn);
+}
+
+template <class ParseHandler, typename Unit>
 bool GeneralParser<ParseHandler, Unit>::functionArguments(
     YieldHandling yieldHandling, FunctionSyntaxKind kind,
     FunctionNodeType funNode) {
   FunctionBox* funbox = pc_->functionBox();
 
   bool parenFreeArrow = false;
   // Modifier for the following tokens.
   // TokenStream::SlashIsDiv for the following cases:
@@ -2165,17 +2176,17 @@ bool GeneralParser<ParseHandler, Unit>::
                                               : JSMSG_PAREN_BEFORE_FORMAL);
       return false;
     }
 
     firstTokenPos = pos();
 
     // Record the start of function source (for FunctionToString). If we
     // are parenFreeArrow, we will set this below, after consuming the NAME.
-    tokenStream.setFunctionStart(funbox);
+    setFunctionStartAtCurrentToken(funbox);
   } else {
     // When delazifying, we may not have a current token and pos() is
     // garbage. In that case, substitute the first token's position.
     if (!tokenStream.peekTokenPos(&firstTokenPos, firstTokenModifier)) {
       return false;
     }
   }
 
@@ -2280,17 +2291,17 @@ bool GeneralParser<ParseHandler, Unit>::
 
         default: {
           if (!TokenKindIsPossibleIdentifier(tt)) {
             error(JSMSG_MISSING_FORMAL);
             return false;
           }
 
           if (parenFreeArrow) {
-            tokenStream.setFunctionStart(funbox);
+            setFunctionStartAtCurrentToken(funbox);
           }
 
           RootedPropertyName name(cx_, bindingIdentifier(yieldHandling));
           if (!name) {
             return false;
           }
 
           if (!notePositionalFormalParameter(funNode, name, pos().begin,
@@ -7162,17 +7173,17 @@ GeneralParser<ParseHandler, Unit>::synth
   // Create a ListNode for the parameters + body (there are no parameters).
   ListNodeType argsbody =
       handler_.newList(ParseNodeKind::ParamsBody, synthesizedBodyPos);
   if (!argsbody) {
     return null();
   }
   handler_.setFunctionFormalParametersAndBody(funNode, argsbody);
   funbox->function()->setArgCount(0);
-  tokenStream.setFunctionStart(funbox);
+  setFunctionStartAtCurrentToken(funbox);
 
   pc_->functionScope().useAsVarScope(pc_);
 
   auto stmtList = handler_.newStatementList(synthesizedBodyPos);
   if (!stmtList) {
     return null();
   }
 
@@ -7299,17 +7310,17 @@ GeneralParser<ParseHandler, Unit>::field
                                        directives, GeneratorKind::NotGenerator,
                                        FunctionAsyncKind::SyncFunction);
   if (!funbox) {
     return null();
   }
   funbox->initFieldInitializer(pc_, hasHeritage);
   handler_.setFunctionBox(funNode, funbox);
 
-  // We can't use tokenStream.setFunctionStart, because that uses pos().begin,
+  // We can't use setFunctionStartAtCurrentToken because that uses pos().begin,
   // which is incorrect for fields without initializers (pos() points to the
   // field identifier)
   uint32_t firstTokenLine, firstTokenColumn;
   tokenStream.computeLineAndColumn(firstTokenPos.begin, &firstTokenLine,
                                    &firstTokenColumn);
 
   funbox->setStart(firstTokenPos.begin, firstTokenLine, firstTokenColumn);
 
--- a/js/src/frontend/Parser.h
+++ b/js/src/frontend/Parser.h
@@ -1050,16 +1050,18 @@ class MOZ_STACK_CLASS GeneralParser : pu
       FunctionSyntaxKind kind, GeneratorKind generatorKind,
       FunctionAsyncKind asyncKind, bool tryAnnexB,
       Directives inheritedDirectives, Directives* newDirectives);
 
   inline bool skipLazyInnerFunction(FunctionNodeType funNode,
                                     uint32_t toStringStart,
                                     FunctionSyntaxKind kind, bool tryAnnexB);
 
+  void setFunctionStartAtCurrentToken(FunctionBox* funbox) const;
+
  public:
   /* Public entry points for parsing. */
   Node statementListItem(YieldHandling yieldHandling,
                          bool canHaveDirectives = false);
 
   // Parse an inner function given an enclosing ParseContext and a
   // FunctionBox for the inner function.
   MOZ_MUST_USE FunctionNodeType innerFunctionForFunctionBox(
--- a/js/src/frontend/SharedContext.h
+++ b/js/src/frontend/SharedContext.h
@@ -562,29 +562,16 @@ class FunctionBox : public ObjectBox, pu
     uint32_t offset = anyChars.currentToken().pos.end;
     bufEnd = offset;
     toStringEnd = offset;
   }
 
   void trace(JSTracer* trc) override;
 };
 
-template <typename Unit, class AnyCharsAccess>
-inline void GeneralTokenStreamChars<Unit, AnyCharsAccess>::setFunctionStart(
-    FunctionBox* funbox) const {
-  const TokenStreamAnyChars& anyChars = anyCharsAccess();
-
-  uint32_t bufStart = anyChars.currentToken().pos.begin;
-
-  uint32_t startLine, startColumn;
-  computeLineAndColumn(bufStart, &startLine, &startColumn);
-
-  funbox->setStart(bufStart, startLine, startColumn);
-}
-
 inline FunctionBox* SharedContext::asFunctionBox() {
   MOZ_ASSERT(isFunctionBox());
   return static_cast<FunctionBox*>(this);
 }
 
 // In generators, we treat all bindings as closed so that they get stored on
 // the heap.  This way there is less information to copy off the stack when
 // suspending, and back on when resuming.  It also avoids the need to create
--- a/js/src/frontend/TokenStream.h
+++ b/js/src/frontend/TokenStream.h
@@ -2089,18 +2089,16 @@ class GeneralTokenStreamChars : public S
     // separators don't need special handling.
     // https://tc39.github.io/ecma262/#sec-static-semantics-tv-and-trv
     if (!fillCharBufferFromSourceNormalizingAsciiLineBreaks(cur, end)) {
       return nullptr;
     }
 
     return drainCharBufferIntoAtom(anyChars.cx);
   }
-
-  inline void setFunctionStart(FunctionBox* funbox) const;
 };
 
 template <typename Unit, class AnyCharsAccess>
 class TokenStreamChars;
 
 template <class AnyCharsAccess>
 class TokenStreamChars<char16_t, AnyCharsAccess>
     : public GeneralTokenStreamChars<char16_t, AnyCharsAccess> {