From a467125c8d0a8930eab28d9114b5531b9ad01f75 Mon Sep 17 00:00:00 2001 From: Benjamin Coe Date: Fri, 18 Dec 2020 10:40:07 -0800 Subject: [PATCH] deps: V8: cherry-pick dfcdf7837e23 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Original commit message: [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 Commit-Queue: Toon Verwaest Cr-Commit-Position: refs/heads/master@{#71765} Refs: https://github.com/v8/v8/commit/dfcdf7837e23cc0da31f9b2d4211f856413d13af PR-URL: https://github.com/nodejs/node/pull/36573 Fixes: https://github.com/nodejs/node/issues/36619 Reviewed-By: Michaƫl Zasso Reviewed-By: Rich Trott Reviewed-By: Michael Dawson Reviewed-By: Jiawen Geng --- common.gypi | 2 +- deps/v8/src/parsing/parser-base.h | 15 +++++++++------ deps/v8/test/mjsunit/code-coverage-block.js | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/common.gypi b/common.gypi index 1832067c1d284b..89bdba7ab003bc 100644 --- a/common.gypi +++ b/common.gypi @@ -36,7 +36,7 @@ # Reset this number to 0 on major V8 upgrades. # Increment by one for each non-official patch applied to deps/v8. - 'v8_embedder_string': '-node.65', + 'v8_embedder_string': '-node.66', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/src/parsing/parser-base.h b/deps/v8/src/parsing/parser-base.h index 903ce2bb7f8c4c..c064ea5ebb16aa 100644 --- a/deps/v8/src/parsing/parser-base.h +++ b/deps/v8/src/parsing/parser-base.h @@ -2973,12 +2973,15 @@ ParserBase::ParseCoalesceExpression(ExpressionT expression) { bool first_nullish = true; while (peek() == Token::NULLISH) { SourceRange right_range; - SourceRangeScope right_range_scope(scanner(), &right_range); - Consume(Token::NULLISH); - int pos = peek_position(); - - // Parse BitwiseOR or higher. - ExpressionT y = ParseBinaryExpression(6); + int pos; + ExpressionT y; + { + SourceRangeScope right_range_scope(scanner(), &right_range); + Consume(Token::NULLISH); + pos = peek_position(); + // Parse BitwiseOR or higher. + y = ParseBinaryExpression(6); + } if (first_nullish) { expression = factory()->NewBinaryOperation(Token::NULLISH, expression, y, pos); diff --git a/deps/v8/test/mjsunit/code-coverage-block.js b/deps/v8/test/mjsunit/code-coverage-block.js index ea1c2ea5fc9770..4584f3134a90db 100644 --- a/deps/v8/test/mjsunit/code-coverage-block.js +++ b/deps/v8/test/mjsunit/code-coverage-block.js @@ -1177,4 +1177,22 @@ a(true); // 0500 {"start":0,"end":401,"count":2}, {"start":154,"end":254,"count":0}]); + TestCoverage( +"https://crbug.com/v8/11231 - nullish coalescing", +` +const a = true // 0000 +const b = false // 0050 +const c = undefined // 0100 +const d = a ?? 99 // 0150 +const e = 33 // 0200 +const f = b ?? (c ?? 99) // 0250 +const g = 33 // 0300 +const h = c ?? (c ?? 'hello') // 0350 +const i = c ?? b ?? 'hello' // 0400 +`, +[{"start":0,"end":449,"count":1}, + {"start":162,"end":167,"count":0}, + {"start":262,"end":274,"count":0}, + {"start":417,"end":427,"count":0}]); + %DebugToggleBlockCoverage(false);