65 std::numeric_limits<size_t>::max() - 1;
67 std::numeric_limits<size_t>::max();
76 if (had_parser_error_) {
77 scanner_->set_parser_error();
79 scanner_->reset_parser_error_flag();
80 scanner_->SeekNext(bookmark_);
82 bookmark_ = kBookmarkWasApplied;
86 return bookmark_ != kNoBookmark && bookmark_ != kBookmarkWasApplied;
90 return bookmark_ == kBookmarkWasApplied;
119template <
bool capture_raw,
bool unicode>
125 for (
int i = 0;
i < expected_length;
i++) {
130 ? MessageTemplate::kInvalidUnicodeEscapeSequence
131 : MessageTemplate::kInvalidHexEscapeSequence);
141template <
bool capture_raw>
152 MessageTemplate::kUndefinedUnicodeCodePoint);
197 if (
next_next().token != Token::kUninitialized) {
229 return Token::kIllegal;
242 return Token::kWhitespace;
248 return Token::kWhitespace;
256 int current_position,
257 std::vector<int>& positions) {
259 int last_position = current_position;
261 const char* char_data =
reinterpret_cast<const char*
>(data.data());
262 while (
pos <
static_cast<size_t>(data.length())) {
264 if (delta == std::numeric_limits<int32_t>::min()) {
271 last_position += delta;
272 positions.push_back(last_position);
274 positions.shrink_to_fit();
293 if (!name.is_one_byte())
return;
301 DCHECK(hash_or_at_sign ==
'#' || hash_or_at_sign ==
'@');
306 hash_or_at_sign ==
'#' &&
c0_ !=
'=') {
308 }
else if (name_literal ==
310 hash_or_at_sign ==
'#') {
311 value = &per_function_compile_hints_value;
337 if (value == &per_function_compile_hints_value &&
343 ProcessPerFunctionCompileHints(value_literal,
source_pos(),
352 const int kSlack = 3;
366 return hint_position >=
position - kSlack &&
374 if (!
next().after_line_terminator) {
388 return Token::kWhitespace;
407 return Token::kWhitespace;
412 return Token::kIllegal;
419 if (
c0_ !=
'-' ||
Peek() !=
'-') {
421 return Token::kLessThan;
430void Scanner::SanityCheckTokenDesc(
const TokenDesc& token)
const {
434 switch (token.token) {
435 case Token::kUninitialized:
436 case Token::kIllegal:
438 case Token::kTemplateSpan:
439 case Token::kTemplateTail:
442 DCHECK_EQ(token.invalid_template_escape_message, MessageTemplate::kNone);
456 if (
pos != current_pos) {
467template <
bool capture_raw>
481 case 'b' : c =
'\b';
break;
482 case 'f' : c =
'\f';
break;
483 case 'n' : c =
'\n';
break;
484 case 'r' : c =
'\r';
break;
485 case 't' : c =
'\t';
break;
514 octal_message_ = capture_raw ? MessageTemplate::kTemplate8Or9Escape
515 : MessageTemplate::kStrict8Or9Escape;
524template <
bool capture_raw>
526 DCHECK(
'0' <= c && c <=
'7');
531 if (d < 0 || d > 7)
break;
533 if (nx >= 256)
break;
544 octal_message_ = capture_raw ? MessageTemplate::kTemplateOctalLiteral
545 : MessageTemplate::kStrictOctalEscape;
569 while (
c0_ ==
'\\') {
573 return Token::kIllegal;
579 return Token::kString;
584 return Token::kIllegal;
601 return token == Token::kIllegal ? Token::kIllegal : Token::kPrivateName;
605 return Token::kIllegal;
631 const bool capture_raw =
true;
636 result = Token::kTemplateTail;
638 }
else if (c ==
'$' &&
Peek() ==
'{') {
642 }
else if (c ==
'\\') {
651 if (lastChar ==
'\r') {
688template <
typename IsolateT>
700template <
typename IsolateT>
714 bool is_check_first_digit) {
716 if (is_check_first_digit && !predicate(
c0_))
return false;
718 bool separator_seen =
false;
719 while (predicate(
c0_) ||
c0_ ==
'_') {
724 MessageTemplate::kContinuousNumericSeparator);
727 separator_seen =
true;
730 separator_seen =
false;
734 if (separator_seen) {
736 MessageTemplate::kTrailingNumericSeparator);
744 if (allow_numeric_separator) {
752 MessageTemplate::kInvalidOrUnexpectedToken);
759 bool separator_seen =
false;
765 MessageTemplate::kContinuousNumericSeparator);
768 separator_seen =
true;
771 separator_seen =
false;
772 *value = 10 * *value + (
c0_ -
'0');
778 if (separator_seen) {
780 MessageTemplate::kTrailingNumericSeparator);
788 if (allow_numeric_separator) {
793 *value = 10 * *value + (
c0_ -
'0');
846 bool at_start = !seen_period;
852 return Token::kIllegal;
878 return Token::kIllegal;
885 }
else if (
c0_ ==
'_') {
887 MessageTemplate::kZeroDigitNumericSeparator);
888 return Token::kIllegal;
900 return Token::kIllegal;
903 if (
next().literal_chars.one_byte_literal().length() <= 10 &&
916 return Token::kIllegal;
922 return Token::kIllegal;
929 bool is_bigint =
false;
936 if (length > kMaxBigIntCharacters) {
938 MessageTemplate::kBigIntTooBig);
939 return Token::kIllegal;
961 return Token::kIllegal;
970 return is_bigint ? Token::kBigInt : Token::kNumber;
980template <
bool capture_raw>
991 MessageTemplate::kInvalidUnicodeEscapeSequence);
997 const bool unicode =
true;
1002 bool can_be_keyword) {
1012 return Token::kIllegal;
1025 if (can_be_keyword &&
next().literal_chars.is_one_byte()) {
1029 if (
base::IsInRange(token, Token::kIdentifier, Token::kYield))
return token;
1031 if (token == Token::kFutureStrictReservedWord) {
1032 if (escaped)
return Token::kEscapedStrictReservedWord;
1036 if (!escaped)
return token;
1038 static_assert(Token::kLet + 1 == Token::kStatic);
1040 return Token::kEscapedStrictReservedWord;
1042 return Token::kEscapedKeyword;
1045 return Token::kIdentifier;
1050 DCHECK(
next().token == Token::kDiv ||
next().token == Token::kAssignDiv);
1053 bool in_character_class =
false;
1059 if (
next().token == Token::kAssignDiv) {
1063 while (
c0_ !=
'/' || in_character_class) {
1081 if (
c0_ ==
'[') in_character_class =
true;
1082 if (
c0_ ==
']') in_character_class =
false;
1099 if (!maybe_flag.has_value())
return {};
1101 if (flags & flag)
return {};
1137 switch (
current().number_kind) {
1155 int length = vector.length();
1157 memcpy(buffer, vector.begin(), length);
1171 token.token = Token::kUninitialized;
1172 token.invalid_template_escape_message = MessageTemplate::kNone;
constexpr T * begin() const
const AstRawString * GetOneByteString(base::Vector< const uint8_t > literal)
const AstRawString * GetTwoByteString(base::Vector< const uint16_t > literal)
static const uint32_t kMaxLengthBits
static std::optional< RegExpFlag > FlagFromChar(char c)
DirectHandle< String > Internalize(IsolateT *isolate) const
base::Vector< const uint8_t > one_byte_literal() const
static const size_t kNoBookmark
static const size_t kBookmarkWasApplied
bool HasBeenApplied() const
void Set(size_t bookmark)
ErrorState(MessageTemplate *message_stack, Scanner::Location *location_stack)
MessageTemplate *const message_stack_
void MoveErrorTo(TokenDesc *dest)
Scanner::Location *const location_stack_
MessageTemplate const old_message_
Scanner::Location const old_location_
V8_INLINE void AddLiteralCharAdvance()
void SeekForward(int pos)
MessageTemplate octal_message_
base::Vector< const uint16_t > literal_two_byte_string() const
V8_INLINE Token::Value ScanIdentifierOrKeywordInner()
bool IsValidBigIntKind(NumberKind kind)
base::Vector< const uint16_t > raw_literal_two_byte_string() const
TokenDesc * next_next_next_
Token::Value SkipMagicComment(base::uc32 hash_or_at_sign)
static bool IsInvalid(base::uc32 c)
static constexpr base::uc32 kInvalidSequence
const TokenDesc & next_next() const
void PushBack(base::uc32 ch)
V8_INLINE void AddLiteralChar(base::uc32 c)
Token::Value ScanIdentifierOrKeywordInnerSlow(bool escaped, bool can_be_keyword)
bool IsDecimalNumberKind(NumberKind kind)
base::uc32 ScanUnicodeEscape()
bool CombineSurrogatePair()
base::uc32 ScanOctalEscape(base::uc32 c, int length)
Token::Value ScanString()
Token::Value ScanTemplateSpan()
const AstRawString * CurrentSymbol(AstValueFactory *ast_value_factory) const
base::Vector< const uint8_t > literal_one_byte_string() const
Token::Value ScanNumber(bool seen_period)
LiteralBuffer source_mapping_url_
const Location & location() const
const char * CurrentLiteralAsCString(Zone *zone) const
base::Vector< const uint8_t > next_literal_one_byte_string() const
Token::Value SkipMultiLineComment()
DirectHandle< String > SourceMappingUrl(IsolateT *isolate) const
Token::Value SkipSingleHTMLComment()
V8_INLINE void AddRawLiteralChar(base::uc32 c)
Utf16CharacterStream *const source_
const AstRawString * CurrentRawSymbol(AstValueFactory *ast_value_factory) const
base::Vector< const uint16_t > next_literal_two_byte_string() const
bool ScanDecimalAsSmiWithNumericSeparators(uint64_t *value)
base::Vector< const uint8_t > raw_literal_one_byte_string() const
V8_INLINE void AdvanceUntil(FunctionType check)
@ DECIMAL_WITH_LEADING_ZERO
Token::Value PeekAheadAhead()
bool is_next_literal_one_byte() const
base::uc32 ScanUnlimitedLengthHexNumber(base::uc32 max_value, int beg_pos)
TokenDesc token_storage_[4]
UnoptimizedCompileFlags flags_
Scanner(Utf16CharacterStream *source, UnoptimizedCompileFlags flags)
LiteralBuffer source_url_
DirectHandle< String > SourceUrl(IsolateT *isolate) const
base::uc32 ScanIdentifierUnicodeEscape()
MessageTemplate scanner_error_
bool is_raw_literal_one_byte() const
bool ScanDigitsWithNumericSeparators(bool(*predicate)(base::uc32 ch), bool is_check_first_digit)
static constexpr base::uc32 kEndOfInput
std::optional< RegExpFlags > ScanRegExpFlags()
const TokenDesc & next_next_next() const
std::vector< int > per_function_compile_hint_positions_
const AstRawString * NextSymbol(AstValueFactory *ast_value_factory) const
Location scanner_error_location_
bool ScanImplicitOctalDigits(int start_pos, NumberKind *kind)
Token::Value SkipSingleLineComment()
static const int kMaxAscii
bool saw_source_mapping_url_magic_comment_at_sign_
bool HasPerFunctionCompileHint(int position)
base::uc32 ScanHexNumber(int expected_length)
bool is_literal_one_byte() const
size_t per_function_compile_hint_positions_idx_
bool saw_magic_comment_compile_hints_all_
void SeekNext(size_t position)
bool ScanDecimalAsSmi(uint64_t *value, bool allow_numeric_separator)
static constexpr base::uc32 Invalid()
Token::Value ScanHtmlComment()
Token::Value ScanPrivateName()
void TryToParseMagicComment(base::uc32 hash_or_at_sign)
void ReportScannerError(const Location &location, MessageTemplate error)
bool ScanDecimalDigits(bool allow_numeric_separator)
const TokenDesc & current() const
static constexpr int kMaxValue
static const base::uc32 kMaxCodePoint
T * AllocateArray(size_t length)
ZoneVector< RpoNumber > & result
V8_INLINE bool IsStringLiteralLineTerminator(uchar c)
V8_INLINE bool IsLineTerminator(uchar c)
Vector< const uint8_t > StaticOneByteVector(const char(&array)[N])
constexpr bool IsInRange(T value, U lower_limit, U higher_limit)
int32_t VLQBase64Decode(const char *start, size_t sz, size_t *pos)
bool IsIdentifierStart(base::uc32 c)
constexpr bool IsHexDigit(base::uc32 c)
double OctalStringToDouble(base::Vector< const uint8_t > str)
double HexStringToDouble(base::Vector< const uint8_t > str)
constexpr bool IsCarriageReturn(base::uc32 c)
bool IsWhiteSpaceOrLineTerminator(base::uc32 c)
bool CharCanBeKeyword(base::uc32 c)
too high values may cause the compiler to set high thresholds for inlining to as much as possible avoid inlined allocation of objects that cannot escape trace load stores from virtual maglev objects use TurboFan fast string builder analyze liveness of environment slots and zap dead values trace TurboFan load elimination emit data about basic block usage in builtins to this enable builtin reordering when run mksnapshot flag for emit warnings when applying builtin profile data verify register allocation in TurboFan randomly schedule instructions to stress dependency tracking enable store store elimination in TurboFan rewrite far to near simulate GC compiler thread race related to allow float parameters to be passed in simulator mode JS Wasm Run additional turbo_optimize_inlined_js_wasm_wrappers enable experimental feedback collection in generic lowering enable Turboshaft s WasmLoadElimination enable Turboshaft s low level load elimination for JS enable Turboshaft s escape analysis for string concatenation use enable Turbolev features that we want to ship in the not too far future trace individual Turboshaft reduction steps trace intermediate Turboshaft reduction steps invocation count threshold for early optimization Enables optimizations which favor memory size over execution speed Enables sampling allocation profiler with X as a sample interval min size of a semi the new space consists of two semi spaces max size of the Collect garbage after Collect garbage after keeps maps alive for< n > old space garbage collections print one detailed trace line in name
double ImplicitOctalStringToDouble(base::Vector< const uint8_t > str)
static constexpr const uint8_t character_scan_flags[128]
constexpr bool IsOctalDigit(base::uc32 c)
double BinaryStringToDouble(base::Vector< const uint8_t > str)
constexpr bool IsNonOctalDecimalDigit(base::uc32 c)
bool MayTerminateString(uint8_t scan_flags)
bool IsWhiteSpace(base::uc32 c)
constexpr bool IsDecimalDigit(base::uc32 c)
V8_INLINE Token::Value KeywordOrIdentifierToken(const uint8_t *input, int input_length)
bool MultilineCommentCharacterNeedsSlowPath(uint8_t scan_flags)
constexpr bool IsBinaryDigit(base::uc32 c)
constexpr bool IsLineFeed(base::uc32 c)
constexpr int AsciiAlphaToLower(base::uc32 c)
bool IsIdentifierPart(base::uc32 c)
double StringToDouble(const char *str, ConversionFlag flags, double empty_string_val)
#define DCHECK_LE(v1, v2)
#define DCHECK_NOT_NULL(val)
#define DCHECK_NE(v1, v2)
#define DCHECK(condition)
#define DCHECK_EQ(v1, v2)
static Location invalid()
Location invalid_template_escape_location
LiteralBuffer literal_chars
MessageTemplate invalid_template_escape_message
LiteralBuffer raw_literal_chars
bool after_line_terminator
#define V8_LIKELY(condition)
#define V8_UNLIKELY(condition)