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

[coverage] Add continuation counters for catch and finally blocks

These counters handle cases in which the catch/finally block contains a jump
statement.

Bug: v8:6000
Change-Id: Ic83f11ee431edabe61f129c9abc3adc12a79c338
Reviewed-on: https://chromium-review.googlesource.com/586595Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46945}
parent bde4dc8e
......@@ -190,8 +190,14 @@ class TryCatchStatementSourceRanges final : public AstNodeSourceRanges {
: catch_range_(catch_range) {}
SourceRange GetRange(SourceRangeKind kind) {
DCHECK(kind == SourceRangeKind::kCatch);
switch (kind) {
case SourceRangeKind::kCatch:
return catch_range_;
case SourceRangeKind::kContinuation:
return SourceRange::ContinuationOf(catch_range_);
default:
UNREACHABLE();
}
}
private:
......@@ -204,8 +210,14 @@ class TryFinallyStatementSourceRanges final : public AstNodeSourceRanges {
: finally_range_(finally_range) {}
SourceRange GetRange(SourceRangeKind kind) {
DCHECK(kind == SourceRangeKind::kFinally);
switch (kind) {
case SourceRangeKind::kFinally:
return finally_range_;
case SourceRangeKind::kContinuation:
return SourceRange::ContinuationOf(finally_range_);
default:
UNREACHABLE();
}
}
private:
......
......@@ -1572,6 +1572,8 @@ void BytecodeGenerator::VisitTryCatchStatement(TryCatchStatement* stmt) {
BuildIncrementBlockCoverageCounterIfEnabled(stmt, SourceRangeKind::kCatch);
VisitInScope(stmt->catch_block(), stmt->scope());
try_control_builder.EndCatch();
BuildIncrementBlockCoverageCounterIfEnabled(stmt,
SourceRangeKind::kContinuation);
}
void BytecodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) {
......@@ -1637,6 +1639,8 @@ void BytecodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) {
// Dynamic dispatch after the finally-block.
commands.ApplyDeferredCommands();
BuildIncrementBlockCoverageCounterIfEnabled(stmt,
SourceRangeKind::kContinuation);
}
void BytecodeGenerator::VisitDebuggerStatement(DebuggerStatement* stmt) {
......
......@@ -355,10 +355,31 @@ TestCoverage(
{"start":219,"end":232,"count":0},
{"start":264,"end":274,"count":0},
{"start":369,"end":380,"count":0},
{"start":403,"end":414,"count":0}, // TODO(jgruber): Include `catch` in range.
{"start":390,"end":414,"count":0}, // TODO(jgruber): Include `catch` in range.
{"start":513,"end":564,"count":0}]
);
TestCoverage("try/catch/finally statements with early return",
`
!function() { // 0000
try { throw 42; } catch (e) { return; } // 0050
nop(); // 0100
}(); // 0150
!function() { // 0200
try { throw 42; } catch (e) {} // 0250
finally { return; } // 0300
nop(); // 0350
}(); // 0400
`,
[{"start":0,"end":449,"count":1},
{"start":1,"end":151,"count":1},
{"start":67,"end":80,"count":0},
{"start":89,"end":151,"count":0},
{"start":201,"end":401,"count":1},
{"start":267,"end":280,"count":0},
{"start":319,"end":401,"count":0}]
);
TestCoverage(
"early return in blocks",
`
......@@ -568,9 +589,9 @@ it.next(); it.return(); // 0450
`,
[{"start":0,"end":449,"count":1},
{"start":11,"end":351,"count":3},
{"start":112,"end":253,"count":0},
{"start":112,"end":262,"count":0},
{"start":262,"end":272,"count":1},
{"start":310,"end":351,"count":0}] // TODO(jgruber): Missing continuation.
{"start":272,"end":351,"count":0}]
);
TestCoverage("yield expressions (.throw and try/catch/finally)",
......@@ -588,9 +609,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":253,"count":1},
{"start":262,"end":272,"count":1},
{"start":310,"end":351,"count":0}] // TODO(jgruber): Missing continuation.
{"start":164,"end":310,"count":1},
{"start":310,"end":351,"count":0}]
);
TestCoverage(
......
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