LCOV - code coverage report
Current view: top level - src/parsing - parser-base.h (source / functions) Hit Total Coverage
Test: app.info Lines: 1800 1816 99.1 %
Date: 2019-02-19 Functions: 269 270 99.6 %

          Line data    Source code
       1             : // Copyright 2012 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #ifndef V8_PARSING_PARSER_BASE_H_
       6             : #define V8_PARSING_PARSER_BASE_H_
       7             : 
       8             : #include <stdint.h>
       9             : #include <vector>
      10             : 
      11             : #include "src/ast/ast-source-ranges.h"
      12             : #include "src/ast/ast.h"
      13             : #include "src/ast/scopes.h"
      14             : #include "src/bailout-reason.h"
      15             : #include "src/base/flags.h"
      16             : #include "src/base/hashmap.h"
      17             : #include "src/base/v8-fallthrough.h"
      18             : #include "src/counters.h"
      19             : #include "src/function-kind.h"
      20             : #include "src/globals.h"
      21             : #include "src/log.h"
      22             : #include "src/message-template.h"
      23             : #include "src/parsing/expression-scope.h"
      24             : #include "src/parsing/func-name-inferrer.h"
      25             : #include "src/parsing/scanner.h"
      26             : #include "src/parsing/token.h"
      27             : #include "src/pointer-with-payload.h"
      28             : #include "src/zone/zone-chunk-list.h"
      29             : 
      30             : namespace v8 {
      31             : namespace internal {
      32             : 
      33             : enum FunctionNameValidity {
      34             :   kFunctionNameIsStrictReserved,
      35             :   kSkipFunctionNameCheck,
      36             :   kFunctionNameValidityUnknown
      37             : };
      38             : 
      39             : enum AllowLabelledFunctionStatement {
      40             :   kAllowLabelledFunctionStatement,
      41             :   kDisallowLabelledFunctionStatement,
      42             : };
      43             : 
      44             : enum ParsingArrowHeadFlag { kCertainlyNotArrowHead, kMaybeArrowHead };
      45             : 
      46             : enum class ParseFunctionFlag : uint8_t {
      47             :   kIsNormal = 0,
      48             :   kIsGenerator = 1 << 0,
      49             :   kIsAsync = 1 << 1
      50             : };
      51             : 
      52             : typedef base::Flags<ParseFunctionFlag> ParseFunctionFlags;
      53             : 
      54             : struct FormalParametersBase {
      55     5294883 :   explicit FormalParametersBase(DeclarationScope* scope) : scope(scope) {}
      56             : 
      57             :   int num_parameters() const {
      58             :     // Don't include the rest parameter into the function's formal parameter
      59             :     // count (esp. the SharedFunctionInfo::internal_formal_parameter_count,
      60             :     // which says whether we need to create an arguments adaptor frame).
      61     4321878 :     return arity - has_rest;
      62             :   }
      63             : 
      64     7948583 :   void UpdateArityAndFunctionLength(bool is_optional, bool is_rest) {
      65     7948583 :     if (!is_optional && !is_rest && function_length == arity) {
      66     7796783 :       ++function_length;
      67             :     }
      68     7948583 :     ++arity;
      69     7948583 :   }
      70             : 
      71             :   DeclarationScope* scope;
      72             :   bool has_rest = false;
      73             :   bool is_simple = true;
      74             :   int function_length = 0;
      75             :   int arity = 0;
      76             : };
      77             : 
      78             : // Stack-allocated scope to collect source ranges from the parser.
      79             : class SourceRangeScope final {
      80             :  public:
      81      189055 :   SourceRangeScope(const Scanner* scanner, SourceRange* range)
      82      189055 :       : scanner_(scanner), range_(range) {
      83     4130371 :     range_->start = scanner->peek_location().beg_pos;
      84             :     DCHECK_NE(range_->start, kNoSourcePosition);
      85             :     DCHECK_EQ(range_->end, kNoSourcePosition);
      86      189055 :   }
      87             : 
      88      189177 :   ~SourceRangeScope() {
      89             :     DCHECK_EQ(kNoSourcePosition, range_->end);
      90     4319740 :     range_->end = scanner_->location().end_pos;
      91             :     DCHECK_NE(range_->end, kNoSourcePosition);
      92      189177 :   }
      93             : 
      94             :  private:
      95             :   const Scanner* scanner_;
      96             :   SourceRange* range_;
      97             : 
      98             :   DISALLOW_IMPLICIT_CONSTRUCTORS(SourceRangeScope);
      99             : };
     100             : 
     101             : // ----------------------------------------------------------------------------
     102             : // The RETURN_IF_PARSE_ERROR macro is a convenient macro to enforce error
     103             : // handling for functions that may fail (by returning if there was an parser
     104             : // error).
     105             : //
     106             : // Usage:
     107             : //     foo = ParseFoo(); // may fail
     108             : //     RETURN_IF_PARSE_ERROR
     109             : //
     110             : //     SAFE_USE(foo);
     111             : 
     112             : #define RETURN_IF_PARSE_ERROR \
     113             :   if (has_error()) return impl()->NullStatement();
     114             : 
     115             : // Common base class template shared between parser and pre-parser.
     116             : // The Impl parameter is the actual class of the parser/pre-parser,
     117             : // following the Curiously Recurring Template Pattern (CRTP).
     118             : // The structure of the parser objects is roughly the following:
     119             : //
     120             : //   // A structure template containing type definitions, needed to
     121             : //   // avoid a cyclic dependency.
     122             : //   template <typename Impl>
     123             : //   struct ParserTypes;
     124             : //
     125             : //   // The parser base object, which should just implement pure
     126             : //   // parser behavior.  The Impl parameter is the actual derived
     127             : //   // class (according to CRTP), which implements impure parser
     128             : //   // behavior.
     129             : //   template <typename Impl>
     130             : //   class ParserBase { ... };
     131             : //
     132             : //   // And then, for each parser variant (e.g., parser, preparser, etc):
     133             : //   class Parser;
     134             : //
     135             : //   template <>
     136             : //   class ParserTypes<Parser> { ... };
     137             : //
     138             : //   class Parser : public ParserBase<Parser> { ... };
     139             : //
     140             : // The parser base object implements pure parsing, according to the
     141             : // language grammar.  Different parser implementations may exhibit
     142             : // different parser-driven behavior that is not considered as pure
     143             : // parsing, e.g., early error detection and reporting, AST generation, etc.
     144             : 
     145             : // The ParserTypes structure encapsulates the differences in the
     146             : // types used in parsing methods.  E.g., Parser methods use Expression*
     147             : // and PreParser methods use PreParserExpression.  For any given parser
     148             : // implementation class Impl, it is expected to contain the following typedefs:
     149             : //
     150             : // template <>
     151             : // struct ParserTypes<Impl> {
     152             : //   // Synonyms for ParserBase<Impl> and Impl, respectively.
     153             : //   typedef Base;
     154             : //   typedef Impl;
     155             : //   // Return types for traversing functions.
     156             : //   typedef Identifier;
     157             : //   typedef Expression;
     158             : //   typedef FunctionLiteral;
     159             : //   typedef ObjectLiteralProperty;
     160             : //   typedef ClassLiteralProperty;
     161             : //   typedef ExpressionList;
     162             : //   typedef ObjectPropertyList;
     163             : //   typedef ClassPropertyList;
     164             : //   typedef FormalParameters;
     165             : //   typedef Statement;
     166             : //   typedef StatementList;
     167             : //   typedef Block;
     168             : //   typedef BreakableStatement;
     169             : //   typedef ForStatement;
     170             : //   typedef IterationStatement;
     171             : //   // For constructing objects returned by the traversing functions.
     172             : //   typedef Factory;
     173             : //   // For other implementation-specific tasks.
     174             : //   typedef Target;
     175             : //   typedef TargetScope;
     176             : // };
     177             : 
     178             : template <typename Impl>
     179             : struct ParserTypes;
     180             : 
     181             : enum class ParsePropertyKind : uint8_t {
     182             :   kAccessorGetter,
     183             :   kAccessorSetter,
     184             :   kValue,
     185             :   kShorthand,
     186             :   kAssign,
     187             :   kMethod,
     188             :   kClassField,
     189             :   kShorthandOrClassField,
     190             :   kSpread,
     191             :   kNotSet
     192             : };
     193             : 
     194             : template <typename Impl>
     195     6707079 : class ParserBase {
     196             :  public:
     197             :   // Shorten type names defined by ParserTypes<Impl>.
     198             :   typedef ParserTypes<Impl> Types;
     199             :   typedef typename v8::internal::ExpressionScope<Types> ExpressionScope;
     200             :   typedef typename v8::internal::ExpressionParsingScope<Types>
     201             :       ExpressionParsingScope;
     202             :   typedef typename v8::internal::AccumulationScope<Types> AccumulationScope;
     203             :   typedef typename v8::internal::ArrowHeadParsingScope<Types>
     204             :       ArrowHeadParsingScope;
     205             :   typedef typename v8::internal::VariableDeclarationParsingScope<Types>
     206             :       VariableDeclarationParsingScope;
     207             :   typedef typename v8::internal::ParameterDeclarationParsingScope<Types>
     208             :       ParameterDeclarationParsingScope;
     209             : 
     210             :   // Return types for traversing functions.
     211             :   typedef typename Types::Block BlockT;
     212             :   typedef typename Types::BreakableStatement BreakableStatementT;
     213             :   typedef typename Types::ClassLiteralProperty ClassLiteralPropertyT;
     214             :   typedef typename Types::ClassPropertyList ClassPropertyListT;
     215             :   typedef typename Types::Expression ExpressionT;
     216             :   typedef typename Types::ExpressionList ExpressionListT;
     217             :   typedef typename Types::FormalParameters FormalParametersT;
     218             :   typedef typename Types::ForStatement ForStatementT;
     219             :   typedef typename Types::FunctionLiteral FunctionLiteralT;
     220             :   typedef typename Types::Identifier IdentifierT;
     221             :   typedef typename Types::IterationStatement IterationStatementT;
     222             :   typedef typename Types::ObjectLiteralProperty ObjectLiteralPropertyT;
     223             :   typedef typename Types::ObjectPropertyList ObjectPropertyListT;
     224             :   typedef typename Types::Statement StatementT;
     225             :   typedef typename Types::StatementList StatementListT;
     226             :   typedef typename Types::Suspend SuspendExpressionT;
     227             :   // For constructing objects returned by the traversing functions.
     228             :   typedef typename Types::Factory FactoryT;
     229             :   // Other implementation-specific tasks.
     230             :   typedef typename Types::FuncNameInferrer FuncNameInferrer;
     231             :   typedef typename Types::FuncNameInferrer::State FuncNameInferrerState;
     232             :   typedef typename Types::SourceRange SourceRange;
     233             :   typedef typename Types::SourceRangeScope SourceRangeScope;
     234             :   typedef typename Types::Target TargetT;
     235             :   typedef typename Types::TargetScope TargetScopeT;
     236             : 
     237             :   // All implementation-specific methods must be called through this.
     238   135503929 :   Impl* impl() { return static_cast<Impl*>(this); }
     239             :   const Impl* impl() const { return static_cast<const Impl*>(this); }
     240             : 
     241     3353502 :   ParserBase(Zone* zone, Scanner* scanner, uintptr_t stack_limit,
     242             :              v8::Extension* extension, AstValueFactory* ast_value_factory,
     243             :              PendingCompilationErrorHandler* pending_error_handler,
     244             :              RuntimeCallStats* runtime_call_stats, Logger* logger,
     245             :              int script_id, bool parsing_module, bool parsing_on_main_thread)
     246             :       : scope_(nullptr),
     247             :         original_scope_(nullptr),
     248             :         function_state_(nullptr),
     249             :         extension_(extension),
     250             :         fni_(ast_value_factory),
     251             :         ast_value_factory_(ast_value_factory),
     252             :         ast_node_factory_(ast_value_factory, zone),
     253             :         runtime_call_stats_(runtime_call_stats),
     254             :         logger_(logger),
     255             :         parsing_on_main_thread_(parsing_on_main_thread),
     256             :         parsing_module_(parsing_module),
     257             :         stack_limit_(stack_limit),
     258             :         pending_error_handler_(pending_error_handler),
     259             :         zone_(zone),
     260             :         expression_scope_(nullptr),
     261             :         scanner_(scanner),
     262             :         function_literal_id_(0),
     263             :         script_id_(script_id),
     264             :         default_eager_compile_hint_(FunctionLiteral::kShouldLazyCompile),
     265             :         allow_natives_(false),
     266             :         allow_harmony_public_fields_(false),
     267             :         allow_harmony_static_fields_(false),
     268             :         allow_harmony_dynamic_import_(false),
     269             :         allow_harmony_import_meta_(false),
     270             :         allow_harmony_private_fields_(false),
     271             :         allow_harmony_private_methods_(false),
     272    10975812 :         allow_eval_cache_(true) {
     273     3353303 :     pointer_buffer_.reserve(32);
     274     3353492 :     variable_buffer_.reserve(32);
     275     3353442 :   }
     276             : 
     277             : #define ALLOW_ACCESSORS(name)                           \
     278             :   bool allow_##name() const { return allow_##name##_; } \
     279             :   void set_allow_##name(bool allow) { allow_##name##_ = allow; }
     280             : 
     281     3353334 :   ALLOW_ACCESSORS(natives)
     282     3353304 :   ALLOW_ACCESSORS(harmony_public_fields)
     283     3353304 :   ALLOW_ACCESSORS(harmony_static_fields)
     284   109540607 :   ALLOW_ACCESSORS(harmony_dynamic_import)
     285     3353304 :   ALLOW_ACCESSORS(harmony_import_meta)
     286     3353304 :   ALLOW_ACCESSORS(harmony_private_methods)
     287     2860521 :   ALLOW_ACCESSORS(eval_cache)
     288             : 
     289             : #undef ALLOW_ACCESSORS
     290             : 
     291    33323172 :   V8_INLINE bool has_error() const { return scanner()->has_parser_error(); }
     292             :   bool allow_harmony_numeric_separator() const {
     293             :     return scanner()->allow_harmony_numeric_separator();
     294             :   }
     295     2957739 :   void set_allow_harmony_numeric_separator(bool allow) {
     296             :     scanner()->set_allow_harmony_numeric_separator(allow);
     297             :   }
     298             : 
     299      473919 :   bool allow_harmony_private_fields() const {
     300      473919 :     return scanner()->allow_harmony_private_fields();
     301             :   }
     302     3353304 :   void set_allow_harmony_private_fields(bool allow) {
     303             :     scanner()->set_allow_harmony_private_fields(allow);
     304             :   }
     305             : 
     306             :   uintptr_t stack_limit() const { return stack_limit_; }
     307             : 
     308             :   void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; }
     309             : 
     310             :   void set_default_eager_compile_hint(
     311             :       FunctionLiteral::EagerCompileHint eager_compile_hint) {
     312     2437590 :     default_eager_compile_hint_ = eager_compile_hint;
     313             :   }
     314             : 
     315             :   FunctionLiteral::EagerCompileHint default_eager_compile_hint() const {
     316             :     return default_eager_compile_hint_;
     317             :   }
     318             : 
     319        2467 :   int loop_nesting_depth() const {
     320    13100228 :     return function_state_->loop_nesting_depth();
     321             :   }
     322             : 
     323     5500085 :   int GetNextFunctionLiteralId() { return ++function_literal_id_; }
     324             :   int GetLastFunctionLiteralId() const { return function_literal_id_; }
     325             : 
     326     3218254 :   void SkipFunctionLiterals(int delta) { function_literal_id_ += delta; }
     327             : 
     328     4947928 :   void ResetFunctionLiteralId() { function_literal_id_ = 0; }
     329             : 
     330             :   // The Zone where the parsing outputs are stored.
     331     5984939 :   Zone* main_zone() const { return ast_value_factory()->zone(); }
     332             : 
     333             :   // The current Zone, which might be the main zone or a temporary Zone.
     334     1467720 :   Zone* zone() const { return zone_; }
     335             : 
     336             :  protected:
     337             :   friend class v8::internal::ExpressionScope<ParserTypes<Impl>>;
     338             :   friend class v8::internal::ExpressionParsingScope<ParserTypes<Impl>>;
     339             :   friend class v8::internal::ArrowHeadParsingScope<ParserTypes<Impl>>;
     340             : 
     341             :   enum VariableDeclarationContext {
     342             :     kStatementListItem,
     343             :     kStatement,
     344             :     kForStatement
     345             :   };
     346             : 
     347             :   class ClassLiteralChecker;
     348             : 
     349             :   // ---------------------------------------------------------------------------
     350             :   // BlockState and FunctionState implement the parser's scope stack.
     351             :   // The parser's current scope is in scope_. BlockState and FunctionState
     352             :   // constructors push on the scope stack and the destructors pop. They are also
     353             :   // used to hold the parser's per-funcion state.
     354             :   class BlockState {
     355             :    public:
     356      367118 :     BlockState(Scope** scope_stack, Scope* scope)
     357    23503278 :         : scope_stack_(scope_stack), outer_scope_(*scope_stack) {
     358    23508955 :       *scope_stack_ = scope;
     359      367118 :     }
     360             : 
     361     4659120 :     BlockState(Zone* zone, Scope** scope_stack)
     362             :         : BlockState(scope_stack,
     363     9318759 :                      new (zone) Scope(zone, *scope_stack, BLOCK_SCOPE)) {}
     364             : 
     365    23503661 :     ~BlockState() { *scope_stack_ = outer_scope_; }
     366             : 
     367             :    private:
     368             :     Scope** const scope_stack_;
     369             :     Scope* const outer_scope_;
     370             :   };
     371             : 
     372             :   class FunctionState final : public BlockState {
     373             :    public:
     374             :     FunctionState(FunctionState** function_state_stack, Scope** scope_stack,
     375             :                   DeclarationScope* scope);
     376             :     ~FunctionState();
     377             : 
     378   121456744 :     DeclarationScope* scope() const { return scope_->AsDeclarationScope(); }
     379             : 
     380     4595748 :     void AddProperty() { expected_property_count_++; }
     381             :     int expected_property_count() { return expected_property_count_; }
     382             : 
     383             :     void DisableOptimization(BailoutReason reason) {
     384        1734 :       dont_optimize_reason_ = reason;
     385             :     }
     386             :     BailoutReason dont_optimize_reason() { return dont_optimize_reason_; }
     387             : 
     388      476785 :     void AddSuspend() { suspend_count_++; }
     389             :     int suspend_count() const { return suspend_count_; }
     390       44591 :     bool CanSuspend() const { return suspend_count_ > 0; }
     391             : 
     392   242257539 :     FunctionKind kind() const { return scope()->function_kind(); }
     393             : 
     394             :     bool next_function_is_likely_called() const {
     395             :       return next_function_is_likely_called_;
     396             :     }
     397             : 
     398             :     bool previous_function_was_likely_called() const {
     399             :       return previous_function_was_likely_called_;
     400             :     }
     401             : 
     402             :     void set_next_function_is_likely_called() {
     403      610459 :       next_function_is_likely_called_ = !FLAG_max_lazy;
     404             :     }
     405             : 
     406     5792518 :     void RecordFunctionOrEvalCall() { contains_function_or_eval_ = true; }
     407             :     bool contains_function_or_eval() const {
     408             :       return contains_function_or_eval_;
     409             :     }
     410             : 
     411             :     class FunctionOrEvalRecordingScope {
     412             :      public:
     413             :       explicit FunctionOrEvalRecordingScope(FunctionState* state)
     414      250419 :           : state_and_prev_value_(state, state->contains_function_or_eval_) {
     415      250419 :         state->contains_function_or_eval_ = false;
     416             :       }
     417             :       ~FunctionOrEvalRecordingScope() {
     418      250415 :         bool found = state_and_prev_value_->contains_function_or_eval_;
     419      250415 :         if (!found) {
     420      223033 :           state_and_prev_value_->contains_function_or_eval_ =
     421             :               state_and_prev_value_.GetPayload();
     422             :         }
     423             :       }
     424             : 
     425             :      private:
     426             :       PointerWithPayload<FunctionState, bool, 1> state_and_prev_value_;
     427             :     };
     428             : 
     429             :     class LoopScope {
     430             :      public:
     431             :       explicit LoopScope(FunctionState* function_state)
     432             :           : function_state_(function_state) {
     433      987381 :         function_state_->loop_nesting_depth_++;
     434             :       }
     435             : 
     436      987537 :       ~LoopScope() { function_state_->loop_nesting_depth_--; }
     437             : 
     438             :      private:
     439             :       FunctionState* function_state_;
     440             :     };
     441             : 
     442             :     int loop_nesting_depth() const { return loop_nesting_depth_; }
     443             : 
     444             :    private:
     445             :     // Properties count estimation.
     446             :     int expected_property_count_;
     447             : 
     448             :     // How many suspends are needed for this function.
     449             :     int suspend_count_;
     450             : 
     451             :     // How deeply nested we currently are in this function.
     452             :     int loop_nesting_depth_ = 0;
     453             : 
     454             :     FunctionState** function_state_stack_;
     455             :     FunctionState* outer_function_state_;
     456             :     DeclarationScope* scope_;
     457             : 
     458             :     // A reason, if any, why this function should not be optimized.
     459             :     BailoutReason dont_optimize_reason_;
     460             : 
     461             :     // Record whether the next (=== immediately following) function literal is
     462             :     // preceded by a parenthesis / exclamation mark. Also record the previous
     463             :     // state.
     464             :     // These are managed by the FunctionState constructor; the caller may only
     465             :     // call set_next_function_is_likely_called.
     466             :     bool next_function_is_likely_called_;
     467             :     bool previous_function_was_likely_called_;
     468             : 
     469             :     // Track if a function or eval occurs within this FunctionState
     470             :     bool contains_function_or_eval_;
     471             : 
     472             :     friend Impl;
     473             :   };
     474             : 
     475             :   struct DeclarationDescriptor {
     476             :     VariableMode mode;
     477             :     VariableKind kind;
     478             :     int declaration_pos;
     479             :     int initialization_pos;
     480             :   };
     481             : 
     482             :   struct DeclarationParsingResult {
     483             :     struct Declaration {
     484             :       Declaration(ExpressionT pattern, ExpressionT initializer)
     485    14093058 :           : pattern(pattern), initializer(initializer) {
     486             :         DCHECK_IMPLIES(Impl::IsNull(pattern), Impl::IsNull(initializer));
     487             :       }
     488             : 
     489             :       ExpressionT pattern;
     490             :       ExpressionT initializer;
     491             :       int value_beg_pos = kNoSourcePosition;
     492             :     };
     493             : 
     494             :     DeclarationParsingResult()
     495             :         : first_initializer_loc(Scanner::Location::invalid()),
     496    13818080 :           bindings_loc(Scanner::Location::invalid()) {}
     497             : 
     498             :     DeclarationDescriptor descriptor;
     499             :     std::vector<Declaration> declarations;
     500             :     Scanner::Location first_initializer_loc;
     501             :     Scanner::Location bindings_loc;
     502             :   };
     503             : 
     504             :   struct CatchInfo {
     505             :    public:
     506      407032 :     explicit CatchInfo(ParserBase* parser)
     507             :         : pattern(parser->impl()->NullExpression()),
     508             :           variable(nullptr),
     509      406983 :           scope(nullptr) {}
     510             :     ExpressionT pattern;
     511             :     Variable* variable;
     512             :     Scope* scope;
     513             :   };
     514             : 
     515             :   struct ForInfo {
     516             :    public:
     517      932628 :     explicit ForInfo(ParserBase* parser)
     518             :         : bound_names(1, parser->zone()),
     519             :           mode(ForEachStatement::ENUMERATE),
     520             :           position(kNoSourcePosition),
     521     1865318 :           parsing_result() {}
     522             :     ZonePtrList<const AstRawString> bound_names;
     523             :     ForEachStatement::VisitMode mode;
     524             :     int position;
     525             :     DeclarationParsingResult parsing_result;
     526             :   };
     527             : 
     528             :   struct ClassInfo {
     529             :    public:
     530      310443 :     explicit ClassInfo(ParserBase* parser)
     531             :         : variable(nullptr),
     532             :           extends(parser->impl()->NullExpression()),
     533             :           properties(parser->impl()->NewClassPropertyList(4)),
     534             :           static_fields(parser->impl()->NewClassPropertyList(4)),
     535             :           instance_fields(parser->impl()->NewClassPropertyList(4)),
     536             :           constructor(parser->impl()->NullExpression()),
     537             :           has_seen_constructor(false),
     538             :           has_name_static_property(false),
     539             :           has_static_computed_names(false),
     540             :           has_static_class_fields(false),
     541             :           has_instance_members(false),
     542             :           is_anonymous(false),
     543             :           static_fields_scope(nullptr),
     544             :           instance_members_scope(nullptr),
     545     1114329 :           computed_field_count(0) {}
     546             :     Variable* variable;
     547             :     ExpressionT extends;
     548             :     ClassPropertyListT properties;
     549             :     ClassPropertyListT static_fields;
     550             :     ClassPropertyListT instance_fields;
     551             :     FunctionLiteralT constructor;
     552             : 
     553             :     bool has_seen_constructor;
     554             :     bool has_name_static_property;
     555             :     bool has_static_computed_names;
     556             :     bool has_static_class_fields;
     557             :     bool has_instance_members;
     558             :     bool is_anonymous;
     559             :     DeclarationScope* static_fields_scope;
     560             :     DeclarationScope* instance_members_scope;
     561             :     int computed_field_count;
     562             :   };
     563             : 
     564             :   enum class PropertyPosition { kObjectLiteral, kClassLiteral };
     565             :   struct ParsePropertyInfo {
     566             :    public:
     567     1954751 :     explicit ParsePropertyInfo(ParserBase* parser,
     568             :                                AccumulationScope* accumulation_scope = nullptr)
     569             :         : accumulation_scope(accumulation_scope),
     570             :           name(parser->impl()->NullIdentifier()),
     571             :           position(PropertyPosition::kClassLiteral),
     572             :           function_flags(ParseFunctionFlag::kIsNormal),
     573             :           kind(ParsePropertyKind::kNotSet),
     574             :           is_computed_name(false),
     575             :           is_private(false),
     576             :           is_static(false),
     577     7449233 :           is_rest(false) {}
     578             : 
     579     5428933 :     bool ParsePropertyKindFromToken(Token::Value token) {
     580             :       // This returns true, setting the property kind, iff the given token is
     581             :       // one which must occur after a property name, indicating that the
     582             :       // previous token was in fact a name and not a modifier (like the "get" in
     583             :       // "get x").
     584     5428933 :       switch (token) {
     585             :         case Token::COLON:
     586     4491307 :           kind = ParsePropertyKind::kValue;
     587             :           return true;
     588             :         case Token::COMMA:
     589       69859 :           kind = ParsePropertyKind::kShorthand;
     590             :           return true;
     591             :         case Token::RBRACE:
     592      116424 :           kind = ParsePropertyKind::kShorthandOrClassField;
     593             :           return true;
     594             :         case Token::ASSIGN:
     595       72221 :           kind = ParsePropertyKind::kAssign;
     596             :           return true;
     597             :         case Token::LPAREN:
     598      395266 :           kind = ParsePropertyKind::kMethod;
     599             :           return true;
     600             :         case Token::MUL:
     601             :         case Token::SEMICOLON:
     602       20793 :           kind = ParsePropertyKind::kClassField;
     603             :           return true;
     604             :         default:
     605             :           break;
     606             :       }
     607             :       return false;
     608             :     }
     609             : 
     610             :     AccumulationScope* accumulation_scope;
     611             :     IdentifierT name;
     612             :     PropertyPosition position;
     613             :     ParseFunctionFlags function_flags;
     614             :     ParsePropertyKind kind;
     615             :     bool is_computed_name;
     616             :     bool is_private;
     617             :     bool is_static;
     618             :     bool is_rest;
     619             :   };
     620             : 
     621      459965 :   ClassLiteralProperty::Kind ClassPropertyKindFor(ParsePropertyKind kind) {
     622      459965 :     switch (kind) {
     623             :       case ParsePropertyKind::kAccessorGetter:
     624             :         return ClassLiteralProperty::GETTER;
     625             :       case ParsePropertyKind::kAccessorSetter:
     626             :         return ClassLiteralProperty::SETTER;
     627             :       case ParsePropertyKind::kMethod:
     628             :         return ClassLiteralProperty::METHOD;
     629             :       case ParsePropertyKind::kClassField:
     630             :         return ClassLiteralProperty::FIELD;
     631             :       default:
     632             :         // Only returns for deterministic kinds
     633           0 :         UNREACHABLE();
     634             :     }
     635             :   }
     636             : 
     637        9928 :   const AstRawString* ClassFieldVariableName(AstValueFactory* ast_value_factory,
     638             :                                              int index) {
     639        9928 :     std::string name = ".class-field-" + std::to_string(index);
     640       19856 :     return ast_value_factory->GetOneByteString(name.c_str());
     641             :   }
     642             : 
     643     2957943 :   DeclarationScope* NewScriptScope() const {
     644     2957929 :     return new (zone()) DeclarationScope(zone(), ast_value_factory());
     645             :   }
     646             : 
     647      167500 :   DeclarationScope* NewVarblockScope() const {
     648      167502 :     return new (zone()) DeclarationScope(zone(), scope(), BLOCK_SCOPE);
     649             :   }
     650             : 
     651       71705 :   ModuleScope* NewModuleScope(DeclarationScope* parent) const {
     652       71705 :     return new (zone()) ModuleScope(parent, ast_value_factory());
     653             :   }
     654             : 
     655      961392 :   DeclarationScope* NewEvalScope(Scope* parent) const {
     656      961392 :     return new (zone()) DeclarationScope(zone(), parent, EVAL_SCOPE);
     657             :   }
     658             : 
     659     1646685 :   Scope* NewScope(ScopeType scope_type) const {
     660     1646685 :     return NewScopeWithParent(scope(), scope_type);
     661             :   }
     662             : 
     663             :   // This constructor should only be used when absolutely necessary. Most scopes
     664             :   // should automatically use scope() as parent, and be fine with
     665             :   // NewScope(ScopeType) above.
     666     1348809 :   Scope* NewScopeWithParent(Scope* parent, ScopeType scope_type) const {
     667             :     // Must always use the specific constructors for the blacklisted scope
     668             :     // types.
     669             :     DCHECK_NE(FUNCTION_SCOPE, scope_type);
     670             :     DCHECK_NE(SCRIPT_SCOPE, scope_type);
     671             :     DCHECK_NE(MODULE_SCOPE, scope_type);
     672             :     DCHECK_NOT_NULL(parent);
     673     1348860 :     return new (zone()) Scope(zone(), parent, scope_type);
     674             :   }
     675             : 
     676             :   // Creates a function scope that always allocates in zone(). The function
     677             :   // scope itself is either allocated in zone() or in target_zone if one is
     678             :   // passed in.
     679     5570555 :   DeclarationScope* NewFunctionScope(FunctionKind kind,
     680     6238602 :                                      Zone* parse_zone = nullptr) const {
     681             :     DCHECK(ast_value_factory());
     682     5570555 :     if (parse_zone == nullptr) parse_zone = zone();
     683             :     DeclarationScope* result = new (zone())
     684     5570717 :         DeclarationScope(parse_zone, scope(), FUNCTION_SCOPE, kind);
     685             : 
     686             :     // Record presence of an inner function scope
     687     5571097 :     function_state_->RecordFunctionOrEvalCall();
     688             : 
     689             :     // TODO(verwaest): Move into the DeclarationScope constructor.
     690     5571097 :     if (!IsArrowFunction(kind)) {
     691     4467102 :       result->DeclareDefaultFunctionVariables(ast_value_factory());
     692             :     }
     693     5571077 :     return result;
     694             :   }
     695             : 
     696     3572267 :   V8_INLINE DeclarationScope* GetDeclarationScope() const {
     697     3572267 :     return scope()->GetDeclarationScope();
     698             :   }
     699        1739 :   V8_INLINE DeclarationScope* GetClosureScope() const {
     700        1739 :     return scope()->GetClosureScope();
     701             :   }
     702             : 
     703             :   VariableProxy* NewRawVariable(const AstRawString* name, int pos) {
     704             :     return factory()->ast_node_factory()->NewVariableProxy(
     705    70635026 :         name, NORMAL_VARIABLE, pos);
     706             :   }
     707             : 
     708       49208 :   VariableProxy* NewUnresolved(const AstRawString* name) {
     709             :     return scope()->NewUnresolved(factory()->ast_node_factory(), name,
     710       49208 :                                   scanner()->location().beg_pos);
     711             :   }
     712             : 
     713             :   VariableProxy* NewUnresolved(const AstRawString* name, int begin_pos,
     714       66042 :                                VariableKind kind = NORMAL_VARIABLE) {
     715             :     return scope()->NewUnresolved(factory()->ast_node_factory(), name,
     716      101455 :                                   begin_pos, kind);
     717             :   }
     718             : 
     719  2788472080 :   Scanner* scanner() const { return scanner_; }
     720   112308466 :   AstValueFactory* ast_value_factory() const { return ast_value_factory_; }
     721    44043333 :   int position() const { return scanner_->location().beg_pos; }
     722   827744018 :   int peek_position() const { return scanner_->peek_location().beg_pos; }
     723   144766953 :   int end_position() const { return scanner_->location().end_pos; }
     724       51970 :   int peek_end_position() const { return scanner_->peek_location().end_pos; }
     725     3090736 :   bool stack_overflow() const {
     726     3090736 :     return pending_error_handler()->stack_overflow();
     727             :   }
     728       24286 :   void set_stack_overflow() {
     729       12143 :     scanner_->set_parser_error();
     730             :     pending_error_handler()->set_stack_overflow();
     731       12143 :   }
     732   114275505 :   void CheckStackOverflow() {
     733             :     // Any further calls to Next or peek will return the illegal token.
     734   114275505 :     if (GetCurrentStackPosition() < stack_limit_) set_stack_overflow();
     735   114275790 :   }
     736             :   int script_id() { return script_id_; }
     737     2523218 :   void set_script_id(int id) { script_id_ = id; }
     738             : 
     739  2008801112 :   V8_INLINE Token::Value peek() { return scanner()->peek(); }
     740             : 
     741             :   // Returns the position past the following semicolon (if it exists), and the
     742             :   // position past the end of the current token otherwise.
     743      193614 :   int PositionAfterSemicolon() {
     744      193614 :     return (peek() == Token::SEMICOLON) ? peek_end_position() : end_position();
     745             :   }
     746             : 
     747     1922978 :   V8_INLINE Token::Value PeekAhead() { return scanner()->PeekAhead(); }
     748             : 
     749   191656093 :   V8_INLINE Token::Value Next() { return scanner()->Next(); }
     750             : 
     751   192433534 :   V8_INLINE void Consume(Token::Value token) {
     752   195887379 :     Token::Value next = scanner()->Next();
     753             :     USE(next);
     754             :     USE(token);
     755             :     DCHECK_IMPLIES(!has_error(), next == token);
     756             :   }
     757             : 
     758   164275273 :   V8_INLINE bool Check(Token::Value token) {
     759   199390364 :     Token::Value next = scanner()->peek();
     760   199388068 :     if (next == token) {
     761             :       Consume(next);
     762             :       return true;
     763             :     }
     764             :     return false;
     765             :   }
     766             : 
     767    55492563 :   void Expect(Token::Value token) {
     768             :     Token::Value next = Next();
     769    55494337 :     if (V8_UNLIKELY(next != token)) {
     770      830752 :       ReportUnexpectedToken(next);
     771             :     }
     772    55494335 :   }
     773             : 
     774    40995382 :   void ExpectSemicolon() {
     775             :     // Check for automatic semicolon insertion according to
     776             :     // the rules given in ECMA-262, section 7.9, page 21.
     777             :     Token::Value tok = peek();
     778    37541543 :     if (V8_LIKELY(tok == Token::SEMICOLON)) {
     779             :       Next();
     780             :       return;
     781             :     }
     782     5971744 :     if (V8_LIKELY(scanner()->HasLineTerminatorBeforeNext() ||
     783             :                   Token::IsAutoSemicolon(tok))) {
     784             :       return;
     785             :     }
     786             : 
     787     1298235 :     if (scanner()->current_token() == Token::AWAIT && !is_async_function()) {
     788          21 :       ReportMessageAt(scanner()->location(),
     789          21 :                       MessageTemplate::kAwaitNotInAsyncFunction, kSyntaxError);
     790          21 :       return;
     791             :     }
     792             : 
     793     1298179 :     ReportUnexpectedToken(Next());
     794             :   }
     795             : 
     796    44942067 :   bool peek_any_identifier() { return Token::IsAnyIdentifier(peek()); }
     797             : 
     798     2089844 :   bool PeekContextualKeyword(const AstRawString* name) {
     799             :     return peek() == Token::IDENTIFIER &&
     800      504057 :            !scanner()->next_literal_contains_escapes() &&
     801     2089865 :            scanner()->NextSymbol(ast_value_factory()) == name;
     802             :   }
     803             : 
     804      699380 :   bool CheckContextualKeyword(const AstRawString* name) {
     805      699380 :     if (PeekContextualKeyword(name)) {
     806             :       Consume(Token::IDENTIFIER);
     807      189519 :       return true;
     808             :     }
     809             :     return false;
     810             :   }
     811             : 
     812      133681 :   void ExpectContextualKeyword(const AstRawString* name,
     813      271756 :                                const char* fullname = nullptr, int pos = -1) {
     814      133681 :     Expect(Token::IDENTIFIER);
     815      133684 :     if (V8_UNLIKELY(scanner()->CurrentSymbol(ast_value_factory()) != name)) {
     816        9118 :       ReportUnexpectedToken(scanner()->current_token());
     817             :     }
     818      133683 :     if (V8_UNLIKELY(scanner()->literal_contains_escapes())) {
     819             :       const char* full = fullname == nullptr
     820             :                              ? reinterpret_cast<const char*>(name->raw_data())
     821        2825 :                              : fullname;
     822        2825 :       int start = pos == -1 ? position() : pos;
     823        2825 :       impl()->ReportMessageAt(Scanner::Location(start, end_position()),
     824             :                               MessageTemplate::kInvalidEscapedMetaProperty,
     825             :                               full);
     826             :     }
     827      133683 :   }
     828             : 
     829     1483823 :   bool CheckInOrOf(ForEachStatement::VisitMode* visit_mode) {
     830      787332 :     if (Check(Token::IN)) {
     831       90716 :       *visit_mode = ForEachStatement::ENUMERATE;
     832       90716 :       return true;
     833     1393232 :     } else if (CheckContextualKeyword(ast_value_factory()->of_string())) {
     834      188342 :       *visit_mode = ForEachStatement::ITERATE;
     835      188342 :       return true;
     836             :     }
     837             :     return false;
     838             :   }
     839             : 
     840      817273 :   bool PeekInOrOf() {
     841             :     return peek() == Token::IN ||
     842     1199413 :            PeekContextualKeyword(ast_value_factory()->of_string());
     843             :   }
     844             : 
     845             :   // Checks whether an octal literal was last seen between beg_pos and end_pos.
     846             :   // Only called for strict mode strings.
     847     2621218 :   void CheckStrictOctalLiteral(int beg_pos, int end_pos) {
     848             :     Scanner::Location octal = scanner()->octal_position();
     849     2618353 :     if (octal.IsValid() && beg_pos <= octal.beg_pos &&
     850             :         octal.end_pos <= end_pos) {
     851        2865 :       MessageTemplate message = scanner()->octal_message();
     852             :       DCHECK_NE(message, MessageTemplate::kNone);
     853        2865 :       impl()->ReportMessageAt(octal, message);
     854             :       scanner()->clear_octal_position();
     855        2865 :       if (message == MessageTemplate::kStrictDecimalWithLeadingZero) {
     856           0 :         impl()->CountUsage(v8::Isolate::kDecimalWithLeadingZeroInStrictMode);
     857             :       }
     858             :     }
     859     2618353 :   }
     860             : 
     861             :   // Checks if an octal literal or an invalid hex or unicode escape sequence
     862             :   // appears in the current template literal token. In the presence of such,
     863             :   // either returns false or reports an error, depending on should_throw.
     864             :   // Otherwise returns true.
     865      163436 :   inline bool CheckTemplateEscapes(bool should_throw) {
     866             :     DCHECK(Token::IsTemplate(scanner()->current_token()));
     867      150456 :     if (!scanner()->has_invalid_template_escape()) return true;
     868             : 
     869             :     // Handle error case(s)
     870       12980 :     if (should_throw) {
     871        6344 :       impl()->ReportMessageAt(scanner()->invalid_template_escape_location(),
     872             :                               scanner()->invalid_template_escape_message());
     873             :     }
     874       12980 :     scanner()->clear_invalid_template_escape_message();
     875       12980 :     return should_throw;
     876             :   }
     877             : 
     878             :   ExpressionT ParsePossibleDestructuringSubPattern(AccumulationScope* scope);
     879             :   void ClassifyParameter(IdentifierT parameter, int beg_pos, int end_pos);
     880             :   void ClassifyArrowParameter(AccumulationScope* accumulation_scope,
     881             :                               int position, ExpressionT parameter);
     882             : 
     883             :   // Checking the name of a function literal. This has to be done after parsing
     884             :   // the function, since the function can declare itself strict.
     885     4202754 :   void CheckFunctionName(LanguageMode language_mode, IdentifierT function_name,
     886             :                          FunctionNameValidity function_name_validity,
     887             :                          const Scanner::Location& function_name_loc) {
     888     4202754 :     if (impl()->IsNull(function_name)) return;
     889     4137292 :     if (function_name_validity == kSkipFunctionNameCheck) return;
     890             :     // The function name needs to be checked in strict mode.
     891     3098698 :     if (is_sloppy(language_mode)) return;
     892             : 
     893      409246 :     if (impl()->IsEvalOrArguments(function_name)) {
     894         623 :       impl()->ReportMessageAt(function_name_loc,
     895             :                               MessageTemplate::kStrictEvalArguments);
     896         343 :       return;
     897             :     }
     898      408623 :     if (function_name_validity == kFunctionNameIsStrictReserved) {
     899        1807 :       impl()->ReportMessageAt(function_name_loc,
     900             :                               MessageTemplate::kUnexpectedStrictReserved);
     901         231 :       return;
     902             :     }
     903             :   }
     904             : 
     905     1246173 :   typename Types::Factory* factory() { return &ast_node_factory_; }
     906             : 
     907       36482 :   DeclarationScope* GetReceiverScope() const {
     908       36482 :     return scope()->GetReceiverScope();
     909             :   }
     910    52604851 :   LanguageMode language_mode() { return scope()->language_mode(); }
     911     1817077 :   void RaiseLanguageMode(LanguageMode mode) {
     912             :     LanguageMode old = scope()->language_mode();
     913     1817077 :     impl()->SetLanguageMode(scope(), old > mode ? old : mode);
     914     1817082 :   }
     915      100618 :   bool is_generator() const {
     916      201235 :     return IsGeneratorFunction(function_state_->kind());
     917             :   }
     918   108185331 :   bool is_async_function() const {
     919   216368907 :     return IsAsyncFunction(function_state_->kind());
     920             :   }
     921             :   bool is_async_generator() const {
     922             :     return IsAsyncGeneratorFunction(function_state_->kind());
     923             :   }
     924             :   bool is_resumable() const {
     925             :     return IsResumableFunction(function_state_->kind());
     926             :   }
     927             : 
     928             :   const PendingCompilationErrorHandler* pending_error_handler() const {
     929             :     return pending_error_handler_;
     930             :   }
     931             :   PendingCompilationErrorHandler* pending_error_handler() {
     932             :     return pending_error_handler_;
     933             :   }
     934             : 
     935             :   // Report syntax errors.
     936       18878 :   V8_NOINLINE void ReportMessage(MessageTemplate message) {
     937       18878 :     Scanner::Location source_location = scanner()->location();
     938       18878 :     impl()->ReportMessageAt(source_location, message,
     939             :                             static_cast<const char*>(nullptr), kSyntaxError);
     940       18878 :   }
     941             : 
     942             :   template <typename T>
     943         635 :   V8_NOINLINE void ReportMessage(MessageTemplate message, T arg,
     944         635 :                                  ParseErrorType error_type = kSyntaxError) {
     945         635 :     Scanner::Location source_location = scanner()->location();
     946         635 :     impl()->ReportMessageAt(source_location, message, arg, error_type);
     947         635 :   }
     948             : 
     949       25191 :   V8_NOINLINE void ReportMessageAt(Scanner::Location location,
     950             :                                    MessageTemplate message,
     951             :                                    ParseErrorType error_type) {
     952       25191 :     impl()->ReportMessageAt(location, message,
     953             :                             static_cast<const char*>(nullptr), error_type);
     954       25193 :   }
     955             : 
     956             :   V8_NOINLINE void ReportUnexpectedToken(Token::Value token);
     957             : 
     958     5150062 :   void ValidateFormalParameters(LanguageMode language_mode,
     959             :                                 const FormalParametersT& parameters,
     960             :                                 bool allow_duplicates) {
     961     5150062 :     if (!allow_duplicates) parameters.ValidateDuplicate(impl());
     962     5150046 :     if (is_strict(language_mode)) parameters.ValidateStrictMode(impl());
     963     5150059 :   }
     964             : 
     965             :   // Needs to be called if the reference needs to be available from the current
     966             :   // point. It causes the receiver to be context allocated if necessary.
     967             :   // Returns the receiver variable that we're referencing.
     968    10950705 :   V8_INLINE Variable* UseThis() {
     969     5539177 :     DeclarationScope* closure_scope = scope()->GetClosureScope();
     970     5539197 :     DeclarationScope* receiver_scope = closure_scope->GetReceiverScope();
     971     5539216 :     Variable* var = receiver_scope->receiver();
     972     5539188 :     var->set_is_used();
     973     5539148 :     if (closure_scope == receiver_scope) {
     974             :       // It's possible that we're parsing the head of an arrow function, in
     975             :       // which case we haven't realized yet that closure_scope !=
     976             :       // receiver_scope. Mark through the ExpressionScope for now.
     977     5411528 :       expression_scope()->RecordThisUse();
     978             :     } else {
     979      127620 :       closure_scope->set_has_this_reference();
     980      127619 :       var->ForceContextAllocation();
     981             :     }
     982             :     return var;
     983             :   }
     984             : 
     985             :   V8_INLINE IdentifierT ParseAndClassifyIdentifier(Token::Value token);
     986             :   // Parses an identifier or a strict mode future reserved word. Allows passing
     987             :   // in function_kind for the case of parsing the identifier in a function
     988             :   // expression, where the relevant "function_kind" bit is of the function being
     989             :   // parsed, not the containing function.
     990             :   V8_INLINE IdentifierT ParseIdentifier(FunctionKind function_kind);
     991             :   V8_INLINE IdentifierT ParseIdentifier() {
     992     1900150 :     return ParseIdentifier(function_state_->kind());
     993             :   }
     994             :   // Same as above but additionally disallows 'eval' and 'arguments' in strict
     995             :   // mode.
     996             :   IdentifierT ParseNonRestrictedIdentifier();
     997             : 
     998             :   V8_INLINE IdentifierT ParsePropertyName();
     999             : 
    1000             :   ExpressionT ParsePropertyOrPrivatePropertyName();
    1001             : 
    1002             :   ExpressionT ParseRegExpLiteral();
    1003             : 
    1004             :   ExpressionT ParseBindingPattern();
    1005             :   ExpressionT ParsePrimaryExpression();
    1006             : 
    1007             :   // Use when parsing an expression that is known to not be a pattern or part of
    1008             :   // a pattern.
    1009             :   V8_INLINE ExpressionT ParseExpression();
    1010             :   V8_INLINE ExpressionT ParseAssignmentExpression();
    1011             : 
    1012             :   // These methods do not wrap the parsing of the expression inside a new
    1013             :   // expression_scope; they use the outer expression_scope instead. They should
    1014             :   // be used whenever we're parsing something with the "cover" grammar that
    1015             :   // recognizes both patterns and non-patterns (which roughly corresponds to
    1016             :   // what's inside the parentheses generated by the symbol
    1017             :   // "CoverParenthesizedExpressionAndArrowParameterList" in the ES 2017
    1018             :   // specification).
    1019             :   ExpressionT ParseExpressionCoverGrammar();
    1020             :   ExpressionT ParseAssignmentExpressionCoverGrammar();
    1021             : 
    1022             :   ExpressionT ParseArrowParametersWithRest(ExpressionListT* list,
    1023             :                                            AccumulationScope* scope);
    1024             : 
    1025             :   ExpressionT ParseArrayLiteral();
    1026             : 
    1027             :   inline static bool IsAccessor(ParsePropertyKind kind) {
    1028             :     return IsInRange(kind, ParsePropertyKind::kAccessorGetter,
    1029             :                      ParsePropertyKind::kAccessorSetter);
    1030             :   }
    1031             : 
    1032             :   ExpressionT ParseProperty(ParsePropertyInfo* prop_info);
    1033             :   ExpressionT ParseObjectLiteral();
    1034             :   ClassLiteralPropertyT ParseClassPropertyDefinition(
    1035             :       ClassInfo* class_info, ParsePropertyInfo* prop_info, bool has_extends);
    1036             :   void CheckClassFieldName(IdentifierT name, bool is_static);
    1037             :   void CheckClassMethodName(IdentifierT name, ParsePropertyKind type,
    1038             :                             ParseFunctionFlags flags, bool is_static,
    1039             :                             bool* has_seen_constructor);
    1040             :   ExpressionT ParseMemberInitializer(ClassInfo* class_info, int beg_pos,
    1041             :                                      bool is_static);
    1042             :   ObjectLiteralPropertyT ParseObjectPropertyDefinition(
    1043             :       ParsePropertyInfo* prop_info, bool* has_seen_proto);
    1044             :   void ParseArguments(
    1045             :       ExpressionListT* args, bool* has_spread,
    1046             :       ParsingArrowHeadFlag maybe_arrow = kCertainlyNotArrowHead);
    1047             : 
    1048             :   ExpressionT ParseYieldExpression();
    1049             :   V8_INLINE ExpressionT ParseConditionalExpression();
    1050             :   ExpressionT ParseConditionalContinuation(ExpressionT expression, int pos);
    1051             :   ExpressionT ParseBinaryContinuation(ExpressionT x, int prec, int prec1);
    1052             :   V8_INLINE ExpressionT ParseBinaryExpression(int prec);
    1053             :   ExpressionT ParseUnaryOrPrefixExpression();
    1054             :   ExpressionT ParseAwaitExpression();
    1055             :   V8_INLINE ExpressionT ParseUnaryExpression();
    1056             :   V8_INLINE ExpressionT ParsePostfixExpression();
    1057             :   V8_INLINE ExpressionT ParseLeftHandSideExpression();
    1058             :   ExpressionT ParseLeftHandSideContinuation(ExpressionT expression);
    1059             :   ExpressionT ParseMemberWithPresentNewPrefixesExpression();
    1060             :   V8_INLINE ExpressionT ParseMemberWithNewPrefixesExpression();
    1061             :   ExpressionT ParseFunctionExpression();
    1062             :   V8_INLINE ExpressionT ParseMemberExpression();
    1063             :   V8_INLINE ExpressionT
    1064             :   ParseMemberExpressionContinuation(ExpressionT expression) {
    1065   108674377 :     if (!Token::IsMember(peek())) return expression;
    1066    16808552 :     return DoParseMemberExpressionContinuation(expression);
    1067             :   }
    1068             :   ExpressionT DoParseMemberExpressionContinuation(ExpressionT expression);
    1069             : 
    1070             :   ExpressionT ParseArrowFunctionLiteral(const FormalParametersT& parameters);
    1071             :   void ParseAsyncFunctionBody(Scope* scope, StatementListT* body);
    1072             :   ExpressionT ParseAsyncFunctionLiteral();
    1073             :   ExpressionT ParseClassLiteral(IdentifierT name,
    1074             :                                 Scanner::Location class_name_location,
    1075             :                                 bool name_is_strict_reserved,
    1076             :                                 int class_token_pos);
    1077             :   ExpressionT ParseTemplateLiteral(ExpressionT tag, int start, bool tagged);
    1078             :   ExpressionT ParseSuperExpression(bool is_new);
    1079             :   ExpressionT ParseImportExpressions();
    1080             :   ExpressionT ParseNewTargetExpression();
    1081             : 
    1082             :   V8_INLINE void ParseFormalParameter(FormalParametersT* parameters);
    1083             :   void ParseFormalParameterList(FormalParametersT* parameters);
    1084             :   void CheckArityRestrictions(int param_count, FunctionKind function_type,
    1085             :                               bool has_rest, int formals_start_pos,
    1086             :                               int formals_end_pos);
    1087             : 
    1088             :   void ParseVariableDeclarations(VariableDeclarationContext var_context,
    1089             :                                  DeclarationParsingResult* parsing_result,
    1090             :                                  ZonePtrList<const AstRawString>* names);
    1091             :   StatementT ParseAsyncFunctionDeclaration(
    1092             :       ZonePtrList<const AstRawString>* names, bool default_export);
    1093             :   StatementT ParseFunctionDeclaration();
    1094             :   StatementT ParseHoistableDeclaration(ZonePtrList<const AstRawString>* names,
    1095             :                                        bool default_export);
    1096             :   StatementT ParseHoistableDeclaration(int pos, ParseFunctionFlags flags,
    1097             :                                        ZonePtrList<const AstRawString>* names,
    1098             :                                        bool default_export);
    1099             :   StatementT ParseClassDeclaration(ZonePtrList<const AstRawString>* names,
    1100             :                                    bool default_export);
    1101             :   StatementT ParseNativeDeclaration();
    1102             : 
    1103             :   // Whether we're parsing a single-expression arrow function or something else.
    1104             :   enum class FunctionBodyType { kExpression, kBlock };
    1105             :   // Consumes the ending }.
    1106             :   void ParseFunctionBody(StatementListT* body, IdentifierT function_name,
    1107             :                          int pos, const FormalParametersT& parameters,
    1108             :                          FunctionKind kind,
    1109             :                          FunctionLiteral::FunctionType function_type,
    1110             :                          FunctionBodyType body_type);
    1111             : 
    1112             :   // Check if the scope has conflicting var/let declarations from different
    1113             :   // scopes. This covers for example
    1114             :   //
    1115             :   // function f() { { { var x; } let x; } }
    1116             :   // function g() { { var x; let x; } }
    1117             :   //
    1118             :   // The var declarations are hoisted to the function scope, but originate from
    1119             :   // a scope where the name has also been let bound or the var declaration is
    1120             :   // hoisted over such a scope.
    1121     7458480 :   void CheckConflictingVarDeclarations(DeclarationScope* scope) {
    1122    14917288 :     if (has_error()) return;
    1123     6548318 :     Declaration* decl = scope->CheckConflictingVarDeclarations();
    1124     6535109 :     if (decl != nullptr) {
    1125             :       // In ES6, conflicting variable bindings are early errors.
    1126       13283 :       const AstRawString* name = decl->var()->raw_name();
    1127       13283 :       int position = decl->position();
    1128             :       Scanner::Location location =
    1129             :           position == kNoSourcePosition
    1130             :               ? Scanner::Location::invalid()
    1131       13283 :               : Scanner::Location(position, position + 1);
    1132       13283 :       impl()->ReportMessageAt(location, MessageTemplate::kVarRedeclaration,
    1133             :                               name);
    1134             :     }
    1135             :   }
    1136             : 
    1137             :   // TODO(nikolaos, marja): The first argument should not really be passed
    1138             :   // by value. The method is expected to add the parsed statements to the
    1139             :   // list. This works because in the case of the parser, StatementListT is
    1140             :   // a pointer whereas the preparser does not really modify the body.
    1141             :   V8_INLINE void ParseStatementList(StatementListT* body,
    1142             :                                     Token::Value end_token);
    1143             :   StatementT ParseStatementListItem();
    1144             : 
    1145             :   StatementT ParseStatement(ZonePtrList<const AstRawString>* labels,
    1146             :                             ZonePtrList<const AstRawString>* own_labels) {
    1147             :     return ParseStatement(labels, own_labels,
    1148     4832981 :                           kDisallowLabelledFunctionStatement);
    1149             :   }
    1150             :   StatementT ParseStatement(ZonePtrList<const AstRawString>* labels,
    1151             :                             ZonePtrList<const AstRawString>* own_labels,
    1152             :                             AllowLabelledFunctionStatement allow_function);
    1153             :   BlockT ParseBlock(ZonePtrList<const AstRawString>* labels);
    1154             : 
    1155             :   // Parse a SubStatement in strict mode, or with an extra block scope in
    1156             :   // sloppy mode to handle
    1157             :   // ES#sec-functiondeclarations-in-ifstatement-statement-clauses
    1158             :   StatementT ParseScopedStatement(ZonePtrList<const AstRawString>* labels);
    1159             : 
    1160             :   StatementT ParseVariableStatement(VariableDeclarationContext var_context,
    1161             :                                     ZonePtrList<const AstRawString>* names);
    1162             : 
    1163             :   // Magical syntax support.
    1164             :   ExpressionT ParseV8Intrinsic();
    1165             : 
    1166             :   StatementT ParseDebuggerStatement();
    1167             : 
    1168             :   StatementT ParseExpressionOrLabelledStatement(
    1169             :       ZonePtrList<const AstRawString>* labels,
    1170             :       ZonePtrList<const AstRawString>* own_labels,
    1171             :       AllowLabelledFunctionStatement allow_function);
    1172             :   StatementT ParseIfStatement(ZonePtrList<const AstRawString>* labels);
    1173             :   StatementT ParseContinueStatement();
    1174             :   StatementT ParseBreakStatement(ZonePtrList<const AstRawString>* labels);
    1175             :   StatementT ParseReturnStatement();
    1176             :   StatementT ParseWithStatement(ZonePtrList<const AstRawString>* labels);
    1177             :   StatementT ParseDoWhileStatement(ZonePtrList<const AstRawString>* labels,
    1178             :                                    ZonePtrList<const AstRawString>* own_labels);
    1179             :   StatementT ParseWhileStatement(ZonePtrList<const AstRawString>* labels,
    1180             :                                  ZonePtrList<const AstRawString>* own_labels);
    1181             :   StatementT ParseThrowStatement();
    1182             :   StatementT ParseSwitchStatement(ZonePtrList<const AstRawString>* labels);
    1183             :   V8_INLINE StatementT ParseTryStatement();
    1184             :   StatementT ParseForStatement(ZonePtrList<const AstRawString>* labels,
    1185             :                                ZonePtrList<const AstRawString>* own_labels);
    1186             :   StatementT ParseForEachStatementWithDeclarations(
    1187             :       int stmt_pos, ForInfo* for_info, ZonePtrList<const AstRawString>* labels,
    1188             :       ZonePtrList<const AstRawString>* own_labels, Scope* inner_block_scope);
    1189             :   StatementT ParseForEachStatementWithoutDeclarations(
    1190             :       int stmt_pos, ExpressionT expression, int lhs_beg_pos, int lhs_end_pos,
    1191             :       ForInfo* for_info, ZonePtrList<const AstRawString>* labels,
    1192             :       ZonePtrList<const AstRawString>* own_labels);
    1193             : 
    1194             :   // Parse a C-style for loop: 'for (<init>; <cond>; <next>) { ... }'
    1195             :   // "for (<init>;" is assumed to have been parser already.
    1196             :   ForStatementT ParseStandardForLoop(
    1197             :       int stmt_pos, ZonePtrList<const AstRawString>* labels,
    1198             :       ZonePtrList<const AstRawString>* own_labels, ExpressionT* cond,
    1199             :       StatementT* next, StatementT* body);
    1200             :   // Same as the above, but handles those cases where <init> is a
    1201             :   // lexical variable declaration.
    1202             :   StatementT ParseStandardForLoopWithLexicalDeclarations(
    1203             :       int stmt_pos, StatementT init, ForInfo* for_info,
    1204             :       ZonePtrList<const AstRawString>* labels,
    1205             :       ZonePtrList<const AstRawString>* own_labels);
    1206             :   StatementT ParseForAwaitStatement(
    1207             :       ZonePtrList<const AstRawString>* labels,
    1208             :       ZonePtrList<const AstRawString>* own_labels);
    1209             : 
    1210     2387787 :   V8_INLINE bool IsLet(const AstRawString* identifier) const {
    1211     2387787 :     return identifier == ast_value_factory()->let_string();
    1212             :   }
    1213             : 
    1214             :   bool IsNextLetKeyword();
    1215             : 
    1216             :   // Checks if the expression is a valid reference expression (e.g., on the
    1217             :   // left-hand side of assignments). Although ruled out by ECMA as early errors,
    1218             :   // we allow calls for web compatibility and rewrite them to a runtime throw.
    1219             :   ExpressionT RewriteInvalidReferenceExpression(
    1220             :       ExpressionT expression, int beg_pos, int end_pos, MessageTemplate message,
    1221             :       ParseErrorType type = kReferenceError);
    1222             : 
    1223             :   bool IsValidReferenceExpression(ExpressionT expression);
    1224             : 
    1225    25772692 :   bool IsAssignableIdentifier(ExpressionT expression) {
    1226    25772808 :     if (!impl()->IsIdentifier(expression)) return false;
    1227     7540387 :     if (is_strict(language_mode()) &&
    1228             :         impl()->IsEvalOrArguments(impl()->AsIdentifier(expression))) {
    1229             :       return false;
    1230             :     }
    1231     6647815 :     return true;
    1232             :   }
    1233             : 
    1234             :   FunctionKind FunctionKindForImpl(bool is_method, ParseFunctionFlags flags) {
    1235             :     static const FunctionKind kFunctionKinds[][2][2] = {
    1236             :         {
    1237             :             // is_method=false
    1238             :             {// is_generator=false
    1239             :              FunctionKind::kNormalFunction, FunctionKind::kAsyncFunction},
    1240             :             {// is_generator=true
    1241             :              FunctionKind::kGeneratorFunction,
    1242             :              FunctionKind::kAsyncGeneratorFunction},
    1243             :         },
    1244             :         {
    1245             :             // is_method=true
    1246             :             {// is_generator=false
    1247             :              FunctionKind::kConciseMethod, FunctionKind::kAsyncConciseMethod},
    1248             :             {// is_generator=true
    1249             :              FunctionKind::kConciseGeneratorMethod,
    1250             :              FunctionKind::kAsyncConciseGeneratorMethod},
    1251             :         }};
    1252             :     return kFunctionKinds[is_method]
    1253             :                          [(flags & ParseFunctionFlag::kIsGenerator) != 0]
    1254     3390134 :                          [(flags & ParseFunctionFlag::kIsAsync) != 0];
    1255             :   }
    1256             : 
    1257             :   inline FunctionKind FunctionKindFor(ParseFunctionFlags flags) {
    1258             :     const bool kIsMethod = false;
    1259             :     return FunctionKindForImpl(kIsMethod, flags);
    1260             :   }
    1261             : 
    1262             :   inline FunctionKind MethodKindFor(ParseFunctionFlags flags) {
    1263             :     const bool kIsMethod = true;
    1264             :     return FunctionKindForImpl(kIsMethod, flags);
    1265             :   }
    1266             : 
    1267             :   // Keep track of eval() calls since they disable all local variable
    1268             :   // optimizations. This checks if expression is an eval call, and if yes,
    1269             :   // forwards the information to scope.
    1270    13110372 :   Call::PossiblyEval CheckPossibleEvalCall(ExpressionT expression,
    1271             :                                            Scope* scope) {
    1272    22035110 :     if (impl()->IsIdentifier(expression) &&
    1273             :         impl()->IsEval(impl()->AsIdentifier(expression))) {
    1274             :       scope->RecordInnerScopeEvalCall();
    1275      221421 :       function_state_->RecordFunctionOrEvalCall();
    1276      221421 :       if (is_sloppy(scope->language_mode())) {
    1277             :         // For sloppy scopes we also have to record the call at function level,
    1278             :         // in case it includes declarations that will be hoisted.
    1279      146027 :         scope->GetDeclarationScope()->RecordEvalCall();
    1280             :       }
    1281             : 
    1282             :       // This call is only necessary to track evals that may be
    1283             :       // inside arrow function parameter lists. In that case,
    1284             :       // Scope::Snapshot::Reparent will move this bit down into
    1285             :       // the arrow function's scope.
    1286             :       scope->RecordEvalCall();
    1287             : 
    1288      221423 :       return Call::IS_POSSIBLY_EVAL;
    1289             :     }
    1290             :     return Call::NOT_EVAL;
    1291             :   }
    1292             : 
    1293             :   // Convenience method which determines the type of return statement to emit
    1294             :   // depending on the current function type.
    1295     4282748 :   inline StatementT BuildReturnStatement(ExpressionT expr, int pos,
    1296     8250739 :                                          int end_pos = kNoSourcePosition) {
    1297     4282756 :     if (impl()->IsNull(expr)) {
    1298       46074 :       expr = factory()->NewUndefinedLiteral(kNoSourcePosition);
    1299     3967983 :     } else if (is_async_generator()) {
    1300             :       // In async generators, if there is an explicit operand to the return
    1301             :       // statement, await the operand.
    1302       25543 :       expr = factory()->NewAwait(expr, kNoSourcePosition);
    1303       26699 :       function_state_->AddSuspend();
    1304             :     }
    1305     4282689 :     if (is_async_function()) {
    1306       59622 :       return factory()->NewAsyncReturnStatement(expr, pos, end_pos);
    1307             :     }
    1308     2764296 :     return factory()->NewReturnStatement(expr, pos, end_pos);
    1309             :   }
    1310             : 
    1311       37375 :   ModuleDescriptor* module() const {
    1312       37375 :     return scope()->AsModuleScope()->module();
    1313             :   }
    1314    26814967 :   Scope* scope() const { return scope_; }
    1315             : 
    1316             :   // Stack of expression expression_scopes.
    1317             :   // The top of the stack is always pointed to by expression_scope().
    1318             :   V8_INLINE ExpressionScope* expression_scope() const {
    1319             :     DCHECK_NOT_NULL(expression_scope_);
    1320             :     return expression_scope_;
    1321             :   }
    1322             : 
    1323             :   class AcceptINScope final {
    1324             :    public:
    1325    29839834 :     AcceptINScope(ParserBase* parser, bool accept_IN)
    1326    83519296 :         : parser_(parser), previous_accept_IN_(parser->accept_IN_) {
    1327    83519296 :       parser_->accept_IN_ = accept_IN;
    1328    29839834 :     }
    1329             : 
    1330    73877014 :     ~AcceptINScope() { parser_->accept_IN_ = previous_accept_IN_; }
    1331             : 
    1332             :    private:
    1333             :     ParserBase* parser_;
    1334             :     bool previous_accept_IN_;
    1335             :   };
    1336             : 
    1337             :   class ParameterParsingScope {
    1338             :    public:
    1339             :     ParameterParsingScope(Impl* parser, FormalParametersT* parameters)
    1340     4361622 :         : parser_(parser), parent_parameters_(parser_->parameters_) {
    1341     4361622 :       parser_->parameters_ = parameters;
    1342             :     }
    1343             : 
    1344     4361647 :     ~ParameterParsingScope() { parser_->parameters_ = parent_parameters_; }
    1345             : 
    1346             :    private:
    1347             :     Impl* parser_;
    1348             :     FormalParametersT* parent_parameters_;
    1349             :   };
    1350             : 
    1351             :   class FunctionBodyParsingScope {
    1352             :    public:
    1353             :     explicit FunctionBodyParsingScope(Impl* parser)
    1354     2754062 :         : parser_(parser), expression_scope_(parser_->expression_scope_) {
    1355     2754062 :       parser_->expression_scope_ = nullptr;
    1356             :     }
    1357             : 
    1358             :     ~FunctionBodyParsingScope() {
    1359     2733991 :       parser_->expression_scope_ = expression_scope_;
    1360             :     }
    1361             : 
    1362             :    private:
    1363             :     Impl* parser_;
    1364             :     ExpressionScope* expression_scope_;
    1365             :   };
    1366             : 
    1367       90867 :   std::vector<void*>* pointer_buffer() { return &pointer_buffer_; }
    1368             :   std::vector<void*>* variable_buffer() { return &variable_buffer_; }
    1369             : 
    1370             :   // Parser base's protected field members.
    1371             : 
    1372             :   Scope* scope_;                   // Scope stack.
    1373             :   Scope* original_scope_;  // The top scope for the current parsing item.
    1374             :   FunctionState* function_state_;  // Function state stack.
    1375             :   v8::Extension* extension_;
    1376             :   FuncNameInferrer fni_;
    1377             :   AstValueFactory* ast_value_factory_;  // Not owned.
    1378             :   typename Types::Factory ast_node_factory_;
    1379             :   RuntimeCallStats* runtime_call_stats_;
    1380             :   internal::Logger* logger_;
    1381             :   bool parsing_on_main_thread_;
    1382             :   const bool parsing_module_;
    1383             :   uintptr_t stack_limit_;
    1384             :   PendingCompilationErrorHandler* pending_error_handler_;
    1385             : 
    1386             :   // Parser base's private field members.
    1387             : 
    1388             :  private:
    1389             :   Zone* zone_;
    1390             :   ExpressionScope* expression_scope_;
    1391             : 
    1392             :   std::vector<void*> pointer_buffer_;
    1393             :   std::vector<void*> variable_buffer_;
    1394             : 
    1395             :   Scanner* scanner_;
    1396             : 
    1397             :   int function_literal_id_;
    1398             :   int script_id_;
    1399             : 
    1400             :   FunctionLiteral::EagerCompileHint default_eager_compile_hint_;
    1401             : 
    1402             :   // This struct is used to move information about the next arrow function from
    1403             :   // the place where the arrow head was parsed to where the body will be parsed.
    1404             :   // Nothing can be parsed between the head and the body, so it will be consumed
    1405             :   // immediately after it's produced.
    1406             :   // Preallocating the struct as part of the parser minimizes the cost of
    1407             :   // supporting arrow functions on non-arrow expressions.
    1408     3353303 :   struct NextArrowFunctionInfo {
    1409             :     Scanner::Location strict_parameter_error_location =
    1410             :         Scanner::Location::invalid();
    1411             :     MessageTemplate strict_parameter_error_message = MessageTemplate::kNone;
    1412             :     DeclarationScope* scope = nullptr;
    1413             : 
    1414             :     bool HasInitialState() const { return scope == nullptr; }
    1415             : 
    1416             :     void Reset() {
    1417      902956 :       scope = nullptr;
    1418             :       ClearStrictParameterError();
    1419             :       DCHECK(HasInitialState());
    1420             :     }
    1421             : 
    1422             :     // Tracks strict-mode parameter violations of sloppy-mode arrow heads in
    1423             :     // case the function ends up becoming strict mode. Only one global place to
    1424             :     // track this is necessary since arrow functions with none-simple parameters
    1425             :     // cannot become strict-mode later on.
    1426             :     void ClearStrictParameterError() {
    1427     3842269 :       strict_parameter_error_location = Scanner::Location::invalid();
    1428     3842269 :       strict_parameter_error_message = MessageTemplate::kNone;
    1429             :     }
    1430             :   };
    1431             : 
    1432             :   FormalParametersT* parameters_;
    1433             :   NextArrowFunctionInfo next_arrow_function_info_;
    1434             : 
    1435             :   bool accept_IN_ = true;
    1436             : 
    1437             :   bool allow_natives_;
    1438             :   bool allow_harmony_public_fields_;
    1439             :   bool allow_harmony_static_fields_;
    1440             :   bool allow_harmony_dynamic_import_;
    1441             :   bool allow_harmony_import_meta_;
    1442             :   bool allow_harmony_private_fields_;
    1443             :   bool allow_harmony_private_methods_;
    1444             :   bool allow_eval_cache_;
    1445             : };
    1446             : 
    1447             : template <typename Impl>
    1448       52948 : ParserBase<Impl>::FunctionState::FunctionState(
    1449             :     FunctionState** function_state_stack, Scope** scope_stack,
    1450             :     DeclarationScope* scope)
    1451             :     : BlockState(scope_stack, scope),
    1452             :       expected_property_count_(0),
    1453             :       suspend_count_(0),
    1454             :       function_state_stack_(function_state_stack),
    1455             :       outer_function_state_(*function_state_stack),
    1456             :       scope_(scope),
    1457             :       dont_optimize_reason_(BailoutReason::kNoReason),
    1458             :       next_function_is_likely_called_(false),
    1459             :       previous_function_was_likely_called_(false),
    1460    11008584 :       contains_function_or_eval_(false) {
    1461    11008584 :   *function_state_stack = this;
    1462    11008584 :   if (outer_function_state_) {
    1463     5540584 :     outer_function_state_->previous_function_was_likely_called_ =
    1464             :         outer_function_state_->next_function_is_likely_called_;
    1465     5540584 :     outer_function_state_->next_function_is_likely_called_ = false;
    1466             :   }
    1467       52948 : }
    1468             : 
    1469             : template <typename Impl>
    1470       52948 : ParserBase<Impl>::FunctionState::~FunctionState() {
    1471    11008897 :   *function_state_stack_ = outer_function_state_;
    1472       52948 : }
    1473             : 
    1474             : template <typename Impl>
    1475     3507167 : void ParserBase<Impl>::ReportUnexpectedToken(Token::Value token) {
    1476     5387371 :   return impl()->ReportUnexpectedTokenAt(scanner_->location(), token);
    1477             : }
    1478             : 
    1479             : template <typename Impl>
    1480             : typename ParserBase<Impl>::IdentifierT
    1481      213078 : ParserBase<Impl>::ParseAndClassifyIdentifier(Token::Value next) {
    1482             :   DCHECK_EQ(scanner()->current_token(), next);
    1483    72679551 :   if (V8_LIKELY(IsInRange(next, Token::IDENTIFIER, Token::ASYNC))) {
    1484    72578822 :     IdentifierT name = impl()->GetSymbol();
    1485    72636678 :     if (V8_UNLIKELY(impl()->IsArguments(name) &&
    1486             :                     scope()->ShouldBanArguments())) {
    1487        5600 :       ReportMessage(MessageTemplate::kArgumentsDisallowedInInitializer);
    1488             :       return impl()->EmptyIdentifierString();
    1489             :     }
    1490    40043798 :     return name;
    1491             :   }
    1492             : 
    1493      201235 :   if (!Token::IsValidIdentifier(next, language_mode(), is_generator(),
    1494      238711 :                                 parsing_module_ || is_async_function())) {
    1495       34495 :     ReportUnexpectedToken(next);
    1496       16185 :     return impl()->EmptyIdentifierString();
    1497             :   }
    1498             : 
    1499       66122 :   if (next == Token::AWAIT) {
    1500       44762 :     expression_scope()->RecordAsyncArrowParametersError(
    1501             :         scanner()->location(), MessageTemplate::kAwaitBindingIdentifier);
    1502       22381 :     return impl()->GetSymbol();
    1503             :   }
    1504             : 
    1505             :   DCHECK(Token::IsStrictReservedWord(next));
    1506       87482 :   expression_scope()->RecordStrictModeParameterError(
    1507             :       scanner()->location(), MessageTemplate::kUnexpectedStrictReserved);
    1508       43741 :   return impl()->GetSymbol();
    1509             : }
    1510             : 
    1511             : template <class Impl>
    1512             : typename ParserBase<Impl>::IdentifierT ParserBase<Impl>::ParseIdentifier(
    1513             :     FunctionKind function_kind) {
    1514             :   Token::Value next = Next();
    1515             : 
    1516     2834462 :   if (!Token::IsValidIdentifier(
    1517     2834694 :           next, language_mode(), IsGeneratorFunction(function_kind),
    1518     5669206 :           parsing_module_ || IsAsyncFunction(function_kind))) {
    1519        9873 :     ReportUnexpectedToken(next);
    1520        5497 :     return impl()->EmptyIdentifierString();
    1521             :   }
    1522             : 
    1523     2824589 :   return impl()->GetSymbol();
    1524             : }
    1525             : 
    1526             : template <typename Impl>
    1527             : typename ParserBase<Impl>::IdentifierT
    1528      359576 : ParserBase<Impl>::ParseNonRestrictedIdentifier() {
    1529             :   IdentifierT result = ParseIdentifier();
    1530             : 
    1531      376009 :   if (is_strict(language_mode()) &&
    1532       16613 :       V8_UNLIKELY(impl()->IsEvalOrArguments(result))) {
    1533         286 :     impl()->ReportMessageAt(scanner()->location(),
    1534             :                             MessageTemplate::kStrictEvalArguments);
    1535             :   }
    1536             : 
    1537      359395 :   return result;
    1538             : }
    1539             : 
    1540             : template <typename Impl>
    1541             : typename ParserBase<Impl>::IdentifierT ParserBase<Impl>::ParsePropertyName() {
    1542             :   Token::Value next = Next();
    1543     3096356 :   if (V8_LIKELY(Token::IsPropertyName(next))) return impl()->GetSymbol();
    1544             : 
    1545      154038 :   ReportUnexpectedToken(next);
    1546       71641 :   return impl()->EmptyIdentifierString();
    1547             : }
    1548             : 
    1549             : template <typename Impl>
    1550             : typename ParserBase<Impl>::ExpressionT
    1551    14427404 : ParserBase<Impl>::ParsePropertyOrPrivatePropertyName() {
    1552             :   int pos = position();
    1553             :   IdentifierT name;
    1554             :   ExpressionT key;
    1555             :   Token::Value next = Next();
    1556    14427567 :   if (V8_LIKELY(Token::IsPropertyName(next))) {
    1557     8908493 :     name = impl()->GetSymbol();
    1558     5505579 :     key = factory()->NewStringLiteral(name, pos);
    1559       13579 :   } else if (allow_harmony_private_fields() && next == Token::PRIVATE_NAME) {
    1560        3291 :     name = impl()->GetSymbol();
    1561        3291 :     key = impl()->ExpressionFromIdentifier(name, pos, InferName::kNo);
    1562             :   } else {
    1563        7397 :     ReportUnexpectedToken(next);
    1564        7397 :     return impl()->FailureExpression();
    1565             :   }
    1566             :   impl()->PushLiteralName(name);
    1567    14421231 :   return key;
    1568             : }
    1569             : 
    1570             : template <typename Impl>
    1571      158299 : typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseRegExpLiteral() {
    1572             :   int pos = peek_position();
    1573       79256 :   if (!scanner()->ScanRegExpPattern()) {
    1574             :     Next();
    1575         279 :     ReportMessage(MessageTemplate::kUnterminatedRegExp);
    1576         279 :     return impl()->FailureExpression();
    1577             :   }
    1578             : 
    1579             :   IdentifierT js_pattern = impl()->GetNextSymbol();
    1580       79043 :   Maybe<RegExp::Flags> flags = scanner()->ScanRegExpFlags();
    1581       79049 :   if (flags.IsNothing()) {
    1582             :     Next();
    1583         610 :     ReportMessage(MessageTemplate::kMalformedRegExpFlags);
    1584         610 :     return impl()->FailureExpression();
    1585             :   }
    1586       48592 :   int js_flags = flags.FromJust();
    1587             :   Next();
    1588       97184 :   return factory()->NewRegExpLiteral(js_pattern, js_flags, pos);
    1589             : }
    1590             : 
    1591             : template <typename Impl>
    1592     8045591 : typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseBindingPattern() {
    1593             :   // Pattern ::
    1594             :   //   Identifier
    1595             :   //   ArrayLiteral
    1596             :   //   ObjectLiteral
    1597             : 
    1598             :   int beg_pos = peek_position();
    1599             :   Token::Value token = peek();
    1600             :   ExpressionT result;
    1601             : 
    1602     8042285 :   if (Token::IsAnyIdentifier(token)) {
    1603     3874046 :     IdentifierT name = ParseAndClassifyIdentifier(Next());
    1604     8408379 :     if (V8_UNLIKELY(is_strict(language_mode()) &&
    1605             :                     impl()->IsEvalOrArguments(name))) {
    1606        3287 :       impl()->ReportMessageAt(scanner()->location(),
    1607             :                               MessageTemplate::kStrictEvalArguments);
    1608        3287 :       return impl()->FailureExpression();
    1609             :     }
    1610     7761833 :     return impl()->ExpressionFromIdentifier(name, beg_pos);
    1611             :   }
    1612             : 
    1613      277533 :   CheckStackOverflow();
    1614             : 
    1615      277528 :   if (token == Token::LBRACK) {
    1616       57927 :     result = ParseArrayLiteral();
    1617      219601 :   } else if (token == Token::LBRACE) {
    1618      172922 :     result = ParseObjectLiteral();
    1619             :   } else {
    1620       46679 :     ReportUnexpectedToken(Next());
    1621       46679 :     return impl()->FailureExpression();
    1622             :   }
    1623             : 
    1624      230854 :   return result;
    1625             : }
    1626             : 
    1627             : template <typename Impl>
    1628             : typename ParserBase<Impl>::ExpressionT
    1629   216079508 : ParserBase<Impl>::ParsePrimaryExpression() {
    1630   106161898 :   CheckStackOverflow();
    1631             : 
    1632             :   // PrimaryExpression ::
    1633             :   //   'this'
    1634             :   //   'null'
    1635             :   //   'true'
    1636             :   //   'false'
    1637             :   //   Identifier
    1638             :   //   Number
    1639             :   //   String
    1640             :   //   ArrayLiteral
    1641             :   //   ObjectLiteral
    1642             :   //   RegExpLiteral
    1643             :   //   ClassLiteral
    1644             :   //   '(' Expression ')'
    1645             :   //   TemplateLiteral
    1646             :   //   do Block
    1647             :   //   AsyncFunctionLiteral
    1648             : 
    1649             :   int beg_pos = peek_position();
    1650             :   Token::Value token = peek();
    1651             : 
    1652   106192513 :   if (Token::IsAnyIdentifier(token)) {
    1653             :     Consume(token);
    1654             : 
    1655             :     FunctionKind kind = FunctionKind::kArrowFunction;
    1656             : 
    1657    51049774 :     if (V8_UNLIKELY(token == Token::ASYNC &&
    1658             :                     !scanner()->HasLineTerminatorBeforeNext() &&
    1659             :                     !scanner()->literal_contains_escapes())) {
    1660             :       // async function ...
    1661       43862 :       if (peek() == Token::FUNCTION) return ParseAsyncFunctionLiteral();
    1662             : 
    1663             :       // async Identifier => ...
    1664       23361 :       if (peek_any_identifier() && PeekAhead() == Token::ARROW) {
    1665             :         token = Next();
    1666             :         beg_pos = position();
    1667             :         kind = FunctionKind::kAsyncArrowFunction;
    1668             :       }
    1669             :     }
    1670             : 
    1671    50985169 :     if (V8_UNLIKELY(peek() == Token::ARROW)) {
    1672             :       ArrowHeadParsingScope parsing_scope(impl(), kind);
    1673      316125 :       IdentifierT name = ParseAndClassifyIdentifier(token);
    1674      372191 :       ClassifyParameter(name, beg_pos, end_position());
    1675             :       ExpressionT result =
    1676      316127 :           impl()->ExpressionFromIdentifier(name, beg_pos, InferName::kNo);
    1677      372198 :       next_arrow_function_info_.scope = parsing_scope.ValidateAndCreateScope();
    1678      316109 :       return result;
    1679             :     }
    1680             : 
    1681    31135639 :     IdentifierT name = ParseAndClassifyIdentifier(token);
    1682    50626158 :     return impl()->ExpressionFromIdentifier(name, beg_pos);
    1683             :   }
    1684             : 
    1685    55190512 :   if (Token::IsLiteral(token)) {
    1686    25733765 :     return impl()->ExpressionFromLiteral(Next(), beg_pos);
    1687             :   }
    1688             : 
    1689    12606399 :   switch (token) {
    1690             :     case Token::THIS: {
    1691             :       Consume(Token::THIS);
    1692     2481777 :       return impl()->ThisExpression();
    1693             :     }
    1694             : 
    1695             :     case Token::ASSIGN_DIV:
    1696             :     case Token::DIV:
    1697       79256 :       return ParseRegExpLiteral();
    1698             : 
    1699             :     case Token::LBRACK:
    1700     1087414 :       return ParseArrayLiteral();
    1701             : 
    1702             :     case Token::LBRACE:
    1703     1171047 :       return ParseObjectLiteral();
    1704             : 
    1705             :     case Token::LPAREN: {
    1706             :       Consume(Token::LPAREN);
    1707     3477979 :       if (Check(Token::RPAREN)) {
    1708             :         // ()=>x.  The continuation that consumes the => is in
    1709             :         // ParseAssignmentExpressionCoverGrammar.
    1710      421986 :         if (peek() != Token::ARROW) ReportUnexpectedToken(Token::RPAREN);
    1711      421978 :         next_arrow_function_info_.scope =
    1712      421986 :             NewFunctionScope(FunctionKind::kArrowFunction);
    1713      521753 :         return factory()->NewEmptyParentheses(beg_pos);
    1714             :       }
    1715     3055995 :       Scope::Snapshot scope_snapshot(scope());
    1716             :       ArrowHeadParsingScope maybe_arrow(impl(), FunctionKind::kArrowFunction);
    1717             :       // Heuristically try to detect immediately called functions before
    1718             :       // seeing the call parentheses.
    1719     5521992 :       if (peek() == Token::FUNCTION ||
    1720             :           (peek() == Token::ASYNC && PeekAhead() == Token::FUNCTION)) {
    1721      610178 :         function_state_->set_next_function_is_likely_called();
    1722             :       }
    1723             :       AcceptINScope scope(this, true);
    1724     3056006 :       ExpressionT expr = ParseExpressionCoverGrammar();
    1725             :       expr->mark_parenthesized();
    1726     3055991 :       Expect(Token::RPAREN);
    1727             : 
    1728     3055998 :       if (peek() == Token::ARROW) {
    1729      120957 :         next_arrow_function_info_.scope = maybe_arrow.ValidateAndCreateScope();
    1730      120959 :         scope_snapshot.Reparent(next_arrow_function_info_.scope);
    1731             :       } else {
    1732     2935041 :         maybe_arrow.ValidateExpression();
    1733             :       }
    1734             : 
    1735     1893131 :       return expr;
    1736             :     }
    1737             : 
    1738             :     case Token::CLASS: {
    1739             :       Consume(Token::CLASS);
    1740             :       int class_token_pos = position();
    1741       59008 :       IdentifierT name = impl()->NullIdentifier();
    1742             :       bool is_strict_reserved_name = false;
    1743      136744 :       Scanner::Location class_name_location = Scanner::Location::invalid();
    1744      136744 :       if (peek_any_identifier()) {
    1745        1684 :         name = ParseAndClassifyIdentifier(Next());
    1746       18069 :         class_name_location = scanner()->location();
    1747             :         is_strict_reserved_name =
    1748             :             Token::IsStrictReservedWord(scanner()->current_token());
    1749             :       }
    1750             :       return ParseClassLiteral(name, class_name_location,
    1751      136744 :                                is_strict_reserved_name, class_token_pos);
    1752             :     }
    1753             : 
    1754             :     case Token::TEMPLATE_SPAN:
    1755             :     case Token::TEMPLATE_TAIL:
    1756       58069 :       return ParseTemplateLiteral(impl()->NullExpression(), beg_pos, false);
    1757             : 
    1758             :     case Token::MOD:
    1759      127088 :       if (allow_natives() || extension_ != nullptr) {
    1760      126909 :         return ParseV8Intrinsic();
    1761             :       }
    1762             :       break;
    1763             : 
    1764             :     default:
    1765             :       break;
    1766             :   }
    1767             : 
    1768      946576 :   ReportUnexpectedToken(Next());
    1769      946576 :   return impl()->FailureExpression();
    1770             : }
    1771             : 
    1772             : template <typename Impl>
    1773             : typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseExpression() {
    1774    29723020 :   ExpressionParsingScope expression_scope(impl());
    1775    59447244 :   AcceptINScope scope(this, true);
    1776    29723744 :   ExpressionT result = ParseExpressionCoverGrammar();
    1777    29723349 :   expression_scope.ValidateExpression();
    1778    42392001 :   return result;
    1779             : }
    1780             : 
    1781             : template <typename Impl>
    1782             : typename ParserBase<Impl>::ExpressionT
    1783             : ParserBase<Impl>::ParseAssignmentExpression() {
    1784    24574163 :   ExpressionParsingScope expression_scope(impl());
    1785    24574681 :   ExpressionT result = ParseAssignmentExpressionCoverGrammar();
    1786    24573936 :   expression_scope.ValidateExpression();
    1787    24573749 :   return result;
    1788             : }
    1789             : 
    1790             : template <typename Impl>
    1791             : typename ParserBase<Impl>::ExpressionT
    1792   114170903 : ParserBase<Impl>::ParseExpressionCoverGrammar() {
    1793             :   // Expression ::
    1794             :   //   AssignmentExpression
    1795             :   //   Expression ',' AssignmentExpression
    1796             : 
    1797    15835095 :   ExpressionListT list(pointer_buffer());
    1798             :   ExpressionT expression;
    1799    52975474 :   AccumulationScope accumulation_scope(expression_scope());
    1800             :   while (true) {
    1801    39900464 :     if (V8_UNLIKELY(peek() == Token::ELLIPSIS)) {
    1802       10425 :       return ParseArrowParametersWithRest(&list, &accumulation_scope);
    1803             :     }
    1804             : 
    1805             :     int expr_pos = peek_position();
    1806    39890039 :     expression = ParseAssignmentExpressionCoverGrammar();
    1807             : 
    1808    39886272 :     ClassifyArrowParameter(&accumulation_scope, expr_pos, expression);
    1809    18507230 :     list.Add(expression);
    1810             : 
    1811    39888660 :     if (!Check(Token::COMMA)) break;
    1812             : 
    1813     2761352 :     if (peek() == Token::RPAREN && PeekAhead() == Token::ARROW) {
    1814             :       // a trailing comma is allowed at the end of an arrow parameter list
    1815             :       break;
    1816             :     }
    1817             : 
    1818             :     // Pass on the 'set_next_function_is_likely_called' flag if we have
    1819             :     // several function literals separated by comma.
    1820     2760189 :     if (peek() == Token::FUNCTION &&
    1821             :         function_state_->previous_function_was_likely_called()) {
    1822          16 :       function_state_->set_next_function_is_likely_called();
    1823             :     }
    1824             :   }
    1825             : 
    1826             :   // Return the single element if the list is empty. We need to do this because
    1827             :   // callers of this function care about the type of the result if there was
    1828             :   // only a single assignment expression. The preparser would lose this
    1829             :   // information otherwise.
    1830    52958107 :   if (list.length() == 1) return expression;
    1831    21361618 :   return impl()->ExpressionListToExpression(list);
    1832             : }
    1833             : 
    1834             : template <typename Impl>
    1835             : typename ParserBase<Impl>::ExpressionT
    1836       10424 : ParserBase<Impl>::ParseArrowParametersWithRest(
    1837        1654 :     typename ParserBase<Impl>::ExpressionListT* list,
    1838       20851 :     AccumulationScope* accumulation_scope) {
    1839             :   Consume(Token::ELLIPSIS);
    1840             : 
    1841        5409 :   Scanner::Location ellipsis = scanner()->location();
    1842             :   int pattern_pos = peek_position();
    1843       10425 :   ExpressionT pattern = ParseBindingPattern();
    1844       10426 :   ClassifyArrowParameter(accumulation_scope, pattern_pos, pattern);
    1845             : 
    1846             :   expression_scope()->RecordNonSimpleParameter();
    1847             : 
    1848       10426 :   if (V8_UNLIKELY(peek() == Token::ASSIGN)) {
    1849         152 :     ReportMessage(MessageTemplate::kRestDefaultInitializer);
    1850         152 :     return impl()->FailureExpression();
    1851             :   }
    1852             : 
    1853             :   ExpressionT spread =
    1854        5328 :       factory()->NewSpread(pattern, ellipsis.beg_pos, pattern_pos);
    1855       10274 :   if (V8_UNLIKELY(peek() == Token::COMMA)) {
    1856         384 :     ReportMessage(MessageTemplate::kParamAfterRest);
    1857         384 :     return impl()->FailureExpression();
    1858             :   }
    1859             : 
    1860             :   // 'x, y, ...z' in CoverParenthesizedExpressionAndArrowParameterList only
    1861             :   // as the formal parameters of'(x, y, ...z) => foo', and is not itself a
    1862             :   // valid expression.
    1863       18505 :   if (peek() != Token::RPAREN || PeekAhead() != Token::ARROW) {
    1864        3490 :     impl()->ReportUnexpectedTokenAt(ellipsis, Token::ELLIPSIS);
    1865        7050 :     return impl()->FailureExpression();
    1866             :   }
    1867             : 
    1868             :   list->Add(spread);
    1869        1654 :   return impl()->ExpressionListToExpression(*list);
    1870             : }
    1871             : 
    1872             : template <typename Impl>
    1873     2351303 : typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseArrayLiteral() {
    1874             :   // ArrayLiteral ::
    1875             :   //   '[' Expression? (',' Expression?)* ']'
    1876             : 
    1877             :   int pos = peek_position();
    1878      744855 :   ExpressionListT values(pointer_buffer());
    1879             :   int first_spread_index = -1;
    1880             :   Consume(Token::LBRACK);
    1881             : 
    1882     1890279 :   AccumulationScope accumulation_scope(expression_scope());
    1883             : 
    1884    12776856 :   while (!Check(Token::RBRACK)) {
    1885             :     ExpressionT elem;
    1886    10510484 :     if (peek() == Token::COMMA) {
    1887     1073541 :       elem = factory()->NewTheHoleLiteral();
    1888     8362825 :     } else if (Check(Token::ELLIPSIS)) {
    1889             :       int start_pos = position();
    1890             :       int expr_pos = peek_position();
    1891             :       AcceptINScope scope(this, true);
    1892             :       ExpressionT argument =
    1893       40462 :           ParsePossibleDestructuringSubPattern(&accumulation_scope);
    1894       18103 :       elem = factory()->NewSpread(argument, start_pos, expr_pos);
    1895             : 
    1896       18104 :       if (first_spread_index < 0) {
    1897       17166 :         first_spread_index = values.length();
    1898             :       }
    1899             : 
    1900       40459 :       if (argument->IsAssignment()) {
    1901        3215 :         expression_scope()->RecordPatternError(
    1902             :             Scanner::Location(start_pos, end_position()),
    1903             :             MessageTemplate::kInvalidDestructuringTarget);
    1904             :       }
    1905             : 
    1906       40460 :       if (peek() == Token::COMMA) {
    1907        6802 :         expression_scope()->RecordPatternError(
    1908             :             Scanner::Location(start_pos, end_position()),
    1909             :             MessageTemplate::kElementAfterRest);
    1910             :       }
    1911             :     } else {
    1912             :       AcceptINScope scope(this, true);
    1913     8322363 :       elem = ParsePossibleDestructuringSubPattern(&accumulation_scope);
    1914             :     }
    1915     7738214 :     values.Add(elem);
    1916    10510501 :     if (peek() != Token::RBRACK) {
    1917     9929094 :       Expect(Token::COMMA);
    1918     9929506 :       if (elem->IsFailureExpression()) return elem;
    1919             :     }
    1920             :   }
    1921             : 
    1922     1134043 :   return factory()->NewArrayLiteral(values, first_spread_index, pos);
    1923             : }
    1924             : 
    1925             : template <class Impl>
    1926     5493515 : typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseProperty(
    1927     5256127 :     ParsePropertyInfo* prop_info) {
    1928             :   DCHECK_EQ(prop_info->kind, ParsePropertyKind::kNotSet);
    1929             :   DCHECK_EQ(prop_info->function_flags, ParseFunctionFlag::kIsNormal);
    1930             :   DCHECK(!prop_info->is_computed_name);
    1931             : 
    1932     5493503 :   if (Check(Token::ASYNC)) {
    1933             :     Token::Value token = peek();
    1934       65832 :     if ((token != Token::MUL && prop_info->ParsePropertyKindFromToken(token)) ||
    1935             :         scanner()->HasLineTerminatorBeforeNext()) {
    1936        5520 :       prop_info->name = impl()->GetSymbol();
    1937             :       impl()->PushLiteralName(prop_info->name);
    1938        5520 :       return factory()->NewStringLiteral(prop_info->name, position());
    1939             :     }
    1940       29516 :     if (V8_UNLIKELY(scanner()->literal_contains_escapes())) {
    1941           0 :       impl()->ReportUnexpectedToken(Token::ESCAPED_KEYWORD);
    1942             :     }
    1943       29516 :     prop_info->function_flags = ParseFunctionFlag::kIsAsync;
    1944       29516 :     prop_info->kind = ParsePropertyKind::kMethod;
    1945             :   }
    1946             : 
    1947     5487871 :   if (Check(Token::MUL)) {
    1948             :     prop_info->function_flags |= ParseFunctionFlag::kIsGenerator;
    1949       46624 :     prop_info->kind = ParsePropertyKind::kMethod;
    1950             :   }
    1951             : 
    1952    10909193 :   if (prop_info->kind == ParsePropertyKind::kNotSet &&
    1953             :       IsInRange(peek(), Token::GET, Token::SET)) {
    1954             :     Token::Value token = Next();
    1955      114048 :     if (prop_info->ParsePropertyKindFromToken(peek())) {
    1956       35671 :       prop_info->name = impl()->GetSymbol();
    1957             :       impl()->PushLiteralName(prop_info->name);
    1958       54814 :       return factory()->NewStringLiteral(prop_info->name, position());
    1959             :     }
    1960       78372 :     if (V8_UNLIKELY(scanner()->literal_contains_escapes())) {
    1961         240 :       impl()->ReportUnexpectedToken(Token::ESCAPED_KEYWORD);
    1962             :     }
    1963       78371 :     if (token == Token::GET) {
    1964       43487 :       prop_info->kind = ParsePropertyKind::kAccessorGetter;
    1965       34884 :     } else if (token == Token::SET) {
    1966       34884 :       prop_info->kind = ParsePropertyKind::kAccessorSetter;
    1967             :     }
    1968             :   }
    1969             : 
    1970             :   int pos = peek_position();
    1971             : 
    1972             :   // For non computed property names we normalize the name a bit:
    1973             :   //
    1974             :   //   "12" -> 12
    1975             :   //   12.3 -> "12.3"
    1976             :   //   12.30 -> "12.3"
    1977             :   //   identifier -> "identifier"
    1978             :   //
    1979             :   // This is important because we use the property name as a key in a hash
    1980             :   // table when we compute constant properties.
    1981             :   bool is_array_index;
    1982             :   uint32_t index;
    1983     5452173 :   switch (peek()) {
    1984             :     case Token::PRIVATE_NAME:
    1985       50628 :       prop_info->is_private = true;
    1986             :       is_array_index = false;
    1987             :       Consume(Token::PRIVATE_NAME);
    1988       50628 :       if (prop_info->kind == ParsePropertyKind::kNotSet) {
    1989       32867 :         prop_info->ParsePropertyKindFromToken(peek());
    1990             :       }
    1991       50627 :       prop_info->name = impl()->GetSymbol();
    1992       50627 :       if (V8_UNLIKELY(prop_info->position ==
    1993             :                       PropertyPosition::kObjectLiteral)) {
    1994        1470 :         ReportUnexpectedToken(Token::PRIVATE_NAME);
    1995        1470 :         prop_info->kind = ParsePropertyKind::kNotSet;
    1996        1470 :         return impl()->FailureExpression();
    1997             :       }
    1998       49157 :       if (V8_UNLIKELY(!allow_harmony_private_methods() &&
    1999             :                       (IsAccessor(prop_info->kind) ||
    2000             :                        prop_info->kind == ParsePropertyKind::kMethod))) {
    2001        1920 :         ReportUnexpectedToken(Next());
    2002        1920 :         prop_info->kind = ParsePropertyKind::kNotSet;
    2003        1920 :         return impl()->FailureExpression();
    2004             :       }
    2005             :       break;
    2006             : 
    2007             :     case Token::STRING:
    2008             :       Consume(Token::STRING);
    2009       89978 :       prop_info->name = impl()->GetSymbol();
    2010             :       is_array_index = impl()->IsArrayIndex(prop_info->name, &index);
    2011       89978 :       break;
    2012             : 
    2013             :     case Token::SMI:
    2014             :       Consume(Token::SMI);
    2015     1448357 :       index = scanner()->smi_value();
    2016             :       is_array_index = true;
    2017             :       // Token::SMI were scanned from their canonical representation.
    2018     2121934 :       prop_info->name = impl()->GetSymbol();
    2019     2121935 :       break;
    2020             : 
    2021             :     case Token::NUMBER: {
    2022             :       Consume(Token::NUMBER);
    2023        7225 :       prop_info->name = impl()->GetNumberAsSymbol();
    2024             :       is_array_index = impl()->IsArrayIndex(prop_info->name, &index);
    2025        7225 :       break;
    2026             :     }
    2027             :     case Token::LBRACK: {
    2028       65079 :       prop_info->name = impl()->NullIdentifier();
    2029       65079 :       prop_info->is_computed_name = true;
    2030             :       Consume(Token::LBRACK);
    2031             :       AcceptINScope scope(this, true);
    2032             :       ExpressionT expression = ParseAssignmentExpression();
    2033       65079 :       Expect(Token::RBRACK);
    2034       65079 :       if (prop_info->kind == ParsePropertyKind::kNotSet) {
    2035       59206 :         prop_info->ParsePropertyKindFromToken(peek());
    2036             :       }
    2037       33291 :       return expression;
    2038             :     }
    2039             : 
    2040             :     case Token::ELLIPSIS:
    2041       24531 :       if (prop_info->kind == ParsePropertyKind::kNotSet) {
    2042       24210 :         prop_info->name = impl()->NullIdentifier();
    2043             :         Consume(Token::ELLIPSIS);
    2044             :         AcceptINScope scope(this, true);
    2045             :         int start_pos = peek_position();
    2046             :         ExpressionT expression =
    2047       24211 :             ParsePossibleDestructuringSubPattern(prop_info->accumulation_scope);
    2048       24211 :         prop_info->kind = ParsePropertyKind::kSpread;
    2049             : 
    2050       24211 :         if (!IsValidReferenceExpression(expression)) {
    2051        8264 :           expression_scope()->RecordDeclarationError(
    2052             :               Scanner::Location(start_pos, end_position()),
    2053             :               MessageTemplate::kInvalidRestBindingPattern);
    2054        8264 :           expression_scope()->RecordPatternError(
    2055             :               Scanner::Location(start_pos, end_position()),
    2056             :               MessageTemplate::kInvalidRestAssignmentPattern);
    2057             :         }
    2058             : 
    2059       24211 :         if (peek() != Token::RBRACE) {
    2060       23498 :           expression_scope()->RecordPatternError(
    2061             :               scanner()->location(), MessageTemplate::kElementAfterRest);
    2062             :         }
    2063       13010 :         return expression;
    2064             :       }
    2065             :       V8_FALLTHROUGH;
    2066             : 
    2067             :     default:
    2068     3093367 :       prop_info->name = ParsePropertyName();
    2069             :       is_array_index = false;
    2070     3093367 :       break;
    2071             :   }
    2072             : 
    2073     5359742 :   if (prop_info->kind == ParsePropertyKind::kNotSet) {
    2074     5197459 :     prop_info->ParsePropertyKindFromToken(peek());
    2075             :   }
    2076     3464408 :   impl()->PushLiteralName(prop_info->name);
    2077     3464436 :   return is_array_index ? factory()->NewNumberLiteral(index, pos)
    2078    10274992 :                         : factory()->NewStringLiteral(prop_info->name, pos);
    2079             : }
    2080             : 
    2081             : template <typename Impl>
    2082             : typename ParserBase<Impl>::ClassLiteralPropertyT
    2083      607452 : ParserBase<Impl>::ParseClassPropertyDefinition(ClassInfo* class_info,
    2084             :                                                ParsePropertyInfo* prop_info,
    2085     1399414 :                                                bool has_extends) {
    2086             :   DCHECK_NOT_NULL(class_info);
    2087             :   DCHECK_EQ(prop_info->position, PropertyPosition::kClassLiteral);
    2088             : 
    2089             :   Token::Value name_token = peek();
    2090             :   DCHECK_IMPLIES(name_token == Token::PRIVATE_NAME,
    2091             :                  allow_harmony_private_fields());
    2092             : 
    2093      607454 :   int property_beg_pos = scanner()->peek_location().beg_pos;
    2094             :   int name_token_position = property_beg_pos;
    2095             :   ExpressionT name_expression;
    2096      607454 :   if (name_token == Token::STATIC) {
    2097             :     Consume(Token::STATIC);
    2098      107427 :     name_token_position = scanner()->peek_location().beg_pos;
    2099      107427 :     if (peek() == Token::LPAREN) {
    2100         240 :       prop_info->kind = ParsePropertyKind::kMethod;
    2101             :       // TODO(bakkot) specialize on 'static'
    2102         240 :       prop_info->name = impl()->GetSymbol();
    2103         120 :       name_expression =
    2104             :           factory()->NewStringLiteral(prop_info->name, position());
    2105      321561 :     } else if (peek() == Token::ASSIGN || peek() == Token::SEMICOLON ||
    2106             :                peek() == Token::RBRACE) {
    2107             :       // TODO(bakkot) specialize on 'static'
    2108         800 :       prop_info->name = impl()->GetSymbol();
    2109         400 :       name_expression =
    2110             :           factory()->NewStringLiteral(prop_info->name, position());
    2111             :     } else {
    2112      106387 :       prop_info->is_static = true;
    2113      106387 :       name_expression = ParseProperty(prop_info);
    2114             :     }
    2115             :   } else {
    2116      500027 :     name_expression = ParseProperty(prop_info);
    2117             :   }
    2118             : 
    2119      713818 :   if (!class_info->has_name_static_property && prop_info->is_static &&
    2120             :       impl()->IsName(prop_info->name)) {
    2121         117 :     class_info->has_name_static_property = true;
    2122             :   }
    2123             : 
    2124      607437 :   switch (prop_info->kind) {
    2125             :     case ParsePropertyKind::kAssign:
    2126             :     case ParsePropertyKind::kClassField:
    2127             :     case ParsePropertyKind::kShorthandOrClassField:
    2128             :     case ParsePropertyKind::kNotSet:  // This case is a name followed by a name
    2129             :                                       // or other property. Here we have to
    2130             :                                       // assume that's an uninitialized field
    2131             :                                       // followed by a linebreak followed by a
    2132             :                                       // property, with ASI adding the
    2133             :                                       // semicolon. If not, there will be a
    2134             :                                       // syntax error after parsing the first
    2135             :                                       // name as an uninitialized field.
    2136      225345 :       if (allow_harmony_public_fields() || allow_harmony_private_fields()) {
    2137      113510 :         prop_info->kind = ParsePropertyKind::kClassField;
    2138             :         DCHECK_IMPLIES(prop_info->is_computed_name, !prop_info->is_private);
    2139             : 
    2140      165831 :         if (prop_info->is_static && !allow_harmony_static_fields()) {
    2141       11840 :           ReportUnexpectedToken(Next());
    2142       11840 :           return impl()->NullLiteralProperty();
    2143             :         }
    2144             : 
    2145      101670 :         if (!prop_info->is_computed_name) {
    2146       91737 :           CheckClassFieldName(prop_info->name, prop_info->is_static);
    2147             :         }
    2148             : 
    2149             :         ExpressionT initializer = ParseMemberInitializer(
    2150      101671 :             class_info, property_beg_pos, prop_info->is_static);
    2151      101671 :         ExpectSemicolon();
    2152             : 
    2153             :         ClassLiteralPropertyT result = factory()->NewClassLiteralProperty(
    2154             :             name_expression, initializer, ClassLiteralProperty::FIELD,
    2155             :             prop_info->is_static, prop_info->is_computed_name,
    2156       52039 :             prop_info->is_private);
    2157       52039 :         impl()->SetFunctionNameFromPropertyName(result, prop_info->name);
    2158             : 
    2159      101670 :         return result;
    2160             : 
    2161             :       } else {
    2162       47060 :         ReportUnexpectedToken(Next());
    2163       47060 :         return impl()->NullLiteralProperty();
    2164             :       }
    2165             : 
    2166             :     case ParsePropertyKind::kMethod: {
    2167             :       // MethodDefinition
    2168             :       //    PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}'
    2169             :       //    '*' PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}'
    2170             :       //    async PropertyName '(' StrictFormalParameters ')'
    2171             :       //        '{' FunctionBody '}'
    2172             :       //    async '*' PropertyName '(' StrictFormalParameters ')'
    2173             :       //        '{' FunctionBody '}'
    2174             : 
    2175      400365 :       if (!prop_info->is_computed_name) {
    2176      392634 :         CheckClassMethodName(prop_info->name, ParsePropertyKind::kMethod,
    2177             :                              prop_info->function_flags, prop_info->is_static,
    2178      392634 :                              &class_info->has_seen_constructor);
    2179             :       }
    2180             : 
    2181             :       FunctionKind kind = MethodKindFor(prop_info->function_flags);
    2182             : 
    2183      769703 :       if (!prop_info->is_static && impl()->IsConstructor(prop_info->name)) {
    2184       21141 :         class_info->has_seen_constructor = true;
    2185       21141 :         kind = has_extends ? FunctionKind::kDerivedConstructor
    2186             :                            : FunctionKind::kBaseConstructor;
    2187             :       }
    2188             : 
    2189             :       ExpressionT value = impl()->ParseFunctionLiteral(
    2190             :           prop_info->name, scanner()->location(), kSkipFunctionNameCheck, kind,
    2191             :           name_token_position, FunctionLiteral::kAccessorOrMethod,
    2192      800750 :           language_mode(), nullptr);
    2193             : 
    2194             :       ClassLiteralPropertyT result = factory()->NewClassLiteralProperty(
    2195             :           name_expression, value, ClassLiteralProperty::METHOD,
    2196             :           prop_info->is_static, prop_info->is_computed_name,
    2197      358600 :           prop_info->is_private);
    2198      358599 :       impl()->SetFunctionNameFromPropertyName(result, prop_info->name);
    2199      400395 :       return result;
    2200             :     }
    2201             : 
    2202             :     case ParsePropertyKind::kAccessorGetter:
    2203             :     case ParsePropertyKind::kAccessorSetter: {
    2204             :       DCHECK_EQ(prop_info->function_flags, ParseFunctionFlag::kIsNormal);
    2205       44958 :       bool is_get = prop_info->kind == ParsePropertyKind::kAccessorGetter;
    2206             : 
    2207       44958 :       if (!prop_info->is_computed_name) {
    2208       41377 :         CheckClassMethodName(prop_info->name, prop_info->kind,
    2209             :                              ParseFunctionFlag::kIsNormal, prop_info->is_static,
    2210      105396 :                              &class_info->has_seen_constructor);
    2211             :         // Make sure the name expression is a string since we need a Name for
    2212             :         // Runtime_DefineAccessorPropertyUnchecked and since we can determine
    2213             :         // this statically we can skip the extra runtime check.
    2214       23426 :         name_expression = factory()->NewStringLiteral(
    2215             :             prop_info->name, name_expression->position());
    2216             :       }
    2217             : 
    2218             :       FunctionKind kind = is_get ? FunctionKind::kGetterFunction
    2219       44958 :                                  : FunctionKind::kSetterFunction;
    2220             : 
    2221             :       FunctionLiteralT value = impl()->ParseFunctionLiteral(
    2222             :           prop_info->name, scanner()->location(), kSkipFunctionNameCheck, kind,
    2223             :           name_token_position, FunctionLiteral::kAccessorOrMethod,
    2224       89916 :           language_mode(), nullptr);
    2225             : 
    2226             :       ClassLiteralProperty::Kind property_kind =
    2227       25789 :           is_get ? ClassLiteralProperty::GETTER : ClassLiteralProperty::SETTER;
    2228             :       ClassLiteralPropertyT result = factory()->NewClassLiteralProperty(
    2229             :           name_expression, value, property_kind, prop_info->is_static,
    2230       25789 :           prop_info->is_computed_name, prop_info->is_private);
    2231             :       const AstRawString* prefix =
    2232       25789 :           is_get ? ast_value_factory()->get_space_string()
    2233       25789 :                  : ast_value_factory()->set_space_string();
    2234       25789 :       impl()->SetFunctionNameFromPropertyName(result, prop_info->name, prefix);
    2235       44958 :       return result;
    2236             :     }
    2237             :     case ParsePropertyKind::kValue:
    2238             :     case ParsePropertyKind::kShorthand:
    2239             :     case ParsePropertyKind::kSpread:
    2240        1568 :       impl()->ReportUnexpectedTokenAt(
    2241             :           Scanner::Location(name_token_position, name_expression->position()),
    2242             :           name_token);
    2243        1544 :       return impl()->NullLiteralProperty();
    2244             :   }
    2245           0 :   UNREACHABLE();
    2246             : }
    2247             : 
    2248             : template <typename Impl>
    2249      101670 : typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseMemberInitializer(
    2250      101671 :     ClassInfo* class_info, int beg_pos, bool is_static) {
    2251             :   DeclarationScope* initializer_scope =
    2252             :       is_static ? class_info->static_fields_scope
    2253      101670 :                 : class_info->instance_members_scope;
    2254             : 
    2255      101670 :   if (initializer_scope == nullptr) {
    2256       93071 :     initializer_scope =
    2257             :         NewFunctionScope(FunctionKind::kClassMembersInitializerFunction);
    2258             :     // TODO(gsathya): Make scopes be non contiguous.
    2259             :     initializer_scope->set_start_position(beg_pos);
    2260             :     initializer_scope->SetLanguageMode(LanguageMode::kStrict);
    2261             :   }
    2262             : 
    2263             :   ExpressionT initializer;
    2264      101671 :   if (Check(Token::ASSIGN)) {
    2265             :     FunctionState initializer_state(&function_state_, &scope_,
    2266       32811 :                                     initializer_scope);
    2267             : 
    2268             :     AcceptINScope scope(this, true);
    2269             :     initializer = ParseAssignmentExpression();
    2270             :   } else {
    2271       34652 :     initializer = factory()->NewUndefinedLiteral(kNoSourcePosition);
    2272             :   }
    2273             : 
    2274             :   initializer_scope->set_end_position(end_position());
    2275      101671 :   if (is_static) {
    2276       40481 :     class_info->static_fields_scope = initializer_scope;
    2277       40481 :     class_info->has_static_class_fields = true;
    2278             :   } else {
    2279       61190 :     class_info->instance_members_scope = initializer_scope;
    2280       61190 :     class_info->has_instance_members = true;
    2281             :   }
    2282             : 
    2283      101671 :   return initializer;
    2284             : }
    2285             : 
    2286             : template <typename Impl>
    2287             : typename ParserBase<Impl>::ObjectLiteralPropertyT
    2288     4887078 : ParserBase<Impl>::ParseObjectPropertyDefinition(ParsePropertyInfo* prop_info,
    2289    10108924 :                                                 bool* has_seen_proto) {
    2290             :   DCHECK_EQ(prop_info->position, PropertyPosition::kObjectLiteral);
    2291             :   Token::Value name_token = peek();
    2292     4887087 :   Scanner::Location next_loc = scanner()->peek_location();
    2293             : 
    2294     4887087 :   ExpressionT name_expression = ParseProperty(prop_info);
    2295             : 
    2296             :   DCHECK_IMPLIES(name_token == Token::PRIVATE_NAME, has_error());
    2297             : 
    2298     4887089 :   IdentifierT name = prop_info->name;
    2299     4887089 :   ParseFunctionFlags function_flags = prop_info->function_flags;
    2300     4887089 :   ParsePropertyKind kind = prop_info->kind;
    2301             : 
    2302     4887089 :   switch (prop_info->kind) {
    2303             :     case ParsePropertyKind::kSpread:
    2304             :       DCHECK_EQ(function_flags, ParseFunctionFlag::kIsNormal);
    2305             :       DCHECK(!prop_info->is_computed_name);
    2306             :       DCHECK_EQ(Token::ELLIPSIS, name_token);
    2307             : 
    2308       24185 :       prop_info->is_computed_name = true;
    2309       24185 :       prop_info->is_rest = true;
    2310             : 
    2311             :       return factory()->NewObjectLiteralProperty(
    2312             :           factory()->NewTheHoleLiteral(), name_expression,
    2313       33525 :           ObjectLiteralProperty::SPREAD, true);
    2314             : 
    2315             :     case ParsePropertyKind::kValue: {
    2316             :       DCHECK_EQ(function_flags, ParseFunctionFlag::kIsNormal);
    2317             : 
    2318    13397595 :       if (!prop_info->is_computed_name &&
    2319             :           impl()->IdentifierEquals(name, ast_value_factory()->proto_string())) {
    2320        9401 :         if (*has_seen_proto) {
    2321             :           expression_scope()->RecordExpressionError(
    2322             :               scanner()->location(), MessageTemplate::kDuplicateProto);
    2323             :         }
    2324        9401 :         *has_seen_proto = true;
    2325             :       }
    2326             :       Consume(Token::COLON);
    2327             :       AcceptINScope scope(this, true);
    2328             :       ExpressionT value =
    2329     4489790 :           ParsePossibleDestructuringSubPattern(prop_info->accumulation_scope);
    2330             : 
    2331             :       ObjectLiteralPropertyT result = factory()->NewObjectLiteralProperty(
    2332     2899183 :           name_expression, value, prop_info->is_computed_name);
    2333     2899155 :       impl()->SetFunctionNameFromPropertyName(result, name);
    2334     1590416 :       return result;
    2335             :     }
    2336             : 
    2337             :     case ParsePropertyKind::kAssign:
    2338             :     case ParsePropertyKind::kShorthandOrClassField:
    2339             :     case ParsePropertyKind::kShorthand: {
    2340             :       // PropertyDefinition
    2341             :       //    IdentifierReference
    2342             :       //    CoverInitializedName
    2343             :       //
    2344             :       // CoverInitializedName
    2345             :       //    IdentifierReference Initializer?
    2346             :       DCHECK_EQ(function_flags, ParseFunctionFlag::kIsNormal);
    2347             : 
    2348      203814 :       if (!Token::IsValidIdentifier(name_token, language_mode(), is_generator(),
    2349      403802 :                                     parsing_module_ || is_async_function())) {
    2350        8107 :         ReportUnexpectedToken(Next());
    2351        8108 :         return impl()->NullLiteralProperty();
    2352             :       }
    2353             : 
    2354             :       DCHECK(!prop_info->is_computed_name);
    2355             : 
    2356      195707 :       if (name_token == Token::AWAIT) {
    2357             :         DCHECK(!is_async_function());
    2358             :         expression_scope()->RecordAsyncArrowParametersError(
    2359             :             next_loc, MessageTemplate::kAwaitBindingIdentifier);
    2360             :       }
    2361             :       ExpressionT lhs =
    2362      195707 :           impl()->ExpressionFromIdentifier(name, next_loc.beg_pos);
    2363      195709 :       if (!IsAssignableIdentifier(lhs)) {
    2364        1140 :         expression_scope()->RecordPatternError(
    2365             :             next_loc, MessageTemplate::kStrictEvalArguments);
    2366             :       }
    2367             : 
    2368             :       ExpressionT value;
    2369      195700 :       if (peek() == Token::ASSIGN) {
    2370             :         Consume(Token::ASSIGN);
    2371             :         {
    2372             :           AcceptINScope scope(this, true);
    2373             :           ExpressionT rhs = ParseAssignmentExpression();
    2374       13135 :           value = factory()->NewAssignment(Token::ASSIGN, lhs, rhs,
    2375             :                                            kNoSourcePosition);
    2376       13135 :           impl()->SetFunctionNameFromIdentifierRef(rhs, lhs);
    2377             :         }
    2378       30935 :         expression_scope()->RecordExpressionError(
    2379             :             Scanner::Location(next_loc.beg_pos, end_position()),
    2380             :             MessageTemplate::kInvalidCoverInitializedName);
    2381             :       } else {
    2382             :         value = lhs;
    2383             :       }
    2384             : 
    2385             :       ObjectLiteralPropertyT result = factory()->NewObjectLiteralProperty(
    2386       71777 :           name_expression, value, ObjectLiteralProperty::COMPUTED, false);
    2387       71776 :       impl()->SetFunctionNameFromPropertyName(result, name);
    2388      195699 :       return result;
    2389             :     }
    2390             : 
    2391             :     case ParsePropertyKind::kMethod: {
    2392             :       // MethodDefinition
    2393             :       //    PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}'
    2394             :       //    '*' PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}'
    2395             : 
    2396      119500 :       expression_scope()->RecordPatternError(
    2397             :           Scanner::Location(next_loc.beg_pos, end_position()),
    2398             :           MessageTemplate::kInvalidDestructuringTarget);
    2399             : 
    2400             :       FunctionKind kind = MethodKindFor(function_flags);
    2401             : 
    2402             :       ExpressionT value = impl()->ParseFunctionLiteral(
    2403             :           name, scanner()->location(), kSkipFunctionNameCheck, kind,
    2404             :           next_loc.beg_pos, FunctionLiteral::kAccessorOrMethod, language_mode(),
    2405      119488 :           nullptr);
    2406             : 
    2407             :       ObjectLiteralPropertyT result = factory()->NewObjectLiteralProperty(
    2408             :           name_expression, value, ObjectLiteralProperty::COMPUTED,
    2409       34217 :           prop_info->is_computed_name);
    2410       34217 :       impl()->SetFunctionNameFromPropertyName(result, name);
    2411       59750 :       return result;
    2412             :     }
    2413             : 
    2414             :     case ParsePropertyKind::kAccessorGetter:
    2415             :     case ParsePropertyKind::kAccessorSetter: {
    2416             :       DCHECK_EQ(function_flags, ParseFunctionFlag::kIsNormal);
    2417       32455 :       bool is_get = kind == ParsePropertyKind::kAccessorGetter;
    2418             : 
    2419       64910 :       expression_scope()->RecordPatternError(
    2420             :           Scanner::Location(next_loc.beg_pos, end_position()),
    2421             :           MessageTemplate::kInvalidDestructuringTarget);
    2422             : 
    2423       19782 :       if (!prop_info->is_computed_name) {
    2424             :         // Make sure the name expression is a string since we need a Name for
    2425             :         // Runtime_DefineAccessorPropertyUnchecked and since we can determine
    2426             :         // this statically we can skip the extra runtime check.
    2427       19211 :         name_expression =
    2428             :             factory()->NewStringLiteral(name, name_expression->position());
    2429             :       }
    2430             : 
    2431             :       FunctionKind kind = is_get ? FunctionKind::kGetterFunction
    2432       32454 :                                  : FunctionKind::kSetterFunction;
    2433             : 
    2434             :       FunctionLiteralT value = impl()->ParseFunctionLiteral(
    2435             :           name, scanner()->location(), kSkipFunctionNameCheck, kind,
    2436             :           next_loc.beg_pos, FunctionLiteral::kAccessorOrMethod, language_mode(),
    2437       64908 :           nullptr);
    2438             : 
    2439             :       ObjectLiteralPropertyT result = factory()->NewObjectLiteralProperty(
    2440             :           name_expression, value,
    2441             :           is_get ? ObjectLiteralProperty::GETTER
    2442             :                  : ObjectLiteralProperty::SETTER,
    2443       19785 :           prop_info->is_computed_name);
    2444             :       const AstRawString* prefix =
    2445       19785 :           is_get ? ast_value_factory()->get_space_string()
    2446       19785 :                  : ast_value_factory()->set_space_string();
    2447       19785 :       impl()->SetFunctionNameFromPropertyName(result, name, prefix);
    2448       32455 :       return result;
    2449             :     }
    2450             : 
    2451             :     case ParsePropertyKind::kClassField:
    2452             :     case ParsePropertyKind::kNotSet:
    2453       77169 :       ReportUnexpectedToken(Next());
    2454       77169 :       return impl()->NullLiteralProperty();
    2455             :   }
    2456           0 :   UNREACHABLE();
    2457             : }
    2458             : 
    2459             : template <typename Impl>
    2460     2687958 : typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseObjectLiteral() {
    2461             :   // ObjectLiteral ::
    2462             :   // '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}'
    2463             : 
    2464             :   int pos = peek_position();
    2465      623975 :   ObjectPropertyListT properties(pointer_buffer());
    2466             :   int number_of_boilerplate_properties = 0;
    2467             : 
    2468             :   bool has_computed_names = false;
    2469             :   bool has_rest_property = false;
    2470     1343905 :   bool has_seen_proto = false;
    2471             : 
    2472             :   Consume(Token::LBRACE);
    2473     1968038 :   AccumulationScope accumulation_scope(expression_scope());
    2474             : 
    2475    10526080 :   while (!Check(Token::RBRACE)) {
    2476     3073194 :     FuncNameInferrerState fni_state(&fni_);
    2477             : 
    2478     1813862 :     ParsePropertyInfo prop_info(this, &accumulation_scope);
    2479     4887064 :     prop_info.position = PropertyPosition::kObjectLiteral;
    2480             :     ObjectLiteralPropertyT property =
    2481     4887064 :         ParseObjectPropertyDefinition(&prop_info, &has_seen_proto);
    2482     4972190 :     if (impl()->IsNull(property)) return impl()->FailureExpression();
    2483             : 
    2484     3036093 :     if (prop_info.is_computed_name) {
    2485             :       has_computed_names = true;
    2486             :     }
    2487             : 
    2488     4801638 :     if (prop_info.is_rest) {
    2489             :       has_rest_property = true;
    2490             :     }
    2491             : 
    2492     3036101 :     if (impl()->IsBoilerplateProperty(property) && !has_computed_names) {
    2493             :       // Count CONSTANT or COMPUTED properties to maintain the enumeration
    2494             :       // order.
    2495     3001518 :       number_of_boilerplate_properties++;
    2496             :     }
    2497             : 
    2498     3036101 :     properties.Add(property);
    2499             : 
    2500     4801692 :     if (peek() != Token::RBRACE) {
    2501     3893499 :       Expect(Token::COMMA);
    2502             :     }
    2503             : 
    2504             :     fni_.Infer();
    2505             :   }
    2506             : 
    2507             :   // In pattern rewriter, we rewrite rest property to call out to a
    2508             :   // runtime function passing all the other properties as arguments to
    2509             :   // this runtime function. Here, we make sure that the number of
    2510             :   // properties is less than number of arguments allowed for a runtime
    2511             :   // call.
    2512     1264923 :   if (has_rest_property && properties.length() > Code::kMaxArguments) {
    2513          20 :     expression_scope()->RecordPatternError(Scanner::Location(pos, position()),
    2514             :                                            MessageTemplate::kTooManyArguments);
    2515             :   }
    2516             : 
    2517             :   return impl()->InitializeObjectLiteral(factory()->NewObjectLiteral(
    2518     1894099 :       properties, number_of_boilerplate_properties, pos, has_rest_property));
    2519             : }
    2520             : 
    2521             : template <typename Impl>
    2522    13735789 : void ParserBase<Impl>::ParseArguments(
    2523    15631840 :     typename ParserBase<Impl>::ExpressionListT* args, bool* has_spread,
    2524    42144806 :     ParsingArrowHeadFlag maybe_arrow) {
    2525             :   // Arguments ::
    2526             :   //   '(' (AssignmentExpression)*[','] ')'
    2527             : 
    2528    13735789 :   *has_spread = false;
    2529             :   Consume(Token::LPAREN);
    2530    13737593 :   AccumulationScope accumulation_scope(expression_scope());
    2531             : 
    2532    37205281 :   while (peek() != Token::RPAREN) {
    2533             :     int start_pos = peek_position();
    2534             :     bool is_spread = Check(Token::ELLIPSIS);
    2535             :     int expr_pos = peek_position();
    2536             : 
    2537             :     AcceptINScope scope(this, true);
    2538    19373797 :     ExpressionT argument = ParseAssignmentExpressionCoverGrammar();
    2539             : 
    2540    19371829 :     if (V8_UNLIKELY(maybe_arrow == kMaybeArrowHead)) {
    2541        9047 :       ClassifyArrowParameter(&accumulation_scope, expr_pos, argument);
    2542        9047 :       if (is_spread) {
    2543             :         expression_scope()->RecordNonSimpleParameter();
    2544         456 :         if (argument->IsAssignment()) {
    2545             :           expression_scope()->RecordAsyncArrowParametersError(
    2546             :               scanner()->location(), MessageTemplate::kRestDefaultInitializer);
    2547             :         }
    2548         456 :         if (peek() == Token::COMMA) {
    2549             :           expression_scope()->RecordAsyncArrowParametersError(
    2550             :               scanner()->peek_location(), MessageTemplate::kParamAfterRest);
    2551             :         }
    2552             :       }
    2553             :     }
    2554    19371829 :     if (is_spread) {
    2555       12296 :       *has_spread = true;
    2556        5190 :       argument = factory()->NewSpread(argument, start_pos, expr_pos);
    2557             :     }
    2558             :     args->Add(argument);
    2559    19375235 :     if (!Check(Token::COMMA)) break;
    2560             :   }
    2561             : 
    2562    13735957 :   if (args->length() > Code::kMaxArguments) {
    2563          29 :     ReportMessage(MessageTemplate::kTooManyArguments);
    2564    13736614 :     return;
    2565             :   }
    2566             : 
    2567    27471856 :   Scanner::Location location = scanner_->location();
    2568    13736431 :   if (!Check(Token::RPAREN)) {
    2569        9892 :     impl()->ReportMessageAt(location, MessageTemplate::kUnterminatedArgList);
    2570    13736431 :   }
    2571             : }
    2572             : 
    2573             : // Precedence = 2
    2574             : template <typename Impl>
    2575             : typename ParserBase<Impl>::ExpressionT
    2576   124097532 : ParserBase<Impl>::ParseAssignmentExpressionCoverGrammar() {
    2577             :   // AssignmentExpression ::
    2578             :   //   ConditionalExpression
    2579             :   //   ArrowFunction
    2580             :   //   YieldExpression
    2581             :   //   LeftHandSideExpression AssignmentOperator AssignmentExpression
    2582             :   int lhs_beg_pos = peek_position();
    2583             : 
    2584    96793124 :   if (peek() == Token::YIELD && is_generator()) {
    2585       43478 :     return ParseYieldExpression();
    2586             :   }
    2587             : 
    2588    50364141 :   FuncNameInferrerState fni_state(&fni_);
    2589             : 
    2590             :   DCHECK_IMPLIES(!has_error(), next_arrow_function_info_.HasInitialState());
    2591             : 
    2592    47935319 :   ExpressionT expression = ParseConditionalExpression();
    2593             : 
    2594             :   Token::Value op = peek();
    2595             : 
    2596    96680204 :   if (!Token::IsArrowOrAssignmentOp(op)) return expression;
    2597             : 
    2598             :   // Arrow functions.
    2599    12440477 :   if (V8_UNLIKELY(op == Token::ARROW)) {
    2600             :     Scanner::Location loc(lhs_beg_pos, end_position());
    2601             : 
    2602     1405676 :     if (!impl()->IsIdentifier(expression) && !expression->is_parenthesized()) {
    2603       19258 :       impl()->ReportMessageAt(
    2604             :           Scanner::Location(expression->position(), position()),
    2605             :           MessageTemplate::kMalformedArrowFunParamList);
    2606       12842 :       return impl()->FailureExpression();
    2607             :     }
    2608             : 
    2609      897300 :     DeclarationScope* scope = next_arrow_function_info_.scope;
    2610             :     scope->set_start_position(lhs_beg_pos);
    2611             : 
    2612             :     FormalParametersT parameters(scope);
    2613      357917 :     parameters.set_strict_parameter_error(
    2614             :         next_arrow_function_info_.strict_parameter_error_location,
    2615             :         next_arrow_function_info_.strict_parameter_error_message);
    2616      897300 :     parameters.is_simple = scope->has_simple_parameters();
    2617             :     next_arrow_function_info_.Reset();
    2618             : 
    2619      357917 :     impl()->DeclareArrowFunctionFormalParameters(&parameters, expression, loc);
    2620             : 
    2621      897304 :     expression = ParseArrowFunctionLiteral(parameters);
    2622             : 
    2623      897289 :     return expression;
    2624             :   }
    2625             : 
    2626    11530340 :   if (V8_LIKELY(impl()->IsAssignableIdentifier(expression))) {
    2627     3235385 :     if (expression->is_parenthesized()) {
    2628        2273 :       expression_scope()->RecordDeclarationError(
    2629             :           Scanner::Location(lhs_beg_pos, end_position()),
    2630             :           MessageTemplate::kInvalidDestructuringTarget);
    2631             :     }
    2632             :     expression_scope()->MarkIdentifierAsAssigned();
    2633     8294614 :   } else if (expression->IsProperty()) {
    2634     8094356 :     expression_scope()->RecordDeclarationError(
    2635             :         Scanner::Location(lhs_beg_pos, end_position()),
    2636             :         MessageTemplate::kInvalidPropertyBindingPattern);
    2637      200258 :   } else if (expression->IsPattern() && op == Token::ASSIGN) {
    2638             :     // Destructuring assignmment.
    2639      189733 :     if (expression->is_parenthesized()) {
    2640        1716 :       expression_scope()->RecordPatternError(
    2641             :           Scanner::Location(lhs_beg_pos, end_position()),
    2642             :           MessageTemplate::kInvalidDestructuringTarget);
    2643             :     }
    2644             :     expression_scope()->ValidateAsPattern(expression, lhs_beg_pos,
    2645             :                                           end_position());
    2646             :   } else {
    2647             :     DCHECK(!IsValidReferenceExpression(expression));
    2648       10525 :     expression = RewriteInvalidReferenceExpression(
    2649             :         expression, lhs_beg_pos, end_position(),
    2650             :         MessageTemplate::kInvalidLhsInAssignment);
    2651             :   }
    2652             : 
    2653             :   Consume(op);
    2654             :   int op_position = position();
    2655             : 
    2656             :   ExpressionT right = ParseAssignmentExpression();
    2657             : 
    2658    11530354 :   if (op == Token::ASSIGN) {
    2659             :     // We try to estimate the set of properties set by constructors. We define a
    2660             :     // new property whenever there is an assignment to a property of 'this'. We
    2661             :     // should probably only add properties if we haven't seen them before.
    2662             :     // Otherwise we'll probably overestimate the number of properties.
    2663    11082047 :     if (impl()->IsThisProperty(expression)) function_state_->AddProperty();
    2664             : 
    2665             :     impl()->CheckAssigningFunctionLiteralToProperty(expression, right);
    2666             : 
    2667             :     // Check if the right hand side is a call to avoid inferring a
    2668             :     // name if we're dealing with "a = function(){...}();"-like
    2669             :     // expression.
    2670     5569265 :     if (right->IsCall() || right->IsCallNew()) {
    2671             :       fni_.RemoveLastFunction();
    2672             :     } else {
    2673             :       fni_.Infer();
    2674             :     }
    2675             : 
    2676     5569235 :     impl()->SetFunctionNameFromIdentifierRef(right, expression);
    2677             :   } else {
    2678      448234 :     expression_scope()->RecordPatternError(
    2679             :         Scanner::Location(lhs_beg_pos, end_position()),
    2680             :         MessageTemplate::kInvalidDestructuringTarget);
    2681             :     fni_.RemoveLastFunction();
    2682             :   }
    2683             : 
    2684     5671886 :   return factory()->NewAssignment(op, expression, right, op_position);
    2685             : }
    2686             : 
    2687             : template <typename Impl>
    2688             : typename ParserBase<Impl>::ExpressionT
    2689      173908 : ParserBase<Impl>::ParseYieldExpression() {
    2690             :   // YieldExpression ::
    2691             :   //   'yield' ([no line terminator] '*'? AssignmentExpression)?
    2692             :   int pos = peek_position();
    2693       86954 :   expression_scope()->RecordParameterInitializerError(
    2694             :       scanner()->peek_location(), MessageTemplate::kYieldInParameter);
    2695             :   Consume(Token::YIELD);
    2696       43477 :   if (V8_UNLIKELY(scanner()->literal_contains_escapes())) {
    2697         240 :     impl()->ReportUnexpectedToken(Token::ESCAPED_KEYWORD);
    2698             :   }
    2699             : 
    2700       43477 :   CheckStackOverflow();
    2701             : 
    2702             :   // The following initialization is necessary.
    2703             :   ExpressionT expression = impl()->NullExpression();
    2704             :   bool delegating = false;  // yield*
    2705       43477 :   if (!scanner()->HasLineTerminatorBeforeNext()) {
    2706       41624 :     if (Check(Token::MUL)) delegating = true;
    2707             :     switch (peek()) {
    2708             :       case Token::EOS:
    2709             :       case Token::SEMICOLON:
    2710             :       case Token::RBRACE:
    2711             :       case Token::RBRACK:
    2712             :       case Token::RPAREN:
    2713             :       case Token::COLON:
    2714             :       case Token::COMMA:
    2715             :       case Token::IN:
    2716             :         // The above set of tokens is the complete set of tokens that can appear
    2717             :         // after an AssignmentExpression, and none of them can start an
    2718             :         // AssignmentExpression.  This allows us to avoid looking for an RHS for
    2719             :         // a regular yield, given only one look-ahead token.
    2720       11869 :         if (!delegating) break;
    2721             :         // Delegating yields require an RHS; fall through.
    2722             :         V8_FALLTHROUGH;
    2723             :       default:
    2724       30156 :         expression = ParseAssignmentExpressionCoverGrammar();
    2725       30156 :         break;
    2726             :     }
    2727             :   }
    2728             : 
    2729       43478 :   if (delegating) {
    2730        2213 :     ExpressionT yieldstar = factory()->NewYieldStar(expression, pos);
    2731        5481 :     impl()->RecordSuspendSourceRange(yieldstar, PositionAfterSemicolon());
    2732        5481 :     function_state_->AddSuspend();
    2733       10962 :     if (IsAsyncGeneratorFunction(function_state_->kind())) {
    2734             :       // iterator_close and delegated_iterator_output suspend ids.
    2735        2781 :       function_state_->AddSuspend();
    2736        2781 :       function_state_->AddSuspend();
    2737             :     }
    2738        5481 :     return yieldstar;
    2739             :   }
    2740             : 
    2741             :   // Hackily disambiguate o from o.next and o [Symbol.iterator]().
    2742             :   // TODO(verwaest): Come up with a better solution.
    2743             :   ExpressionT yield =
    2744       17893 :       factory()->NewYield(expression, pos, Suspend::kOnExceptionThrow);
    2745       37997 :   impl()->RecordSuspendSourceRange(yield, PositionAfterSemicolon());
    2746       37997 :   function_state_->AddSuspend();
    2747       37997 :   return yield;
    2748             : }
    2749             : 
    2750             : // Precedence = 3
    2751             : template <typename Impl>
    2752             : typename ParserBase<Impl>::ExpressionT
    2753    96700569 : ParserBase<Impl>::ParseConditionalExpression() {
    2754             :   // ConditionalExpression ::
    2755             :   //   LogicalOrExpression
    2756             :   //   LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression
    2757             : 
    2758    96700569 :   int pos = peek_position();
    2759             :   // We start using the binary expression parser for prec >= 4 only!
    2760             :   ExpressionT expression = ParseBinaryExpression(4);
    2761             :   return peek() == Token::CONDITIONAL
    2762             :              ? ParseConditionalContinuation(expression, pos)
    2763    96682489 :              : expression;
    2764             : }
    2765             : 
    2766             : template <typename Impl>
    2767             : typename ParserBase<Impl>::ExpressionT
    2768      274549 : ParserBase<Impl>::ParseConditionalContinuation(ExpressionT expression,
    2769       92152 :                                                int pos) {
    2770             :   SourceRange then_range, else_range;
    2771             : 
    2772             :   ExpressionT left;
    2773             :   {
    2774             :     SourceRangeScope range_scope(scanner(), &then_range);
    2775             :     Consume(Token::CONDITIONAL);
    2776             :     // In parsing the first assignment expression in conditional
    2777             :     // expressions we always accept the 'in' keyword; see ECMA-262,
    2778             :     // section 11.12, page 58.
    2779             :     AcceptINScope scope(this, true);
    2780             :     left = ParseAssignmentExpression();
    2781             :   }
    2782             :   ExpressionT right;
    2783             :   {
    2784             :     SourceRangeScope range_scope(scanner(), &else_range);
    2785      274578 :     Expect(Token::COLON);
    2786             :     right = ParseAssignmentExpression();
    2787             :   }
    2788       46079 :   ExpressionT expr = factory()->NewConditional(expression, left, right, pos);
    2789             :   impl()->RecordConditionalSourceRange(expr, then_range, else_range);
    2790      274580 :   return expr;
    2791             : }
    2792             : 
    2793             : // Precedence >= 4
    2794             : template <typename Impl>
    2795             : typename ParserBase<Impl>::ExpressionT
    2796    11585604 : ParserBase<Impl>::ParseBinaryContinuation(ExpressionT x, int prec, int prec1) {
    2797    59865923 :   do {
    2798             :     // prec1 >= 4
    2799   202283073 :     while (Token::Precedence(peek(), accept_IN_) == prec1) {
    2800             :       SourceRange right_range;
    2801             :       int pos = peek_position();
    2802             :       ExpressionT y;
    2803             :       Token::Value op;
    2804             :       {
    2805             :         SourceRangeScope right_range_scope(scanner(), &right_range);
    2806             :         op = Next();
    2807             : 
    2808             :         const bool is_right_associative = op == Token::EXP;
    2809    11348345 :         const int next_prec = is_right_associative ? prec1 : prec1 + 1;
    2810             :         y = ParseBinaryExpression(next_prec);
    2811             :       }
    2812             : 
    2813             :       // For now we distinguish between comparisons and other binary
    2814             :       // operations.  (We could combine the two and get rid of this
    2815             :       // code and AST node eventually.)
    2816    11347115 :       if (Token::IsCompareOp(op)) {
    2817             :         // We have a comparison.
    2818             :         Token::Value cmp = op;
    2819      962851 :         switch (op) {
    2820       26682 :           case Token::NE: cmp = Token::EQ; break;
    2821      189348 :           case Token::NE_STRICT: cmp = Token::EQ_STRICT; break;
    2822             :           default: break;
    2823             :         }
    2824     5399251 :         x = factory()->NewCompareOperation(cmp, x, y, pos);
    2825      962826 :         if (cmp != op) {
    2826             :           // The comparison was negated - add a NOT.
    2827      432060 :           x = factory()->NewUnaryOperation(Token::NOT, x, pos);
    2828             :         }
    2829     2753135 :       } else if (!impl()->ShortcutNumericLiteralBinaryExpression(&x, y, op,
    2830             :                                                                  pos) &&
    2831     1063837 :                  !impl()->CollapseNaryExpression(&x, y, op, pos, right_range)) {
    2832             :         // We have a "normal" binary operation.
    2833     6665109 :         x = factory()->NewBinaryOperation(op, x, y, pos);
    2834      721871 :         if (op == Token::OR || op == Token::AND) {
    2835             :           impl()->RecordBinaryOperationSourceRange(x, right_range);
    2836             :         }
    2837             :       }
    2838             :     }
    2839    59865923 :     --prec1;
    2840             :   } while (prec1 >= prec);
    2841             : 
    2842     8937672 :   return x;
    2843             : }
    2844             : 
    2845             : // Precedence >= 4
    2846             : template <typename Impl>
    2847             : typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseBinaryExpression(
    2848             :     int prec) {
    2849             :   DCHECK_GE(prec, 4);
    2850             :   ExpressionT x = ParseUnaryExpression();
    2851   216062315 :   int prec1 = Token::Precedence(peek(), accept_IN_);
    2852   108029461 :   if (prec1 >= prec) {
    2853     8937879 :     return ParseBinaryContinuation(x, prec, prec1);
    2854             :   }
    2855             :   return x;
    2856             : }
    2857             : 
    2858             : template <typename Impl>
    2859             : typename ParserBase<Impl>::ExpressionT
    2860     6955556 : ParserBase<Impl>::ParseUnaryOrPrefixExpression() {
    2861             :   Token::Value op = Next();
    2862             :   int pos = position();
    2863             : 
    2864             :   // Assume "! function ..." indicates the function is likely to be called.
    2865     2785488 :   if (op == Token::NOT && peek() == Token::FUNCTION) {
    2866         265 :     function_state_->set_next_function_is_likely_called();
    2867             :   }
    2868             : 
    2869     2200379 :   CheckStackOverflow();
    2870             : 
    2871             :   int expression_position = peek_position();
    2872     1413658 :   ExpressionT expression = ParseUnaryExpression();
    2873             : 
    2874     2200250 :   if (Token::IsUnaryOp(op)) {
    2875     1944059 :     if (op == Token::DELETE) {
    2876       26405 :       if (impl()->IsIdentifier(expression) && is_strict(language_mode())) {
    2877             :         // "delete identifier" is a syntax error in strict mode.
    2878        1486 :         ReportMessage(MessageTemplate::kStrictDelete);
    2879        1486 :         return impl()->FailureExpression();
    2880             :       }
    2881             : 
    2882       21792 :       if (impl()->IsPropertyWithPrivateFieldKey(expression)) {
    2883        2400 :         ReportMessage(MessageTemplate::kDeletePrivateField);
    2884        2400 :         return impl()->FailureExpression();
    2885             :       }
    2886             :     }
    2887             : 
    2888     1940147 :     if (peek() == Token::EXP) {
    2889        2886 :       impl()->ReportMessageAt(
    2890             :           Scanner::Location(pos, peek_end_position()),
    2891             :           MessageTemplate::kUnexpectedTokenUnaryExponentiation);
    2892        2886 :       return impl()->FailureExpression();
    2893             :     }
    2894             : 
    2895             :     // Allow the parser's implementation to rewrite the expression.
    2896      683406 :     return impl()->BuildUnaryExpression(expression, op, pos);
    2897             :   }
    2898             : 
    2899             :   DCHECK(Token::IsCountOp(op));
    2900             : 
    2901      256191 :   if (V8_LIKELY(IsValidReferenceExpression(expression))) {
    2902      251169 :     if (impl()->IsIdentifier(expression)) {
    2903             :       expression_scope()->MarkIdentifierAsAssigned();
    2904             :     }
    2905             :   } else {
    2906        5028 :     expression = RewriteInvalidReferenceExpression(
    2907             :         expression, expression_position, end_position(),
    2908             :         MessageTemplate::kInvalidLhsInPrefixOp);
    2909             :   }
    2910             : 
    2911             :   return factory()->NewCountOperation(op, true /* prefix */, expression,
    2912      199885 :                                       position());
    2913             : }
    2914             : 
    2915             : template <typename Impl>
    2916             : typename ParserBase<Impl>::ExpressionT
    2917      186999 : ParserBase<Impl>::ParseAwaitExpression() {
    2918      106656 :   expression_scope()->RecordParameterInitializerError(
    2919             :       scanner()->peek_location(),
    2920             :       MessageTemplate::kAwaitExpressionFormalParameter);
    2921             :   int await_pos = peek_position();
    2922             :   Consume(Token::AWAIT);
    2923       53330 :   if (V8_UNLIKELY(scanner()->literal_contains_escapes())) {
    2924         140 :     impl()->ReportUnexpectedToken(Token::ESCAPED_KEYWORD);
    2925             :   }
    2926             : 
    2927       53328 :   CheckStackOverflow();
    2928             : 
    2929             :   ExpressionT value = ParseUnaryExpression();
    2930             : 
    2931       27015 :   ExpressionT expr = factory()->NewAwait(value, await_pos);
    2932       53331 :   function_state_->AddSuspend();
    2933       53331 :   impl()->RecordSuspendSourceRange(expr, PositionAfterSemicolon());
    2934       53329 :   return expr;
    2935             : }
    2936             : 
    2937             : template <typename Impl>
    2938             : typename ParserBase<Impl>::ExpressionT
    2939   108102325 : ParserBase<Impl>::ParseUnaryExpression() {
    2940             :   // UnaryExpression ::
    2941             :   //   PostfixExpression
    2942             :   //   'delete' UnaryExpression
    2943             :   //   'void' UnaryExpression
    2944             :   //   'typeof' UnaryExpression
    2945             :   //   '++' UnaryExpression
    2946             :   //   '--' UnaryExpression
    2947             :   //   '+' UnaryExpression
    2948             :   //   '-' UnaryExpression
    2949             :   //   '~' UnaryExpression
    2950             :   //   '!' UnaryExpression
    2951             :   //   [+Await] AwaitExpression[?Yield]
    2952             : 
    2953             :   Token::Value op = peek();
    2954   110300850 :   if (Token::IsUnaryOrCountOp(op)) return ParseUnaryOrPrefixExpression();
    2955   108102325 :   if (is_async_function() && op == Token::AWAIT) {
    2956       53330 :     return ParseAwaitExpression();
    2957             :   }
    2958             :   return ParsePostfixExpression();
    2959             : }
    2960             : 
    2961             : template <typename Impl>
    2962             : typename ParserBase<Impl>::ExpressionT
    2963   217069592 : ParserBase<Impl>::ParsePostfixExpression() {
    2964             :   // PostfixExpression ::
    2965             :   //   LeftHandSideExpression ('++' | '--')?
    2966             : 
    2967   108047731 :   int lhs_beg_pos = peek_position();
    2968    55019898 :   ExpressionT expression = ParseLeftHandSideExpression();
    2969   215044050 :   if (!scanner()->HasLineTerminatorBeforeNext() && Token::IsCountOp(peek())) {
    2970      785896 :     if (V8_UNLIKELY(!IsValidReferenceExpression(expression))) {
    2971        2843 :       expression = RewriteInvalidReferenceExpression(
    2972             :           expression, lhs_beg_pos, end_position(),
    2973        2843 :           MessageTemplate::kInvalidLhsInPostfixOp);
    2974             :     }
    2975      785865 :     if (impl()->IsIdentifier(expression)) {
    2976      763557 :       expression_scope()->MarkIdentifierAsAssigned();
    2977             :     }
    2978             : 
    2979             :     Token::Value next = Next();
    2980      785894 :     expression =
    2981             :         factory()->NewCountOperation(next,
    2982             :                                      false /* postfix */,
    2983             :                                      expression,
    2984             :                                      position());
    2985             :   }
    2986    54988613 :   return expression;
    2987             : }
    2988             : 
    2989             : template <typename Impl>
    2990             : typename ParserBase<Impl>::ExpressionT
    2991             : ParserBase<Impl>::ParseLeftHandSideExpression() {
    2992             :   // LeftHandSideExpression ::
    2993             :   //   (NewExpression | MemberExpression) ...
    2994             : 
    2995             :   ExpressionT result = ParseMemberWithNewPrefixesExpression();
    2996   108190475 :   if (!Token::IsPropertyOrCall(peek())) return result;
    2997    12879069 :   return ParseLeftHandSideContinuation(result);
    2998             : }
    2999             : 
    3000             : template <typename Impl>
    3001             : typename ParserBase<Impl>::ExpressionT
    3002    41762293 : ParserBase<Impl>::ParseLeftHandSideContinuation(ExpressionT result) {
    3003             :   DCHECK(Token::IsPropertyOrCall(peek()));
    3004             : 
    3005    34711083 :   if (V8_UNLIKELY(peek() == Token::LPAREN && impl()->IsIdentifier(result) &&
    3006             :                   scanner()->current_token() == Token::ASYNC &&
    3007             :                   !scanner()->HasLineTerminatorBeforeNext() &&
    3008             :                   !scanner()->literal_contains_escapes())) {
    3009             :     DCHECK(impl()->IsAsync(impl()->AsIdentifier(result)));
    3010             :     int pos = position();
    3011             : 
    3012             :     ArrowHeadParsingScope maybe_arrow(impl(),
    3013             :                                       FunctionKind::kAsyncArrowFunction);
    3014       15899 :     Scope::Snapshot scope_snapshot(scope());
    3015             : 
    3016        8128 :     ExpressionListT args(pointer_buffer());
    3017             :     bool has_spread;
    3018       15898 :     ParseArguments(&args, &has_spread, kMaybeArrowHead);
    3019       15900 :     if (V8_LIKELY(peek() == Token::ARROW)) {
    3020        6539 :       fni_.RemoveAsyncKeywordFromEnd();
    3021       11619 :       next_arrow_function_info_.scope = maybe_arrow.ValidateAndCreateScope();
    3022       11621 :       scope_snapshot.Reparent(next_arrow_function_info_.scope);
    3023             :       // async () => ...
    3024       21685 :       if (!args.length()) return factory()->NewEmptyParentheses(pos);
    3025             :       // async ( Arguments ) => ...
    3026        3011 :       ExpressionT result = impl()->ExpressionListToExpression(args);
    3027             :       result->mark_parenthesized();
    3028        5710 :       return result;
    3029             :     }
    3030             : 
    3031        4279 :     if (has_spread) {
    3032           9 :       result = impl()->SpreadCall(result, args, pos, Call::NOT_EVAL);
    3033             :     } else {
    3034        4270 :       result = factory()->NewCall(result, args, pos, Call::NOT_EVAL);
    3035             :     }
    3036             : 
    3037        4279 :     maybe_arrow.ValidateExpression();
    3038             : 
    3039             :     fni_.RemoveLastFunction();
    3040        4279 :     if (!Token::IsPropertyOrCall(peek())) return result;
    3041             :   }
    3042             : 
    3043    13416519 :   do {
    3044    13415831 :     switch (peek()) {
    3045             :       /* Property */
    3046             :       case Token::LBRACK: {
    3047             :         Consume(Token::LBRACK);
    3048             :         int pos = position();
    3049             :         AcceptINScope scope(this, true);
    3050       20428 :         ExpressionT index = ParseExpressionCoverGrammar();
    3051       20428 :         result = factory()->NewProperty(result, index, pos);
    3052       20428 :         Expect(Token::RBRACK);
    3053             :         break;
    3054             :       }
    3055             : 
    3056             :       /* Property */
    3057             :       case Token::PERIOD: {
    3058             :         Consume(Token::PERIOD);
    3059             :         int pos = position();
    3060      284123 :         ExpressionT key = ParsePropertyOrPrivatePropertyName();
    3061      284126 :         result = factory()->NewProperty(result, key, pos);
    3062       81431 :         break;
    3063             :       }
    3064             : 
    3065             :       /* Call */
    3066             :       case Token::LPAREN: {
    3067             :         int pos;
    3068     6396359 :         if (Token::IsCallable(scanner()->current_token())) {
    3069             :           // For call of an identifier we want to report position of
    3070             :           // the identifier as position of the call in the stack trace.
    3071             :           pos = position();
    3072             :         } else {
    3073             :           // For other kinds of calls we record position of the parenthesis as
    3074             :           // position of the call. Note that this is extremely important for
    3075             :           // expressions of the form function(){...}() for which call position
    3076             :           // should not point to the closing brace otherwise it will intersect
    3077             :           // with positions recorded for function literal and confuse debugger.
    3078             :           pos = peek_position();
    3079             :           // Also the trailing parenthesis are a hint that the function will
    3080             :           // be called immediately. If we happen to have parsed a preceding
    3081             :           // function literal eagerly, we can also compile it eagerly.
    3082      161507 :           if (result->IsFunctionLiteral()) {
    3083      213182 :             result->AsFunctionLiteral()->SetShouldEagerCompile();
    3084      106601 :             if (scope()->is_script_scope()) {
    3085             :               // A non-top-level iife is likely to be executed multiple times
    3086             :               // and so shouldn`t be optimized as one-shot.
    3087             :               result->AsFunctionLiteral()->mark_as_oneshot_iife();
    3088             :             }
    3089             :           }
    3090             :         }
    3091             :         bool has_spread;
    3092     6396369 :         ExpressionListT args(pointer_buffer());
    3093    13109828 :         ParseArguments(&args, &has_spread);
    3094             : 
    3095             :         // Keep track of eval() calls since they disable all local variable
    3096             :         // optimizations.
    3097             :         // The calls that need special treatment are the
    3098             :         // direct eval calls. These calls are all of the form eval(...), with
    3099             :         // no explicit receiver.
    3100             :         // These calls are marked as potentially direct eval calls. Whether
    3101             :         // they are actually direct calls to eval is determined at run time.
    3102             :         Call::PossiblyEval is_possibly_eval =
    3103    13110481 :             CheckPossibleEvalCall(result, scope());
    3104             : 
    3105    13110715 :         if (has_spread) {
    3106        9106 :           result = impl()->SpreadCall(result, args, pos, is_possibly_eval);
    3107             :         } else {
    3108    13101635 :           result = factory()->NewCall(result, args, pos, is_possibly_eval);
    3109             :         }
    3110             : 
    3111             :         fni_.RemoveLastFunction();
    3112             :         break;
    3113             :       }
    3114             : 
    3115             :       /* Call */
    3116             :       default:
    3117             :         DCHECK(Token::IsTemplate(peek()));
    3118        1487 :         result = ParseTemplateLiteral(result, position(), true);
    3119        1487 :         break;
    3120             :     }
    3121             :   } while (Token::IsPropertyOrCall(peek()));
    3122     6556281 :   return result;
    3123             : }
    3124             : 
    3125             : template <typename Impl>
    3126             : typename ParserBase<Impl>::ExpressionT
    3127     1245094 : ParserBase<Impl>::ParseMemberWithPresentNewPrefixesExpression() {
    3128             :   // NewExpression ::
    3129             :   //   ('new')+ MemberExpression
    3130             :   //
    3131             :   // NewTarget ::
    3132             :   //   'new' '.' 'target'
    3133             : 
    3134             :   // The grammar for new expressions is pretty warped. We can have several 'new'
    3135             :   // keywords following each other, and then a MemberExpression. When we see '('
    3136             :   // after the MemberExpression, it's associated with the rightmost unassociated
    3137             :   // 'new' to create a NewExpression with arguments. However, a NewExpression
    3138             :   // can also occur without arguments.
    3139             : 
    3140             :   // Examples of new expression:
    3141             :   // new foo.bar().baz means (new (foo.bar)()).baz
    3142             :   // new foo()() means (new foo())()
    3143             :   // new new foo()() means (new (new foo())())
    3144             :   // new new foo means new (new foo)
    3145             :   // new new foo() means new (new foo())
    3146             :   // new new foo().bar().baz means (new (new foo()).bar()).baz
    3147             :   Consume(Token::NEW);
    3148             :   int new_pos = position();
    3149             :   ExpressionT result;
    3150             : 
    3151      537065 :   CheckStackOverflow();
    3152             : 
    3153      536926 :   if (peek() == Token::SUPER) {
    3154             :     const bool is_new = true;
    3155        7738 :     result = ParseSuperExpression(is_new);
    3156     1048277 :   } else if (allow_harmony_dynamic_import() && peek() == Token::IMPORT &&
    3157             :              (!allow_harmony_import_meta() || PeekAhead() == Token::LPAREN)) {
    3158        2000 :     impl()->ReportMessageAt(scanner()->peek_location(),
    3159             :                             MessageTemplate::kImportCallNotNewExpression);
    3160        2000 :     return impl()->FailureExpression();
    3161      527239 :   } else if (peek() == Token::PERIOD) {
    3162        8112 :     result = ParseNewTargetExpression();
    3163        3012 :     return ParseMemberExpressionContinuation(result);
    3164             :   } else {
    3165             :     result = ParseMemberWithNewPrefixesExpression();
    3166             :   }
    3167      526920 :   if (peek() == Token::LPAREN) {
    3168             :     // NewExpression with arguments.
    3169             :     {
    3170      141782 :       ExpressionListT args(pointer_buffer());
    3171             :       bool has_spread;
    3172      483378 :       ParseArguments(&args, &has_spread);
    3173             : 
    3174      483328 :       if (has_spread) {
    3175         225 :         result = impl()->SpreadCallNew(result, args, new_pos);
    3176             :       } else {
    3177      141560 :         result = factory()->NewCallNew(result, args, new_pos);
    3178             :       }
    3179             :     }
    3180             :     // The expression can still continue with . or [ after the arguments.
    3181      141789 :     return ParseMemberExpressionContinuation(result);
    3182             :   }
    3183             :   // NewExpression without arguments.
    3184       26115 :   ExpressionListT args(pointer_buffer());
    3185       26115 :   return factory()->NewCallNew(result, args, new_pos);
    3186             : }
    3187             : 
    3188             : template <typename Impl>
    3189             : typename ParserBase<Impl>::ExpressionT
    3190             : ParserBase<Impl>::ParseMemberWithNewPrefixesExpression() {
    3191             :   return peek() == Token::NEW ? ParseMemberWithPresentNewPrefixesExpression()
    3192   108709974 :                               : ParseMemberExpression();
    3193             : }
    3194             : 
    3195             : template <typename Impl>
    3196             : typename ParserBase<Impl>::ExpressionT
    3197     4782323 : ParserBase<Impl>::ParseFunctionExpression() {
    3198             :   Consume(Token::FUNCTION);
    3199             :   int function_token_position = position();
    3200             : 
    3201             :   FunctionKind function_kind = Check(Token::MUL)
    3202             :                                    ? FunctionKind::kGeneratorFunction
    3203     1928656 :                                    : FunctionKind::kNormalFunction;
    3204       79667 :   IdentifierT name = impl()->NullIdentifier();
    3205             :   bool is_strict_reserved_name = Token::IsStrictReservedWord(peek());
    3206     1928640 :   Scanner::Location function_name_location = Scanner::Location::invalid();
    3207             :   FunctionLiteral::FunctionType function_type =
    3208             :       FunctionLiteral::kAnonymousExpression;
    3209     1848970 :   if (impl()->ParsingDynamicFunctionDeclaration()) {
    3210             :     // We don't want dynamic functions to actually declare their name
    3211             :     // "anonymous". We just want that name in the toString().
    3212             :     Consume(Token::IDENTIFIER);
    3213             :     DCHECK_IMPLIES(!has_error(),
    3214             :                    scanner()->CurrentSymbol(ast_value_factory()) ==
    3215             :                        ast_value_factory()->anonymous_string());
    3216     1591259 :   } else if (peek_any_identifier()) {
    3217       22733 :     name = ParseIdentifier(function_kind);
    3218      925297 :     function_name_location = scanner()->location();
    3219             :     function_type = FunctionLiteral::kNamedExpression;
    3220             :   }
    3221             :   FunctionLiteralT result = impl()->ParseFunctionLiteral(
    3222             :       name, function_name_location,
    3223             :       is_strict_reserved_name ? kFunctionNameIsStrictReserved
    3224             :                               : kFunctionNameValidityUnknown,
    3225             :       function_kind, function_token_position, function_type, language_mode(),
    3226     1928451 :       nullptr);
    3227             :   // TODO(verwaest): FailureFunctionLiteral?
    3228     1929351 :   if (impl()->IsNull(result)) return impl()->FailureExpression();
    3229       79660 :   return result;
    3230             : }
    3231             : 
    3232             : template <typename Impl>
    3233             : typename ParserBase<Impl>::ExpressionT
    3234   106213574 : ParserBase<Impl>::ParseMemberExpression() {
    3235             :   // MemberExpression ::
    3236             :   //   (PrimaryExpression | FunctionLiteral | ClassLiteral)
    3237             :   //     ('[' Expression ']' | '.' Identifier | Arguments | TemplateLiteral)*
    3238             :   //
    3239             :   // CallExpression ::
    3240             :   //   (SuperCall | ImportCall)
    3241             :   //     ('[' Expression ']' | '.' Identifier | Arguments | TemplateLiteral)*
    3242             :   //
    3243             :   // The '[' Expression ']' and '.' Identifier parts are parsed by
    3244             :   // ParseMemberExpressionContinuation, and the Arguments part is parsed by the
    3245             :   // caller.
    3246             : 
    3247             :   // Parse the initial primary or function expression.
    3248    55089244 :   ExpressionT result;
    3249   108166382 :   if (peek() == Token::FUNCTION) {
    3250     1928646 :     result = ParseFunctionExpression();
    3251   106234206 :   } else if (peek() == Token::SUPER) {
    3252             :     const bool is_new = false;
    3253       20632 :     result = ParseSuperExpression(is_new);
    3254   206126401 :   } else if (allow_harmony_dynamic_import() && peek() == Token::IMPORT) {
    3255       31721 :     result = ParseImportExpressions();
    3256             :   } else {
    3257   106177415 :     result = ParsePrimaryExpression();
    3258             :   }
    3259             : 
    3260             :   return ParseMemberExpressionContinuation(result);
    3261             : }
    3262             : 
    3263             : template <typename Impl>
    3264             : typename ParserBase<Impl>::ExpressionT
    3265      133339 : ParserBase<Impl>::ParseImportExpressions() {
    3266             :   DCHECK(allow_harmony_dynamic_import());
    3267             : 
    3268             :   Consume(Token::IMPORT);
    3269             :   int pos = position();
    3270       57222 :   if (allow_harmony_import_meta() && Check(Token::PERIOD)) {
    3271       24613 :     ExpectContextualKeyword(ast_value_factory()->meta_string(), "import.meta",
    3272       24613 :                             pos);
    3273       24613 :     if (!parsing_module_) {
    3274       13478 :       impl()->ReportMessageAt(scanner()->location(),
    3275             :                               MessageTemplate::kImportMetaOutsideModule);
    3276       13478 :       return impl()->FailureExpression();
    3277             :     }
    3278             : 
    3279        3210 :     return impl()->ImportMetaExpression(pos);
    3280             :   }
    3281        7108 :   Expect(Token::LPAREN);
    3282        7108 :   if (peek() == Token::RPAREN) {
    3283          85 :     impl()->ReportMessageAt(scanner()->location(),
    3284             :                             MessageTemplate::kImportMissingSpecifier);
    3285          85 :     return impl()->FailureExpression();
    3286             :   }
    3287             :   AcceptINScope scope(this, true);
    3288        7023 :   ExpressionT arg = ParseAssignmentExpressionCoverGrammar();
    3289        7025 :   Expect(Token::RPAREN);
    3290             : 
    3291        3598 :   return factory()->NewImportCallExpression(arg, pos);
    3292             : }
    3293             : 
    3294             : template <typename Impl>
    3295       28369 : typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseSuperExpression(
    3296       49744 :     bool is_new) {
    3297             :   Consume(Token::SUPER);
    3298             :   int pos = position();
    3299             : 
    3300       28369 :   DeclarationScope* scope = GetReceiverScope();
    3301             :   FunctionKind kind = scope->function_kind();
    3302       65772 :   if (IsConciseMethod(kind) || IsAccessorFunction(kind) ||
    3303             :       IsClassConstructor(kind)) {
    3304       17004 :     if (Token::IsProperty(peek())) {
    3305             :       scope->RecordSuperPropertyUsage();
    3306             :       UseThis();
    3307        2758 :       return impl()->NewSuperPropertyReference(pos);
    3308             :     }
    3309             :     // new super() is never allowed.
    3310             :     // super() is only allowed in derived constructor
    3311       23576 :     if (!is_new && peek() == Token::LPAREN && IsDerivedConstructor(kind)) {
    3312             :       // TODO(rossberg): This might not be the correct FunctionState for the
    3313             :       // method here.
    3314             :       expression_scope()->RecordThisUse();
    3315             :       UseThis()->set_maybe_assigned();
    3316        2742 :       return impl()->NewSuperCallReference(pos);
    3317             :     }
    3318             :   }
    3319             : 
    3320       15561 :   impl()->ReportMessageAt(scanner()->location(),
    3321             :                           MessageTemplate::kUnexpectedSuper);
    3322       15561 :   return impl()->FailureExpression();
    3323             : }
    3324             : 
    3325             : template <typename Impl>
    3326             : typename ParserBase<Impl>::ExpressionT
    3327       18206 : ParserBase<Impl>::ParseNewTargetExpression() {
    3328             :   int pos = position();
    3329             :   Consume(Token::PERIOD);
    3330        8114 :   ExpectContextualKeyword(ast_value_factory()->target_string(), "new.target",
    3331        8114 :                           pos);
    3332             : 
    3333        8114 :   if (!GetReceiverScope()->is_function_scope()) {
    3334        1980 :     impl()->ReportMessageAt(scanner()->location(),
    3335             :                             MessageTemplate::kUnexpectedNewTarget);
    3336        1980 :     return impl()->FailureExpression();
    3337             :   }
    3338             : 
    3339        2033 :   return impl()->NewTargetExpression(pos);
    3340             : }
    3341             : 
    3342             : template <typename Impl>
    3343             : typename ParserBase<Impl>::ExpressionT
    3344    35068426 : ParserBase<Impl>::DoParseMemberExpressionContinuation(ExpressionT expression) {
    3345             :   DCHECK(Token::IsMember(peek()));
    3346             :   // Parses this part of MemberExpression:
    3347             :   // ('[' Expression ']' | '.' Identifier | TemplateLiteral)*
    3348    18260800 :   do {
    3349    18259758 :     switch (peek()) {
    3350             :       case Token::LBRACK: {
    3351             :         Consume(Token::LBRACK);
    3352             :         int pos = position();
    3353             :         AcceptINScope scope(this, true);
    3354     4104263 :         ExpressionT index = ParseExpressionCoverGrammar();
    3355     4104255 :         expression = factory()->NewProperty(expression, index, pos);
    3356             :         impl()->PushPropertyName(index);
    3357     4104240 :         Expect(Token::RBRACK);
    3358             :         break;
    3359             :       }
    3360             :       case Token::PERIOD: {
    3361             :         Consume(Token::PERIOD);
    3362             :         int pos = peek_position();
    3363    14143846 :         ExpressionT key = ParsePropertyOrPrivatePropertyName();
    3364    14144542 :         expression = factory()->NewProperty(expression, key, pos);
    3365     5430412 :         break;
    3366             :       }
    3367             :       default: {
    3368             :         DCHECK(Token::IsTemplate(peek()));
    3369             :         int pos;
    3370       12587 :         if (scanner()->current_token() == Token::IDENTIFIER) {
    3371             :           pos = position();
    3372             :         } else {
    3373             :           pos = peek_position();
    3374        1725 :           if (expression->IsFunctionLiteral()) {
    3375             :             // If the tag function looks like an IIFE, set_parenthesized() to
    3376             :             // force eager compilation.
    3377         642 :             expression->AsFunctionLiteral()->SetShouldEagerCompile();
    3378             :           }
    3379             :         }
    3380       12587 :         expression = ParseTemplateLiteral(expression, pos, true);
    3381       12586 :         break;
    3382             :       }
    3383             :     }
    3384             :   } while (Token::IsMember(peek()));
    3385    16808754 :   return expression;
    3386             : }
    3387             : 
    3388             : template <typename Impl>
    3389    42951436 : void ParserBase<Impl>::ParseFormalParameter(FormalParametersT* parameters) {
    3390             :   // FormalParameter[Yield,GeneratorParameter] :
    3391             :   //   BindingElement[?Yield, ?GeneratorParameter]
    3392     3904932 :   FuncNameInferrerState fni_state(&fni_);
    3393     7823333 :   int pos = peek_position();
    3394     7823354 :   auto declaration_it = scope()->declarations()->end();
    3395     7823300 :   ExpressionT pattern = ParseBindingPattern();
    3396     7823583 :   if (impl()->IsIdentifier(pattern)) {
    3397    15505494 :     ClassifyParameter(impl()->AsIdentifier(pattern), pos, end_position());
    3398             :   } else {
    3399       70849 :     parameters->is_simple = false;
    3400             :   }
    3401             : 
    3402     3918634 :   ExpressionT initializer = impl()->NullExpression();
    3403     7823556 :   if (Check(Token::ASSIGN)) {
    3404      117347 :     parameters->is_simple = false;
    3405             : 
    3406      117347 :     if (parameters->has_rest) {
    3407           0 :       ReportMessage(MessageTemplate::kRestDefaultInitializer);
    3408           6 :       return;
    3409             :     }
    3410             : 
    3411      117347 :     AcceptINScope accept_in_scope(this, true);
    3412       98681 :     initializer = ParseAssignmentExpression();
    3413      117347 :     impl()->SetFunctionNameFromIdentifierRef(initializer, pattern);
    3414             :   }
    3415             : 
    3416     7823556 :   auto declaration_end = scope()->declarations()->end();
    3417     7823530 :   int initializer_end = end_position();
    3418     3900530 :   for (; declaration_it != declaration_end; ++declaration_it) {
    3419     3900532 :     declaration_it->var()->set_initializer_position(initializer_end);
    3420             :   }
    3421             : 
    3422    11728413 :   impl()->AddFormalParameter(parameters, pattern, initializer, end_position(),
    3423     3904923 :                              parameters->has_rest);
    3424             : }
    3425             : 
    3426             : template <typename Impl>
    3427     7246516 : void ParserBase<Impl>::ParseFormalParameterList(FormalParametersT* parameters) {
    3428             :   // FormalParameters[Yield] :
    3429             :   //   [empty]
    3430             :   //   FunctionRestParameter[?Yield]
    3431             :   //   FormalParameterList[?Yield]
    3432             :   //   FormalParameterList[?Yield] ,
    3433             :   //   FormalParameterList[?Yield] , FunctionRestParameter[?Yield]
    3434             :   //
    3435             :   // FormalParameterList[Yield] :
    3436             :   //   FormalParameter[?Yield]
    3437             :   //   FormalParameterList[?Yield] , FormalParameter[?Yield]
    3438             :   ParameterParsingScope scope(impl(), parameters);
    3439             : 
    3440             :   DCHECK_EQ(0, parameters->arity);
    3441             : 
    3442     4343702 :   if (peek() != Token::RPAREN) {
    3443             :     while (true) {
    3444             :       // Add one since we're going to be adding a parameter.
    3445     7805357 :       if (parameters->arity + 1 > Code::kMaxArguments) {
    3446          18 :         ReportMessage(MessageTemplate::kTooManyParameters);
    3447          18 :         return;
    3448             :       }
    3449     7805250 :       parameters->has_rest = Check(Token::ELLIPSIS);
    3450             :       ParseFormalParameter(parameters);
    3451             : 
    3452     7805365 :       if (parameters->has_rest) {
    3453       17787 :         parameters->is_simple = false;
    3454       17787 :         if (peek() == Token::COMMA) {
    3455        3223 :           impl()->ReportMessageAt(scanner()->peek_location(),
    3456             :                                   MessageTemplate::kParamAfterRest);
    3457        3223 :           return;
    3458             :         }
    3459             :         break;
    3460             :       }
    3461     7787395 :       if (!Check(Token::COMMA)) break;
    3462     5299140 :       if (peek() == Token::RPAREN) {
    3463             :         // allow the trailing comma
    3464             :         break;
    3465             :       }
    3466             :     }
    3467             :   }
    3468             : 
    3469             :   impl()->DeclareFormalParameters(parameters);
    3470             : }
    3471             : 
    3472             : template <typename Impl>
    3473    13608554 : void ParserBase<Impl>::ParseVariableDeclarations(
    3474             :     VariableDeclarationContext var_context,
    3475             :     DeclarationParsingResult* parsing_result,
    3476   121554942 :     ZonePtrList<const AstRawString>* names) {
    3477             :   // VariableDeclarations ::
    3478             :   //   ('var' | 'const' | 'let') (Identifier ('=' AssignmentExpression)?)+[',']
    3479             :   //
    3480             :   // ES6:
    3481             :   // FIXME(marja, nikolaos): Add an up-to-date comment about ES6 variable
    3482             :   // declaration syntax.
    3483             : 
    3484             :   DCHECK_NOT_NULL(parsing_result);
    3485    13608554 :   parsing_result->descriptor.kind = NORMAL_VARIABLE;
    3486    13608554 :   parsing_result->descriptor.declaration_pos = peek_position();
    3487    13608554 :   parsing_result->descriptor.initialization_pos = peek_position();
    3488             : 
    3489    13608667 :   switch (peek()) {
    3490             :     case Token::VAR:
    3491    11470379 :       parsing_result->descriptor.mode = VariableMode::kVar;
    3492             :       Consume(Token::VAR);
    3493             :       break;
    3494             :     case Token::CONST:
    3495             :       Consume(Token::CONST);
    3496             :       DCHECK_NE(var_context, kStatement);
    3497      539576 :       parsing_result->descriptor.mode = VariableMode::kConst;
    3498      539576 :       break;
    3499             :     case Token::LET:
    3500             :       Consume(Token::LET);
    3501             :       DCHECK_NE(var_context, kStatement);
    3502     1598726 :       parsing_result->descriptor.mode = VariableMode::kLet;
    3503     1598726 :       break;
    3504             :     default:
    3505           0 :       UNREACHABLE();  // by current callers
    3506             :       break;
    3507             :   }
    3508             : 
    3509             :   VariableDeclarationParsingScope declaration(
    3510    13608981 :       impl(), parsing_result->descriptor.mode, names);
    3511    13608981 :   Scope* target_scope = IsLexicalVariableMode(parsing_result->descriptor.mode)
    3512             :                             ? scope()
    3513    25079649 :                             : scope()->GetDeclarationScope();
    3514             : 
    3515    13608919 :   auto declaration_it = target_scope->declarations()->end();
    3516             : 
    3517             :   int bindings_start = peek_position();
    3518    14030328 :   do {
    3519             :     // Parse binding pattern.
    3520     9205468 :     FuncNameInferrerState fni_state(&fni_);
    3521             : 
    3522             :     int decl_pos = peek_position();
    3523             : 
    3524      424763 :     IdentifierT name;
    3525             :     ExpressionT pattern;
    3526             :     // Check for an identifier first, so that we can elide the pattern in cases
    3527             :     // where there is no initializer (and so no proxy needs to be created).
    3528    14111619 :     if (V8_LIKELY(Token::IsAnyIdentifier(peek()))) {
    3529     4779978 :       name = ParseAndClassifyIdentifier(Next());
    3530    15538831 :       if (V8_UNLIKELY(is_strict(language_mode()) &&
    3531             :                       impl()->IsEvalOrArguments(name))) {
    3532         478 :         impl()->ReportMessageAt(scanner()->location(),
    3533             :                                 MessageTemplate::kStrictEvalArguments);
    3534         478 :         return;
    3535             :       }
    3536    14088220 :       if (peek() == Token::ASSIGN ||
    3537      176690 :           (var_context == kForStatement && PeekInOrOf()) ||
    3538             :           parsing_result->descriptor.mode == VariableMode::kLet) {
    3539             :         // Assignments need the variable expression for the assignment LHS, and
    3540             :         // for of/in will need it later, so create the expression now.
    3541     4541083 :         pattern = impl()->ExpressionFromIdentifier(name, decl_pos);
    3542             :       } else {
    3543             :         // Otherwise, elide the variable expression and just declare it.
    3544             :         impl()->DeclareIdentifier(name, decl_pos);
    3545      238685 :         pattern = impl()->NullExpression();
    3546             :       }
    3547             :     } else {
    3548      126138 :       name = impl()->NullIdentifier();
    3549      199741 :       pattern = ParseBindingPattern();
    3550             :       DCHECK(!impl()->IsIdentifier(pattern));
    3551             :     }
    3552             : 
    3553    14111453 :     Scanner::Location variable_loc = scanner()->location();
    3554             : 
    3555             :     ExpressionT value = impl()->NullExpression();
    3556             :     int value_beg_pos = kNoSourcePosition;
    3557    14111080 :     if (Check(Token::ASSIGN)) {
    3558             :       DCHECK(!impl()->IsNull(pattern));
    3559             :       {
    3560             :         value_beg_pos = peek_position();
    3561    11263756 :         AcceptINScope scope(this, var_context != kForStatement);
    3562             :         value = ParseAssignmentExpression();
    3563             :       }
    3564             :       variable_loc.end_pos = end_position();
    3565             : 
    3566    11263447 :       if (!parsing_result->first_initializer_loc.IsValid()) {
    3567    11155210 :         parsing_result->first_initializer_loc = variable_loc;
    3568             :       }
    3569             : 
    3570             :       // Don't infer if it is "a = function(){...}();"-like expression.
    3571    11263508 :       if (impl()->IsIdentifier(pattern)) {
    3572     6844642 :         if (!value->IsCall() && !value->IsCallNew()) {
    3573             :           fni_.Infer();
    3574             :         } else {
    3575             :           fni_.RemoveLastFunction();
    3576             :         }
    3577             :       }
    3578             : 
    3579     6871337 :       impl()->SetFunctionNameFromIdentifierRef(value, pattern);
    3580             :     } else {
    3581             : #ifdef DEBUG
    3582             :       // We can fall through into here on error paths, so don't DCHECK those.
    3583             :       if (!has_error()) {
    3584             :         // We should never get identifier patterns for the non-initializer path,
    3585             :         // as those expressions should be elided.
    3586             :         DCHECK_EQ(!impl()->IsNull(name),
    3587             :                   Token::IsAnyIdentifier(scanner()->current_token()));
    3588             :         DCHECK_IMPLIES(impl()->IsNull(pattern), !impl()->IsNull(name));
    3589             :         // The only times we have a non-null pattern are:
    3590             :         //   1. This is a destructuring declaration (with no initializer, which
    3591             :         //      is immediately an error),
    3592             :         //   2. This is a declaration in a for in/of loop, or
    3593             :         //   3. This is a let (which has an implicit undefined initializer)
    3594             :         DCHECK_IMPLIES(
    3595             :             !impl()->IsNull(pattern),
    3596             :             !impl()->IsIdentifier(pattern) ||
    3597             :                 (var_context == kForStatement && PeekInOrOf()) ||
    3598             :                 parsing_result->descriptor.mode == VariableMode::kLet);
    3599             :       }
    3600             : #endif
    3601             : 
    3602     2847324 :       if (var_context != kForStatement || !PeekInOrOf()) {
    3603             :         // ES6 'const' and binding patterns require initializers.
    3604     3022705 :         if (parsing_result->descriptor.mode == VariableMode::kConst ||
    3605             :             impl()->IsNull(name)) {
    3606      162958 :           impl()->ReportMessageAt(
    3607             :               Scanner::Location(decl_pos, end_position()),
    3608             :               MessageTemplate::kDeclarationMissingInitializer,
    3609             :               impl()->IsNull(name) ? "destructuring" : "const");
    3610       81479 :           return;
    3611             :         }
    3612             :         // 'let x' initializes 'x' to undefined.
    3613     2550709 :         if (parsing_result->descriptor.mode == VariableMode::kLet) {
    3614      201491 :           value = factory()->NewUndefinedLiteral(position());
    3615             :         }
    3616             :       }
    3617             :     }
    3618             : 
    3619             :     int initializer_position = end_position();
    3620    14029251 :     auto declaration_end = target_scope->declarations()->end();
    3621    37796142 :     for (; declaration_it != declaration_end; ++declaration_it) {
    3622     9737640 :       declaration_it->var()->set_initializer_position(initializer_position);
    3623             :     }
    3624             : 
    3625             :     // Patterns should be elided iff. they don't have an initializer.
    3626             :     DCHECK_IMPLIES(impl()->IsNull(pattern),
    3627             :                    impl()->IsNull(value) ||
    3628             :                        (var_context == kForStatement && PeekInOrOf()));
    3629             : 
    3630             :     typename DeclarationParsingResult::Declaration decl(pattern, value);
    3631    14029251 :     decl.value_beg_pos = value_beg_pos;
    3632             : 
    3633    14029251 :     parsing_result->declarations.push_back(decl);
    3634             :   } while (Check(Token::COMMA));
    3635             : 
    3636    13527642 :   parsing_result->bindings_loc =
    3637             :       Scanner::Location(bindings_start, end_position());
    3638             : }
    3639             : 
    3640             : template <typename Impl>
    3641             : typename ParserBase<Impl>::StatementT
    3642        3192 : ParserBase<Impl>::ParseFunctionDeclaration() {
    3643             :   Consume(Token::FUNCTION);
    3644             : 
    3645             :   int pos = position();
    3646             :   ParseFunctionFlags flags = ParseFunctionFlag::kIsNormal;
    3647        1436 :   if (Check(Token::MUL)) {
    3648         320 :     impl()->ReportMessageAt(
    3649             :         scanner()->location(),
    3650             :         MessageTemplate::kGeneratorInSingleStatementContext);
    3651         320 :     return impl()->NullStatement();
    3652             :   }
    3653        1116 :   return ParseHoistableDeclaration(pos, flags, nullptr, false);
    3654             : }
    3655             : 
    3656             : template <typename Impl>
    3657             : typename ParserBase<Impl>::StatementT
    3658     1054382 : ParserBase<Impl>::ParseHoistableDeclaration(
    3659     1054503 :     ZonePtrList<const AstRawString>* names, bool default_export) {
    3660             :   Consume(Token::FUNCTION);
    3661             : 
    3662             :   int pos = position();
    3663             :   ParseFunctionFlags flags = ParseFunctionFlag::kIsNormal;
    3664     1054514 :   if (Check(Token::MUL)) {
    3665             :     flags |= ParseFunctionFlag::kIsGenerator;
    3666             :   }
    3667     1054514 :   return ParseHoistableDeclaration(pos, flags, names, default_export);
    3668             : }
    3669             : 
    3670             : template <typename Impl>
    3671             : typename ParserBase<Impl>::StatementT
    3672     1213690 : ParserBase<Impl>::ParseHoistableDeclaration(
    3673             :     int pos, ParseFunctionFlags flags, ZonePtrList<const AstRawString>* names,
    3674     3641240 :     bool default_export) {
    3675     1213690 :   CheckStackOverflow();
    3676             : 
    3677             :   // FunctionDeclaration ::
    3678             :   //   'function' Identifier '(' FormalParameters ')' '{' FunctionBody '}'
    3679             :   //   'function' '(' FormalParameters ')' '{' FunctionBody '}'
    3680             :   // GeneratorDeclaration ::
    3681             :   //   'function' '*' Identifier '(' FormalParameters ')' '{' FunctionBody '}'
    3682             :   //   'function' '*' '(' FormalParameters ')' '{' FunctionBody '}'
    3683             :   //
    3684             :   // The anonymous forms are allowed iff [default_export] is true.
    3685             :   //
    3686             :   // 'function' and '*' (if present) have been consumed by the caller.
    3687             : 
    3688             :   DCHECK_IMPLIES((flags & ParseFunctionFlag::kIsAsync) != 0,
    3689             :                  (flags & ParseFunctionFlag::kIsGenerator) == 0);
    3690             : 
    3691     1371908 :   if ((flags & ParseFunctionFlag::kIsAsync) != 0 && Check(Token::MUL)) {
    3692             :     // Async generator
    3693             :     flags |= ParseFunctionFlag::kIsGenerator;
    3694             :   }
    3695             : 
    3696             :   IdentifierT name;
    3697             :   FunctionNameValidity name_validity;
    3698             :   IdentifierT variable_name;
    3699     1213828 :   if (default_export && peek() == Token::LPAREN) {
    3700             :     impl()->GetDefaultStrings(&name, &variable_name);
    3701             :     name_validity = kSkipFunctionNameCheck;
    3702             :   } else {
    3703             :     bool is_strict_reserved = Token::IsStrictReservedWord(peek());
    3704             :     name = ParseIdentifier();
    3705     1213787 :     name_validity = is_strict_reserved ? kFunctionNameIsStrictReserved
    3706             :                                        : kFunctionNameValidityUnknown;
    3707             :     variable_name = name;
    3708             :   }
    3709             : 
    3710      979070 :   FuncNameInferrerState fni_state(&fni_);
    3711             :   impl()->PushEnclosingName(name);
    3712             : 
    3713             :   FunctionKind function_kind = FunctionKindFor(flags);
    3714             : 
    3715             :   FunctionLiteralT function = impl()->ParseFunctionLiteral(
    3716             :       name, scanner()->location(), name_validity, function_kind, pos,
    3717     2427360 :       FunctionLiteral::kDeclaration, language_mode(), nullptr);
    3718             : 
    3719             :   // In ES6, a function behaves as a lexical binding, except in
    3720             :   // a script scope, or the initial scope of eval or another function.
    3721             :   VariableMode mode =
    3722     1185792 :       (!scope()->is_declaration_scope() || scope()->is_module_scope())
    3723             :           ? VariableMode::kLet
    3724     2399572 :           : VariableMode::kVar;
    3725             :   // Async functions don't undergo sloppy mode block scoped hoisting, and don't
    3726             :   // allow duplicates in a block. Both are represented by the
    3727             :   // sloppy_block_functions_. Don't add them to the map for async functions.
    3728             :   // Generators are also supposed to be prohibited; currently doing this behind
    3729             :   // a flag and UseCounting violations to assess web compatibility.
    3730             :   VariableKind kind = is_sloppy(language_mode()) &&
    3731             :                               !scope()->is_declaration_scope() &&
    3732             :                               flags == ParseFunctionFlag::kIsNormal
    3733             :                           ? SLOPPY_BLOCK_FUNCTION_VARIABLE
    3734     1213780 :                           : NORMAL_VARIABLE;
    3735             : 
    3736             :   return impl()->DeclareFunction(variable_name, function, mode, kind, pos,
    3737     1213796 :                                  end_position(), names);
    3738             : }
    3739             : 
    3740             : template <typename Impl>
    3741      175096 : typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseClassDeclaration(
    3742      456162 :     ZonePtrList<const AstRawString>* names, bool default_export) {
    3743             :   // ClassDeclaration ::
    3744             :   //   'class' Identifier ('extends' LeftHandExpression)? '{' ClassBody '}'
    3745             :   //   'class' ('extends' LeftHandExpression)? '{' ClassBody '}'
    3746             :   //
    3747             :   // The anonymous form is allowed iff [default_export] is true.
    3748             :   //
    3749             :   // 'class' is expected to be consumed by the caller.
    3750             :   //
    3751             :   // A ClassDeclaration
    3752             :   //
    3753             :   //   class C { ... }
    3754             :   //
    3755             :   // has the same semantics as:
    3756             :   //
    3757             :   //   let C = class C { ... };
    3758             :   //
    3759             :   // so rewrite it as such.
    3760             : 
    3761             :   int class_token_pos = position();
    3762       69131 :   IdentifierT name = impl()->NullIdentifier();
    3763             :   bool is_strict_reserved = Token::IsStrictReservedWord(peek());
    3764             :   IdentifierT variable_name = impl()->NullIdentifier();
    3765      175181 :   if (default_export && (peek() == Token::EXTENDS || peek() == Token::LBRACE)) {
    3766             :     impl()->GetDefaultStrings(&name, &variable_name);
    3767             :   } else {
    3768             :     name = ParseIdentifier();
    3769             :     variable_name = name;
    3770             :   }
    3771             : 
    3772      175095 :   ExpressionParsingScope no_expression_scope(impl());
    3773             :   ExpressionT value = ParseClassLiteral(name, scanner()->location(),
    3774      350198 :                                         is_strict_reserved, class_token_pos);
    3775             :   no_expression_scope.ValidateExpression();
    3776             :   int end_pos = position();
    3777             :   return impl()->DeclareClass(variable_name, value, names, class_token_pos,
    3778      281068 :                               end_pos);
    3779             : }
    3780             : 
    3781             : // Language extension which is only enabled for source files loaded
    3782             : // through the API's extension mechanism.  A native function
    3783             : // declaration is resolved by looking up the function through a
    3784             : // callback provided by the extension.
    3785             : template <typename Impl>
    3786             : typename ParserBase<Impl>::StatementT
    3787        3468 : ParserBase<Impl>::ParseNativeDeclaration() {
    3788        1734 :   function_state_->DisableOptimization(BailoutReason::kNativeFunctionLiteral);
    3789             : 
    3790             :   int pos = peek_position();
    3791             :   Consume(Token::FUNCTION);
    3792             :   // Allow "eval" or "arguments" for backward compatibility.
    3793             :   IdentifierT name = ParseIdentifier();
    3794        1734 :   Expect(Token::LPAREN);
    3795        1734 :   if (peek() != Token::RPAREN) {
    3796           0 :     do {
    3797             :       ParseIdentifier();
    3798             :     } while (Check(Token::COMMA));
    3799             :   }
    3800        1734 :   Expect(Token::RPAREN);
    3801        1734 :   Expect(Token::SEMICOLON);
    3802        1734 :   return impl()->DeclareNative(name, pos);
    3803             : }
    3804             : 
    3805             : template <typename Impl>
    3806             : typename ParserBase<Impl>::StatementT
    3807      158202 : ParserBase<Impl>::ParseAsyncFunctionDeclaration(
    3808      316404 :     ZonePtrList<const AstRawString>* names, bool default_export) {
    3809             :   // AsyncFunctionDeclaration ::
    3810             :   //   async [no LineTerminator here] function BindingIdentifier[Await]
    3811             :   //       ( FormalParameters[Await] ) { AsyncFunctionBody }
    3812             :   DCHECK_EQ(scanner()->current_token(), Token::ASYNC);
    3813      158202 :   if (V8_UNLIKELY(scanner()->literal_contains_escapes())) {
    3814           0 :     impl()->ReportUnexpectedToken(Token::ESCAPED_KEYWORD);
    3815             :   }
    3816             :   int pos = position();
    3817             :   DCHECK(!scanner()->HasLineTerminatorBeforeNext());
    3818             :   Consume(Token::FUNCTION);
    3819             :   ParseFunctionFlags flags = ParseFunctionFlag::kIsAsync;
    3820      158205 :   return ParseHoistableDeclaration(pos, flags, names, default_export);
    3821             : }
    3822             : 
    3823             : template <typename Impl>
    3824     2754062 : void ParserBase<Impl>::ParseFunctionBody(
    3825       31861 :     StatementListT* body, IdentifierT function_name, int pos,
    3826             :     const FormalParametersT& parameters, FunctionKind kind,
    3827     4452004 :     FunctionLiteral::FunctionType function_type, FunctionBodyType body_type) {
    3828             :   FunctionBodyParsingScope body_parsing_scope(impl());
    3829             : 
    3830     1793351 :   if (IsResumableFunction(kind)) impl()->PrepareGeneratorVariables();
    3831             : 
    3832     2754047 :   DeclarationScope* function_scope = parameters.scope;
    3833             :   DeclarationScope* inner_scope = function_scope;
    3834             : 
    3835             :   // Building the parameter initialization block declares the parameters.
    3836             :   // TODO(verwaest): Rely on ArrowHeadParsingScope instead.
    3837     2754047 :   if (V8_UNLIKELY(!parameters.is_simple)) {
    3838      146787 :     if (has_error()) return;
    3839       53352 :     BlockT init_block = impl()->BuildParameterInitializationBlock(parameters);
    3840       53354 :     if (IsAsyncFunction(kind) && !IsAsyncGeneratorFunction(kind)) {
    3841        1776 :       init_block = impl()->BuildRejectPromiseOnException(init_block);
    3842             :     }
    3843             :     body->Add(init_block);
    3844       53355 :     if (has_error()) return;
    3845             : 
    3846       53355 :     inner_scope = NewVarblockScope();
    3847       53354 :     inner_scope->set_start_position(scanner()->location().beg_pos);
    3848             :   }
    3849             : 
    3850     1773192 :   StatementListT inner_body(pointer_buffer());
    3851             : 
    3852             :   {
    3853     2697259 :     BlockState block_state(&scope_, inner_scope);
    3854             : 
    3855     2697259 :     if (body_type == FunctionBodyType::kExpression) {
    3856      292733 :       ExpressionT expression = ParseAssignmentExpression();
    3857             : 
    3858      701245 :       if (IsAsyncFunction(kind)) {
    3859        2301 :         BlockT block = factory()->NewBlock(1, true);
    3860        2301 :         impl()->RewriteAsyncFunctionBody(&inner_body, block, expression);
    3861             :       } else {
    3862      697599 :         inner_body.Add(
    3863             :             BuildReturnStatement(expression, expression->position()));
    3864             :       }
    3865             :     } else {
    3866             :       DCHECK(accept_IN_);
    3867             :       DCHECK_EQ(FunctionBodyType::kBlock, body_type);
    3868             :       // If we are parsing the source as if it is wrapped in a function, the
    3869             :       // source ends without a closing brace.
    3870             :       Token::Value closing_token = function_type == FunctionLiteral::kWrapped
    3871             :                                        ? Token::EOS
    3872     1996033 :                                        : Token::RBRACE;
    3873             : 
    3874     1996033 :       if (IsAsyncGeneratorFunction(kind)) {
    3875       24603 :         impl()->ParseAndRewriteAsyncGeneratorFunctionBody(pos, kind,
    3876             :                                                           &inner_body);
    3877     1934033 :       } else if (IsGeneratorFunction(kind)) {
    3878       25190 :         impl()->ParseAndRewriteGeneratorFunctionBody(pos, kind, &inner_body);
    3879     1877404 :       } else if (IsAsyncFunction(kind)) {
    3880       92704 :         ParseAsyncFunctionBody(inner_scope, &inner_body);
    3881             :       } else {
    3882             :         ParseStatementList(&inner_body, closing_token);
    3883             :       }
    3884             : 
    3885     1996103 :       if (IsDerivedConstructor(kind)) {
    3886        3575 :         ExpressionParsingScope expression_scope(impl());
    3887        5908 :         inner_body.Add(factory()->NewReturnStatement(impl()->ThisExpression(),
    3888             :                                                      kNoSourcePosition));
    3889             :         expression_scope.ValidateExpression();
    3890             :       }
    3891     1996103 :       Expect(closing_token);
    3892             :     }
    3893             :   }
    3894             : 
    3895             :   scope()->set_end_position(end_position());
    3896             : 
    3897             :   bool allow_duplicate_parameters = false;
    3898             : 
    3899     2697379 :   CheckConflictingVarDeclarations(inner_scope);
    3900             : 
    3901     2697351 :   if (V8_LIKELY(parameters.is_simple)) {
    3902             :     DCHECK_EQ(inner_scope, function_scope);
    3903     2643998 :     if (is_sloppy(function_scope->language_mode())) {
    3904     1021502 :       impl()->InsertSloppyBlockFunctionVarBindings(function_scope);
    3905             :     }
    3906     4160252 :     allow_duplicate_parameters =
    3907             :         is_sloppy(function_scope->language_mode()) && !IsConciseMethod(kind);
    3908             :   } else {
    3909             :     DCHECK_NOT_NULL(inner_scope);
    3910             :     DCHECK_EQ(function_scope, scope());
    3911             :     DCHECK_EQ(function_scope, inner_scope->outer_scope());
    3912       31859 :     impl()->SetLanguageMode(function_scope, inner_scope->language_mode());
    3913             : 
    3914       53355 :     if (is_sloppy(inner_scope->language_mode())) {
    3915       19782 :       impl()->InsertSloppyBlockFunctionVarBindings(inner_scope);
    3916             :     }
    3917             : 
    3918             :     inner_scope->set_end_position(end_position());
    3919       53354 :     if (inner_scope->FinalizeBlockScope() != nullptr) {
    3920       10023 :       BlockT inner_block = factory()->NewBlock(true, inner_body);
    3921             :       inner_body.Rewind();
    3922       10022 :       inner_body.Add(inner_block);
    3923             :       inner_block->set_scope(inner_scope);
    3924       10022 :       if (!impl()->HasCheckedSyntax()) {
    3925             :         const AstRawString* conflict = inner_scope->FindVariableDeclaredIn(
    3926        9866 :             function_scope, VariableMode::kLastLexicalVariableMode);
    3927        9867 :         if (conflict != nullptr) {
    3928         114 :           impl()->ReportVarRedeclarationIn(conflict, inner_scope);
    3929             :         }
    3930             :       }
    3931       10023 :       impl()->InsertShadowingVarBindingInitializers(inner_block);
    3932             :     }
    3933             :   }
    3934             : 
    3935     2697304 :   ValidateFormalParameters(language_mode(), parameters,
    3936     2697304 :                            allow_duplicate_parameters);
    3937             : 
    3938     2697322 :   if (!IsArrowFunction(kind)) {
    3939             :     // Declare arguments after parsing the function since lexical 'arguments'
    3940             :     // masks the arguments object. Declare arguments before declaring the
    3941             :     // function var since the arguments object masks 'function arguments'.
    3942     1647917 :     function_scope->DeclareArguments(ast_value_factory());
    3943             :   }
    3944             : 
    3945     1773193 :   impl()->DeclareFunctionNameVar(function_name, function_type, function_scope);
    3946             : 
    3947             :   inner_body.MergeInto(body);
    3948             : }
    3949             : 
    3950             : template <typename Impl>
    3951     4184294 : void ParserBase<Impl>::CheckArityRestrictions(int param_count,
    3952             :                                               FunctionKind function_kind,
    3953             :                                               bool has_rest,
    3954             :                                               int formals_start_pos,
    3955             :                                               int formals_end_pos) {
    3956     5467147 :   if (impl()->HasCheckedSyntax()) return;
    3957     4184390 :   if (IsGetterFunction(function_kind)) {
    3958       45374 :     if (param_count != 0) {
    3959        6062 :       impl()->ReportMessageAt(
    3960             :           Scanner::Location(formals_start_pos, formals_end_pos),
    3961             :           MessageTemplate::kBadGetterArity);
    3962             :     }
    3963     4139016 :   } else if (IsSetterFunction(function_kind)) {
    3964       37019 :     if (param_count != 1) {
    3965        1022 :       impl()->ReportMessageAt(
    3966             :           Scanner::Location(formals_start_pos, formals_end_pos),
    3967             :           MessageTemplate::kBadSetterArity);
    3968             :     }
    3969       37019 :     if (has_rest) {
    3970         936 :       impl()->ReportMessageAt(
    3971             :           Scanner::Location(formals_start_pos, formals_end_pos),
    3972             :           MessageTemplate::kBadSetterRestParameter);
    3973             :     }
    3974             :   }
    3975             : }
    3976             : 
    3977             : template <typename Impl>
    3978     1589952 : bool ParserBase<Impl>::IsNextLetKeyword() {
    3979             :   DCHECK_EQ(Token::LET, peek());
    3980             :   Token::Value next_next = PeekAhead();
    3981     1590365 :   switch (next_next) {
    3982             :     case Token::LBRACE:
    3983             :     case Token::LBRACK:
    3984             :     case Token::IDENTIFIER:
    3985             :     case Token::STATIC:
    3986             :     case Token::LET:  // `let let;` is disallowed by static semantics, but the
    3987             :                       // token must be first interpreted as a keyword in order
    3988             :                       // for those semantics to apply. This ensures that ASI is
    3989             :                       // not honored when a LineTerminator separates the
    3990             :                       // tokens.
    3991             :     case Token::YIELD:
    3992             :     case Token::AWAIT:
    3993             :     case Token::GET:
    3994             :     case Token::SET:
    3995             :     case Token::ASYNC:
    3996             :       return true;
    3997             :     case Token::FUTURE_STRICT_RESERVED_WORD:
    3998        3280 :       return is_sloppy(language_mode());
    3999             :     default:
    4000        8394 :       return false;
    4001             :   }
    4002             : }
    4003             : 
    4004             : template <typename Impl>
    4005             : typename ParserBase<Impl>::ExpressionT
    4006     1074481 : ParserBase<Impl>::ParseArrowFunctionLiteral(
    4007     1702263 :     const FormalParametersT& formal_parameters) {
    4008             :   const RuntimeCallCounterId counters[2][2] = {
    4009             :       {RuntimeCallCounterId::kParseBackgroundArrowFunctionLiteral,
    4010             :        RuntimeCallCounterId::kParseArrowFunctionLiteral},
    4011             :       {RuntimeCallCounterId::kPreParseBackgroundArrowFunctionLiteral,
    4012     1074481 :        RuntimeCallCounterId::kPreParseArrowFunctionLiteral}};
    4013             :   RuntimeCallTimerScope runtime_timer(
    4014             :       runtime_call_stats_,
    4015     1074481 :       counters[Impl::IsPreParser()][parsing_on_main_thread_]);
    4016             :   base::ElapsedTimer timer;
    4017     1074511 :   if (V8_UNLIKELY(FLAG_log_function_events)) timer.Start();
    4018             : 
    4019             :   DCHECK_IMPLIES(!has_error(), peek() == Token::ARROW);
    4020     2137816 :   if (!impl()->HasCheckedSyntax() && scanner_->HasLineTerminatorBeforeNext()) {
    4021             :     // ASI inserts `;` after arrow parameters if a line terminator is found.
    4022             :     // `=> ...` is never a valid expression, so report as syntax error.
    4023             :     // If next token is not `=>`, it's a syntax error anyways.
    4024         480 :     impl()->ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW);
    4025         480 :     return impl()->FailureExpression();
    4026             :   }
    4027             : 
    4028             :   int expected_property_count = -1;
    4029             :   int suspend_count = 0;
    4030             :   int function_literal_id = GetNextFunctionLiteralId();
    4031             : 
    4032     1074046 :   FunctionKind kind = formal_parameters.scope->function_kind();
    4033             :   FunctionLiteral::EagerCompileHint eager_compile_hint =
    4034      534905 :       default_eager_compile_hint_;
    4035      534905 :   bool can_preparse = impl()->parse_lazily() &&
    4036      534905 :                       eager_compile_hint == FunctionLiteral::kShouldLazyCompile;
    4037             :   // TODO(marja): consider lazy-parsing inner arrow functions too. is_this
    4038             :   // handling in Scope::ResolveVariable needs to change.
    4039             :   bool is_lazy_top_level_function =
    4040      849191 :       can_preparse && impl()->AllowsLazyParsingWithoutUnresolvedVariables();
    4041             :   bool has_braces = true;
    4042      534916 :   ProducedPreparseData* produced_preparse_data = nullptr;
    4043      534916 :   StatementListT body(pointer_buffer());
    4044             :   {
    4045             :     FunctionState function_state(&function_state_, &scope_,
    4046     1074057 :                                  formal_parameters.scope);
    4047             : 
    4048             :     Consume(Token::ARROW);
    4049             : 
    4050     1074050 :     if (peek() == Token::LBRACE) {
    4051             :       // Multiple statement body
    4052             :       DCHECK_EQ(scope(), formal_parameters.scope);
    4053             : 
    4054      126295 :       if (is_lazy_top_level_function) {
    4055             :         // FIXME(marja): Arrow function parameters will be parsed even if the
    4056             :         // body is preparsed; move relevant parts of parameter handling to
    4057             :         // simulate consistent parameter handling.
    4058             : 
    4059             :         // Building the parameter initialization block declares the parameters.
    4060             :         // TODO(verwaest): Rely on ArrowHeadParsingScope instead.
    4061       30180 :         if (!formal_parameters.is_simple) {
    4062        6191 :           impl()->BuildParameterInitializationBlock(formal_parameters);
    4063       11868 :           if (has_error()) return impl()->FailureExpression();
    4064             :         }
    4065             : 
    4066             :         // For arrow functions, we don't need to retrieve data about function
    4067             :         // parameters.
    4068       30180 :         int dummy_num_parameters = -1;
    4069             :         DCHECK_NE(kind & FunctionKind::kArrowFunction, 0);
    4070             :         bool did_preparse_successfully = impl()->SkipFunction(
    4071             :             nullptr, kind, FunctionLiteral::kAnonymousExpression,
    4072             :             formal_parameters.scope, &dummy_num_parameters,
    4073       30180 :             &produced_preparse_data);
    4074             : 
    4075             :         DCHECK_NULL(produced_preparse_data);
    4076             : 
    4077       30184 :         if (did_preparse_successfully) {
    4078             :           // Validate parameter names. We can do this only after preparsing the
    4079             :           // function, since the function can declare itself strict.
    4080       24507 :           ValidateFormalParameters(language_mode(), formal_parameters, false);
    4081             :         } else {
    4082             :           // In case we did not sucessfully preparse the function because of an
    4083             :           // unidentified error we do a full reparse to return the error.
    4084             :           // Parse again in the outer scope, since the language mode may change.
    4085        5677 :           BlockState block_state(&scope_, scope()->outer_scope());
    4086             :           ExpressionT expression = ParseConditionalExpression();
    4087             :           // Reparsing the head may have caused a stack overflow.
    4088        5698 :           if (has_error()) return impl()->FailureExpression();
    4089             : 
    4090        5656 :           DeclarationScope* function_scope = next_arrow_function_info_.scope;
    4091             :           FunctionState function_state(&function_state_, &scope_,
    4092             :                                        function_scope);
    4093             :           Scanner::Location loc(function_scope->start_position(),
    4094        5656 :                                 end_position());
    4095             :           FormalParametersT parameters(function_scope);
    4096        5656 :           parameters.is_simple = function_scope->has_simple_parameters();
    4097        5656 :           impl()->DeclareArrowFunctionFormalParameters(&parameters, expression,
    4098             :                                                        loc);
    4099             :           next_arrow_function_info_.Reset();
    4100             : 
    4101             :           Consume(Token::ARROW);
    4102             :           Consume(Token::LBRACE);
    4103             : 
    4104             :           AcceptINScope scope(this, true);
    4105        5656 :           ParseFunctionBody(&body, impl()->NullIdentifier(), kNoSourcePosition,
    4106             :                             parameters, kind,
    4107             :                             FunctionLiteral::kAnonymousExpression,
    4108             :                             FunctionBodyType::kBlock);
    4109        5656 :           CHECK(has_error());
    4110             :           return impl()->FailureExpression();
    4111             :         }
    4112             :       } else {
    4113             :         Consume(Token::LBRACE);
    4114             :         AcceptINScope scope(this, true);
    4115      342529 :         ParseFunctionBody(&body, impl()->NullIdentifier(), kNoSourcePosition,
    4116             :                           formal_parameters, kind,
    4117             :                           FunctionLiteral::kAnonymousExpression,
    4118      835344 :                           FunctionBodyType::kBlock);
    4119       96115 :         expected_property_count = function_state.expected_property_count();
    4120             :       }
    4121             :     } else {
    4122             :       // Single-expression body
    4123             :       has_braces = false;
    4124      701353 :       ParseFunctionBody(&body, impl()->NullIdentifier(), kNoSourcePosition,
    4125             :                         formal_parameters, kind,
    4126             :                         FunctionLiteral::kAnonymousExpression,
    4127     1286823 :                         FunctionBodyType::kExpression);
    4128      408584 :       expected_property_count = function_state.expected_property_count();
    4129             :     }
    4130             : 
    4131     2749351 :     formal_parameters.scope->set_end_position(end_position());
    4132             : 
    4133             :     // Validate strict mode.
    4134     1068339 :     if (is_strict(language_mode())) {
    4135      622585 :       CheckStrictOctalLiteral(formal_parameters.scope->start_position(),
    4136      622585 :                               end_position());
    4137             :     }
    4138      529207 :     suspend_count = function_state.suspend_count();
    4139             :   }
    4140             : 
    4141             :   FunctionLiteralT function_literal = factory()->NewFunctionLiteral(
    4142             :       impl()->EmptyIdentifierString(), formal_parameters.scope, body,
    4143             :       expected_property_count, formal_parameters.num_parameters(),
    4144             :       formal_parameters.function_length,
    4145             :       FunctionLiteral::kNoDuplicateParameters,
    4146             :       FunctionLiteral::kAnonymousExpression, eager_compile_hint,
    4147             :       formal_parameters.scope->start_position(), has_braces,
    4148     1587626 :       function_literal_id, produced_preparse_data);
    4149             : 
    4150             :   function_literal->set_suspend_count(suspend_count);
    4151      529220 :   function_literal->set_function_token_position(
    4152             :       formal_parameters.scope->start_position());
    4153             : 
    4154             :   impl()->AddFunctionForNameInference(function_literal);
    4155             : 
    4156     1068341 :   if (V8_UNLIKELY((FLAG_log_function_events))) {
    4157          12 :     Scope* scope = formal_parameters.scope;
    4158           6 :     double ms = timer.Elapsed().InMillisecondsF();
    4159             :     const char* event_name =
    4160           3 :         is_lazy_top_level_function ? "preparse-no-resolution" : "parse";
    4161             :     const char* name = "arrow function";
    4162           6 :     logger_->FunctionEvent(event_name, script_id(), ms, scope->start_position(),
    4163             :                            scope->end_position(), name, strlen(name));
    4164             :   }
    4165             : 
    4166     1068345 :   return function_literal;
    4167             : }
    4168             : 
    4169             : template <typename Impl>
    4170      311837 : typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseClassLiteral(
    4171             :     IdentifierT name, Scanner::Location class_name_location,
    4172      783834 :     bool name_is_strict_reserved, int class_token_pos) {
    4173             :   bool is_anonymous = impl()->IsNull(name);
    4174             : 
    4175             :   // All parts of a ClassDeclaration and ClassExpression are strict code.
    4176      311841 :   if (!impl()->HasCheckedSyntax() && !is_anonymous) {
    4177      193094 :     if (name_is_strict_reserved) {
    4178        1080 :       impl()->ReportMessageAt(class_name_location,
    4179             :                               MessageTemplate::kUnexpectedStrictReserved);
    4180        1080 :       return impl()->FailureExpression();
    4181             :     }
    4182      192020 :     if (impl()->IsEvalOrArguments(name)) {
    4183         320 :       impl()->ReportMessageAt(class_name_location,
    4184             :                               MessageTemplate::kStrictEvalArguments);
    4185         320 :       return impl()->FailureExpression();
    4186             :     }
    4187             :   }
    4188             : 
    4189             :   Scope* block_scope = NewScope(BLOCK_SCOPE);
    4190      310444 :   BlockState block_state(&scope_, block_scope);
    4191      310444 :   RaiseLanguageMode(LanguageMode::kStrict);
    4192             : 
    4193      310446 :   ClassInfo class_info(this);
    4194      310441 :   class_info.is_anonymous = is_anonymous;
    4195             :   impl()->DeclareClassVariable(name, &class_info, class_token_pos);
    4196             : 
    4197             :   scope()->set_start_position(end_position());
    4198      310443 :   if (Check(Token::EXTENDS)) {
    4199       60192 :     FuncNameInferrerState fni_state(&fni_);
    4200      111454 :     ExpressionParsingScope scope(impl());
    4201      111455 :     class_info.extends = ParseLeftHandSideExpression();
    4202       60192 :     scope.ValidateExpression();
    4203             :   }
    4204             : 
    4205      310442 :   Expect(Token::LBRACE);
    4206             : 
    4207      310438 :   const bool has_extends = !impl()->IsNull(class_info.extends);
    4208     1512591 :   while (peek() != Token::RBRACE) {
    4209      685854 :     if (Check(Token::SEMICOLON)) continue;
    4210      466537 :     FuncNameInferrerState fni_state(&fni_);
    4211             :     // If we haven't seen the constructor yet, it potentially is the next
    4212             :     // property.
    4213      466537 :     bool is_constructor = !class_info.has_seen_constructor;
    4214      140915 :     ParsePropertyInfo prop_info(this);
    4215      140915 :     prop_info.position = PropertyPosition::kClassLiteral;
    4216             :     ClassLiteralPropertyT property =
    4217      607452 :         ParseClassPropertyDefinition(&class_info, &prop_info, has_extends);
    4218             : 
    4219      754967 :     if (has_error()) return impl()->FailureExpression();
    4220             : 
    4221             :     ClassLiteralProperty::Kind property_kind =
    4222      459969 :         ClassPropertyKindFor(prop_info.kind);
    4223      459961 :     if (!class_info.has_static_computed_names && prop_info.is_static &&
    4224             :         prop_info.is_computed_name) {
    4225        5127 :       class_info.has_static_computed_names = true;
    4226             :     }
    4227      392546 :     is_constructor &= class_info.has_seen_constructor;
    4228             : 
    4229      459961 :     if (V8_UNLIKELY(property_kind == ClassLiteralProperty::FIELD)) {
    4230       61345 :       if (prop_info.is_computed_name) {
    4231             :         DCHECK(!prop_info.is_private);
    4232        9928 :         class_info.computed_field_count++;
    4233             :       }
    4234             : 
    4235       61345 :       impl()->DeclareClassField(property, prop_info.name, prop_info.is_static,
    4236             :                                 prop_info.is_computed_name,
    4237             :                                 prop_info.is_private, &class_info);
    4238             :     } else {
    4239      360793 :       impl()->DeclareClassProperty(name, property, is_constructor, &class_info);
    4240             :     }
    4241             :     impl()->InferFunctionName();
    4242             :   }
    4243             : 
    4244      162945 :   Expect(Token::RBRACE);
    4245             :   int end_pos = end_position();
    4246             :   block_scope->set_end_position(end_pos);
    4247             :   return impl()->RewriteClassLiteral(block_scope, name, &class_info,
    4248      109009 :                                      class_token_pos, end_pos);
    4249             : }
    4250             : 
    4251             : template <typename Impl>
    4252       92704 : void ParserBase<Impl>::ParseAsyncFunctionBody(Scope* scope,
    4253       92705 :                                               StatementListT* body) {
    4254             :   BlockT block = impl()->NullBlock();
    4255             :   {
    4256       40513 :     StatementListT statements(pointer_buffer());
    4257             :     ParseStatementList(&statements, Token::RBRACE);
    4258       40513 :     block = factory()->NewBlock(true, statements);
    4259             :   }
    4260       81028 :   impl()->RewriteAsyncFunctionBody(
    4261             :       body, block, factory()->NewUndefinedLiteral(kNoSourcePosition));
    4262             :   scope->set_end_position(end_position());
    4263       92705 : }
    4264             : 
    4265             : template <typename Impl>
    4266             : typename ParserBase<Impl>::ExpressionT
    4267       63804 : ParserBase<Impl>::ParseAsyncFunctionLiteral() {
    4268             :   // AsyncFunctionLiteral ::
    4269             :   //   async [no LineTerminator here] function ( FormalParameters[Await] )
    4270             :   //       { AsyncFunctionBody }
    4271             :   //
    4272             :   //   async [no LineTerminator here] function BindingIdentifier[Await]
    4273             :   //       ( FormalParameters[Await] ) { AsyncFunctionBody }
    4274             :   DCHECK_EQ(scanner()->current_token(), Token::ASYNC);
    4275       21268 :   if (V8_UNLIKELY(scanner()->literal_contains_escapes())) {
    4276           0 :     impl()->ReportUnexpectedToken(Token::ESCAPED_KEYWORD);
    4277             :   }
    4278             :   int pos = position();
    4279             :   Consume(Token::FUNCTION);
    4280        8060 :   IdentifierT name = impl()->NullIdentifier();
    4281             :   FunctionLiteral::FunctionType type = FunctionLiteral::kAnonymousExpression;
    4282             : 
    4283             :   ParseFunctionFlags flags = ParseFunctionFlag::kIsAsync;
    4284       21268 :   if (Check(Token::MUL)) flags |= ParseFunctionFlag::kIsGenerator;
    4285             :   const FunctionKind kind = FunctionKindFor(flags);
    4286             :   bool is_strict_reserved = Token::IsStrictReservedWord(peek());
    4287             : 
    4288       13208 :   if (impl()->ParsingDynamicFunctionDeclaration()) {
    4289             :     // We don't want dynamic functions to actually declare their name
    4290             :     // "anonymous". We just want that name in the toString().
    4291             : 
    4292             :     // Consuming token we did not peek yet, which could lead to a ILLEGAL token
    4293             :     // in the case of a stackoverflow.
    4294             :     Consume(Token::IDENTIFIER);
    4295             :     DCHECK_IMPLIES(!has_error(),
    4296             :                    scanner()->CurrentSymbol(ast_value_factory()) ==
    4297             :                        ast_value_factory()->anonymous_string());
    4298       20658 :   } else if (peek_any_identifier()) {
    4299             :     type = FunctionLiteral::kNamedExpression;
    4300        3604 :     name = ParseIdentifier(kind);
    4301             :   }
    4302             :   FunctionLiteralT result = impl()->ParseFunctionLiteral(
    4303             :       name, scanner()->location(),
    4304             :       is_strict_reserved ? kFunctionNameIsStrictReserved
    4305             :                          : kFunctionNameValidityUnknown,
    4306       42536 :       kind, pos, type, language_mode(), nullptr);
    4307       21528 :   if (impl()->IsNull(result)) return impl()->FailureExpression();
    4308        8060 :   return result;
    4309             : }
    4310             : 
    4311             : template <typename Impl>
    4312       72140 : typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseTemplateLiteral(
    4313      207648 :     ExpressionT tag, int start, bool tagged) {
    4314             :   // A TemplateLiteral is made up of 0 or more TEMPLATE_SPAN tokens (literal
    4315             :   // text followed by a substitution expression), finalized by a single
    4316             :   // TEMPLATE_TAIL.
    4317             :   //
    4318             :   // In terms of draft language, TEMPLATE_SPAN may be either the TemplateHead or
    4319             :   // TemplateMiddle productions, while TEMPLATE_TAIL is either TemplateTail, or
    4320             :   // NoSubstitutionTemplate.
    4321             :   //
    4322             :   // When parsing a TemplateLiteral, we must have scanned either an initial
    4323             :   // TEMPLATE_SPAN, or a TEMPLATE_TAIL.
    4324             :   DCHECK(peek() == Token::TEMPLATE_SPAN || peek() == Token::TEMPLATE_TAIL);
    4325             : 
    4326       72140 :   if (tagged) {
    4327             :     // TaggedTemplate expressions prevent the eval compilation cache from being
    4328             :     // used. This flag is only used if an eval is being parsed.
    4329             :     set_allow_eval_cache(false);
    4330             :   }
    4331             : 
    4332       72140 :   bool forbid_illegal_escapes = !tagged;
    4333             : 
    4334             :   // If we reach a TEMPLATE_TAIL first, we are parsing a NoSubstitutionTemplate.
    4335             :   // In this case we may simply consume the token and build a template with a
    4336             :   // single TEMPLATE_SPAN and no expressions.
    4337       72141 :   if (peek() == Token::TEMPLATE_TAIL) {
    4338             :     Consume(Token::TEMPLATE_TAIL);
    4339             :     int pos = position();
    4340        9676 :     typename Impl::TemplateLiteralState ts = impl()->OpenTemplateLiteral(pos);
    4341       18174 :     bool is_valid = CheckTemplateEscapes(forbid_illegal_escapes);
    4342        9677 :     impl()->AddTemplateSpan(&ts, is_valid, true);
    4343        9678 :     return impl()->CloseTemplateLiteral(&ts, start, tag);
    4344             :   }
    4345             : 
    4346             :   Consume(Token::TEMPLATE_SPAN);
    4347             :   int pos = position();
    4348       28228 :   typename Impl::TemplateLiteralState ts = impl()->OpenTemplateLiteral(pos);
    4349       53972 :   bool is_valid = CheckTemplateEscapes(forbid_illegal_escapes);
    4350       28228 :   impl()->AddTemplateSpan(&ts, is_valid, false);
    4351             :   Token::Value next;
    4352             : 
    4353             :   // If we open with a TEMPLATE_SPAN, we must scan the subsequent expression,
    4354             :   // and repeat if the following token is a TEMPLATE_SPAN as well (in this
    4355             :   // case, representing a TemplateMiddle).
    4356             : 
    4357       78318 :   do {
    4358             :     next = peek();
    4359             : 
    4360             :     int expr_pos = peek_position();
    4361             :     AcceptINScope scope(this, true);
    4362       84872 :     ExpressionT expression = ParseExpressionCoverGrammar();
    4363             :     impl()->AddTemplateExpression(&ts, expression);
    4364             : 
    4365       84872 :     if (peek() != Token::RBRACE) {
    4366        6557 :       impl()->ReportMessageAt(Scanner::Location(expr_pos, peek_position()),
    4367             :                               MessageTemplate::kUnterminatedTemplateExpr);
    4368        3460 :       return impl()->FailureExpression();
    4369             :     }
    4370             : 
    4371             :     // If we didn't die parsing that expression, our next token should be a
    4372             :     // TEMPLATE_SPAN or TEMPLATE_TAIL.
    4373             :     next = scanner()->ScanTemplateContinuation();
    4374             :     Next();
    4375             :     pos = position();
    4376             : 
    4377       78318 :     bool is_valid = CheckTemplateEscapes(forbid_illegal_escapes);
    4378       44390 :     impl()->AddTemplateSpan(&ts, is_valid, next == Token::TEMPLATE_TAIL);
    4379             :   } while (next == Token::TEMPLATE_SPAN);
    4380             : 
    4381             :   DCHECK_IMPLIES(!has_error(), next == Token::TEMPLATE_TAIL);
    4382             :   // Once we've reached a TEMPLATE_TAIL, we can close the TemplateLiteral.
    4383       25132 :   return impl()->CloseTemplateLiteral(&ts, start, tag);
    4384             : }
    4385             : 
    4386             : template <typename Impl>
    4387             : typename ParserBase<Impl>::ExpressionT
    4388       27432 : ParserBase<Impl>::RewriteInvalidReferenceExpression(ExpressionT expression,
    4389             :                                                     int beg_pos, int end_pos,
    4390             :                                                     MessageTemplate message,
    4391        2271 :                                                     ParseErrorType type) {
    4392             :   DCHECK(!IsValidReferenceExpression(expression));
    4393       27434 :   if (impl()->IsIdentifier(expression)) {
    4394             :     DCHECK(is_strict(language_mode()));
    4395             :     DCHECK(impl()->IsEvalOrArguments(impl()->AsIdentifier(expression)));
    4396             : 
    4397        5383 :     ReportMessageAt(Scanner::Location(beg_pos, end_pos),
    4398        5383 :                     MessageTemplate::kStrictEvalArguments, kSyntaxError);
    4399        5383 :     return impl()->FailureExpression();
    4400             :   }
    4401       25701 :   if (expression->IsCall() && !expression->AsCall()->is_tagged_template()) {
    4402        2271 :     expression_scope()->RecordPatternError(
    4403             :         Scanner::Location(beg_pos, end_pos),
    4404             :         MessageTemplate::kInvalidDestructuringTarget);
    4405             :     // If it is a call, make it a runtime error for legacy web compatibility.
    4406             :     // Bug: https://bugs.chromium.org/p/v8/issues/detail?id=4480
    4407             :     // Rewrite `expr' to `expr[throw ReferenceError]'.
    4408        2271 :     impl()->CountUsage(
    4409             :         is_strict(language_mode())
    4410             :             ? v8::Isolate::kAssigmentExpressionLHSIsCallInStrict
    4411             :             : v8::Isolate::kAssigmentExpressionLHSIsCallInSloppy);
    4412        1052 :     ExpressionT error = impl()->NewThrowReferenceError(message, beg_pos);
    4413        3490 :     return factory()->NewProperty(expression, error, beg_pos);
    4414             :   }
    4415       19780 :   ReportMessageAt(Scanner::Location(beg_pos, end_pos), message, type);
    4416       19780 :   return impl()->FailureExpression();
    4417             : }
    4418             : 
    4419             : template <typename Impl>
    4420    15362178 : void ParserBase<Impl>::ClassifyParameter(IdentifierT parameter, int begin,
    4421       15771 :                                          int end) {
    4422    15362225 :   if (impl()->IsEvalOrArguments(parameter)) {
    4423       15771 :     expression_scope()->RecordStrictModeParameterError(
    4424             :         Scanner::Location(begin, end), MessageTemplate::kStrictEvalArguments);
    4425             :   }
    4426    15362225 : }
    4427             : 
    4428             : template <typename Impl>
    4429    39905389 : void ParserBase<Impl>::ClassifyArrowParameter(
    4430             :     AccumulationScope* accumulation_scope, int position,
    4431    81850014 :     ExpressionT parameter) {
    4432    39905389 :   accumulation_scope->Accumulate();
    4433   118924829 :   if (parameter->is_parenthesized() ||
    4434    52270215 :       !(impl()->IsIdentifier(parameter) || parameter->IsPattern() ||
    4435             :         parameter->IsAssignment())) {
    4436    23422963 :     expression_scope()->RecordDeclarationError(
    4437             :         Scanner::Location(position, end_position()),
    4438             :         MessageTemplate::kInvalidDestructuringTarget);
    4439    16486666 :   } else if (impl()->IsIdentifier(parameter)) {
    4440     5136315 :     ClassifyParameter(impl()->AsIdentifier(parameter), position,
    4441             :                       end_position());
    4442             :   } else {
    4443             :     expression_scope()->RecordNonSimpleParameter();
    4444             :   }
    4445    39909661 : }
    4446             : 
    4447             : template <typename Impl>
    4448    13942930 : bool ParserBase<Impl>::IsValidReferenceExpression(ExpressionT expression) {
    4449    24761071 :   return IsAssignableIdentifier(expression) || expression->IsProperty();
    4450             : }
    4451             : 
    4452             : template <typename Impl>
    4453             : typename ParserBase<Impl>::ExpressionT
    4454    12876723 : ParserBase<Impl>::ParsePossibleDestructuringSubPattern(
    4455    35844484 :     AccumulationScope* scope) {
    4456    12876723 :   if (scope) scope->Accumulate();
    4457             :   int begin = peek_position();
    4458    21337807 :   ExpressionT result = ParseAssignmentExpressionCoverGrammar();
    4459             : 
    4460    12876700 :   if (IsValidReferenceExpression(result)) {
    4461             :     // Parenthesized identifiers and property references are allowed as part of
    4462             :     // a larger assignment pattern, even though parenthesized patterns
    4463             :     // themselves are not allowed, e.g., "[(x)] = []". Only accumulate
    4464             :     // assignment pattern errors if the parsed expression is more complex.
    4465     2413948 :     if (impl()->IsIdentifier(result)) {
    4466     2101352 :       if (result->is_parenthesized()) {
    4467        8353 :         expression_scope()->RecordDeclarationError(
    4468             :             Scanner::Location(begin, end_position()),
    4469             :             MessageTemplate::kInvalidDestructuringTarget);
    4470             :       }
    4471             :       IdentifierT identifier = impl()->AsIdentifier(result);
    4472     2101344 :       ClassifyParameter(identifier, begin, end_position());
    4473             :     } else {
    4474             :       DCHECK(result->IsProperty());
    4475      312596 :       expression_scope()->RecordDeclarationError(
    4476             :           Scanner::Location(begin, end_position()),
    4477             :           MessageTemplate::kInvalidPropertyBindingPattern);
    4478      312595 :       if (scope != nullptr) scope->ValidateExpression();
    4479             :     }
    4480    31165959 :   } else if (result->is_parenthesized() ||
    4481             :              (!result->IsPattern() && !result->IsAssignment())) {
    4482    10112027 :     expression_scope()->RecordPatternError(
    4483             :         Scanner::Location(begin, end_position()),
    4484             :         MessageTemplate::kInvalidDestructuringTarget);
    4485             :   }
    4486             : 
    4487    12876703 :   return result;
    4488             : }
    4489             : 
    4490             : template <typename Impl>
    4491      126898 : typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseV8Intrinsic() {
    4492             :   // CallRuntime ::
    4493             :   //   '%' Identifier Arguments
    4494             : 
    4495             :   int pos = peek_position();
    4496             :   Consume(Token::MOD);
    4497             :   // Allow "eval" or "arguments" for backward compatibility.
    4498             :   IdentifierT name = ParseIdentifier();
    4499      126987 :   if (peek() != Token::LPAREN) {
    4500           0 :     impl()->ReportUnexpectedToken(peek());
    4501           0 :     return impl()->FailureExpression();
    4502             :   }
    4503             :   bool has_spread;
    4504       54104 :   ExpressionListT args(pointer_buffer());
    4505      126987 :   ParseArguments(&args, &has_spread);
    4506             : 
    4507      126994 :   if (has_spread) {
    4508           9 :     ReportMessageAt(Scanner::Location(pos, position()),
    4509           9 :                     MessageTemplate::kIntrinsicWithSpread, kSyntaxError);
    4510           9 :     return impl()->FailureExpression();
    4511             :   }
    4512             : 
    4513       54118 :   return impl()->NewV8Intrinsic(name, args, pos);
    4514             : }
    4515             : 
    4516             : template <typename Impl>
    4517             : void ParserBase<Impl>::ParseStatementList(StatementListT* body,
    4518     4560419 :                                           Token::Value end_token) {
    4519             :   // StatementList ::
    4520             :   //   (StatementListItem)* <end_token>
    4521             :   DCHECK_NOT_NULL(body);
    4522             : 
    4523     8221887 :   while (peek() == Token::STRING) {
    4524             :     bool use_strict = false;
    4525             :     bool use_asm = false;
    4526             : 
    4527     1520141 :     Scanner::Location token_loc = scanner()->peek_location();
    4528             : 
    4529     1520145 :     if (scanner()->NextLiteralEquals("use strict")) {
    4530             :       use_strict = true;
    4531     1099462 :     } else if (scanner()->NextLiteralEquals("use asm")) {
    4532             :       use_asm = true;
    4533             :     }
    4534             : 
    4535     1520143 :     StatementT stat = ParseStatementListItem();
    4536     1528706 :     if (impl()->IsNull(stat)) return;
    4537             : 
    4538     1313433 :     body->Add(stat);
    4539             : 
    4540     1520091 :     if (!impl()->IsStringLiteral(stat)) break;
    4541             : 
    4542     1513879 :     if (use_strict) {
    4543             :       // Directive "use strict" (ES5 14.1).
    4544      420670 :       RaiseLanguageMode(LanguageMode::kStrict);
    4545      420671 :       if (!scope()->HasSimpleParameters()) {
    4546             :         // TC39 deemed "use strict" directives to be an error when occurring
    4547             :         // in the body of a function with non-simple parameter list, on
    4548             :         // 29/7/2015. https://goo.gl/ueA7Ln
    4549        8533 :         impl()->ReportMessageAt(token_loc,
    4550             :                                 MessageTemplate::kIllegalLanguageModeDirective,
    4551             :                                 "use strict");
    4552             :         return;
    4553             :       }
    4554     1093209 :     } else if (use_asm) {
    4555             :       // Directive "use asm".
    4556        4265 :       impl()->SetAsmModule();
    4557             :     } else {
    4558             :       // Possibly an unknown directive.
    4559             :       // Should not change mode, but will increment usage counters
    4560             :       // as appropriate. Ditto usages below.
    4561     1085967 :       RaiseLanguageMode(LanguageMode::kSloppy);
    4562             :     }
    4563             :   }
    4564             : 
    4565             :   // Allocate a target stack to use for this set of source elements. This way,
    4566             :   // all scripts and functions get their own target stack thus avoiding illegal
    4567             :   // breaks and continues across functions.
    4568     3052619 :   TargetScopeT target_scope(this);
    4569    39301769 :   while (peek() != end_token) {
    4570    33473516 :     StatementT stat = ParseStatementListItem();
    4571    34353221 :     if (impl()->IsNull(stat)) return;
    4572    32594407 :     if (stat->IsEmptyStatement()) continue;
    4573    17554722 :     body->Add(stat);
    4574     2587010 :   }
    4575             : }
    4576             : 
    4577             : template <typename Impl>
    4578             : typename ParserBase<Impl>::StatementT
    4579    42518212 : ParserBase<Impl>::ParseStatementListItem() {
    4580             :   // ECMA 262 6th Edition
    4581             :   // StatementListItem[Yield, Return] :
    4582             :   //   Statement[?Yield, ?Return]
    4583             :   //   Declaration[?Yield]
    4584             :   //
    4585             :   // Declaration[Yield] :
    4586             :   //   HoistableDeclaration[?Yield]
    4587             :   //   ClassDeclaration[?Yield]
    4588             :   //   LexicalDeclaration[In, ?Yield]
    4589             :   //
    4590             :   // HoistableDeclaration[Yield, Default] :
    4591             :   //   FunctionDeclaration[?Yield, ?Default]
    4592             :   //   GeneratorDeclaration[?Yield, ?Default]
    4593             :   //
    4594             :   // LexicalDeclaration[In, Yield] :
    4595             :   //   LetOrConst BindingList[?In, ?Yield] ;
    4596             : 
    4597    42358999 :   switch (peek()) {
    4598             :     case Token::FUNCTION:
    4599     1054095 :       return ParseHoistableDeclaration(nullptr, false);
    4600             :     case Token::CLASS:
    4601             :       Consume(Token::CLASS);
    4602      175022 :       return ParseClassDeclaration(nullptr, false);
    4603             :     case Token::VAR:
    4604             :     case Token::CONST:
    4605    11529407 :       return ParseVariableStatement(kStatementListItem, nullptr);
    4606             :     case Token::LET:
    4607     1345840 :       if (IsNextLetKeyword()) {
    4608     1338192 :         return ParseVariableStatement(kStatementListItem, nullptr);
    4609             :       }
    4610             :       break;
    4611             :     case Token::ASYNC:
    4612      317912 :       if (PeekAhead() == Token::FUNCTION &&
    4613             :           !scanner()->HasLineTerminatorAfterNext()) {
    4614             :         Consume(Token::ASYNC);
    4615      158081 :         return ParseAsyncFunctionDeclaration(nullptr, false);
    4616             :       }
    4617             :       break;
    4618             :     default:
    4619             :       break;
    4620             :   }
    4621    28104506 :   return ParseStatement(nullptr, nullptr, kAllowLabelledFunctionStatement);
    4622             : }
    4623             : 
    4624             : template <typename Impl>
    4625    32969279 : typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseStatement(
    4626             :     ZonePtrList<const AstRawString>* labels,
    4627             :     ZonePtrList<const AstRawString>* own_labels,
    4628      945735 :     AllowLabelledFunctionStatement allow_function) {
    4629             :   // Statement ::
    4630             :   //   Block
    4631             :   //   VariableStatement
    4632             :   //   EmptyStatement
    4633             :   //   ExpressionStatement
    4634             :   //   IfStatement
    4635             :   //   IterationStatement
    4636             :   //   ContinueStatement
    4637             :   //   BreakStatement
    4638             :   //   ReturnStatement
    4639             :   //   WithStatement
    4640             :   //   LabelledStatement
    4641             :   //   SwitchStatement
    4642             :   //   ThrowStatement
    4643             :   //   TryStatement
    4644             :   //   DebuggerStatement
    4645             : 
    4646             :   // {own_labels} is always a subset of {labels}.
    4647             :   DCHECK_IMPLIES(labels == nullptr, own_labels == nullptr);
    4648             : 
    4649             :   // Note: Since labels can only be used by 'break' and 'continue'
    4650             :   // statements, which themselves are only valid within blocks,
    4651             :   // iterations or 'switch' statements (i.e., BreakableStatements),
    4652             :   // labels can be simply ignored in all other cases; except for
    4653             :   // trivial labeled break statements 'label: break label' which is
    4654             :   // parsed into an empty statement.
    4655    32969088 :   switch (peek()) {
    4656             :     case Token::LBRACE:
    4657     2966638 :       return ParseBlock(labels);
    4658             :     case Token::SEMICOLON:
    4659             :       Next();
    4660      262683 :       return factory()->EmptyStatement();
    4661             :     case Token::IF:
    4662     3398839 :       return ParseIfStatement(labels);
    4663             :     case Token::DO:
    4664       17980 :       return ParseDoWhileStatement(labels, own_labels);
    4665             :     case Token::WHILE:
    4666       36802 :       return ParseWhileStatement(labels, own_labels);
    4667             :     case Token::FOR:
    4668     1066516 :       if (V8_UNLIKELY(is_async_function() && PeekAhead() == Token::AWAIT)) {
    4669      128558 :         return ParseForAwaitStatement(labels, own_labels);
    4670             :       }
    4671      804145 :       return ParseForStatement(labels, own_labels);
    4672             :     case Token::CONTINUE:
    4673       53364 :       return ParseContinueStatement();
    4674             :     case Token::BREAK:
    4675      195487 :       return ParseBreakStatement(labels);
    4676             :     case Token::RETURN:
    4677     3560452 :       return ParseReturnStatement();
    4678             :     case Token::THROW:
    4679      303917 :       return ParseThrowStatement();
    4680             :     case Token::TRY: {
    4681             :       // It is somewhat complicated to have labels on try-statements.
    4682             :       // When breaking out of a try-finally statement, one must take
    4683             :       // great care not to treat it as a fall-through. It is much easier
    4684             :       // just to wrap the entire try-statement in a statement block and
    4685             :       // put the labels there.
    4686      503482 :       if (labels == nullptr) return ParseTryStatement();
    4687         112 :       StatementListT statements(pointer_buffer());
    4688         112 :       BlockT result = factory()->NewBlock(false, labels);
    4689             :       TargetT target(this, result);
    4690             :       StatementT statement = ParseTryStatement();
    4691         112 :       statements.Add(statement);
    4692             :       result->InitializeStatements(statements, zone());
    4693           0 :       return result;
    4694             :     }
    4695             :     case Token::WITH:
    4696      101435 :       return ParseWithStatement(labels);
    4697             :     case Token::SWITCH:
    4698      135166 :       return ParseSwitchStatement(labels);
    4699             :     case Token::FUNCTION:
    4700             :       // FunctionDeclaration only allowed as a StatementListItem, not in
    4701             :       // an arbitrary Statement position. Exceptions such as
    4702             :       // ES#sec-functiondeclarations-in-ifstatement-statement-clauses
    4703             :       // are handled by calling ParseScopedStatement rather than
    4704             :       // ParseStatement directly.
    4705       17196 :       impl()->ReportMessageAt(scanner()->peek_location(),
    4706             :                               is_strict(language_mode())
    4707             :                                   ? MessageTemplate::kStrictFunction
    4708             :                                   : MessageTemplate::kSloppyFunction);
    4709        8598 :       return impl()->NullStatement();
    4710             :     case Token::DEBUGGER:
    4711      141815 :       return ParseDebuggerStatement();
    4712             :     case Token::VAR:
    4713         454 :       return ParseVariableStatement(kStatement, nullptr);
    4714             :     case Token::ASYNC:
    4715        7572 :       if (!impl()->HasCheckedSyntax() &&
    4716             :           !scanner()->HasLineTerminatorAfterNext() &&
    4717             :           PeekAhead() == Token::FUNCTION) {
    4718        1280 :         impl()->ReportMessageAt(
    4719             :             scanner()->peek_location(),
    4720             :             MessageTemplate::kAsyncFunctionInSingleStatementContext);
    4721        1280 :         return impl()->NullStatement();
    4722             :       }
    4723             :       V8_FALLTHROUGH;
    4724             :     default:
    4725             :       return ParseExpressionOrLabelledStatement(labels, own_labels,
    4726    20329845 :                                                 allow_function);
    4727             :   }
    4728             : }
    4729             : 
    4730             : template <typename Impl>
    4731     3776773 : typename ParserBase<Impl>::BlockT ParserBase<Impl>::ParseBlock(
    4732    22542028 :     ZonePtrList<const AstRawString>* labels) {
    4733             :   // Block ::
    4734             :   //   '{' StatementList '}'
    4735             : 
    4736             :   // Parse the statements and collect escaping labels.
    4737      946215 :   BlockT body = factory()->NewBlock(false, labels);
    4738      946249 :   StatementListT statements(pointer_buffer());
    4739             : 
    4740     3776807 :   CheckStackOverflow();
    4741             : 
    4742             :   {
    4743     7554092 :     BlockState block_state(zone(), &scope_);
    4744             :     scope()->set_start_position(peek_position());
    4745             :     TargetT target(this, body);
    4746             : 
    4747     3777228 :     Expect(Token::LBRACE);
    4748             : 
    4749    13649750 :     while (peek() != Token::RBRACE) {
    4750     6135687 :       StatementT stat = ParseStatementListItem();
    4751     6135729 :       if (impl()->IsNull(stat)) return body;
    4752     6095278 :       if (stat->IsEmptyStatement()) continue;
    4753     1609354 :       statements.Add(stat);
    4754             :     }
    4755             : 
    4756     3736818 :     Expect(Token::RBRACE);
    4757             : 
    4758             :     int end_pos = end_position();
    4759             :     scope()->set_end_position(end_pos);
    4760             : 
    4761             :     impl()->RecordBlockSourceRange(body, end_pos);
    4762     3736842 :     body->set_scope(scope()->FinalizeBlockScope());
    4763             :   }
    4764             : 
    4765      919558 :   body->InitializeStatements(statements, zone_);
    4766     3736726 :   return body;
    4767             : }
    4768             : 
    4769             : template <typename Impl>
    4770     3782672 : typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseScopedStatement(
    4771        6064 :     ZonePtrList<const AstRawString>* labels) {
    4772     7139745 :   if (is_strict(language_mode()) || peek() != Token::FUNCTION) {
    4773      680182 :     return ParseStatement(labels, nullptr);
    4774             :   } else {
    4775             :     // Make a block around the statement for a lexical binding
    4776             :     // is introduced by a FunctionDeclaration.
    4777        1858 :     BlockState block_state(zone(), &scope_);
    4778         929 :     scope()->set_start_position(scanner()->location().beg_pos);
    4779         490 :     BlockT block = factory()->NewBlock(1, false);
    4780         929 :     StatementT body = ParseFunctionDeclaration();
    4781         490 :     block->statements()->Add(body, zone());
    4782             :     scope()->set_end_position(end_position());
    4783         929 :     block->set_scope(scope()->FinalizeBlockScope());
    4784         439 :     return block;
    4785             :   }
    4786             : }
    4787             : 
    4788             : template <typename Impl>
    4789    12885390 : typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseVariableStatement(
    4790             :     VariableDeclarationContext var_context,
    4791             :     ZonePtrList<const AstRawString>* names) {
    4792             :   // VariableStatement ::
    4793             :   //   VariableDeclarations ';'
    4794             : 
    4795             :   // The scope of a var declared variable anywhere inside a function
    4796             :   // is the entire function (ECMA-262, 3rd, 10.1.3, and 12.2). Thus we can
    4797             :   // transform a source-level var declaration into a (Function) Scope
    4798             :   // declaration, and rewrite the source-level initialization into an assignment
    4799             :   // statement. We use a block to collect multiple assignments.
    4800             :   //
    4801             :   // We mark the block as initializer block because we don't want the
    4802             :   // rewriter to add a '.result' assignment to such a block (to get compliant
    4803             :   // behavior for code such as print(eval('var x = 7')), and for cosmetic
    4804             :   // reasons when pretty-printing. Also, unless an assignment (initialization)
    4805             :   // is inside an initializer block, it is ignored.
    4806             : 
    4807             :   DeclarationParsingResult parsing_result;
    4808    12885390 :   ParseVariableDeclarations(var_context, &parsing_result, names);
    4809    12886315 :   ExpectSemicolon();
    4810    21435879 :   return impl()->BuildInitializationBlock(&parsing_result);
    4811             : }
    4812             : 
    4813             : template <typename Impl>
    4814             : typename ParserBase<Impl>::StatementT
    4815      141813 : ParserBase<Impl>::ParseDebuggerStatement() {
    4816             :   // In ECMA-262 'debugger' is defined as a reserved keyword. In some browser
    4817             :   // contexts this is used as a statement which invokes the debugger as i a
    4818             :   // break point is present.
    4819             :   // DebuggerStatement ::
    4820             :   //   'debugger' ';'
    4821             : 
    4822             :   int pos = peek_position();
    4823             :   Consume(Token::DEBUGGER);
    4824      141817 :   ExpectSemicolon();
    4825      194171 :   return factory()->NewDebuggerStatement(pos);
    4826             : }
    4827             : 
    4828             : template <typename Impl>
    4829             : typename ParserBase<Impl>::StatementT
    4830    20332239 : ParserBase<Impl>::ParseExpressionOrLabelledStatement(
    4831             :     ZonePtrList<const AstRawString>* labels,
    4832             :     ZonePtrList<const AstRawString>* own_labels,
    4833    10445437 :     AllowLabelledFunctionStatement allow_function) {
    4834             :   // ExpressionStatement | LabelledStatement ::
    4835             :   //   Expression ';'
    4836             :   //   Identifier ':' Statement
    4837             :   //
    4838             :   // ExpressionStatement[Yield] :
    4839             :   //   [lookahead notin {{, function, class, let [}] Expression[In, ?Yield] ;
    4840             : 
    4841             :   int pos = peek_position();
    4842             : 
    4843    20332514 :   switch (peek()) {
    4844             :     case Token::FUNCTION:
    4845             :     case Token::LBRACE:
    4846           0 :       UNREACHABLE();  // Always handled by the callers.
    4847             :     case Token::CLASS:
    4848         308 :       ReportUnexpectedToken(Next());
    4849         308 :       return impl()->NullStatement();
    4850             :     case Token::LET: {
    4851             :       Token::Value next_next = PeekAhead();
    4852             :       // "let" followed by either "[", "{" or an identifier means a lexical
    4853             :       // declaration, which should not appear here.
    4854             :       // However, ASI may insert a line break before an identifier or a brace.
    4855        9211 :       if (next_next != Token::LBRACK &&
    4856             :           ((next_next != Token::LBRACE && next_next != Token::IDENTIFIER) ||
    4857         560 :            scanner_->HasLineTerminatorAfterNext())) {
    4858             :         break;
    4859             :       }
    4860         325 :       impl()->ReportMessageAt(scanner()->peek_location(),
    4861             :                               MessageTemplate::kUnexpectedLexicalDeclaration);
    4862         326 :       return impl()->NullStatement();
    4863             :     }
    4864             :     default:
    4865             :       break;
    4866             :   }
    4867             : 
    4868    20331880 :   bool starts_with_identifier = peek_any_identifier();
    4869     9890686 :   ExpressionT expr = ParseExpression();
    4870    20365322 :   if (peek() == Token::COLON && starts_with_identifier &&
    4871             :       impl()->IsIdentifier(expr)) {
    4872             :     // The whole expression was a single identifier, and not, e.g.,
    4873             :     // something starting with an identifier or a parenthesized identifier.
    4874       15714 :     impl()->DeclareLabel(&labels, &own_labels,
    4875             :                          impl()->AsIdentifierExpression(expr));
    4876             :     Consume(Token::COLON);
    4877             :     // ES#sec-labelled-function-declarations Labelled Function Declarations
    4878       37271 :     if (peek() == Token::FUNCTION && is_sloppy(language_mode()) &&
    4879             :         allow_function == kAllowLabelledFunctionStatement) {
    4880         507 :       return ParseFunctionDeclaration();
    4881             :     }
    4882       32079 :     return ParseStatement(labels, own_labels, allow_function);
    4883             :   }
    4884             : 
    4885             :   // If we have an extension, we allow a native function declaration.
    4886             :   // A native function declaration starts with "native function" with
    4887             :   // no line-terminator between the two words.
    4888    20308011 :   if (extension_ != nullptr && peek() == Token::FUNCTION &&
    4889             :       !scanner()->HasLineTerminatorBeforeNext() && impl()->IsNative(expr) &&
    4890        1739 :       !scanner()->literal_contains_escapes()) {
    4891        1734 :     return ParseNativeDeclaration();
    4892             :   }
    4893             : 
    4894             :   // Parsed expression statement, followed by semicolon.
    4895    20297598 :   ExpectSemicolon();
    4896    20702140 :   if (expr->IsFailureExpression()) return impl()->NullStatement();
    4897    19831821 :   return factory()->NewExpressionStatement(expr, pos);
    4898             : }
    4899             : 
    4900             : template <typename Impl>
    4901     3398814 : typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseIfStatement(
    4902     1304531 :     ZonePtrList<const AstRawString>* labels) {
    4903             :   // IfStatement ::
    4904             :   //   'if' '(' Expression ')' Statement ('else' Statement)?
    4905             : 
    4906             :   int pos = peek_position();
    4907             :   Consume(Token::IF);
    4908     3398847 :   Expect(Token::LPAREN);
    4909             :   ExpressionT condition = ParseExpression();
    4910     3399007 :   Expect(Token::RPAREN);
    4911             : 
    4912             :   SourceRange then_range, else_range;
    4913             :   StatementT then_statement = impl()->NullStatement();
    4914             :   {
    4915             :     SourceRangeScope range_scope(scanner(), &then_range);
    4916             :     // Make a copy of {labels} to avoid conflicts with any
    4917             :     // labels that may be applied to the else clause below.
    4918             :     auto labels_copy =
    4919             :         labels == nullptr
    4920             :             ? labels
    4921     3399542 :             : new (zone()) ZonePtrList<const AstRawString>(*labels, zone());
    4922     3398976 :     then_statement = ParseScopedStatement(labels_copy);
    4923             :   }
    4924             : 
    4925             :   StatementT else_statement = impl()->NullStatement();
    4926     3399068 :   if (Check(Token::ELSE)) {
    4927      383727 :     else_statement = ParseScopedStatement(labels);
    4928       57381 :     else_range = SourceRange::ContinuationOf(then_range, end_position());
    4929             :   } else {
    4930      565914 :     else_statement = factory()->EmptyStatement();
    4931             :   }
    4932             :   StatementT stmt =
    4933      623295 :       factory()->NewIfStatement(condition, then_statement, else_statement, pos);
    4934             :   impl()->RecordIfStatementSourceRange(stmt, then_range, else_range);
    4935     3399075 :   return stmt;
    4936             : }
    4937             : 
    4938             : template <typename Impl>
    4939             : typename ParserBase<Impl>::StatementT
    4940      119519 : ParserBase<Impl>::ParseContinueStatement() {
    4941             :   // ContinueStatement ::
    4942             :   //   'continue' Identifier? ';'
    4943             : 
    4944             :   int pos = peek_position();
    4945             :   Consume(Token::CONTINUE);
    4946             :   IdentifierT label = impl()->NullIdentifier();
    4947             :   Token::Value tok = peek();
    4948      106547 :   if (!scanner()->HasLineTerminatorBeforeNext() &&
    4949             :       !Token::IsAutoSemicolon(tok)) {
    4950             :     // ECMA allows "eval" or "arguments" as labels even in strict mode.
    4951             :     label = ParseIdentifier();
    4952             :   }
    4953       13259 :   IterationStatementT target = impl()->LookupContinueTarget(label);
    4954       53361 :   if (impl()->IsNull(target)) {
    4955             :     // Illegal continue statement.
    4956             :     MessageTemplate message = MessageTemplate::kIllegalContinue;
    4957         457 :     BreakableStatementT breakable_target = impl()->LookupBreakTarget(label);
    4958         457 :     if (impl()->IsNull(label)) {
    4959             :       message = MessageTemplate::kNoIterationStatement;
    4960         362 :     } else if (impl()->IsNull(breakable_target)) {
    4961             :       message = MessageTemplate::kUnknownLabel;
    4962             :     }
    4963         457 :     ReportMessage(message, label);
    4964         457 :     return impl()->NullStatement();
    4965             :   }
    4966       52904 :   ExpectSemicolon();
    4967       12803 :   StatementT stmt = factory()->NewContinueStatement(target, pos);
    4968             :   impl()->RecordJumpStatementSourceRange(stmt, end_position());
    4969       52908 :   return stmt;
    4970             : }
    4971             : 
    4972             : template <typename Impl>
    4973      195478 : typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseBreakStatement(
    4974      283435 :     ZonePtrList<const AstRawString>* labels) {
    4975             :   // BreakStatement ::
    4976             :   //   'break' Identifier? ';'
    4977             : 
    4978             :   int pos = peek_position();
    4979             :   Consume(Token::BREAK);
    4980             :   IdentifierT label = impl()->NullIdentifier();
    4981             :   Token::Value tok = peek();
    4982      390740 :   if (!scanner()->HasLineTerminatorBeforeNext() &&
    4983             :       !Token::IsAutoSemicolon(tok)) {
    4984             :     // ECMA allows "eval" or "arguments" as labels even in strict mode.
    4985             :     label = ParseIdentifier();
    4986             :   }
    4987             :   // Parse labeled break statements that target themselves into
    4988             :   // empty statements, e.g. 'l1: l2: l3: break l2;'
    4989       51410 :   if (!impl()->IsNull(label) && impl()->ContainsLabel(labels, label)) {
    4990          99 :     ExpectSemicolon();
    4991          99 :     return factory()->EmptyStatement();
    4992             :   }
    4993       43991 :   BreakableStatementT target = impl()->LookupBreakTarget(label);
    4994      195382 :   if (impl()->IsNull(target)) {
    4995             :     // Illegal break statement.
    4996             :     MessageTemplate message = MessageTemplate::kIllegalBreak;
    4997         133 :     if (!impl()->IsNull(label)) {
    4998             :       message = MessageTemplate::kUnknownLabel;
    4999             :     }
    5000         133 :     ReportMessage(message, label);
    5001         133 :     return impl()->NullStatement();
    5002             :   }
    5003      195249 :   ExpectSemicolon();
    5004       43859 :   StatementT stmt = factory()->NewBreakStatement(target, pos);
    5005             :   impl()->RecordJumpStatementSourceRange(stmt, end_position());
    5006      195259 :   return stmt;
    5007             : }
    5008             : 
    5009             : template <typename Impl>
    5010    12643912 : typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseReturnStatement() {
    5011             :   // ReturnStatement ::
    5012             :   //   'return' [no line terminator] Expression? ';'
    5013             : 
    5014             :   // Consume the return token. It is necessary to do that before
    5015             :   // reporting any errors on it, because of the way errors are
    5016             :   // reported (underlining).
    5017             :   Consume(Token::RETURN);
    5018     3560658 :   Scanner::Location loc = scanner()->location();
    5019             : 
    5020     3560605 :   switch (GetDeclarationScope()->scope_type()) {
    5021             :     case SCRIPT_SCOPE:
    5022             :     case EVAL_SCOPE:
    5023             :     case MODULE_SCOPE:
    5024         103 :       impl()->ReportMessageAt(loc, MessageTemplate::kIllegalReturn);
    5025         103 :       return impl()->NullStatement();
    5026             :     default:
    5027             :       break;
    5028             :   }
    5029             : 
    5030             :   Token::Value tok = peek();
    5031             :   ExpressionT return_value = impl()->NullExpression();
    5032     7120897 :   if (scanner()->HasLineTerminatorBeforeNext() || Token::IsAutoSemicolon(tok)) {
    5033      629730 :     if (IsDerivedConstructor(function_state_->kind())) {
    5034          39 :       ExpressionParsingScope expression_scope(impl());
    5035          15 :       return_value = impl()->ThisExpression();
    5036             :       expression_scope.ValidateExpression();
    5037             :     }
    5038             :   } else {
    5039             :     return_value = ParseExpression();
    5040             :   }
    5041     3560469 :   ExpectSemicolon();
    5042             : 
    5043      981157 :   return_value = impl()->RewriteReturn(return_value, loc.beg_pos);
    5044             :   int continuation_pos = end_position();
    5045             :   StatementT stmt =
    5046     3560594 :       BuildReturnStatement(return_value, loc.beg_pos, continuation_pos);
    5047             :   impl()->RecordJumpStatementSourceRange(stmt, end_position());
    5048     3560529 :   return stmt;
    5049             : }
    5050             : 
    5051             : template <typename Impl>
    5052      101433 : typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseWithStatement(
    5053      240209 :     ZonePtrList<const AstRawString>* labels) {
    5054             :   // WithStatement ::
    5055             :   //   'with' '(' Expression ')' Statement
    5056             : 
    5057             :   Consume(Token::WITH);
    5058             :   int pos = position();
    5059             : 
    5060      101432 :   if (is_strict(language_mode())) {
    5061         701 :     ReportMessage(MessageTemplate::kStrictWith);
    5062         701 :     return impl()->NullStatement();
    5063             :   }
    5064             : 
    5065      100731 :   Expect(Token::LPAREN);
    5066             :   ExpressionT expr = ParseExpression();
    5067      100731 :   Expect(Token::RPAREN);
    5068             : 
    5069             :   Scope* with_scope = NewScope(WITH_SCOPE);
    5070             :   StatementT body = impl()->NullStatement();
    5071             :   {
    5072      100734 :     BlockState block_state(&scope_, with_scope);
    5073      100734 :     with_scope->set_start_position(scanner()->peek_location().beg_pos);
    5074             :     body = ParseStatement(labels, nullptr);
    5075             :     with_scope->set_end_position(end_position());
    5076             :   }
    5077       76846 :   return factory()->NewWithStatement(with_scope, expr, body, pos);
    5078             : }
    5079             : 
    5080             : template <typename Impl>
    5081       17978 : typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseDoWhileStatement(
    5082             :     ZonePtrList<const AstRawString>* labels,
    5083        8130 :     ZonePtrList<const AstRawString>* own_labels) {
    5084             :   // DoStatement ::
    5085             :   //   'do' Statement 'while' '(' Expression ')' ';'
    5086       17978 :   typename FunctionState::LoopScope loop_scope(function_state_);
    5087             : 
    5088             :   auto loop =
    5089        4064 :       factory()->NewDoWhileStatement(labels, own_labels, peek_position());
    5090             :   TargetT target(this, loop);
    5091             : 
    5092             :   SourceRange body_range;
    5093             :   StatementT body = impl()->NullStatement();
    5094             : 
    5095             :   Consume(Token::DO);
    5096             : 
    5097       17980 :   CheckStackOverflow();
    5098             :   {
    5099             :     SourceRangeScope range_scope(scanner(), &body_range);
    5100             :     body = ParseStatement(nullptr, nullptr);
    5101             :   }
    5102       17980 :   Expect(Token::WHILE);
    5103       17980 :   Expect(Token::LPAREN);
    5104             : 
    5105             :   ExpressionT cond = ParseExpression();
    5106       17980 :   Expect(Token::RPAREN);
    5107             : 
    5108             :   // Allow do-statements to be terminated with and without
    5109             :   // semi-colons. This allows code such as 'do;while(0)return' to
    5110             :   // parse, which would not be the case if we had used the
    5111             :   // ExpectSemicolon() functionality here.
    5112             :   Check(Token::SEMICOLON);
    5113             : 
    5114             :   loop->Initialize(cond, body);
    5115             :   impl()->RecordIterationStatementSourceRange(loop, body_range);
    5116             : 
    5117       31893 :   return loop;
    5118             : }
    5119             : 
    5120             : template <typename Impl>
    5121       36802 : typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseWhileStatement(
    5122             :     ZonePtrList<const AstRawString>* labels,
    5123       34166 :     ZonePtrList<const AstRawString>* own_labels) {
    5124             :   // WhileStatement ::
    5125             :   //   'while' '(' Expression ')' Statement
    5126       36802 :   typename FunctionState::LoopScope loop_scope(function_state_);
    5127             : 
    5128       17083 :   auto loop = factory()->NewWhileStatement(labels, own_labels, peek_position());
    5129             :   TargetT target(this, loop);
    5130             : 
    5131             :   SourceRange body_range;
    5132             :   StatementT body = impl()->NullStatement();
    5133             : 
    5134             :   Consume(Token::WHILE);
    5135       36806 :   Expect(Token::LPAREN);
    5136             :   ExpressionT cond = ParseExpression();
    5137       36805 :   Expect(Token::RPAREN);
    5138             :   {
    5139             :     SourceRangeScope range_scope(scanner(), &body_range);
    5140             :     body = ParseStatement(nullptr, nullptr);
    5141             :   }
    5142             : 
    5143             :   loop->Initialize(cond, body);
    5144             :   impl()->RecordIterationStatementSourceRange(loop, body_range);
    5145             : 
    5146       56528 :   return loop;
    5147             : }
    5148             : 
    5149             : template <typename Impl>
    5150      647990 : typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseThrowStatement() {
    5151             :   // ThrowStatement ::
    5152             :   //   'throw' Expression ';'
    5153             : 
    5154             :   Consume(Token::THROW);
    5155             :   int pos = position();
    5156      303932 :   if (scanner()->HasLineTerminatorBeforeNext()) {
    5157         177 :     ReportMessage(MessageTemplate::kNewlineAfterThrow);
    5158         177 :     return impl()->NullStatement();
    5159             :   }
    5160             :   ExpressionT exception = ParseExpression();
    5161      303721 :   ExpectSemicolon();
    5162             : 
    5163             :   StatementT stmt = impl()->NewThrowStatement(exception, pos);
    5164             :   impl()->RecordThrowSourceRange(stmt, end_position());
    5165             : 
    5166      303750 :   return stmt;
    5167             : }
    5168             : 
    5169             : template <typename Impl>
    5170      135136 : typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseSwitchStatement(
    5171     1120938 :     ZonePtrList<const AstRawString>* labels) {
    5172             :   // SwitchStatement ::
    5173             :   //   'switch' '(' Expression ')' '{' CaseClause* '}'
    5174             :   // CaseClause ::
    5175             :   //   'case' Expression ':' StatementList
    5176             :   //   'default' ':' StatementList
    5177             : 
    5178             :   int switch_pos = peek_position();
    5179             : 
    5180             :   Consume(Token::SWITCH);
    5181      135170 :   Expect(Token::LPAREN);
    5182             :   ExpressionT tag = ParseExpression();
    5183      135114 :   Expect(Token::RPAREN);
    5184             : 
    5185             :   auto switch_statement =
    5186       14302 :       factory()->NewSwitchStatement(labels, tag, switch_pos);
    5187             : 
    5188             :   {
    5189      270342 :     BlockState cases_block_state(zone(), &scope_);
    5190             :     scope()->set_start_position(switch_pos);
    5191             :     scope()->SetNonlinear();
    5192             :     TargetT target(this, switch_statement);
    5193             : 
    5194             :     bool default_seen = false;
    5195      135173 :     Expect(Token::LBRACE);
    5196     1481043 :     while (peek() != Token::RBRACE) {
    5197             :       // An empty label indicates the default case.
    5198             :       ExpressionT label = impl()->NullExpression();
    5199       89609 :       StatementListT statements(pointer_buffer());
    5200             :       SourceRange clause_range;
    5201             :       {
    5202             :         SourceRangeScope range_scope(scanner(), &clause_range);
    5203     1212074 :         if (Check(Token::CASE)) {
    5204             :           label = ParseExpression();
    5205             :         } else {
    5206      127025 :           Expect(Token::DEFAULT);
    5207      127022 :           if (default_seen) {
    5208          18 :             ReportMessage(MessageTemplate::kMultipleDefaultsInSwitch);
    5209          18 :             return impl()->NullStatement();
    5210             :           }
    5211             :           default_seen = true;
    5212             :         }
    5213     1212036 :         Expect(Token::COLON);
    5214     6157124 :         while (peek() != Token::CASE && peek() != Token::DEFAULT &&
    5215             :                peek() != Token::RBRACE) {
    5216     1113998 :           StatementT stat = ParseStatementListItem();
    5217     1114065 :           if (impl()->IsNull(stat)) return stat;
    5218     1112850 :           if (stat->IsEmptyStatement()) continue;
    5219      117441 :           statements.Add(stat);
    5220             :         }
    5221             :       }
    5222       88854 :       auto clause = factory()->NewCaseClause(label, statements);
    5223             :       impl()->RecordCaseClauseSourceRange(clause, clause_range);
    5224       88853 :       switch_statement->cases()->Add(clause, zone());
    5225             :     }
    5226      133933 :     Expect(Token::RBRACE);
    5227             : 
    5228             :     int end_pos = end_position();
    5229             :     scope()->set_end_position(end_pos);
    5230             :     impl()->RecordSwitchStatementSourceRange(switch_statement, end_pos);
    5231      133941 :     Scope* switch_scope = scope()->FinalizeBlockScope();
    5232      133940 :     if (switch_scope != nullptr) {
    5233         922 :       return impl()->RewriteSwitchStatement(switch_statement, switch_scope);
    5234             :     }
    5235      119031 :     return switch_statement;
    5236             :   }
    5237             : }
    5238             : 
    5239             : template <typename Impl>
    5240     3857124 : typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseTryStatement() {
    5241             :   // TryStatement ::
    5242             :   //   'try' Block Catch
    5243             :   //   'try' Block Finally
    5244             :   //   'try' Block Catch Finally
    5245             :   //
    5246             :   // Catch ::
    5247             :   //   'catch' '(' Identifier ')' Block
    5248             :   //
    5249             :   // Finally ::
    5250             :   //   'finally' Block
    5251             : 
    5252             :   Consume(Token::TRY);
    5253       96557 :   int pos = position();
    5254             : 
    5255      407242 :   BlockT try_block = ParseBlock(nullptr);
    5256             : 
    5257      407195 :   CatchInfo catch_info(this);
    5258             : 
    5259      445739 :   if (peek() != Token::CATCH && peek() != Token::FINALLY) {
    5260        1015 :     ReportMessage(MessageTemplate::kNoCatchOrFinally);
    5261             :     return impl()->NullStatement();
    5262             :   }
    5263             : 
    5264       95714 :   SourceRange catch_range, finally_range;
    5265             : 
    5266      310379 :   BlockT catch_block = impl()->NullBlock();
    5267             :   {
    5268      406107 :     SourceRangeScope catch_range_scope(scanner(), &catch_range);
    5269      406178 :     if (Check(Token::CATCH)) {
    5270             :       bool has_binding;
    5271             :       has_binding = Check(Token::LPAREN);
    5272             : 
    5273      368532 :       if (has_binding) {
    5274      367240 :         catch_info.scope = NewScope(CATCH_SCOPE);
    5275      367198 :         catch_info.scope->set_start_position(scanner()->location().beg_pos);
    5276             : 
    5277             :         {
    5278      367170 :           BlockState catch_block_state(&scope_, catch_info.scope);
    5279      179328 :           StatementListT catch_statements(pointer_buffer());
    5280             : 
    5281             :           // Create a block scope to hold any lexical declarations created
    5282             :           // as part of destructuring the catch parameter.
    5283             :           {
    5284      367110 :             BlockState catch_variable_block_state(zone(), &scope_);
    5285      734494 :             scope()->set_start_position(position());
    5286             : 
    5287      367252 :             if (peek_any_identifier()) {
    5288      358276 :               IdentifierT identifier = ParseNonRestrictedIdentifier();
    5289      360828 :               RETURN_IF_PARSE_ERROR;
    5290      713497 :               catch_info.variable = impl()->DeclareCatchVariableName(
    5291             :                   catch_info.scope, identifier);
    5292             :             } else {
    5293        8975 :               catch_info.variable = catch_info.scope->DeclareCatchVariableName(
    5294             :                   ast_value_factory()->dot_catch_string());
    5295             : 
    5296        8975 :               auto declaration_it = scope()->declarations()->end();
    5297             : 
    5298             :               VariableDeclarationParsingScope destructuring(
    5299        8975 :                   impl(), VariableMode::kLet, nullptr);
    5300        8975 :               catch_info.pattern = ParseBindingPattern();
    5301             : 
    5302        8975 :               int initializer_position = end_position();
    5303        8975 :               auto declaration_end = scope()->declarations()->end();
    5304        5829 :               for (; declaration_it != declaration_end; ++declaration_it) {
    5305        5829 :                 declaration_it->var()->set_initializer_position(
    5306             :                     initializer_position);
    5307             :               }
    5308             : 
    5309        8975 :               RETURN_IF_PARSE_ERROR;
    5310        5233 :               catch_statements.Add(impl()->RewriteCatchPattern(&catch_info));
    5311             :             }
    5312             : 
    5313      362061 :             Expect(Token::RPAREN);
    5314             : 
    5315      449706 :             BlockT inner_block = ParseBlock(nullptr);
    5316       88462 :             catch_statements.Add(inner_block);
    5317             : 
    5318             :             // Check for `catch(e) { let e; }` and similar errors.
    5319      362089 :             if (!impl()->HasCheckedSyntax()) {
    5320      361302 :               Scope* inner_scope = inner_block->scope();
    5321      361294 :               if (inner_scope != nullptr) {
    5322             :                 const AstRawString* conflict = nullptr;
    5323        1650 :                 if (impl()->IsNull(catch_info.pattern)) {
    5324        1120 :                   const AstRawString* name = catch_info.variable->raw_name();
    5325        1120 :                   if (inner_scope->LookupLocal(name)) conflict = name;
    5326             :                 } else {
    5327         530 :                   conflict = inner_scope->FindVariableDeclaredIn(
    5328             :                       scope(), VariableMode::kVar);
    5329             :                 }
    5330        1650 :                 if (conflict != nullptr) {
    5331         360 :                   impl()->ReportVarRedeclarationIn(conflict, inner_scope);
    5332             :                 }
    5333             :               }
    5334             :             }
    5335             : 
    5336      724127 :             scope()->set_end_position(end_position());
    5337      362081 :             catch_block = factory()->NewBlock(false, catch_statements);
    5338      362073 :             catch_block->set_scope(scope()->FinalizeBlockScope());
    5339      362069 :           }
    5340             :         }
    5341             : 
    5342      362073 :         catch_info.scope->set_end_position(end_position());
    5343             :       } else {
    5344        1292 :         catch_block = ParseBlock(nullptr);
    5345             :       }
    5346       93341 :     }
    5347             :   }
    5348             : 
    5349             :   BlockT finally_block = impl()->NullBlock();
    5350             :   DCHECK(has_error() || peek() == Token::FINALLY ||
    5351             :          !impl()->IsNull(catch_block));
    5352             :   {
    5353      400955 :     SourceRangeScope range_scope(scanner(), &finally_range);
    5354      401096 :     if (Check(Token::FINALLY)) {
    5355       39865 :       finally_block = ParseBlock(nullptr);
    5356       93342 :     }
    5357             :   }
    5358             : 
    5359      401104 :   RETURN_IF_PARSE_ERROR;
    5360             :   return impl()->RewriteTryStatement(try_block, catch_block, catch_range,
    5361             :                                      finally_block, finally_range, catch_info,
    5362       92535 :                                      pos);
    5363             : }
    5364             : 
    5365             : template <typename Impl>
    5366      804043 : typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseForStatement(
    5367             :     ZonePtrList<const AstRawString>* labels,
    5368     2780007 :     ZonePtrList<const AstRawString>* own_labels) {
    5369             :   // Either a standard for loop
    5370             :   //   for (<init>; <cond>; <next>) { ... }
    5371             :   // or a for-each loop
    5372             :   //   for (<each> of|in <iterable>) { ... }
    5373             :   //
    5374             :   // We parse a declaration/expression after the 'for (' and then read the first
    5375             :   // expression/declaration before we know if this is a for or a for-each.
    5376      804043 :   typename FunctionState::LoopScope loop_scope(function_state_);
    5377             : 
    5378             :   int stmt_pos = peek_position();
    5379      804043 :   ForInfo for_info(this);
    5380             : 
    5381             :   Consume(Token::FOR);
    5382      804184 :   Expect(Token::LPAREN);
    5383             : 
    5384     1567726 :   if (peek() == Token::CONST || (peek() == Token::LET && IsNextLetKeyword())) {
    5385             :     // The initializer contains lexical declarations,
    5386             :     // so create an in-between scope.
    5387      500834 :     BlockState for_state(zone(), &scope_);
    5388             :     scope()->set_start_position(position());
    5389             : 
    5390             :     // Also record whether inner functions or evals are found inside
    5391             :     // this loop, as this information is used to simplify the desugaring
    5392             :     // if none are found.
    5393             :     typename FunctionState::FunctionOrEvalRecordingScope recording_scope(
    5394      250419 :         function_state_);
    5395             : 
    5396             :     // Create an inner block scope which will be the parent scope of scopes
    5397             :     // possibly created by ParseVariableDeclarations.
    5398             :     Scope* inner_block_scope = NewScope(BLOCK_SCOPE);
    5399             :     {
    5400             :       BlockState inner_state(&scope_, inner_block_scope);
    5401      250423 :       ParseVariableDeclarations(kForStatement, &for_info.parsing_result,
    5402             :                                 &for_info.bound_names);
    5403             :     }
    5404             :     DCHECK(IsLexicalVariableMode(for_info.parsing_result.descriptor.mode));
    5405      250413 :     for_info.position = position();
    5406             : 
    5407      250413 :     if (CheckInOrOf(&for_info.mode)) {
    5408             :       scope()->set_is_hidden();
    5409             :       return ParseForEachStatementWithDeclarations(
    5410      128002 :           stmt_pos, &for_info, labels, own_labels, inner_block_scope);
    5411             :     }
    5412             : 
    5413      122415 :     Expect(Token::SEMICOLON);
    5414             : 
    5415             :     // Parse the remaining code in the inner block scope since the declaration
    5416             :     // above was parsed there. We'll finalize the unnecessary outer block scope
    5417             :     // after parsing the rest of the loop.
    5418             :     StatementT result = impl()->NullStatement();
    5419      122417 :     inner_block_scope->set_start_position(scope()->start_position());
    5420             :     {
    5421             :       BlockState inner_state(&scope_, inner_block_scope);
    5422             :       StatementT init =
    5423      122418 :           impl()->BuildInitializationBlock(&for_info.parsing_result);
    5424             : 
    5425      122418 :       result = ParseStandardForLoopWithLexicalDeclarations(
    5426             :           stmt_pos, init, &for_info, labels, own_labels);
    5427             :     }
    5428      122400 :     Scope* finalized = scope()->FinalizeBlockScope();
    5429             :     DCHECK_NULL(finalized);
    5430             :     USE(finalized);
    5431      122412 :     return result;
    5432             :   }
    5433             : 
    5434             :   StatementT init = impl()->NullStatement();
    5435      553658 :   if (peek() == Token::VAR) {
    5436      383979 :     ParseVariableDeclarations(kForStatement, &for_info.parsing_result,
    5437             :                               &for_info.bound_names);
    5438             :     DCHECK_EQ(for_info.parsing_result.descriptor.mode, VariableMode::kVar);
    5439      384076 :     for_info.position = scanner()->location().beg_pos;
    5440             : 
    5441      384076 :     if (CheckInOrOf(&for_info.mode)) {
    5442             :       return ParseForEachStatementWithDeclarations(stmt_pos, &for_info, labels,
    5443       34096 :                                                    own_labels, scope());
    5444             :     }
    5445             : 
    5446      195746 :     init = impl()->BuildInitializationBlock(&for_info.parsing_result);
    5447      169678 :   } else if (peek() != Token::SEMICOLON) {
    5448             :     // The initializer does not contain declarations.
    5449             :     int lhs_beg_pos = peek_position();
    5450             :     int lhs_end_pos;
    5451             :     bool is_for_each;
    5452             :     ExpressionT expression;
    5453             :     {
    5454      152852 :       ExpressionParsingScope parsing_scope(impl());
    5455             :       AcceptINScope scope(this, false);
    5456      152854 :       expression = ParseExpressionCoverGrammar();
    5457             :       // Initializer is reference followed by in/of.
    5458             :       lhs_end_pos = end_position();
    5459      152853 :       is_for_each = CheckInOrOf(&for_info.mode);
    5460      152851 :       if (is_for_each) {
    5461      116958 :         if (expression->IsPattern()) {
    5462       24209 :           parsing_scope.ValidatePattern(expression, lhs_beg_pos, lhs_end_pos);
    5463             :         } else {
    5464       92749 :           expression = parsing_scope.ValidateAndRewriteReference(
    5465             :               expression, lhs_beg_pos, lhs_end_pos);
    5466             :         }
    5467             :       } else {
    5468             :         parsing_scope.ValidateExpression();
    5469             :       }
    5470             :     }
    5471             : 
    5472      152855 :     if (is_for_each) {
    5473             :       return ParseForEachStatementWithoutDeclarations(
    5474             :           stmt_pos, expression, lhs_beg_pos, lhs_end_pos, &for_info, labels,
    5475      116961 :           own_labels);
    5476             :     }
    5477             :     // Initializer is just an expression.
    5478       18884 :     init = factory()->NewExpressionStatement(expression, lhs_beg_pos);
    5479             :   }
    5480             : 
    5481      402637 :   Expect(Token::SEMICOLON);
    5482             : 
    5483             :   // Standard 'for' loop, we have parsed the initializer at this point.
    5484      402670 :   ExpressionT cond = impl()->NullExpression();
    5485      402682 :   StatementT next = impl()->NullStatement();
    5486      402687 :   StatementT body = impl()->NullStatement();
    5487             :   ForStatementT loop =
    5488      402687 :       ParseStandardForLoop(stmt_pos, labels, own_labels, &cond, &next, &body);
    5489      405639 :   RETURN_IF_PARSE_ERROR;
    5490      223553 :   loop->Initialize(init, cond, next, body);
    5491      396150 :   return loop;
    5492             : }
    5493             : 
    5494             : template <typename Impl>
    5495             : typename ParserBase<Impl>::StatementT
    5496      162086 : ParserBase<Impl>::ParseForEachStatementWithDeclarations(
    5497             :     int stmt_pos, ForInfo* for_info, ZonePtrList<const AstRawString>* labels,
    5498     1116927 :     ZonePtrList<const AstRawString>* own_labels, Scope* inner_block_scope) {
    5499             :   // Just one declaration followed by in/of.
    5500      324172 :   if (for_info->parsing_result.declarations.size() != 1) {
    5501        6012 :     impl()->ReportMessageAt(for_info->parsing_result.bindings_loc,
    5502             :                             MessageTemplate::kForInOfLoopMultiBindings,
    5503             :                             ForEachStatement::VisitModeString(for_info->mode));
    5504        3006 :     return impl()->NullStatement();
    5505             :   }
    5506      165346 :   if (for_info->parsing_result.first_initializer_loc.IsValid() &&
    5507             :       (is_strict(language_mode()) ||
    5508             :        for_info->mode == ForEachStatement::ITERATE ||
    5509        1443 :        IsLexicalVariableMode(for_info->parsing_result.descriptor.mode) ||
    5510         625 :        !impl()->IsIdentifier(
    5511             :            for_info->parsing_result.declarations[0].pattern))) {
    5512        7158 :     impl()->ReportMessageAt(for_info->parsing_result.first_initializer_loc,
    5513             :                             MessageTemplate::kForInOfLoopInitializer,
    5514             :                             ForEachStatement::VisitModeString(for_info->mode));
    5515        3579 :     return impl()->NullStatement();
    5516             :   }
    5517             : 
    5518       89307 :   BlockT init_block = impl()->RewriteForVarInLegacy(*for_info);
    5519             : 
    5520             :   auto loop = factory()->NewForEachStatement(for_info->mode, labels, own_labels,
    5521       89302 :                                              stmt_pos);
    5522             :   TargetT target(this, loop);
    5523             : 
    5524             :   ExpressionT enumerable = impl()->NullExpression();
    5525      155495 :   if (for_info->mode == ForEachStatement::ITERATE) {
    5526             :     AcceptINScope scope(this, true);
    5527             :     enumerable = ParseAssignmentExpression();
    5528             :   } else {
    5529             :     enumerable = ParseExpression();
    5530             :   }
    5531             : 
    5532      155509 :   Expect(Token::RPAREN);
    5533             : 
    5534      155517 :   if (IsLexicalVariableMode(for_info->parsing_result.descriptor.mode)) {
    5535             :     inner_block_scope->set_start_position(position());
    5536             :   }
    5537             : 
    5538       89313 :   ExpressionT each_variable = impl()->NullExpression();
    5539       89313 :   BlockT body_block = impl()->NullBlock();
    5540             :   {
    5541      155519 :     BlockState block_state(&scope_, inner_block_scope);
    5542             : 
    5543             :     SourceRange body_range;
    5544       89313 :     StatementT body = impl()->NullStatement();
    5545             :     {
    5546             :       SourceRangeScope range_scope(scanner(), &body_range);
    5547       89312 :       body = ParseStatement(nullptr, nullptr);
    5548             :     }
    5549             :     impl()->RecordIterationStatementSourceRange(loop, body_range);
    5550             : 
    5551       89312 :     impl()->DesugarBindingInForEachStatement(for_info, &body_block,
    5552             :                                              &each_variable);
    5553       89309 :     body_block->statements()->Add(body, zone());
    5554             : 
    5555      155514 :     if (IsLexicalVariableMode(for_info->parsing_result.descriptor.mode)) {
    5556             :       scope()->set_end_position(end_position());
    5557      123634 :       body_block->set_scope(scope()->FinalizeBlockScope());
    5558             :     }
    5559             :   }
    5560             : 
    5561       89309 :   loop->Initialize(each_variable, enumerable, body_block);
    5562             : 
    5563       89309 :   init_block = impl()->CreateForEachStatementTDZ(init_block, *for_info);
    5564             : 
    5565             :   // Parsed for-in loop w/ variable declarations.
    5566      155512 :   if (!impl()->IsNull(init_block)) {
    5567       72860 :     init_block->statements()->Add(loop, zone());
    5568      123849 :     if (IsLexicalVariableMode(for_info->parsing_result.descriptor.mode)) {
    5569             :       scope()->set_end_position(end_position());
    5570      123636 :       init_block->set_scope(scope()->FinalizeBlockScope());
    5571             :     }
    5572      123848 :     return init_block;
    5573             :   }
    5574             : 
    5575       15217 :   return loop;
    5576             : }
    5577             : 
    5578             : template <typename Impl>
    5579             : typename ParserBase<Impl>::StatementT
    5580      116958 : ParserBase<Impl>::ParseForEachStatementWithoutDeclarations(
    5581             :     int stmt_pos, ExpressionT expression, int lhs_beg_pos, int lhs_end_pos,
    5582             :     ForInfo* for_info, ZonePtrList<const AstRawString>* labels,
    5583       59800 :     ZonePtrList<const AstRawString>* own_labels) {
    5584             :   auto loop = factory()->NewForEachStatement(for_info->mode, labels, own_labels,
    5585       59799 :                                              stmt_pos);
    5586             :   TargetT target(this, loop);
    5587             : 
    5588             :   ExpressionT enumerable = impl()->NullExpression();
    5589      116959 :   if (for_info->mode == ForEachStatement::ITERATE) {
    5590             :     AcceptINScope scope(this, true);
    5591             :     enumerable = ParseAssignmentExpression();
    5592             :   } else {
    5593             :     enumerable = ParseExpression();
    5594             :   }
    5595             : 
    5596      116959 :   Expect(Token::RPAREN);
    5597             : 
    5598             :   StatementT body = impl()->NullStatement();
    5599             :   SourceRange body_range;
    5600             :   {
    5601             :     SourceRangeScope range_scope(scanner(), &body_range);
    5602             :     body = ParseStatement(nullptr, nullptr);
    5603             :   }
    5604             :   impl()->RecordIterationStatementSourceRange(loop, body_range);
    5605      127392 :   RETURN_IF_PARSE_ERROR;
    5606             :   loop->Initialize(expression, enumerable, body);
    5607       96074 :   return loop;
    5608             : }
    5609             : 
    5610             : template <typename Impl>
    5611             : typename ParserBase<Impl>::StatementT
    5612      122393 : ParserBase<Impl>::ParseStandardForLoopWithLexicalDeclarations(
    5613             :     int stmt_pos, StatementT init, ForInfo* for_info,
    5614             :     ZonePtrList<const AstRawString>* labels,
    5615      662289 :     ZonePtrList<const AstRawString>* own_labels) {
    5616             :   // The condition and the next statement of the for loop must be parsed
    5617             :   // in a new scope.
    5618             :   Scope* inner_scope = NewScope(BLOCK_SCOPE);
    5619             :   ForStatementT loop = impl()->NullStatement();
    5620      122412 :   ExpressionT cond = impl()->NullExpression();
    5621      122413 :   StatementT next = impl()->NullStatement();
    5622      122411 :   StatementT body = impl()->NullStatement();
    5623             :   {
    5624      122411 :     BlockState block_state(&scope_, inner_scope);
    5625      122411 :     scope()->set_start_position(scanner()->location().beg_pos);
    5626      122411 :     loop =
    5627             :         ParseStandardForLoop(stmt_pos, labels, own_labels, &cond, &next, &body);
    5628      126275 :     RETURN_IF_PARSE_ERROR;
    5629             :     scope()->set_end_position(end_position());
    5630             :   }
    5631             : 
    5632             :   scope()->set_end_position(end_position());
    5633      115399 :   if (for_info->bound_names.length() > 0 &&
    5634             :       function_state_->contains_function_or_eval()) {
    5635             :     scope()->set_is_hidden();
    5636             :     return impl()->DesugarLexicalBindingsInForStatement(
    5637       17509 :         loop, init, cond, next, body, inner_scope, *for_info);
    5638             :   } else {
    5639       97561 :     inner_scope = inner_scope->FinalizeBlockScope();
    5640             :     DCHECK_NULL(inner_scope);
    5641             :     USE(inner_scope);
    5642             :   }
    5643             : 
    5644       97568 :   Scope* for_scope = scope()->FinalizeBlockScope();
    5645       97562 :   if (for_scope != nullptr) {
    5646             :     // Rewrite a for statement of the form
    5647             :     //   for (const x = i; c; n) b
    5648             :     //
    5649             :     // into
    5650             :     //
    5651             :     //   {
    5652             :     //     const x = i;
    5653             :     //     for (; c; n) b
    5654             :     //   }
    5655             :     //
    5656             :     DCHECK(!impl()->IsNull(init));
    5657       39140 :     BlockT block = factory()->NewBlock(2, false);
    5658       39138 :     block->statements()->Add(init, zone());
    5659       39137 :     block->statements()->Add(loop, zone());
    5660             :     block->set_scope(for_scope);
    5661       39138 :     loop->Initialize(impl()->NullStatement(), cond, next, body);
    5662       97560 :     return block;
    5663             :   }
    5664             : 
    5665           0 :   loop->Initialize(init, cond, next, body);
    5666           0 :   return loop;
    5667             : }
    5668             : 
    5669             : template <typename Impl>
    5670      524966 : typename ParserBase<Impl>::ForStatementT ParserBase<Impl>::ParseStandardForLoop(
    5671             :     int stmt_pos, ZonePtrList<const AstRawString>* labels,
    5672             :     ZonePtrList<const AstRawString>* own_labels, ExpressionT* cond,
    5673      286930 :     StatementT* next, StatementT* body) {
    5674      286895 :   ForStatementT loop = factory()->NewForStatement(labels, own_labels, stmt_pos);
    5675             :   TargetT target(this, loop);
    5676             : 
    5677      525071 :   if (peek() != Token::SEMICOLON) {
    5678      510908 :     *cond = ParseExpression();
    5679             :   }
    5680      525126 :   Expect(Token::SEMICOLON);
    5681             : 
    5682      525126 :   if (peek() != Token::RPAREN) {
    5683             :     ExpressionT exp = ParseExpression();
    5684      705289 :     *next = factory()->NewExpressionStatement(exp, exp->position());
    5685             :   }
    5686      525125 :   Expect(Token::RPAREN);
    5687             : 
    5688             :   SourceRange body_range;
    5689             :   {
    5690             :     SourceRangeScope range_scope(scanner(), &body_range);
    5691      525101 :     *body = ParseStatement(nullptr, nullptr);
    5692             :   }
    5693             :   impl()->RecordIterationStatementSourceRange(loop, body_range);
    5694             : 
    5695      525101 :   return loop;
    5696             : }
    5697             : 
    5698             : template <typename Impl>
    5699      128558 : typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseForAwaitStatement(
    5700             :     ZonePtrList<const AstRawString>* labels,
    5701     1448226 :     ZonePtrList<const AstRawString>* own_labels) {
    5702             :   // for await '(' ForDeclaration of AssignmentExpression ')'
    5703             :   DCHECK(is_async_function());
    5704      128558 :   typename FunctionState::LoopScope loop_scope(function_state_);
    5705             : 
    5706             :   int stmt_pos = peek_position();
    5707             : 
    5708      128558 :   ForInfo for_info(this);
    5709      128558 :   for_info.mode = ForEachStatement::ITERATE;
    5710             : 
    5711             :   // Create an in-between scope for let-bound iteration variables.
    5712      257116 :   BlockState for_state(zone(), &scope_);
    5713      128558 :   Expect(Token::FOR);
    5714      128558 :   Expect(Token::AWAIT);
    5715      128558 :   Expect(Token::LPAREN);
    5716      128558 :   scope()->set_start_position(scanner()->location().beg_pos);
    5717             :   scope()->set_is_hidden();
    5718             : 
    5719             :   auto loop = factory()->NewForOfStatement(labels, own_labels, stmt_pos,
    5720       34660 :                                            IteratorType::kAsync);
    5721             :   // Two suspends: one for next() and one for return()
    5722      128558 :   function_state_->AddSuspend();
    5723      128558 :   function_state_->AddSuspend();
    5724             : 
    5725             :   TargetT target(this, loop);
    5726             : 
    5727       34660 :   ExpressionT each_variable = impl()->NullExpression();
    5728             : 
    5729             :   bool has_declarations = false;
    5730             :   Scope* inner_block_scope = NewScope(BLOCK_SCOPE);
    5731             : 
    5732      342244 :   if (peek() == Token::VAR || peek() == Token::CONST ||
    5733       33578 :       (peek() == Token::LET && IsNextLetKeyword())) {
    5734             :     // The initializer contains declarations
    5735             :     // 'for' 'await' '(' ForDeclaration 'of' AssignmentExpression ')'
    5736             :     //     Statement
    5737             :     // 'for' 'await' '(' 'var' ForBinding 'of' AssignmentExpression ')'
    5738             :     //     Statement
    5739             :     has_declarations = true;
    5740             : 
    5741             :     {
    5742             :       BlockState inner_state(&scope_, inner_block_scope);
    5743       88791 :       ParseVariableDeclarations(kForStatement, &for_info.parsing_result,
    5744             :                                 &for_info.bound_names);
    5745             :     }
    5746       88791 :     for_info.position = scanner()->location().beg_pos;
    5747             : 
    5748             :     // Only a single declaration is allowed in for-await-of loops
    5749      177582 :     if (for_info.parsing_result.declarations.size() != 1) {
    5750       15760 :       impl()->ReportMessageAt(for_info.parsing_result.bindings_loc,
    5751             :                               MessageTemplate::kForInOfLoopMultiBindings,
    5752             :                               "for-await-of");
    5753       15760 :       return impl()->NullStatement();
    5754             :     }
    5755             : 
    5756             :     // for-await-of's declarations do not permit initializers.
    5757       73031 :     if (for_info.parsing_result.first_initializer_loc.IsValid()) {
    5758       14720 :       impl()->ReportMessageAt(for_info.parsing_result.first_initializer_loc,
    5759             :                               MessageTemplate::kForInOfLoopInitializer,
    5760             :                               "for-await-of");
    5761       14720 :       return impl()->NullStatement();
    5762             :     }
    5763             :   } else {
    5764             :     // The initializer does not contain declarations.
    5765             :     // 'for' 'await' '(' LeftHandSideExpression 'of' AssignmentExpression ')'
    5766             :     //     Statement
    5767             :     int lhs_beg_pos = peek_position();
    5768             :     BlockState inner_state(&scope_, inner_block_scope);
    5769       39767 :     ExpressionParsingScope parsing_scope(impl());
    5770       12245 :     ExpressionT lhs = each_variable = ParseLeftHandSideExpression();
    5771             :     int lhs_end_pos = end_position();
    5772             : 
    5773       39767 :     if (lhs->IsPattern()) {
    5774       28070 :       parsing_scope.ValidatePattern(lhs, lhs_beg_pos, lhs_end_pos);
    5775             :     } else {
    5776       11697 :       each_variable = parsing_scope.ValidateAndRewriteReference(
    5777             :           lhs, lhs_beg_pos, lhs_end_pos);
    5778             :     }
    5779             :   }
    5780             : 
    5781      196156 :   ExpectContextualKeyword(ast_value_factory()->of_string());
    5782             : 
    5783             :   const bool kAllowIn = true;
    5784             :   ExpressionT iterable = impl()->NullExpression();
    5785             : 
    5786             :   {
    5787             :     AcceptINScope scope(this, kAllowIn);
    5788             :     iterable = ParseAssignmentExpression();
    5789             :   }
    5790             : 
    5791       98078 :   Expect(Token::RPAREN);
    5792             : 
    5793       26980 :   StatementT body = impl()->NullStatement();
    5794             :   {
    5795             :     BlockState block_state(&scope_, inner_block_scope);
    5796       98078 :     scope()->set_start_position(scanner()->location().beg_pos);
    5797             : 
    5798             :     SourceRange body_range;
    5799             :     {
    5800             :       SourceRangeScope range_scope(scanner(), &body_range);
    5801       26979 :       body = ParseStatement(nullptr, nullptr);
    5802             :       scope()->set_end_position(end_position());
    5803             :     }
    5804             :     impl()->RecordIterationStatementSourceRange(loop, body_range);
    5805             : 
    5806       98077 :     if (has_declarations) {
    5807       14734 :       BlockT body_block = impl()->NullBlock();
    5808       14734 :       impl()->DesugarBindingInForEachStatement(&for_info, &body_block,
    5809             :                                                &each_variable);
    5810       14735 :       body_block->statements()->Add(body, zone());
    5811       58311 :       body_block->set_scope(scope()->FinalizeBlockScope());
    5812       14735 :       body = body_block;
    5813             :     } else {
    5814       39767 :       Scope* block_scope = scope()->FinalizeBlockScope();
    5815             :       DCHECK_NULL(block_scope);
    5816             :       USE(block_scope);
    5817             :     }
    5818             :   }
    5819             : 
    5820       26980 :   loop->Initialize(each_variable, iterable, body);
    5821             : 
    5822       98078 :   if (!has_declarations) {
    5823       39767 :     Scope* for_scope = scope()->FinalizeBlockScope();
    5824             :     DCHECK_NULL(for_scope);
    5825             :     USE(for_scope);
    5826       27522 :     return loop;
    5827             :   }
    5828             : 
    5829             :   BlockT init_block =
    5830       14735 :       impl()->CreateForEachStatementTDZ(impl()->NullBlock(), for_info);
    5831             : 
    5832             :   scope()->set_end_position(end_position());
    5833       58311 :   Scope* for_scope = scope()->FinalizeBlockScope();
    5834             :   // Parsed for-in loop w/ variable declarations.
    5835       58311 :   if (!impl()->IsNull(init_block)) {
    5836       11728 :     init_block->statements()->Add(loop, zone());
    5837             :     init_block->set_scope(for_scope);
    5838       46516 :     return init_block;
    5839             :   }
    5840             :   DCHECK_NULL(for_scope);
    5841        8788 :   return loop;
    5842             : }
    5843             : 
    5844             : template <typename Impl>
    5845      434011 : void ParserBase<Impl>::CheckClassMethodName(IdentifierT name,
    5846             :                                             ParsePropertyKind type,
    5847             :                                             ParseFunctionFlags flags,
    5848             :                                             bool is_static,
    5849      434011 :                                             bool* has_seen_constructor) {
    5850             :   DCHECK(type == ParsePropertyKind::kMethod || IsAccessor(type));
    5851             : 
    5852      434011 :   AstValueFactory* avf = ast_value_factory();
    5853             : 
    5854      434011 :   if (is_static) {
    5855       37993 :     if (impl()->IdentifierEquals(name, avf->prototype_string())) {
    5856        1094 :       ReportMessage(MessageTemplate::kStaticPrototype);
    5857        1094 :       return;
    5858             :     }
    5859      396018 :   } else if (impl()->IdentifierEquals(name,
    5860             :                                       avf->private_constructor_string())) {
    5861         960 :     ReportMessage(MessageTemplate::kConstructorIsPrivate);
    5862         960 :     return;
    5863      395058 :   } else if (impl()->IdentifierEquals(name, avf->constructor_string())) {
    5864       21654 :     if (flags != ParseFunctionFlag::kIsNormal || IsAccessor(type)) {
    5865             :       MessageTemplate msg = (flags & ParseFunctionFlag::kIsGenerator) != 0
    5866             :                                 ? MessageTemplate::kConstructorIsGenerator
    5867             :                                 : (flags & ParseFunctionFlag::kIsAsync) != 0
    5868             :                                       ? MessageTemplate::kConstructorIsAsync
    5869        1690 :                                       : MessageTemplate::kConstructorIsAccessor;
    5870        1008 :       ReportMessage(msg);
    5871        1008 :       return;
    5872             :     }
    5873       20646 :     if (*has_seen_constructor) {
    5874          98 :       ReportMessage(MessageTemplate::kDuplicateConstructor);
    5875          98 :       return;
    5876             :     }
    5877       20548 :     *has_seen_constructor = true;
    5878       20548 :     return;
    5879             :   }
    5880             : }
    5881             : 
    5882             : template <typename Impl>
    5883       91737 : void ParserBase<Impl>::CheckClassFieldName(IdentifierT name, bool is_static) {
    5884      128621 :   AstValueFactory* avf = ast_value_factory();
    5885      128787 :   if (is_static && impl()->IdentifierEquals(name, avf->prototype_string())) {
    5886         166 :     ReportMessage(MessageTemplate::kStaticPrototype);
    5887          86 :     return;
    5888             :   }
    5889             : 
    5890      182650 :   if (impl()->IdentifierEquals(name, avf->constructor_string()) ||
    5891             :       impl()->IdentifierEquals(name, avf->private_constructor_string())) {
    5892        1132 :     ReportMessage(MessageTemplate::kConstructorClassField);
    5893         572 :     return;
    5894             :   }
    5895             : }
    5896             : 
    5897             : #undef RETURN_IF_PARSE_ERROR
    5898             : 
    5899             : }  // namespace internal
    5900             : }  // namespace v8
    5901             : 
    5902             : #endif  // V8_PARSING_PARSER_BASE_H_

Generated by: LCOV version 1.10