Skip to content

Commit 2e92cb4

Browse files
mmarchinitargos
authored andcommittedApr 22, 2020
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 <verwaest@chromium.org> Commit-Queue: Toon Verwaest <verwaest@chromium.org> Cr-Commit-Position: refs/heads/master@{#66038} Refs: v8/v8@f925780 Fixes: #31284 Signed-off-by: Matheus Marchini <mmarchini@netflix.com> PR-URL: #32180 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
1 parent e54eb46 commit 2e92cb4

8 files changed

+22
-16
lines changed
 

‎common.gypi

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
# Reset this number to 0 on major V8 upgrades.
3636
# Increment by one for each non-official patch applied to deps/v8.
37-
'v8_embedder_string': '-node.34',
37+
'v8_embedder_string': '-node.35',
3838

3939
##### V8 defaults for Node.js #####
4040

‎deps/v8/src/parsing/parser.cc

-1
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,6 @@ FunctionLiteral* Parser::ParseProgram(Isolate* isolate, ParseInfo* info) {
502502
Scope::DeserializationMode::kIncludingVariables);
503503

504504
scanner_.Initialize();
505-
scanner_.SkipHashBang();
506505
FunctionLiteral* result = DoParseProgram(isolate, info);
507506
MaybeResetCharacterStream(info, result);
508507
MaybeProcessSourceRanges(info, result, stack_limit_);

‎deps/v8/src/parsing/preparser.cc

-4
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,6 @@ PreParser::PreParseResult PreParser::PreParseProgram() {
7474
scope->set_is_being_lazily_parsed(true);
7575
#endif
7676

77-
// Note: We should only skip the hashbang in non-Eval scripts
78-
// (currently, Eval is not handled by the PreParser).
79-
scanner()->SkipHashBang();
80-
8177
// ModuleDeclarationInstantiation for Source Text Module Records creates a
8278
// new Module Environment Record whose outer lexical environment record is
8379
// the global scope.

‎deps/v8/src/parsing/scanner-inl.h

+4
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,10 @@ V8_INLINE Token::Value Scanner::ScanSingleToken() {
505505
return ScanTemplateSpan();
506506

507507
case Token::PRIVATE_NAME:
508+
if (source_pos() == 0 && Peek() == '!') {
509+
token = SkipSingleLineComment();
510+
continue;
511+
}
508512
return ScanPrivateName();
509513

510514
case Token::WHITESPACE:

‎deps/v8/src/parsing/scanner.cc

-7
Original file line numberDiff line numberDiff line change
@@ -314,13 +314,6 @@ Token::Value Scanner::SkipMultiLineComment() {
314314
return Token::ILLEGAL;
315315
}
316316

317-
void Scanner::SkipHashBang() {
318-
if (c0_ == '#' && Peek() == '!' && source_pos() == 0) {
319-
SkipSingleLineComment();
320-
Scan();
321-
}
322-
}
323-
324317
Token::Value Scanner::ScanHtmlComment() {
325318
// Check for <!-- comments.
326319
DCHECK_EQ(c0_, '!');

‎deps/v8/src/parsing/scanner.h

-3
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,6 @@ class V8_EXPORT_PRIVATE Scanner {
420420

421421
const Utf16CharacterStream* stream() const { return source_; }
422422

423-
// If the next characters in the stream are "#!", the line is skipped.
424-
void SkipHashBang();
425-
426423
private:
427424
// Scoped helper for saving & restoring scanner error state.
428425
// This is used for tagged template literals, in which normally forbidden
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env d8
2+
// Copyright 2015 the V8 project authors. All rights reserved.
3+
// Use of this source code is governed by a BSD-style license that can be
4+
// found in the LICENSE file.
5+
//
6+
//
7+
8+
const x = 'valid code';
9+
10+
'incomplete string
11+
12+
const y = 'even more valid code!';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*%(basename)s:10: SyntaxError: Invalid or unexpected token
2+
'incomplete string
3+
^^^^^^^^^^^^^^^^^^
4+
5+
SyntaxError: Invalid or unexpected token

0 commit comments

Comments
 (0)
Please sign in to comment.