From abd0c59062bf3eee1e70b0a46496407f3455e78f Mon Sep 17 00:00:00 2001 From: Matheus Marchini Date: Tue, 10 Mar 2020 10:45:10 -0700 Subject: [PATCH] deps: V8: cherry-pick f9257802c1c0 Original commit message: Fix scanner-level error reporting for hashbang When the file begins with a hashbang, the scanner is in a failed state when SkipHashbang() is called. This is usually not an issue but when the parser encounters an ILLEGAL token, it will reset the SyntaxError location because of it. Bug: v8:10110 Change-Id: I1c7344bf5ad20079cff80130c991f3bff4d7e9a8 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1995312 Reviewed-by: Toon Verwaest Commit-Queue: Toon Verwaest Cr-Commit-Position: refs/heads/master@{#66038} Refs: https://github.com/v8/v8/commit/f9257802c1c0a0663a1d05bacf662283f6bd9050 Fixes: https://github.com/nodejs/node/issues/31284 Signed-off-by: Matheus Marchini --- common.gypi | 2 +- deps/v8/src/parsing/parser.cc | 1 - deps/v8/src/parsing/preparser.cc | 4 ---- deps/v8/src/parsing/scanner-inl.h | 4 ++++ deps/v8/src/parsing/scanner.cc | 7 ------- deps/v8/src/parsing/scanner.h | 3 --- .../test/message/fail/hashbang-incomplete-string.js | 12 ++++++++++++ .../test/message/fail/hashbang-incomplete-string.out | 5 +++++ 8 files changed, 22 insertions(+), 16 deletions(-) create mode 100644 deps/v8/test/message/fail/hashbang-incomplete-string.js create mode 100644 deps/v8/test/message/fail/hashbang-incomplete-string.out diff --git a/common.gypi b/common.gypi index 6488241b3c6601..3878ba74c75d9c 100644 --- a/common.gypi +++ b/common.gypi @@ -39,7 +39,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.30', + 'v8_embedder_string': '-node.31', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/src/parsing/parser.cc b/deps/v8/src/parsing/parser.cc index edb9604bb5cfd1..a05884adc0d2d2 100644 --- a/deps/v8/src/parsing/parser.cc +++ b/deps/v8/src/parsing/parser.cc @@ -503,7 +503,6 @@ FunctionLiteral* Parser::ParseProgram(Isolate* isolate, ParseInfo* info) { Scope::DeserializationMode::kIncludingVariables); scanner_.Initialize(); - scanner_.SkipHashBang(); FunctionLiteral* result = DoParseProgram(isolate, info); MaybeResetCharacterStream(info, result); MaybeProcessSourceRanges(info, result, stack_limit_); diff --git a/deps/v8/src/parsing/preparser.cc b/deps/v8/src/parsing/preparser.cc index 67ee1930accaca..c25ed2f8dd4cb8 100644 --- a/deps/v8/src/parsing/preparser.cc +++ b/deps/v8/src/parsing/preparser.cc @@ -74,10 +74,6 @@ PreParser::PreParseResult PreParser::PreParseProgram() { scope->set_is_being_lazily_parsed(true); #endif - // Note: We should only skip the hashbang in non-Eval scripts - // (currently, Eval is not handled by the PreParser). - scanner()->SkipHashBang(); - // ModuleDeclarationInstantiation for Source Text Module Records creates a // new Module Environment Record whose outer lexical environment record is // the global scope. diff --git a/deps/v8/src/parsing/scanner-inl.h b/deps/v8/src/parsing/scanner-inl.h index b76076d92ffaaa..53b53cb9981259 100644 --- a/deps/v8/src/parsing/scanner-inl.h +++ b/deps/v8/src/parsing/scanner-inl.h @@ -505,6 +505,10 @@ V8_INLINE Token::Value Scanner::ScanSingleToken() { return ScanTemplateSpan(); case Token::PRIVATE_NAME: + if (source_pos() == 0 && Peek() == '!') { + token = SkipSingleLineComment(); + continue; + } return ScanPrivateName(); case Token::WHITESPACE: diff --git a/deps/v8/src/parsing/scanner.cc b/deps/v8/src/parsing/scanner.cc index 28e43747874605..d444719f638906 100644 --- a/deps/v8/src/parsing/scanner.cc +++ b/deps/v8/src/parsing/scanner.cc @@ -314,13 +314,6 @@ Token::Value Scanner::SkipMultiLineComment() { return Token::ILLEGAL; } -void Scanner::SkipHashBang() { - if (c0_ == '#' && Peek() == '!' && source_pos() == 0) { - SkipSingleLineComment(); - Scan(); - } -} - Token::Value Scanner::ScanHtmlComment() { // Check for