5#ifndef V8_PARSING_PARSER_BASE_H_
6#define V8_PARSING_PARSER_BASE_H_
36class PreParserIdentifier;
87 : scanner_(scanner), range_(range) {
95 range_->end = scanner_->location().end_pos;
117#define RETURN_IF_PARSE_ERROR \
118 if (has_error()) return impl()->NullStatement();
183template <
typename Impl>
200template <
typename Impl>
243 Impl*
impl() {
return static_cast<Impl*
>(
this); }
244 const Impl*
impl()
const {
return static_cast<const Impl*
>(
this); }
251 bool compile_hints_magic_enabled,
252 bool compile_hints_per_function_magic_enabled)
273 compile_hints_per_function_magic_enabled) {
334 class ClassLiteralChecker;
422 if ((anonymous && t->is_target_for_anonymous()) ||
425 impl()->GetRawNameFromIdentifier(
label)))) {
426 return t->statement();
429 return impl()->NullStatement();
435 if (!t->is_iteration())
continue;
437 DCHECK(t->is_target_for_anonymous());
439 impl()->GetRawNameFromIdentifier(
label))) {
440 return impl()->AsIterationStatement(t->statement());
443 return impl()->NullStatement();
488 : state_and_prev_value_(state, state->contains_function_or_eval_) {
489 state->contains_function_or_eval_ =
false;
492 bool found = state_and_prev_value_->contains_function_or_eval_;
494 state_and_prev_value_->contains_function_or_eval_ =
495 state_and_prev_value_.GetPayload();
506 : function_state_(function_state) {
507 function_state_->loop_nesting_depth_++;
613 constructor(parser->
impl()->NullExpression()) {}
644 int beg_pos,
int info_id) {
680 name(parser->
impl()->NullIdentifier()),
701 case Token::kRightBrace:
707 case Token::kLeftParen:
711 case Token::kSemicolon:
740 if (*labels ==
nullptr) {
743 zone()->template New<ZonePtrList<const AstRawString>>(1,
zone());
745 zone()->template New<ZonePtrList<const AstRawString>>(1,
zone());
747 if (*own_labels ==
nullptr) {
749 zone()->template New<ZonePtrList<const AstRawString>>(1,
zone());
759 if (labels !=
nullptr) {
760 for (
int i = labels->
length();
i-- > 0;) {
761 if (labels->
at(
i) ==
label)
return true;
809 std::string name =
".class-field-" + std::to_string(index);
815 std::string name =
".accessor-storage-" + std::to_string(index);
837 return zone()->template New<ClassScope>(
zone(), parent, is_anonymous);
861 return zone()->template New<Scope>(
zone(), parent, scope_type);
868 Zone* parse_zone =
nullptr)
const {
870 if (parse_zone ==
nullptr) parse_zone =
zone();
892 return factory()->ast_node_factory()->NewVariableProxy(
898 scanner()->location().beg_pos);
968 if (
V8_LIKELY(tok == Token::kSemicolon)) {
980 MessageTemplate::kAwaitNotInDebugEvaluate);
983 MessageTemplate::kAwaitNotInAsyncContext);
994 return peek() == Token::kIdentifier &&
1020 const char* fullname =
nullptr,
int pos = -1) {
1021 Expect(Token::kIdentifier);
1026 const char* full = fullname ==
nullptr
1027 ?
reinterpret_cast<const char*
>(name->raw_data())
1031 MessageTemplate::kInvalidEscapedMetaProperty,
1044 impl()->ReportUnexpectedToken(Token::kEscapedKeyword);
1049 if (
Check(Token::kIn)) {
1070 DCHECK_NE(message, MessageTemplate::kNone);
1071 impl()->ReportMessageAt(octal, message);
1073 if (message == MessageTemplate::kStrictDecimalWithLeadingZero) {
1085 if (!
scanner()->has_invalid_template_escape())
return true;
1089 impl()->ReportMessageAt(
scanner()->invalid_template_escape_location(),
1090 scanner()->invalid_template_escape_message());
1093 return should_throw;
1111 if (
impl()->IsEvalOrArguments(function_name)) {
1112 impl()->ReportMessageAt(function_name_loc,
1113 MessageTemplate::kStrictEvalArguments);
1117 impl()->ReportMessageAt(function_name_loc,
1118 MessageTemplate::kUnexpectedStrictReserved);
1131 impl()->SetLanguageMode(
scope(), old > mode ? old : mode);
1149 return flags().is_module() ||
1188 if (
v8_flags.js_explicit_resource_management) {
1189 switch (token_after_using) {
1190 case Token::kIdentifier:
1191 case Token::kStatic:
1198 case Token::kAccessor:
1202 return is_await_using;
1203 case Token::kFutureStrictReservedWord:
1204 case Token::kEscapedStrictReservedWord:
1219 return ((
peek() == Token::kUsing &&
1220 !
scanner()->HasLineTerminatorAfterNext() &&
1223 !
scanner()->HasLineTerminatorAfterNext() &&
1225 !
scanner()->HasLineTerminatorAfterNextNext() &&
1236 template <
typename... Ts>
1241 template <
typename... Ts>
1244 impl()->pending_error_handler()->ReportMessageAt(
1253 impl()->PreParserIdentifierToAstRawString(arg0));
1260 bool allow_duplicates) {
1261 if (!allow_duplicates) parameters.ValidateDuplicate(
impl());
1275 if (closure_scope == receiver_scope) {
1292 ParsePropertyInfo* prop_info);
1343 int seen_variables);
1356 int name_token_position);
1358 ParsePropertyInfo* prop_info,
ExpressionT* name_expression);
1360 ParsePropertyInfo* prop_info,
ExpressionT* name_expression,
1361 int* name_token_position);
1363 ClassInfo* class_info, ParsePropertyInfo* prop_info,
bool has_extends);
1367 bool* has_seen_constructor);
1369 int info_id,
bool is_static);
1372 ParsePropertyInfo* prop_info,
bool* has_seen_proto);
1405 int function_literal_id,
1406 bool could_be_immediately_invoked);
1411 bool name_is_strict_reserved,
1412 int class_token_pos);
1424 bool has_rest,
int formals_start_pos,
1425 int formals_end_pos);
1428 DeclarationParsingResult* parsing_result,
1434 bool default_export);
1437 bool default_export);
1439 bool default_export);
1461 bool allowed_catch_binding_var_redeclaration =
false;
1463 &allowed_catch_binding_var_redeclaration);
1464 if (allowed_catch_binding_var_redeclaration) {
1467 if (decl !=
nullptr) {
1475 impl()->ReportMessageAt(location, MessageTemplate::kVarRedeclaration,
1497 Scope* block_scope);
1535 int stmt_pos,
ExpressionT expression,
int lhs_beg_pos,
int lhs_end_pos,
1548 int stmt_pos,
StatementT init, ForInfo* for_info,
1567 int beg_pos,
int end_pos,
1574 if (!
impl()->IsIdentifier(expression))
return false;
1576 impl()->IsEvalOrArguments(
impl()->AsIdentifier(expression))) {
1612 return kFunctionKinds[sub_function_kind]
1632 if (
impl()->IsIdentifier(expression) &&
1633 impl()->IsEval(
impl()->AsIdentifier(expression)) && !is_optional_call) {
1655 return factory()->NewAsyncReturnStatement(expr,
pos, end_pos);
1657 return factory()->NewReturnStatement(expr,
pos, end_pos);
1680 :
parser_(parser), previous_accept_IN_(parser->accept_IN_) {
1681 parser_->accept_IN_ = accept_IN;
1695 parser_->parameters_ = parameters;
1708 :
parser_(parser), expression_scope_(
parser_->expression_scope_) {
1709 parser_->expression_scope_ =
nullptr;
1806template <
typename Impl>
1811 expected_property_count_(0),
1813 function_state_stack_(function_state_stack),
1814 outer_function_state_(*function_state_stack),
1817 next_function_is_likely_called_(false),
1818 previous_function_was_likely_called_(false),
1819 contains_function_or_eval_(false) {
1820 *function_state_stack =
this;
1828template <
typename Impl>
1830 *function_state_stack_ = outer_function_state_;
1833template <
typename Impl>
1838template <
typename Impl>
1844 scope()->ShouldBanArguments())) {
1846 MessageTemplate::kArgumentsDisallowedInInitializerAndStaticBlock);
1860 if (next == Token::kAwait) {
1863 scanner()->peek_location(), MessageTemplate::kAwaitBindingIdentifier);
1868template <
typename Impl>
1876 scope()->ShouldBanArguments())) {
1878 MessageTemplate::kArgumentsDisallowedInInitializerAndStaticBlock);
1879 return impl()->EmptyIdentifierString();
1887 return impl()->EmptyIdentifierString();
1890 if (next == Token::kAwait) {
1892 scanner()->location(), MessageTemplate::kAwaitBindingIdentifier);
1893 return impl()->GetIdentifier();
1898 scanner()->location(), MessageTemplate::kUnexpectedStrictReserved);
1899 return impl()->GetIdentifier();
1902template <
class Impl>
1909 flags().is_module() ||
1912 return impl()->EmptyIdentifierString();
1915 return impl()->GetIdentifier();
1918template <
typename Impl>
1926 MessageTemplate::kStrictEvalArguments);
1932template <
typename Impl>
1936 if (
peek() == Token::kColon)
return impl()->GetSymbol();
1937 return impl()->GetIdentifier();
1941 return impl()->EmptyIdentifierString();
1944template <
typename Impl>
1947 !
flags().is_repl_mode()) {
1951 while (current_scope !=
nullptr) {
1978template <
typename Impl>
1986 name =
impl()->GetSymbol();
1988 }
else if (next == Token::kPrivateName) {
1998 name =
impl()->GetIdentifier();
2001 if (private_name_scope_iter.
Done() &&
2004 MessageTemplate::kInvalidPrivateFieldResolution,
2005 impl()->GetRawNameFromIdentifier(name));
2006 return impl()->FailureExpression();
2009 impl()->ExpressionFromPrivateName(&private_name_scope_iter, name,
pos);
2012 return impl()->FailureExpression();
2014 impl()->PushLiteralName(name);
2018template <
typename Impl>
2023template <
typename Impl>
2031 const unsigned char* d =
pattern->raw_data();
2034 static_cast<const uint8_t*
>(d),
2035 pattern->length(), flags, regexp_error, no_gc);
2038 reinterpret_cast<const uint16_t*
>(d),
2039 pattern->length(), flags, regexp_error, no_gc);
2043template <
typename Impl>
2046 if (!
scanner()->ScanRegExpPattern()) {
2049 return impl()->FailureExpression();
2058 return impl()->FailureExpression();
2066 return impl()->FailureExpression();
2071template <
typename Impl>
2085 impl()->IsEvalOrArguments(name))) {
2087 MessageTemplate::kStrictEvalArguments);
2088 return impl()->FailureExpression();
2090 return impl()->ExpressionFromIdentifier(name, beg_pos);
2095 if (token == Token::kLeftBracket) {
2097 }
else if (token == Token::kLeftBrace) {
2101 return impl()->FailureExpression();
2107template <
typename Impl>
2138 !
scanner()->HasLineTerminatorBeforeNext() &&
2139 !
scanner()->literal_contains_escapes())) {
2160 parsing_scope.function_literal_id();
2167 return impl()->ExpressionFromIdentifier(name, beg_pos);
2171 return impl()->ExpressionFromLiteral(
Next(), beg_pos);
2178 case Token::kThis: {
2182 if (
peek() == Token::kPeriod ||
peek() == Token::kQuestionPeriod) {
2183 return impl()->ThisExpression();
2185 return impl()->NewThisExpression(beg_pos);
2188 case Token::kAssignDiv:
2192 case Token::kFunction:
2195 case Token::kSuper: {
2198 case Token::kImport:
2201 case Token::kLeftBracket:
2204 case Token::kLeftBrace:
2207 case Token::kLeftParen: {
2210 if (
Check(Token::kRightParen)) {
2222 return factory()->NewEmptyParentheses(beg_pos);
2225 bool could_be_immediately_invoked_arrow_function =
2233 if (
peek() == Token::kFunction ||
2234 (
peek() == Token::kAsync &&
PeekAhead() == Token::kFunction)) {
2239 expr->mark_parenthesized();
2240 Expect(Token::kRightParen);
2242 if (
peek() == Token::kArrow) {
2245 maybe_arrow.function_literal_id();
2247 could_be_immediately_invoked_arrow_function;
2250 maybe_arrow.ValidateExpression();
2256 case Token::kClass: {
2260 case Token::kTemplateSpan:
2261 case Token::kTemplateTail:
2265 if (
flags().allow_natives_syntax() ||
impl()->ParsingExtension()) {
2275 return impl()->FailureExpression();
2278template <
typename Impl>
2287template <
typename Impl>
2296template <
typename Impl>
2305template <
typename Impl>
2315 int variable_index = 0;
2326 list.Add(expression);
2331 if (!
Check(Token::kComma))
break;
2333 if (
peek() == Token::kRightParen &&
PeekAhead() == Token::kArrow) {
2340 if (
peek() == Token::kFunction &&
2351 return impl()->ExpressionListToExpression(list);
2354template <
typename Impl>
2370 return impl()->FailureExpression();
2377 return impl()->FailureExpression();
2385 if (
peek() != Token::kRightParen ||
PeekAhead() != Token::kArrow) {
2386 impl()->ReportUnexpectedTokenAt(ellipsis, Token::kEllipsis);
2387 return impl()->FailureExpression();
2391 return impl()->ExpressionListToExpression(*list);
2394template <
typename Impl>
2401 int first_spread_index = -1;
2406 while (!
Check(Token::kRightBracket)) {
2408 if (
peek() == Token::kComma) {
2409 elem =
factory()->NewTheHoleLiteral();
2410 }
else if (
Check(Token::kEllipsis)) {
2416 elem =
factory()->NewSpread(argument, start_pos, expr_pos);
2418 if (first_spread_index < 0) {
2419 first_spread_index = values.length();
2422 if (argument->IsAssignment()) {
2425 MessageTemplate::kInvalidDestructuringTarget);
2428 if (
peek() == Token::kComma) {
2431 MessageTemplate::kElementAfterRest);
2438 if (
peek() != Token::kRightBracket) {
2440 if (elem->IsFailureExpression())
return elem;
2444 return factory()->NewArrayLiteral(values, first_spread_index,
pos);
2447template <
class Impl>
2454 if (
Check(Token::kAsync)) {
2456 if ((token != Token::kMul &&
2458 scanner()->HasLineTerminatorBeforeNext()) {
2459 prop_info->
name =
impl()->GetIdentifier();
2460 impl()->PushLiteralName(prop_info->
name);
2464 impl()->ReportUnexpectedToken(Token::kEscapedKeyword);
2470 if (
Check(Token::kMul)) {
2479 prop_info->
name =
impl()->GetIdentifier();
2480 impl()->PushLiteralName(prop_info->
name);
2484 impl()->ReportUnexpectedToken(Token::kEscapedKeyword);
2486 if (token == Token::kGet) {
2488 }
else if (token == Token::kSet) {
2504 bool is_array_index;
2507 case Token::kPrivateName:
2509 is_array_index =
false;
2514 prop_info->
name =
impl()->GetIdentifier();
2519 return impl()->FailureExpression();
2523 case Token::kString:
2525 prop_info->
name =
peek() == Token::kColon ?
impl()->GetSymbol()
2526 :
impl()->GetIdentifier();
2527 is_array_index =
impl()->IsArrayIndex(prop_info->
name, &index);
2533 is_array_index =
true;
2535 prop_info->
name =
impl()->GetSymbol();
2538 case Token::kNumber: {
2540 prop_info->
name =
impl()->GetNumberAsSymbol();
2541 is_array_index =
impl()->IsArrayIndex(prop_info->
name, &index);
2545 case Token::kBigInt: {
2547 prop_info->
name =
impl()->GetBigIntAsSymbol();
2548 is_array_index =
impl()->IsArrayIndex(prop_info->
name, &index);
2552 case Token::kLeftBracket: {
2553 prop_info->
name =
impl()->NullIdentifier();
2558 Expect(Token::kRightBracket);
2565 case Token::kEllipsis:
2567 prop_info->
name =
impl()->NullIdentifier();
2578 MessageTemplate::kInvalidRestBindingPattern);
2581 MessageTemplate::kInvalidRestAssignmentPattern);
2584 if (
peek() != Token::kRightBrace) {
2586 scanner()->location(), MessageTemplate::kElementAfterRest);
2594 is_array_index =
false;
2601 impl()->PushLiteralName(prop_info->
name);
2602 return is_array_index ?
factory()->NewNumberLiteral(index,
pos)
2606template <
typename Impl>
2609 int name_token_position) {
2610 switch (prop_info->
kind) {
2618 impl()->ReportUnexpectedTokenAt(
2625template <
typename Impl>
2628 if (
peek() == Token::kLeftParen) {
2630 prop_info->
name =
impl()->GetIdentifier();
2634 if (
peek() == Token::kAssign ||
peek() == Token::kSemicolon ||
2635 peek() == Token::kRightBrace) {
2636 prop_info->
name =
impl()->GetIdentifier();
2643template <
typename Impl>
2646 int* name_token_position) {
2652 if (
scanner()->HasLineTerminatorBeforeNext()) {
2654 prop_info->
name =
impl()->GetIdentifier();
2663 *name_token_position);
2666template <
typename Impl>
2678 int name_token_position = property_beg_pos;
2680 if (name_token == Token::kStatic) {
2685 if (
v8_flags.js_decorators &&
peek() == Token::kAccessor) {
2687 &name_token_position)) {
2688 return impl()->NullLiteralProperty();
2694 }
else if (
v8_flags.js_decorators && name_token == Token::kAccessor) {
2696 &name_token_position)) {
2697 return impl()->NullLiteralProperty();
2703 switch (prop_info->
kind) {
2723 impl()->ReindexComputedMemberName(name_expression);
2730 class_info, property_beg_pos, next_info_id, prop_info->
is_static);
2737 result =
impl()->NewClassLiteralPropertyWithAccessorInfo(
2738 scope()->AsClassScope(), class_info, prop_info->
name,
2739 name_expression, value, prop_info->
is_static,
2749 impl()->SetFunctionNameFromPropertyName(
result, prop_info->
name);
2786 impl()->SetFunctionNameFromPropertyName(
result, prop_info->
name);
2802 name_expression =
factory()->NewStringLiteral(
2803 prop_info->
name, name_expression->position());
2823 name_expression, value, property_kind, prop_info->
is_static,
2828 impl()->SetFunctionNameFromPropertyName(
result, prop_info->
name, prefix);
2834 impl()->ReportUnexpectedTokenAt(
2837 return impl()->NullLiteralProperty();
2842template <
typename Impl>
2844 ClassInfo* class_info,
int beg_pos,
int info_id,
bool is_static) {
2851 if (
Check(Token::kAssign)) {
2864template <
typename Impl>
2883 return static_block;
2886template <
typename Impl>
2889 bool* has_seen_proto) {
2901 switch (prop_info->
kind) {
2905 DCHECK_EQ(Token::kEllipsis, name_token);
2910 return factory()->NewObjectLiteralProperty(
2911 factory()->NewTheHoleLiteral(), name_expression,
2918 scanner()->CurrentLiteralEquals(
"__proto__")) {
2919 if (*has_seen_proto) {
2921 scanner()->location(), MessageTemplate::kDuplicateProto);
2923 *has_seen_proto =
true;
2932 impl()->SetFunctionNameFromPropertyName(
result, name);
2948 return impl()->NullLiteralProperty();
2952 impl()->ExpressionFromIdentifier(name, next_loc.
beg_pos);
2955 next_loc, MessageTemplate::kStrictEvalArguments);
2959 if (
peek() == Token::kAssign) {
2964 value =
factory()->NewAssignment(Token::kAssign, lhs, rhs,
2966 impl()->SetFunctionNameFromIdentifierRef(rhs, lhs);
2970 MessageTemplate::kInvalidCoverInitializedName);
2977 impl()->SetFunctionNameFromPropertyName(
result, name);
2988 MessageTemplate::kInvalidDestructuringTarget);
2990 std::unique_ptr<BlockState> block_state;
2995 constexpr bool kIsStatic =
false;
3006 impl()->SetFunctionNameFromPropertyName(
result, name);
3017 MessageTemplate::kInvalidDestructuringTarget);
3024 factory()->NewStringLiteral(name, name_expression->position());
3027 std::unique_ptr<BlockState> block_state;
3042 name_expression, value,
3049 impl()->SetFunctionNameFromPropertyName(
result, name, prefix);
3057 return impl()->NullLiteralProperty();
3062template <
typename Impl>
3069 int number_of_boilerplate_properties = 0;
3071 bool has_computed_names =
false;
3072 bool has_rest_property =
false;
3073 bool has_seen_proto =
false;
3083 while (!
Check(Token::kRightBrace)) {
3090 if (
impl()->
IsNull(property))
return impl()->FailureExpression();
3093 has_computed_names =
true;
3097 has_rest_property =
true;
3100 if (
impl()->IsBoilerplateProperty(property) && !has_computed_names) {
3103 number_of_boilerplate_properties++;
3106 properties.Add(property);
3108 if (
peek() != Token::kRightBrace) {
3131 MessageTemplate::kTooManyArguments);
3134 return impl()->InitializeObjectLiteral(
3135 factory()->NewObjectLiteral(properties, number_of_boilerplate_properties,
3136 pos, has_rest_property, home_object));
3139template <
typename Impl>
3146 *has_spread =
false;
3150 int variable_index = 0;
3151 while (
peek() != Token::kRightParen) {
3153 bool is_spread =
Check(Token::kEllipsis);
3163 if (argument->IsAssignment()) {
3165 scanner()->location(), MessageTemplate::kRestDefaultInitializer);
3167 if (
peek() == Token::kComma) {
3169 scanner()->peek_location(), MessageTemplate::kParamAfterRest);
3175 argument =
factory()->NewSpread(argument, start_pos, expr_pos);
3177 args->Add(argument);
3182 if (!
Check(Token::kComma))
break;
3191 if (!
Check(Token::kRightParen)) {
3192 impl()->ReportMessageAt(location, MessageTemplate::kUnterminatedArgList);
3196template <
typename Impl>
3225template <
typename Impl>
3254template <
typename Impl>
3269 if (!
impl()->IsIdentifier(expression) && !expression->is_parenthesized()) {
3270 impl()->ReportMessageAt(
3272 MessageTemplate::kMalformedArrowFunParamList);
3273 return impl()->FailureExpression();
3281 parameters.set_strict_parameter_error(
3284 parameters.is_simple =
scope->has_simple_parameters();
3285 bool could_be_immediately_invoked =
3289 impl()->DeclareArrowFunctionFormalParameters(¶meters, expression, loc);
3296 impl()->ReindexArrowFunctionFormalParameters(¶meters);
3300 could_be_immediately_invoked);
3306 if (expression->is_parenthesized()) {
3309 MessageTemplate::kInvalidDestructuringTarget);
3312 }
else if (expression->IsProperty()) {
3315 MessageTemplate::kInvalidPropertyBindingPattern);
3317 }
else if (expression->IsPattern() && op == Token::kAssign) {
3319 if (expression->is_parenthesized()) {
3322 impl()->ReportMessageAt(loc,
3323 MessageTemplate::kInvalidDestructuringTarget);
3329 impl()->ReportMessageAt(loc, MessageTemplate::kInvalidLhsInAssignment);
3341 MessageTemplate::kInvalidLhsInAssignment, early_error);
3351 impl()->CheckAssigningFunctionLiteralToProperty(expression, right);
3356 if (right->IsCall() || right->IsCallNew()) {
3357 fni_.RemoveLastFunction();
3362 impl()->SetFunctionNameFromIdentifierRef(right, expression);
3364 fni_.RemoveLastFunction();
3367 if (op == Token::kAssign) {
3377 MessageTemplate::kInvalidDestructuringTarget);
3380 return factory()->NewAssignment(op, expression, right, op_position);
3383template <
typename Impl>
3390 scanner()->peek_location(), MessageTemplate::kYieldInParameter);
3393 impl()->ReportUnexpectedToken(Token::kEscapedKeyword);
3400 bool delegating =
false;
3401 if (!
scanner()->HasLineTerminatorBeforeNext()) {
3402 if (
Check(Token::kMul)) delegating =
true;
3405 case Token::kSemicolon:
3406 case Token::kRightBrace:
3407 case Token::kRightBracket:
3408 case Token::kRightParen:
3416 if (!delegating)
break;
3448template <
typename Impl>
3457 return peek() == Token::kConditional
3462template <
typename Impl>
3472 if (
peek() == Token::kAnd ||
peek() == Token::kOr) {
3482template <
typename Impl>
3494 bool first_nullish =
true;
3495 while (
peek() == Token::kNullish) {
3506 if (first_nullish) {
3508 factory()->NewBinaryOperation(Token::kNullish, expression,
y,
pos);
3509 impl()->RecordBinaryOperationSourceRange(expression, right_range);
3510 first_nullish =
false;
3512 impl()->CollapseNaryExpression(&expression,
y, Token::kNullish,
pos,
3519template <
typename Impl>
3522 int condition_pos) {
3532 bool else_found =
false;
3553 &condition_or_else_range);
3555 condition_or_else_expression =
3559 else_found = (
peek() != Token::kConditional);
3562 else_expression = condition_or_else_expression;
3570 else_expression, condition_pos);
3571 impl()->RecordConditionalSourceRange(expr, then_range, else_range);
3578 expr =
factory()->NewConditionalChain(1, condition_pos);
3581 impl()->CollapseConditionalChain(&expr,
condition, then_expression,
3582 else_expression, condition_pos,
3586 condition = condition_or_else_expression;
3587 condition_pos = condition_or_else_pos;
3589 }
while (!else_found);
3592 for (
const auto& else_range_beg_pos : else_ranges_beg_pos) {
3593 impl()->AppendConditionalChainElse(
3600template <
typename Impl>
3623 impl()->RecordConditionalSourceRange(expr, then_range, else_range);
3628template <
typename Impl>
3642 const bool is_right_associative = op == Token::kExp;
3643 const int next_prec = is_right_associative ? prec1 : prec1 + 1;
3657 case Token::kNotEqStrict:
3658 cmp = Token::kEqStrict;
3667 }
else if (!
impl()->ShortcutLiteralBinaryExpression(&
x,
y, op,
pos) &&
3668 !
impl()->CollapseNaryExpression(&
x,
y, op,
pos, right_range)) {
3671 if (op == Token::kOr || op == Token::kAnd) {
3672 impl()->RecordBinaryOperationSourceRange(
x, right_range);
3677 }
while (prec1 >= prec);
3683template <
typename Impl>
3693 if (
peek() != Token::kIn || prec1 < prec) {
3695 return impl()->FailureExpression();
3702 if (prec1 >= prec) {
3708template <
typename Impl>
3715 if (op == Token::kNot &&
peek() == Token::kFunction) {
3725 if (op == Token::kDelete) {
3729 return impl()->FailureExpression();
3732 if (
impl()->IsPrivateReference(expression)) {
3734 return impl()->FailureExpression();
3738 if (
peek() == Token::kExp) {
3739 impl()->ReportMessageAt(
3741 MessageTemplate::kUnexpectedTokenUnaryExponentiation);
3742 return impl()->FailureExpression();
3746 return impl()->BuildUnaryExpression(expression, op,
pos);
3752 if (
impl()->IsIdentifier(expression)) {
3756 const bool early_error =
false;
3759 MessageTemplate::kInvalidLhsInPrefixOp, early_error);
3762 return factory()->NewCountOperation(op,
true , expression,
3766template <
typename Impl>
3771 MessageTemplate::kAwaitExpressionFormalParameter);
3775 impl()->ReportUnexpectedToken(Token::kEscapedKeyword);
3784 if (
peek() == Token::kExp) {
3785 impl()->ReportMessageAt(
3787 MessageTemplate::kUnexpectedTokenUnaryExponentiation);
3788 return impl()->FailureExpression();
3797template <
typename Impl>
3821template <
typename Impl>
3830 scanner()->HasLineTerminatorBeforeNext())) {
3836template <
typename Impl>
3841 const bool early_error =
false;
3844 MessageTemplate::kInvalidLhsInPostfixOp, early_error);
3846 if (
impl()->IsIdentifier(expression)) {
3851 return factory()->NewCountOperation(next,
false , expression,
3855template <
typename Impl>
3866template <
typename Impl>
3872 scanner()->current_token() == Token::kAsync &&
3873 !
scanner()->HasLineTerminatorBeforeNext() &&
3874 !
scanner()->literal_contains_escapes())) {
3886 fni_.RemoveAsyncKeywordFromEnd();
3889 maybe_arrow.function_literal_id();
3895 result->mark_parenthesized();
3901 maybe_arrow.ValidateExpression();
3903 fni_.RemoveLastFunction();
3907 bool optional_chaining =
false;
3908 bool is_optional =
false;
3909 int optional_link_begin;
3912 case Token::kQuestionPeriod: {
3915 return impl()->FailureExpression();
3919 Consume(Token::kQuestionPeriod);
3921 optional_chaining =
true;
3930 case Token::kLeftBracket: {
3936 Expect(Token::kRightBracket);
3941 case Token::kPeriod: {
3944 return impl()->FailureExpression();
3954 case Token::kLeftParen: {
3970 if (
result->IsFunctionLiteral()) {
3971 result->AsFunctionLiteral()->SetShouldEagerCompile();
3985 int eval_scope_info_index = 0;
3991 eval_scope_info_index, is_optional);
3993 fni_.RemoveLastFunction();
3999 if (optional_chaining) {
4000 impl()->ReportMessageAt(
scanner()->peek_location(),
4001 MessageTemplate::kOptionalChainingNoTemplate);
4002 return impl()->FailureExpression();
4011 impl()->RecordExpressionSourceRange(
result, chain_link_range);
4012 is_optional =
false;
4015 if (optional_chaining)
return factory()->NewOptionalChain(
result);
4019template <
typename Impl>
4052 if (
peek() == Token::kImport) {
4054 if (
result->IsImportCallExpression()) {
4057 MessageTemplate::kImportCallNotNewExpression);
4058 return impl()->FailureExpression();
4060 }
else if (
peek() == Token::kPeriod) {
4065 if (
result->IsSuperCallReference()) {
4068 MessageTemplate::kUnexpectedSuper);
4069 return impl()->FailureExpression();
4072 if (
peek() == Token::kLeftParen) {
4085 if (
peek() == Token::kQuestionPeriod) {
4086 impl()->ReportMessageAt(
scanner()->peek_location(),
4087 MessageTemplate::kOptionalChainingNoNew);
4088 return impl()->FailureExpression();
4096template <
typename Impl>
4100 int function_token_position =
position();
4110 if (
impl()->ParsingDynamicFunctionDeclaration()) {
4123 name, function_name_location,
4126 function_kind, function_token_position, function_syntax_kind,
4133template <
typename Impl>
4153template <
typename Impl>
4168 if (
Check(Token::kPeriod)) {
4169 if (
v8_flags.js_source_phase_imports &&
4177 MessageTemplate::kImportMetaOutsideModule);
4178 return impl()->FailureExpression();
4180 return impl()->ImportMetaExpression(
pos);
4185 if (!
flags().is_module()) {
4187 MessageTemplate::kImportOutsideModule);
4191 return impl()->FailureExpression();
4195 if (
peek() == Token::kRightParen) {
4197 MessageTemplate::kImportMissingSpecifier);
4198 return impl()->FailureExpression();
4208 if (
v8_flags.harmony_import_attributes &&
4210 if (
Check(Token::kRightParen)) {
4212 return factory()->NewImportCallExpression(specifier, phase,
pos);
4215 Check(Token::kComma);
4217 Expect(Token::kRightParen);
4218 return factory()->NewImportCallExpression(specifier, phase,
4219 import_options,
pos);
4223 Expect(Token::kRightParen);
4224 return factory()->NewImportCallExpression(specifier, phase,
pos);
4227template <
typename Impl>
4238 if (
peek() == Token::kPeriod &&
PeekAhead() == Token::kPrivateName) {
4242 impl()->ReportMessage(MessageTemplate::kUnexpectedPrivateField);
4243 return impl()->FailureExpression();
4245 if (
peek() == Token::kQuestionPeriod) {
4246 Consume(Token::kQuestionPeriod);
4247 impl()->ReportMessage(MessageTemplate::kOptionalChainingNoSuper);
4248 return impl()->FailureExpression();
4250 scope->RecordSuperPropertyUsage();
4252 return impl()->NewSuperPropertyReference(
pos);
4262 return impl()->NewSuperCallReference(
pos);
4267 MessageTemplate::kUnexpectedSuper);
4268 return impl()->FailureExpression();
4271template <
typename Impl>
4281 MessageTemplate::kUnexpectedNewTarget);
4282 return impl()->FailureExpression();
4285 return impl()->NewTargetExpression(
pos);
4288template <
typename Impl>
4296 case Token::kLeftBracket: {
4301 expression =
factory()->NewProperty(expression, index,
pos);
4302 impl()->PushPropertyName(index);
4303 Expect(Token::kRightBracket);
4306 case Token::kPeriod: {
4316 if (
scanner()->current_token() == Token::kIdentifier) {
4320 if (expression->IsFunctionLiteral()) {
4323 expression->AsFunctionLiteral()->SetShouldEagerCompile();
4334template <
typename Impl>
4345 parameters->is_simple =
false;
4349 if (
Check(Token::kAssign)) {
4350 parameters->is_simple =
false;
4352 if (parameters->has_rest) {
4359 impl()->SetFunctionNameFromIdentifierRef(initializer,
pattern);
4364 for (; declaration_it != declaration_end; ++declaration_it) {
4365 Variable* var = declaration_it->var();
4381 parameters->has_rest);
4384template <
typename Impl>
4400 if (
peek() != Token::kRightParen) {
4402 parameters->has_rest =
Check(Token::kEllipsis);
4405 if (parameters->has_rest) {
4406 parameters->is_simple =
false;
4407 if (
peek() == Token::kComma) {
4408 impl()->ReportMessageAt(
scanner()->peek_location(),
4409 MessageTemplate::kParamAfterRest);
4414 if (!
Check(Token::kComma))
break;
4415 if (
peek() == Token::kRightParen) {
4427 impl()->DeclareFormalParameters(parameters);
4430template <
typename Impl>
4474 DCHECK(
peek() != Token::kLeftBracket &&
peek() != Token::kLeftBrace);
4488 DCHECK(
peek() != Token::kLeftBracket &&
peek() != Token::kLeftBrace);
4503 auto declaration_it = target_scope->
declarations()->end();
4519 impl()->IsEvalOrArguments(name))) {
4521 MessageTemplate::kStrictEvalArguments);
4524 if (
peek() == Token::kAssign ||
4529 pattern =
impl()->ExpressionFromIdentifier(name, decl_pos);
4532 impl()->DeclareIdentifier(name, decl_pos);
4537 name =
impl()->NullIdentifier();
4543 MessageTemplate::kDeclarationMissingInitializer,
4552 if (
Check(Token::kAssign)) {
4567 if (!value->IsCall() && !value->IsCallNew()) {
4570 fni_.RemoveLastFunction();
4574 impl()->SetFunctionNameFromIdentifierRef(value,
pattern);
4601 impl()->ReportMessageAt(
4603 MessageTemplate::kDeclarationMissingInitializer,
4617 auto declaration_end = target_scope->
declarations()->end();
4618 for (; declaration_it != declaration_end; ++declaration_it) {
4619 declaration_it->var()->set_initializer_position(initializer_position);
4631 }
while (
Check(Token::kComma));
4637template <
typename Impl>
4644 if (
Check(Token::kMul)) {
4645 impl()->ReportMessageAt(
4647 MessageTemplate::kGeneratorInSingleStatementContext);
4648 return impl()->NullStatement();
4653template <
typename Impl>
4661 if (
Check(Token::kMul)) {
4667template <
typename Impl>
4671 bool default_export) {
4696 if (
peek() == Token::kLeftParen) {
4697 if (default_export) {
4698 impl()->GetDefaultStrings(&name, &variable_name);
4702 return impl()->NullStatement();
4709 variable_name =
name;
4713 impl()->PushEnclosingName(name);
4718 name,
scanner()->location(), name_validity, function_kind,
pos,
4738 return impl()->DeclareFunction(variable_name, function, mode,
kind,
pos,
4742template <
typename Impl>
4767 if (default_export &&
4768 (
peek() == Token::kExtends ||
peek() == Token::kLeftBrace)) {
4769 impl()->GetDefaultStrings(&name, &variable_name);
4772 variable_name =
name;
4777 is_strict_reserved, class_token_pos);
4778 no_expression_scope.ValidateExpression();
4780 return impl()->DeclareClass(variable_name, value, names, class_token_pos,
4788template <
typename Impl>
4797 Expect(Token::kLeftParen);
4798 if (
peek() != Token::kRightParen) {
4801 }
while (
Check(Token::kComma));
4803 Expect(Token::kRightParen);
4804 Expect(Token::kSemicolon);
4805 return impl()->DeclareNative(name,
pos);
4808template <
typename Impl>
4817 impl()->ReportUnexpectedToken(Token::kEscapedKeyword);
4826template <
typename Impl>
4842 body->Add(
impl()->BuildParameterInitializationBlock(parameters));
4865 : Token::kRightBrace;
4868 impl()->ParseAsyncGeneratorFunctionBody(
pos,
kind, &inner_body);
4870 impl()->ParseGeneratorFunctionBody(
pos,
kind, &inner_body);
4890 bool allow_duplicate_parameters =
false;
4897 impl()->InsertSloppyBlockFunctionVarBindings(function_scope);
4899 allow_duplicate_parameters =
4908 impl()->InsertSloppyBlockFunctionVarBindings(inner_scope);
4914 inner_body.Rewind();
4915 inner_body.Add(inner_block);
4916 inner_block->set_scope(inner_scope);
4918 if (!
impl()->HasCheckedSyntax()) {
4921 if (conflict !=
nullptr) {
4922 impl()->ReportVarRedeclarationIn(conflict, inner_scope);
4935 impl()->InsertShadowingVarBindingInitializers(inner_block);
4940 allow_duplicate_parameters);
4946 impl()->DeclareFunctionNameVar(function_name, function_syntax_kind,
4949 inner_body.MergeInto(body);
4952template <
typename Impl>
4956 int formals_start_pos,
4957 int formals_end_pos) {
4958 if (
impl()->HasCheckedSyntax())
return;
4960 if (param_count != 0) {
4961 impl()->ReportMessageAt(
4963 MessageTemplate::kBadGetterArity);
4966 if (param_count != 1) {
4967 impl()->ReportMessageAt(
4969 MessageTemplate::kBadSetterArity);
4972 impl()->ReportMessageAt(
4974 MessageTemplate::kBadSetterRestParameter);
4979template <
typename Impl>
4983 switch (next_next) {
4984 case Token::kLeftBrace:
4985 case Token::kLeftBracket:
4986 case Token::kIdentifier:
4987 case Token::kStatic:
4999 case Token::kAccessor:
5002 case Token::kFutureStrictReservedWord:
5003 case Token::kEscapedStrictReservedWord:
5015template <
typename Impl>
5019 bool could_be_immediately_invoked) {
5022 ? RuntimeCallCounterId::kPreParseArrowFunctionLiteral
5023 : RuntimeCallCounterId::kParseArrowFunctionLiteral,
5024 RuntimeCallStats::kThreadSpecific);
5036 return impl()->FailureExpression();
5039 int expected_property_count = 0;
5040 int suspend_count = 0;
5043 int compile_hint_position = formal_parameters.scope->start_position();
5045 could_be_immediately_invoked ||
5053 eager_compile_hint =
5054 impl()->GetEmbedderCompileHint(eager_compile_hint, compile_hint_position);
5056 bool can_preparse =
impl()->parse_lazily() &&
5060 bool is_lazy_top_level_function =
5061 can_preparse &&
impl()->AllowsLazyParsingWithoutUnresolvedVariables();
5062 bool has_braces =
true;
5067 formal_parameters.scope);
5071 if (
peek() == Token::kLeftBrace) {
5075 if (is_lazy_top_level_function) {
5082 if (!formal_parameters.is_simple) {
5083 impl()->BuildParameterInitializationBlock(formal_parameters);
5089 int dummy_num_parameters = -1;
5090 int dummy_function_length = -1;
5092 bool did_preparse_successfully =
impl()->SkipFunction(
5094 formal_parameters.scope, &dummy_num_parameters,
5095 &dummy_function_length, &produced_preparse_data);
5099 if (did_preparse_successfully) {
5119 impl()->DeclareArrowFunctionFormalParameters(¶meters, expression,
5133 return impl()->FailureExpression();
5140 formal_parameters,
kind,
5150 formal_parameters,
kind,
5156 formal_parameters.scope->set_end_position(
end_position());
5167 impl()->EmptyIdentifierString(), formal_parameters.scope, body,
5168 expected_property_count, formal_parameters.num_parameters(),
5169 formal_parameters.function_length,
5172 formal_parameters.scope->start_position(), has_braces,
5173 function_literal_id, produced_preparse_data);
5175 function_literal->set_suspend_count(suspend_count);
5176 function_literal->set_function_token_position(
5177 formal_parameters.scope->start_position());
5179 impl()->RecordFunctionLiteralSourceRange(function_literal);
5180 impl()->AddFunctionForNameInference(function_literal);
5184 double ms = timer.Elapsed().InMillisecondsF();
5185 const char* event_name =
5186 is_lazy_top_level_function ?
"preparse-no-resolution" :
"parse";
5187 const char* name =
"arrow function";
5193 return function_literal;
5196template <
typename Impl>
5198 Scope* outer_scope) {
5202 bool is_strict_reserved_name =
false;
5207 is_strict_reserved_name =
5211 is_strict_reserved_name, class_token_pos);
5214template <
typename Impl>
5217 bool name_is_strict_reserved,
int class_token_pos) {
5218 bool is_anonymous =
impl()->IsEmptyIdentifier(name);
5221 if (!
impl()->HasCheckedSyntax() && !is_anonymous) {
5222 if (name_is_strict_reserved) {
5223 impl()->ReportMessageAt(class_name_location,
5224 MessageTemplate::kUnexpectedStrictReserved);
5225 return impl()->FailureExpression();
5227 if (
impl()->IsEvalOrArguments(name)) {
5228 impl()->ReportMessageAt(class_name_location,
5229 MessageTemplate::kStrictEvalArguments);
5230 return impl()->FailureExpression();
5244 if (
Check(Token::kExtends)) {
5249 scope.ValidateExpression();
5252 Expect(Token::kLeftBrace);
5259 if (unresolvable !=
nullptr) {
5262 MessageTemplate::kInvalidPrivateFieldResolution,
5264 return impl()->FailureExpression();
5279 bool should_save_class_variable_index =
5281 if (!class_info.
is_anonymous || should_save_class_variable_index) {
5282 impl()->DeclareClassVariable(class_scope, name, &class_info,
5284 if (should_save_class_variable_index) {
5290 return impl()->RewriteClassLiteral(class_scope, name, &class_info,
5294template <
typename Impl>
5297 int class_token_pos,
5299 bool has_extends = !
impl()->IsNull(class_info.
extends);
5301 while (
peek() != end_token) {
5302 if (
Check(Token::kSemicolon))
continue;
5305 if (
peek() == Token::kStatic &&
PeekAhead() == Token::kLeftBrace) {
5307 impl()->AddClassStaticBlock(static_block, &class_info);
5340 impl()->DeclarePrivateClassMember(
scope()->AsClassScope(), prop_info.
name,
5341 property, property_kind,
5343 impl()->InferFunctionName();
5358 impl()->DeclarePublicClassField(class_scope, property,
5361 impl()->InferFunctionName();
5369 impl()->AddInstanceFieldOrStaticElement(property, &class_info,
5375 impl()->InferFunctionName();
5382template <
typename Impl>
5393 impl()->ReportUnexpectedToken(Token::kEscapedKeyword);
5405 if (
impl()->ParsingDynamicFunctionDeclaration()) {
5428template <
typename Impl>
5441 DCHECK(
peek() == Token::kTemplateSpan ||
peek() == Token::kTemplateTail);
5449 bool forbid_illegal_escapes = !tagged;
5454 if (
peek() == Token::kTemplateTail) {
5455 Consume(Token::kTemplateTail);
5457 typename Impl::TemplateLiteralState ts =
impl()->OpenTemplateLiteral(
pos);
5459 impl()->AddTemplateSpan(&ts, is_valid,
true);
5460 return impl()->CloseTemplateLiteral(&ts,
start, tag);
5463 Consume(Token::kTemplateSpan);
5465 typename Impl::TemplateLiteralState ts =
impl()->OpenTemplateLiteral(
pos);
5467 impl()->AddTemplateSpan(&ts, is_valid,
false);
5480 impl()->AddTemplateExpression(&ts, expression);
5482 if (
peek() != Token::kRightBrace) {
5484 MessageTemplate::kUnterminatedTemplateExpr);
5485 return impl()->FailureExpression();
5495 impl()->AddTemplateSpan(&ts, is_valid, next == Token::kTemplateTail);
5496 }
while (next == Token::kTemplateSpan);
5500 return impl()->CloseTemplateLiteral(&ts,
start, tag);
5503template <
typename Impl>
5506 int beg_pos,
int end_pos,
5510 if (
impl()->IsIdentifier(expression)) {
5512 DCHECK(
impl()->IsEvalOrArguments(
impl()->AsIdentifier(expression)));
5515 MessageTemplate::kStrictEvalArguments);
5516 return impl()->FailureExpression();
5518 if (expression->IsCall() && !expression->AsCall()->is_tagged_template() &&
5522 MessageTemplate::kInvalidDestructuringTarget);
5531 return factory()->NewProperty(expression, error, beg_pos);
5537 return impl()->FailureExpression();
5540template <
typename Impl>
5543 if (
impl()->IsEvalOrArguments(parameter)) {
5549template <
typename Impl>
5553 accumulation_scope->Accumulate();
5554 if (parameter->is_parenthesized() ||
5555 !(
impl()->IsIdentifier(parameter) || parameter->IsPattern() ||
5556 parameter->IsAssignment())) {
5559 MessageTemplate::kInvalidDestructuringTarget);
5560 }
else if (
impl()->IsIdentifier(parameter)) {
5568template <
typename Impl>
5573template <
typename Impl>
5587 if (
result->is_parenthesized()) {
5590 MessageTemplate::kInvalidDestructuringTarget);
5598 MessageTemplate::kInvalidPropertyBindingPattern);
5599 if (
scope !=
nullptr)
scope->ValidateExpression();
5601 }
else if (
result->is_parenthesized() ||
5605 MessageTemplate::kInvalidDestructuringTarget);
5611template <
typename Impl>
5620 if (
peek() != Token::kLeftParen) {
5621 impl()->ReportUnexpectedToken(
peek());
5622 return impl()->FailureExpression();
5630 MessageTemplate::kIntrinsicWithSpread);
5631 return impl()->FailureExpression();
5637template <
typename Impl>
5644 while (
peek() == Token::kString) {
5645 bool use_strict =
false;
5646#if V8_ENABLE_WEBASSEMBLY
5647 bool use_asm =
false;
5652 if (
scanner()->NextLiteralExactlyEquals(
"use strict")) {
5654#if V8_ENABLE_WEBASSEMBLY
5655 }
else if (
scanner()->NextLiteralExactlyEquals(
"use asm")) {
5665 if (!
impl()->IsStringLiteral(stat))
break;
5670 if (!
scope()->HasSimpleParameters()) {
5674 impl()->ReportMessageAt(token_loc,
5675 MessageTemplate::kIllegalLanguageModeDirective,
5679#if V8_ENABLE_WEBASSEMBLY
5680 }
else if (use_asm) {
5682 impl()->SetAsmModule();
5692 while (
peek() != end_token) {
5695 if (stat->IsEmptyStatement())
continue;
5700template <
typename Impl>
5723 case Token::kFunction:
5737 if (!
v8_flags.js_explicit_resource_management)
break;
5739 if (!(
scanner()->HasLineTerminatorAfterNext()) &&
5745 if (!
v8_flags.js_explicit_resource_management)
break;
5748 if (!(
scanner()->HasLineTerminatorAfterNext()) &&
5750 !(
scanner()->HasLineTerminatorAfterNextNext()) &&
5757 !
scanner()->HasLineTerminatorAfterNext()) {
5768template <
typename Impl>
5800 case Token::kLeftBrace:
5802 case Token::kSemicolon:
5804 return factory()->EmptyStatement();
5816 case Token::kContinue:
5820 case Token::kReturn:
5837 result->InitializeStatements(statements,
zone());
5842 case Token::kSwitch:
5844 case Token::kFunction:
5850 impl()->ReportMessageAt(
scanner()->peek_location(),
5852 ? MessageTemplate::kStrictFunction
5853 : MessageTemplate::kSloppyFunction);
5854 return impl()->NullStatement();
5855 case Token::kDebugger:
5860 if (!
impl()->HasCheckedSyntax() &&
5861 !
scanner()->HasLineTerminatorAfterNext() &&
5863 impl()->ReportMessageAt(
5865 MessageTemplate::kAsyncFunctionInSingleStatementContext);
5866 return impl()->NullStatement();
5875template <
typename Impl>
5882 BlockT body =
factory()->NewBlock(
false, labels !=
nullptr);
5892 Expect(Token::kLeftBrace);
5894 while (
peek() != Token::kRightBrace) {
5897 if (stat->IsEmptyStatement())
continue;
5898 statements.Add(stat);
5901 Expect(Token::kRightBrace);
5906 impl()->RecordBlockSourceRange(body, end_pos);
5907 body->set_scope(
scope()->FinalizeBlockScope());
5910 body->InitializeStatements(statements,
zone());
5914template <
typename Impl>
5920template <
typename Impl>
5932 block->statements()->Add(body,
zone());
5934 block->set_scope(
scope()->FinalizeBlockScope());
5939template <
typename Impl>
5961 return impl()->BuildInitializationBlock(&parsing_result);
5964template <
typename Impl>
5979template <
typename Impl>
5995 case Token::kFunction:
5996 case Token::kLeftBrace:
6000 return impl()->NullStatement();
6006 if (next_next != Token::kLeftBracket &&
6007 ((next_next != Token::kLeftBrace &&
6008 next_next != Token::kIdentifier) ||
6012 impl()->ReportMessageAt(
scanner()->peek_location(),
6013 MessageTemplate::kUnexpectedLexicalDeclaration);
6014 return impl()->NullStatement();
6031 if (
peek() == Token::kColon && starts_with_identifier &&
6032 impl()->IsIdentifier(expr)) {
6037 impl()->DeclareLabel(&labels, &own_labels,
label->raw_name());
6057 if (
impl()->ParsingExtension() &&
peek() == Token::kFunction &&
6058 !
scanner()->HasLineTerminatorBeforeNext() &&
impl()->IsNative(expr) &&
6059 !
scanner()->literal_contains_escapes()) {
6065 if (expr->IsFailureExpression())
return impl()->NullStatement();
6066 return factory()->NewExpressionStatement(expr,
pos);
6069template <
typename Impl>
6077 Expect(Token::kLeftParen);
6079 Expect(Token::kRightParen);
6090 :
zone()->template New<ZonePtrList<const AstRawString>>(*labels,
6096 if (
Check(Token::kElse)) {
6100 else_statement =
factory()->EmptyStatement();
6104 impl()->RecordIfStatementSourceRange(stmt, then_range, else_range);
6108template <
typename Impl>
6118 if (!
scanner()->HasLineTerminatorBeforeNext() &&
6129 message = MessageTemplate::kNoIterationStatement;
6130 }
else if (
impl()->
IsNull(breakable_target)) {
6131 message = MessageTemplate::kUnknownLabel;
6134 return impl()->NullStatement();
6142template <
typename Impl>
6152 if (!
scanner()->HasLineTerminatorBeforeNext() &&
6162 return factory()->EmptyStatement();
6169 message = MessageTemplate::kUnknownLabel;
6172 return impl()->NullStatement();
6180template <
typename Impl>
6196 impl()->ReportMessageAt(loc, MessageTemplate::kIllegalReturn);
6197 return impl()->NullStatement();
6203 impl()->ReportMessageAt(loc, MessageTemplate::kIllegalReturn);
6204 return impl()->NullStatement();
6213 if (!
scanner()->HasLineTerminatorBeforeNext() &&
6226template <
typename Impl>
6237 return impl()->NullStatement();
6240 Expect(Token::kLeftParen);
6242 Expect(Token::kRightParen);
6252 return factory()->NewWithStatement(with_scope, expr, body,
pos);
6255template <
typename Impl>
6277 Expect(Token::kLeftParen);
6280 Expect(Token::kRightParen);
6286 Check(Token::kSemicolon);
6288 loop->Initialize(cond, body);
6289 impl()->RecordIterationStatementSourceRange(loop, body_range);
6294template <
typename Impl>
6309 Expect(Token::kLeftParen);
6311 Expect(Token::kRightParen);
6317 loop->Initialize(cond, body);
6318 impl()->RecordIterationStatementSourceRange(loop, body_range);
6323template <
typename Impl>
6330 if (
scanner()->HasLineTerminatorBeforeNext()) {
6332 return impl()->NullStatement();
6343template <
typename Impl>
6354 Expect(Token::kLeftParen);
6356 Expect(Token::kRightParen);
6358 auto switch_statement =
factory()->NewSwitchStatement(tag, switch_pos);
6367 bool default_seen =
false;
6368 Expect(Token::kLeftBrace);
6369 while (
peek() != Token::kRightBrace) {
6376 if (
Check(Token::kCase)) {
6382 return impl()->NullStatement();
6384 default_seen =
true;
6387 while (
peek() != Token::kCase &&
peek() != Token::kDefault &&
6388 peek() != Token::kRightBrace) {
6391 if (stat->IsEmptyStatement())
continue;
6392 statements.Add(stat);
6395 auto clause =
factory()->NewCaseClause(
label, statements);
6396 impl()->RecordCaseClauseSourceRange(clause, clause_range);
6397 switch_statement->cases()->Add(clause,
zone());
6399 Expect(Token::kRightBrace);
6403 impl()->RecordSwitchStatementSourceRange(switch_statement, end_pos);
6405 if (switch_scope !=
nullptr) {
6406 return impl()->RewriteSwitchStatement(switch_statement, switch_scope);
6408 return switch_statement;
6412template <
typename Impl>
6432 if (
peek() != Token::kCatch &&
peek() != Token::kFinally) {
6434 return impl()->NullStatement();
6442 if (
Check(Token::kCatch)) {
6444 has_binding =
Check(Token::kLeftParen);
6463 catch_info.
variable =
impl()->DeclareCatchVariableName(
6477 for (; declaration_it != declaration_end; ++declaration_it) {
6478 declaration_it->var()->set_initializer_position(
6479 initializer_position);
6483 catch_statements.Add(
impl()->RewriteCatchPattern(&catch_info));
6486 Expect(Token::kRightParen);
6489 catch_statements.Add(inner_block);
6492 if (!
impl()->HasCheckedSyntax()) {
6493 Scope* inner_scope = inner_block->scope();
6494 if (inner_scope !=
nullptr) {
6503 if (conflict !=
nullptr) {
6504 impl()->ReportVarRedeclarationIn(conflict, inner_scope);
6510 catch_block =
factory()->NewBlock(
false, catch_statements);
6511 catch_block->set_scope(
scope()->FinalizeBlockScope());
6527 if (
Check(Token::kFinally)) {
6533 return impl()->RewriteTryStatement(try_block, catch_block, catch_range,
6534 finally_block, finally_range, catch_info,
6538template <
typename Impl>
6555 Expect(Token::kLeftParen);
6557 bool starts_with_let =
peek() == Token::kLet;
6558 bool starts_with_using_or_await_using_keyword =
6561 starts_with_using_or_await_using_keyword) {
6587 if (starts_with_using_or_await_using_keyword &&
6590 MessageTemplate::kInvalidUsingInForInLoop);
6593 stmt_pos, &for_info, labels, own_labels, inner_block_scope);
6596 Expect(Token::kSemicolon);
6608 stmt_pos, init, &for_info, labels, own_labels);
6617 if (
peek() == Token::kVar) {
6625 own_labels,
scope());
6629 }
else if (
peek() != Token::kSemicolon) {
6632 int lhs_beg_pos = next_loc.
beg_pos;
6649 if ((starts_with_let || expression_is_async) &&
6651 impl()->ReportMessageAt(next_loc, starts_with_let
6652 ? MessageTemplate::kForOfLet
6653 : MessageTemplate::kForOfAsync);
6654 return impl()->NullStatement();
6656 if (expression->IsPattern()) {
6657 parsing_scope.ValidatePattern(expression, lhs_beg_pos, lhs_end_pos);
6659 expression = parsing_scope.ValidateAndRewriteReference(
6660 expression, lhs_beg_pos, lhs_end_pos);
6663 parsing_scope.ValidateExpression();
6669 stmt_pos, expression, lhs_beg_pos, lhs_end_pos, &for_info, labels,
6673 init =
factory()->NewExpressionStatement(expression, lhs_beg_pos);
6676 Expect(Token::kSemicolon);
6685 loop->Initialize(init, cond, next, body);
6689template <
typename Impl>
6697 MessageTemplate::kForInOfLoopMultiBindings,
6699 return impl()->NullStatement();
6705 !
impl()->IsIdentifier(
6708 MessageTemplate::kForInOfLoopInitializer,
6710 return impl()->NullStatement();
6713 BlockT init_block =
impl()->RewriteForVarInLegacy(*for_info);
6715 auto loop =
factory()->NewForEachStatement(for_info->
mode, stmt_pos);
6734 Expect(Token::kRightParen);
6747 impl()->RecordIterationStatementSourceRange(loop, body_range);
6749 impl()->DesugarBindingInForEachStatement(for_info, &body_block,
6751 body_block->statements()->Add(body,
zone());
6755 body_block->set_scope(
scope()->FinalizeBlockScope());
6759 loop->Initialize(each_variable, enumerable, body_block,
6760 enumerable_block_scope);
6762 init_block =
impl()->CreateForEachStatementTDZ(init_block, *for_info);
6766 init_block->statements()->Add(loop,
zone());
6769 init_block->set_scope(
scope()->FinalizeBlockScope());
6777template <
typename Impl>
6780 int stmt_pos,
ExpressionT expression,
int lhs_beg_pos,
int lhs_end_pos,
6783 auto loop =
factory()->NewForEachStatement(for_info->
mode, stmt_pos);
6794 Expect(Token::kRightParen);
6802 impl()->RecordIterationStatementSourceRange(loop, body_range);
6804 loop->Initialize(expression, enumerable, body,
nullptr);
6808template <
typename Impl>
6834 return impl()->DesugarLexicalBindingsInForStatement(
6835 loop, init, cond, next, body, inner_scope, *for_info);
6843 if (for_scope !=
nullptr) {
6856 block->statements()->Add(init,
zone());
6857 block->statements()->Add(loop,
zone());
6858 block->set_scope(for_scope);
6859 loop->Initialize(
impl()->NullStatement(), cond, next, body);
6863 loop->Initialize(init, cond, next, body);
6867template <
typename Impl>
6876 if (
peek() != Token::kSemicolon) {
6879 Expect(Token::kSemicolon);
6881 if (
peek() != Token::kRightParen) {
6883 *next =
factory()->NewExpressionStatement(exp, exp->position());
6885 Expect(Token::kRightParen);
6892 impl()->RecordIterationStatementSourceRange(loop, body_range);
6897template <
typename Impl>
6914 Expect(Token::kLeftParen);
6927 bool has_declarations =
false;
6931 bool starts_with_let =
peek() == Token::kLet;
6932 if (
peek() == Token::kVar ||
peek() == Token::kConst ||
6940 has_declarations =
true;
6952 MessageTemplate::kForInOfLoopMultiBindings,
6954 return impl()->NullStatement();
6960 MessageTemplate::kForInOfLoopInitializer,
6962 return impl()->NullStatement();
6968 if (starts_with_let) {
6969 impl()->ReportMessageAt(
scanner()->peek_location(),
6970 MessageTemplate::kForOfLet);
6971 return impl()->NullStatement();
6979 if (lhs->IsPattern()) {
6980 parsing_scope.ValidatePattern(lhs, lhs_beg_pos, lhs_end_pos);
6982 each_variable = parsing_scope.ValidateAndRewriteReference(
6983 lhs, lhs_beg_pos, lhs_end_pos);
6989 const bool kAllowIn =
true;
7002 Expect(Token::kRightParen);
7014 impl()->RecordIterationStatementSourceRange(loop, body_range);
7016 if (has_declarations) {
7018 impl()->DesugarBindingInForEachStatement(&for_info, &body_block,
7020 body_block->statements()->Add(body,
zone());
7021 body_block->set_scope(
scope()->FinalizeBlockScope());
7030 loop->Initialize(each_variable, iterable, body, iterable_block_scope);
7032 if (!has_declarations) {
7040 impl()->CreateForEachStatementTDZ(
impl()->NullBlock(), for_info);
7046 init_block->statements()->Add(loop,
zone());
7047 init_block->set_scope(for_scope);
7054template <
typename Impl>
7059 bool* has_seen_constructor) {
7064 if (
impl()->IdentifierEquals(name, avf->private_constructor_string())) {
7067 }
else if (is_static) {
7068 if (
impl()->IdentifierEquals(name, avf->prototype_string())) {
7072 }
else if (
impl()->IdentifierEquals(name, avf->constructor_string())) {
7075 ? MessageTemplate::kConstructorIsGenerator
7077 ? MessageTemplate::kConstructorIsAsync
7078 : MessageTemplate::kConstructorIsAccessor;
7082 if (*has_seen_constructor) {
7086 *has_seen_constructor =
true;
7091template <
typename Impl>
7094 if (is_static &&
impl()->IdentifierEquals(name, avf->prototype_string())) {
7099 if (
impl()->IdentifierEquals(name, avf->constructor_string()) ||
7100 impl()->IdentifierEquals(name, avf->private_constructor_string())) {
7106#undef RETURN_IF_PARSE_ERROR
@ kExplicitResourceManagement
@ kDecimalWithLeadingZeroInStrictMode
@ kAssigmentExpressionLHSIsCallInSloppy
@ kVarRedeclaredCatchBinding
@ kAssigmentExpressionLHSIsCallInStrict
const AstRawString * GetOneByteString(base::Vector< const uint8_t > literal)
Zone * single_parse_zone() const
bool should_save_class_variable_index() const
Variable * class_variable()
VariableProxy * ResolvePrivateNamesPartially()
Variable * DeclareBrandVariable(AstValueFactory *ast_value_factory, IsStaticFlag is_static_flag, int class_token_pos)
static const int kMaxArguments
FunctionKind function_kind() const
void set_has_this_reference()
void DeclareArguments(AstValueFactory *ast_value_factory)
bool has_simple_parameters() const
static const char * VisitModeString(VisitMode mode)
SourceTextModuleDescriptor * module() const
AcceptINScope(ParserBase *parser, bool accept_IN)
BlockState(Zone *zone, Scope **scope_stack)
BlockState(Scope **scope_stack, Scope *scope)
Scope **const scope_stack_
Scope *const outer_scope_
ExpressionScope * expression_scope_
FunctionParsingScope(Impl *parser)
FunctionOrEvalRecordingScope(FunctionState *state)
base::PointerWithPayload< FunctionState, bool, 1 > state_and_prev_value_
~FunctionOrEvalRecordingScope()
FunctionState * function_state_
LoopScope(FunctionState *function_state)
BailoutReason dont_optimize_reason_
void DisableOptimization(BailoutReason reason)
FunctionState(FunctionState **function_state_stack, Scope **scope_stack, DeclarationScope *scope)
BailoutReason dont_optimize_reason()
int loop_nesting_depth() const
int suspend_count() const
void RecordFunctionOrEvalCall()
bool next_function_is_likely_called() const
bool contains_function_or_eval() const
int expected_property_count_
void set_next_function_is_likely_called()
bool next_function_is_likely_called_
bool previous_function_was_likely_called() const
int expected_property_count()
bool previous_function_was_likely_called_
DeclarationScope * scope_
bool contains_function_or_eval_
FunctionKind kind() const
DeclarationScope * scope() const
FunctionState * outer_function_state_
Target ** target_stack_address()
FunctionState ** function_state_stack_
FormalParametersT * parent_parameters_
ParameterParsingScope(Impl *parser, FormalParametersT *parameters)
const BreakableStatementT statement() const
const TargetType target_type_
const BreakableStatementT statement_
const ZonePtrList< const AstRawString > *const labels_
const ZonePtrList< const AstRawString > * own_labels() const
const ZonePtrList< const AstRawString > * labels() const
Target(ParserBase *parser, BreakableStatementT statement, ZonePtrList< const AstRawString > *labels, ZonePtrList< const AstRawString > *own_labels, TargetType target_type)
bool is_target_for_anonymous() const
bool is_iteration() const
const Target * previous() const
const ZonePtrList< const AstRawString > *const own_labels_
Scanner * scanner() const
V8_INLINE void ParseStatementList(StatementListT *body, Token::Value end_token)
RuntimeCallStats * runtime_call_stats_
typename Types::Expression ExpressionT
ExpressionT ParseConditionalContinuation(ExpressionT expression, int pos)
bool is_generator() const
V8_INLINE ExpressionT ParseAssignmentExpression()
ExpressionT ParseExpressionCoverGrammar()
AstValueFactory * ast_value_factory_
FunctionKind FunctionKindForImpl(SubFunctionKind sub_function_kind, ParseFunctionFlags flags)
V8_NOINLINE void ReportMessageAt(Scanner::Location source_location, MessageTemplate message, const PreParserIdentifier &arg0)
DeclarationScope * GetReceiverScope() const
V8_INLINE DeclarationScope * GetDeclarationScope() const
BreakableStatementT LookupBreakTarget(IdentifierT label)
StatementT ParseThrowStatement()
StatementT ParseDebuggerStatement()
typename Types::StatementList StatementListT
V8_INLINE bool ParseCurrentSymbolAsClassFieldOrMethod(ParsePropertyInfo *prop_info, ExpressionT *name_expression)
bool IsParsingWhileDebugging() const
bool CheckInOrOf(ForEachStatement::VisitMode *visit_mode)
ExpressionT ParseFunctionExpression()
V8_INLINE ExpressionScope * expression_scope() const
ExpressionT ParseBindingPattern()
V8_INLINE Token::Value PeekAhead()
void ParseFormalParameterList(FormalParametersT *parameters)
IdentifierT ParseNonRestrictedIdentifier()
void CheckConflictingVarDeclarations(DeclarationScope *scope)
bool CheckContextualKeyword(Token::Value token)
typename v8::internal::ExpressionParsingScope< Types > ExpressionParsingScope
StatementT ParseNativeDeclaration()
StatementT ParseWhileStatement(ZonePtrList< const AstRawString > *labels, ZonePtrList< const AstRawString > *own_labels)
void ClassifyArrowParameter(AccumulationScope *accumulation_scope, int position, ExpressionT parameter)
StatementT ParseAsyncFunctionDeclaration(ZonePtrList< const AstRawString > *names, bool default_export)
int peek_end_position() const
StatementT ParseForStatement(ZonePtrList< const AstRawString > *labels, ZonePtrList< const AstRawString > *own_labels)
bool IsAssignableIdentifier(ExpressionT expression)
V8_INLINE ExpressionT ParseExpression()
V8_INLINE IdentifierT ParsePropertyName()
typename v8::internal::VariableDeclarationParsingScope< Types > VariableDeclarationParsingScope
bool stack_overflow() const
void ValidateFormalParameters(LanguageMode language_mode, const FormalParametersT ¶meters, bool allow_duplicates)
ExpressionT ParseArrowParametersWithRest(ExpressionListT *list, AccumulationScope *scope, int seen_variables)
void CheckStackOverflow()
VariableProxy * NewRawVariable(const AstRawString *name, int pos)
ExpressionT RewriteInvalidReferenceExpression(ExpressionT expression, int beg_pos, int end_pos, MessageTemplate message, bool early_error)
ExpressionT ParseLeftHandSideContinuation(ExpressionT expression)
void CheckStrictOctalLiteral(int beg_pos, int end_pos)
int PositionAfterSemicolon()
typename Types::Factory FactoryT
ExpressionT ParseAwaitExpression()
Scope * NewScopeWithParent(Scope *parent, ScopeType scope_type) const
typename Types::ForStatement ForStatementT
const AstRawString * ClassFieldVariableName(AstValueFactory *ast_value_factory, int index)
FunctionLiteral::EagerCompileHint default_eager_compile_hint_
StatementT ParseBreakStatement(ZonePtrList< const AstRawString > *labels)
FunctionState * function_state_
PendingCompilationErrorHandler * pending_error_handler()
V8_INLINE IdentifierT ParseAndClassifyIdentifier(Token::Value token)
typename Types::SourceRangeScope SourceRangeScope
V8_INLINE bool IsLet(const AstRawString *identifier) const
V8_NOINLINE void ReportMessage(MessageTemplate message, const Ts &... args)
ExpressionT ParseConditionalChainExpression(ExpressionT condition, int condition_pos)
bool has_module_in_scope_chain_
V8_INLINE bool IsExtraordinaryPrivateNameAccessAllowed() const
DeclarationScope * NewFunctionScope(FunctionKind kind, Zone *parse_zone=nullptr) const
void CheckFunctionName(LanguageMode language_mode, IdentifierT function_name, FunctionNameValidity function_name_validity, const Scanner::Location &function_name_loc)
IterationStatementT LookupContinueTarget(IdentifierT label)
V8_INLINE ExpressionT ParseMemberExpressionContinuation(ExpressionT expression)
V8_INLINE bool ParseAccessorPropertyOrAutoAccessors(ParsePropertyInfo *prop_info, ExpressionT *name_expression, int *name_token_position)
StatementT ParseScopedStatement(ZonePtrList< const AstRawString > *labels)
typename Types::ClassLiteralProperty ClassLiteralPropertyT
VariableMode GetVariableMode(ClassLiteralProperty::Kind kind)
ExpressionT ParseImportExpressions()
static bool IsAccessor(ParsePropertyKind kind)
ClassScope * NewClassScope(Scope *parent, bool is_anonymous) const
void Expect(Token::Value token)
void CheckClassMethodName(IdentifierT name, ParsePropertyKind type, ParseFunctionFlags flags, bool is_static, bool *has_seen_constructor)
StatementT ParseStatementListItem()
DeclarationScope * NewScriptScope(REPLMode repl_mode) const
internal::V8FileLogger * v8_file_logger_
ExpressionT ParseAsyncFunctionLiteral()
typename Types::SourceRange SourceRange
void set_default_eager_compile_hint(FunctionLiteral::EagerCompileHint eager_compile_hint)
V8_INLINE Token::Value peek()
ObjectLiteralPropertyT ParseObjectPropertyDefinition(ParsePropertyInfo *prop_info, bool *has_seen_proto)
ExpressionT ParseV8Intrinsic()
typename Types::FunctionLiteral FunctionLiteralT
bool IsAwaitAsIdentifierDisallowed(FunctionKind kind) const
V8_INLINE Token::Value PeekAheadAhead()
V8_INLINE ExpressionT ParseBinaryExpression(int prec)
bool parsing_on_main_thread_
V8_INLINE ExpressionT ParsePostfixExpression()
bool PeekContextualKeyword(const AstRawString *name)
bool PeekContextualKeyword(Token::Value token)
ExpressionT ParsePrimaryExpression()
ExpressionT ParseLogicalExpression()
std::vector< std::pair< VariableProxy *, int > > * variable_buffer()
const Impl * impl() const
void set_allow_eval_cache(bool allow)
V8_INLINE ExpressionT ParseConditionalExpression()
void CheckArityRestrictions(int param_count, FunctionKind function_type, bool has_rest, int formals_start_pos, int formals_end_pos)
typename Types::ClassStaticElementList ClassStaticElementListT
void set_stack_overflow()
bool compile_hints_magic_enabled_
V8_INLINE bool ClassifyPropertyIdentifier(Token::Value token, ParsePropertyInfo *prop_info)
StatementT ParseForEachStatementWithDeclarations(int stmt_pos, ForInfo *for_info, ZonePtrList< const AstRawString > *labels, ZonePtrList< const AstRawString > *own_labels, Scope *inner_block_scope)
std::vector< std::pair< VariableProxy *, int > > variable_buffer_
ClassLiteralPropertyT ParseClassPropertyDefinition(ClassInfo *class_info, ParsePropertyInfo *prop_info, bool has_extends)
typename Types::FuncNameInferrer FuncNameInferrer
bool is_using_allowed() const
NextArrowFunctionInfo next_arrow_function_info_
bool is_async_generator() const
ForStatementT ParseStandardForLoop(int stmt_pos, ZonePtrList< const AstRawString > *labels, ZonePtrList< const AstRawString > *own_labels, ExpressionT *cond, StatementT *next, StatementT *body)
typename Types::Identifier IdentifierT
V8_INLINE void Consume(Token::Value token)
StatementT ParseContinueStatement()
StatementT ParseReturnStatement()
SourceTextModuleDescriptor * module() const
typename v8::internal::AccumulationScope< Types > AccumulationScope
V8_INLINE bool VerifyCanHaveAutoAccessorOrThrow(ParsePropertyInfo *prop_info, ExpressionT name_expression, int name_token_position)
const UnoptimizedCompileFlags & flags() const
BlockT ParseBlock(ZonePtrList< const AstRawString > *labels, Scope *block_scope)
StatementT ParseFunctionDeclaration()
ExpressionT ParseMemberWithPresentNewPrefixesExpression()
ExpressionT ParseAssignmentExpressionCoverGrammar()
V8_INLINE Token::Value Next()
ExpressionT DoParseMemberExpressionContinuation(ExpressionT expression)
typename Types::Statement StatementT
const AstRawString * AutoAccessorVariableName(AstValueFactory *ast_value_factory, int index)
ExpressionT ParseProperty(ParsePropertyInfo *prop_info)
ExpressionT ParseObjectLiteral()
bool ValidateRegExpLiteral(const AstRawString *pattern, RegExpFlags flags, RegExpError *regexp_error)
typename Types::BreakableStatement BreakableStatementT
const UnoptimizedCompileFlags flags_
int peek_position() const
ExpressionT ParseTemplateLiteral(ExpressionT tag, int start, bool tagged)
StatementT ParseStatement(ZonePtrList< const AstRawString > *labels, ZonePtrList< const AstRawString > *own_labels)
ExpressionT ParseCoalesceExpression(ExpressionT expression)
bool has_module_in_scope_chain() const
VariableDeclarationContext
FunctionKind FunctionKindFor(ParseFunctionFlags flags)
int loop_nesting_depth() const
Types::Factory * factory()
V8_INLINE void ParseFormalParameter(FormalParametersT *parameters)
bool CheckContextualKeyword(const AstRawString *name)
ExpressionT ParseRegExpLiteral()
StatementT ParseStandardForLoopWithLexicalDeclarations(int stmt_pos, StatementT init, ForInfo *for_info, ZonePtrList< const AstRawString > *labels, ZonePtrList< const AstRawString > *own_labels)
void ExpectContextualKeyword(const AstRawString *name, const char *fullname=nullptr, int pos=-1)
ExpressionT ParseMemberInitializer(ClassInfo *class_info, int beg_pos, int info_id, bool is_static)
VariableProxy * NewUnresolved(const AstRawString *name)
AstValueFactory * ast_value_factory() const
bool is_async_function() const
PendingCompilationErrorHandler * pending_error_handler_
Scope * object_literal_scope_
void ParseArguments(ExpressionListT *args, bool *has_spread, ParsingArrowHeadFlag maybe_arrow=kCertainlyNotArrowHead)
V8_INLINE bool Check(Token::Value token)
void ParseFunctionBody(StatementListT *body, IdentifierT function_name, int pos, const FormalParametersT ¶meters, FunctionKind kind, FunctionSyntaxKind function_syntax_kind, FunctionBodyType body_type)
StatementT ParseClassDeclaration(ZonePtrList< const AstRawString > *names, bool default_export)
bool allow_eval_cache() const
ExpressionT ParseUnaryOrPrefixExpression()
V8_INLINE DeclarationScope * GetClosureScope() const
ExpressionT ParseClassExpression(Scope *outer_scope)
ExpressionT ParseClassLiteral(Scope *outer_scope, IdentifierT name, Scanner::Location class_name_location, bool name_is_strict_reserved, int class_token_pos)
bool TargetStackContainsLabel(const AstRawString *label)
bool MaybeParsingArrowhead() const
ExpressionT ParseSuperExpression()
void set_has_module_in_scope_chain()
int GetLastInfoId() const
bool is_await_as_identifier_disallowed() const
bool is_resumable() const
typename Types::ExpressionList ExpressionListT
typename Types::ObjectPropertyList ObjectPropertyListT
ParserBase(Zone *zone, Scanner *scanner, uintptr_t stack_limit, AstValueFactory *ast_value_factory, PendingCompilationErrorHandler *pending_error_handler, RuntimeCallStats *runtime_call_stats, V8FileLogger *v8_file_logger, UnoptimizedCompileFlags flags, bool parsing_on_main_thread, bool compile_hints_magic_enabled, bool compile_hints_per_function_magic_enabled)
typename v8::internal::ArrowHeadParsingScope< Types > ArrowHeadParsingScope
std::vector< void * > pointer_buffer_
bool ContainsLabel(const ZonePtrList< const AstRawString > *labels, const AstRawString *label)
void CheckClassFieldName(IdentifierT name, bool is_static)
bool IsValidReferenceExpression(ExpressionT expression)
StatementT ParseVariableStatement(VariableDeclarationContext var_context, ZonePtrList< const AstRawString > *names)
ExpressionT ParsePossibleDestructuringSubPattern(AccumulationScope *scope)
ExpressionT ParseArrayLiteral()
BlockT ParseClassStaticBlock(ClassInfo *class_info)
V8_INLINE IdentifierT ParseIdentifier(FunctionKind function_kind)
bool peek_any_identifier()
BlockT ParseBlock(ZonePtrList< const AstRawString > *labels)
const PendingCompilationErrorHandler * pending_error_handler() const
Scope * NewScope(ScopeType scope_type) const
ExpressionT ParseAssignmentExpressionCoverGrammarContinuation(int lhs_beg_pos, ExpressionT expression)
ExpressionT ParsePropertyOrPrivatePropertyName()
typename v8::internal::ExpressionScope< Types > ExpressionScope
StatementT ParseForEachStatementWithoutDeclarations(int stmt_pos, ExpressionT expression, int lhs_beg_pos, int lhs_end_pos, ForInfo *for_info, ZonePtrList< const AstRawString > *labels, ZonePtrList< const AstRawString > *own_labels)
V8_INLINE ExpressionT ParseUnaryExpression()
typename Types::Block BlockT
StatementT ParseHoistableDeclaration(ZonePtrList< const AstRawString > *names, bool default_export)
Types::Factory ast_node_factory_
bool is_await_allowed() const
DeclarationScope * NewEvalScope(Scope *parent) const
ExpressionT ParseNewTargetExpression()
ExpressionT ParseBinaryContinuation(ExpressionT x, int prec, int prec1)
bool ValidateRegExpFlags(RegExpFlags flags)
void RaiseLanguageMode(LanguageMode mode)
V8_INLINE ExpressionT ParseLeftHandSideExpression()
void DeclareLabel(ZonePtrList< const AstRawString > **labels, ZonePtrList< const AstRawString > **own_labels, const AstRawString *label)
V8_INLINE bool has_error() const
typename Types::ObjectLiteralProperty ObjectLiteralPropertyT
StatementT ParseForAwaitStatement(ZonePtrList< const AstRawString > *labels, ZonePtrList< const AstRawString > *own_labels)
StatementT BuildReturnStatement(ExpressionT expr, int pos, int end_pos=ReturnStatement::kFunctionLiteralReturnPosition)
StatementT ParseDoWhileStatement(ZonePtrList< const AstRawString > *labels, ZonePtrList< const AstRawString > *own_labels)
V8_NOINLINE void ReportMessageAt(Scanner::Location source_location, MessageTemplate message, const Ts &... args)
ExpressionT ParseConditionalChainAssignmentExpressionCoverGrammar()
typename Types::FuncNameInferrer::State FuncNameInferrerState
bool IsNextUsingKeyword(Token::Value token_after_using, bool is_await_using)
StatementT ParseIfStatement(ZonePtrList< const AstRawString > *labels)
V8_NOINLINE ExpressionT ParsePostfixContinuation(ExpressionT expression, int lhs_beg_pos)
void ParseClassLiteralBody(ClassInfo &class_info, IdentifierT name, int class_token_pos, Token::Value end_token)
StatementT ParseStatement(ZonePtrList< const AstRawString > *labels, ZonePtrList< const AstRawString > *own_labels, AllowLabelledFunctionStatement allow_function)
Scope * NewBlockScopeForObjectLiteral()
FormalParametersT * parameters_
V8_INLINE IdentifierT ParseIdentifier()
void SkipInfos(int delta)
bool CheckTemplateEscapes(bool should_throw)
StatementT ParseSwitchStatement(ZonePtrList< const AstRawString > *labels)
StatementT ParseWithStatement(ZonePtrList< const AstRawString > *labels)
V8_INLINE StatementT ParseTryStatement()
FunctionLiteral::EagerCompileHint default_eager_compile_hint() const
const AstRawString * GetNextSymbolForRegExpLiteral() const
typename Types::Suspend SuspendExpressionT
V8_NOINLINE void ReportUnexpectedToken(Token::Value token)
DeclarationScope * NewVarblockScope() const
int position_after_last_primary_expression_open_parenthesis_
ModuleScope * NewModuleScope(DeclarationScope *parent) const
void ExpectContextualKeyword(Token::Value token)
V8_INLINE ExpressionT ParseConditionalChainAssignmentExpression()
typename Types::ClassPropertyList ClassPropertyListT
V8_INLINE ExpressionT ParseMemberExpression()
bool CheckPossibleEvalCall(ExpressionT expression, bool is_optional_call, Scope *scope)
bool compile_hints_per_function_magic_enabled_
uintptr_t stack_limit() const
std::vector< void * > * pointer_buffer()
void ClassifyParameter(IdentifierT parameter, int beg_pos, int end_pos)
typename v8::internal::ParameterDeclarationParsingScope< Types > ParameterDeclarationParsingScope
LanguageMode language_mode()
VariableProxy * NewUnresolved(const AstRawString *name, int begin_pos, VariableKind kind=NORMAL_VARIABLE)
ClassLiteralProperty::Kind ClassPropertyKindFor(ParsePropertyKind kind)
ExpressionT ParseYieldExpression()
typename Types::IterationStatement IterationStatementT
StatementT ParseExpressionOrLabelledStatement(ZonePtrList< const AstRawString > *labels, ZonePtrList< const AstRawString > *own_labels, AllowLabelledFunctionStatement allow_function)
FunctionKind MethodKindFor(bool is_static, ParseFunctionFlags flags)
ExpressionT ParseArrowFunctionLiteral(const FormalParametersT ¶meters, int function_literal_id, bool could_be_immediately_invoked)
void ParseVariableDeclarations(VariableDeclarationContext var_context, DeclarationParsingResult *parsing_result, ZonePtrList< const AstRawString > *names)
typename Types::FormalParameters FormalParametersT
ExpressionScope * expression_scope_
void set_stack_limit(uintptr_t stack_limit)
bool IfStartsWithUsingOrAwaitUsingKeyword()
StatementT ParseHoistableDeclaration(int pos, ParseFunctionFlags flags, ZonePtrList< const AstRawString > *names, bool default_export)
static bool VerifySyntax(Zone *zone, uintptr_t stack_limit, const CharT *input, int input_length, RegExpFlags flags, RegExpError *regexp_error_out, const DisallowGarbageCollection &no_gc)
static V8_EXPORT_PRIVATE bool VerifyFlags(RegExpFlags flags)
static constexpr int kFunctionLiteralReturnPosition
Token::Value peek() const
void clear_invalid_template_escape_message()
bool SawMagicCommentCompileHintsAll() const
bool next_literal_contains_escapes() const
uint32_t smi_value() const
bool literal_contains_escapes() const
const Location & location() const
Token::Value current_token() const
V8_INLINE bool has_parser_error() const
Token::Value ScanTemplateContinuation()
bool HasLineTerminatorBeforeNext() const
Token::Value PeekAheadAhead()
V8_INLINE void set_parser_error()
MessageTemplate octal_message() const
std::optional< RegExpFlags > ScanRegExpFlags()
const AstRawString * NextSymbol(AstValueFactory *ast_value_factory) const
void clear_octal_position()
const Location & peek_location() const
bool HasPerFunctionCompileHint(int position)
Location octal_position() const
bool HasLineTerminatorAfterNext()
void Reparent(DeclarationScope *new_parent)
void set_is_block_scope_for_object_literal()
void SetLanguageMode(LanguageMode language_mode)
void set_end_position(int statement_pos)
base::ThreadedList< Declaration > * declarations()
Scope * outer_scope() const
DeclarationScope * AsDeclarationScope()
VariableProxy * NewUnresolved(AstNodeFactory *factory, const AstRawString *name, int start_pos, VariableKind kind=NORMAL_VARIABLE)
ClassScope * AsClassScope()
ModuleScope * AsModuleScope()
DeclarationScope * GetReceiverScope()
void DeleteUnresolved(VariableProxy *var)
Variable * DeclareHomeObjectVariable(AstValueFactory *ast_value_factory)
Variable * DeclareCatchVariableName(const AstRawString *name)
ScopeType scope_type() const
Variable * DeclareStaticHomeObjectVariable(AstValueFactory *ast_value_factory)
DeclarationScope * GetClosureScope()
bool has_await_using_declaration() const
bool needs_home_object() const
const AstRawString * FindVariableDeclaredIn(Scope *scope, VariableMode mode_limit)
void set_start_position(int statement_pos)
Scope * FinalizeBlockScope()
DeclarationScope * GetDeclarationScope()
LanguageMode language_mode() const
int start_position() const
bool is_module_scope() const
bool is_declaration_scope() const
Variable * LookupLocal(const AstRawString *name)
SourceRangeScope(const Scanner *scanner, SourceRange *range)
DISALLOW_IMPLICIT_CONSTRUCTORS(SourceRangeScope)
static bool IsArrowOrAssignmentOp(Value token)
static V8_INLINE bool IsValidIdentifier(Value token, LanguageMode language_mode, bool is_generator, bool disallow_await)
static bool IsAutoSemicolon(Value token)
static bool IsTemplate(Value token)
static bool IsAnyIdentifier(Value token)
static bool IsMember(Value token)
static bool IsCompareOp(Value op)
static bool IsLogicalAssignmentOp(Value token)
static bool IsUnaryOrCountOp(Value op)
static bool IsProperty(Value token)
static bool IsUnaryOp(Value op)
static bool IsCallable(Value token)
static bool IsLiteral(Value token)
static bool IsPropertyOrCall(Value token)
static bool IsCountOp(Value op)
static bool IsStrictReservedWord(Value token)
static bool IsPropertyName(Value token)
static int Precedence(Value token, bool accept_IN)
void FunctionEvent(const char *reason, int script_id, double time_delta_ms, int start_position, int end_position, Tagged< String > function_name)
const AstRawString * raw_name() const
void clear_maybe_assigned()
int initializer_position()
void set_initializer_position(int pos)
const AstRawString * raw_name() const
void ForceContextAllocation()
V8_INLINE int length() const
T & emplace_back(Args &&... args)
DeclarationScope * scope_
base::Vector< const DirectHandle< Object > > args
ZoneVector< RpoNumber > & result
constexpr bool IsInRange(T value, U lower_limit, U higher_limit)
bool IsArrowFunction(FunctionKind kind)
bool is_sloppy(LanguageMode language_mode)
constexpr int kNoSourcePosition
bool IsClassConstructor(FunctionKind kind)
bool IsLexicalVariableMode(VariableMode mode)
SharedFunctionInfo::HasStaticPrivateMethodsOrAccessorsBit SharedFunctionInfo::MaglevCompilationFailedBit syntax_kind
bool IsGeneratorFunction(FunctionKind kind)
bool IsDerivedConstructor(FunctionKind kind)
@ kPrivateGetterAndSetter
@ kLastLexicalVariableMode
bool IsResumableFunction(FunctionKind kind)
bool IsConciseMethod(FunctionKind kind)
bool IsAsyncFunction(FunctionKind kind)
bool IsAccessorFunction(FunctionKind kind)
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
bool IsImmutableLexicalVariableMode(VariableMode mode)
@ SLOPPY_BLOCK_FUNCTION_VARIABLE
bool IsAsyncGeneratorFunction(FunctionKind kind)
uintptr_t GetCurrentStackPosition()
bool IsModule(FunctionKind kind)
constexpr bool RegExpErrorIsStackOverflow(RegExpError error)
constexpr int kFunctionLiteralIdTopLevel
AllowLabelledFunctionStatement
@ kAllowLabelledFunctionStatement
@ kDisallowLabelledFunctionStatement
const char * RegExpErrorString(RegExpError error)
bool is_strict(LanguageMode language_mode)
@ kAutoAccessorClassField
V8_EXPORT_PRIVATE FlagValues v8_flags
bool IsGetterFunction(FunctionKind kind)
@ kFunctionNameIsStrictReserved
@ kFunctionNameValidityUnknown
@ kStaticConciseGeneratorMethod
@ kClassStaticInitializerFunction
@ kConciseGeneratorMethod
@ kAsyncConciseGeneratorMethod
@ kClassMembersInitializerFunction
@ kAsyncGeneratorFunction
@ kStaticAsyncConciseMethod
@ kStaticAsyncConciseGeneratorMethod
kInstanceDescriptorsOffset kTransitionsOrPrototypeInfoOffset IsNull(value)||IsJSProxy(value)||IsWasmObject(value)||(IsJSObject(value) &&(HeapLayout
bool IsSetterFunction(FunctionKind kind)
const char * ImmutableLexicalVariableModeToString(VariableMode mode)
#define RETURN_IF_PARSE_ERROR
RegExpParserImpl< CharT > *const parser_
#define DCHECK_NOT_NULL(val)
#define DCHECK_IMPLIES(v1, v2)
#define DCHECK_NE(v1, v2)
#define DCHECK_GE(v1, v2)
#define DCHECK(condition)
#define DCHECK_EQ(v1, v2)
CatchInfo(ParserBase *parser)
ClassPropertyListT public_members
Variable * static_home_object_variable
Variable * home_object_variable
bool has_static_computed_names
FunctionLiteralT constructor
bool has_static_elements() const
ClassStaticElementListT static_elements
DeclarationScope * EnsureInstanceMembersScope(ParserBase *parser, int beg_pos, int info_id)
DeclarationScope * EnsureStaticElementsScope(ParserBase *parser, int beg_pos, int info_id)
ClassPropertyListT instance_fields
bool has_instance_members() const
int instance_members_function_id
int static_elements_function_id
DeclarationScope * static_elements_scope
ClassInfo(ParserBase *parser)
bool has_static_private_methods_or_accessors
DeclarationScope * instance_members_scope
ClassPropertyListT private_members
bool has_seen_constructor
Declaration(ExpressionT pattern, ExpressionT initializer)
DeclarationDescriptor descriptor
Scanner::Location first_initializer_loc
Scanner::Location bindings_loc
std::vector< Declaration > declarations
DeclarationParsingResult()
ForEachStatement::VisitMode mode
ZonePtrList< const AstRawString > bound_names
DeclarationParsingResult parsing_result
ForInfo(ParserBase *parser)
void ClearStrictParameterError()
Scanner::Location strict_parameter_error_location
bool HasInitialState() const
MessageTemplate strict_parameter_error_message
bool could_be_immediately_invoked
bool ParsePropertyKindFromToken(Token::Value token)
PropertyPosition position
AccumulationScope * accumulation_scope
ParsePropertyInfo(ParserBase *parser, AccumulationScope *accumulation_scope=nullptr)
ParseFunctionFlags function_flags
static Location invalid()
static SourceRange ContinuationOf(const SourceRange &that, int end=kNoSourcePosition)
#define V8_LIKELY(condition)
#define V8_UNLIKELY(condition)