[scanner] Combine surrogate pairs at start when scanning private names

Bug: v8:12523
Change-Id: Ic3779fe6f20965d177d99d0a570a735df72e4fde
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3366994
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78493}
This commit is contained in:
Shu-yu Guo 2022-01-04 14:25:01 -08:00 committed by V8 LUCI CQ
parent 8393133d6d
commit c7c5b49298
2 changed files with 26 additions and 7 deletions
src/parsing
test/mjsunit/harmony

View File

@ -497,17 +497,19 @@ Token::Value Scanner::ScanPrivateName() {
next().literal_chars.Start(); next().literal_chars.Start();
DCHECK_EQ(c0_, '#'); DCHECK_EQ(c0_, '#');
DCHECK(!IsIdentifierStart(kEndOfInput)); DCHECK(!IsIdentifierStart(kEndOfInput));
if (!IsIdentifierStart(Peek())) { Advance();
ReportScannerError(source_pos(), if (IsIdentifierStart(c0_) ||
MessageTemplate::kInvalidOrUnexpectedToken); (CombineSurrogatePair() && IsIdentifierStart(c0_))) {
return Token::ILLEGAL; AddLiteralChar('#');
}
AddLiteralCharAdvance();
Token::Value token = ScanIdentifierOrKeywordInner(); Token::Value token = ScanIdentifierOrKeywordInner();
return token == Token::ILLEGAL ? Token::ILLEGAL : Token::PRIVATE_NAME; return token == Token::ILLEGAL ? Token::ILLEGAL : Token::PRIVATE_NAME;
} }
PushBack('#'); // Undo Advance()
ReportScannerError(source_pos(), MessageTemplate::kInvalidOrUnexpectedToken);
return Token::ILLEGAL;
}
Token::Value Scanner::ScanTemplateSpan() { Token::Value Scanner::ScanTemplateSpan() {
// When scanning a TemplateSpan, we are looking for the following construct: // When scanning a TemplateSpan, we are looking for the following construct:
// TEMPLATE_SPAN :: // TEMPLATE_SPAN ::

View File

@ -0,0 +1,17 @@
// Copyright 2022 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.
class C1 {
#𖥸 = 42;
m() { return this.#𖥸; }
}
assertEquals((new C1).m(), 42);
class C2 {
#𖥸() { return 42; }
m() { return this.#𖥸(); }
}
assertEquals((new C2).m(), 42);