Skip to content

Commit

Permalink
deps: V8: cherry-pick f9257802c1c0
Browse files Browse the repository at this point in the history
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 <[email protected]>
    Commit-Queue: Toon Verwaest <[email protected]>
    Cr-Commit-Position: refs/heads/master@{#66038}

Refs: v8/v8@f925780
Fixes: #31284
Signed-off-by: Matheus Marchini <[email protected]>

PR-URL: #32180
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
  • Loading branch information
mmarchini authored and BridgeAR committed Mar 17, 2020
1 parent fc2909a commit 612ee7d
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,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.29',
'v8_embedder_string': '-node.30',

##### V8 defaults for Node.js #####

Expand Down
1 change: 0 additions & 1 deletion deps/v8/src/parsing/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
Expand Down
4 changes: 0 additions & 4 deletions deps/v8/src/parsing/preparser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions deps/v8/src/parsing/scanner-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 0 additions & 7 deletions deps/v8/src/parsing/scanner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_, '!');
Expand Down
3 changes: 0 additions & 3 deletions deps/v8/src/parsing/scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,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
Expand Down
12 changes: 12 additions & 0 deletions deps/v8/test/message/fail/hashbang-incomplete-string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/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!';
5 changes: 5 additions & 0 deletions deps/v8/test/message/fail/hashbang-incomplete-string.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*%(basename)s:10: SyntaxError: Invalid or unexpected token
'incomplete string
^^^^^^^^^^^^^^^^^^

SyntaxError: Invalid or unexpected token

0 comments on commit 612ee7d

Please sign in to comment.