Commit f9257802 authored by Jan Krems's avatar Jan Krems Committed by Commit Bot

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/+/1995312Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66038}
parent d651b8e7
......@@ -505,7 +505,6 @@ FunctionLiteral* Parser::ParseProgram(Isolate* isolate, Handle<Script> script,
Scope::DeserializationMode::kIncludingVariables);
scanner_.Initialize();
scanner_.SkipHashBang();
FunctionLiteral* result = DoParseProgram(isolate, info);
MaybeResetCharacterStream(info, result);
MaybeProcessSourceRanges(info, result, stack_limit_);
......
......@@ -75,10 +75,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.
......
......@@ -506,6 +506,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:
......
......@@ -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 <!-- comments.
DCHECK_EQ(c0_, '!');
......
......@@ -422,9 +422,6 @@ class V8_EXPORT_PRIVATE Scanner {
const Utf16CharacterStream* stream() const { return source_; }
// If the next characters in the stream are "#!", the line is skipped.
void SkipHashBang();
private:
// Scoped helper for saving & restoring scanner error state.
// This is used for tagged template literals, in which normally forbidden
......
#!/usr/bin/env d8
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
//
const x = 'valid code';
'incomplete string
const y = 'even more valid code!';
*%(basename)s:10: SyntaxError: Invalid or unexpected token
'incomplete string
^^^^^^^^^^^^^^^^^^
SyntaxError: Invalid or unexpected token
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment