Skip to content

Commit 966bd36

Browse files
mmarchiniCommit Bot
authored andcommitted
Merged: Fix scanner-level error reporting for hashbang
Revision: f925780 BUG=v8:10110 NOTRY=true NOPRESUBMIT=true NOTREECHECKS=true [email protected] Change-Id: If5d39d5c971e239f5612f017606615ebccc3b5de Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2102928 Reviewed-by: Toon Verwaest <[email protected]> Commit-Queue: Toon Verwaest <[email protected]> Cr-Commit-Position: refs/branch-heads/8.1@{#49} Cr-Branched-From: a4dcd39-refs/heads/8.1.307@{#1} Cr-Branched-From: f22c213-refs/heads/master@{#66031}
1 parent a21998f commit 966bd36

File tree

7 files changed

+21
-15
lines changed

7 files changed

+21
-15
lines changed

src/parsing/parser.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,6 @@ FunctionLiteral* Parser::ParseProgram(Isolate* isolate, Handle<Script> script,
505505
Scope::DeserializationMode::kIncludingVariables);
506506

507507
scanner_.Initialize();
508-
scanner_.SkipHashBang();
509508
FunctionLiteral* result = DoParseProgram(isolate, info);
510509
MaybeResetCharacterStream(info, result);
511510
MaybeProcessSourceRanges(info, result, stack_limit_);

src/parsing/preparser.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ PreParser::PreParseResult PreParser::PreParseProgram() {
7575
scope->set_is_being_lazily_parsed(true);
7676
#endif
7777

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

src/parsing/scanner-inl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,10 @@ V8_INLINE Token::Value Scanner::ScanSingleToken() {
506506
return ScanTemplateSpan();
507507

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

511515
case Token::WHITESPACE:

src/parsing/scanner.cc

Lines changed: 0 additions & 7 deletions
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_, '!');

src/parsing/scanner.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,6 @@ class V8_EXPORT_PRIVATE Scanner {
422422

423423
const Utf16CharacterStream* stream() const { return source_; }
424424

425-
// If the next characters in the stream are "#!", the line is skipped.
426-
void SkipHashBang();
427-
428425
private:
429426
// Scoped helper for saving & restoring scanner error state.
430427
// This is used for tagged template literals, in which normally forbidden
Lines changed: 12 additions & 0 deletions
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!';
Lines changed: 5 additions & 0 deletions
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)