mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
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: https://github.com/v8/v8/commit/f9257802c1c0a0663a1d05bacf662283f6bd9050
Fixes: https://github.com/nodejs/node/issues/31284
Signed-off-by: Matheus Marchini <mmarchini@netflix.com>
PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
1 parent
e54eb46cdb
commit
2e92cb476d
8 files changed
+22
-16
No files matched your search
+1
-1
@@ -34,7 +34,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.34',
|
||||
'v8_embedder_string': '-node.35',
|
||||
|
||||
##### V8 defaults for Node.js #####
|
||||
|
||||
|
||||
Vendored
-1
@@ -502,7 +502,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_);
|
||||
|
||||
Vendored
-4
@@ -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.
|
||||
|
||||
Vendored
+4
@@ -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:
|
||||
|
||||
Vendored
-7
@@ -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_, '!');
|
||||
|
||||
Vendored
-3
@@ -420,9 +420,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
|
||||
|
||||
@@ -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!';
|
||||
@@ -0,0 +1,5 @@
|
||||
*%(basename)s:10: SyntaxError: Invalid or unexpected token
|
||||
'incomplete string
|
||||
^^^^^^^^^^^^^^^^^^
|
||||
|
||||
SyntaxError: Invalid or unexpected token
|
||||
Reference in new issue
Block a user