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,6 +5445,8 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseTryStatement(
SourceRange catch_range, finally_range;
BlockT catch_block = impl()->NullBlock();
{
SourceRangeScope catch_range_scope(scanner(), &catch_range);
if (Check(Token::CATCH)) {
Expect(Token::LPAREN, CHECK_OK);
catch_info.scope = NewScope(CATCH_SCOPE);
......@@ -5453,7 +5455,8 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseTryStatement(
{
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.
......@@ -5481,7 +5484,6 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseTryStatement(
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);
......@@ -5492,13 +5494,16 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseTryStatement(
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);
if (Check(Token::FINALLY)) {
finally_block = ParseBlock(nullptr, CHECK_OK);
}
}
return impl()->RewriteTryStatement(try_block, catch_block, catch_range,
finally_block, finally_range, catch_info,
......
......@@ -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