Commit b0b97da5 authored by adamk's avatar adamk Committed by Commit bot

[cleanup] Remove un-scoped ParseBlock from Parser

Because the Scope will be optimized away by the call to
FinalizeBlockScope in the case where there are no lexical
declarations in the block, this should have no effect on
anything downstream from the Parser, and simply removes
duplicate parsing code.

Due to the change from ParseStatement to ParseStatementListItem,
this will result in slightly different error messages for
lexical declarations in sloppy mode (until those are shipped).

R=littledan@chromium.org, rossberg@chromium.org
CQ_INCLUDE_TRYBOTS=tryserver.chromium.linux:linux_chromium_rel_ng;tryserver.blink:linux_blink_rel

Review URL: https://codereview.chromium.org/1433743005

Cr-Commit-Position: refs/heads/master@{#31966}
parent e752f964
......@@ -2352,34 +2352,6 @@ Statement* Parser::ParseClassDeclaration(ZoneList<const AstRawString*>* names,
Block* Parser::ParseBlock(ZoneList<const AstRawString*>* labels, bool* ok) {
if (is_strict(language_mode()) || allow_harmony_sloppy()) {
return ParseScopedBlock(labels, ok);
}
// Block ::
// '{' Statement* '}'
// Note that a Block does not introduce a new execution scope!
// (ECMA-262, 3rd, 12.2)
//
// Construct block expecting 16 statements.
Block* result =
factory()->NewBlock(labels, 16, false, RelocInfo::kNoPosition);
Target target(&this->target_stack_, result);
Expect(Token::LBRACE, CHECK_OK);
while (peek() != Token::RBRACE) {
Statement* stat = ParseStatement(NULL, CHECK_OK);
if (stat && !stat->IsEmpty()) {
result->statements()->Add(stat, zone());
}
}
Expect(Token::RBRACE, CHECK_OK);
return result;
}
Block* Parser::ParseScopedBlock(ZoneList<const AstRawString*>* labels,
bool* ok) {
// The harmony mode uses block elements instead of statements.
//
// Block ::
......@@ -3190,7 +3162,7 @@ TryStatement* Parser::ParseTryStatement(bool* ok) {
{
BlockState block_state(&scope_, catch_scope);
// TODO(adamk): Make a version of ParseScopedBlock that takes a scope and
// TODO(adamk): Make a version of ParseBlock that takes a scope and
// a block.
catch_block =
factory()->NewBlock(nullptr, 16, false, RelocInfo::kNoPosition);
......@@ -4136,7 +4108,7 @@ DoExpression* Parser::ParseDoExpression(bool* ok) {
Expect(Token::DO, CHECK_OK);
Variable* result =
scope_->NewTemporary(ast_value_factory()->dot_result_string());
Block* block = ParseScopedBlock(nullptr, CHECK_OK);
Block* block = ParseBlock(nullptr, CHECK_OK);
DoExpression* expr = factory()->NewDoExpression(block, result, pos);
if (!Rewriter::Rewrite(this, expr, ast_value_factory())) {
*ok = false;
......
......@@ -1086,9 +1086,6 @@ class Parser : public ParserBase<ParserTraits> {
TryStatement* ParseTryStatement(bool* ok);
DebuggerStatement* ParseDebuggerStatement(bool* ok);
// Support for hamony block scoped bindings.
Block* ParseScopedBlock(ZoneList<const AstRawString*>* labels, bool* ok);
// !%_IsSpecObject(result = iterator.next()) &&
// %ThrowIteratorResultNotAnObject(result)
Expression* BuildIteratorNextResult(Expression* iterator, Variable* result,
......
......@@ -477,19 +477,12 @@ PreParser::Statement PreParser::ParseClassDeclaration(bool* ok) {
PreParser::Statement PreParser::ParseBlock(bool* ok) {
// Block ::
// '{' Statement* '}'
// '{' StatementList '}'
// Note that a Block does not introduce a new execution scope!
// (ECMA-262, 3rd, 12.2)
//
Expect(Token::LBRACE, CHECK_OK);
Statement final = Statement::Default();
while (peek() != Token::RBRACE) {
if (is_strict(language_mode()) || allow_harmony_sloppy()) {
final = ParseStatementListItem(CHECK_OK);
} else {
final = ParseStatement(CHECK_OK);
}
final = ParseStatementListItem(CHECK_OK);
}
Expect(Token::RBRACE, ok);
return final;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment