Bug 883333, part 10 - Refactor throw statement parsing. r=Waldo.
authorJason Orendorff <jorendorff@mozilla.com>
Fri, 21 Jun 2013 08:18:00 -0500
changeset 147465 c825cf583de8d9556228733ef8d204c64b3fbf37
parent 147464 d8cce0fb9d9abae1038c95efa989ab0a01399c11
child 147466 58eadcfb83f47f453dae2754d1119ffa7912c689
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 10 - Refactor throw statement parsing. r=Waldo.
js/src/frontend/Parser.cpp
js/src/frontend/Parser.h
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -4574,16 +4574,42 @@ Parser<ParseHandler>::labeledStatement()
     /* Pop the label, set pn_expr, and return early. */
     PopStatementPC(context, pc);
 
     return handler.newLabeledStatement(label, pn, begin);
 }
 
 template <typename ParseHandler>
 typename ParseHandler::Node
+Parser<ParseHandler>::throwStatement()
+{
+    JS_ASSERT(tokenStream.isCurrentTokenType(TOK_THROW));
+    uint32_t begin = pos().begin;
+
+    /* ECMA-262 Edition 3 says 'throw [no LineTerminator here] Expr'. */
+    TokenKind tt = tokenStream.peekTokenSameLine(TSF_OPERAND);
+    if (tt == TOK_ERROR)
+        return null();
+    if (tt == TOK_EOF || tt == TOK_EOL || tt == TOK_SEMI || tt == TOK_RC) {
+        report(ParseError, false, null(), JSMSG_SYNTAX_ERROR);
+        return null();
+    }
+
+    Node throwExpr = expr();
+    if (!throwExpr)
+        return null();
+
+    if (!MatchOrInsertSemicolon(context, &tokenStream))
+        return null();
+
+    return handler.newThrowStatement(throwExpr, TokenPos::make(begin, pos().end));
+}
+
+template <typename ParseHandler>
+typename ParseHandler::Node
 Parser<ParseHandler>::tryStatement()
 {
     JS_ASSERT(tokenStream.isCurrentTokenType(TOK_TRY));
     uint32_t begin = pos().begin;
 
     /*
      * try nodes are ternary.
      * kid1 is the try statement
@@ -4823,37 +4849,17 @@ Parser<ParseHandler>::statement(bool can
 
       case TOK_RETURN:
         return returnStatementOrYieldExpression();
 
       case TOK_WITH:
         return withStatement();
 
       case TOK_THROW:
-      {
-        uint32_t begin = pos().begin;
-
-        /* ECMA-262 Edition 3 says 'throw [no LineTerminator here] Expr'. */
-        TokenKind tt = tokenStream.peekTokenSameLine(TSF_OPERAND);
-        if (tt == TOK_ERROR)
-            return null();
-        if (tt == TOK_EOF || tt == TOK_EOL || tt == TOK_SEMI || tt == TOK_RC) {
-            report(ParseError, false, null(), JSMSG_SYNTAX_ERROR);
-            return null();
-        }
-
-        Node pnexp = expr();
-        if (!pnexp)
-            return null();
-
-        pn = handler.newThrowStatement(pnexp, TokenPos::make(begin, pos().end));
-        if (!pn)
-            return null();
-        break;
-      }
+        return throwStatement();
 
       case TOK_TRY:
         return tryStatement();
 
       case TOK_FUNCTION:
         return functionStmt();
 
       case TOK_DEBUGGER:
--- a/js/src/frontend/Parser.h
+++ b/js/src/frontend/Parser.h
@@ -422,16 +422,17 @@ struct Parser : private AutoGCRooter, pu
     Node whileStatement();
     Node forStatement();
     Node switchStatement();
     Node continueStatement();
     Node breakStatement();
     Node returnStatementOrYieldExpression();
     Node withStatement();
     Node labeledStatement();
+    Node throwStatement();
     Node tryStatement();
 #if JS_HAS_BLOCK_SCOPE
     Node letStatement();
 #endif
     Node expressionStatement();
     Node variables(ParseNodeKind kind, bool *psimple = NULL,
                    StaticBlockObject *blockObj = NULL,
                    VarContext varContext = HoistVars);