Skip to content

Commit dfcdf78

Browse files
bcoeCommit Bot
authored andcommitted
[coverage] fix greedy nullish coalescing
The SourceRangeScope helper was consuming too many characters, instead explicitly create SourceRange, based on scanner position. Bug: v8:11231 Change-Id: I852d211227abacf867e8f1ab3e3ab06dbdba2a9b Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2576006 Reviewed-by: Toon Verwaest <[email protected]> Commit-Queue: Toon Verwaest <[email protected]> Cr-Commit-Position: refs/heads/master@{#71765}
1 parent 434d512 commit dfcdf78

2 files changed

Lines changed: 27 additions & 6 deletions

File tree

src/parsing/parser-base.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2980,12 +2980,15 @@ ParserBase<Impl>::ParseCoalesceExpression(ExpressionT expression) {
29802980
bool first_nullish = true;
29812981
while (peek() == Token::NULLISH) {
29822982
SourceRange right_range;
2983-
SourceRangeScope right_range_scope(scanner(), &right_range);
2984-
Consume(Token::NULLISH);
2985-
int pos = peek_position();
2986-
2987-
// Parse BitwiseOR or higher.
2988-
ExpressionT y = ParseBinaryExpression(6);
2983+
int pos;
2984+
ExpressionT y;
2985+
{
2986+
SourceRangeScope right_range_scope(scanner(), &right_range);
2987+
Consume(Token::NULLISH);
2988+
pos = peek_position();
2989+
// Parse BitwiseOR or higher.
2990+
y = ParseBinaryExpression(6);
2991+
}
29892992
if (first_nullish) {
29902993
expression =
29912994
factory()->NewBinaryOperation(Token::NULLISH, expression, y, pos);

test/mjsunit/code-coverage-block.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,4 +1177,22 @@ a(true); // 0500
11771177
{"start":0,"end":401,"count":2},
11781178
{"start":154,"end":254,"count":0}]);
11791179

1180+
TestCoverage(
1181+
"https://crbug.com/v8/11231 - nullish coalescing",
1182+
`
1183+
const a = true // 0000
1184+
const b = false // 0050
1185+
const c = undefined // 0100
1186+
const d = a ?? 99 // 0150
1187+
const e = 33 // 0200
1188+
const f = b ?? (c ?? 99) // 0250
1189+
const g = 33 // 0300
1190+
const h = c ?? (c ?? 'hello') // 0350
1191+
const i = c ?? b ?? 'hello' // 0400
1192+
`,
1193+
[{"start":0,"end":449,"count":1},
1194+
{"start":162,"end":167,"count":0},
1195+
{"start":262,"end":274,"count":0},
1196+
{"start":417,"end":427,"count":0}]);
1197+
11801198
%DebugToggleBlockCoverage(false);

0 commit comments

Comments
 (0)