Bug 883333, part 12 - Factor block parsing out of Parser::statement. r=Waldo.
authorJason Orendorff <jorendorff@mozilla.com>
Fri, 21 Jun 2013 08:18:00 -0500
changeset 147467 a9565c559885b87cb29b0062651ed96a6b773a95
parent 147466 58eadcfb83f47f453dae2754d1119ffa7912c689
child 147468 698c78923ec571d6d98d128135ea1124998d41c3
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo
bugs883333
milestone24.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 883333, part 12 - Factor block parsing out of Parser::statement. r=Waldo.
js/src/frontend/Parser.cpp
js/src/frontend/Parser.h
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -3324,16 +3324,35 @@ static bool
 PushBlocklikeStatement(StmtInfoPC *stmt, StmtType type, ParseContext<ParseHandler> *pc)
 {
     PushStatementPC(pc, stmt, type);
     return GenerateBlockId(pc, stmt->blockid);
 }
 
 template <typename ParseHandler>
 typename ParseHandler::Node
+Parser<ParseHandler>::blockStatement()
+{
+    JS_ASSERT(tokenStream.currentToken().type == TOK_LC);
+
+    StmtInfoPC stmtInfo(context);
+    if (!PushBlocklikeStatement(&stmtInfo, STMT_BLOCK, pc))
+        return null();
+
+    Node list = statements();
+    if (!list)
+        return null();
+
+    MUST_MATCH_TOKEN(TOK_RC, JSMSG_CURLY_IN_COMPOUND);
+    PopStatementPC(context, pc);
+    return list;
+}
+
+template <typename ParseHandler>
+typename ParseHandler::Node
 Parser<ParseHandler>::newBindingNode(PropertyName *name, bool functionScope, VarContext varContext)
 {
     /*
      * If this name is being injected into an existing block/function, see if
      * it has already been declared or if it resolves an outstanding lexdep.
      * Otherwise, this is a let block/expr that introduces a new scope and thus
      * shadows existing decls and doesn't resolve existing lexdeps. Duplicate
      * names are caught by bindLet.
@@ -4794,29 +4813,17 @@ typename ParseHandler::Node
 Parser<ParseHandler>::statement(bool canHaveDirectives)
 {
     Node pn;
 
     JS_CHECK_RECURSION(context, return null());
 
     switch (tokenStream.getToken(TSF_OPERAND)) {
       case TOK_LC:
-      {
-        StmtInfoPC stmtInfo(context);
-        if (!PushBlocklikeStatement(&stmtInfo, STMT_BLOCK, pc))
-            return null();
-
-        pn = statements();
-        if (!pn)
-            return null();
-
-        MUST_MATCH_TOKEN(TOK_RC, JSMSG_CURLY_IN_COMPOUND);
-        PopStatementPC(context, pc);
-        return pn;
-      }
+        return blockStatement();
 
       case TOK_VAR:
         pn = variables(PNK_VAR);
         if (!pn)
             return null();
 
         /* Tell js_EmitTree to generate a final POP. */
         handler.setListFlag(pn, PNX_POPVAR);
--- a/js/src/frontend/Parser.h
+++ b/js/src/frontend/Parser.h
@@ -412,16 +412,17 @@ struct Parser : private AutoGCRooter, pu
      * Some parsers have two versions:  an always-inlined version (with an 'i'
      * suffix) and a never-inlined version (with an 'n' suffix).
      */
     Node moduleDecl();
     Node functionStmt();
     Node functionExpr();
     Node statements();
 
+    Node blockStatement();
     Node ifStatement();
     Node doWhileStatement();
     Node whileStatement();
     Node forStatement();
     Node switchStatement();
     Node continueStatement();
     Node breakStatement();
     Node returnStatementOrYieldExpression();