From 27931d088d4169baa744f3ef6eca445c545b1c71 Mon Sep 17 00:00:00 2001 From: Jason Orendorff Date: Fri, 21 Jun 2013 08:18:00 -0500 Subject: [PATCH] Bug 883333, part 12 - Factor block parsing out of Parser::statement. r=Waldo. --HG-- extra : rebase_source : 1af9d3df561cb5d9bc2c16c77451d070f48bccf4 --- js/src/frontend/Parser.cpp | 33 ++++++++++++++++++++------------- js/src/frontend/Parser.h | 1 + 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp index 627fb3c18ed7..5421df5fcda0 100644 --- a/js/src/frontend/Parser.cpp +++ b/js/src/frontend/Parser.cpp @@ -3327,6 +3327,25 @@ PushBlocklikeStatement(StmtInfoPC *stmt, StmtType type, ParseContextblockid); } +template +typename ParseHandler::Node +Parser::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::Node Parser::newBindingNode(PropertyName *name, bool functionScope, VarContext varContext) @@ -4799,19 +4818,7 @@ Parser::statement(bool canHaveDirectives) 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); diff --git a/js/src/frontend/Parser.h b/js/src/frontend/Parser.h index 0e59f32052fc..c54c39bd7f1e 100644 --- a/js/src/frontend/Parser.h +++ b/js/src/frontend/Parser.h @@ -417,6 +417,7 @@ struct Parser : private AutoGCRooter, public StrictModeGetter Node functionExpr(); Node statements(); + Node blockStatement(); Node ifStatement(); Node doWhileStatement(); Node whileStatement();