Reviewers: Michael Starzinger,
Message:
thanks for review!
https://codereview.chromium.org/148233011/diff/1/test/cctest/test-parsing.cc
File test/cctest/test-parsing.cc (right):
https://codereview.chromium.org/148233011/diff/1/test/cctest/test-parsing.cc#newcode1994
test/cctest/test-parsing.cc:1994: RunParserSyncTest(context_data,
statement_data, kError);
On 2014/02/07 15:00:00, Michael Starzinger wrote:
Can we also test the one or two success cases, just for the heck of
it?
Done.
Description:
Unify (Pre)Parser::ParseTryStatement.
Notes:
- This makes Parser and PreParser produce the same errors with the added
test
cases (this was not the case before).
- ParseBlock already does Expect(Token::LBRACE), so no need to check it
twice.
BUG=v8:3126
LOG=N
[email protected]
Please review this at https://codereview.chromium.org/148233011/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+55, -23 lines):
M src/parser.cc
M src/preparser.cc
M test/cctest/test-parsing.cc
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index
54a83e8568bc1b3dd9880966f03da6f37268b098..5e7680e6c19df12853d7ee850fc9bf65010f41fc
100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -2486,23 +2486,21 @@ TryStatement* Parser::ParseTryStatement(bool* ok) {
Expect(Token::RPAREN, CHECK_OK);
- if (peek() == Token::LBRACE) {
- Target target(&this->target_stack_, &catch_collector);
- VariableMode mode = is_extended_mode() ? LET : VAR;
- catch_variable =
- catch_scope->DeclareLocal(name, mode, kCreatedInitialized);
-
- BlockState block_state(this, catch_scope);
- catch_block = ParseBlock(NULL, CHECK_OK);
- } else {
- Expect(Token::LBRACE, CHECK_OK);
- }
+ Target target(&this->target_stack_, &catch_collector);
+ VariableMode mode = is_extended_mode() ? LET : VAR;
+ catch_variable =
+ catch_scope->DeclareLocal(name, mode, kCreatedInitialized);
+
+ BlockState block_state(this, catch_scope);
+ catch_block = ParseBlock(NULL, CHECK_OK);
+
catch_scope->set_end_position(scanner().location().end_pos);
tok = peek();
}
Block* finally_block = NULL;
- if (tok == Token::FINALLY || catch_block == NULL) {
+ ASSERT(tok == Token::FINALLY || catch_block != NULL);
+ if (tok == Token::FINALLY) {
Consume(Token::FINALLY);
finally_block = ParseBlock(NULL, CHECK_OK);
}
Index: src/preparser.cc
diff --git a/src/preparser.cc b/src/preparser.cc
index
49d6cd293de0ced12a617b8476b682dd5fe18080..fa6f217993e1619fc10e0861ed578550f6a5b788
100644
--- a/src/preparser.cc
+++ b/src/preparser.cc
@@ -699,15 +699,17 @@ PreParser::Statement
PreParser::ParseTryStatement(bool* ok) {
// Finally ::
// 'finally' Block
- // In preparsing, allow any number of catch/finally blocks, including
zero
- // of both.
-
Expect(Token::TRY, CHECK_OK);
ParseBlock(CHECK_OK);
- bool catch_or_finally_seen = false;
- if (peek() == Token::CATCH) {
+ Token::Value tok = peek();
+ if (tok != Token::CATCH && tok != Token::FINALLY) {
+ ReportMessageAt(scanner()->location(), "no_catch_or_finally", NULL);
+ *ok = false;
+ return Statement::Default();
+ }
+ if (tok == Token::CATCH) {
Consume(Token::CATCH);
Expect(Token::LPAREN, CHECK_OK);
ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK);
@@ -715,15 +717,11 @@ PreParser::Statement
PreParser::ParseTryStatement(bool* ok) {
{ Scope::InsideWith iw(scope_);
ParseBlock(CHECK_OK);
}
- catch_or_finally_seen = true;
+ tok = peek();
}
- if (peek() == Token::FINALLY) {
+ if (tok == Token::FINALLY) {
Consume(Token::FINALLY);
ParseBlock(CHECK_OK);
- catch_or_finally_seen = true;
- }
- if (!catch_or_finally_seen) {
- *ok = false;
}
return Statement::Default();
}
Index: test/cctest/test-parsing.cc
diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc
index
85b2f3c4002c50a051d6604f59b968be6cba0fd2..22d5056f8007c4afa1ae0f95cc813d3f22133e6c
100644
--- a/test/cctest/test-parsing.cc
+++ b/test/cctest/test-parsing.cc
@@ -1977,3 +1977,39 @@ TEST(FunctionDeclaresItselfStrict) {
RunParserSyncTest(context_data, strict_statement_data, kError);
RunParserSyncTest(context_data, non_strict_statement_data, kSuccess);
}
+
+
+TEST(ErrorsTryWithoutCatchOrFinally) {
+ const char* context_data[][2] = {
+ {"", ""},
+ { NULL, NULL }
+ };
+
+ const char* statement_data[] = {
+ "try { }",
+ "try { } foo();",
+ "try { } catch (e) foo();",
+ "try { } catch { }",
+ "try { } finally foo();",
+ NULL
+ };
+
+ RunParserSyncTest(context_data, statement_data, kError);
+}
+
+
+TEST(NoErrorsTryCatchFinally) {
+ const char* context_data[][2] = {
+ {"", ""},
+ { NULL, NULL }
+ };
+
+ const char* statement_data[] = {
+ "try { } catch (e) { }",
+ "try { } catch (e) { } finally { }",
+ "try { } finally { }",
+ NULL
+ };
+
+ RunParserSyncTest(context_data, statement_data, kSuccess);
+}
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.