Commit d4c1b2aa authored by jgruber's avatar jgruber Committed by Commit Bot

[coverage] Include catch and finally keywords in ranges

This includes the catch and finally keywords in the respective range.
For instance:

// Catch range previously:  |<--------->|
try { /* ... */ } catch (e) { /* ... */ }
// Now:           |<------------------->|

Bug: v8:6000
Change-Id: I1bd9f7fce8bb7de945da83ab512833841b9d956a
Reviewed-on: https://chromium-review.googlesource.com/586598
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46959}
parent b87ba9f2
......@@ -5445,59 +5445,64 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseTryStatement(
SourceRange catch_range, finally_range;
BlockT catch_block = impl()->NullBlock();
if (Check(Token::CATCH)) {
Expect(Token::LPAREN, CHECK_OK);
catch_info.scope = NewScope(CATCH_SCOPE);
catch_info.scope->set_start_position(scanner()->location().beg_pos);
{
SourceRangeScope catch_range_scope(scanner(), &catch_range);
if (Check(Token::CATCH)) {
Expect(Token::LPAREN, CHECK_OK);
catch_info.scope = NewScope(CATCH_SCOPE);
catch_info.scope->set_start_position(scanner()->location().beg_pos);
{
BlockState catch_block_state(&scope_, catch_info.scope);
{
BlockState catch_block_state(&scope_, catch_info.scope);
catch_block = factory()->NewBlock(nullptr, 16, false, kNoSourcePosition);
catch_block =
factory()->NewBlock(nullptr, 16, false, kNoSourcePosition);
// Create a block scope to hold any lexical declarations created
// as part of destructuring the catch parameter.
{
BlockState catch_variable_block_state(zone(), &scope_);
scope()->set_start_position(scanner()->location().beg_pos);
typename Types::Target target(this, catch_block);
// This does not simply call ParsePrimaryExpression to avoid
// ExpressionFromIdentifier from being called in the first
// branch, which would introduce an unresolved symbol and mess
// with arrow function names.
if (peek_any_identifier()) {
catch_info.name =
ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK);
} else {
ExpressionClassifier pattern_classifier(this);
catch_info.pattern = ParsePrimaryExpression(CHECK_OK);
ValidateBindingPattern(CHECK_OK);
}
// Create a block scope to hold any lexical declarations created
// as part of destructuring the catch parameter.
{
BlockState catch_variable_block_state(zone(), &scope_);
scope()->set_start_position(scanner()->location().beg_pos);
typename Types::Target target(this, catch_block);
// This does not simply call ParsePrimaryExpression to avoid
// ExpressionFromIdentifier from being called in the first
// branch, which would introduce an unresolved symbol and mess
// with arrow function names.
if (peek_any_identifier()) {
catch_info.name =
ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK);
} else {
ExpressionClassifier pattern_classifier(this);
catch_info.pattern = ParsePrimaryExpression(CHECK_OK);
ValidateBindingPattern(CHECK_OK);
}
Expect(Token::RPAREN, CHECK_OK);
impl()->RewriteCatchPattern(&catch_info, CHECK_OK);
if (!impl()->IsNullStatement(catch_info.init_block)) {
catch_block->statements()->Add(catch_info.init_block, zone());
}
Expect(Token::RPAREN, CHECK_OK);
impl()->RewriteCatchPattern(&catch_info, CHECK_OK);
if (!impl()->IsNullStatement(catch_info.init_block)) {
catch_block->statements()->Add(catch_info.init_block, zone());
}
SourceRangeScope range_scope(scanner(), &catch_range);
catch_info.inner_block = ParseBlock(nullptr, CHECK_OK);
catch_block->statements()->Add(catch_info.inner_block, zone());
impl()->ValidateCatchBlock(catch_info, CHECK_OK);
scope()->set_end_position(scanner()->location().end_pos);
catch_block->set_scope(scope()->FinalizeBlockScope());
catch_info.inner_block = ParseBlock(nullptr, CHECK_OK);
catch_block->statements()->Add(catch_info.inner_block, zone());
impl()->ValidateCatchBlock(catch_info, CHECK_OK);
scope()->set_end_position(scanner()->location().end_pos);
catch_block->set_scope(scope()->FinalizeBlockScope());
}
}
}
catch_info.scope->set_end_position(scanner()->location().end_pos);
catch_info.scope->set_end_position(scanner()->location().end_pos);
}
}
BlockT finally_block = impl()->NullBlock();
DCHECK(peek() == Token::FINALLY || !impl()->IsNullStatement(catch_block));
if (Check(Token::FINALLY)) {
{
SourceRangeScope range_scope(scanner(), &finally_range);
finally_block = ParseBlock(nullptr, CHECK_OK);
if (Check(Token::FINALLY)) {
finally_block = ParseBlock(nullptr, CHECK_OK);
}
}
return impl()->RewriteTryStatement(try_block, catch_block, catch_range,
......
......@@ -351,12 +351,12 @@ TestCoverage(
`,
[{"start":0,"end":849,"count":1},
{"start":1,"end":801,"count":1},
{"start":77,"end":87,"count":0},
{"start":219,"end":232,"count":0},
{"start":264,"end":274,"count":0},
{"start":369,"end":380,"count":0},
{"start":390,"end":414,"count":0}, // TODO(jgruber): Include `catch` in range.
{"start":513,"end":564,"count":0}]
{"start":67,"end":87,"count":0},
{"start":219,"end":222,"count":0},
{"start":254,"end":274,"count":0},
{"start":369,"end":372,"count":0},
{"start":390,"end":404,"count":0},
{"start":513,"end":554,"count":0}]
);
TestCoverage("try/catch/finally statements with early return",
......@@ -373,10 +373,10 @@ TestCoverage("try/catch/finally statements with early return",
`,
[{"start":0,"end":449,"count":1},
{"start":1,"end":151,"count":1},
{"start":67,"end":80,"count":0},
{"start":67,"end":70,"count":0},
{"start":89,"end":151,"count":0},
{"start":201,"end":401,"count":1},
{"start":267,"end":280,"count":0},
{"start":267,"end":270,"count":0},
{"start":319,"end":401,"count":0}]
);
......@@ -408,7 +408,7 @@ TestCoverage(
`,
[{"start":0,"end":1099,"count":1},
{"start":1,"end":151,"count":1},
{"start":67,"end":80,"count":0},
{"start":67,"end":70,"count":0},
{"start":89,"end":151,"count":0},
{"start":201,"end":351,"count":1},
{"start":284,"end":351,"count":0},
......@@ -416,9 +416,8 @@ TestCoverage(
{"start":569,"end":701,"count":0},
{"start":561,"end":568,"count":0}, // TODO(jgruber): Sorting.
{"start":751,"end":1051,"count":1},
{"start":817,"end":830,"count":0},
{"start":817,"end":820,"count":0},
{"start":861,"end":1051,"count":0}]
);
TestCoverage(
......@@ -589,8 +588,8 @@ it.next(); it.return(); // 0450
`,
[{"start":0,"end":449,"count":1},
{"start":11,"end":351,"count":3},
{"start":112,"end":262,"count":0},
{"start":262,"end":272,"count":1},
{"start":112,"end":254,"count":0},
{"start":254,"end":272,"count":1},
{"start":272,"end":351,"count":0}]
);
......@@ -608,8 +607,8 @@ it.next(); it.throw(42); // 0550
`,
[{"start":0,"end":449,"count":1},
{"start":11,"end":351,"count":3},
{"start":112,"end":164,"count":0},
{"start":164,"end":310,"count":1},
{"start":112,"end":154,"count":0},
{"start":154,"end":310,"count":1},
{"start":310,"end":351,"count":0}]
);
......
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