LCOV - code coverage report
Current view: top level - src/parsing - parser-base.h (source / functions) Hit Total Coverage
Test: app.info Lines: 1988 2021 98.4 %
Date: 2017-04-26 Functions: 289 291 99.3 %

          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 "src/ast/ast.h"
       9             : #include "src/ast/scopes.h"
      10             : #include "src/bailout-reason.h"
      11             : #include "src/base/hashmap.h"
      12             : #include "src/counters.h"
      13             : #include "src/globals.h"
      14             : #include "src/messages.h"
      15             : #include "src/parsing/expression-classifier.h"
      16             : #include "src/parsing/func-name-inferrer.h"
      17             : #include "src/parsing/scanner.h"
      18             : #include "src/parsing/token.h"
      19             : 
      20             : namespace v8 {
      21             : namespace internal {
      22             : 
      23             : class PreParsedScopeData;
      24             : 
      25             : enum FunctionNameValidity {
      26             :   kFunctionNameIsStrictReserved,
      27             :   kSkipFunctionNameCheck,
      28             :   kFunctionNameValidityUnknown
      29             : };
      30             : 
      31             : enum AllowLabelledFunctionStatement {
      32             :   kAllowLabelledFunctionStatement,
      33             :   kDisallowLabelledFunctionStatement,
      34             : };
      35             : 
      36             : enum class ParseFunctionFlags {
      37             :   kIsNormal = 0,
      38             :   kIsGenerator = 1,
      39             :   kIsAsync = 2,
      40             :   kIsDefault = 4
      41             : };
      42             : 
      43             : static inline ParseFunctionFlags operator|(ParseFunctionFlags lhs,
      44             :                                            ParseFunctionFlags rhs) {
      45             :   typedef unsigned char T;
      46             :   return static_cast<ParseFunctionFlags>(static_cast<T>(lhs) |
      47             :                                          static_cast<T>(rhs));
      48             : }
      49             : 
      50             : static inline ParseFunctionFlags& operator|=(ParseFunctionFlags& lhs,
      51             :                                              const ParseFunctionFlags& rhs) {
      52             :   lhs = lhs | rhs;
      53             :   return lhs;
      54             : }
      55             : 
      56             : static inline bool operator&(ParseFunctionFlags bitfield,
      57             :                              ParseFunctionFlags mask) {
      58             :   typedef unsigned char T;
      59     2067247 :   return static_cast<T>(bitfield) & static_cast<T>(mask);
      60             : }
      61             : 
      62             : struct FormalParametersBase {
      63     8711014 :   explicit FormalParametersBase(DeclarationScope* scope) : scope(scope) {}
      64             : 
      65             :   int num_parameters() const {
      66             :     // Don't include the rest parameter into the function's formal parameter
      67             :     // count (esp. the SharedFunctionInfo::internal_formal_parameter_count,
      68             :     // which says whether we need to create an arguments adaptor frame).
      69     8167550 :     return arity - has_rest;
      70             :   }
      71             : 
      72    11550279 :   void UpdateArityAndFunctionLength(bool is_optional, bool is_rest) {
      73    11550279 :     if (!is_optional && !is_rest && function_length == arity) {
      74    11481403 :       ++function_length;
      75             :     }
      76    11550279 :     ++arity;
      77    11550279 :   }
      78             : 
      79             :   DeclarationScope* scope;
      80             :   bool has_rest = false;
      81             :   bool is_simple = true;
      82             :   int function_length = 0;
      83             :   int arity = 0;
      84             : };
      85             : 
      86             : 
      87             : // ----------------------------------------------------------------------------
      88             : // The CHECK_OK macro is a convenient macro to enforce error
      89             : // handling for functions that may fail (by returning !*ok).
      90             : //
      91             : // CAUTION: This macro appends extra statements after a call,
      92             : // thus it must never be used where only a single statement
      93             : // is correct (e.g. an if statement branch w/o braces)!
      94             : 
      95             : #define CHECK_OK_CUSTOM(x, ...) ok);       \
      96             :   if (!*ok) return impl()->x(__VA_ARGS__); \
      97             :   ((void)0
      98             : #define DUMMY )  // to make indentation work
      99             : #undef DUMMY
     100             : 
     101             : // Used in functions where the return type is ExpressionT.
     102             : #define CHECK_OK CHECK_OK_CUSTOM(EmptyExpression)
     103             : 
     104             : #define CHECK_OK_VOID ok); \
     105             :   if (!*ok) return;        \
     106             :   ((void)0
     107             : #define DUMMY )  // to make indentation work
     108             : #undef DUMMY
     109             : 
     110             : // Common base class template shared between parser and pre-parser.
     111             : // The Impl parameter is the actual class of the parser/pre-parser,
     112             : // following the Curiously Recurring Template Pattern (CRTP).
     113             : // The structure of the parser objects is roughly the following:
     114             : //
     115             : //   // A structure template containing type definitions, needed to
     116             : //   // avoid a cyclic dependency.
     117             : //   template <typename Impl>
     118             : //   struct ParserTypes;
     119             : //
     120             : //   // The parser base object, which should just implement pure
     121             : //   // parser behavior.  The Impl parameter is the actual derived
     122             : //   // class (according to CRTP), which implements impure parser
     123             : //   // behavior.
     124             : //   template <typename Impl>
     125             : //   class ParserBase { ... };
     126             : //
     127             : //   // And then, for each parser variant (e.g., parser, preparser, etc):
     128             : //   class Parser;
     129             : //
     130             : //   template <>
     131             : //   class ParserTypes<Parser> { ... };
     132             : //
     133             : //   class Parser : public ParserBase<Parser> { ... };
     134             : //
     135             : // The parser base object implements pure parsing, according to the
     136             : // language grammar.  Different parser implementations may exhibit
     137             : // different parser-driven behavior that is not considered as pure
     138             : // parsing, e.g., early error detection and reporting, AST generation, etc.
     139             : 
     140             : // The ParserTypes structure encapsulates the differences in the
     141             : // types used in parsing methods.  E.g., Parser methods use Expression*
     142             : // and PreParser methods use PreParserExpression.  For any given parser
     143             : // implementation class Impl, it is expected to contain the following typedefs:
     144             : //
     145             : // template <>
     146             : // struct ParserTypes<Impl> {
     147             : //   // Synonyms for ParserBase<Impl> and Impl, respectively.
     148             : //   typedef Base;
     149             : //   typedef Impl;
     150             : //   // TODO(nikolaos): this one will probably go away, as it is
     151             : //   // not related to pure parsing.
     152             : //   typedef Variable;
     153             : //   // Return types for traversing functions.
     154             : //   typedef Identifier;
     155             : //   typedef Expression;
     156             : //   typedef FunctionLiteral;
     157             : //   typedef ObjectLiteralProperty;
     158             : //   typedef ClassLiteralProperty;
     159             : //   typedef ExpressionList;
     160             : //   typedef ObjectPropertyList;
     161             : //   typedef ClassPropertyList;
     162             : //   typedef FormalParameters;
     163             : //   typedef Statement;
     164             : //   typedef StatementList;
     165             : //   typedef Block;
     166             : //   typedef BreakableStatement;
     167             : //   typedef IterationStatement;
     168             : //   // For constructing objects returned by the traversing functions.
     169             : //   typedef Factory;
     170             : //   // For other implementation-specific tasks.
     171             : //   typedef Target;
     172             : //   typedef TargetScope;
     173             : // };
     174             : 
     175             : template <typename Impl>
     176             : struct ParserTypes;
     177             : 
     178             : template <typename Impl>
     179             : class ParserBase {
     180             :  public:
     181             :   // Shorten type names defined by ParserTypes<Impl>.
     182             :   typedef ParserTypes<Impl> Types;
     183             :   typedef typename Types::Identifier IdentifierT;
     184             :   typedef typename Types::Expression ExpressionT;
     185             :   typedef typename Types::FunctionLiteral FunctionLiteralT;
     186             :   typedef typename Types::ObjectLiteralProperty ObjectLiteralPropertyT;
     187             :   typedef typename Types::ClassLiteralProperty ClassLiteralPropertyT;
     188             :   typedef typename Types::Suspend SuspendExpressionT;
     189             :   typedef typename Types::ExpressionList ExpressionListT;
     190             :   typedef typename Types::FormalParameters FormalParametersT;
     191             :   typedef typename Types::Statement StatementT;
     192             :   typedef typename Types::StatementList StatementListT;
     193             :   typedef typename Types::Block BlockT;
     194             :   typedef typename v8::internal::ExpressionClassifier<Types>
     195             :       ExpressionClassifier;
     196             : 
     197             :   // All implementation-specific methods must be called through this.
     198    42771457 :   Impl* impl() { return static_cast<Impl*>(this); }
     199             :   const Impl* impl() const { return static_cast<const Impl*>(this); }
     200             : 
     201             :   ParserBase(Zone* zone, Scanner* scanner, uintptr_t stack_limit,
     202             :              v8::Extension* extension, AstValueFactory* ast_value_factory,
     203             :              RuntimeCallStats* runtime_call_stats,
     204             :              PreParsedScopeData* preparsed_scope_data,
     205             :              bool parsing_on_main_thread = true)
     206             :       : scope_(nullptr),
     207             :         original_scope_(nullptr),
     208             :         function_state_(nullptr),
     209             :         extension_(extension),
     210             :         fni_(nullptr),
     211             :         ast_value_factory_(ast_value_factory),
     212             :         ast_node_factory_(ast_value_factory),
     213             :         runtime_call_stats_(runtime_call_stats),
     214             :         parsing_on_main_thread_(parsing_on_main_thread),
     215             :         parsing_module_(false),
     216             :         stack_limit_(stack_limit),
     217             :         preparsed_scope_data_(preparsed_scope_data),
     218             :         zone_(zone),
     219             :         classifier_(nullptr),
     220             :         scanner_(scanner),
     221             :         stack_overflow_(false),
     222             :         default_eager_compile_hint_(FunctionLiteral::kShouldLazyCompile),
     223             :         function_literal_id_(0),
     224             :         allow_natives_(false),
     225             :         allow_tailcalls_(false),
     226             :         allow_harmony_do_expressions_(false),
     227             :         allow_harmony_function_sent_(false),
     228             :         allow_harmony_restrictive_generators_(false),
     229             :         allow_harmony_trailing_commas_(false),
     230             :         allow_harmony_class_fields_(false),
     231             :         allow_harmony_object_rest_spread_(false),
     232             :         allow_harmony_dynamic_import_(false),
     233             :         allow_harmony_async_iteration_(false),
     234     7955088 :         allow_harmony_template_escapes_(false) {}
     235             : 
     236             : #define ALLOW_ACCESSORS(name)                           \
     237             :   bool allow_##name() const { return allow_##name##_; } \
     238             :   void set_allow_##name(bool allow) { allow_##name##_ = allow; }
     239             : 
     240     3977543 :   ALLOW_ACCESSORS(natives);
     241     3977543 :   ALLOW_ACCESSORS(tailcalls);
     242     3977543 :   ALLOW_ACCESSORS(harmony_do_expressions);
     243     3977543 :   ALLOW_ACCESSORS(harmony_function_sent);
     244     3571936 :   ALLOW_ACCESSORS(harmony_restrictive_generators);
     245     3977543 :   ALLOW_ACCESSORS(harmony_trailing_commas);
     246     3977543 :   ALLOW_ACCESSORS(harmony_class_fields);
     247     3977543 :   ALLOW_ACCESSORS(harmony_object_rest_spread);
     248     3977543 :   ALLOW_ACCESSORS(harmony_dynamic_import);
     249     3977543 :   ALLOW_ACCESSORS(harmony_async_iteration);
     250     3977543 :   ALLOW_ACCESSORS(harmony_template_escapes);
     251             : 
     252             : #undef ALLOW_ACCESSORS
     253             : 
     254             :   uintptr_t stack_limit() const { return stack_limit_; }
     255             : 
     256         160 :   void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; }
     257             : 
     258             :   void set_default_eager_compile_hint(
     259             :       FunctionLiteral::EagerCompileHint eager_compile_hint) {
     260     3571936 :     default_eager_compile_hint_ = eager_compile_hint;
     261             :   }
     262             : 
     263             :   FunctionLiteral::EagerCompileHint default_eager_compile_hint() const {
     264             :     return default_eager_compile_hint_;
     265             :   }
     266             : 
     267     8815618 :   int GetNextFunctionLiteralId() { return ++function_literal_id_; }
     268             :   int GetLastFunctionLiteralId() const { return function_literal_id_; }
     269             : 
     270     2688944 :   void SkipFunctionLiterals(int delta) { function_literal_id_ += delta; }
     271             : 
     272     5002100 :   void ResetFunctionLiteralId() { function_literal_id_ = 0; }
     273             : 
     274    39601251 :   Zone* zone() const { return zone_; }
     275             : 
     276             :  protected:
     277             :   friend class v8::internal::ExpressionClassifier<ParserTypes<Impl>>;
     278             : 
     279             :   enum AllowRestrictedIdentifiers {
     280             :     kAllowRestrictedIdentifiers,
     281             :     kDontAllowRestrictedIdentifiers
     282             :   };
     283             : 
     284             :   enum LazyParsingResult { kLazyParsingComplete, kLazyParsingAborted };
     285             : 
     286             :   enum VariableDeclarationContext {
     287             :     kStatementListItem,
     288             :     kStatement,
     289             :     kForStatement
     290             :   };
     291             : 
     292             :   enum class FunctionBodyType { kNormal, kSingleExpression };
     293             : 
     294             :   class ClassLiteralChecker;
     295             :   class ObjectLiteralChecker;
     296             : 
     297             :   // ---------------------------------------------------------------------------
     298             :   // BlockState and FunctionState implement the parser's scope stack.
     299             :   // The parser's current scope is in scope_. BlockState and FunctionState
     300             :   // constructors push on the scope stack and the destructors pop. They are also
     301             :   // used to hold the parser's per-funcion state.
     302             :   class BlockState BASE_EMBEDDED {
     303             :    public:
     304             :     BlockState(Scope** scope_stack, Scope* scope)
     305    33547169 :         : scope_stack_(scope_stack), outer_scope_(*scope_stack) {
     306    33547169 :       *scope_stack_ = scope;
     307             :     }
     308             : 
     309     9560393 :     BlockState(Zone* zone, Scope** scope_stack)
     310             :         : BlockState(scope_stack,
     311    19120786 :                      new (zone) Scope(zone, *scope_stack, BLOCK_SCOPE)) {}
     312             : 
     313    33142428 :     ~BlockState() { *scope_stack_ = outer_scope_; }
     314             : 
     315             :    private:
     316             :     Scope** const scope_stack_;
     317             :     Scope* const outer_scope_;
     318             :   };
     319             : 
     320             :   struct DestructuringAssignment {
     321             :    public:
     322       92429 :     DestructuringAssignment(ExpressionT expression, Scope* scope)
     323       92429 :         : assignment(expression), scope(scope) {}
     324             : 
     325             :     ExpressionT assignment;
     326             :     Scope* scope;
     327             :   };
     328             : 
     329             :   class TailCallExpressionList {
     330             :    public:
     331             :     explicit TailCallExpressionList(Zone* zone)
     332    26569084 :         : zone_(zone), expressions_(0, zone), has_explicit_tail_calls_(false) {}
     333             : 
     334     6680620 :     const ZoneList<ExpressionT>& expressions() const { return expressions_; }
     335             :     const Scanner::Location& location() const { return loc_; }
     336             : 
     337             :     bool has_explicit_tail_calls() const { return has_explicit_tail_calls_; }
     338             : 
     339      809506 :     void Swap(TailCallExpressionList& other) {
     340             :       expressions_.Swap(&other.expressions_);
     341             :       std::swap(loc_, other.loc_);
     342             :       std::swap(has_explicit_tail_calls_, other.has_explicit_tail_calls_);
     343      809506 :     }
     344             : 
     345             :     void AddImplicitTailCall(ExpressionT expr) {
     346       11779 :       expressions_.Add(expr, zone_);
     347             :     }
     348             : 
     349      283653 :     void Append(const TailCallExpressionList& other) {
     350      283653 :       if (!has_explicit_tail_calls()) {
     351      283653 :         loc_ = other.loc_;
     352      283653 :         has_explicit_tail_calls_ = other.has_explicit_tail_calls_;
     353             :       }
     354      283653 :       expressions_.AddAll(other.expressions_, zone_);
     355      283653 :     }
     356             : 
     357             :    private:
     358             :     Zone* zone_;
     359             :     ZoneList<ExpressionT> expressions_;
     360             :     Scanner::Location loc_;
     361             :     bool has_explicit_tail_calls_;
     362             :   };
     363             : 
     364             :   // Defines whether tail call expressions are allowed or not.
     365             :   enum class ReturnExprContext {
     366             :     // We are inside return statement which is allowed to contain tail call
     367             :     // expressions. Tail call expressions are allowed.
     368             :     kInsideValidReturnStatement,
     369             : 
     370             :     // We are inside a block in which tail call expressions are allowed but
     371             :     // not yet inside a return statement.
     372             :     kInsideValidBlock,
     373             : 
     374             :     // Tail call expressions are not allowed in the following blocks.
     375             :     kInsideTryBlock,
     376             :     kInsideForInOfBody,
     377             :   };
     378             : 
     379             :   class FunctionState final : public BlockState {
     380             :    public:
     381             :     FunctionState(FunctionState** function_state_stack, Scope** scope_stack,
     382             :                   DeclarationScope* scope);
     383             :     ~FunctionState();
     384             : 
     385   118189120 :     DeclarationScope* scope() const { return scope_->AsDeclarationScope(); }
     386             : 
     387     1356551 :     void AddProperty() { expected_property_count_++; }
     388             :     int expected_property_count() { return expected_property_count_; }
     389             : 
     390   233590745 :     FunctionKind kind() const { return scope()->function_kind(); }
     391             :     FunctionState* outer() const { return outer_function_state_; }
     392             : 
     393      413958 :     typename Types::Variable* generator_object_variable() const {
     394      140615 :       return scope()->generator_object_var();
     395             :     }
     396             : 
     397      669860 :     typename Types::Variable* promise_variable() const {
     398      669860 :       return scope()->promise_var();
     399             :     }
     400             : 
     401             :     void RewindDestructuringAssignments(int pos) {
     402             :       destructuring_assignments_to_rewrite_.Rewind(pos);
     403             :     }
     404             : 
     405             :     void SetDestructuringAssignmentsScope(int pos, Scope* scope) {
     406      690451 :       for (int i = pos; i < destructuring_assignments_to_rewrite_.length();
     407             :            ++i) {
     408      692765 :         destructuring_assignments_to_rewrite_[i].scope = scope;
     409             :       }
     410             :     }
     411             : 
     412             :     const ZoneList<DestructuringAssignment>&
     413     8643199 :         destructuring_assignments_to_rewrite() const {
     414     8643199 :       return destructuring_assignments_to_rewrite_;
     415             :     }
     416             : 
     417     6680620 :     TailCallExpressionList& tail_call_expressions() {
     418     6680620 :       return tail_call_expressions_;
     419             :     }
     420       12488 :     void AddImplicitTailCallExpression(ExpressionT expression) {
     421       12488 :       if (return_expr_context() ==
     422             :           ReturnExprContext::kInsideValidReturnStatement) {
     423             :         tail_call_expressions_.AddImplicitTailCall(expression);
     424             :       }
     425        4031 :     }
     426             : 
     427   304421527 :     ZoneList<typename ExpressionClassifier::Error>* GetReportedErrorList() {
     428   304421527 :       return &reported_errors_;
     429             :     }
     430             : 
     431             :     ReturnExprContext return_expr_context() const {
     432             :       return return_expr_context_;
     433             :     }
     434             :     void set_return_expr_context(ReturnExprContext context) {
     435    15739038 :       return_expr_context_ = context;
     436             :     }
     437             : 
     438   457279739 :     ZoneList<ExpressionT>* non_patterns_to_rewrite() {
     439   457279739 :       return &non_patterns_to_rewrite_;
     440             :     }
     441             : 
     442             :     bool next_function_is_likely_called() const {
     443             :       return next_function_is_likely_called_;
     444             :     }
     445             : 
     446             :     bool previous_function_was_likely_called() const {
     447             :       return previous_function_was_likely_called_;
     448             :     }
     449             : 
     450             :     void set_next_function_is_likely_called() {
     451      965864 :       next_function_is_likely_called_ = true;
     452             :     }
     453             : 
     454     9243676 :     void RecordFunctionOrEvalCall() { contains_function_or_eval_ = true; }
     455             :     bool contains_function_or_eval() const {
     456             :       return contains_function_or_eval_;
     457             :     }
     458             : 
     459             :     class FunctionOrEvalRecordingScope {
     460             :      public:
     461             :       explicit FunctionOrEvalRecordingScope(FunctionState* state)
     462             :           : state_(state) {
     463     1271511 :         prev_value_ = state->contains_function_or_eval_;
     464     1271511 :         state->contains_function_or_eval_ = false;
     465             :       }
     466             :       ~FunctionOrEvalRecordingScope() {
     467     1271511 :         bool found = state_->contains_function_or_eval_;
     468     1271511 :         if (!found) {
     469     1167039 :           state_->contains_function_or_eval_ = prev_value_;
     470             :         }
     471             :       }
     472             : 
     473             :      private:
     474             :       FunctionState* state_;
     475             :       bool prev_value_;
     476             :     };
     477             : 
     478             :    private:
     479       92429 :     void AddDestructuringAssignment(DestructuringAssignment pair) {
     480       92429 :       destructuring_assignments_to_rewrite_.Add(pair, scope_->zone());
     481       92429 :     }
     482             : 
     483       19210 :     void AddNonPatternForRewriting(ExpressionT expr, bool* ok) {
     484       19210 :       non_patterns_to_rewrite_.Add(expr, scope_->zone());
     485       19210 :       if (non_patterns_to_rewrite_.length() >=
     486             :           std::numeric_limits<uint16_t>::max())
     487           0 :         *ok = false;
     488       19210 :     }
     489             : 
     490             :     // Properties count estimation.
     491             :     int expected_property_count_;
     492             : 
     493             :     FunctionState** function_state_stack_;
     494             :     FunctionState* outer_function_state_;
     495             :     DeclarationScope* scope_;
     496             : 
     497             :     ZoneList<DestructuringAssignment> destructuring_assignments_to_rewrite_;
     498             :     TailCallExpressionList tail_call_expressions_;
     499             :     ReturnExprContext return_expr_context_;
     500             :     ZoneList<ExpressionT> non_patterns_to_rewrite_;
     501             : 
     502             :     ZoneList<typename ExpressionClassifier::Error> reported_errors_;
     503             : 
     504             :     // Record whether the next (=== immediately following) function literal is
     505             :     // preceded by a parenthesis / exclamation mark. Also record the previous
     506             :     // state.
     507             :     // These are managed by the FunctionState constructor; the caller may only
     508             :     // call set_next_function_is_likely_called.
     509             :     bool next_function_is_likely_called_;
     510             :     bool previous_function_was_likely_called_;
     511             : 
     512             :     // Track if a function or eval occurs within this FunctionState
     513             :     bool contains_function_or_eval_;
     514             : 
     515             :     friend Impl;
     516             :   };
     517             : 
     518             :   // This scope sets current ReturnExprContext to given value.
     519             :   class ReturnExprScope {
     520             :    public:
     521     8139569 :     explicit ReturnExprScope(FunctionState* function_state,
     522             :                              ReturnExprContext return_expr_context)
     523             :         : function_state_(function_state),
     524             :           sav_return_expr_context_(function_state->return_expr_context()) {
     525             :       // Don't update context if we are requested to enable tail call
     526             :       // expressions but current block does not allow them.
     527     7356076 :       if (return_expr_context !=
     528             :               ReturnExprContext::kInsideValidReturnStatement ||
     529             :           sav_return_expr_context_ == ReturnExprContext::kInsideValidBlock) {
     530             :         function_state->set_return_expr_context(return_expr_context);
     531             :       }
     532             :     }
     533             :     ~ReturnExprScope() {
     534             :       function_state_->set_return_expr_context(sav_return_expr_context_);
     535             :     }
     536             : 
     537             :    private:
     538             :     FunctionState* function_state_;
     539             :     ReturnExprContext sav_return_expr_context_;
     540             :   };
     541             : 
     542             :   // Collects all return expressions at tail call position in this scope
     543             :   // to a separate list.
     544             :   class CollectExpressionsInTailPositionToListScope {
     545             :    public:
     546             :     CollectExpressionsInTailPositionToListScope(FunctionState* function_state,
     547             :                                                 TailCallExpressionList* list)
     548             :         : function_state_(function_state), list_(list) {
     549      404753 :       function_state->tail_call_expressions().Swap(*list_);
     550             :     }
     551             :     ~CollectExpressionsInTailPositionToListScope() {
     552      404753 :       function_state_->tail_call_expressions().Swap(*list_);
     553             :     }
     554             : 
     555             :    private:
     556             :     FunctionState* function_state_;
     557             :     TailCallExpressionList* list_;
     558             :   };
     559             : 
     560             :   struct DeclarationDescriptor {
     561             :     enum Kind { NORMAL, PARAMETER };
     562             :     Scope* scope;
     563             :     VariableMode mode;
     564             :     int declaration_pos;
     565             :     int initialization_pos;
     566             :     Kind declaration_kind;
     567             :   };
     568             : 
     569             :   struct DeclarationParsingResult {
     570             :     struct Declaration {
     571             :       Declaration(ExpressionT pattern, int initializer_position,
     572             :                   ExpressionT initializer)
     573             :           : pattern(pattern),
     574             :             initializer_position(initializer_position),
     575    18840582 :             initializer(initializer) {}
     576             : 
     577             :       ExpressionT pattern;
     578             :       int initializer_position;
     579             :       ExpressionT initializer;
     580             :     };
     581             : 
     582             :     DeclarationParsingResult()
     583             :         : declarations(4),
     584             :           first_initializer_loc(Scanner::Location::invalid()),
     585    18419590 :           bindings_loc(Scanner::Location::invalid()) {}
     586             : 
     587             :     DeclarationDescriptor descriptor;
     588             :     List<Declaration> declarations;
     589             :     Scanner::Location first_initializer_loc;
     590             :     Scanner::Location bindings_loc;
     591             :   };
     592             : 
     593             :   struct CatchInfo {
     594             :    public:
     595     1271952 :     explicit CatchInfo(ParserBase* parser)
     596             :         : name(parser->impl()->EmptyIdentifier()),
     597             :           pattern(parser->impl()->EmptyExpression()),
     598             :           scope(nullptr),
     599             :           init_block(parser->impl()->NullBlock()),
     600             :           inner_block(parser->impl()->NullBlock()),
     601             :           bound_names(1, parser->zone()),
     602     1634076 :           tail_call_expressions(parser->zone()) {}
     603             :     IdentifierT name;
     604             :     ExpressionT pattern;
     605             :     Scope* scope;
     606             :     BlockT init_block;
     607             :     BlockT inner_block;
     608             :     ZoneList<const AstRawString*> bound_names;
     609             :     TailCallExpressionList tail_call_expressions;
     610             :   };
     611             : 
     612             :   struct ForInfo {
     613             :    public:
     614     1421942 :     explicit ForInfo(ParserBase* parser)
     615             :         : bound_names(1, parser->zone()),
     616             :           mode(ForEachStatement::ENUMERATE),
     617             :           position(kNoSourcePosition),
     618     2843884 :           parsing_result() {}
     619             :     ZoneList<const AstRawString*> bound_names;
     620             :     ForEachStatement::VisitMode mode;
     621             :     int position;
     622             :     DeclarationParsingResult parsing_result;
     623             :   };
     624             : 
     625             :   struct ClassInfo {
     626             :    public:
     627      150667 :     explicit ClassInfo(ParserBase* parser)
     628             :         : proxy(nullptr),
     629             :           extends(parser->impl()->EmptyExpression()),
     630             :           properties(parser->impl()->NewClassPropertyList(4)),
     631             :           constructor(parser->impl()->EmptyFunctionLiteral()),
     632             :           has_seen_constructor(false),
     633             :           has_name_static_property(false),
     634      391042 :           has_static_computed_names(false) {}
     635             :     VariableProxy* proxy;
     636             :     ExpressionT extends;
     637             :     typename Types::ClassPropertyList properties;
     638             :     FunctionLiteralT constructor;
     639             :     bool has_seen_constructor;
     640             :     bool has_name_static_property;
     641             :     bool has_static_computed_names;
     642             :   };
     643             : 
     644     4048656 :   DeclarationScope* NewScriptScope() const {
     645     4048656 :     return new (zone()) DeclarationScope(zone(), ast_value_factory());
     646             :   }
     647             : 
     648       95557 :   DeclarationScope* NewVarblockScope() const {
     649       95557 :     return new (zone()) DeclarationScope(zone(), scope(), BLOCK_SCOPE);
     650             :   }
     651             : 
     652       28202 :   ModuleScope* NewModuleScope(DeclarationScope* parent) const {
     653       28202 :     return new (zone()) ModuleScope(parent, ast_value_factory());
     654             :   }
     655             : 
     656     1400404 :   DeclarationScope* NewEvalScope(Scope* parent) const {
     657     1400404 :     return new (zone()) DeclarationScope(zone(), parent, EVAL_SCOPE);
     658             :   }
     659             : 
     660      554842 :   Scope* NewScope(ScopeType scope_type) const {
     661      554842 :     return NewScopeWithParent(scope(), scope_type);
     662             :   }
     663             : 
     664             :   // This constructor should only be used when absolutely necessary. Most scopes
     665             :   // should automatically use scope() as parent, and be fine with
     666             :   // NewScope(ScopeType) above.
     667     1106093 :   Scope* NewScopeWithParent(Scope* parent, ScopeType scope_type) const {
     668             :     // Must always use the specific constructors for the blacklisted scope
     669             :     // types.
     670             :     DCHECK_NE(FUNCTION_SCOPE, scope_type);
     671             :     DCHECK_NE(SCRIPT_SCOPE, scope_type);
     672             :     DCHECK_NE(MODULE_SCOPE, scope_type);
     673             :     DCHECK_NOT_NULL(parent);
     674     1106093 :     return new (zone()) Scope(zone(), parent, scope_type);
     675             :   }
     676             : 
     677             :   // Creates a function scope that always allocates in zone(). The function
     678             :   // scope itself is either allocated in zone() or in target_zone if one is
     679             :   // passed in.
     680     8790443 :   DeclarationScope* NewFunctionScope(FunctionKind kind,
     681     9280149 :                                      Zone* target_zone = nullptr) const {
     682             :     DCHECK(ast_value_factory());
     683     8790443 :     if (target_zone == nullptr) target_zone = zone();
     684             :     DeclarationScope* result = new (target_zone)
     685     8790445 :         DeclarationScope(zone(), scope(), FUNCTION_SCOPE, kind);
     686             : 
     687             :     // Record presence of an inner function scope
     688     8790446 :     function_state_->RecordFunctionOrEvalCall();
     689             : 
     690             :     // TODO(verwaest): Move into the DeclarationScope constructor.
     691     8790446 :     if (!IsArrowFunction(kind)) {
     692     8051728 :       result->DeclareDefaultFunctionVariables(ast_value_factory());
     693             :     }
     694     8790444 :     return result;
     695             :   }
     696             : 
     697     7234900 :   V8_INLINE DeclarationScope* GetDeclarationScope() const {
     698     7245483 :     return scope()->GetDeclarationScope();
     699             :   }
     700        6353 :   V8_INLINE DeclarationScope* GetClosureScope() const {
     701        6353 :     return scope()->GetClosureScope();
     702             :   }
     703             : 
     704  3966966254 :   Scanner* scanner() const { return scanner_; }
     705   356171002 :   AstValueFactory* ast_value_factory() const { return ast_value_factory_; }
     706             :   int position() const { return scanner_->location().beg_pos; }
     707             :   int peek_position() const { return scanner_->peek_location().beg_pos; }
     708      348354 :   bool stack_overflow() const { return stack_overflow_; }
     709          52 :   void set_stack_overflow() { stack_overflow_ = true; }
     710             : 
     711  2363087139 :   INLINE(Token::Value peek()) {
     712  3140523665 :     if (stack_overflow_) return Token::ILLEGAL;
     713  3140470477 :     return scanner()->peek();
     714             :   }
     715             : 
     716   120225200 :   INLINE(Token::Value PeekAhead()) {
     717   120225249 :     if (stack_overflow_) return Token::ILLEGAL;
     718   120225200 :     return scanner()->PeekAhead();
     719             :   }
     720             : 
     721   553471595 :   INLINE(Token::Value Next()) {
     722   571728725 :     if (stack_overflow_) return Token::ILLEGAL;
     723             :     {
     724   571720544 :       if (GetCurrentStackPosition() < stack_limit_) {
     725             :         // Any further calls to Next or peek will return the illegal token.
     726             :         // The current call must return the next token, which might already
     727             :         // have been peek'ed.
     728       10629 :         stack_overflow_ = true;
     729             :       }
     730             :     }
     731   571720566 :     return scanner()->Next();
     732             :   }
     733             : 
     734   123467831 :   void Consume(Token::Value token) {
     735             :     Token::Value next = Next();
     736             :     USE(next);
     737             :     USE(token);
     738             :     DCHECK(next == token);
     739   123467969 :   }
     740             : 
     741   246094827 :   bool Check(Token::Value token) {
     742             :     Token::Value next = peek();
     743   246095031 :     if (next == token) {
     744    27681319 :       Consume(next);
     745    27681326 :       return true;
     746             :     }
     747             :     return false;
     748             :   }
     749             : 
     750   148775636 :   void Expect(Token::Value token, bool* ok) {
     751             :     Token::Value next = Next();
     752   148775751 :     if (next != token) {
     753       75885 :       ReportUnexpectedToken(next);
     754       75885 :       *ok = false;
     755             :     }
     756   148775751 :   }
     757             : 
     758    53762575 :   void ExpectSemicolon(bool* ok) {
     759             :     // Check for automatic semicolon insertion according to
     760             :     // the rules given in ECMA-262, section 7.9, page 21.
     761             :     Token::Value tok = peek();
     762    50862681 :     if (tok == Token::SEMICOLON) {
     763             :       Next();
     764             :       return;
     765             :     }
     766     5799828 :     if (scanner()->HasAnyLineTerminatorBeforeNext() ||
     767             :         tok == Token::RBRACE ||
     768             :         tok == Token::EOS) {
     769             :       return;
     770             :     }
     771       12473 :     Expect(Token::SEMICOLON, ok);
     772             :   }
     773             : 
     774             :   // Dummy functions, just useful as arguments to CHECK_OK_CUSTOM.
     775             :   static void Void() {}
     776             :   template <typename T>
     777             :   static T Return(T result) {
     778             :     return result;
     779             :   }
     780             : 
     781    30613878 :   bool is_any_identifier(Token::Value token) {
     782             :     return token == Token::IDENTIFIER || token == Token::ENUM ||
     783             :            token == Token::AWAIT || token == Token::ASYNC ||
     784             :            token == Token::ESCAPED_STRICT_RESERVED_WORD ||
     785             :            token == Token::FUTURE_STRICT_RESERVED_WORD || token == Token::LET ||
     786    30613878 :            token == Token::STATIC || token == Token::YIELD;
     787             :   }
     788    61148758 :   bool peek_any_identifier() { return is_any_identifier(peek()); }
     789             : 
     790     1111801 :   bool CheckContextualKeyword(Token::Value token) {
     791     1111801 :     if (PeekContextualKeyword(token)) {
     792      155855 :       Consume(Token::IDENTIFIER);
     793      155855 :       return true;
     794             :     }
     795             :     return false;
     796             :   }
     797             : 
     798     1633383 :   bool PeekContextualKeyword(Token::Value token) {
     799             :     DCHECK(Token::IsContextualKeyword(token));
     800             :     return peek() == Token::IDENTIFIER &&
     801     1633383 :            scanner()->next_contextual_token() == token;
     802             :   }
     803             : 
     804             :   void ExpectMetaProperty(Token::Value property_name, const char* full_name,
     805             :                           int pos, bool* ok);
     806             : 
     807      271584 :   void ExpectContextualKeyword(Token::Value token, bool* ok) {
     808             :     DCHECK(Token::IsContextualKeyword(token));
     809      278226 :     Expect(Token::IDENTIFIER, CHECK_OK_CUSTOM(Void));
     810      132471 :     if (scanner()->current_contextual_token() != token) {
     811           0 :       ReportUnexpectedToken(scanner()->current_token());
     812           0 :       *ok = false;
     813             :     }
     814             :   }
     815             : 
     816     1239100 :   bool CheckInOrOf(ForEachStatement::VisitMode* visit_mode) {
     817     1239100 :     if (Check(Token::IN)) {
     818      129244 :       *visit_mode = ForEachStatement::ENUMERATE;
     819      129244 :       return true;
     820     1109856 :     } else if (CheckContextualKeyword(Token::OF)) {
     821      155059 :       *visit_mode = ForEachStatement::ITERATE;
     822      155059 :       return true;
     823             :     }
     824             :     return false;
     825             :   }
     826             : 
     827      263585 :   bool PeekInOrOf() {
     828      263585 :     return peek() == Token::IN || PeekContextualKeyword(Token::OF);
     829             :   }
     830             : 
     831             :   // Checks whether an octal literal was last seen between beg_pos and end_pos.
     832             :   // Only called for strict mode strings.
     833     5178039 :   void CheckStrictOctalLiteral(int beg_pos, int end_pos, bool* ok) {
     834             :     Scanner::Location octal = scanner()->octal_position();
     835     5177484 :     if (octal.IsValid() && beg_pos <= octal.beg_pos &&
     836             :         octal.end_pos <= end_pos) {
     837         555 :       MessageTemplate::Template message = scanner()->octal_message();
     838             :       DCHECK_NE(message, MessageTemplate::kNone);
     839         156 :       impl()->ReportMessageAt(octal, message);
     840             :       scanner()->clear_octal_position();
     841         555 :       if (message == MessageTemplate::kStrictDecimalWithLeadingZero) {
     842           0 :         impl()->CountUsage(v8::Isolate::kDecimalWithLeadingZeroInStrictMode);
     843             :       }
     844         555 :       *ok = false;
     845             :     }
     846     5177484 :   }
     847             : 
     848             :   // Checks if an octal literal or an invalid hex or unicode escape sequence
     849             :   // appears in the current template literal token. In the presence of such,
     850             :   // either returns false or reports an error, depending on should_throw.
     851             :   // Otherwise returns true.
     852      163823 :   inline bool CheckTemplateEscapes(bool should_throw, bool* ok) {
     853             :     DCHECK(scanner()->current_token() == Token::TEMPLATE_SPAN ||
     854             :            scanner()->current_token() == Token::TEMPLATE_TAIL);
     855      163823 :     if (!scanner()->has_invalid_template_escape()) {
     856             :       return true;
     857             :     }
     858             : 
     859             :     // Handle error case(s)
     860       27404 :     if (should_throw) {
     861        9696 :       impl()->ReportMessageAt(scanner()->invalid_template_escape_location(),
     862             :                               scanner()->invalid_template_escape_message());
     863       19676 :       *ok = false;
     864             :     }
     865             :     return false;
     866             :   }
     867             : 
     868             :   void CheckDestructuringElement(ExpressionT element, int beg_pos, int end_pos);
     869             : 
     870             :   // Checking the name of a function literal. This has to be done after parsing
     871             :   // the function, since the function can declare itself strict.
     872     7712937 :   void CheckFunctionName(LanguageMode language_mode, IdentifierT function_name,
     873             :                          FunctionNameValidity function_name_validity,
     874             :                          const Scanner::Location& function_name_loc, bool* ok) {
     875     7712937 :     if (function_name_validity == kSkipFunctionNameCheck) return;
     876             :     // The function name needs to be checked in strict mode.
     877     6040313 :     if (is_sloppy(language_mode)) return;
     878             : 
     879     3133244 :     if (impl()->IsEvalOrArguments(function_name)) {
     880         344 :       impl()->ReportMessageAt(function_name_loc,
     881             :                               MessageTemplate::kStrictEvalArguments);
     882         741 :       *ok = false;
     883         741 :       return;
     884             :     }
     885     3132503 :     if (function_name_validity == kFunctionNameIsStrictReserved) {
     886        1560 :       impl()->ReportMessageAt(function_name_loc,
     887             :                               MessageTemplate::kUnexpectedStrictReserved);
     888        2732 :       *ok = false;
     889        2732 :       return;
     890             :     }
     891             :   }
     892             : 
     893             :   // Determine precedence of given token.
     894             :   static int Precedence(Token::Value token, bool accept_IN) {
     895   193884078 :     if (token == Token::IN && !accept_IN)
     896             :       return 0;  // 0 precedence will terminate binary expression parsing
     897             :     return Token::Precedence(token);
     898             :   }
     899             : 
     900    16847243 :   typename Types::Factory* factory() { return &ast_node_factory_; }
     901             : 
     902       60795 :   DeclarationScope* GetReceiverScope() const {
     903       60795 :     return scope()->GetReceiverScope();
     904             :   }
     905    66310852 :   LanguageMode language_mode() { return scope()->language_mode(); }
     906    43382582 :   void RaiseLanguageMode(LanguageMode mode) {
     907             :     LanguageMode old = scope()->language_mode();
     908    43382582 :     impl()->SetLanguageMode(scope(), old > mode ? old : mode);
     909    43382584 :   }
     910             :   bool is_generator() const {
     911             :     return IsGeneratorFunction(function_state_->kind());
     912             :   }
     913             :   bool is_async_function() const {
     914             :     return IsAsyncFunction(function_state_->kind());
     915             :   }
     916      100031 :   bool is_async_generator() const {
     917      200062 :     return IsAsyncGeneratorFunction(function_state_->kind());
     918             :   }
     919       99489 :   bool is_resumable() const {
     920      198978 :     return IsResumableFunction(function_state_->kind());
     921             :   }
     922             : 
     923             :   // Report syntax errors.
     924        6191 :   void ReportMessage(MessageTemplate::Template message) {
     925             :     Scanner::Location source_location = scanner()->location();
     926        2485 :     impl()->ReportMessageAt(source_location, message,
     927             :                             static_cast<const char*>(nullptr), kSyntaxError);
     928        6191 :   }
     929             : 
     930             :   template <typename T>
     931         557 :   void ReportMessage(MessageTemplate::Template message, T arg,
     932         557 :                      ParseErrorType error_type = kSyntaxError) {
     933             :     Scanner::Location source_location = scanner()->location();
     934             :     impl()->ReportMessageAt(source_location, message, arg, error_type);
     935         557 :   }
     936             : 
     937       10031 :   void ReportMessageAt(Scanner::Location location,
     938             :                        MessageTemplate::Template message,
     939             :                        ParseErrorType error_type) {
     940       14146 :     impl()->ReportMessageAt(location, message,
     941             :                             static_cast<const char*>(nullptr), error_type);
     942       10031 :   }
     943             : 
     944             :   void GetUnexpectedTokenMessage(
     945             :       Token::Value token, MessageTemplate::Template* message,
     946             :       Scanner::Location* location, const char** arg,
     947             :       MessageTemplate::Template default_ = MessageTemplate::kUnexpectedToken);
     948             : 
     949             :   void ReportUnexpectedToken(Token::Value token);
     950             :   void ReportUnexpectedTokenAt(
     951             :       Scanner::Location location, Token::Value token,
     952             :       MessageTemplate::Template message = MessageTemplate::kUnexpectedToken);
     953             : 
     954      122315 :   void ReportClassifierError(
     955             :       const typename ExpressionClassifier::Error& error) {
     956      122315 :     impl()->ReportMessageAt(error.location, error.message, error.arg,
     957             :                             error.type);
     958      122315 :   }
     959             : 
     960   202424143 :   void ValidateExpression(bool* ok) {
     961   202424143 :     if (!classifier()->is_valid_expression()) {
     962       11639 :       ReportClassifierError(classifier()->expression_error());
     963       11639 :       *ok = false;
     964             :     }
     965   202424143 :   }
     966             : 
     967      769510 :   void ValidateFormalParameterInitializer(bool* ok) {
     968      769510 :     if (!classifier()->is_valid_formal_parameter_initializer()) {
     969        8928 :       ReportClassifierError(classifier()->formal_parameter_initializer_error());
     970        8928 :       *ok = false;
     971             :     }
     972      769510 :   }
     973             : 
     974    30520373 :   void ValidateBindingPattern(bool* ok) {
     975    30520373 :     if (!classifier()->is_valid_binding_pattern()) {
     976       31979 :       ReportClassifierError(classifier()->binding_pattern_error());
     977       31979 :       *ok = false;
     978             :     }
     979    30520373 :   }
     980             : 
     981      653006 :   void ValidateAssignmentPattern(bool* ok) {
     982      653006 :     if (!classifier()->is_valid_assignment_pattern()) {
     983       20266 :       ReportClassifierError(classifier()->assignment_pattern_error());
     984       20266 :       *ok = false;
     985             :     }
     986      653006 :   }
     987             : 
     988     8504656 :   void ValidateFormalParameters(LanguageMode language_mode,
     989     9600158 :                                 bool allow_duplicates, bool* ok) {
     990    13498983 :     if (!allow_duplicates &&
     991             :         !classifier()->is_valid_formal_parameter_list_without_duplicates()) {
     992        5669 :       ReportClassifierError(classifier()->duplicate_formal_parameter_error());
     993        5669 :       *ok = false;
     994    13095659 :     } else if (is_strict(language_mode) &&
     995             :                !classifier()->is_valid_strict_mode_formal_parameters()) {
     996        3490 :       ReportClassifierError(classifier()->strict_mode_formal_parameter_error());
     997        3490 :       *ok = false;
     998             :     }
     999     8504656 :   }
    1000             : 
    1001             :   bool IsValidArrowFormalParametersStart(Token::Value token) {
    1002       39499 :     return is_any_identifier(token) || token == Token::LPAREN;
    1003             :   }
    1004             : 
    1005      722471 :   void ValidateArrowFormalParameters(ExpressionT expr,
    1006             :                                      bool parenthesized_formals, bool is_async,
    1007      729592 :                                      bool* ok) {
    1008      722471 :     if (classifier()->is_valid_binding_pattern()) {
    1009             :       // A simple arrow formal parameter: IDENTIFIER => BODY.
    1010      145744 :       if (!impl()->IsIdentifier(expr)) {
    1011        1344 :         impl()->ReportMessageAt(scanner()->location(),
    1012             :                                 MessageTemplate::kUnexpectedToken,
    1013             :                                 Token::String(scanner()->current_token()));
    1014         864 :         *ok = false;
    1015             :       }
    1016      576727 :     } else if (!classifier()->is_valid_arrow_formal_parameters()) {
    1017             :       // If after parsing the expr, we see an error but the expression is
    1018             :       // neither a valid binding pattern nor a valid parenthesized formal
    1019             :       // parameter list, show the "arrow formal parameters" error if the formals
    1020             :       // started with a parenthesis, and the binding pattern error otherwise.
    1021             :       const typename ExpressionClassifier::Error& error =
    1022             :           parenthesized_formals ? classifier()->arrow_formal_parameters_error()
    1023       35688 :                                 : classifier()->binding_pattern_error();
    1024       35688 :       ReportClassifierError(error);
    1025       35688 :       *ok = false;
    1026             :     }
    1027      728632 :     if (is_async && !classifier()->is_valid_async_arrow_formal_parameters()) {
    1028             :       const typename ExpressionClassifier::Error& error =
    1029             :           classifier()->async_arrow_formal_parameters_error();
    1030          96 :       ReportClassifierError(error);
    1031          96 :       *ok = false;
    1032             :     }
    1033      722471 :   }
    1034             : 
    1035     1657718 :   void ValidateLetPattern(bool* ok) {
    1036     1657718 :     if (!classifier()->is_valid_let_pattern()) {
    1037        2736 :       ReportClassifierError(classifier()->let_pattern_error());
    1038        2736 :       *ok = false;
    1039             :     }
    1040     1657718 :   }
    1041             : 
    1042   417942273 :   void BindingPatternUnexpectedToken() {
    1043   139314105 :     MessageTemplate::Template message = MessageTemplate::kUnexpectedToken;
    1044             :     const char* arg;
    1045   139314105 :     Scanner::Location location = scanner()->peek_location();
    1046   139314036 :     GetUnexpectedTokenMessage(peek(), &message, &location, &arg);
    1047   278628126 :     classifier()->RecordBindingPatternError(location, message, arg);
    1048   139314067 :   }
    1049             : 
    1050   636024635 :   void ArrowFormalParametersUnexpectedToken() {
    1051   212008279 :     MessageTemplate::Template message = MessageTemplate::kUnexpectedToken;
    1052             :     const char* arg;
    1053   212008279 :     Scanner::Location location = scanner()->peek_location();
    1054   212007971 :     GetUnexpectedTokenMessage(peek(), &message, &location, &arg);
    1055   424016154 :     classifier()->RecordArrowFormalParametersError(location, message, arg);
    1056   212007852 :   }
    1057             : 
    1058             :   // Recursive descent functions.
    1059             :   // All ParseXXX functions take as the last argument an *ok parameter
    1060             :   // which is set to false if parsing failed; it is unchanged otherwise.
    1061             :   // By making the 'exception handling' explicit, we are forced to check
    1062             :   // for failure at the call sites. The family of CHECK_OK* macros can
    1063             :   // be useful for this.
    1064             : 
    1065             :   // Parses an identifier that is valid for the current scope, in particular it
    1066             :   // fails on strict mode future reserved keywords in a strict scope. If
    1067             :   // allow_eval_or_arguments is kAllowEvalOrArguments, we allow "eval" or
    1068             :   // "arguments" as identifier even in strict mode (this is needed in cases like
    1069             :   // "var foo = eval;").
    1070             :   IdentifierT ParseIdentifier(AllowRestrictedIdentifiers, bool* ok);
    1071             :   IdentifierT ParseAndClassifyIdentifier(bool* ok);
    1072             :   // Parses an identifier or a strict mode future reserved word, and indicate
    1073             :   // whether it is strict mode future reserved. Allows passing in function_kind
    1074             :   // for the case of parsing the identifier in a function expression, where the
    1075             :   // relevant "function_kind" bit is of the function being parsed, not the
    1076             :   // containing function.
    1077             :   IdentifierT ParseIdentifierOrStrictReservedWord(FunctionKind function_kind,
    1078             :                                                   bool* is_strict_reserved,
    1079             :                                                   bool* ok);
    1080     2178444 :   IdentifierT ParseIdentifierOrStrictReservedWord(bool* is_strict_reserved,
    1081             :                                                   bool* ok) {
    1082             :     return ParseIdentifierOrStrictReservedWord(function_state_->kind(),
    1083     4356888 :                                                is_strict_reserved, ok);
    1084             :   }
    1085             : 
    1086             :   IdentifierT ParseIdentifierName(bool* ok);
    1087             : 
    1088             :   ExpressionT ParseRegExpLiteral(bool* ok);
    1089             : 
    1090             :   ExpressionT ParsePrimaryExpression(bool* is_async, bool* ok);
    1091             :   ExpressionT ParsePrimaryExpression(bool* ok) {
    1092             :     bool is_async;
    1093    30196333 :     return ParsePrimaryExpression(&is_async, ok);
    1094             :   }
    1095             : 
    1096             :   // This method wraps the parsing of the expression inside a new expression
    1097             :   // classifier and calls RewriteNonPattern if parsing is successful.
    1098             :   // It should be used whenever we're parsing an expression that will be
    1099             :   // used as a non-pattern (i.e., in most cases).
    1100             :   V8_INLINE ExpressionT ParseExpression(bool accept_IN, bool* ok);
    1101             : 
    1102             :   // This method does not wrap the parsing of the expression inside a
    1103             :   // new expression classifier; it uses the top-level classifier instead.
    1104             :   // It should be used whenever we're parsing something with the "cover"
    1105             :   // grammar that recognizes both patterns and non-patterns (which roughly
    1106             :   // corresponds to what's inside the parentheses generated by the symbol
    1107             :   // "CoverParenthesizedExpressionAndArrowParameterList" in the ES 2017
    1108             :   // specification).
    1109             :   ExpressionT ParseExpressionCoverGrammar(bool accept_IN, bool* ok);
    1110             : 
    1111             :   ExpressionT ParseArrayLiteral(bool* ok);
    1112             : 
    1113             :   enum class PropertyKind {
    1114             :     kAccessorProperty,
    1115             :     kValueProperty,
    1116             :     kShorthandProperty,
    1117             :     kMethodProperty,
    1118             :     kClassField,
    1119             :     kSpreadProperty,
    1120             :     kNotSet
    1121             :   };
    1122             : 
    1123             :   bool SetPropertyKindFromToken(Token::Value token, PropertyKind* kind);
    1124             :   ExpressionT ParsePropertyName(IdentifierT* name, PropertyKind* kind,
    1125             :                                 bool* is_generator, bool* is_get, bool* is_set,
    1126             :                                 bool* is_async, bool* is_computed_name,
    1127             :                                 bool* ok);
    1128             :   ExpressionT ParseObjectLiteral(bool* ok);
    1129             :   ClassLiteralPropertyT ParseClassPropertyDefinition(
    1130             :       ClassLiteralChecker* checker, bool has_extends, bool* is_computed_name,
    1131             :       bool* has_seen_constructor, ClassLiteralProperty::Kind* property_kind,
    1132             :       bool* is_static, bool* has_name_static_property, bool* ok);
    1133             :   FunctionLiteralT ParseClassFieldForInitializer(bool has_initializer,
    1134             :                                                  bool* ok);
    1135             :   ObjectLiteralPropertyT ParseObjectPropertyDefinition(
    1136             :       ObjectLiteralChecker* checker, bool* is_computed_name,
    1137             :       bool* is_rest_property, bool* ok);
    1138             :   ExpressionListT ParseArguments(Scanner::Location* first_spread_pos,
    1139             :                                  bool maybe_arrow, bool* ok);
    1140     1112003 :   ExpressionListT ParseArguments(Scanner::Location* first_spread_pos,
    1141             :                                  bool* ok) {
    1142     3361041 :     return ParseArguments(first_spread_pos, false, ok);
    1143             :   }
    1144             : 
    1145             :   ExpressionT ParseAssignmentExpression(bool accept_IN, bool* ok);
    1146             :   ExpressionT ParseYieldExpression(bool accept_IN, bool* ok);
    1147             :   ExpressionT ParseConditionalExpression(bool accept_IN, bool* ok);
    1148             :   ExpressionT ParseBinaryExpression(int prec, bool accept_IN, bool* ok);
    1149             :   ExpressionT ParseUnaryExpression(bool* ok);
    1150             :   ExpressionT ParsePostfixExpression(bool* ok);
    1151             :   ExpressionT ParseLeftHandSideExpression(bool* ok);
    1152             :   ExpressionT ParseMemberWithNewPrefixesExpression(bool* is_async, bool* ok);
    1153             :   ExpressionT ParseMemberExpression(bool* is_async, bool* ok);
    1154             :   ExpressionT ParseMemberExpressionContinuation(ExpressionT expression,
    1155             :                                                 bool* is_async, bool* ok);
    1156             : 
    1157             :   // `rewritable_length`: length of the destructuring_assignments_to_rewrite()
    1158             :   // queue in the parent function state, prior to parsing of formal parameters.
    1159             :   // If the arrow function is lazy, any items added during formal parameter
    1160             :   // parsing are removed from the queue.
    1161             :   ExpressionT ParseArrowFunctionLiteral(bool accept_IN,
    1162             :                                         const FormalParametersT& parameters,
    1163             :                                         int rewritable_length, bool* ok);
    1164             :   void ParseAsyncFunctionBody(Scope* scope, StatementListT body,
    1165             :                               FunctionKind kind, FunctionBodyType type,
    1166             :                               bool accept_IN, int pos, bool* ok);
    1167             :   ExpressionT ParseAsyncFunctionLiteral(bool* ok);
    1168             :   ExpressionT ParseClassLiteral(IdentifierT name,
    1169             :                                 Scanner::Location class_name_location,
    1170             :                                 bool name_is_strict_reserved,
    1171             :                                 int class_token_pos, bool* ok);
    1172             :   ExpressionT ParseTemplateLiteral(ExpressionT tag, int start, bool tagged,
    1173             :                                    bool* ok);
    1174             :   ExpressionT ParseSuperExpression(bool is_new, bool* ok);
    1175             :   ExpressionT ParseDynamicImportExpression(bool* ok);
    1176             :   ExpressionT ParseNewTargetExpression(bool* ok);
    1177             : 
    1178             :   void ParseFormalParameter(FormalParametersT* parameters, bool* ok);
    1179             :   void ParseFormalParameterList(FormalParametersT* parameters, bool* ok);
    1180             :   void CheckArityRestrictions(int param_count, FunctionKind function_type,
    1181             :                               bool has_rest, int formals_start_pos,
    1182             :                               int formals_end_pos, bool* ok);
    1183             : 
    1184             :   BlockT ParseVariableDeclarations(VariableDeclarationContext var_context,
    1185             :                                    DeclarationParsingResult* parsing_result,
    1186             :                                    ZoneList<const AstRawString*>* names,
    1187             :                                    bool* ok);
    1188             :   StatementT ParseAsyncFunctionDeclaration(ZoneList<const AstRawString*>* names,
    1189             :                                            bool default_export, bool* ok);
    1190             :   StatementT ParseFunctionDeclaration(bool* ok);
    1191             :   StatementT ParseHoistableDeclaration(ZoneList<const AstRawString*>* names,
    1192             :                                        bool default_export, bool* ok);
    1193             :   StatementT ParseHoistableDeclaration(int pos, ParseFunctionFlags flags,
    1194             :                                        ZoneList<const AstRawString*>* names,
    1195             :                                        bool default_export, bool* ok);
    1196             :   StatementT ParseClassDeclaration(ZoneList<const AstRawString*>* names,
    1197             :                                    bool default_export, bool* ok);
    1198             :   StatementT ParseNativeDeclaration(bool* ok);
    1199             : 
    1200             :   // Consumes the ending }.
    1201             :   void ParseFunctionBody(StatementListT result, IdentifierT function_name,
    1202             :                          int pos, const FormalParametersT& parameters,
    1203             :                          FunctionKind kind,
    1204             :                          FunctionLiteral::FunctionType function_type, bool* ok);
    1205             : 
    1206             :   // Under some circumstances, we allow preparsing to abort if the preparsed
    1207             :   // function is "long and trivial", and fully parse instead. Our current
    1208             :   // definition of "long and trivial" is:
    1209             :   // - over kLazyParseTrialLimit statements
    1210             :   // - all starting with an identifier (i.e., no if, for, while, etc.)
    1211             :   static const int kLazyParseTrialLimit = 200;
    1212             : 
    1213             :   // TODO(nikolaos, marja): The first argument should not really be passed
    1214             :   // by value. The method is expected to add the parsed statements to the
    1215             :   // list. This works because in the case of the parser, StatementListT is
    1216             :   // a pointer whereas the preparser does not really modify the body.
    1217             :   V8_INLINE void ParseStatementList(StatementListT body, int end_token,
    1218             :                                     bool* ok) {
    1219     9409189 :     LazyParsingResult result = ParseStatementList(body, end_token, false, ok);
    1220     9409207 :     USE(result);
    1221             :     DCHECK_EQ(result, kLazyParsingComplete);
    1222             :   }
    1223             :   LazyParsingResult ParseStatementList(StatementListT body, int end_token,
    1224             :                                        bool may_abort, bool* ok);
    1225             :   StatementT ParseStatementListItem(bool* ok);
    1226             :   StatementT ParseStatement(ZoneList<const AstRawString*>* labels, bool* ok) {
    1227     8870691 :     return ParseStatement(labels, kDisallowLabelledFunctionStatement, ok);
    1228             :   }
    1229             :   StatementT ParseStatement(ZoneList<const AstRawString*>* labels,
    1230             :                             AllowLabelledFunctionStatement allow_function,
    1231             :                             bool* ok);
    1232             :   StatementT ParseStatementAsUnlabelled(ZoneList<const AstRawString*>* labels,
    1233             :                                         bool* ok);
    1234             :   BlockT ParseBlock(ZoneList<const AstRawString*>* labels, bool* ok);
    1235             : 
    1236             :   // Parse a SubStatement in strict mode, or with an extra block scope in
    1237             :   // sloppy mode to handle
    1238             :   // ES#sec-functiondeclarations-in-ifstatement-statement-clauses
    1239             :   StatementT ParseScopedStatement(ZoneList<const AstRawString*>* labels,
    1240             :                                   bool* ok);
    1241             : 
    1242             :   StatementT ParseVariableStatement(VariableDeclarationContext var_context,
    1243             :                                     ZoneList<const AstRawString*>* names,
    1244             :                                     bool* ok);
    1245             : 
    1246             :   // Magical syntax support.
    1247             :   ExpressionT ParseV8Intrinsic(bool* ok);
    1248             : 
    1249             :   ExpressionT ParseDoExpression(bool* ok);
    1250             : 
    1251             :   StatementT ParseDebuggerStatement(bool* ok);
    1252             : 
    1253             :   StatementT ParseExpressionOrLabelledStatement(
    1254             :       ZoneList<const AstRawString*>* labels,
    1255             :       AllowLabelledFunctionStatement allow_function, bool* ok);
    1256             :   StatementT ParseIfStatement(ZoneList<const AstRawString*>* labels, bool* ok);
    1257             :   StatementT ParseContinueStatement(bool* ok);
    1258             :   StatementT ParseBreakStatement(ZoneList<const AstRawString*>* labels,
    1259             :                                  bool* ok);
    1260             :   StatementT ParseReturnStatement(bool* ok);
    1261             :   StatementT ParseWithStatement(ZoneList<const AstRawString*>* labels,
    1262             :                                 bool* ok);
    1263             :   StatementT ParseDoWhileStatement(ZoneList<const AstRawString*>* labels,
    1264             :                                    bool* ok);
    1265             :   StatementT ParseWhileStatement(ZoneList<const AstRawString*>* labels,
    1266             :                                  bool* ok);
    1267             :   StatementT ParseThrowStatement(bool* ok);
    1268             :   StatementT ParseSwitchStatement(ZoneList<const AstRawString*>* labels,
    1269             :                                   bool* ok);
    1270             :   StatementT ParseTryStatement(bool* ok);
    1271             :   StatementT ParseForStatement(ZoneList<const AstRawString*>* labels, bool* ok);
    1272             :   StatementT ParseForEachStatementWithDeclarations(
    1273             :       int stmt_pos, ForInfo* for_info, ZoneList<const AstRawString*>* labels,
    1274             :       bool* ok);
    1275             :   StatementT ParseForEachStatementWithoutDeclarations(
    1276             :       int stmt_pos, ExpressionT expression, int lhs_beg_pos, int lhs_end_pos,
    1277             :       ForInfo* for_info, ZoneList<const AstRawString*>* labels, bool* ok);
    1278             : 
    1279             :   // Parse a C-style for loop: 'for (<init>; <cond>; <step>) { ... }'
    1280             :   StatementT ParseStandardForLoop(int stmt_pos, StatementT init,
    1281             :                                   bool bound_names_are_lexical,
    1282             :                                   ForInfo* for_info, BlockState* for_state,
    1283             :                                   ZoneList<const AstRawString*>* labels,
    1284             :                                   bool* ok);
    1285             :   StatementT ParseForAwaitStatement(ZoneList<const AstRawString*>* labels,
    1286             :                                     bool* ok);
    1287             : 
    1288             :   bool IsNextLetKeyword();
    1289             :   bool IsTrivialExpression();
    1290             : 
    1291             :   // Checks if the expression is a valid reference expression (e.g., on the
    1292             :   // left-hand side of assignments). Although ruled out by ECMA as early errors,
    1293             :   // we allow calls for web compatibility and rewrite them to a runtime throw.
    1294             :   ExpressionT CheckAndRewriteReferenceExpression(
    1295             :       ExpressionT expression, int beg_pos, int end_pos,
    1296             :       MessageTemplate::Template message, bool* ok);
    1297             :   ExpressionT CheckAndRewriteReferenceExpression(
    1298             :       ExpressionT expression, int beg_pos, int end_pos,
    1299             :       MessageTemplate::Template message, ParseErrorType type, bool* ok);
    1300             : 
    1301             :   bool IsValidReferenceExpression(ExpressionT expression);
    1302             : 
    1303   155760111 :   bool IsAssignableIdentifier(ExpressionT expression) {
    1304   155760354 :     if (!impl()->IsIdentifier(expression)) return false;
    1305    53097361 :     if (is_strict(language_mode()) &&
    1306             :         impl()->IsEvalOrArguments(impl()->AsIdentifier(expression))) {
    1307             :       return false;
    1308             :     }
    1309    26827772 :     return true;
    1310             :   }
    1311             : 
    1312   120862855 :   bool IsValidPattern(ExpressionT expression) {
    1313   275512372 :     return expression->IsObjectLiteral() || expression->IsArrayLiteral();
    1314             :   }
    1315             : 
    1316             :   // Due to hoisting, the value of a 'var'-declared variable may actually change
    1317             :   // even if the code contains only the "initial" assignment, namely when that
    1318             :   // assignment occurs inside a loop.  For example:
    1319             :   //
    1320             :   //   let i = 10;
    1321             :   //   do { var x = i } while (i--):
    1322             :   //
    1323             :   // As a simple and very conservative approximation of this, we explicitly mark
    1324             :   // as maybe-assigned any non-lexical variable whose initializing "declaration"
    1325             :   // does not syntactically occur in the function scope.  (In the example above,
    1326             :   // it occurs in a block scope.)
    1327             :   //
    1328             :   // Note that non-lexical variables include temporaries, which may also get
    1329             :   // assigned inside a loop due to the various rewritings that the parser
    1330             :   // performs.
    1331             :   //
    1332             :   static void MarkLoopVariableAsAssigned(Scope* scope, Variable* var);
    1333             : 
    1334             :   FunctionKind FunctionKindForImpl(bool is_method, bool is_generator,
    1335             :                                    bool is_async) {
    1336             :     static const FunctionKind kFunctionKinds[][2][2] = {
    1337             :         {
    1338             :             // is_method=false
    1339             :             {// is_generator=false
    1340             :              FunctionKind::kNormalFunction, FunctionKind::kAsyncFunction},
    1341             :             {// is_generator=true
    1342             :              FunctionKind::kGeneratorFunction,
    1343             :              FunctionKind::kAsyncGeneratorFunction},
    1344             :         },
    1345             :         {
    1346             :             // is_method=true
    1347             :             {// is_generator=false
    1348             :              FunctionKind::kConciseMethod, FunctionKind::kAsyncConciseMethod},
    1349             :             {// is_generator=true
    1350             :              FunctionKind::kConciseGeneratorMethod,
    1351             :              FunctionKind::kAsyncConciseGeneratorMethod},
    1352             :         }};
    1353     2471686 :     return kFunctionKinds[is_method][is_generator][is_async];
    1354             :   }
    1355             : 
    1356             :   inline FunctionKind FunctionKindFor(bool is_generator, bool is_async) {
    1357             :     const bool kIsMethod = false;
    1358             :     return FunctionKindForImpl(kIsMethod, is_generator, is_async);
    1359             :   }
    1360             : 
    1361             :   inline FunctionKind MethodKindFor(bool is_generator, bool is_async) {
    1362             :     const bool kIsMethod = true;
    1363             :     return FunctionKindForImpl(kIsMethod, is_generator, is_async);
    1364             :   }
    1365             : 
    1366             :   // Keep track of eval() calls since they disable all local variable
    1367             :   // optimizations. This checks if expression is an eval call, and if yes,
    1368             :   // forwards the information to scope.
    1369    14880126 :   Call::PossiblyEval CheckPossibleEvalCall(ExpressionT expression,
    1370             :                                            Scope* scope) {
    1371    22515741 :     if (impl()->IsIdentifier(expression) &&
    1372             :         impl()->IsEval(impl()->AsIdentifier(expression))) {
    1373             :       scope->RecordEvalCall();
    1374      453230 :       function_state_->RecordFunctionOrEvalCall();
    1375      453230 :       if (is_sloppy(scope->language_mode())) {
    1376             :         // For sloppy scopes we also have to record the call at function level,
    1377             :         // in case it includes declarations that will be hoisted.
    1378      350124 :         scope->GetDeclarationScope()->RecordEvalCall();
    1379             :       }
    1380             :       return Call::IS_POSSIBLY_EVAL;
    1381             :     }
    1382             :     return Call::NOT_EVAL;
    1383             :   }
    1384             : 
    1385             :   // Convenience method which determines the type of return statement to emit
    1386             :   // depending on the current function type.
    1387    15542483 :   inline StatementT BuildReturnStatement(ExpressionT expr, int pos) {
    1388     7787825 :     if (is_generator() && !is_async_generator()) {
    1389        6743 :       expr = impl()->BuildIteratorResult(expr, true);
    1390             :     }
    1391             : 
    1392     7754667 :     if (is_async_function()) {
    1393       44560 :       return factory()->NewAsyncReturnStatement(expr, pos);
    1394             :     }
    1395    11696828 :     return factory()->NewReturnStatement(expr, pos);
    1396             :   }
    1397             : 
    1398      119359 :   inline SuspendExpressionT BuildSuspend(ExpressionT generator,
    1399             :                                          ExpressionT expr, int pos,
    1400             :                                          Suspend::OnException on_exception,
    1401      142662 :                                          SuspendFlags suspend_type) {
    1402             :     DCHECK_EQ(0,
    1403             :               static_cast<int>(suspend_type & ~SuspendFlags::kSuspendTypeMask));
    1404      119359 :     if (V8_UNLIKELY(is_async_generator())) {
    1405             :       suspend_type = static_cast<SuspendFlags>(suspend_type |
    1406             :                                                SuspendFlags::kAsyncGenerator);
    1407             :     }
    1408             :     return factory()->NewSuspend(generator, expr, pos, on_exception,
    1409      119359 :                                  suspend_type);
    1410             :   }
    1411             : 
    1412             :   // Validation per ES6 object literals.
    1413             :   class ObjectLiteralChecker {
    1414             :    public:
    1415             :     explicit ObjectLiteralChecker(ParserBase* parser)
    1416     2326846 :         : parser_(parser), has_seen_proto_(false) {}
    1417             : 
    1418             :     void CheckDuplicateProto(Token::Value property);
    1419             : 
    1420             :    private:
    1421     4549209 :     bool IsProto() const {
    1422             :       return this->scanner()->CurrentMatchesContextualEscaped(
    1423     4549209 :           Token::PROTO_UNDERSCORED);
    1424             :     }
    1425             : 
    1426             :     ParserBase* parser() const { return parser_; }
    1427     4552599 :     Scanner* scanner() const { return parser_->scanner(); }
    1428             : 
    1429             :     ParserBase* parser_;
    1430             :     bool has_seen_proto_;
    1431             :   };
    1432             : 
    1433             :   // Validation per ES6 class literals.
    1434             :   class ClassLiteralChecker {
    1435             :    public:
    1436             :     explicit ClassLiteralChecker(ParserBase* parser)
    1437      149171 :         : parser_(parser), has_seen_constructor_(false) {}
    1438             : 
    1439             :     void CheckClassMethodName(Token::Value property, PropertyKind type,
    1440             :                               bool is_generator, bool is_async, bool is_static,
    1441             :                               bool* ok);
    1442             : 
    1443             :    private:
    1444      347522 :     bool IsConstructor() {
    1445             :       return this->scanner()->CurrentMatchesContextualEscaped(
    1446      347522 :           Token::CONSTRUCTOR);
    1447             :     }
    1448       24022 :     bool IsPrototype() {
    1449       24022 :       return this->scanner()->CurrentMatchesContextualEscaped(Token::PROTOTYPE);
    1450             :     }
    1451             : 
    1452             :     ParserBase* parser() const { return parser_; }
    1453      371544 :     Scanner* scanner() const { return parser_->scanner(); }
    1454             : 
    1455             :     ParserBase* parser_;
    1456             :     bool has_seen_constructor_;
    1457             :   };
    1458             : 
    1459       10300 :   ModuleDescriptor* module() const {
    1460       10300 :     return scope()->AsModuleScope()->module();
    1461             :   }
    1462     7648831 :   Scope* scope() const { return scope_; }
    1463             : 
    1464             :   // Stack of expression classifiers.
    1465             :   // The top of the stack is always pointed to by classifier().
    1466             :   V8_INLINE ExpressionClassifier* classifier() const {
    1467             :     DCHECK_NOT_NULL(classifier_);
    1468             :     return classifier_;
    1469             :   }
    1470             : 
    1471             :   // Accumulates the classifier that is on top of the stack (inner) to
    1472             :   // the one that is right below (outer) and pops the inner.
    1473             :   V8_INLINE void Accumulate(unsigned productions,
    1474             :                             bool merge_non_patterns = true) {
    1475             :     DCHECK_NOT_NULL(classifier_);
    1476   210843997 :     ExpressionClassifier* previous = classifier_->previous();
    1477             :     DCHECK_NOT_NULL(previous);
    1478   210843993 :     previous->Accumulate(classifier_, productions, merge_non_patterns);
    1479   210844212 :     classifier_ = previous;
    1480             :   }
    1481             : 
    1482             :   V8_INLINE void AccumulateNonBindingPatternErrors() {
    1483             :     static const bool kMergeNonPatterns = true;
    1484             :     this->Accumulate(ExpressionClassifier::AllProductions &
    1485             :                          ~(ExpressionClassifier::BindingPatternProduction |
    1486             :                            ExpressionClassifier::LetPatternProduction),
    1487             :                      kMergeNonPatterns);
    1488             :   }
    1489             : 
    1490             :   // Pops and discards the classifier that is on top of the stack
    1491             :   // without accumulating.
    1492             :   V8_INLINE void DiscardExpressionClassifier() {
    1493             :     DCHECK_NOT_NULL(classifier_);
    1494      700305 :     classifier_->Discard();
    1495      700305 :     classifier_ = classifier_->previous();
    1496             :   }
    1497             : 
    1498             :   // Accumulate errors that can be arbitrarily deep in an expression.
    1499             :   // These correspond to the ECMAScript spec's 'Contains' operation
    1500             :   // on productions. This includes:
    1501             :   //
    1502             :   // - YieldExpression is disallowed in arrow parameters in a generator.
    1503             :   // - AwaitExpression is disallowed in arrow parameters in an async function.
    1504             :   // - AwaitExpression is disallowed in async arrow parameters.
    1505             :   //
    1506             :   V8_INLINE void AccumulateFormalParameterContainmentErrors() {
    1507             :     Accumulate(ExpressionClassifier::FormalParameterInitializerProduction |
    1508             :                ExpressionClassifier::AsyncArrowFormalParametersProduction);
    1509             :   }
    1510             : 
    1511             :   // Parser base's protected field members.
    1512             : 
    1513             :   Scope* scope_;                   // Scope stack.
    1514             :   Scope* original_scope_;  // The top scope for the current parsing item.
    1515             :   FunctionState* function_state_;  // Function state stack.
    1516             :   v8::Extension* extension_;
    1517             :   FuncNameInferrer* fni_;
    1518             :   AstValueFactory* ast_value_factory_;  // Not owned.
    1519             :   typename Types::Factory ast_node_factory_;
    1520             :   RuntimeCallStats* runtime_call_stats_;
    1521             :   bool parsing_on_main_thread_;
    1522             :   bool parsing_module_;
    1523             :   uintptr_t stack_limit_;
    1524             :   PreParsedScopeData* preparsed_scope_data_;
    1525             : 
    1526             :   // Parser base's private field members.
    1527             : 
    1528             :  private:
    1529             :   Zone* zone_;
    1530             :   ExpressionClassifier* classifier_;
    1531             : 
    1532             :   Scanner* scanner_;
    1533             :   bool stack_overflow_;
    1534             : 
    1535             :   FunctionLiteral::EagerCompileHint default_eager_compile_hint_;
    1536             : 
    1537             :   int function_literal_id_;
    1538             : 
    1539             :   bool allow_natives_;
    1540             :   bool allow_tailcalls_;
    1541             :   bool allow_harmony_do_expressions_;
    1542             :   bool allow_harmony_function_sent_;
    1543             :   bool allow_harmony_restrictive_generators_;
    1544             :   bool allow_harmony_trailing_commas_;
    1545             :   bool allow_harmony_class_fields_;
    1546             :   bool allow_harmony_object_rest_spread_;
    1547             :   bool allow_harmony_dynamic_import_;
    1548             :   bool allow_harmony_async_iteration_;
    1549             :   bool allow_harmony_template_escapes_;
    1550             : 
    1551             :   friend class DiscardableZoneScope;
    1552             : };
    1553             : 
    1554             : template <typename Impl>
    1555    12860551 : ParserBase<Impl>::FunctionState::FunctionState(
    1556             :     FunctionState** function_state_stack, Scope** scope_stack,
    1557             :     DeclarationScope* scope)
    1558             :     : BlockState(scope_stack, scope),
    1559             :       expected_property_count_(0),
    1560             :       function_state_stack_(function_state_stack),
    1561             :       outer_function_state_(*function_state_stack),
    1562             :       scope_(scope),
    1563             :       destructuring_assignments_to_rewrite_(16, scope->zone()),
    1564             :       tail_call_expressions_(scope->zone()),
    1565             :       return_expr_context_(ReturnExprContext::kInsideValidBlock),
    1566             :       non_patterns_to_rewrite_(0, scope->zone()),
    1567             :       reported_errors_(16, scope->zone()),
    1568             :       next_function_is_likely_called_(false),
    1569             :       previous_function_was_likely_called_(false),
    1570    25721109 :       contains_function_or_eval_(false) {
    1571    12860561 :   *function_state_stack = this;
    1572    12860561 :   if (outer_function_state_) {
    1573     7377850 :     outer_function_state_->previous_function_was_likely_called_ =
    1574             :         outer_function_state_->next_function_is_likely_called_;
    1575     7377850 :     outer_function_state_->next_function_is_likely_called_ = false;
    1576             :   }
    1577    12860561 : }
    1578             : 
    1579             : template <typename Impl>
    1580             : ParserBase<Impl>::FunctionState::~FunctionState() {
    1581    12860559 :   *function_state_stack_ = outer_function_state_;
    1582             : }
    1583             : 
    1584             : template <typename Impl>
    1585   351774448 : void ParserBase<Impl>::GetUnexpectedTokenMessage(
    1586             :     Token::Value token, MessageTemplate::Template* message,
    1587             :     Scanner::Location* location, const char** arg,
    1588       18513 :     MessageTemplate::Template default_) {
    1589   351774448 :   *arg = nullptr;
    1590   351774448 :   switch (token) {
    1591             :     case Token::EOS:
    1592      238880 :       *message = MessageTemplate::kUnexpectedEOS;
    1593      238880 :       break;
    1594             :     case Token::SMI:
    1595             :     case Token::NUMBER:
    1596    70599630 :       *message = MessageTemplate::kUnexpectedTokenNumber;
    1597    70599630 :       break;
    1598             :     case Token::STRING:
    1599    22897092 :       *message = MessageTemplate::kUnexpectedTokenString;
    1600    22897092 :       break;
    1601             :     case Token::IDENTIFIER:
    1602    69159208 :       *message = MessageTemplate::kUnexpectedTokenIdentifier;
    1603    69159208 :       break;
    1604             :     case Token::AWAIT:
    1605             :     case Token::ENUM:
    1606       67294 :       *message = MessageTemplate::kUnexpectedReserved;
    1607       67294 :       break;
    1608             :     case Token::LET:
    1609             :     case Token::STATIC:
    1610             :     case Token::YIELD:
    1611             :     case Token::FUTURE_STRICT_RESERVED_WORD:
    1612       85581 :       *message = is_strict(language_mode())
    1613             :                      ? MessageTemplate::kUnexpectedStrictReserved
    1614             :                      : MessageTemplate::kUnexpectedTokenIdentifier;
    1615       85581 :       break;
    1616             :     case Token::TEMPLATE_SPAN:
    1617             :     case Token::TEMPLATE_TAIL:
    1618      181427 :       *message = MessageTemplate::kUnexpectedTemplateString;
    1619      181427 :       break;
    1620             :     case Token::ESCAPED_STRICT_RESERVED_WORD:
    1621             :     case Token::ESCAPED_KEYWORD:
    1622       23264 :       *message = MessageTemplate::kInvalidEscapedReservedWord;
    1623       23264 :       break;
    1624             :     case Token::ILLEGAL:
    1625       18513 :       if (scanner()->has_error()) {
    1626        3801 :         *message = scanner()->error();
    1627        3801 :         *location = scanner()->error_location();
    1628             :       } else {
    1629       14712 :         *message = MessageTemplate::kInvalidOrUnexpectedToken;
    1630             :       }
    1631             :       break;
    1632             :     case Token::REGEXP_LITERAL:
    1633         384 :       *message = MessageTemplate::kUnexpectedTokenRegExp;
    1634         384 :       break;
    1635             :     default:
    1636             :       const char* name = Token::String(token);
    1637             :       DCHECK(name != NULL);
    1638   188503175 :       *arg = name;
    1639   188503175 :       break;
    1640             :   }
    1641   351774448 : }
    1642             : 
    1643             : template <typename Impl>
    1644      449441 : void ParserBase<Impl>::ReportUnexpectedToken(Token::Value token) {
    1645      449441 :   return ReportUnexpectedTokenAt(scanner_->location(), token);
    1646             : }
    1647             : 
    1648             : template <typename Impl>
    1649      451820 : void ParserBase<Impl>::ReportUnexpectedTokenAt(
    1650             :     Scanner::Location source_location, Token::Value token,
    1651             :     MessageTemplate::Template message) {
    1652             :   const char* arg;
    1653      451820 :   GetUnexpectedTokenMessage(token, &message, &source_location, &arg);
    1654      451820 :   impl()->ReportMessageAt(source_location, message, arg);
    1655      451820 : }
    1656             : 
    1657             : template <typename Impl>
    1658     2686492 : typename ParserBase<Impl>::IdentifierT ParserBase<Impl>::ParseIdentifier(
    1659             :     AllowRestrictedIdentifiers allow_restricted_identifiers, bool* ok) {
    1660     2686492 :   ExpressionClassifier classifier(this);
    1661     2687360 :   auto result = ParseAndClassifyIdentifier(CHECK_OK_CUSTOM(EmptyIdentifier));
    1662             : 
    1663     2684332 :   if (allow_restricted_identifiers == kDontAllowRestrictedIdentifiers) {
    1664      387665 :     ValidateAssignmentPattern(CHECK_OK_CUSTOM(EmptyIdentifier));
    1665      387819 :     ValidateBindingPattern(CHECK_OK_CUSTOM(EmptyIdentifier));
    1666             :   }
    1667             : 
    1668     2683976 :   return result;
    1669             : }
    1670             : 
    1671             : template <typename Impl>
    1672             : typename ParserBase<Impl>::IdentifierT
    1673   236279957 : ParserBase<Impl>::ParseAndClassifyIdentifier(bool* ok) {
    1674             :   Token::Value next = Next();
    1675   111745157 :   if (next == Token::IDENTIFIER || next == Token::ASYNC ||
    1676       24110 :       (next == Token::AWAIT && !parsing_module_ && !is_async_function())) {
    1677    28407366 :     IdentifierT name = impl()->GetSymbol();
    1678             :     // When this function is used to read a formal parameter, we don't always
    1679             :     // know whether the function is going to be strict or sloppy.  Indeed for
    1680             :     // arrow functions we don't always know that the identifier we are reading
    1681             :     // is actually a formal parameter.  Therefore besides the errors that we
    1682             :     // must detect because we know we're in strict mode, we also record any
    1683             :     // error that we might make in the future once we know the language mode.
    1684   111608307 :     if (impl()->IsEvalOrArguments(name)) {
    1685     1159510 :       classifier()->RecordStrictModeFormalParameterError(
    1686             :           scanner()->location(), MessageTemplate::kStrictEvalArguments);
    1687      579755 :       if (is_strict(language_mode())) {
    1688      296742 :         classifier()->RecordBindingPatternError(
    1689             :             scanner()->location(), MessageTemplate::kStrictEvalArguments);
    1690             :       }
    1691   111028552 :     } else if (next == Token::AWAIT) {
    1692       41664 :       classifier()->RecordAsyncArrowFormalParametersError(
    1693             :           scanner()->location(), MessageTemplate::kAwaitBindingIdentifier);
    1694             :     }
    1695             : 
    1696   122827567 :     if (classifier()->duplicate_finder() != nullptr &&
    1697             :         scanner()->IsDuplicateSymbol(classifier()->duplicate_finder(),
    1698             :                                      ast_value_factory())) {
    1699       43034 :       classifier()->RecordDuplicateFormalParameterError(scanner()->location());
    1700             :     }
    1701   111608309 :     return name;
    1702      105537 :   } else if (is_sloppy(language_mode()) &&
    1703             :              (next == Token::FUTURE_STRICT_RESERVED_WORD ||
    1704             :               next == Token::ESCAPED_STRICT_RESERVED_WORD ||
    1705             :               next == Token::LET || next == Token::STATIC ||
    1706             :               (next == Token::YIELD && !is_generator()))) {
    1707      107554 :     classifier()->RecordStrictModeFormalParameterError(
    1708             :         scanner()->location(), MessageTemplate::kUnexpectedStrictReserved);
    1709       55185 :     if (next == Token::ESCAPED_STRICT_RESERVED_WORD &&
    1710             :         is_strict(language_mode())) {
    1711           0 :       ReportUnexpectedToken(next);
    1712           0 :       *ok = false;
    1713           0 :       return impl()->EmptyIdentifier();
    1714             :     }
    1715       53777 :     if (scanner()->IsLet()) {
    1716       27834 :       classifier()->RecordLetPatternError(
    1717             :           scanner()->location(), MessageTemplate::kLetInLexicalBinding);
    1718             :     }
    1719       53777 :     return impl()->GetSymbol();
    1720             :   } else {
    1721       36563 :     ReportUnexpectedToken(next);
    1722       36563 :     *ok = false;
    1723       36563 :     return impl()->EmptyIdentifier();
    1724             :   }
    1725             : }
    1726             : 
    1727             : template <class Impl>
    1728             : typename ParserBase<Impl>::IdentifierT
    1729     3057949 : ParserBase<Impl>::ParseIdentifierOrStrictReservedWord(
    1730             :     FunctionKind function_kind, bool* is_strict_reserved, bool* ok) {
    1731             :   Token::Value next = Next();
    1732     3059975 :   if (next == Token::IDENTIFIER || (next == Token::AWAIT && !parsing_module_ &&
    1733             :                                     !IsAsyncFunction(function_kind)) ||
    1734             :       next == Token::ASYNC) {
    1735     3043024 :     *is_strict_reserved = false;
    1736       19667 :   } else if (next == Token::ESCAPED_STRICT_RESERVED_WORD ||
    1737             :              next == Token::FUTURE_STRICT_RESERVED_WORD || next == Token::LET ||
    1738             :              next == Token::STATIC ||
    1739             :              (next == Token::YIELD && !IsGeneratorFunction(function_kind))) {
    1740       10079 :     *is_strict_reserved = true;
    1741             :   } else {
    1742        4856 :     ReportUnexpectedToken(next);
    1743        4856 :     *ok = false;
    1744        4856 :     return impl()->EmptyIdentifier();
    1745             :   }
    1746             : 
    1747     3053101 :   return impl()->GetSymbol();
    1748             : }
    1749             : 
    1750             : template <typename Impl>
    1751    24032593 : typename ParserBase<Impl>::IdentifierT ParserBase<Impl>::ParseIdentifierName(
    1752             :     bool* ok) {
    1753             :   Token::Value next = Next();
    1754    24113617 :   if (next != Token::IDENTIFIER && next != Token::ASYNC &&
    1755             :       next != Token::ENUM && next != Token::AWAIT && next != Token::LET &&
    1756             :       next != Token::STATIC && next != Token::YIELD &&
    1757             :       next != Token::FUTURE_STRICT_RESERVED_WORD &&
    1758             :       next != Token::ESCAPED_KEYWORD &&
    1759             :       next != Token::ESCAPED_STRICT_RESERVED_WORD && !Token::IsKeyword(next)) {
    1760       19682 :     ReportUnexpectedToken(next);
    1761       19682 :     *ok = false;
    1762       19682 :     return impl()->EmptyIdentifier();
    1763             :   }
    1764             : 
    1765    24012918 :   return impl()->GetSymbol();
    1766             : }
    1767             : 
    1768             : template <typename Impl>
    1769      129549 : typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseRegExpLiteral(
    1770      258803 :     bool* ok) {
    1771             :   int pos = peek_position();
    1772      129549 :   if (!scanner()->ScanRegExpPattern()) {
    1773             :     Next();
    1774         295 :     ReportMessage(MessageTemplate::kUnterminatedRegExp);
    1775         295 :     *ok = false;
    1776         295 :     return impl()->EmptyExpression();
    1777             :   }
    1778             : 
    1779             :   IdentifierT js_pattern = impl()->GetNextSymbol();
    1780      129254 :   Maybe<RegExp::Flags> flags = scanner()->ScanRegExpFlags();
    1781      129254 :   if (flags.IsNothing()) {
    1782             :     Next();
    1783         955 :     ReportMessage(MessageTemplate::kMalformedRegExpFlags);
    1784         955 :     *ok = false;
    1785         955 :     return impl()->EmptyExpression();
    1786             :   }
    1787       97489 :   int js_flags = flags.FromJust();
    1788             :   Next();
    1789       97489 :   return factory()->NewRegExpLiteral(js_pattern, js_flags, pos);
    1790             : }
    1791             : 
    1792             : template <typename Impl>
    1793   182032856 : typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePrimaryExpression(
    1794   198391669 :     bool* is_async, bool* ok) {
    1795             :   // PrimaryExpression ::
    1796             :   //   'this'
    1797             :   //   'null'
    1798             :   //   'true'
    1799             :   //   'false'
    1800             :   //   Identifier
    1801             :   //   Number
    1802             :   //   String
    1803             :   //   ArrayLiteral
    1804             :   //   ObjectLiteral
    1805             :   //   RegExpLiteral
    1806             :   //   ClassLiteral
    1807             :   //   '(' Expression ')'
    1808             :   //   TemplateLiteral
    1809             :   //   do Block
    1810             :   //   AsyncFunctionLiteral
    1811             : 
    1812             :   int beg_pos = peek_position();
    1813   182033251 :   switch (peek()) {
    1814             :     case Token::THIS: {
    1815     5865104 :       BindingPatternUnexpectedToken();
    1816     5865105 :       Consume(Token::THIS);
    1817     5689892 :       return impl()->ThisExpression(beg_pos);
    1818             :     }
    1819             : 
    1820             :     case Token::NULL_LITERAL:
    1821             :     case Token::TRUE_LITERAL:
    1822             :     case Token::FALSE_LITERAL:
    1823             :     case Token::SMI:
    1824             :     case Token::NUMBER:
    1825    41403440 :       BindingPatternUnexpectedToken();
    1826    31910595 :       return impl()->ExpressionFromLiteral(Next(), beg_pos);
    1827             : 
    1828             :     case Token::ASYNC:
    1829       87476 :       if (!scanner()->HasAnyLineTerminatorAfterNext() &&
    1830             :           PeekAhead() == Token::FUNCTION) {
    1831       20217 :         Consume(Token::ASYNC);
    1832       20217 :         return ParseAsyncFunctionLiteral(CHECK_OK);
    1833             :       }
    1834             :       // CoverCallExpressionAndAsyncArrowHead
    1835       23521 :       *is_async = true;
    1836             :     /* falls through */
    1837             :     case Token::IDENTIFIER:
    1838             :     case Token::LET:
    1839             :     case Token::STATIC:
    1840             :     case Token::YIELD:
    1841             :     case Token::AWAIT:
    1842             :     case Token::ESCAPED_STRICT_RESERVED_WORD:
    1843             :     case Token::FUTURE_STRICT_RESERVED_WORD: {
    1844             :       // Using eval or arguments in this context is OK even in strict mode.
    1845   109032989 :       IdentifierT name = ParseAndClassifyIdentifier(CHECK_OK);
    1846   108977430 :       return impl()->ExpressionFromIdentifier(name, beg_pos);
    1847             :     }
    1848             : 
    1849             :     case Token::STRING: {
    1850    13121811 :       BindingPatternUnexpectedToken();
    1851    13121812 :       Consume(Token::STRING);
    1852     9798760 :       return impl()->ExpressionFromString(beg_pos);
    1853             :     }
    1854             : 
    1855             :     case Token::ASSIGN_DIV:
    1856             :     case Token::DIV:
    1857      259098 :       classifier()->RecordBindingPatternError(
    1858             :           scanner()->peek_location(), MessageTemplate::kUnexpectedTokenRegExp);
    1859      129549 :       return ParseRegExpLiteral(ok);
    1860             : 
    1861             :     case Token::LBRACK:
    1862     1206713 :       return ParseArrayLiteral(ok);
    1863             : 
    1864             :     case Token::LBRACE:
    1865     2326846 :       return ParseObjectLiteral(ok);
    1866             : 
    1867             :     case Token::LPAREN: {
    1868             :       // Arrow function formal parameters are either a single identifier or a
    1869             :       // list of BindingPattern productions enclosed in parentheses.
    1870             :       // Parentheses are not valid on the LHS of a BindingPattern, so we use the
    1871             :       // is_valid_binding_pattern() check to detect multiple levels of
    1872             :       // parenthesization.
    1873             :       bool pattern_error = !classifier()->is_valid_binding_pattern();
    1874     6491469 :       classifier()->RecordPatternError(scanner()->peek_location(),
    1875             :                                        MessageTemplate::kUnexpectedToken,
    1876             :                                        Token::String(Token::LPAREN));
    1877     6491469 :       if (pattern_error) ArrowFormalParametersUnexpectedToken();
    1878     6491469 :       Consume(Token::LPAREN);
    1879     6491469 :       if (Check(Token::RPAREN)) {
    1880             :         // ()=>x.  The continuation that looks for the => is in
    1881             :         // ParseAssignmentExpression.
    1882      731972 :         classifier()->RecordExpressionError(scanner()->location(),
    1883             :                                             MessageTemplate::kUnexpectedToken,
    1884             :                                             Token::String(Token::RPAREN));
    1885      651076 :         return factory()->NewEmptyParentheses(beg_pos);
    1886             :       }
    1887             :       // Heuristically try to detect immediately called functions before
    1888             :       // seeing the call parentheses.
    1889    11306908 :       if (peek() == Token::FUNCTION ||
    1890             :           (peek() == Token::ASYNC && PeekAhead() == Token::FUNCTION)) {
    1891      965798 :         function_state_->set_next_function_is_likely_called();
    1892             :       }
    1893     6173571 :       ExpressionT expr = ParseExpressionCoverGrammar(true, CHECK_OK);
    1894     5974480 :       Expect(Token::RPAREN, CHECK_OK);
    1895     5972248 :       return expr;
    1896             :     }
    1897             : 
    1898             :     case Token::CLASS: {
    1899       66484 :       BindingPatternUnexpectedToken();
    1900       66484 :       Consume(Token::CLASS);
    1901             :       int class_token_pos = position();
    1902       21928 :       IdentifierT name = impl()->EmptyIdentifier();
    1903       66484 :       bool is_strict_reserved_name = false;
    1904       66484 :       Scanner::Location class_name_location = Scanner::Location::invalid();
    1905       66484 :       if (peek_any_identifier()) {
    1906       23999 :         name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name,
    1907       24047 :                                                    CHECK_OK);
    1908       23903 :         class_name_location = scanner()->location();
    1909             :       }
    1910             :       return ParseClassLiteral(name, class_name_location,
    1911       66388 :                                is_strict_reserved_name, class_token_pos, ok);
    1912             :     }
    1913             : 
    1914             :     case Token::TEMPLATE_SPAN:
    1915             :     case Token::TEMPLATE_TAIL:
    1916       60978 :       BindingPatternUnexpectedToken();
    1917       60978 :       return ParseTemplateLiteral(impl()->NoTemplateTag(), beg_pos, false, ok);
    1918             : 
    1919             :     case Token::MOD:
    1920     2249206 :       if (allow_natives() || extension_ != NULL) {
    1921     2249046 :         BindingPatternUnexpectedToken();
    1922     2249046 :         return ParseV8Intrinsic(ok);
    1923             :       }
    1924             :       break;
    1925             : 
    1926             :     case Token::DO:
    1927        1474 :       if (allow_harmony_do_expressions()) {
    1928        1267 :         BindingPatternUnexpectedToken();
    1929        1267 :         return ParseDoExpression(ok);
    1930             :       }
    1931             :       break;
    1932             : 
    1933             :     default:
    1934             :       break;
    1935             :   }
    1936             : 
    1937       78617 :   ReportUnexpectedToken(Next());
    1938       78617 :   *ok = false;
    1939       78617 :   return impl()->EmptyExpression();
    1940             : }
    1941             : 
    1942             : template <typename Impl>
    1943             : typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseExpression(
    1944             :     bool accept_IN, bool* ok) {
    1945    43025855 :   ExpressionClassifier classifier(this);
    1946    43025864 :   ExpressionT result = ParseExpressionCoverGrammar(accept_IN, CHECK_OK);
    1947    85542933 :   impl()->RewriteNonPattern(CHECK_OK);
    1948     7655733 :   return result;
    1949             : }
    1950             : 
    1951             : template <typename Impl>
    1952             : typename ParserBase<Impl>::ExpressionT
    1953   106507595 : ParserBase<Impl>::ParseExpressionCoverGrammar(bool accept_IN, bool* ok) {
    1954             :   // Expression ::
    1955             :   //   AssignmentExpression
    1956             :   //   Expression ',' AssignmentExpression
    1957             : 
    1958             :   ExpressionT result = impl()->EmptyExpression();
    1959             :   while (true) {
    1960             :     int comma_pos = position();
    1961    58301130 :     ExpressionClassifier binding_classifier(this);
    1962             :     ExpressionT right;
    1963    58301140 :     if (Check(Token::ELLIPSIS)) {
    1964             :       // 'x, y, ...z' in CoverParenthesizedExpressionAndArrowParameterList only
    1965             :       // as the formal parameters of'(x, y, ...z) => foo', and is not itself a
    1966             :       // valid expression.
    1967       25402 :       classifier()->RecordExpressionError(scanner()->location(),
    1968             :                                           MessageTemplate::kUnexpectedToken,
    1969             :                                           Token::String(Token::ELLIPSIS));
    1970             :       int ellipsis_pos = position();
    1971             :       int pattern_pos = peek_position();
    1972       13253 :       ExpressionT pattern = ParsePrimaryExpression(CHECK_OK);
    1973       12101 :       ValidateBindingPattern(CHECK_OK);
    1974       11199 :       right = factory()->NewSpread(pattern, ellipsis_pos, pattern_pos);
    1975             :     } else {
    1976    58439958 :       right = ParseAssignmentExpression(accept_IN, CHECK_OK);
    1977             :     }
    1978             :     // No need to accumulate binding pattern-related errors, since
    1979             :     // an Expression can't be a binding pattern anyway.
    1980             :     AccumulateNonBindingPatternErrors();
    1981    57889408 :     if (!impl()->IsIdentifier(right)) classifier()->RecordNonSimpleParameter();
    1982    57889408 :     if (impl()->IsEmptyExpression(result)) {
    1983             :       // First time through the loop.
    1984             :       result = right;
    1985             :     } else {
    1986      609983 :       result =
    1987             :           factory()->NewBinaryOperation(Token::COMMA, result, right, comma_pos);
    1988             :     }
    1989             : 
    1990    57889408 :     if (!Check(Token::COMMA)) break;
    1991             : 
    1992      620179 :     if (right->IsSpread()) {
    1993         768 :       classifier()->RecordArrowFormalParametersError(
    1994             :           scanner()->location(), MessageTemplate::kParamAfterRest);
    1995             :     }
    1996             : 
    1997     1177904 :     if (allow_harmony_trailing_commas() && peek() == Token::RPAREN &&
    1998             :         PeekAhead() == Token::ARROW) {
    1999             :       // a trailing comma is allowed at the end of an arrow parameter list
    2000             :       break;
    2001             :     }
    2002             : 
    2003             :     // Pass on the 'set_next_function_is_likely_called' flag if we have
    2004             :     // several function literals separated by comma.
    2005      619396 :     if (peek() == Token::FUNCTION &&
    2006             :         function_state_->previous_function_was_likely_called()) {
    2007          29 :       function_state_->set_next_function_is_likely_called();
    2008             :     }
    2009             :   }
    2010             : 
    2011    57270001 :   return result;
    2012             : }
    2013             : 
    2014             : template <typename Impl>
    2015     1206713 : typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseArrayLiteral(
    2016    26828334 :     bool* ok) {
    2017             :   // ArrayLiteral ::
    2018             :   //   '[' Expression? (',' Expression?)* ']'
    2019             : 
    2020             :   int pos = peek_position();
    2021      857524 :   ExpressionListT values = impl()->NewExpressionList(4);
    2022             :   int first_spread_index = -1;
    2023     1206713 :   Expect(Token::LBRACK, CHECK_OK);
    2024    17056945 :   while (peek() != Token::RBRACK) {
    2025             :     ExpressionT elem;
    2026    15860738 :     if (peek() == Token::COMMA) {
    2027     1423841 :       elem = impl()->GetLiteralTheHole(peek_position());
    2028    13007804 :     } else if (peek() == Token::ELLIPSIS) {
    2029             :       int start_pos = peek_position();
    2030       47045 :       Consume(Token::ELLIPSIS);
    2031             :       int expr_pos = peek_position();
    2032       47669 :       ExpressionT argument = ParseAssignmentExpression(true, CHECK_OK);
    2033       45797 :       elem = factory()->NewSpread(argument, start_pos, expr_pos);
    2034             : 
    2035       45797 :       if (first_spread_index < 0) {
    2036       41900 :         first_spread_index = values->length();
    2037             :       }
    2038             : 
    2039       69543 :       if (argument->IsAssignment()) {
    2040        4642 :         classifier()->RecordPatternError(
    2041             :             Scanner::Location(start_pos, scanner()->location().end_pos),
    2042             :             MessageTemplate::kInvalidDestructuringTarget);
    2043             :       } else {
    2044       41155 :         CheckDestructuringElement(argument, start_pos,
    2045             :                                   scanner()->location().end_pos);
    2046             :       }
    2047             : 
    2048       45797 :       if (peek() == Token::COMMA) {
    2049       10464 :         classifier()->RecordPatternError(
    2050             :             Scanner::Location(start_pos, scanner()->location().end_pos),
    2051             :             MessageTemplate::kElementAfterRest);
    2052             :       }
    2053             :     } else {
    2054             :       int beg_pos = peek_position();
    2055    12966091 :       elem = ParseAssignmentExpression(true, CHECK_OK);
    2056    12951529 :       CheckDestructuringElement(elem, beg_pos, scanner()->location().end_pos);
    2057             :     }
    2058    15850260 :     values->Add(elem, zone_);
    2059    15850260 :     if (peek() != Token::RBRACK) {
    2060    15176282 :       Expect(Token::COMMA, CHECK_OK);
    2061             :     }
    2062             :   }
    2063     1196207 :   Expect(Token::RBRACK, CHECK_OK);
    2064             : 
    2065             :   ExpressionT result =
    2066      770437 :       factory()->NewArrayLiteral(values, first_spread_index, pos);
    2067     1196207 :   if (first_spread_index >= 0) {
    2068       19210 :     result = factory()->NewRewritableExpression(result);
    2069       19210 :     impl()->QueueNonPatternForRewriting(result, ok);
    2070       41900 :     if (!*ok) {
    2071             :       // If the non-pattern rewriting mechanism is used in the future for
    2072             :       // rewriting other things than spreads, this error message will have
    2073             :       // to change.  Also, this error message will never appear while pre-
    2074             :       // parsing (this is OK, as it is an implementation limitation).
    2075           0 :       ReportMessage(MessageTemplate::kTooManySpreads);
    2076           0 :       return impl()->EmptyExpression();
    2077             :     }
    2078             :   }
    2079     1196207 :   return result;
    2080             : }
    2081             : 
    2082             : template <class Impl>
    2083     6914802 : bool ParserBase<Impl>::SetPropertyKindFromToken(Token::Value token,
    2084             :                                                 PropertyKind* kind) {
    2085             :   // This returns true, setting the property kind, iff the given token is one
    2086             :   // which must occur after a property name, indicating that the previous token
    2087             :   // was in fact a name and not a modifier (like the "get" in "get x").
    2088     6914802 :   switch (token) {
    2089             :     case Token::COLON:
    2090     6211588 :       *kind = PropertyKind::kValueProperty;
    2091             :       return true;
    2092             :     case Token::COMMA:
    2093             :     case Token::RBRACE:
    2094             :     case Token::ASSIGN:
    2095      257702 :       *kind = PropertyKind::kShorthandProperty;
    2096             :       return true;
    2097             :     case Token::LPAREN:
    2098      363204 :       *kind = PropertyKind::kMethodProperty;
    2099             :       return true;
    2100             :     case Token::MUL:
    2101             :     case Token::SEMICOLON:
    2102        6138 :       *kind = PropertyKind::kClassField;
    2103             :       return true;
    2104             :     default:
    2105             :       break;
    2106             :   }
    2107             :   return false;
    2108             : }
    2109             : 
    2110             : template <class Impl>
    2111     6988139 : typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePropertyName(
    2112             :     IdentifierT* name, PropertyKind* kind, bool* is_generator, bool* is_get,
    2113     7196008 :     bool* is_set, bool* is_async, bool* is_computed_name, bool* ok) {
    2114             :   DCHECK(*kind == PropertyKind::kNotSet);
    2115             :   DCHECK(!*is_generator);
    2116             :   DCHECK(!*is_get);
    2117             :   DCHECK(!*is_set);
    2118             :   DCHECK(!*is_async);
    2119             :   DCHECK(!*is_computed_name);
    2120             : 
    2121     6988139 :   *is_generator = Check(Token::MUL);
    2122     6988139 :   if (*is_generator) {
    2123       31598 :     *kind = PropertyKind::kMethodProperty;
    2124             :   }
    2125             : 
    2126             :   Token::Value token = peek();
    2127             :   int pos = peek_position();
    2128             : 
    2129     7006581 :   if (!*is_generator && token == Token::ASYNC &&
    2130             :       !scanner()->HasAnyLineTerminatorAfterNext()) {
    2131       18056 :     Consume(Token::ASYNC);
    2132             :     token = peek();
    2133       26028 :     if (token == Token::MUL && allow_harmony_async_iteration() &&
    2134        3506 :         !scanner()->HasAnyLineTerminatorBeforeNext()) {
    2135        3506 :       Consume(Token::MUL);
    2136             :       token = peek();
    2137        3506 :       *is_generator = true;
    2138       14550 :     } else if (SetPropertyKindFromToken(token, kind)) {
    2139        4128 :       *name = impl()->GetSymbol();  // TODO(bakkot) specialize on 'async'
    2140        2064 :       impl()->PushLiteralName(*name);
    2141        4128 :       return factory()->NewStringLiteral(*name, pos);
    2142             :     }
    2143       13928 :     *kind = PropertyKind::kMethodProperty;
    2144       13928 :     *is_async = true;
    2145             :     pos = peek_position();
    2146             :   }
    2147             : 
    2148     6984013 :   if (token == Token::IDENTIFIER && !*is_generator && !*is_async) {
    2149             :     // This is checking for 'get' and 'set' in particular.
    2150     4008971 :     Consume(Token::IDENTIFIER);
    2151             :     token = peek();
    2152     4071041 :     if (SetPropertyKindFromToken(token, kind) ||
    2153             :         !scanner()->IsGetOrSet(is_get, is_set)) {
    2154     3948112 :       *name = impl()->GetSymbol();
    2155     3359400 :       impl()->PushLiteralName(*name);
    2156     3948112 :       return factory()->NewStringLiteral(*name, pos);
    2157             :     }
    2158       60859 :     *kind = PropertyKind::kAccessorProperty;
    2159             :     pos = peek_position();
    2160             :   }
    2161             : 
    2162             :   // For non computed property names we normalize the name a bit:
    2163             :   //
    2164             :   //   "12" -> 12
    2165             :   //   12.3 -> "12.3"
    2166             :   //   12.30 -> "12.3"
    2167             :   //   identifier -> "identifier"
    2168             :   //
    2169             :   // This is important because we use the property name as a key in a hash
    2170             :   // table when we compute constant properties.
    2171     1089361 :   ExpressionT expression = impl()->EmptyExpression();
    2172     3035901 :   switch (token) {
    2173             :     case Token::STRING:
    2174     1186915 :       Consume(Token::STRING);
    2175     1186915 :       *name = impl()->GetSymbol();
    2176     1186915 :       break;
    2177             : 
    2178             :     case Token::SMI:
    2179     1620964 :       Consume(Token::SMI);
    2180     1620964 :       *name = impl()->GetNumberAsSymbol();
    2181     1620964 :       break;
    2182             : 
    2183             :     case Token::NUMBER:
    2184        9189 :       Consume(Token::NUMBER);
    2185        9189 :       *name = impl()->GetNumberAsSymbol();
    2186        9189 :       break;
    2187             : 
    2188             :     case Token::LBRACK: {
    2189       61434 :       *name = impl()->EmptyIdentifier();
    2190       61434 :       *is_computed_name = true;
    2191       61434 :       Consume(Token::LBRACK);
    2192       61434 :       ExpressionClassifier computed_name_classifier(this);
    2193       62082 :       expression = ParseAssignmentExpression(true, CHECK_OK);
    2194       60330 :       impl()->RewriteNonPattern(CHECK_OK);
    2195             :       AccumulateFormalParameterContainmentErrors();
    2196       60546 :       Expect(Token::RBRACK, CHECK_OK);
    2197             :       break;
    2198             :     }
    2199             : 
    2200             :     case Token::ELLIPSIS:
    2201       34153 :       if (allow_harmony_object_rest_spread()) {
    2202       19225 :         *name = impl()->EmptyIdentifier();
    2203       19225 :         Consume(Token::ELLIPSIS);
    2204       20041 :         expression = ParseAssignmentExpression(true, CHECK_OK);
    2205       17737 :         *kind = PropertyKind::kSpreadProperty;
    2206             : 
    2207       17737 :         if (expression->IsAssignment()) {
    2208        1056 :           classifier()->RecordPatternError(
    2209             :               scanner()->location(),
    2210             :               MessageTemplate::kInvalidDestructuringTarget);
    2211             :         } else {
    2212       17209 :           CheckDestructuringElement(expression, pos,
    2213             :                                     scanner()->location().end_pos);
    2214             :         }
    2215             : 
    2216       17737 :         if (peek() != Token::RBRACE) {
    2217       10620 :           classifier()->RecordPatternError(scanner()->location(),
    2218             :                                            MessageTemplate::kElementAfterRest);
    2219             :         }
    2220       17737 :         return expression;
    2221             :       }
    2222             : 
    2223             :     default:
    2224      148548 :       *name = ParseIdentifierName(CHECK_OK);
    2225             :       break;
    2226             :   }
    2227             : 
    2228     2996183 :   if (*kind == PropertyKind::kNotSet) {
    2229     2891286 :     SetPropertyKindFromToken(peek(), kind);
    2230             :   }
    2231             : 
    2232     2996183 :   if (*is_computed_name) {
    2233       30591 :     return expression;
    2234             :   }
    2235             : 
    2236     1899163 :   impl()->PushLiteralName(*name);
    2237             : 
    2238             :   uint32_t index;
    2239             :   return impl()->IsArrayIndex(*name, &index)
    2240     4835448 :              ? factory()->NewNumberLiteral(index, pos)
    2241     4835448 :              : factory()->NewStringLiteral(*name, pos);
    2242             : }
    2243             : 
    2244             : template <typename Impl>
    2245             : typename ParserBase<Impl>::ClassLiteralPropertyT
    2246      404498 : ParserBase<Impl>::ParseClassPropertyDefinition(
    2247             :     ClassLiteralChecker* checker, bool has_extends, bool* is_computed_name,
    2248             :     bool* has_seen_constructor, ClassLiteralProperty::Kind* property_kind,
    2249      834688 :     bool* is_static, bool* has_name_static_property, bool* ok) {
    2250             :   DCHECK_NOT_NULL(has_seen_constructor);
    2251             :   DCHECK_NOT_NULL(has_name_static_property);
    2252      404498 :   bool is_get = false;
    2253      404498 :   bool is_set = false;
    2254      404498 :   bool is_generator = false;
    2255      404498 :   bool is_async = false;
    2256      404498 :   *is_static = false;
    2257      404498 :   *property_kind = ClassLiteralProperty::METHOD;
    2258      404498 :   PropertyKind kind = PropertyKind::kNotSet;
    2259             : 
    2260             :   Token::Value name_token = peek();
    2261             : 
    2262             :   int function_token_position = scanner()->peek_location().beg_pos;
    2263      440154 :   IdentifierT name = impl()->EmptyIdentifier();
    2264             :   ExpressionT name_expression;
    2265      404498 :   if (name_token == Token::STATIC) {
    2266       29482 :     Consume(Token::STATIC);
    2267             :     function_token_position = scanner()->peek_location().beg_pos;
    2268       29482 :     if (peek() == Token::LPAREN) {
    2269         288 :       kind = PropertyKind::kMethodProperty;
    2270         288 :       name = impl()->GetSymbol();  // TODO(bakkot) specialize on 'static'
    2271         288 :       name_expression = factory()->NewStringLiteral(name, position());
    2272       87582 :     } else if (peek() == Token::ASSIGN || peek() == Token::SEMICOLON ||
    2273             :                peek() == Token::RBRACE) {
    2274         192 :       name = impl()->GetSymbol();  // TODO(bakkot) specialize on 'static'
    2275         192 :       name_expression = factory()->NewStringLiteral(name, position());
    2276             :     } else {
    2277       29002 :       *is_static = true;
    2278       29002 :       name_expression = ParsePropertyName(
    2279             :           &name, &kind, &is_generator, &is_get, &is_set, &is_async,
    2280       29002 :           is_computed_name, CHECK_OK_CUSTOM(EmptyClassLiteralProperty));
    2281             :     }
    2282             :   } else {
    2283      375016 :     name_expression = ParsePropertyName(
    2284             :         &name, &kind, &is_generator, &is_get, &is_set, &is_async,
    2285      375664 :         is_computed_name, CHECK_OK_CUSTOM(EmptyClassLiteralProperty));
    2286             :   }
    2287             : 
    2288      432127 :   if (!*has_name_static_property && *is_static && impl()->IsName(name)) {
    2289         126 :     *has_name_static_property = true;
    2290             :   }
    2291             : 
    2292      403132 :   switch (kind) {
    2293             :     case PropertyKind::kClassField:
    2294             :     case PropertyKind::kNotSet:  // This case is a name followed by a name or
    2295             :                                  // other property. Here we have to assume
    2296             :                                  // that's an uninitialized field followed by a
    2297             :                                  // linebreak followed by a property, with ASI
    2298             :                                  // adding the semicolon. If not, there will be
    2299             :                                  // a syntax error after parsing the first name
    2300             :                                  // as an uninitialized field.
    2301             :     case PropertyKind::kShorthandProperty:
    2302             :     case PropertyKind::kValueProperty:
    2303       19530 :       if (allow_harmony_class_fields()) {
    2304       16896 :         bool has_initializer = Check(Token::ASSIGN);
    2305             :         ExpressionT function_literal = ParseClassFieldForInitializer(
    2306       17088 :             has_initializer, CHECK_OK_CUSTOM(EmptyClassLiteralProperty));
    2307       17280 :         ExpectSemicolon(CHECK_OK_CUSTOM(EmptyClassLiteralProperty));
    2308       14976 :         *property_kind = ClassLiteralProperty::FIELD;
    2309             :         return factory()->NewClassLiteralProperty(
    2310             :             name_expression, function_literal, *property_kind, *is_static,
    2311       14976 :             *is_computed_name);
    2312             :       } else {
    2313        2634 :         ReportUnexpectedToken(Next());
    2314        2634 :         *ok = false;
    2315        2634 :         return impl()->EmptyClassLiteralProperty();
    2316             :       }
    2317             : 
    2318             :     case PropertyKind::kMethodProperty: {
    2319             :       DCHECK(!is_get && !is_set);
    2320             : 
    2321             :       // MethodDefinition
    2322             :       //    PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}'
    2323             :       //    '*' PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}'
    2324             :       //    async PropertyName '(' StrictFormalParameters ')'
    2325             :       //        '{' FunctionBody '}'
    2326             :       //    async '*' PropertyName '(' StrictFormalParameters ')'
    2327             :       //        '{' FunctionBody '}'
    2328             : 
    2329      348866 :       if (!*is_computed_name) {
    2330      341849 :         checker->CheckClassMethodName(
    2331             :             name_token, PropertyKind::kMethodProperty, is_generator, is_async,
    2332      342617 :             *is_static, CHECK_OK_CUSTOM(EmptyClassLiteralProperty));
    2333             :       }
    2334             : 
    2335      347274 :       FunctionKind kind = MethodKindFor(is_generator, is_async);
    2336             : 
    2337      677278 :       if (!*is_static && impl()->IsConstructor(name)) {
    2338       15275 :         *has_seen_constructor = true;
    2339       15275 :         kind = has_extends ? FunctionKind::kDerivedConstructor
    2340             :                            : FunctionKind::kBaseConstructor;
    2341             :       }
    2342             : 
    2343             :       ExpressionT value = impl()->ParseFunctionLiteral(
    2344             :           name, scanner()->location(), kSkipFunctionNameCheck, kind,
    2345             :           FLAG_harmony_function_tostring ? function_token_position
    2346             :                                          : kNoSourcePosition,
    2347             :           FunctionLiteral::kAccessorOrMethod, language_mode(),
    2348      699252 :           CHECK_OK_CUSTOM(EmptyClassLiteralProperty));
    2349             : 
    2350      337586 :       *property_kind = ClassLiteralProperty::METHOD;
    2351             :       return factory()->NewClassLiteralProperty(name_expression, value,
    2352             :                                                 *property_kind, *is_static,
    2353      644956 :                                                 *is_computed_name);
    2354             :     }
    2355             : 
    2356             :     case PropertyKind::kAccessorProperty: {
    2357             :       DCHECK((is_get || is_set) && !is_generator && !is_async);
    2358             : 
    2359       34736 :       if (!*is_computed_name) {
    2360       30196 :         checker->CheckClassMethodName(
    2361             :             name_token, PropertyKind::kAccessorProperty, false, false,
    2362       30676 :             *is_static, CHECK_OK_CUSTOM(EmptyClassLiteralProperty));
    2363             :         // Make sure the name expression is a string since we need a Name for
    2364             :         // Runtime_DefineAccessorPropertyUnchecked and since we can determine
    2365             :         // this statically we can skip the extra runtime check.
    2366       29124 :         name_expression =
    2367             :             factory()->NewStringLiteral(name, name_expression->position());
    2368             :       }
    2369             : 
    2370             :       FunctionKind kind = is_get ? FunctionKind::kGetterFunction
    2371       33664 :                                  : FunctionKind::kSetterFunction;
    2372             : 
    2373             :       FunctionLiteralT value = impl()->ParseFunctionLiteral(
    2374             :           name, scanner()->location(), kSkipFunctionNameCheck, kind,
    2375             :           FLAG_harmony_function_tostring ? function_token_position
    2376             :                                          : kNoSourcePosition,
    2377             :           FunctionLiteral::kAccessorOrMethod, language_mode(),
    2378       69728 :           CHECK_OK_CUSTOM(EmptyClassLiteralProperty));
    2379             : 
    2380       20697 :       if (!*is_computed_name) {
    2381       16451 :         impl()->AddAccessorPrefixToFunctionName(is_get, value, name);
    2382             :       }
    2383             : 
    2384       28696 :       *property_kind =
    2385             :           is_get ? ClassLiteralProperty::GETTER : ClassLiteralProperty::SETTER;
    2386             :       return factory()->NewClassLiteralProperty(name_expression, value,
    2387             :                                                 *property_kind, *is_static,
    2388       41394 :                                                 *is_computed_name);
    2389             :     }
    2390             :     case PropertyKind::kSpreadProperty:
    2391           0 :       UNREACHABLE();
    2392             :   }
    2393           0 :   UNREACHABLE();
    2394             :   return impl()->EmptyClassLiteralProperty();
    2395             : }
    2396             : 
    2397             : template <typename Impl>
    2398             : typename ParserBase<Impl>::FunctionLiteralT
    2399       16896 : ParserBase<Impl>::ParseClassFieldForInitializer(bool has_initializer,
    2400       58560 :                                                 bool* ok) {
    2401             :   // Makes a concise method which evaluates and returns the initialized value
    2402             :   // (or undefined if absent).
    2403             :   FunctionKind kind = FunctionKind::kConciseMethod;
    2404       16896 :   DeclarationScope* initializer_scope = NewFunctionScope(kind);
    2405        8256 :   initializer_scope->set_start_position(scanner()->location().end_pos);
    2406       16896 :   FunctionState initializer_state(&function_state_, &scope_, initializer_scope);
    2407             :   DCHECK_EQ(initializer_scope, scope());
    2408             :   scope()->SetLanguageMode(STRICT);
    2409       16896 :   ExpressionClassifier expression_classifier(this);
    2410             :   ExpressionT value;
    2411       16896 :   if (has_initializer) {
    2412        5952 :     value = this->ParseAssignmentExpression(
    2413        6144 :         true, CHECK_OK_CUSTOM(EmptyFunctionLiteral));
    2414        5568 :     impl()->RewriteNonPattern(CHECK_OK_CUSTOM(EmptyFunctionLiteral));
    2415             :   } else {
    2416        5472 :     value = factory()->NewUndefinedLiteral(kNoSourcePosition);
    2417             :   }
    2418             :   initializer_scope->set_end_position(scanner()->location().end_pos);
    2419             :   typename Types::StatementList body = impl()->NewStatementList(1);
    2420        8256 :   body->Add(factory()->NewReturnStatement(value, kNoSourcePosition), zone());
    2421             :   FunctionLiteralT function_literal = factory()->NewFunctionLiteral(
    2422             :       impl()->EmptyIdentifierString(), initializer_scope, body,
    2423             :       initializer_state.expected_property_count(), 0, 0,
    2424             :       FunctionLiteral::kNoDuplicateParameters,
    2425             :       FunctionLiteral::kAnonymousExpression, default_eager_compile_hint_,
    2426       16512 :       initializer_scope->start_position(), true, GetNextFunctionLiteralId());
    2427       16512 :   return function_literal;
    2428             : }
    2429             : 
    2430             : template <typename Impl>
    2431             : typename ParserBase<Impl>::ObjectLiteralPropertyT
    2432     6584121 : ParserBase<Impl>::ParseObjectPropertyDefinition(ObjectLiteralChecker* checker,
    2433             :                                                 bool* is_computed_name,
    2434             :                                                 bool* is_rest_property,
    2435    20053086 :                                                 bool* ok) {
    2436     6584121 :   bool is_get = false;
    2437     6584121 :   bool is_set = false;
    2438     6584121 :   bool is_generator = false;
    2439     6584121 :   bool is_async = false;
    2440     6584121 :   PropertyKind kind = PropertyKind::kNotSet;
    2441             : 
    2442     6592475 :   IdentifierT name = impl()->EmptyIdentifier();
    2443             :   Token::Value name_token = peek();
    2444             :   int next_beg_pos = scanner()->peek_location().beg_pos;
    2445             :   int next_end_pos = scanner()->peek_location().end_pos;
    2446             : 
    2447        9594 :   ExpressionT name_expression = ParsePropertyName(
    2448             :       &name, &kind, &is_generator, &is_get, &is_set, &is_async,
    2449     6595527 :       is_computed_name, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
    2450             : 
    2451     6563506 :   switch (kind) {
    2452             :     case PropertyKind::kSpreadProperty:
    2453             :       DCHECK(allow_harmony_object_rest_spread());
    2454             :       DCHECK(!is_get && !is_set && !is_generator && !is_async &&
    2455             :              !*is_computed_name);
    2456             :       DCHECK(name_token == Token::ELLIPSIS);
    2457             : 
    2458       17737 :       *is_computed_name = true;
    2459       17737 :       *is_rest_property = true;
    2460             : 
    2461             :       return factory()->NewObjectLiteralProperty(
    2462             :           impl()->GetLiteralTheHole(kNoSourcePosition), name_expression,
    2463       16286 :           ObjectLiteralProperty::SPREAD, true);
    2464             : 
    2465             :     case PropertyKind::kValueProperty: {
    2466             :       DCHECK(!is_get && !is_set && !is_generator && !is_async);
    2467             : 
    2468     6210535 :       if (!*is_computed_name) {
    2469     6169542 :         checker->CheckDuplicateProto(name_token);
    2470             :       }
    2471     6210535 :       Consume(Token::COLON);
    2472             :       int beg_pos = peek_position();
    2473     1488661 :       ExpressionT value = ParseAssignmentExpression(
    2474     6231430 :           true, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
    2475     6185662 :       CheckDestructuringElement(value, beg_pos, scanner()->location().end_pos);
    2476             : 
    2477             :       ObjectLiteralPropertyT result = factory()->NewObjectLiteralProperty(
    2478     4696999 :           name_expression, value, *is_computed_name);
    2479             : 
    2480     4697000 :       if (!*is_computed_name) {
    2481     4681466 :         impl()->SetFunctionNameFromPropertyName(result, name);
    2482             :       }
    2483             : 
    2484     6185661 :       return result;
    2485             :     }
    2486             : 
    2487             :     case PropertyKind::kShorthandProperty: {
    2488             :       // PropertyDefinition
    2489             :       //    IdentifierReference
    2490             :       //    CoverInitializedName
    2491             :       //
    2492             :       // CoverInitializedName
    2493             :       //    IdentifierReference Initializer?
    2494             :       DCHECK(!is_get && !is_set && !is_generator && !is_async);
    2495             : 
    2496      248390 :       if (!Token::IsIdentifier(name_token, language_mode(),
    2497             :                                this->is_generator(),
    2498      990331 :                                parsing_module_ || is_async_function())) {
    2499        9669 :         ReportUnexpectedToken(Next());
    2500        9669 :         *ok = false;
    2501        9669 :         return impl()->EmptyObjectLiteralProperty();
    2502             :       }
    2503             : 
    2504             :       DCHECK(!*is_computed_name);
    2505             : 
    2506      262026 :       if (classifier()->duplicate_finder() != nullptr &&
    2507             :           scanner()->IsDuplicateSymbol(classifier()->duplicate_finder(),
    2508             :                                        ast_value_factory())) {
    2509        1016 :         classifier()->RecordDuplicateFormalParameterError(
    2510             :             scanner()->location());
    2511             :       }
    2512             : 
    2513      413593 :       if (impl()->IsEvalOrArguments(name) && is_strict(language_mode())) {
    2514        4032 :         classifier()->RecordBindingPatternError(
    2515             :             scanner()->location(), MessageTemplate::kStrictEvalArguments);
    2516             :       }
    2517             : 
    2518      238721 :       if (name_token == Token::LET) {
    2519         124 :         classifier()->RecordLetPatternError(
    2520             :             scanner()->location(), MessageTemplate::kLetInLexicalBinding);
    2521             :       }
    2522      238721 :       if (name_token == Token::AWAIT) {
    2523             :         DCHECK(!is_async_function());
    2524         384 :         classifier()->RecordAsyncArrowFormalParametersError(
    2525             :             Scanner::Location(next_beg_pos, next_end_pos),
    2526             :             MessageTemplate::kAwaitBindingIdentifier);
    2527             :       }
    2528      238721 :       ExpressionT lhs = impl()->ExpressionFromIdentifier(name, next_beg_pos);
    2529      238721 :       CheckDestructuringElement(lhs, next_beg_pos, next_end_pos);
    2530             : 
    2531             :       ExpressionT value;
    2532      238721 :       if (peek() == Token::ASSIGN) {
    2533       40800 :         Consume(Token::ASSIGN);
    2534       40800 :         ExpressionClassifier rhs_classifier(this);
    2535             :         ExpressionT rhs = ParseAssignmentExpression(
    2536       40992 :             true, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
    2537       40416 :         impl()->RewriteNonPattern(CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
    2538             :         AccumulateFormalParameterContainmentErrors();
    2539       16857 :         value = factory()->NewAssignment(Token::ASSIGN, lhs, rhs,
    2540             :                                          kNoSourcePosition);
    2541       40416 :         classifier()->RecordExpressionError(
    2542             :             Scanner::Location(next_beg_pos, scanner()->location().end_pos),
    2543             :             MessageTemplate::kInvalidCoverInitializedName);
    2544             : 
    2545       16857 :         impl()->SetFunctionNameFromIdentifierRef(rhs, lhs);
    2546             :       } else {
    2547             :         value = lhs;
    2548             :       }
    2549             : 
    2550             :       return factory()->NewObjectLiteralProperty(
    2551      340496 :           name_expression, value, ObjectLiteralProperty::COMPUTED, false);
    2552             :     }
    2553             : 
    2554             :     case PropertyKind::kMethodProperty: {
    2555             :       DCHECK(!is_get && !is_set);
    2556             : 
    2557             :       // MethodDefinition
    2558             :       //    PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}'
    2559             :       //    '*' PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}'
    2560             : 
    2561       59048 :       classifier()->RecordPatternError(
    2562             :           Scanner::Location(next_beg_pos, scanner()->location().end_pos),
    2563             :           MessageTemplate::kInvalidDestructuringTarget);
    2564             : 
    2565       59048 :       FunctionKind kind = MethodKindFor(is_generator, is_async);
    2566             : 
    2567       19038 :       ExpressionT value = impl()->ParseFunctionLiteral(
    2568             :           name, scanner()->location(), kSkipFunctionNameCheck, kind,
    2569             :           FLAG_harmony_function_tostring ? next_beg_pos : kNoSourcePosition,
    2570             :           FunctionLiteral::kAccessorOrMethod, language_mode(),
    2571      124168 :           CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
    2572             : 
    2573             :       return factory()->NewObjectLiteralProperty(
    2574             :           name_expression, value, ObjectLiteralProperty::COMPUTED,
    2575       55404 :           *is_computed_name);
    2576             :     }
    2577             : 
    2578             :     case PropertyKind::kAccessorProperty: {
    2579             :       DCHECK((is_get || is_set) && !(is_set && is_get) && !is_generator &&
    2580             :              !is_async);
    2581             : 
    2582       25739 :       classifier()->RecordPatternError(
    2583             :           Scanner::Location(next_beg_pos, scanner()->location().end_pos),
    2584             :           MessageTemplate::kInvalidDestructuringTarget);
    2585             : 
    2586       25739 :       if (!*is_computed_name) {
    2587             :         // Make sure the name expression is a string since we need a Name for
    2588             :         // Runtime_DefineAccessorPropertyUnchecked and since we can determine
    2589             :         // this statically we can skip the extra runtime check.
    2590       24868 :         name_expression =
    2591             :             factory()->NewStringLiteral(name, name_expression->position());
    2592             :       }
    2593             : 
    2594             :       FunctionKind kind = is_get ? FunctionKind::kGetterFunction
    2595       25739 :                                  : FunctionKind::kSetterFunction;
    2596             : 
    2597        6982 :       FunctionLiteralT value = impl()->ParseFunctionLiteral(
    2598             :           name, scanner()->location(), kSkipFunctionNameCheck, kind,
    2599             :           FLAG_harmony_function_tostring ? next_beg_pos : kNoSourcePosition,
    2600             :           FunctionLiteral::kAccessorOrMethod, language_mode(),
    2601       53178 :           CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
    2602             : 
    2603       14707 :       if (!*is_computed_name) {
    2604       14164 :         impl()->AddAccessorPrefixToFunctionName(is_get, value, name);
    2605             :       }
    2606             : 
    2607             :       return factory()->NewObjectLiteralProperty(
    2608             :           name_expression, value, is_get ? ObjectLiteralProperty::GETTER
    2609             :                                          : ObjectLiteralProperty::SETTER,
    2610       29414 :           *is_computed_name);
    2611             :     }
    2612             : 
    2613             :     case PropertyKind::kClassField:
    2614             :     case PropertyKind::kNotSet:
    2615        2057 :       ReportUnexpectedToken(Next());
    2616        2057 :       *ok = false;
    2617        2057 :       return impl()->EmptyObjectLiteralProperty();
    2618             :   }
    2619           0 :   UNREACHABLE();
    2620             :   return impl()->EmptyObjectLiteralProperty();
    2621             : }
    2622             : 
    2623             : template <typename Impl>
    2624     2326846 : typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseObjectLiteral(
    2625     8837058 :     bool* ok) {
    2626             :   // ObjectLiteral ::
    2627             :   // '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}'
    2628             : 
    2629             :   int pos = peek_position();
    2630      659710 :   typename Types::ObjectPropertyList properties =
    2631      707192 :       impl()->NewObjectPropertyList(4);
    2632             :   int number_of_boilerplate_properties = 0;
    2633             : 
    2634             :   bool has_computed_names = false;
    2635             :   bool has_rest_property = false;
    2636             :   ObjectLiteralChecker checker(this);
    2637             : 
    2638     2326846 :   Expect(Token::LBRACE, CHECK_OK);
    2639             : 
    2640     8834598 :   while (peek() != Token::RBRACE) {
    2641     6584121 :     FuncNameInferrer::State fni_state(fni_);
    2642             : 
    2643     6584121 :     bool is_computed_name = false;
    2644     6584121 :     bool is_rest_property = false;
    2645             :     ObjectLiteralPropertyT property = ParseObjectPropertyDefinition(
    2646     6630283 :         &checker, &is_computed_name, &is_rest_property, CHECK_OK);
    2647             : 
    2648     4917800 :     if (is_computed_name) {
    2649             :       has_computed_names = true;
    2650             :     }
    2651             : 
    2652     6510164 :     if (is_rest_property) {
    2653             :       has_rest_property = true;
    2654             :     }
    2655             : 
    2656     4917800 :     if (impl()->IsBoilerplateProperty(property) && !has_computed_names) {
    2657             :       // Count CONSTANT or COMPUTED properties to maintain the enumeration
    2658             :       // order.
    2659     4796779 :       number_of_boilerplate_properties++;
    2660             :     }
    2661             : 
    2662     1592364 :     properties->Add(property, zone());
    2663             : 
    2664     6510164 :     if (peek() != Token::RBRACE) {
    2665             :       // Need {} because of the CHECK_OK macro.
    2666     4753645 :       Expect(Token::COMMA, CHECK_OK);
    2667             :     }
    2668             : 
    2669     6507750 :     if (fni_ != nullptr) fni_->Infer();
    2670             :   }
    2671     2250477 :   Expect(Token::RBRACE, CHECK_OK);
    2672             : 
    2673             :   // In pattern rewriter, we rewrite rest property to call out to a
    2674             :   // runtime function passing all the other properties as arguments to
    2675             :   // this runtime function. Here, we make sure that the number of
    2676             :   // properties is less than number of arguments allowed for a runtime
    2677             :   // call.
    2678     2250477 :   if (has_rest_property && properties->length() > Code::kMaxArguments) {
    2679          24 :     this->classifier()->RecordPatternError(Scanner::Location(pos, position()),
    2680             :                                            MessageTemplate::kTooManyArguments);
    2681             :   }
    2682             : 
    2683             :   return factory()->NewObjectLiteral(
    2684     1590767 :       properties, number_of_boilerplate_properties, pos, has_rest_property);
    2685             : }
    2686             : 
    2687             : template <typename Impl>
    2688    18258224 : typename ParserBase<Impl>::ExpressionListT ParserBase<Impl>::ParseArguments(
    2689    66840486 :     Scanner::Location* first_spread_arg_loc, bool maybe_arrow, bool* ok) {
    2690             :   // Arguments ::
    2691             :   //   '(' (AssignmentExpression)*[','] ')'
    2692             : 
    2693             :   Scanner::Location spread_arg = Scanner::Location::invalid();
    2694     3544290 :   ExpressionListT result = impl()->NewExpressionList(4);
    2695    18258237 :   Expect(Token::LPAREN, CHECK_OK_CUSTOM(NullExpressionList));
    2696    18258249 :   bool done = (peek() == Token::RPAREN);
    2697    65194347 :   while (!done) {
    2698             :     int start_pos = peek_position();
    2699    28687050 :     bool is_spread = Check(Token::ELLIPSIS);
    2700             :     int expr_pos = peek_position();
    2701             : 
    2702             :     ExpressionT argument =
    2703    28690944 :         ParseAssignmentExpression(true, CHECK_OK_CUSTOM(NullExpressionList));
    2704    28677900 :     if (!maybe_arrow) {
    2705    28672585 :       impl()->RewriteNonPattern(CHECK_OK_CUSTOM(NullExpressionList));
    2706             :     }
    2707    28677899 :     if (is_spread) {
    2708        9621 :       if (!spread_arg.IsValid()) {
    2709             :         spread_arg.beg_pos = start_pos;
    2710             :         spread_arg.end_pos = peek_position();
    2711             :       }
    2712        9621 :       argument = factory()->NewSpread(argument, start_pos, expr_pos);
    2713             :     }
    2714    28677899 :     result->Add(argument, zone_);
    2715             : 
    2716    28677898 :     if (result->length() > Code::kMaxArguments) {
    2717          39 :       ReportMessage(MessageTemplate::kTooManyArguments);
    2718          39 :       *ok = false;
    2719          39 :       return impl()->NullExpressionList();
    2720             :     }
    2721    28677843 :     done = (peek() != Token::COMMA);
    2722    28677843 :     if (!done) {
    2723             :       Next();
    2724    26970313 :       if (allow_harmony_trailing_commas() && peek() == Token::RPAREN) {
    2725             :         // allow trailing comma
    2726             :         done = true;
    2727             :       }
    2728             :     }
    2729             :   }
    2730    18249048 :   Scanner::Location location = scanner_->location();
    2731    18249067 :   if (Token::RPAREN != Next()) {
    2732         107 :     impl()->ReportMessageAt(location, MessageTemplate::kUnterminatedArgList);
    2733         377 :     *ok = false;
    2734         377 :     return impl()->NullExpressionList();
    2735             :   }
    2736    18248690 :   *first_spread_arg_loc = spread_arg;
    2737             : 
    2738    18260532 :   if (!maybe_arrow || peek() != Token::ARROW) {
    2739    18240641 :     if (maybe_arrow) {
    2740        3905 :       impl()->RewriteNonPattern(CHECK_OK_CUSTOM(NullExpressionList));
    2741             :     }
    2742             :   }
    2743             : 
    2744    18248456 :   return result;
    2745             : }
    2746             : 
    2747             : // Precedence = 2
    2748             : template <typename Impl>
    2749             : typename ParserBase<Impl>::ExpressionT
    2750   442863514 : ParserBase<Impl>::ParseAssignmentExpression(bool accept_IN, bool* ok) {
    2751             :   // AssignmentExpression ::
    2752             :   //   ConditionalExpression
    2753             :   //   ArrowFunction
    2754             :   //   YieldExpression
    2755             :   //   LeftHandSideExpression AssignmentOperator AssignmentExpression
    2756             :   int lhs_beg_pos = peek_position();
    2757             : 
    2758   138314730 :   if (peek() == Token::YIELD && is_generator()) {
    2759       49604 :     return ParseYieldExpression(accept_IN, ok);
    2760             :   }
    2761             : 
    2762   138202731 :   FuncNameInferrer::State fni_state(fni_);
    2763             :   ExpressionClassifier arrow_formals_classifier(
    2764   138202783 :       this, classifier()->duplicate_finder());
    2765             : 
    2766   276405833 :   Scope::Snapshot scope_snapshot(scope());
    2767             :   int rewritable_length =
    2768   138202927 :       function_state_->destructuring_assignments_to_rewrite().length();
    2769             : 
    2770             :   bool is_async = peek() == Token::ASYNC &&
    2771             :                   !scanner()->HasAnyLineTerminatorAfterNext() &&
    2772   138281911 :                   IsValidArrowFormalParametersStart(PeekAhead());
    2773             : 
    2774   138202755 :   bool parenthesized_formals = peek() == Token::LPAREN;
    2775   138202755 :   if (!is_async && !parenthesized_formals) {
    2776   133596630 :     ArrowFormalParametersUnexpectedToken();
    2777             :   }
    2778             : 
    2779             :   // Parse a simple, faster sub-grammar (primary expression) if it's evident
    2780             :   // that we have only a trivial expression to parse.
    2781             :   ExpressionT expression;
    2782   138202736 :   if (IsTrivialExpression()) {
    2783    70693707 :     expression = ParsePrimaryExpression(&is_async, CHECK_OK);
    2784             :   } else {
    2785    67693966 :     expression = ParseConditionalExpression(accept_IN, CHECK_OK);
    2786             :   }
    2787             : 
    2788   137754395 :   if (is_async && impl()->IsIdentifier(expression) && peek_any_identifier() &&
    2789             :       PeekAhead() == Token::ARROW) {
    2790             :     // async Identifier => AsyncConciseBody
    2791         505 :     IdentifierT name = ParseAndClassifyIdentifier(CHECK_OK);
    2792         154 :     expression =
    2793             :         impl()->ExpressionFromIdentifier(name, position(), InferName::kNo);
    2794         337 :     if (fni_) {
    2795             :       // Remove `async` keyword from inferred name stack.
    2796         183 :       fni_->RemoveAsyncKeywordFromEnd();
    2797             :     }
    2798             :   }
    2799             : 
    2800   137744371 :   if (peek() == Token::ARROW) {
    2801      722471 :     Scanner::Location arrow_loc = scanner()->peek_location();
    2802      722471 :     ValidateArrowFormalParameters(expression, parenthesized_formals, is_async,
    2803     1463410 :                                   CHECK_OK);
    2804             :     // This reads strangely, but is correct: it checks whether any
    2805             :     // sub-expression of the parameter list failed to be a valid formal
    2806             :     // parameter initializer. Since YieldExpressions are banned anywhere
    2807             :     // in an arrow parameter list, this is correct.
    2808             :     // TODO(adamk): Rename "FormalParameterInitializerError" to refer to
    2809             :     // "YieldExpression", which is its only use.
    2810      685823 :     ValidateFormalParameterInitializer(ok);
    2811             : 
    2812             :     Scanner::Location loc(lhs_beg_pos, scanner()->location().end_pos);
    2813             :     DeclarationScope* scope =
    2814             :         NewFunctionScope(is_async ? FunctionKind::kAsyncArrowFunction
    2815      685823 :                                   : FunctionKind::kArrowFunction);
    2816             : 
    2817             :     // Because the arrow's parameters were parsed in the outer scope,
    2818             :     // we need to fix up the scope chain appropriately.
    2819      685823 :     scope_snapshot.Reparent(scope);
    2820      685823 :     function_state_->SetDestructuringAssignmentsScope(rewritable_length, scope);
    2821             : 
    2822             :     FormalParametersT parameters(scope);
    2823      685823 :     if (!classifier()->is_simple_parameter_list()) {
    2824             :       scope->SetHasNonSimpleParameters();
    2825       31100 :       parameters.is_simple = false;
    2826             :     }
    2827             : 
    2828             :     scope->set_start_position(lhs_beg_pos);
    2829      685823 :     Scanner::Location duplicate_loc = Scanner::Location::invalid();
    2830      685823 :     impl()->DeclareArrowFunctionFormalParameters(&parameters, expression, loc,
    2831      688607 :                                                  &duplicate_loc, CHECK_OK);
    2832      680255 :     if (duplicate_loc.IsValid()) {
    2833          73 :       classifier()->RecordDuplicateFormalParameterError(duplicate_loc);
    2834             :     }
    2835      680255 :     expression = ParseArrowFunctionLiteral(accept_IN, parameters,
    2836     1368274 :                                            rewritable_length, CHECK_OK);
    2837             :     DiscardExpressionClassifier();
    2838      664546 :     classifier()->RecordPatternError(arrow_loc,
    2839             :                                      MessageTemplate::kUnexpectedToken,
    2840             :                                      Token::String(Token::ARROW));
    2841             : 
    2842      664546 :     if (fni_ != nullptr) fni_->Infer();
    2843             : 
    2844      664546 :     return expression;
    2845             :   }
    2846             : 
    2847             :   // "expression" was not itself an arrow function parameter list, but it might
    2848             :   // form part of one.  Propagate speculative formal parameter error locations
    2849             :   // (including those for binding patterns, since formal parameters can
    2850             :   // themselves contain binding patterns).
    2851             :   unsigned productions = ExpressionClassifier::AllProductions &
    2852             :                          ~ExpressionClassifier::ArrowFormalParametersProduction;
    2853             : 
    2854             :   // Parenthesized identifiers and property references are allowed as part
    2855             :   // of a larger assignment pattern, even though parenthesized patterns
    2856             :   // themselves are not allowed, e.g., "[(x)] = []". Only accumulate
    2857             :   // assignment pattern errors if the parsed expression is more complex.
    2858   137021900 :   if (IsValidReferenceExpression(expression)) {
    2859             :     productions &= ~ExpressionClassifier::AssignmentPatternProduction;
    2860             :   }
    2861             : 
    2862             :   const bool is_destructuring_assignment =
    2863   140180462 :       IsValidPattern(expression) && peek() == Token::ASSIGN;
    2864   137021883 :   if (is_destructuring_assignment) {
    2865             :     // This is definitely not an expression so don't accumulate
    2866             :     // expression-related errors.
    2867      205101 :     productions &= ~ExpressionClassifier::ExpressionProduction;
    2868             :   }
    2869             : 
    2870   137021872 :   if (!Token::IsAssignmentOp(peek())) {
    2871             :     // Parsed conditional expression only (no assignment).
    2872             :     // Pending non-pattern expressions must be merged.
    2873             :     Accumulate(productions);
    2874   122463524 :     return expression;
    2875             :   } else {
    2876             :     // Pending non-pattern expressions must be discarded.
    2877             :     Accumulate(productions, false);
    2878             :   }
    2879             : 
    2880    14558516 :   if (is_destructuring_assignment) {
    2881      214341 :     ValidateAssignmentPattern(CHECK_OK);
    2882             :   } else {
    2883             :     expression = CheckAndRewriteReferenceExpression(
    2884             :         expression, lhs_beg_pos, scanner()->location().end_pos,
    2885    14359229 :         MessageTemplate::kInvalidLhsInAssignment, CHECK_OK);
    2886             :   }
    2887             : 
    2888             :   impl()->MarkExpressionAsAssigned(expression);
    2889             : 
    2890             :   Token::Value op = Next();  // Get assignment operator.
    2891    14528544 :   if (op != Token::ASSIGN) {
    2892     1510316 :     classifier()->RecordPatternError(scanner()->location(),
    2893             :                                      MessageTemplate::kUnexpectedToken,
    2894             :                                      Token::String(op));
    2895             :   }
    2896             :   int pos = position();
    2897             : 
    2898    14528544 :   ExpressionClassifier rhs_classifier(this);
    2899             : 
    2900    14533638 :   ExpressionT right = ParseAssignmentExpression(accept_IN, CHECK_OK);
    2901    14518497 :   impl()->RewriteNonPattern(CHECK_OK);
    2902             :   AccumulateFormalParameterContainmentErrors();
    2903             : 
    2904             :   // We try to estimate the set of properties set by constructors. We define a
    2905             :   // new property whenever there is an assignment to a property of 'this'. We
    2906             :   // should probably only add properties if we haven't seen them
    2907             :   // before. Otherwise we'll probably overestimate the number of properties.
    2908    28280020 :   if (op == Token::ASSIGN && impl()->IsThisProperty(expression)) {
    2909     1356551 :     function_state_->AddProperty();
    2910             :   }
    2911             : 
    2912             :   impl()->CheckAssigningFunctionLiteralToProperty(expression, right);
    2913             : 
    2914    14517581 :   if (fni_ != NULL) {
    2915             :     // Check if the right hand side is a call to avoid inferring a
    2916             :     // name if we're dealing with "a = function(){...}();"-like
    2917             :     // expression.
    2918    29026105 :     if ((op == Token::INIT || op == Token::ASSIGN) &&
    2919           0 :         (!right->IsCall() && !right->IsCallNew())) {
    2920     8759509 :       fni_->Infer();
    2921             :     } else {
    2922     1463927 :       fni_->RemoveLastFunction();
    2923             :     }
    2924             :   }
    2925             : 
    2926    10223436 :   if (op == Token::ASSIGN) {
    2927     9659692 :     impl()->SetFunctionNameFromIdentifierRef(right, expression);
    2928             :   }
    2929             : 
    2930    14517582 :   if (op == Token::ASSIGN_EXP) {
    2931             :     DCHECK(!is_destructuring_assignment);
    2932         179 :     return impl()->RewriteAssignExponentiation(expression, right, pos);
    2933             :   }
    2934             : 
    2935    10223257 :   ExpressionT result = factory()->NewAssignment(op, expression, right, pos);
    2936             : 
    2937    10223255 :   if (is_destructuring_assignment) {
    2938       92429 :     result = factory()->NewRewritableExpression(result);
    2939             :     impl()->QueueDestructuringAssignmentForRewriting(result);
    2940             :   }
    2941             : 
    2942    14517229 :   return result;
    2943             : }
    2944             : 
    2945             : template <typename Impl>
    2946       49604 : typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseYieldExpression(
    2947      289640 :     bool accept_IN, bool* ok) {
    2948             :   // YieldExpression ::
    2949             :   //   'yield' ([no line terminator] '*'? AssignmentExpression)?
    2950             :   int pos = peek_position();
    2951       99208 :   classifier()->RecordPatternError(
    2952             :       scanner()->peek_location(), MessageTemplate::kInvalidDestructuringTarget);
    2953       99208 :   classifier()->RecordFormalParameterInitializerError(
    2954             :       scanner()->peek_location(), MessageTemplate::kYieldInParameter);
    2955       49604 :   Expect(Token::YIELD, CHECK_OK);
    2956             :   ExpressionT generator_object =
    2957       70964 :       factory()->NewVariableProxy(function_state_->generator_object_variable());
    2958             :   // The following initialization is necessary.
    2959             :   ExpressionT expression = impl()->EmptyExpression();
    2960             :   bool delegating = false;  // yield*
    2961       99208 :   if (!scanner()->HasAnyLineTerminatorBeforeNext()) {
    2962       47566 :     if (Check(Token::MUL)) delegating = true;
    2963       47566 :     switch (peek()) {
    2964             :       case Token::EOS:
    2965             :       case Token::SEMICOLON:
    2966             :       case Token::RBRACE:
    2967             :       case Token::RBRACK:
    2968             :       case Token::RPAREN:
    2969             :       case Token::COLON:
    2970             :       case Token::COMMA:
    2971             :         // The above set of tokens is the complete set of tokens that can appear
    2972             :         // after an AssignmentExpression, and none of them can start an
    2973             :         // AssignmentExpression.  This allows us to avoid looking for an RHS for
    2974             :         // a regular yield, given only one look-ahead token.
    2975       19083 :         if (!delegating) break;
    2976             :         // Delegating yields require an RHS; fall through.
    2977             :       default:
    2978       30121 :         expression = ParseAssignmentExpression(accept_IN, CHECK_OK);
    2979       27169 :         impl()->RewriteNonPattern(CHECK_OK);
    2980             :         break;
    2981             :     }
    2982             :   }
    2983             : 
    2984       47906 :   if (delegating) {
    2985        2599 :     return impl()->RewriteYieldStar(generator_object, expression, pos);
    2986             :   }
    2987             : 
    2988       41620 :   if (!is_async_generator()) {
    2989             :     // Async generator yield is rewritten in Ignition, and doesn't require
    2990             :     // producing an Iterator Result.
    2991       13675 :     expression = impl()->BuildIteratorResult(expression, false);
    2992             :   }
    2993             : 
    2994             :   // Hackily disambiguate o from o.next and o [Symbol.iterator]().
    2995             :   // TODO(verwaest): Come up with a better solution.
    2996             :   ExpressionT yield =
    2997             :       BuildSuspend(generator_object, expression, pos,
    2998       18317 :                    Suspend::kOnExceptionThrow, SuspendFlags::kYield);
    2999       41620 :   return yield;
    3000             : }
    3001             : 
    3002             : // Precedence = 3
    3003             : template <typename Impl>
    3004             : typename ParserBase<Impl>::ExpressionT
    3005    67509399 : ParserBase<Impl>::ParseConditionalExpression(bool accept_IN,
    3006    52336062 :                                              bool* ok) {
    3007             :   // ConditionalExpression ::
    3008             :   //   LogicalOrExpression
    3009             :   //   LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression
    3010             : 
    3011             :   int pos = peek_position();
    3012             :   // We start using the binary expression parser for prec >= 4 only!
    3013    67691148 :   ExpressionT expression = ParseBinaryExpression(4, accept_IN, CHECK_OK);
    3014    67056706 :   if (peek() != Token::CONDITIONAL) return expression;
    3015      454150 :   impl()->RewriteNonPattern(CHECK_OK);
    3016      453286 :   BindingPatternUnexpectedToken();
    3017      453286 :   ArrowFormalParametersUnexpectedToken();
    3018      453286 :   Consume(Token::CONDITIONAL);
    3019             : 
    3020             :   ExpressionT left;
    3021             :   {
    3022      453286 :     ExpressionClassifier classifier(this);
    3023             :     // In parsing the first assignment expression in conditional
    3024             :     // expressions we always accept the 'in' keyword; see ECMA-262,
    3025             :     // section 11.12, page 58.
    3026      454453 :     left = ParseAssignmentExpression(true, CHECK_OK);
    3027             :     AccumulateNonBindingPatternErrors();
    3028             :   }
    3029      450979 :   impl()->RewriteNonPattern(CHECK_OK);
    3030      450829 :   Expect(Token::COLON, CHECK_OK);
    3031             :   ExpressionT right;
    3032             :   {
    3033      450631 :     ExpressionClassifier classifier(this);
    3034      451826 :     right = ParseAssignmentExpression(accept_IN, CHECK_OK);
    3035             :     AccumulateNonBindingPatternErrors();
    3036             :   }
    3037      448250 :   impl()->RewriteNonPattern(CHECK_OK);
    3038      718906 :   return factory()->NewConditional(expression, left, right, pos);
    3039             : }
    3040             : 
    3041             : 
    3042             : // Precedence >= 4
    3043             : template <typename Impl>
    3044    85291118 : typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseBinaryExpression(
    3045    12611956 :     int prec, bool accept_IN, bool* ok) {
    3046             :   DCHECK(prec >= 4);
    3047    85472291 :   ExpressionT x = ParseUnaryExpression(CHECK_OK);
    3048   176101136 :   for (int prec1 = Precedence(peek(), accept_IN); prec1 >= prec; prec1--) {
    3049             :     // prec1 >= 4
    3050   109044546 :     while (Precedence(peek(), accept_IN) == prec1) {
    3051    17783519 :       impl()->RewriteNonPattern(CHECK_OK);
    3052    17781791 :       BindingPatternUnexpectedToken();
    3053    17781796 :       ArrowFormalParametersUnexpectedToken();
    3054             :       Token::Value op = Next();
    3055             :       int pos = position();
    3056             : 
    3057             :       const bool is_right_associative = op == Token::EXP;
    3058    17781804 :       const int next_prec = is_right_associative ? prec1 : prec1 + 1;
    3059    17783381 :       ExpressionT y = ParseBinaryExpression(next_prec, accept_IN, CHECK_OK);
    3060    17778258 :       impl()->RewriteNonPattern(CHECK_OK);
    3061             : 
    3062    12609988 :       if (impl()->ShortcutNumericLiteralBinaryExpression(&x, y, op, pos)) {
    3063             :         continue;
    3064             :       }
    3065             : 
    3066             :       // For now we distinguish between comparisons and other binary
    3067             :       // operations.  (We could combine the two and get rid of this
    3068             :       // code and AST node eventually.)
    3069    17069564 :       if (Token::IsCompareOp(op)) {
    3070             :         // We have a comparison.
    3071             :         Token::Value cmp = op;
    3072     7236431 :         switch (op) {
    3073      277696 :           case Token::NE: cmp = Token::EQ; break;
    3074     1303627 :           case Token::NE_STRICT: cmp = Token::EQ_STRICT; break;
    3075             :           default: break;
    3076             :         }
    3077     7236431 :         x = factory()->NewCompareOperation(cmp, x, y, pos);
    3078     5604458 :         if (cmp != op) {
    3079             :           // The comparison was negated - add a NOT.
    3080     2596320 :           x = factory()->NewUnaryOperation(Token::NOT, x, pos);
    3081             :         }
    3082     9833133 :       } else if (op == Token::EXP) {
    3083        7112 :         x = impl()->RewriteExponentiation(x, y, pos);
    3084             :       } else {
    3085             :         // We have a "normal" binary operation.
    3086    13362037 :         x = factory()->NewBinaryOperation(op, x, y, pos);
    3087             :       }
    3088             :     }
    3089             :   }
    3090    84834879 :   return x;
    3091             : }
    3092             : 
    3093             : template <typename Impl>
    3094    89648335 : typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseUnaryExpression(
    3095    89432929 :     bool* ok) {
    3096             :   // UnaryExpression ::
    3097             :   //   PostfixExpression
    3098             :   //   'delete' UnaryExpression
    3099             :   //   'void' UnaryExpression
    3100             :   //   'typeof' UnaryExpression
    3101             :   //   '++' UnaryExpression
    3102             :   //   '--' UnaryExpression
    3103             :   //   '+' UnaryExpression
    3104             :   //   '-' UnaryExpression
    3105             :   //   '~' UnaryExpression
    3106             :   //   '!' UnaryExpression
    3107             :   //   [+Await] AwaitExpression[?Yield]
    3108             : 
    3109             :   Token::Value op = peek();
    3110    89648375 :   if (Token::IsUnaryOp(op)) {
    3111     4008151 :     BindingPatternUnexpectedToken();
    3112     4008151 :     ArrowFormalParametersUnexpectedToken();
    3113             : 
    3114             :     op = Next();
    3115             :     int pos = position();
    3116             : 
    3117             :     // Assume "! function ..." indicates the function is likely to be called.
    3118     5454190 :     if (op == Token::NOT && peek() == Token::FUNCTION) {
    3119          37 :       function_state_->set_next_function_is_likely_called();
    3120             :     }
    3121             : 
    3122     4008899 :     ExpressionT expression = ParseUnaryExpression(CHECK_OK);
    3123     4005173 :     impl()->RewriteNonPattern(CHECK_OK);
    3124             : 
    3125     4045339 :     if (op == Token::DELETE && is_strict(language_mode())) {
    3126       28028 :       if (impl()->IsIdentifier(expression)) {
    3127             :         // "delete identifier" is a syntax error in strict mode.
    3128         744 :         ReportMessage(MessageTemplate::kStrictDelete);
    3129         744 :         *ok = false;
    3130         744 :         return impl()->EmptyExpression();
    3131             :       }
    3132             :     }
    3133             : 
    3134     4004429 :     if (peek() == Token::EXP) {
    3135        3456 :       ReportUnexpectedToken(Next());
    3136        3456 :       *ok = false;
    3137        3456 :       return impl()->EmptyExpression();
    3138             :     }
    3139             : 
    3140             :     // Allow the parser's implementation to rewrite the expression.
    3141     3151268 :     return impl()->BuildUnaryExpression(expression, op, pos);
    3142    85640224 :   } else if (Token::IsCountOp(op)) {
    3143      302948 :     BindingPatternUnexpectedToken();
    3144      302948 :     ArrowFormalParametersUnexpectedToken();
    3145             :     op = Next();
    3146             :     int beg_pos = peek_position();
    3147      304990 :     ExpressionT expression = ParseUnaryExpression(CHECK_OK);
    3148             :     expression = CheckAndRewriteReferenceExpression(
    3149             :         expression, beg_pos, scanner()->location().end_pos,
    3150      300843 :         MessageTemplate::kInvalidLhsInPrefixOp, CHECK_OK);
    3151             :     impl()->MarkExpressionAsAssigned(expression);
    3152      297321 :     impl()->RewriteNonPattern(CHECK_OK);
    3153             : 
    3154             :     return factory()->NewCountOperation(op,
    3155             :                                         true /* prefix */,
    3156             :                                         expression,
    3157      224693 :                                         position());
    3158             : 
    3159    85839520 :   } else if (is_async_function() && peek() == Token::AWAIT) {
    3160       92254 :     classifier()->RecordFormalParameterInitializerError(
    3161             :         scanner()->peek_location(),
    3162             :         MessageTemplate::kAwaitExpressionFormalParameter);
    3163             : 
    3164             :     int await_pos = peek_position();
    3165       46127 :     Consume(Token::AWAIT);
    3166             : 
    3167       49991 :     ExpressionT value = ParseUnaryExpression(CHECK_OK);
    3168             : 
    3169       19175 :     return impl()->RewriteAwaitExpression(value, await_pos);
    3170             :   } else {
    3171    85291147 :     return ParsePostfixExpression(ok);
    3172             :   }
    3173             : }
    3174             : 
    3175             : template <typename Impl>
    3176    85291143 : typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePostfixExpression(
    3177   173024310 :     bool* ok) {
    3178             :   // PostfixExpression ::
    3179             :   //   LeftHandSideExpression ('++' | '--')?
    3180             : 
    3181             :   int lhs_beg_pos = peek_position();
    3182    85467616 :   ExpressionT expression = ParseLeftHandSideExpression(CHECK_OK);
    3183   253072680 :   if (!scanner()->HasAnyLineTerminatorBeforeNext() &&
    3184             :       Token::IsCountOp(peek())) {
    3185     1561751 :     BindingPatternUnexpectedToken();
    3186     1561751 :     ArrowFormalParametersUnexpectedToken();
    3187             : 
    3188      237691 :     expression = CheckAndRewriteReferenceExpression(
    3189             :         expression, lhs_beg_pos, scanner()->location().end_pos,
    3190     1563073 :         MessageTemplate::kInvalidLhsInPostfixOp, CHECK_OK);
    3191             :     impl()->MarkExpressionAsAssigned(expression);
    3192     1559502 :     impl()->RewriteNonPattern(CHECK_OK);
    3193             : 
    3194             :     Token::Value next = Next();
    3195     1559502 :     expression =
    3196             :         factory()->NewCountOperation(next,
    3197             :                                      false /* postfix */,
    3198             :                                      expression,
    3199             :                                      position());
    3200             :   }
    3201    84845977 :   return expression;
    3202             : }
    3203             : 
    3204             : template <typename Impl>
    3205             : typename ParserBase<Impl>::ExpressionT
    3206   115524950 : ParserBase<Impl>::ParseLeftHandSideExpression(bool* ok) {
    3207             :   // LeftHandSideExpression ::
    3208             :   //   (NewExpression | MemberExpression) ...
    3209             : 
    3210    85367120 :   bool is_async = false;
    3211             :   ExpressionT result =
    3212    85538935 :       ParseMemberWithNewPrefixesExpression(&is_async, CHECK_OK);
    3213             : 
    3214             :   while (true) {
    3215   100470234 :     switch (peek()) {
    3216             :       case Token::LBRACK: {
    3217       29712 :         impl()->RewriteNonPattern(CHECK_OK);
    3218       29712 :         BindingPatternUnexpectedToken();
    3219       29712 :         ArrowFormalParametersUnexpectedToken();
    3220       29712 :         Consume(Token::LBRACK);
    3221             :         int pos = position();
    3222       29712 :         ExpressionT index = ParseExpressionCoverGrammar(true, CHECK_OK);
    3223       29697 :         impl()->RewriteNonPattern(CHECK_OK);
    3224       29697 :         result = factory()->NewProperty(result, index, pos);
    3225       29697 :         Expect(Token::RBRACK, CHECK_OK);
    3226       11219 :         break;
    3227             :       }
    3228             : 
    3229             :       case Token::LPAREN: {
    3230             :         int pos;
    3231    14908953 :         impl()->RewriteNonPattern(CHECK_OK);
    3232    14897213 :         BindingPatternUnexpectedToken();
    3233    14897206 :         if (scanner()->current_token() == Token::IDENTIFIER ||
    3234             :             scanner()->current_token() == Token::SUPER ||
    3235             :             scanner()->current_token() == Token::ASYNC) {
    3236             :           // For call of an identifier we want to report position of
    3237             :           // the identifier as position of the call in the stack trace.
    3238             :           pos = position();
    3239             :         } else {
    3240             :           // For other kinds of calls we record position of the parenthesis as
    3241             :           // position of the call. Note that this is extremely important for
    3242             :           // expressions of the form function(){...}() for which call position
    3243             :           // should not point to the closing brace otherwise it will intersect
    3244             :           // with positions recorded for function literal and confuse debugger.
    3245             :           pos = peek_position();
    3246             :           // Also the trailing parenthesis are a hint that the function will
    3247             :           // be called immediately. If we happen to have parsed a preceding
    3248             :           // function literal eagerly, we can also compile it eagerly.
    3249      300410 :           if (result->IsFunctionLiteral()) {
    3250      417376 :             result->AsFunctionLiteral()->SetShouldEagerCompile();
    3251             :           }
    3252             :         }
    3253             :         Scanner::Location spread_pos;
    3254             :         ExpressionListT args;
    3255    14909817 :         if (V8_UNLIKELY(is_async && impl()->IsIdentifier(result))) {
    3256       12432 :           ExpressionClassifier async_classifier(this);
    3257       12912 :           args = ParseArguments(&spread_pos, true, CHECK_OK);
    3258       11636 :           if (peek() == Token::ARROW) {
    3259        8047 :             if (fni_) {
    3260        4487 :               fni_->RemoveAsyncKeywordFromEnd();
    3261             :             }
    3262        8311 :             ValidateBindingPattern(CHECK_OK);
    3263        7759 :             ValidateFormalParameterInitializer(CHECK_OK);
    3264        7279 :             if (!classifier()->is_valid_async_arrow_formal_parameters()) {
    3265        1824 :               ReportClassifierError(
    3266             :                   classifier()->async_arrow_formal_parameters_error());
    3267        1824 :               *ok = false;
    3268        1824 :               return impl()->EmptyExpression();
    3269             :             }
    3270        5455 :             if (args->length()) {
    3271             :               // async ( Arguments ) => ...
    3272         672 :               return impl()->ExpressionListToExpression(args);
    3273             :             }
    3274             :             // async () => ...
    3275        5182 :             return factory()->NewEmptyParentheses(pos);
    3276             :           } else {
    3277             :             AccumulateFormalParameterContainmentErrors();
    3278             :           }
    3279             :         } else {
    3280    14888363 :           args = ParseArguments(&spread_pos, false, CHECK_OK);
    3281             :         }
    3282             : 
    3283    14880112 :         ArrowFormalParametersUnexpectedToken();
    3284             : 
    3285             :         // Keep track of eval() calls since they disable all local variable
    3286             :         // optimizations.
    3287             :         // The calls that need special treatment are the
    3288             :         // direct eval calls. These calls are all of the form eval(...), with
    3289             :         // no explicit receiver.
    3290             :         // These calls are marked as potentially direct eval calls. Whether
    3291             :         // they are actually direct calls to eval is determined at run time.
    3292             :         Call::PossiblyEval is_possibly_eval =
    3293    14880126 :             CheckPossibleEvalCall(result, scope());
    3294             : 
    3295             :         bool is_super_call = result->IsSuperCallReference();
    3296    14880125 :         if (spread_pos.IsValid()) {
    3297        8190 :           result = impl()->SpreadCall(result, args, pos, is_possibly_eval);
    3298             :         } else {
    3299    14871935 :           result = factory()->NewCall(result, args, pos, is_possibly_eval);
    3300             :         }
    3301             : 
    3302             :         // Explicit calls to the super constructor using super() perform an
    3303             :         // implicit binding assignment to the 'this' variable.
    3304    14880120 :         if (is_super_call) {
    3305        5691 :           classifier()->RecordAssignmentPatternError(
    3306             :               Scanner::Location(pos, scanner()->location().end_pos),
    3307             :               MessageTemplate::kInvalidDestructuringTarget);
    3308             :           ExpressionT this_expr = impl()->ThisExpression(pos);
    3309        5691 :           result =
    3310             :               factory()->NewAssignment(Token::INIT, this_expr, result, pos);
    3311             :         }
    3312             : 
    3313    14880120 :         if (fni_ != NULL) fni_->RemoveLastFunction();
    3314    14880125 :         break;
    3315             :       }
    3316             : 
    3317             :       case Token::PERIOD: {
    3318      623809 :         impl()->RewriteNonPattern(CHECK_OK);
    3319      623809 :         BindingPatternUnexpectedToken();
    3320      623809 :         ArrowFormalParametersUnexpectedToken();
    3321      623809 :         Consume(Token::PERIOD);
    3322             :         int pos = position();
    3323      623809 :         IdentifierT name = ParseIdentifierName(CHECK_OK);
    3324      906087 :         result = factory()->NewProperty(
    3325             :             result, factory()->NewStringLiteral(name, pos), pos);
    3326      341531 :         impl()->PushLiteralName(name);
    3327      282278 :         break;
    3328             :       }
    3329             : 
    3330             :       case Token::TEMPLATE_SPAN:
    3331             :       case Token::TEMPLATE_TAIL: {
    3332        1813 :         impl()->RewriteNonPattern(CHECK_OK);
    3333        1813 :         BindingPatternUnexpectedToken();
    3334        1813 :         ArrowFormalParametersUnexpectedToken();
    3335        1813 :         result = ParseTemplateLiteral(result, position(), true, CHECK_OK);
    3336             :         break;
    3337             :       }
    3338             : 
    3339             :       default:
    3340    20208273 :         return result;
    3341             :     }
    3342             :   }
    3343             : }
    3344             : 
    3345             : template <typename Impl>
    3346             : typename ParserBase<Impl>::ExpressionT
    3347    86527253 : ParserBase<Impl>::ParseMemberWithNewPrefixesExpression(bool* is_async,
    3348     2258018 :                                                        bool* ok) {
    3349             :   // NewExpression ::
    3350             :   //   ('new')+ MemberExpression
    3351             :   //
    3352             :   // NewTarget ::
    3353             :   //   'new' '.' 'target'
    3354             : 
    3355             :   // The grammar for new expressions is pretty warped. We can have several 'new'
    3356             :   // keywords following each other, and then a MemberExpression. When we see '('
    3357             :   // after the MemberExpression, it's associated with the rightmost unassociated
    3358             :   // 'new' to create a NewExpression with arguments. However, a NewExpression
    3359             :   // can also occur without arguments.
    3360             : 
    3361             :   // Examples of new expression:
    3362             :   // new foo.bar().baz means (new (foo.bar)()).baz
    3363             :   // new foo()() means (new foo())()
    3364             :   // new new foo()() means (new (new foo())())
    3365             :   // new new foo means new (new foo)
    3366             :   // new new foo() means new (new foo())
    3367             :   // new new foo().bar().baz means (new (new foo()).bar()).baz
    3368             : 
    3369    86527278 :   if (peek() == Token::NEW) {
    3370     1202335 :     BindingPatternUnexpectedToken();
    3371     1202335 :     ArrowFormalParametersUnexpectedToken();
    3372     1202335 :     Consume(Token::NEW);
    3373             :     int new_pos = position();
    3374             :     ExpressionT result;
    3375     1202335 :     if (peek() == Token::SUPER) {
    3376             :       const bool is_new = true;
    3377       11774 :       result = ParseSuperExpression(is_new, CHECK_OK);
    3378     1197357 :     } else if (allow_harmony_dynamic_import() && peek() == Token::IMPORT) {
    3379        1200 :       impl()->ReportMessageAt(scanner()->peek_location(),
    3380             :                               MessageTemplate::kImportCallNotNewExpression);
    3381        2400 :       *ok = false;
    3382        2400 :       return impl()->EmptyExpression();
    3383     1191665 :     } else if (peek() == Token::PERIOD) {
    3384       31576 :       return ParseNewTargetExpression(CHECK_OK);
    3385             :     } else {
    3386     1162119 :       result = ParseMemberWithNewPrefixesExpression(is_async, CHECK_OK);
    3387             :     }
    3388     1157870 :     impl()->RewriteNonPattern(CHECK_OK);
    3389     1157870 :     if (peek() == Token::LPAREN) {
    3390             :       // NewExpression with arguments.
    3391             :       Scanner::Location spread_pos;
    3392     1112041 :       ExpressionListT args = ParseArguments(&spread_pos, CHECK_OK);
    3393             : 
    3394     1111266 :       if (spread_pos.IsValid()) {
    3395         283 :         result = impl()->SpreadCallNew(result, args, new_pos);
    3396             :       } else {
    3397     1110983 :         result = factory()->NewCallNew(result, args, new_pos);
    3398             :       }
    3399             :       // The expression can still continue with . or [ after the arguments.
    3400     1111266 :       result = ParseMemberExpressionContinuation(result, is_async, CHECK_OK);
    3401     1111266 :       return result;
    3402             :     }
    3403             :     // NewExpression without arguments.
    3404       41480 :     return factory()->NewCallNew(result, impl()->NewExpressionList(0), new_pos);
    3405             :   }
    3406             :   // No 'new' or 'super' keyword.
    3407    85324943 :   return ParseMemberExpression(is_async, ok);
    3408             : }
    3409             : 
    3410             : template <typename Impl>
    3411    85324938 : typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseMemberExpression(
    3412    86179011 :     bool* is_async, bool* ok) {
    3413             :   // MemberExpression ::
    3414             :   //   (PrimaryExpression | FunctionLiteral | ClassLiteral)
    3415             :   //     ('[' Expression ']' | '.' Identifier | Arguments | TemplateLiteral)*
    3416             :   //
    3417             :   // CallExpression ::
    3418             :   //   (SuperCall | ImportCall)
    3419             :   //     ('[' Expression ']' | '.' Identifier | Arguments | TemplateLiteral)*
    3420             :   //
    3421             :   // The '[' Expression ']' and '.' Identifier parts are parsed by
    3422             :   // ParseMemberExpressionContinuation, and the Arguments part is parsed by the
    3423             :   // caller.
    3424             : 
    3425             :   // Parse the initial primary or function expression.
    3426             :   ExpressionT result;
    3427    85324944 :   if (peek() == Token::FUNCTION) {
    3428     4156324 :     BindingPatternUnexpectedToken();
    3429     4156326 :     ArrowFormalParametersUnexpectedToken();
    3430             : 
    3431     4156327 :     Consume(Token::FUNCTION);
    3432             :     int function_token_position = position();
    3433             : 
    3434     4156710 :     if (allow_harmony_function_sent() && peek() == Token::PERIOD) {
    3435             :       // function.sent
    3436             :       int pos = position();
    3437       63303 :       ExpectMetaProperty(Token::SENT, "function.sent", pos, CHECK_OK);
    3438             : 
    3439         154 :       if (!is_generator()) {
    3440             :         // TODO(neis): allow escaping into closures?
    3441          34 :         impl()->ReportMessageAt(scanner()->location(),
    3442             :                                 MessageTemplate::kUnexpectedFunctionSent);
    3443          54 :         *ok = false;
    3444          54 :         return impl()->EmptyExpression();
    3445             :       }
    3446             : 
    3447          42 :       return impl()->FunctionSentExpression(pos);
    3448             :     }
    3449             : 
    3450     4156156 :     FunctionKind function_kind = Check(Token::MUL)
    3451             :                                      ? FunctionKind::kGeneratorFunction
    3452     4156154 :                                      : FunctionKind::kNormalFunction;
    3453       75125 :     IdentifierT name = impl()->EmptyIdentifier();
    3454     4156154 :     bool is_strict_reserved_name = false;
    3455     4156154 :     Scanner::Location function_name_location = Scanner::Location::invalid();
    3456             :     FunctionLiteral::FunctionType function_type =
    3457             :         FunctionLiteral::kAnonymousExpression;
    3458     4081029 :     if (impl()->ParsingDynamicFunctionDeclaration()) {
    3459             :       // We don't want dynamic functions to actually declare their name
    3460             :       // "anonymous". We just want that name in the toString().
    3461        1078 :       if (stack_overflow()) {
    3462         450 :         *ok = false;
    3463         450 :         return impl()->EmptyExpression();
    3464             :       }
    3465         628 :       Consume(Token::IDENTIFIER);
    3466             :       DCHECK(scanner()->CurrentMatchesContextual(Token::ANONYMOUS));
    3467     4155076 :     } else if (peek_any_identifier()) {
    3468      874511 :       name = ParseIdentifierOrStrictReservedWord(
    3469     1749502 :           function_kind, &is_strict_reserved_name, CHECK_OK);
    3470      873730 :       function_name_location = scanner()->location();
    3471             :       function_type = FunctionLiteral::kNamedExpression;
    3472             :     }
    3473     4154927 :     result = impl()->ParseFunctionLiteral(
    3474             :         name, function_name_location,
    3475             :         is_strict_reserved_name ? kFunctionNameIsStrictReserved
    3476             :                                 : kFunctionNameValidityUnknown,
    3477             :         function_kind, function_token_position, function_type, language_mode(),
    3478     4169952 :         CHECK_OK);
    3479    81168503 :   } else if (peek() == Token::SUPER) {
    3480             :     const bool is_new = false;
    3481       26591 :     result = ParseSuperExpression(is_new, CHECK_OK);
    3482    81217232 :   } else if (allow_harmony_dynamic_import() && peek() == Token::IMPORT) {
    3483        5661 :     result = ParseDynamicImportExpression(CHECK_OK);
    3484             :   } else {
    3485    81279115 :     result = ParsePrimaryExpression(is_async, CHECK_OK);
    3486             :   }
    3487             : 
    3488    84928375 :   result = ParseMemberExpressionContinuation(result, is_async, CHECK_OK);
    3489    84903605 :   return result;
    3490             : }
    3491             : 
    3492             : template <typename Impl>
    3493             : typename ParserBase<Impl>::ExpressionT
    3494        6297 : ParserBase<Impl>::ParseDynamicImportExpression(bool* ok) {
    3495             :   DCHECK(allow_harmony_dynamic_import());
    3496        4317 :   Consume(Token::IMPORT);
    3497             :   int pos = position();
    3498        5181 :   Expect(Token::LPAREN, CHECK_OK);
    3499        3237 :   ExpressionT arg = ParseAssignmentExpression(true, CHECK_OK);
    3500        2373 :   Expect(Token::RPAREN, CHECK_OK);
    3501        1896 :   return factory()->NewImportCallExpression(arg, pos);
    3502             : }
    3503             : 
    3504             : template <typename Impl>
    3505       29267 : typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseSuperExpression(
    3506       34014 :     bool is_new, bool* ok) {
    3507       29267 :   Expect(Token::SUPER, CHECK_OK);
    3508             :   int pos = position();
    3509             : 
    3510       29267 :   DeclarationScope* scope = GetReceiverScope();
    3511             :   FunctionKind kind = scope->function_kind();
    3512       67313 :   if (IsConciseMethod(kind) || IsAccessorFunction(kind) ||
    3513             :       IsClassConstructor(kind)) {
    3514       30129 :     if (peek() == Token::PERIOD || peek() == Token::LBRACK) {
    3515             :       scope->RecordSuperPropertyUsage();
    3516        6119 :       return impl()->NewSuperPropertyReference(pos);
    3517             :     }
    3518             :     // new super() is never allowed.
    3519             :     // super() is only allowed in derived constructor
    3520       22863 :     if (!is_new && peek() == Token::LPAREN && IsDerivedConstructor(kind)) {
    3521             :       // TODO(rossberg): This might not be the correct FunctionState for the
    3522             :       // method here.
    3523        5545 :       return impl()->NewSuperCallReference(pos);
    3524             :     }
    3525             :   }
    3526             : 
    3527        9098 :   impl()->ReportMessageAt(scanner()->location(),
    3528             :                           MessageTemplate::kUnexpectedSuper);
    3529       15724 :   *ok = false;
    3530       15724 :   return impl()->EmptyExpression();
    3531             : }
    3532             : 
    3533             : template <typename Impl>
    3534       31742 : void ParserBase<Impl>::ExpectMetaProperty(Token::Value property_name,
    3535             :                                           const char* full_name, int pos,
    3536       31742 :                                           bool* ok) {
    3537       31742 :   Consume(Token::PERIOD);
    3538       63484 :   ExpectContextualKeyword(property_name, CHECK_OK_CUSTOM(Void));
    3539       31742 :   if (scanner()->literal_contains_escapes()) {
    3540          42 :     impl()->ReportMessageAt(
    3541             :         Scanner::Location(pos, scanner()->location().end_pos),
    3542             :         MessageTemplate::kInvalidEscapedMetaProperty, full_name);
    3543          60 :     *ok = false;
    3544             :   }
    3545             : }
    3546             : 
    3547             : template <typename Impl>
    3548             : typename ParserBase<Impl>::ExpressionT
    3549       96600 : ParserBase<Impl>::ParseNewTargetExpression(bool* ok) {
    3550             :   int pos = position();
    3551       31612 :   ExpectMetaProperty(Token::TARGET, "new.target", pos, CHECK_OK);
    3552             : 
    3553       31528 :   classifier()->RecordAssignmentPatternError(
    3554             :       Scanner::Location(pos, scanner()->location().end_pos),
    3555             :       MessageTemplate::kInvalidDestructuringTarget);
    3556             : 
    3557       31528 :   if (!GetReceiverScope()->is_function_scope()) {
    3558        1008 :     impl()->ReportMessageAt(scanner()->location(),
    3559             :                             MessageTemplate::kUnexpectedNewTarget);
    3560        1968 :     *ok = false;
    3561        1968 :     return impl()->EmptyExpression();
    3562             :   }
    3563             : 
    3564       25292 :   return impl()->NewTargetExpression(pos);
    3565             : }
    3566             : 
    3567             : template <typename Impl>
    3568             : typename ParserBase<Impl>::ExpressionT
    3569    86031999 : ParserBase<Impl>::ParseMemberExpressionContinuation(ExpressionT expression,
    3570    24862412 :                                                     bool* is_async, bool* ok) {
    3571             :   // Parses this part of MemberExpression:
    3572             :   // ('[' Expression ']' | '.' Identifier | TemplateLiteral)*
    3573             :   while (true) {
    3574   117549211 :     switch (peek()) {
    3575             :       case Token::LBRACK: {
    3576     8238729 :         *is_async = false;
    3577     8239305 :         impl()->RewriteNonPattern(CHECK_OK);
    3578     8237577 :         BindingPatternUnexpectedToken();
    3579     8237576 :         ArrowFormalParametersUnexpectedToken();
    3580             : 
    3581     8237576 :         Consume(Token::LBRACK);
    3582             :         int pos = position();
    3583     8238381 :         ExpressionT index = ParseExpressionCoverGrammar(true, CHECK_OK);
    3584     8236049 :         impl()->RewriteNonPattern(CHECK_OK);
    3585     8235761 :         expression = factory()->NewProperty(expression, index, pos);
    3586             :         impl()->PushPropertyName(index);
    3587     8235804 :         Expect(Token::RBRACK, CHECK_OK);
    3588     3353075 :         break;
    3589             :       }
    3590             :       case Token::PERIOD: {
    3591    23269018 :         *is_async = false;
    3592    23269307 :         impl()->RewriteNonPattern(CHECK_OK);
    3593    23268445 :         BindingPatternUnexpectedToken();
    3594    23268429 :         ArrowFormalParametersUnexpectedToken();
    3595             : 
    3596    23268429 :         Consume(Token::PERIOD);
    3597             :         int pos = position();
    3598    23268722 :         IdentifierT name = ParseIdentifierName(CHECK_OK);
    3599    26580284 :         expression = factory()->NewProperty(
    3600             :             expression, factory()->NewStringLiteral(name, pos), pos);
    3601    19955366 :         impl()->PushLiteralName(name);
    3602     3312456 :         break;
    3603             :       }
    3604             :       case Token::TEMPLATE_SPAN:
    3605             :       case Token::TEMPLATE_TAIL: {
    3606       24804 :         *is_async = false;
    3607       26532 :         impl()->RewriteNonPattern(CHECK_OK);
    3608       21348 :         BindingPatternUnexpectedToken();
    3609       21348 :         ArrowFormalParametersUnexpectedToken();
    3610             :         int pos;
    3611       21348 :         if (scanner()->current_token() == Token::IDENTIFIER) {
    3612             :           pos = position();
    3613             :         } else {
    3614             :           pos = peek_position();
    3615        2291 :           if (expression->IsFunctionLiteral()) {
    3616             :             // If the tag function looks like an IIFE, set_parenthesized() to
    3617             :             // force eager compilation.
    3618         938 :             expression->AsFunctionLiteral()->SetShouldEagerCompile();
    3619             :           }
    3620             :         }
    3621       25140 :         expression = ParseTemplateLiteral(expression, pos, true, CHECK_OK);
    3622             :         break;
    3623             :       }
    3624             :       case Token::ILLEGAL: {
    3625        1803 :         ReportUnexpectedTokenAt(scanner()->peek_location(), Token::ILLEGAL);
    3626        1803 :         *ok = false;
    3627        1803 :         return impl()->EmptyExpression();
    3628             :       }
    3629             :       default:
    3630    20335170 :         return expression;
    3631             :     }
    3632             :   }
    3633             :   DCHECK(false);
    3634             :   return impl()->EmptyExpression();
    3635             : }
    3636             : 
    3637             : template <typename Impl>
    3638    11275992 : void ParserBase<Impl>::ParseFormalParameter(FormalParametersT* parameters,
    3639     9680722 :                                             bool* ok) {
    3640             :   // FormalParameter[Yield,GeneratorParameter] :
    3641             :   //   BindingElement[?Yield, ?GeneratorParameter]
    3642    11275992 :   bool is_rest = parameters->has_rest;
    3643             : 
    3644    11307559 :   ExpressionT pattern = ParsePrimaryExpression(CHECK_OK_CUSTOM(Void));
    3645    11247021 :   ValidateBindingPattern(CHECK_OK_CUSTOM(Void));
    3646             : 
    3647    11234791 :   if (!impl()->IsIdentifier(pattern)) {
    3648       38057 :     parameters->is_simple = false;
    3649       38057 :     ValidateFormalParameterInitializer(CHECK_OK_CUSTOM(Void));
    3650             :     classifier()->RecordNonSimpleParameter();
    3651             :   }
    3652             : 
    3653             :   ExpressionT initializer = impl()->EmptyExpression();
    3654    11234023 :   if (!is_rest && Check(Token::ASSIGN)) {
    3655       41423 :     ExpressionClassifier init_classifier(this);
    3656       41423 :     initializer = ParseAssignmentExpression(true, CHECK_OK_CUSTOM(Void));
    3657       38063 :     impl()->RewriteNonPattern(CHECK_OK_CUSTOM(Void));
    3658       38063 :     ValidateFormalParameterInitializer(CHECK_OK_CUSTOM(Void));
    3659       35759 :     parameters->is_simple = false;
    3660             :     DiscardExpressionClassifier();
    3661             :     classifier()->RecordNonSimpleParameter();
    3662             : 
    3663       27593 :     impl()->SetFunctionNameFromIdentifierRef(initializer, pattern);
    3664             :   }
    3665             : 
    3666             :   impl()->AddFormalParameter(parameters, pattern, initializer,
    3667             :                              scanner()->location().end_pos, is_rest);
    3668             : }
    3669             : 
    3670             : template <typename Impl>
    3671     7984050 : void ParserBase<Impl>::ParseFormalParameterList(FormalParametersT* parameters,
    3672     6906066 :                                                 bool* ok) {
    3673             :   // FormalParameters[Yield] :
    3674             :   //   [empty]
    3675             :   //   FunctionRestParameter[?Yield]
    3676             :   //   FormalParameterList[?Yield]
    3677             :   //   FormalParameterList[?Yield] ,
    3678             :   //   FormalParameterList[?Yield] , FunctionRestParameter[?Yield]
    3679             :   //
    3680             :   // FormalParameterList[Yield] :
    3681             :   //   FormalParameter[?Yield]
    3682             :   //   FormalParameterList[?Yield] , FormalParameter[?Yield]
    3683             : 
    3684             :   DCHECK_EQ(0, parameters->arity);
    3685             : 
    3686     7984054 :   if (peek() != Token::RPAREN) {
    3687             :     while (true) {
    3688    11266079 :       if (parameters->arity > Code::kMaxArguments) {
    3689          15 :         ReportMessage(MessageTemplate::kTooManyParameters);
    3690          15 :         *ok = false;
    3691          15 :         return;
    3692             :       }
    3693    11266064 :       parameters->has_rest = Check(Token::ELLIPSIS);
    3694    11266065 :       ParseFormalParameter(parameters, CHECK_OK_CUSTOM(Void));
    3695             : 
    3696    11218429 :       if (parameters->has_rest) {
    3697       15807 :         parameters->is_simple = false;
    3698             :         classifier()->RecordNonSimpleParameter();
    3699       15807 :         if (peek() == Token::COMMA) {
    3700        2112 :           impl()->ReportMessageAt(scanner()->peek_location(),
    3701             :                                   MessageTemplate::kParamAfterRest);
    3702        3456 :           *ok = false;
    3703        3456 :           return;
    3704             :         }
    3705             :         break;
    3706             :       }
    3707    11202622 :       if (!Check(Token::COMMA)) break;
    3708    13718358 :       if (allow_harmony_trailing_commas() && peek() == Token::RPAREN) {
    3709             :         // allow the trailing comma
    3710             :         break;
    3711             :       }
    3712             :     }
    3713             :   }
    3714             : 
    3715     7932944 :   impl()->DeclareFormalParameters(parameters->scope, parameters->params);
    3716             : }
    3717             : 
    3718             : template <typename Impl>
    3719    18172373 : typename ParserBase<Impl>::BlockT ParserBase<Impl>::ParseVariableDeclarations(
    3720             :     VariableDeclarationContext var_context,
    3721             :     DeclarationParsingResult* parsing_result,
    3722   144810993 :     ZoneList<const AstRawString*>* names, bool* ok) {
    3723             :   // VariableDeclarations ::
    3724             :   //   ('var' | 'const' | 'let') (Identifier ('=' AssignmentExpression)?)+[',']
    3725             :   //
    3726             :   // ES6:
    3727             :   // FIXME(marja, nikolaos): Add an up-to-date comment about ES6 variable
    3728             :   // declaration syntax.
    3729             : 
    3730             :   DCHECK_NOT_NULL(parsing_result);
    3731    18172373 :   parsing_result->descriptor.declaration_kind = DeclarationDescriptor::NORMAL;
    3732    18172373 :   parsing_result->descriptor.declaration_pos = peek_position();
    3733    18172373 :   parsing_result->descriptor.initialization_pos = peek_position();
    3734             : 
    3735             :   BlockT init_block = impl()->NullBlock();
    3736    18172373 :   if (var_context != kForStatement) {
    3737    13017670 :     init_block = factory()->NewBlock(
    3738             :         nullptr, 1, true, parsing_result->descriptor.declaration_pos);
    3739             :   }
    3740             : 
    3741    18172372 :   switch (peek()) {
    3742             :     case Token::VAR:
    3743    16730826 :       parsing_result->descriptor.mode = VAR;
    3744    16730826 :       Consume(Token::VAR);
    3745    16730825 :       break;
    3746             :     case Token::CONST:
    3747      674763 :       Consume(Token::CONST);
    3748             :       DCHECK(var_context != kStatement);
    3749      674763 :       parsing_result->descriptor.mode = CONST;
    3750      674763 :       break;
    3751             :     case Token::LET:
    3752      766783 :       Consume(Token::LET);
    3753             :       DCHECK(var_context != kStatement);
    3754      766783 :       parsing_result->descriptor.mode = LET;
    3755      766783 :       break;
    3756             :     default:
    3757           0 :       UNREACHABLE();  // by current callers
    3758             :       break;
    3759             :   }
    3760             : 
    3761    18172371 :   parsing_result->descriptor.scope = scope();
    3762             : 
    3763             :   int bindings_start = peek_position();
    3764    18671840 :   do {
    3765             :     // Parse binding pattern.
    3766    18891550 :     FuncNameInferrer::State fni_state(fni_);
    3767             : 
    3768             :     ExpressionT pattern = impl()->EmptyExpression();
    3769             :     int decl_pos = peek_position();
    3770             :     {
    3771    18891550 :       ExpressionClassifier pattern_classifier(this);
    3772    18909552 :       pattern = ParsePrimaryExpression(CHECK_OK_CUSTOM(NullBlock));
    3773             : 
    3774    18862421 :       ValidateBindingPattern(CHECK_OK_CUSTOM(NullBlock));
    3775    37679594 :       if (IsLexicalVariableMode(parsing_result->descriptor.mode)) {
    3776     1659086 :         ValidateLetPattern(CHECK_OK_CUSTOM(NullBlock));
    3777             :       }
    3778             :     }
    3779             : 
    3780             :     Scanner::Location variable_loc = scanner()->location();
    3781             :     bool single_name = impl()->IsIdentifier(pattern);
    3782             : 
    3783    18837062 :     if (single_name) {
    3784    14178488 :       impl()->PushVariableName(impl()->AsIdentifier(pattern));
    3785             :     }
    3786             : 
    3787             :     ExpressionT value = impl()->EmptyExpression();
    3788             :     int initializer_position = kNoSourcePosition;
    3789    18837062 :     if (Check(Token::ASSIGN)) {
    3790    15664066 :       ExpressionClassifier classifier(this);
    3791    15664065 :       value = ParseAssignmentExpression(var_context != kForStatement,
    3792    31363303 :                                         CHECK_OK_CUSTOM(NullBlock));
    3793    15595015 :       impl()->RewriteNonPattern(CHECK_OK_CUSTOM(NullBlock));
    3794             :       variable_loc.end_pos = scanner()->location().end_pos;
    3795             : 
    3796    15594151 :       if (!parsing_result->first_initializer_loc.IsValid()) {
    3797    15345710 :         parsing_result->first_initializer_loc = variable_loc;
    3798             :       }
    3799             : 
    3800             :       // Don't infer if it is "a = function(){...}();"-like expression.
    3801    15594151 :       if (single_name && fni_ != nullptr) {
    3802    21834373 :         if (!value->IsCall() && !value->IsCallNew()) {
    3803    10008563 :           fni_->Infer();
    3804             :         } else {
    3805     1524722 :           fni_->RemoveLastFunction();
    3806             :         }
    3807             :       }
    3808             : 
    3809    11610631 :       impl()->SetFunctionNameFromIdentifierRef(value, pattern);
    3810             : 
    3811             :       // End position of the initializer is after the assignment expression.
    3812             :       initializer_position = scanner()->location().end_pos;
    3813             :     } else {
    3814     3172996 :       if (var_context != kForStatement || !PeekInOrOf()) {
    3815             :         // ES6 'const' and binding patterns require initializers.
    3816     5904961 :         if (parsing_result->descriptor.mode == CONST ||
    3817             :             !impl()->IsIdentifier(pattern)) {
    3818       41181 :           impl()->ReportMessageAt(
    3819             :               Scanner::Location(decl_pos, scanner()->location().end_pos),
    3820             :               MessageTemplate::kDeclarationMissingInitializer,
    3821             :               !impl()->IsIdentifier(pattern) ? "destructuring" : "const");
    3822       24413 :           *ok = false;
    3823       24413 :           return impl()->NullBlock();
    3824             :         }
    3825             :         // 'let x' initializes 'x' to undefined.
    3826     2933554 :         if (parsing_result->descriptor.mode == LET) {
    3827             :           value = impl()->GetLiteralUndefined(position());
    3828             :         }
    3829             :       }
    3830             : 
    3831             :       // End position of the initializer is after the variable.
    3832             :       initializer_position = position();
    3833             :     }
    3834             : 
    3835             :     typename DeclarationParsingResult::Declaration decl(
    3836             :         pattern, initializer_position, value);
    3837    18742734 :     if (var_context == kForStatement) {
    3838             :       // Save the declaration for further handling in ParseForStatement.
    3839     1188624 :       parsing_result->declarations.Add(decl);
    3840             :     } else {
    3841             :       // Immediately declare the variable otherwise. This avoids O(N^2)
    3842             :       // behavior (where N is the number of variables in a single
    3843             :       // declaration) in the PatternRewriter having to do with removing
    3844             :       // and adding VariableProxies to the Scope (see bug 4699).
    3845    17554110 :       impl()->DeclareAndInitializeVariables(init_block,
    3846             :                                             &parsing_result->descriptor, &decl,
    3847    17554110 :                                             names, CHECK_OK_CUSTOM(NullBlock));
    3848             :     }
    3849             :   } while (Check(Token::COMMA));
    3850             : 
    3851    17952661 :   parsing_result->bindings_loc =
    3852             :       Scanner::Location(bindings_start, scanner()->location().end_pos);
    3853             : 
    3854             :   DCHECK(*ok);
    3855    17952661 :   return init_block;
    3856             : }
    3857             : 
    3858             : template <typename Impl>
    3859             : typename ParserBase<Impl>::StatementT
    3860        3428 : ParserBase<Impl>::ParseFunctionDeclaration(bool* ok) {
    3861        1522 :   Consume(Token::FUNCTION);
    3862             :   int pos = position();
    3863             :   ParseFunctionFlags flags = ParseFunctionFlags::kIsNormal;
    3864        1522 :   if (Check(Token::MUL)) {
    3865         192 :     impl()->ReportMessageAt(scanner()->location(),
    3866             :                             MessageTemplate::kGeneratorInLegacyContext);
    3867         384 :     *ok = false;
    3868         384 :     return impl()->NullStatement();
    3869             :   }
    3870        1138 :   return ParseHoistableDeclaration(pos, flags, nullptr, false, ok);
    3871             : }
    3872             : 
    3873             : template <typename Impl>
    3874             : typename ParserBase<Impl>::StatementT
    3875     1894838 : ParserBase<Impl>::ParseHoistableDeclaration(
    3876     1894839 :     ZoneList<const AstRawString*>* names, bool default_export, bool* ok) {
    3877     1894838 :   Expect(Token::FUNCTION, CHECK_OK_CUSTOM(NullStatement));
    3878             :   int pos = position();
    3879             :   ParseFunctionFlags flags = ParseFunctionFlags::kIsNormal;
    3880     1894839 :   if (Check(Token::MUL)) {
    3881             :     flags |= ParseFunctionFlags::kIsGenerator;
    3882             :   }
    3883     1894839 :   return ParseHoistableDeclaration(pos, flags, names, default_export, ok);
    3884             : }
    3885             : 
    3886             : template <typename Impl>
    3887             : typename ParserBase<Impl>::StatementT
    3888     2067247 : ParserBase<Impl>::ParseHoistableDeclaration(
    3889             :     int pos, ParseFunctionFlags flags, ZoneList<const AstRawString*>* names,
    3890     6072997 :     bool default_export, bool* ok) {
    3891             :   // FunctionDeclaration ::
    3892             :   //   'function' Identifier '(' FormalParameters ')' '{' FunctionBody '}'
    3893             :   //   'function' '(' FormalParameters ')' '{' FunctionBody '}'
    3894             :   // GeneratorDeclaration ::
    3895             :   //   'function' '*' Identifier '(' FormalParameters ')' '{' FunctionBody '}'
    3896             :   //   'function' '*' '(' FormalParameters ')' '{' FunctionBody '}'
    3897             :   //
    3898             :   // The anonymous forms are allowed iff [default_export] is true.
    3899             :   //
    3900             :   // 'function' and '*' (if present) have been consumed by the caller.
    3901             : 
    3902             :   bool is_generator = flags & ParseFunctionFlags::kIsGenerator;
    3903             :   const bool is_async = flags & ParseFunctionFlags::kIsAsync;
    3904             :   DCHECK(!is_generator || !is_async);
    3905             : 
    3906     2067247 :   if (allow_harmony_async_iteration() && is_async && Check(Token::MUL)) {
    3907             :     // Async generator
    3908             :     is_generator = true;
    3909             :   }
    3910             : 
    3911             :   IdentifierT name;
    3912             :   FunctionNameValidity name_validity;
    3913             :   IdentifierT variable_name;
    3914     2067398 :   if (default_export && peek() == Token::LPAREN) {
    3915             :     impl()->GetDefaultStrings(&name, &variable_name);
    3916             :     name_validity = kSkipFunctionNameCheck;
    3917             :   } else {
    3918             :     bool is_strict_reserved;
    3919      241857 :     name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved,
    3920     2068452 :                                                CHECK_OK_CUSTOM(NullStatement));
    3921     2064407 :     name_validity = is_strict_reserved ? kFunctionNameIsStrictReserved
    3922             :                                        : kFunctionNameValidityUnknown;
    3923      240588 :     variable_name = name;
    3924             :   }
    3925             : 
    3926     2064471 :   FuncNameInferrer::State fni_state(fni_);
    3927     1823883 :   impl()->PushEnclosingName(name);
    3928             : 
    3929             :   FunctionKind kind = FunctionKindFor(is_generator, is_async);
    3930             : 
    3931             :   FunctionLiteralT function = impl()->ParseFunctionLiteral(
    3932             :       name, scanner()->location(), name_validity, kind, pos,
    3933             :       FunctionLiteral::kDeclaration, language_mode(),
    3934     4194516 :       CHECK_OK_CUSTOM(NullStatement));
    3935             : 
    3936             :   // In ES6, a function behaves as a lexical binding, except in
    3937             :   // a script scope, or the initial scope of eval or another function.
    3938             :   VariableMode mode =
    3939     1897454 :       (!scope()->is_declaration_scope() || scope()->is_module_scope()) ? LET
    3940     3824550 :                                                                        : VAR;
    3941             :   // Async functions don't undergo sloppy mode block scoped hoisting, and don't
    3942             :   // allow duplicates in a block. Both are represented by the
    3943             :   // sloppy_block_function_map. Don't add them to the map for async functions.
    3944             :   // Generators are also supposed to be prohibited; currently doing this behind
    3945             :   // a flag and UseCounting violations to assess web compatibility.
    3946             :   bool is_sloppy_block_function =
    3947             :       is_sloppy(language_mode()) && !scope()->is_declaration_scope() &&
    3948     1941279 :       !is_async && !(allow_harmony_restrictive_generators() && is_generator);
    3949             : 
    3950             :   return impl()->DeclareFunction(variable_name, function, mode, pos,
    3951     1752082 :                                  is_sloppy_block_function, names, ok);
    3952             : }
    3953             : 
    3954             : template <typename Impl>
    3955       87281 : typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseClassDeclaration(
    3956      227540 :     ZoneList<const AstRawString*>* names, bool default_export, bool* ok) {
    3957             :   // ClassDeclaration ::
    3958             :   //   'class' Identifier ('extends' LeftHandExpression)? '{' ClassBody '}'
    3959             :   //   'class' ('extends' LeftHandExpression)? '{' ClassBody '}'
    3960             :   //
    3961             :   // The anonymous form is allowed iff [default_export] is true.
    3962             :   //
    3963             :   // 'class' is expected to be consumed by the caller.
    3964             :   //
    3965             :   // A ClassDeclaration
    3966             :   //
    3967             :   //   class C { ... }
    3968             :   //
    3969             :   // has the same semantics as:
    3970             :   //
    3971             :   //   let C = class C { ... };
    3972             :   //
    3973             :   // so rewrite it as such.
    3974             : 
    3975             :   int class_token_pos = position();
    3976       24420 :   IdentifierT name = impl()->EmptyIdentifier();
    3977       87281 :   bool is_strict_reserved = false;
    3978             :   IdentifierT variable_name = impl()->EmptyIdentifier();
    3979       87379 :   if (default_export && (peek() == Token::EXTENDS || peek() == Token::LBRACE)) {
    3980             :     impl()->GetDefaultStrings(&name, &variable_name);
    3981             :   } else {
    3982       24420 :     name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved,
    3983       87652 :                                                CHECK_OK_CUSTOM(NullStatement));
    3984             :     variable_name = name;
    3985             :   }
    3986             : 
    3987       86391 :   ExpressionClassifier no_classifier(this);
    3988             :   ExpressionT value =
    3989             :       ParseClassLiteral(name, scanner()->location(), is_strict_reserved,
    3990      181110 :                         class_token_pos, CHECK_OK_CUSTOM(NullStatement));
    3991             :   int end_pos = position();
    3992             :   return impl()->DeclareClass(variable_name, value, names, class_token_pos,
    3993       53868 :                               end_pos, ok);
    3994             : }
    3995             : 
    3996             : // Language extension which is only enabled for source files loaded
    3997             : // through the API's extension mechanism.  A native function
    3998             : // declaration is resolved by looking up the function through a
    3999             : // callback provided by the extension.
    4000             : template <typename Impl>
    4001        2988 : typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseNativeDeclaration(
    4002        2988 :     bool* ok) {
    4003             :   int pos = peek_position();
    4004        2988 :   Expect(Token::FUNCTION, CHECK_OK_CUSTOM(NullStatement));
    4005             :   // Allow "eval" or "arguments" for backward compatibility.
    4006             :   IdentifierT name = ParseIdentifier(kAllowRestrictedIdentifiers,
    4007        2988 :                                      CHECK_OK_CUSTOM(NullStatement));
    4008        2988 :   Expect(Token::LPAREN, CHECK_OK_CUSTOM(NullStatement));
    4009        2988 :   if (peek() != Token::RPAREN) {
    4010           0 :     do {
    4011           0 :       ParseIdentifier(kAllowRestrictedIdentifiers,
    4012           0 :                       CHECK_OK_CUSTOM(NullStatement));
    4013             :     } while (Check(Token::COMMA));
    4014             :   }
    4015        2988 :   Expect(Token::RPAREN, CHECK_OK_CUSTOM(NullStatement));
    4016        2988 :   Expect(Token::SEMICOLON, CHECK_OK_CUSTOM(NullStatement));
    4017        2988 :   return impl()->DeclareNative(name, pos, ok);
    4018             : }
    4019             : 
    4020             : template <typename Impl>
    4021             : typename ParserBase<Impl>::StatementT
    4022      171294 : ParserBase<Impl>::ParseAsyncFunctionDeclaration(
    4023      171294 :     ZoneList<const AstRawString*>* names, bool default_export, bool* ok) {
    4024             :   // AsyncFunctionDeclaration ::
    4025             :   //   async [no LineTerminator here] function BindingIdentifier[Await]
    4026             :   //       ( FormalParameters[Await] ) { AsyncFunctionBody }
    4027             :   DCHECK_EQ(scanner()->current_token(), Token::ASYNC);
    4028             :   int pos = position();
    4029      342588 :   if (scanner()->HasAnyLineTerminatorBeforeNext()) {
    4030           0 :     *ok = false;
    4031           0 :     impl()->ReportUnexpectedToken(scanner()->current_token());
    4032           0 :     return impl()->NullStatement();
    4033             :   }
    4034      171294 :   Expect(Token::FUNCTION, CHECK_OK_CUSTOM(NullStatement));
    4035             :   ParseFunctionFlags flags = ParseFunctionFlags::kIsAsync;
    4036      171270 :   return ParseHoistableDeclaration(pos, flags, names, default_export, ok);
    4037             : }
    4038             : 
    4039             : template <typename Impl>
    4040     6682586 : void ParserBase<Impl>::ParseFunctionBody(
    4041             :     typename ParserBase<Impl>::StatementListT result, IdentifierT function_name,
    4042             :     int pos, const FormalParametersT& parameters, FunctionKind kind,
    4043    20771292 :     FunctionLiteral::FunctionType function_type, bool* ok) {
    4044             :   static const int kFunctionNameAssignmentIndex = 0;
    4045     6682586 :   if (function_type == FunctionLiteral::kNamedExpression) {
    4046             :     DCHECK(!impl()->IsEmptyIdentifier(function_name));
    4047             :     // If we have a named function expression, we add a local variable
    4048             :     // declaration to the body of the function with the name of the
    4049             :     // function and let it refer to the function itself (closure).
    4050             :     // Not having parsed the function body, the language mode may still change,
    4051             :     // so we reserve a spot and create the actual const assignment later.
    4052             :     DCHECK_EQ(kFunctionNameAssignmentIndex, result->length());
    4053             :     result->Add(impl()->NullStatement(), zone());
    4054             :   }
    4055             : 
    4056     6682580 :   DeclarationScope* function_scope = scope()->AsDeclarationScope();
    4057             :   DeclarationScope* inner_scope = function_scope;
    4058             :   BlockT inner_block = impl()->NullBlock();
    4059             : 
    4060      401157 :   StatementListT body = result;
    4061     6682582 :   if (!parameters.is_simple) {
    4062       78604 :     inner_scope = NewVarblockScope();
    4063             :     inner_scope->set_start_position(scanner()->location().beg_pos);
    4064       50244 :     inner_block = factory()->NewBlock(NULL, 8, true, kNoSourcePosition);
    4065             :     inner_block->set_scope(inner_scope);
    4066       78604 :     body = inner_block->statements();
    4067             :   }
    4068             : 
    4069             :   {
    4070     6682582 :     BlockState block_state(&scope_, inner_scope);
    4071             : 
    4072     6682582 :     if (IsGeneratorFunction(kind)) {
    4073       47797 :       impl()->ParseAndRewriteGeneratorFunctionBody(pos, kind, body, ok);
    4074     6566410 :     } else if (IsAsyncFunction(kind)) {
    4075             :       const bool accept_IN = true;
    4076       95528 :       ParseAsyncFunctionBody(inner_scope, body, kind, FunctionBodyType::kNormal,
    4077      191056 :                              accept_IN, pos, CHECK_OK_VOID);
    4078             :     } else {
    4079     6470889 :       ParseStatementList(body, Token::RBRACE, CHECK_OK_VOID);
    4080             :     }
    4081             : 
    4082     6577768 :     if (IsDerivedConstructor(kind)) {
    4083        6204 :       body->Add(factory()->NewReturnStatement(impl()->ThisExpression(),
    4084             :                                               kNoSourcePosition),
    4085             :                 zone());
    4086             :     }
    4087             :   }
    4088             : 
    4089     6577768 :   Expect(Token::RBRACE, CHECK_OK_VOID);
    4090             :   scope()->set_end_position(scanner()->location().end_pos);
    4091             : 
    4092     6542346 :   if (!parameters.is_simple) {
    4093             :     DCHECK_NOT_NULL(inner_scope);
    4094             :     DCHECK_EQ(function_scope, scope());
    4095             :     DCHECK_EQ(function_scope, inner_scope->outer_scope());
    4096       47156 :     impl()->SetLanguageMode(function_scope, inner_scope->language_mode());
    4097             :     BlockT init_block =
    4098       70524 :         impl()->BuildParameterInitializationBlock(parameters, CHECK_OK_VOID);
    4099             : 
    4100       69314 :     if (is_sloppy(inner_scope->language_mode())) {
    4101       19680 :       impl()->InsertSloppyBlockFunctionVarBindings(inner_scope);
    4102             :     }
    4103             : 
    4104             :     // TODO(littledan): Merge the two rejection blocks into one
    4105       71088 :     if (IsAsyncFunction(kind) && !IsAsyncGeneratorFunction(kind)) {
    4106        1643 :       init_block = impl()->BuildRejectPromiseOnException(init_block);
    4107             :     }
    4108             : 
    4109             :     inner_scope->set_end_position(scanner()->location().end_pos);
    4110       69314 :     if (inner_scope->FinalizeBlockScope() != nullptr) {
    4111       15976 :       impl()->CheckConflictingVarDeclarations(inner_scope, CHECK_OK_VOID);
    4112       15474 :       impl()->InsertShadowingVarBindingInitializers(inner_block);
    4113             :     } else {
    4114             :       inner_block->set_scope(nullptr);
    4115             :     }
    4116             :     inner_scope = nullptr;
    4117             : 
    4118             :     result->Add(init_block, zone());
    4119             :     result->Add(inner_block, zone());
    4120             :   } else {
    4121             :     DCHECK_EQ(inner_scope, function_scope);
    4122     6471822 :     if (is_sloppy(function_scope->language_mode())) {
    4123     2352640 :       impl()->InsertSloppyBlockFunctionVarBindings(function_scope);
    4124             :     }
    4125             :   }
    4126             : 
    4127     6540989 :   if (!IsArrowFunction(kind)) {
    4128             :     // Declare arguments after parsing the function since lexical 'arguments'
    4129             :     // masks the arguments object. Declare arguments before declaring the
    4130             :     // function var since the arguments object masks 'function arguments'.
    4131     6358195 :     function_scope->DeclareArguments(ast_value_factory());
    4132             :   }
    4133             : 
    4134     6207150 :   impl()->CreateFunctionNameAssignment(function_name, pos, function_type,
    4135             :                                        function_scope, result,
    4136             :                                        kFunctionNameAssignmentIndex);
    4137     6207149 :   impl()->MarkCollectedTailCallExpressions();
    4138             : }
    4139             : 
    4140             : template <typename Impl>
    4141     7886527 : void ParserBase<Impl>::CheckArityRestrictions(int param_count,
    4142             :                                               FunctionKind function_kind,
    4143             :                                               bool has_rest,
    4144             :                                               int formals_start_pos,
    4145             :                                               int formals_end_pos, bool* ok) {
    4146     7886527 :   if (IsGetterFunction(function_kind)) {
    4147       35741 :     if (param_count != 0) {
    4148         189 :       impl()->ReportMessageAt(
    4149             :           Scanner::Location(formals_start_pos, formals_end_pos),
    4150             :           MessageTemplate::kBadGetterArity);
    4151         293 :       *ok = false;
    4152             :     }
    4153     7850786 :   } else if (IsSetterFunction(function_kind)) {
    4154       26036 :     if (param_count != 1) {
    4155        1080 :       impl()->ReportMessageAt(
    4156             :           Scanner::Location(formals_start_pos, formals_end_pos),
    4157             :           MessageTemplate::kBadSetterArity);
    4158        1702 :       *ok = false;
    4159             :     }
    4160       26036 :     if (has_rest) {
    4161         240 :       impl()->ReportMessageAt(
    4162             :           Scanner::Location(formals_start_pos, formals_end_pos),
    4163             :           MessageTemplate::kBadSetterRestParameter);
    4164         384 :       *ok = false;
    4165             :     }
    4166             :   }
    4167     7886527 : }
    4168             : 
    4169             : template <typename Impl>
    4170      779470 : bool ParserBase<Impl>::IsNextLetKeyword() {
    4171             :   DCHECK(peek() == Token::LET);
    4172             :   Token::Value next_next = PeekAhead();
    4173      778388 :   switch (next_next) {
    4174             :     case Token::LBRACE:
    4175             :     case Token::LBRACK:
    4176             :     case Token::IDENTIFIER:
    4177             :     case Token::STATIC:
    4178             :     case Token::LET:  // `let let;` is disallowed by static semantics, but the
    4179             :                       // token must be first interpreted as a keyword in order
    4180             :                       // for those semantics to apply. This ensures that ASI is
    4181             :                       // not honored when a LineTerminator separates the
    4182             :                       // tokens.
    4183             :     case Token::ASYNC:
    4184             :       return true;
    4185             :     case Token::AWAIT:
    4186             :       // In an async function, allow ASI between `let` and `yield`
    4187         122 :       return !is_async_function() || !scanner_->HasAnyLineTerminatorAfterNext();
    4188             :     case Token::YIELD:
    4189             :       // In an generator, allow ASI between `let` and `yield`
    4190         986 :       return !is_generator() || !scanner_->HasAnyLineTerminatorAfterNext();
    4191             :     case Token::FUTURE_STRICT_RESERVED_WORD:
    4192        3840 :       return is_sloppy(language_mode());
    4193             :     default:
    4194       11468 :       return false;
    4195             :   }
    4196             : }
    4197             : 
    4198             : template <typename Impl>
    4199   138202689 : bool ParserBase<Impl>::IsTrivialExpression() {
    4200             :   Token::Value peek_token = peek();
    4201   138202981 :   if (peek_token == Token::SMI || peek_token == Token::NUMBER ||
    4202             :       peek_token == Token::NULL_LITERAL || peek_token == Token::TRUE_LITERAL ||
    4203             :       peek_token == Token::FALSE_LITERAL || peek_token == Token::STRING ||
    4204             :       peek_token == Token::IDENTIFIER || peek_token == Token::THIS) {
    4205             :     // PeekAhead() is expensive & may not always be called, so we only call it
    4206             :     // after checking peek().
    4207             :     Token::Value peek_ahead = PeekAhead();
    4208   119015285 :     if (peek_ahead == Token::COMMA || peek_ahead == Token::RPAREN ||
    4209             :         peek_ahead == Token::SEMICOLON || peek_ahead == Token::RBRACK) {
    4210             :       return true;
    4211             :     }
    4212             :   }
    4213             :   return false;
    4214             : }
    4215             : 
    4216             : template <typename Impl>
    4217             : typename ParserBase<Impl>::ExpressionT
    4218      733048 : ParserBase<Impl>::ParseArrowFunctionLiteral(
    4219             :     bool accept_IN, const FormalParametersT& formal_parameters,
    4220     2604035 :     int rewritable_length, bool* ok) {
    4221             :   const RuntimeCallStats::CounterId counters[2][2] = {
    4222             :       {&RuntimeCallStats::ParseBackgroundArrowFunctionLiteral,
    4223             :        &RuntimeCallStats::ParseArrowFunctionLiteral},
    4224             :       {&RuntimeCallStats::PreParseBackgroundArrowFunctionLiteral,
    4225      733048 :        &RuntimeCallStats::PreParseArrowFunctionLiteral}};
    4226             :   RuntimeCallTimerScope runtime_timer(
    4227             :       runtime_call_stats_,
    4228      733048 :       counters[Impl::IsPreParser()][parsing_on_main_thread_]);
    4229             : 
    4230     1465998 :   if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) {
    4231             :     // ASI inserts `;` after arrow parameters if a line terminator is found.
    4232             :     // `=> ...` is never a valid expression, so report as syntax error.
    4233             :     // If next token is not `=>`, it's a syntax error anyways.
    4234         576 :     ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW);
    4235         576 :     *ok = false;
    4236         576 :     return impl()->EmptyExpression();
    4237             :   }
    4238             : 
    4239       80470 :   StatementListT body = impl()->NullStatementList();
    4240             :   int expected_property_count = -1;
    4241             :   int function_literal_id = GetNextFunctionLiteralId();
    4242             : 
    4243      732472 :   FunctionKind kind = formal_parameters.scope->function_kind();
    4244             :   FunctionLiteral::EagerCompileHint eager_compile_hint =
    4245      652002 :       default_eager_compile_hint_;
    4246      652002 :   bool can_preparse = impl()->parse_lazily() &&
    4247      652002 :                       eager_compile_hint == FunctionLiteral::kShouldLazyCompile;
    4248             :   // TODO(marja): consider lazy-parsing inner arrow functions too. is_this
    4249             :   // handling in Scope::ResolveVariable needs to change.
    4250             :   bool is_lazy_top_level_function =
    4251     1197036 :       can_preparse && impl()->AllowsLazyParsingWithoutUnresolvedVariables();
    4252             :   bool should_be_used_once_hint = false;
    4253             :   bool has_braces = true;
    4254             :   {
    4255             :     FunctionState function_state(&function_state_, &scope_,
    4256      732472 :                                  formal_parameters.scope);
    4257             : 
    4258      732472 :     Expect(Token::ARROW, CHECK_OK);
    4259             : 
    4260      732374 :     if (peek() == Token::LBRACE) {
    4261             :       // Multiple statement body
    4262             :       DCHECK_EQ(scope(), formal_parameters.scope);
    4263      176983 :       if (is_lazy_top_level_function) {
    4264             :         // FIXME(marja): Arrow function parameters will be parsed even if the
    4265             :         // body is preparsed; move relevant parts of parameter handling to
    4266             :         // simulate consistent parameter handling.
    4267             :         Scanner::BookmarkScope bookmark(scanner());
    4268       31211 :         bookmark.Set();
    4269             :         // For arrow functions, we don't need to retrieve data about function
    4270             :         // parameters.
    4271       31211 :         int dummy_num_parameters = -1;
    4272             :         DCHECK((kind & FunctionKind::kArrowFunction) != 0);
    4273             :         LazyParsingResult result =
    4274             :             impl()->SkipFunction(kind, formal_parameters.scope,
    4275       31211 :                                  &dummy_num_parameters, false, true, CHECK_OK);
    4276       28649 :         formal_parameters.scope->ResetAfterPreparsing(
    4277             :             ast_value_factory_, result == kLazyParsingAborted);
    4278             : 
    4279       28649 :         if (result == kLazyParsingAborted) {
    4280           8 :           bookmark.Apply();
    4281             :           // Trigger eager (re-)parsing, just below this block.
    4282             :           is_lazy_top_level_function = false;
    4283             : 
    4284             :           // This is probably an initialization function. Inform the compiler it
    4285             :           // should also eager-compile this function, and that we expect it to
    4286             :           // be used once.
    4287             :           eager_compile_hint = FunctionLiteral::kShouldEagerCompile;
    4288             :           should_be_used_once_hint = true;
    4289             :         }
    4290             :       }
    4291      174421 :       if (!is_lazy_top_level_function) {
    4292      190640 :         Consume(Token::LBRACE);
    4293       44860 :         body = impl()->NewStatementList(8);
    4294      235500 :         impl()->ParseFunctionBody(body, impl()->EmptyIdentifier(),
    4295             :                                   kNoSourcePosition, formal_parameters, kind,
    4296             :                                   FunctionLiteral::kAnonymousExpression,
    4297      195620 :                                   CHECK_OK);
    4298      142914 :         expected_property_count = function_state.expected_property_count();
    4299             :       }
    4300             :     } else {
    4301             :       // Single-expression body
    4302             :       has_braces = false;
    4303             :       int pos = position();
    4304             :       DCHECK(ReturnExprContext::kInsideValidBlock ==
    4305             :              function_state_->return_expr_context());
    4306             :       ReturnExprScope allow_tail_calls(
    4307      510531 :           function_state_, ReturnExprContext::kInsideValidReturnStatement);
    4308       35610 :       body = impl()->NewStatementList(1);
    4309             :       impl()->AddParameterInitializationBlock(
    4310      510531 :           formal_parameters, body, kind == kAsyncArrowFunction, CHECK_OK);
    4311      510441 :       ExpressionClassifier classifier(this);
    4312      510441 :       if (kind == kAsyncArrowFunction) {
    4313        2237 :         ParseAsyncFunctionBody(scope(), body, kAsyncArrowFunction,
    4314             :                                FunctionBodyType::kSingleExpression, accept_IN,
    4315        4618 :                                pos, CHECK_OK);
    4316        1823 :         impl()->RewriteNonPattern(CHECK_OK);
    4317             :       } else {
    4318      509464 :         ExpressionT expression = ParseAssignmentExpression(accept_IN, CHECK_OK);
    4319      505854 :         impl()->RewriteNonPattern(CHECK_OK);
    4320      505854 :         body->Add(BuildReturnStatement(expression, expression->position()),
    4321             :                   zone());
    4322      474842 :         if (allow_tailcalls() && !is_sloppy(language_mode())) {
    4323             :           // ES6 14.6.1 Static Semantics: IsInTailPosition
    4324             :           impl()->MarkTailPosition(expression);
    4325             :         }
    4326             :       }
    4327      473471 :       expected_property_count = function_state.expected_property_count();
    4328      473471 :       impl()->MarkCollectedTailCallExpressions();
    4329             :     }
    4330             : 
    4331     2403662 :     formal_parameters.scope->set_end_position(scanner()->location().end_pos);
    4332             : 
    4333             :     // Arrow function formal parameters are parsed as StrictFormalParameterList,
    4334             :     // which is not the same as "parameters of a strict function"; it only means
    4335             :     // that duplicates are not allowed.  Of course, the arrow function may
    4336             :     // itself be strict as well.
    4337             :     const bool allow_duplicate_parameters = false;
    4338      719112 :     ValidateFormalParameters(language_mode(), allow_duplicate_parameters,
    4339      720204 :                              CHECK_OK);
    4340             : 
    4341             :     // Validate strict mode.
    4342      716855 :     if (is_strict(language_mode())) {
    4343      396828 :       CheckStrictOctalLiteral(formal_parameters.scope->start_position(),
    4344      793656 :                               scanner()->location().end_pos, CHECK_OK);
    4345             :     }
    4346      716855 :     impl()->CheckConflictingVarDeclarations(formal_parameters.scope, CHECK_OK);
    4347             : 
    4348      643861 :     if (is_lazy_top_level_function) {
    4349       48221 :       FunctionState* parent_state = function_state.outer();
    4350             :       DCHECK_NOT_NULL(parent_state);
    4351             :       DCHECK_GE(parent_state->destructuring_assignments_to_rewrite().length(),
    4352             :                 rewritable_length);
    4353             :       parent_state->RewindDestructuringAssignments(rewritable_length);
    4354             :     }
    4355             : 
    4356             :     impl()->RewriteDestructuringAssignments();
    4357             :   }
    4358             : 
    4359      716855 :   if (FLAG_trace_preparse) {
    4360           0 :     Scope* scope = formal_parameters.scope;
    4361           0 :     PrintF("  [%s]: %i-%i (arrow function)\n",
    4362             :            is_lazy_top_level_function ? "Preparse no-resolution" : "Full parse",
    4363           0 :            scope->start_position(), scope->end_position());
    4364             :   }
    4365             :   FunctionLiteralT function_literal = factory()->NewFunctionLiteral(
    4366             :       impl()->EmptyIdentifierString(), formal_parameters.scope, body,
    4367             :       expected_property_count, formal_parameters.num_parameters(),
    4368             :       formal_parameters.function_length,
    4369             :       FunctionLiteral::kNoDuplicateParameters,
    4370             :       FunctionLiteral::kAnonymousExpression, eager_compile_hint,
    4371             :       formal_parameters.scope->start_position(), has_braces,
    4372     1931583 :       function_literal_id);
    4373             : 
    4374      643861 :   function_literal->set_function_token_position(
    4375             :       formal_parameters.scope->start_position());
    4376      643861 :   if (should_be_used_once_hint) {
    4377             :     function_literal->set_should_be_used_once_hint();
    4378             :   }
    4379             : 
    4380      643861 :   impl()->AddFunctionForNameInference(function_literal);
    4381             : 
    4382      716855 :   return function_literal;
    4383             : }
    4384             : 
    4385             : template <typename Impl>
    4386      152779 : typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseClassLiteral(
    4387             :     IdentifierT name, Scanner::Location class_name_location,
    4388      301334 :     bool name_is_strict_reserved, int class_token_pos, bool* ok) {
    4389             :   // All parts of a ClassDeclaration and ClassExpression are strict code.
    4390      152779 :   if (name_is_strict_reserved) {
    4391         864 :     impl()->ReportMessageAt(class_name_location,
    4392             :                             MessageTemplate::kUnexpectedStrictReserved);
    4393        1728 :     *ok = false;
    4394        1728 :     return impl()->EmptyExpression();
    4395             :   }
    4396      151051 :   if (impl()->IsEvalOrArguments(name)) {
    4397         192 :     impl()->ReportMessageAt(class_name_location,
    4398             :                             MessageTemplate::kStrictEvalArguments);
    4399         384 :     *ok = false;
    4400         384 :     return impl()->EmptyExpression();
    4401             :   }
    4402             : 
    4403      301334 :   BlockState block_state(zone(), &scope_);
    4404      150667 :   RaiseLanguageMode(STRICT);
    4405             : 
    4406      150667 :   ClassInfo class_info(this);
    4407      150667 :   impl()->DeclareClassVariable(name, &class_info, class_token_pos, CHECK_OK);
    4408             : 
    4409             :   scope()->set_start_position(scanner()->location().end_pos);
    4410      150667 :   if (Check(Token::EXTENDS)) {
    4411       31942 :     ExpressionClassifier extends_classifier(this);
    4412       32734 :     class_info.extends = ParseLeftHandSideExpression(CHECK_OK);
    4413       30446 :     impl()->RewriteNonPattern(CHECK_OK);
    4414             :     AccumulateFormalParameterContainmentErrors();
    4415             :   }
    4416             : 
    4417             :   ClassLiteralChecker checker(this);
    4418             : 
    4419      149640 :   Expect(Token::LBRACE, CHECK_OK);
    4420             : 
    4421      148188 :   const bool has_extends = !impl()->IsEmptyExpression(class_info.extends);
    4422      703540 :   while (peek() != Token::RBRACE) {
    4423      456310 :     if (Check(Token::SEMICOLON)) continue;
    4424      404498 :     FuncNameInferrer::State fni_state(fni_);
    4425      404498 :     bool is_computed_name = false;  // Classes do not care about computed
    4426             :                                     // property names here.
    4427             :     bool is_static;
    4428             :     ClassLiteralProperty::Kind property_kind;
    4429      404498 :     ExpressionClassifier property_classifier(this);
    4430             :     // If we haven't seen the constructor yet, it potentially is the next
    4431             :     // property.
    4432      362647 :     bool is_constructor = !class_info.has_seen_constructor;
    4433             :     ClassLiteralPropertyT property = ParseClassPropertyDefinition(
    4434             :         &checker, has_extends, &is_computed_name,
    4435             :         &class_info.has_seen_constructor, &property_kind, &is_static,
    4436      415754 :         &class_info.has_name_static_property, CHECK_OK);
    4437      381258 :     if (!class_info.has_static_computed_names && is_static &&
    4438             :         is_computed_name) {
    4439        2840 :       class_info.has_static_computed_names = true;
    4440             :     }
    4441      350663 :     is_constructor &= class_info.has_seen_constructor;
    4442      381258 :     impl()->RewriteNonPattern(CHECK_OK);
    4443             :     AccumulateFormalParameterContainmentErrors();
    4444             : 
    4445             :     impl()->DeclareClassProperty(name, property, property_kind, is_static,
    4446      381258 :                                  is_constructor, &class_info, CHECK_OK);
    4447      350663 :     impl()->InferFunctionName();
    4448             :   }
    4449             : 
    4450      124948 :   Expect(Token::RBRACE, CHECK_OK);
    4451      124948 :   return impl()->RewriteClassLiteral(name, &class_info, class_token_pos, ok);
    4452             : }
    4453             : 
    4454             : template <typename Impl>
    4455       97765 : void ParserBase<Impl>::ParseAsyncFunctionBody(Scope* scope, StatementListT body,
    4456             :                                               FunctionKind kind,
    4457             :                                               FunctionBodyType body_type,
    4458             :                                               bool accept_IN, int pos,
    4459       73277 :                                               bool* ok) {
    4460             :   impl()->PrepareAsyncFunctionBody(body, kind, pos);
    4461             : 
    4462       40584 :   BlockT block = factory()->NewBlock(nullptr, 8, true, kNoSourcePosition);
    4463             : 
    4464             :   ExpressionT return_value = impl()->EmptyExpression();
    4465       97765 :   if (body_type == FunctionBodyType::kNormal) {
    4466             :     ParseStatementList(block->statements(), Token::RBRACE,
    4467      150557 :                        CHECK_OK_CUSTOM(Void));
    4468       30811 :     return_value = factory()->NewUndefinedLiteral(kNoSourcePosition);
    4469             :   } else {
    4470        2237 :     return_value = ParseAssignmentExpression(accept_IN, CHECK_OK_CUSTOM(Void));
    4471        1823 :     impl()->RewriteNonPattern(CHECK_OK_CUSTOM(Void));
    4472             :   }
    4473             : 
    4474             :   impl()->RewriteAsyncFunctionBody(body, block, return_value,
    4475       73277 :                                    CHECK_OK_CUSTOM(Void));
    4476             :   scope->set_end_position(scanner()->location().end_pos);
    4477             : }
    4478             : 
    4479             : template <typename Impl>
    4480             : typename ParserBase<Impl>::ExpressionT
    4481       60111 : ParserBase<Impl>::ParseAsyncFunctionLiteral(bool* ok) {
    4482             :   // AsyncFunctionLiteral ::
    4483             :   //   async [no LineTerminator here] function ( FormalParameters[Await] )
    4484             :   //       { AsyncFunctionBody }
    4485             :   //
    4486             :   //   async [no LineTerminator here] function BindingIdentifier[Await]
    4487             :   //       ( FormalParameters[Await] ) { AsyncFunctionBody }
    4488             :   DCHECK_EQ(scanner()->current_token(), Token::ASYNC);
    4489             :   int pos = position();
    4490       33712 :   Expect(Token::FUNCTION, CHECK_OK);
    4491       19945 :   bool is_strict_reserved = false;
    4492        6722 :   IdentifierT name = impl()->EmptyIdentifier();
    4493             :   FunctionLiteral::FunctionType type = FunctionLiteral::kAnonymousExpression;
    4494             : 
    4495       19945 :   bool is_generator = allow_harmony_async_iteration() && Check(Token::MUL);
    4496             :   const bool kIsAsync = true;
    4497       20838 :   static const FunctionKind kind = FunctionKindFor(is_generator, kIsAsync);
    4498             : 
    4499       13223 :   if (impl()->ParsingDynamicFunctionDeclaration()) {
    4500             :     // We don't want dynamic functions to actually declare their name
    4501             :     // "anonymous". We just want that name in the toString().
    4502         317 :     if (stack_overflow()) {
    4503           1 :       *ok = false;
    4504           1 :       return impl()->EmptyExpression();
    4505             :     }
    4506         316 :     Consume(Token::IDENTIFIER);
    4507             :     DCHECK(scanner()->CurrentMatchesContextual(Token::ANONYMOUS));
    4508       19628 :   } else if (peek_any_identifier()) {
    4509             :     type = FunctionLiteral::kNamedExpression;
    4510        5005 :     name = ParseIdentifierOrStrictReservedWord(kind, &is_strict_reserved,
    4511       10202 :                                                CHECK_OK);
    4512             :   }
    4513             :   return impl()->ParseFunctionLiteral(
    4514             :       name, scanner()->location(),
    4515             :       is_strict_reserved ? kFunctionNameIsStrictReserved
    4516             :                          : kFunctionNameValidityUnknown,
    4517       39264 :       kind, pos, type, language_mode(), CHECK_OK);
    4518             : }
    4519             : 
    4520             : template <typename Impl>
    4521       84139 : typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseTemplateLiteral(
    4522      368626 :     ExpressionT tag, int start, bool tagged, bool* ok) {
    4523             :   // A TemplateLiteral is made up of 0 or more TEMPLATE_SPAN tokens (literal
    4524             :   // text followed by a substitution expression), finalized by a single
    4525             :   // TEMPLATE_TAIL.
    4526             :   //
    4527             :   // In terms of draft language, TEMPLATE_SPAN may be either the TemplateHead or
    4528             :   // TemplateMiddle productions, while TEMPLATE_TAIL is either TemplateTail, or
    4529             :   // NoSubstitutionTemplate.
    4530             :   //
    4531             :   // When parsing a TemplateLiteral, we must have scanned either an initial
    4532             :   // TEMPLATE_SPAN, or a TEMPLATE_TAIL.
    4533      108112 :   CHECK(peek() == Token::TEMPLATE_SPAN || peek() == Token::TEMPLATE_TAIL);
    4534             : 
    4535       84139 :   bool forbid_illegal_escapes = !allow_harmony_template_escapes() || !tagged;
    4536             : 
    4537             :   // If we reach a TEMPLATE_TAIL first, we are parsing a NoSubstitutionTemplate.
    4538             :   // In this case we may simply consume the token and build a template with a
    4539             :   // single TEMPLATE_SPAN and no expressions.
    4540       84139 :   if (peek() == Token::TEMPLATE_TAIL) {
    4541       23973 :     Consume(Token::TEMPLATE_TAIL);
    4542             :     int pos = position();
    4543       12388 :     typename Impl::TemplateLiteralState ts = impl()->OpenTemplateLiteral(pos);
    4544       27261 :     bool is_valid = CheckTemplateEscapes(forbid_illegal_escapes, CHECK_OK);
    4545        8686 :     impl()->AddTemplateSpan(&ts, is_valid, true);
    4546        8686 :     return impl()->CloseTemplateLiteral(&ts, start, tag);
    4547             :   }
    4548             : 
    4549       60166 :   Consume(Token::TEMPLATE_SPAN);
    4550             :   int pos = position();
    4551       28362 :   typename Impl::TemplateLiteralState ts = impl()->OpenTemplateLiteral(pos);
    4552       62302 :   bool is_valid = CheckTemplateEscapes(forbid_illegal_escapes, CHECK_OK);
    4553       26274 :   impl()->AddTemplateSpan(&ts, is_valid, false);
    4554             :   Token::Value next;
    4555             : 
    4556             :   // If we open with a TEMPLATE_SPAN, we must scan the subsequent expression,
    4557             :   // and repeat if the following token is a TEMPLATE_SPAN as well (in this
    4558             :   // case, representing a TemplateMiddle).
    4559             : 
    4560       71222 :   do {
    4561             :     next = peek();
    4562       84129 :     if (next == Token::EOS) {
    4563        1116 :       impl()->ReportMessageAt(Scanner::Location(start, peek_position()),
    4564             :                               MessageTemplate::kUnterminatedTemplate);
    4565        1791 :       *ok = false;
    4566        1791 :       return impl()->EmptyExpression();
    4567       82338 :     } else if (next == Token::ILLEGAL) {
    4568         768 :       impl()->ReportMessageAt(
    4569             :           Scanner::Location(position() + 1, peek_position()),
    4570             :           MessageTemplate::kUnexpectedToken, "ILLEGAL", kSyntaxError);
    4571         768 :       *ok = false;
    4572         768 :       return impl()->EmptyExpression();
    4573             :     }
    4574             : 
    4575             :     int expr_pos = peek_position();
    4576       82494 :     ExpressionT expression = ParseExpressionCoverGrammar(true, CHECK_OK);
    4577       79924 :     impl()->RewriteNonPattern(CHECK_OK);
    4578             :     impl()->AddTemplateExpression(&ts, expression);
    4579             : 
    4580       79924 :     if (peek() != Token::RBRACE) {
    4581         144 :       impl()->ReportMessageAt(Scanner::Location(expr_pos, peek_position()),
    4582             :                               MessageTemplate::kUnterminatedTemplateExpr);
    4583         240 :       *ok = false;
    4584         240 :       return impl()->EmptyExpression();
    4585             :     }
    4586             : 
    4587             :     // If we didn't die parsing that expression, our next token should be a
    4588             :     // TEMPLATE_SPAN or TEMPLATE_TAIL.
    4589       79684 :     next = scanner()->ScanTemplateContinuation();
    4590             :     Next();
    4591             :     pos = position();
    4592             : 
    4593       79684 :     if (next == Token::EOS) {
    4594           0 :       impl()->ReportMessageAt(Scanner::Location(start, pos),
    4595             :                               MessageTemplate::kUnterminatedTemplate);
    4596           0 :       *ok = false;
    4597           0 :       return impl()->EmptyExpression();
    4598       79684 :     } else if (next == Token::ILLEGAL) {
    4599           0 :       impl()->ReportMessageAt(
    4600             :           Scanner::Location(position() + 1, peek_position()),
    4601             :           MessageTemplate::kUnexpectedToken, "ILLEGAL", kSyntaxError);
    4602           0 :       *ok = false;
    4603           0 :       return impl()->EmptyExpression();
    4604             :     }
    4605             : 
    4606       83956 :     bool is_valid = CheckTemplateEscapes(forbid_illegal_escapes, CHECK_OK);
    4607       35832 :     impl()->AddTemplateSpan(&ts, is_valid, next == Token::TEMPLATE_TAIL);
    4608             :   } while (next == Token::TEMPLATE_SPAN);
    4609             : 
    4610             :   DCHECK_EQ(next, Token::TEMPLATE_TAIL);
    4611             :   // Once we've reached a TEMPLATE_TAIL, we can close the TemplateLiteral.
    4612       20207 :   return impl()->CloseTemplateLiteral(&ts, start, tag);
    4613             : }
    4614             : 
    4615             : template <typename Impl>
    4616             : typename ParserBase<Impl>::ExpressionT
    4617             : ParserBase<Impl>::CheckAndRewriteReferenceExpression(
    4618             :     ExpressionT expression, int beg_pos, int end_pos,
    4619             :     MessageTemplate::Template message, bool* ok) {
    4620             :   return CheckAndRewriteReferenceExpression(expression, beg_pos, end_pos,
    4621    16214693 :                                             message, kReferenceError, ok);
    4622             : }
    4623             : 
    4624             : template <typename Impl>
    4625             : typename ParserBase<Impl>::ExpressionT
    4626    16333580 : ParserBase<Impl>::CheckAndRewriteReferenceExpression(
    4627             :     ExpressionT expression, int beg_pos, int end_pos,
    4628             :     MessageTemplate::Template message, ParseErrorType type, bool* ok) {
    4629    25652651 :   if (impl()->IsIdentifier(expression) && is_strict(language_mode()) &&
    4630             :       impl()->IsEvalOrArguments(impl()->AsIdentifier(expression))) {
    4631        1738 :     ReportMessageAt(Scanner::Location(beg_pos, end_pos),
    4632        1738 :                     MessageTemplate::kStrictEvalArguments, kSyntaxError);
    4633        5436 :     *ok = false;
    4634        5436 :     return impl()->EmptyExpression();
    4635             :   }
    4636    16328144 :   if (expression->IsValidReferenceExpression()) {
    4637     4569247 :     return expression;
    4638             :   }
    4639       21563 :   if (expression->IsCall()) {
    4640             :     // If it is a call, make it a runtime error for legacy web compatibility.
    4641             :     // Bug: https://bugs.chromium.org/p/v8/issues/detail?id=4480
    4642             :     // Rewrite `expr' to `expr[throw ReferenceError]'.
    4643        2822 :     impl()->CountUsage(
    4644             :         is_strict(language_mode())
    4645             :             ? v8::Isolate::kAssigmentExpressionLHSIsCallInStrict
    4646             :             : v8::Isolate::kAssigmentExpressionLHSIsCallInSloppy);
    4647             :     ExpressionT error = impl()->NewThrowReferenceError(message, beg_pos);
    4648        3088 :     return factory()->NewProperty(expression, error, beg_pos);
    4649             :   }
    4650        8293 :   ReportMessageAt(Scanner::Location(beg_pos, end_pos), message, type);
    4651       18741 :   *ok = false;
    4652       18741 :   return impl()->EmptyExpression();
    4653             : }
    4654             : 
    4655             : template <typename Impl>
    4656   155760174 : bool ParserBase<Impl>::IsValidReferenceExpression(ExpressionT expression) {
    4657   272737465 :   return IsAssignableIdentifier(expression) || expression->IsProperty();
    4658             : }
    4659             : 
    4660             : template <typename Impl>
    4661    19434274 : void ParserBase<Impl>::CheckDestructuringElement(ExpressionT expression,
    4662    15024863 :                                                  int begin, int end) {
    4663    57096634 :   if (!IsValidPattern(expression) && !expression->IsAssignment() &&
    4664    18738320 :       !IsValidReferenceExpression(expression)) {
    4665    15024863 :     classifier()->RecordAssignmentPatternError(
    4666             :         Scanner::Location(begin, end),
    4667             :         MessageTemplate::kInvalidDestructuringTarget);
    4668             :   }
    4669    19434275 : }
    4670             : 
    4671             : template <typename Impl>
    4672     2249046 : typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseV8Intrinsic(
    4673     2231200 :     bool* ok) {
    4674             :   // CallRuntime ::
    4675             :   //   '%' Identifier Arguments
    4676             : 
    4677             :   int pos = peek_position();
    4678     2249046 :   Expect(Token::MOD, CHECK_OK);
    4679             :   // Allow "eval" or "arguments" for backward compatibility.
    4680     2249047 :   IdentifierT name = ParseIdentifier(kAllowRestrictedIdentifiers, CHECK_OK);
    4681             :   Scanner::Location spread_pos;
    4682     2249039 :   ExpressionClassifier classifier(this);
    4683     2249039 :   ExpressionListT args = ParseArguments(&spread_pos, CHECK_OK);
    4684             : 
    4685             :   DCHECK(!spread_pos.IsValid());
    4686             : 
    4687     2231180 :   return impl()->NewV8Intrinsic(name, args, pos, ok);
    4688             : }
    4689             : 
    4690             : template <typename Impl>
    4691        1267 : typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseDoExpression(
    4692         772 :     bool* ok) {
    4693             :   // AssignmentExpression ::
    4694             :   //     do '{' StatementList '}'
    4695             : 
    4696             :   int pos = peek_position();
    4697        1267 :   Expect(Token::DO, CHECK_OK);
    4698        1267 :   BlockT block = ParseBlock(nullptr, CHECK_OK);
    4699         760 :   return impl()->RewriteDoExpression(block, pos, ok);
    4700             : }
    4701             : 
    4702             : // Redefinition of CHECK_OK for parsing statements.
    4703             : #undef CHECK_OK
    4704             : #define CHECK_OK CHECK_OK_CUSTOM(NullStatement)
    4705             : 
    4706             : template <typename Impl>
    4707             : typename ParserBase<Impl>::LazyParsingResult
    4708    10831503 : ParserBase<Impl>::ParseStatementList(StatementListT body, int end_token,
    4709    80130747 :                                      bool may_abort, bool* ok) {
    4710             :   // StatementList ::
    4711             :   //   (StatementListItem)* <end_token>
    4712             : 
    4713             :   // Allocate a target stack to use for this set of source
    4714             :   // elements. This way, all scripts and functions get their own
    4715             :   // target stack thus avoiding illegal breaks and continues across
    4716             :   // functions.
    4717             :   typename Types::TargetScope target_scope(this);
    4718             :   int count_statements = 0;
    4719             : 
    4720             :   DCHECK(!impl()->IsNullStatementList(body));
    4721             :   bool directive_prologue = true;  // Parsing directive prologue.
    4722             : 
    4723    66747306 :   while (peek() != end_token) {
    4724    58612274 :     if (directive_prologue && peek() != Token::STRING) {
    4725             :       directive_prologue = false;
    4726             :     }
    4727             : 
    4728             :     bool starts_with_identifier = peek() == Token::IDENTIFIER;
    4729             :     Scanner::Location token_loc = scanner()->peek_location();
    4730             :     StatementT stat =
    4731    46138458 :         ParseStatementListItem(CHECK_OK_CUSTOM(Return, kLazyParsingComplete));
    4732             : 
    4733    90189254 :     if (impl()->IsNullStatement(stat) || impl()->IsEmptyStatement(stat)) {
    4734             :       directive_prologue = false;  // End of directive prologue.
    4735           0 :       continue;
    4736             :     }
    4737             : 
    4738    43243018 :     if (directive_prologue) {
    4739             :       // The length of the token is used to distinguish between strings literals
    4740             :       // that evaluate equal to directives but contain either escape sequences
    4741             :       // (e.g., "use \x73trict") or line continuations (e.g., "use \(newline)
    4742             :       // strict").
    4743     2390685 :       if (impl()->IsUseStrictDirective(stat) &&
    4744             :           token_loc.end_pos - token_loc.beg_pos == sizeof("use strict") + 1) {
    4745             :         // Directive "use strict" (ES5 14.1).
    4746      532879 :         RaiseLanguageMode(STRICT);
    4747      532879 :         if (!scope()->HasSimpleParameters()) {
    4748             :           // TC39 deemed "use strict" directives to be an error when occurring
    4749             :           // in the body of a function with non-simple parameter list, on
    4750             :           // 29/7/2015. https://goo.gl/ueA7Ln
    4751        7218 :           impl()->ReportMessageAt(
    4752             :               token_loc, MessageTemplate::kIllegalLanguageModeDirective,
    4753             :               "use strict");
    4754       10306 :           *ok = false;
    4755       10306 :           return kLazyParsingComplete;
    4756             :         }
    4757     1857806 :       } else if (impl()->IsUseAsmDirective(stat) &&
    4758             :                  token_loc.end_pos - token_loc.beg_pos ==
    4759             :                      sizeof("use asm") + 1) {
    4760             :         // Directive "use asm".
    4761       11102 :         impl()->SetAsmModule();
    4762     1846704 :       } else if (impl()->IsStringLiteral(stat)) {
    4763             :         // Possibly an unknown directive.
    4764             :         // Should not change mode, but will increment usage counters
    4765             :         // as appropriate. Ditto usages below.
    4766     1838202 :         RaiseLanguageMode(SLOPPY);
    4767             :       } else {
    4768             :         // End of the directive prologue.
    4769             :         directive_prologue = false;
    4770        8502 :         RaiseLanguageMode(SLOPPY);
    4771             :       }
    4772             :     } else {
    4773    40852333 :       RaiseLanguageMode(SLOPPY);
    4774             :     }
    4775             : 
    4776             :     // If we're allowed to abort, we will do so when we see a "long and
    4777             :     // trivial" function. Our current definition of "long and trivial" is:
    4778             :     // - over kLazyParseTrialLimit statements
    4779             :     // - all starting with an identifier (i.e., no if, for, while, etc.)
    4780    43232711 :     if (may_abort) {
    4781     1039478 :       if (!starts_with_identifier) {
    4782             :         may_abort = false;
    4783      387707 :       } else if (++count_statements > kLazyParseTrialLimit) {
    4784             :         return kLazyParsingAborted;
    4785             :       }
    4786             :     }
    4787             : 
    4788             :     body->Add(stat, zone());
    4789             :   }
    4790             :   return kLazyParsingComplete;
    4791             : }
    4792             : 
    4793             : template <typename Impl>
    4794    59519745 : typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseStatementListItem(
    4795      171120 :     bool* ok) {
    4796             :   // ECMA 262 6th Edition
    4797             :   // StatementListItem[Yield, Return] :
    4798             :   //   Statement[?Yield, ?Return]
    4799             :   //   Declaration[?Yield]
    4800             :   //
    4801             :   // Declaration[Yield] :
    4802             :   //   HoistableDeclaration[?Yield]
    4803             :   //   ClassDeclaration[?Yield]
    4804             :   //   LexicalDeclaration[In, ?Yield]
    4805             :   //
    4806             :   // HoistableDeclaration[Yield, Default] :
    4807             :   //   FunctionDeclaration[?Yield, ?Default]
    4808             :   //   GeneratorDeclaration[?Yield, ?Default]
    4809             :   //
    4810             :   // LexicalDeclaration[In, Yield] :
    4811             :   //   LetOrConst BindingList[?In, ?Yield] ;
    4812             : 
    4813    59519787 :   switch (peek()) {
    4814             :     case Token::FUNCTION:
    4815     1894426 :       return ParseHoistableDeclaration(nullptr, false, ok);
    4816             :     case Token::CLASS:
    4817       87190 :       Consume(Token::CLASS);
    4818       87190 :       return ParseClassDeclaration(nullptr, false, ok);
    4819             :     case Token::VAR:
    4820             :     case Token::CONST:
    4821    16392530 :       return ParseVariableStatement(kStatementListItem, nullptr, ok);
    4822             :     case Token::LET:
    4823      614578 :       if (IsNextLetKeyword()) {
    4824      604038 :         return ParseVariableStatement(kStatementListItem, nullptr, ok);
    4825             :       }
    4826             :       break;
    4827             :     case Token::ASYNC:
    4828      342618 :       if (PeekAhead() == Token::FUNCTION &&
    4829             :           !scanner()->HasAnyLineTerminatorAfterNext()) {
    4830      171120 :         Consume(Token::ASYNC);
    4831      171120 :         return ParseAsyncFunctionDeclaration(nullptr, false, ok);
    4832             :       }
    4833             :     /* falls through */
    4834             :     default:
    4835             :       break;
    4836             :   }
    4837    40370483 :   return ParseStatement(nullptr, kAllowLabelledFunctionStatement, ok);
    4838             : }
    4839             : 
    4840             : template <typename Impl>
    4841    49241138 : typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseStatement(
    4842             :     ZoneList<const AstRawString*>* labels,
    4843     1584778 :     AllowLabelledFunctionStatement allow_function, bool* ok) {
    4844             :   // Statement ::
    4845             :   //   Block
    4846             :   //   VariableStatement
    4847             :   //   EmptyStatement
    4848             :   //   ExpressionStatement
    4849             :   //   IfStatement
    4850             :   //   IterationStatement
    4851             :   //   ContinueStatement
    4852             :   //   BreakStatement
    4853             :   //   ReturnStatement
    4854             :   //   WithStatement
    4855             :   //   LabelledStatement
    4856             :   //   SwitchStatement
    4857             :   //   ThrowStatement
    4858             :   //   TryStatement
    4859             :   //   DebuggerStatement
    4860             : 
    4861             :   // Note: Since labels can only be used by 'break' and 'continue'
    4862             :   // statements, which themselves are only valid within blocks,
    4863             :   // iterations or 'switch' statements (i.e., BreakableStatements),
    4864             :   // labels can be simply ignored in all other cases; except for
    4865             :   // trivial labeled break statements 'label: break label' which is
    4866             :   // parsed into an empty statement.
    4867    49241194 :   switch (peek()) {
    4868             :     case Token::LBRACE:
    4869     6199010 :       return ParseBlock(labels, ok);
    4870             :     case Token::SEMICOLON:
    4871             :       Next();
    4872      424796 :       return factory()->NewEmptyStatement(kNoSourcePosition);
    4873             :     case Token::IF:
    4874     6035015 :       return ParseIfStatement(labels, ok);
    4875             :     case Token::DO:
    4876       35292 :       return ParseDoWhileStatement(labels, ok);
    4877             :     case Token::WHILE:
    4878      126149 :       return ParseWhileStatement(labels, ok);
    4879             :     case Token::FOR:
    4880     1725967 :       if (V8_UNLIKELY(allow_harmony_async_iteration() && is_async_function() &&
    4881             :                       PeekAhead() == Token::AWAIT)) {
    4882      150431 :         return ParseForAwaitStatement(labels, ok);
    4883             :       }
    4884     1271511 :       return ParseForStatement(labels, ok);
    4885             :     case Token::CONTINUE:
    4886             :     case Token::BREAK:
    4887             :     case Token::RETURN:
    4888             :     case Token::THROW:
    4889             :     case Token::TRY: {
    4890             :       // These statements must have their labels preserved in an enclosing
    4891             :       // block, as the corresponding AST nodes do not currently store their
    4892             :       // labels.
    4893             :       // TODO(nikolaos, marja): Consider adding the labels to the AST nodes.
    4894     8614713 :       if (labels == nullptr) {
    4895     8614366 :         return ParseStatementAsUnlabelled(labels, ok);
    4896             :       } else {
    4897             :         BlockT result =
    4898         347 :             factory()->NewBlock(labels, 1, false, kNoSourcePosition);
    4899             :         typename Types::Target target(this, result);
    4900         347 :         StatementT statement = ParseStatementAsUnlabelled(labels, CHECK_OK);
    4901             :         result->statements()->Add(statement, zone());
    4902         220 :         return result;
    4903             :       }
    4904             :     }
    4905             :     case Token::WITH:
    4906      151321 :       return ParseWithStatement(labels, ok);
    4907             :     case Token::SWITCH:
    4908      184824 :       return ParseSwitchStatement(labels, ok);
    4909             :     case Token::FUNCTION:
    4910             :       // FunctionDeclaration only allowed as a StatementListItem, not in
    4911             :       // an arbitrary Statement position. Exceptions such as
    4912             :       // ES#sec-functiondeclarations-in-ifstatement-statement-clauses
    4913             :       // are handled by calling ParseScopedStatement rather than
    4914             :       // ParseStatement directly.
    4915       15177 :       impl()->ReportMessageAt(scanner()->peek_location(),
    4916             :                               is_strict(language_mode())
    4917             :                                   ? MessageTemplate::kStrictFunction
    4918             :                                   : MessageTemplate::kSloppyFunction);
    4919       10003 :       *ok = false;
    4920       10003 :       return impl()->NullStatement();
    4921             :     case Token::DEBUGGER:
    4922      219820 :       return ParseDebuggerStatement(ok);
    4923             :     case Token::VAR:
    4924         615 :       return ParseVariableStatement(kStatement, nullptr, ok);
    4925             :     default:
    4926    25927567 :       return ParseExpressionOrLabelledStatement(labels, allow_function, ok);
    4927             :   }
    4928             : }
    4929             : 
    4930             : // This method parses a subset of statements (break, continue, return, throw,
    4931             : // try) which are to be grouped because they all require their labeles to be
    4932             : // preserved in an enclosing block.
    4933             : template <typename Impl>
    4934             : typename ParserBase<Impl>::StatementT
    4935     8614708 : ParserBase<Impl>::ParseStatementAsUnlabelled(
    4936             :     ZoneList<const AstRawString*>* labels, bool* ok) {
    4937     8614717 :   switch (peek()) {
    4938             :     case Token::CONTINUE:
    4939      131041 :       return ParseContinueStatement(ok);
    4940             :     case Token::BREAK:
    4941      381507 :       return ParseBreakStatement(labels, ok);
    4942             :     case Token::RETURN:
    4943     7233448 :       return ParseReturnStatement(ok);
    4944             :     case Token::THROW:
    4945      443978 :       return ParseThrowStatement(ok);
    4946             :     case Token::TRY:
    4947      424743 :       return ParseTryStatement(ok);
    4948             :     default:
    4949           0 :       UNREACHABLE();
    4950             :       return impl()->NullStatement();
    4951             :   }
    4952             : }
    4953             : 
    4954             : template <typename Impl>
    4955     7039309 : typename ParserBase<Impl>::BlockT ParserBase<Impl>::ParseBlock(
    4956    37246110 :     ZoneList<const AstRawString*>* labels, bool* ok) {
    4957             :   // Block ::
    4958             :   //   '{' StatementList '}'
    4959             : 
    4960             :   // Construct block expecting 16 statements.
    4961     5551805 :   BlockT body = factory()->NewBlock(labels, 16, false, kNoSourcePosition);
    4962             : 
    4963             :   // Parse the statements and collect escaping labels.
    4964     7039619 :   Expect(Token::LBRACE, CHECK_OK_CUSTOM(NullBlock));
    4965             :   {
    4966    14077276 :     BlockState block_state(zone(), &scope_);
    4967             :     scope()->set_start_position(scanner()->location().beg_pos);
    4968             :     typename Types::Target target(this, body);
    4969             : 
    4970    19247938 :     while (peek() != Token::RBRACE) {
    4971    12248063 :       StatementT stat = ParseStatementListItem(CHECK_OK_CUSTOM(NullBlock));
    4972    24418606 :       if (!impl()->IsNullStatement(stat) && !impl()->IsEmptyStatement(stat)) {
    4973             :         body->statements()->Add(stat, zone());
    4974             :       }
    4975             :     }
    4976             : 
    4977     7006697 :     Expect(Token::RBRACE, CHECK_OK_CUSTOM(NullBlock));
    4978             :     scope()->set_end_position(scanner()->location().end_pos);
    4979     7006696 :     body->set_scope(scope()->FinalizeBlockScope());
    4980             :   }
    4981     7006697 :   return body;
    4982             : }
    4983             : 
    4984             : template <typename Impl>
    4985     7179272 : typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseScopedStatement(
    4986        4292 :     ZoneList<const AstRawString*>* labels, bool* ok) {
    4987    10454162 :   if (is_strict(language_mode()) || peek() != Token::FUNCTION) {
    4988     5609193 :     return ParseStatement(labels, ok);
    4989             :   } else {
    4990             :     // Make a block around the statement for a lexical binding
    4991             :     // is introduced by a FunctionDeclaration.
    4992        2208 :     BlockState block_state(zone(), &scope_);
    4993             :     scope()->set_start_position(scanner()->location().beg_pos);
    4994         566 :     BlockT block = factory()->NewBlock(NULL, 1, false, kNoSourcePosition);
    4995        1242 :     StatementT body = ParseFunctionDeclaration(CHECK_OK);
    4996             :     block->statements()->Add(body, zone());
    4997             :     scope()->set_end_position(scanner()->location().end_pos);
    4998         828 :     block->set_scope(scope()->FinalizeBlockScope());
    4999         828 :     return block;
    5000             :   }
    5001             : }
    5002             : 
    5003             : template <typename Impl>
    5004    16997648 : typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseVariableStatement(
    5005             :     VariableDeclarationContext var_context,
    5006             :     ZoneList<const AstRawString*>* names, bool* ok) {
    5007             :   // VariableStatement ::
    5008             :   //   VariableDeclarations ';'
    5009             : 
    5010             :   // The scope of a var declared variable anywhere inside a function
    5011             :   // is the entire function (ECMA-262, 3rd, 10.1.3, and 12.2). Thus we can
    5012             :   // transform a source-level var declaration into a (Function) Scope
    5013             :   // declaration, and rewrite the source-level initialization into an assignment
    5014             :   // statement. We use a block to collect multiple assignments.
    5015             :   //
    5016             :   // We mark the block as initializer block because we don't want the
    5017             :   // rewriter to add a '.result' assignment to such a block (to get compliant
    5018             :   // behavior for code such as print(eval('var x = 7')), and for cosmetic
    5019             :   // reasons when pretty-printing. Also, unless an assignment (initialization)
    5020             :   // is inside an initializer block, it is ignored.
    5021             : 
    5022             :   DeclarationParsingResult parsing_result;
    5023             :   StatementT result =
    5024    17058337 :       ParseVariableDeclarations(var_context, &parsing_result, names, CHECK_OK);
    5025    16806243 :   ExpectSemicolon(CHECK_OK);
    5026    16800399 :   return result;
    5027             : }
    5028             : 
    5029             : template <typename Impl>
    5030      219820 : typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseDebuggerStatement(
    5031       98375 :     bool* ok) {
    5032             :   // In ECMA-262 'debugger' is defined as a reserved keyword. In some browser
    5033             :   // contexts this is used as a statement which invokes the debugger as i a
    5034             :   // break point is present.
    5035             :   // DebuggerStatement ::
    5036             :   //   'debugger' ';'
    5037             : 
    5038             :   int pos = peek_position();
    5039      219820 :   Expect(Token::DEBUGGER, CHECK_OK);
    5040      219836 :   ExpectSemicolon(CHECK_OK);
    5041      196718 :   return factory()->NewDebuggerStatement(pos);
    5042             : }
    5043             : 
    5044             : template <typename Impl>
    5045             : typename ParserBase<Impl>::StatementT
    5046    25927561 : ParserBase<Impl>::ParseExpressionOrLabelledStatement(
    5047             :     ZoneList<const AstRawString*>* labels,
    5048    20196436 :     AllowLabelledFunctionStatement allow_function, bool* ok) {
    5049             :   // ExpressionStatement | LabelledStatement ::
    5050             :   //   Expression ';'
    5051             :   //   Identifier ':' Statement
    5052             :   //
    5053             :   // ExpressionStatement[Yield] :
    5054             :   //   [lookahead notin {{, function, class, let [}] Expression[In, ?Yield] ;
    5055             : 
    5056             :   int pos = peek_position();
    5057             : 
    5058    25927564 :   switch (peek()) {
    5059             :     case Token::FUNCTION:
    5060             :     case Token::LBRACE:
    5061           0 :       UNREACHABLE();  // Always handled by the callers.
    5062             :     case Token::CLASS:
    5063         408 :       ReportUnexpectedToken(Next());
    5064         408 :       *ok = false;
    5065         408 :       return impl()->NullStatement();
    5066             :     case Token::LET: {
    5067             :       Token::Value next_next = PeekAhead();
    5068             :       // "let" followed by either "[", "{" or an identifier means a lexical
    5069             :       // declaration, which should not appear here.
    5070       11092 :       if (next_next != Token::LBRACK && next_next != Token::LBRACE &&
    5071             :           next_next != Token::IDENTIFIER) {
    5072             :         break;
    5073             :       }
    5074         120 :       impl()->ReportMessageAt(scanner()->peek_location(),
    5075             :                               MessageTemplate::kUnexpectedLexicalDeclaration);
    5076         408 :       *ok = false;
    5077         408 :       return impl()->NullStatement();
    5078             :     }
    5079             :     default:
    5080             :       break;
    5081             :   }
    5082             : 
    5083    25926748 :   bool starts_with_identifier = peek_any_identifier();
    5084    26021858 :   ExpressionT expr = ParseExpression(true, CHECK_OK);
    5085    25734702 :   if (peek() == Token::COLON && starts_with_identifier &&
    5086             :       impl()->IsIdentifier(expr)) {
    5087             :     // The whole expression was a single identifier, and not, e.g.,
    5088             :     // something starting with an identifier or a parenthesized identifier.
    5089       25158 :     labels = impl()->DeclareLabel(labels, impl()->AsIdentifierExpression(expr),
    5090       47854 :                                   CHECK_OK);
    5091       47854 :     Consume(Token::COLON);
    5092             :     // ES#sec-labelled-function-declarations Labelled Function Declarations
    5093       53100 :     if (peek() == Token::FUNCTION && is_sloppy(language_mode()) &&
    5094             :         allow_function == kAllowLabelledFunctionStatement) {
    5095         418 :       return ParseFunctionDeclaration(ok);
    5096             :     }
    5097       24952 :     return ParseStatement(labels, ok);
    5098             :   }
    5099             : 
    5100             :   // If we have an extension, we allow a native function declaration.
    5101             :   // A native function declaration starts with "native function" with
    5102             :   // no line-terminator between the two words.
    5103    25652188 :   if (extension_ != nullptr && peek() == Token::FUNCTION &&
    5104        3000 :       !scanner()->HasAnyLineTerminatorBeforeNext() && impl()->IsNative(expr) &&
    5105             :       !scanner()->literal_contains_escapes()) {
    5106        2988 :     return ParseNativeDeclaration(ok);
    5107             :   }
    5108             : 
    5109             :   // Parsed expression statement, followed by semicolon.
    5110    25638268 :   ExpectSemicolon(CHECK_OK);
    5111    40024148 :   return factory()->NewExpressionStatement(expr, pos);
    5112             : }
    5113             : 
    5114             : template <typename Impl>
    5115     6035015 : typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseIfStatement(
    5116     4644371 :     ZoneList<const AstRawString*>* labels, bool* ok) {
    5117             :   // IfStatement ::
    5118             :   //   'if' '(' Expression ')' Statement ('else' Statement)?
    5119             : 
    5120             :   int pos = peek_position();
    5121     6035015 :   Expect(Token::IF, CHECK_OK);
    5122     6035150 :   Expect(Token::LPAREN, CHECK_OK);
    5123     6035840 :   ExpressionT condition = ParseExpression(true, CHECK_OK);
    5124     6032527 :   Expect(Token::RPAREN, CHECK_OK);
    5125     6033784 :   StatementT then_statement = ParseScopedStatement(labels, CHECK_OK);
    5126             :   StatementT else_statement = impl()->NullStatement();
    5127     6027531 :   if (Check(Token::ELSE)) {
    5128     1148100 :     else_statement = ParseScopedStatement(labels, CHECK_OK);
    5129             :   } else {
    5130     3673063 :     else_statement = factory()->NewEmptyStatement(kNoSourcePosition);
    5131             :   }
    5132             :   return factory()->NewIfStatement(condition, then_statement, else_statement,
    5133     9278258 :                                    pos);
    5134             : }
    5135             : 
    5136             : template <typename Impl>
    5137      131041 : typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseContinueStatement(
    5138      225302 :     bool* ok) {
    5139             :   // ContinueStatement ::
    5140             :   //   'continue' Identifier? ';'
    5141             : 
    5142             :   int pos = peek_position();
    5143      131041 :   Expect(Token::CONTINUE, CHECK_OK);
    5144             :   IdentifierT label = impl()->EmptyIdentifier();
    5145             :   Token::Value tok = peek();
    5146      262082 :   if (!scanner()->HasAnyLineTerminatorBeforeNext() && tok != Token::SEMICOLON &&
    5147             :       tok != Token::RBRACE && tok != Token::EOS) {
    5148             :     // ECMA allows "eval" or "arguments" as labels even in strict mode.
    5149        5479 :     label = ParseIdentifier(kAllowRestrictedIdentifiers, CHECK_OK);
    5150             :   }
    5151             :   typename Types::IterationStatement target =
    5152      130994 :       impl()->LookupContinueTarget(label, CHECK_OK);
    5153      130994 :   if (impl()->IsNullStatement(target)) {
    5154             :     // Illegal continue statement.
    5155             :     MessageTemplate::Template message = MessageTemplate::kIllegalContinue;
    5156             :     typename Types::BreakableStatement breakable_target =
    5157         306 :         impl()->LookupBreakTarget(label, CHECK_OK);
    5158         306 :     if (impl()->IsEmptyIdentifier(label)) {
    5159             :       message = MessageTemplate::kNoIterationStatement;
    5160         156 :     } else if (impl()->IsNullStatement(breakable_target)) {
    5161             :       message = MessageTemplate::kUnknownLabel;
    5162             :     }
    5163         306 :     ReportMessage(message, label);
    5164         306 :     *ok = false;
    5165         306 :     return impl()->NullStatement();
    5166             :   }
    5167      130704 :   ExpectSemicolon(CHECK_OK);
    5168      187844 :   return factory()->NewContinueStatement(target, pos);
    5169             : }
    5170             : 
    5171             : template <typename Impl>
    5172      381507 : typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseBreakStatement(
    5173      664981 :     ZoneList<const AstRawString*>* labels, bool* ok) {
    5174             :   // BreakStatement ::
    5175             :   //   'break' Identifier? ';'
    5176             : 
    5177             :   int pos = peek_position();
    5178      381507 :   Expect(Token::BREAK, CHECK_OK);
    5179             :   IdentifierT label = impl()->EmptyIdentifier();
    5180             :   Token::Value tok = peek();
    5181      763014 :   if (!scanner()->HasAnyLineTerminatorBeforeNext() && tok != Token::SEMICOLON &&
    5182             :       tok != Token::RBRACE && tok != Token::EOS) {
    5183             :     // ECMA allows "eval" or "arguments" as labels even in strict mode.
    5184       39287 :     label = ParseIdentifier(kAllowRestrictedIdentifiers, CHECK_OK);
    5185             :   }
    5186             :   // Parse labeled break statements that target themselves into
    5187             :   // empty statements, e.g. 'l1: l2: l3: break l2;'
    5188      302247 :   if (!impl()->IsEmptyIdentifier(label) &&
    5189             :       impl()->ContainsLabel(labels, label)) {
    5190         147 :     ExpectSemicolon(CHECK_OK);
    5191         144 :     return factory()->NewEmptyStatement(pos);
    5192             :   }
    5193             :   typename Types::BreakableStatement target =
    5194      381313 :       impl()->LookupBreakTarget(label, CHECK_OK);
    5195      381313 :   if (impl()->IsNullStatement(target)) {
    5196             :     // Illegal break statement.
    5197             :     MessageTemplate::Template message = MessageTemplate::kIllegalBreak;
    5198         176 :     if (!impl()->IsEmptyIdentifier(label)) {
    5199             :       message = MessageTemplate::kUnknownLabel;
    5200             :     }
    5201         176 :     ReportMessage(message, label);
    5202         176 :     *ok = false;
    5203         176 :     return impl()->NullStatement();
    5204             :   }
    5205      381139 :   ExpectSemicolon(CHECK_OK);
    5206      566236 :   return factory()->NewBreakStatement(target, pos);
    5207             : }
    5208             : 
    5209             : template <typename Impl>
    5210     7233437 : typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseReturnStatement(
    5211    21664492 :     bool* ok) {
    5212             :   // ReturnStatement ::
    5213             :   //   'return' [no line terminator] Expression? ';'
    5214             : 
    5215             :   // Consume the return token. It is necessary to do that before
    5216             :   // reporting any errors on it, because of the way errors are
    5217             :   // reported (underlining).
    5218     7233437 :   Expect(Token::RETURN, CHECK_OK);
    5219             :   Scanner::Location loc = scanner()->location();
    5220             : 
    5221     7233451 :   switch (GetDeclarationScope()->scope_type()) {
    5222             :     case SCRIPT_SCOPE:
    5223             :     case EVAL_SCOPE:
    5224             :     case MODULE_SCOPE:
    5225          24 :       impl()->ReportMessageAt(loc, MessageTemplate::kIllegalReturn);
    5226         150 :       *ok = false;
    5227         150 :       return impl()->NullStatement();
    5228             :     default:
    5229             :       break;
    5230             :   }
    5231             : 
    5232             :   Token::Value tok = peek();
    5233     1852067 :   ExpressionT return_value = impl()->EmptyExpression();
    5234    14466616 :   if (scanner()->HasAnyLineTerminatorBeforeNext() || tok == Token::SEMICOLON ||
    5235             :       tok == Token::RBRACE || tok == Token::EOS) {
    5236      773764 :     if (IsDerivedConstructor(function_state_->kind())) {
    5237           0 :       return_value = impl()->ThisExpression(loc.beg_pos);
    5238             :     } else {
    5239       43210 :       return_value = impl()->GetLiteralUndefined(position());
    5240             :     }
    5241             :   } else {
    5242    13692851 :     if (IsDerivedConstructor(function_state_->kind())) {
    5243             :       // Because of the return code rewriting that happens in case of a subclass
    5244             :       // constructor we don't want to accept tail calls, therefore we don't set
    5245             :       // ReturnExprScope to kInsideValidReturnStatement here.
    5246         880 :       return_value = ParseExpression(true, CHECK_OK);
    5247             :     } else {
    5248             :       ReturnExprScope maybe_allow_tail_calls(
    5249     6845545 :           function_state_, ReturnExprContext::kInsideValidReturnStatement);
    5250     6847424 :       return_value = ParseExpression(true, CHECK_OK);
    5251             : 
    5252     6880110 :       if (allow_tailcalls() && !is_sloppy(language_mode()) && !is_resumable()) {
    5253             :         // ES6 14.6.1 Static Semantics: IsInTailPosition
    5254       12488 :         function_state_->AddImplicitTailCallExpression(return_value);
    5255             :       }
    5256             :     }
    5257             :   }
    5258     7229373 :   ExpectSemicolon(CHECK_OK);
    5259     7229339 :   return_value = impl()->RewriteReturn(return_value, loc.beg_pos);
    5260     7229336 :   return BuildReturnStatement(return_value, loc.beg_pos);
    5261             : }
    5262             : 
    5263             : template <typename Impl>
    5264      151321 : typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseWithStatement(
    5265      356408 :     ZoneList<const AstRawString*>* labels, bool* ok) {
    5266             :   // WithStatement ::
    5267             :   //   'with' '(' Expression ')' Statement
    5268             : 
    5269      151321 :   Expect(Token::WITH, CHECK_OK);
    5270             :   int pos = position();
    5271             : 
    5272      151321 :   if (is_strict(language_mode())) {
    5273         874 :     ReportMessage(MessageTemplate::kStrictWith);
    5274         874 :     *ok = false;
    5275         874 :     return impl()->NullStatement();
    5276             :   }
    5277             : 
    5278      150461 :   Expect(Token::LPAREN, CHECK_OK);
    5279      150419 :   ExpressionT expr = ParseExpression(true, CHECK_OK);
    5280      150089 :   Expect(Token::RPAREN, CHECK_OK);
    5281             : 
    5282             :   Scope* with_scope = NewScope(WITH_SCOPE);
    5283             :   StatementT body = impl()->NullStatement();
    5284             :   {
    5285      150089 :     BlockState block_state(&scope_, with_scope);
    5286             :     with_scope->set_start_position(scanner()->peek_location().beg_pos);
    5287      150305 :     body = ParseStatement(labels, CHECK_OK);
    5288             :     with_scope->set_end_position(scanner()->location().end_pos);
    5289             :   }
    5290      111218 :   return factory()->NewWithStatement(with_scope, expr, body, pos);
    5291             : }
    5292             : 
    5293             : template <typename Impl>
    5294       35292 : typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseDoWhileStatement(
    5295       14676 :     ZoneList<const AstRawString*>* labels, bool* ok) {
    5296             :   // DoStatement ::
    5297             :   //   'do' Statement 'while' '(' Expression ')' ';'
    5298             : 
    5299       14676 :   auto loop = factory()->NewDoWhileStatement(labels, peek_position());
    5300             :   typename Types::Target target(this, loop);
    5301             : 
    5302       35292 :   Expect(Token::DO, CHECK_OK);
    5303       35873 :   StatementT body = ParseStatement(nullptr, CHECK_OK);
    5304       34156 :   Expect(Token::WHILE, CHECK_OK);
    5305       33798 :   Expect(Token::LPAREN, CHECK_OK);
    5306             : 
    5307       33801 :   ExpressionT cond = ParseExpression(true, CHECK_OK);
    5308       33725 :   Expect(Token::RPAREN, CHECK_OK);
    5309             : 
    5310             :   // Allow do-statements to be terminated with and without
    5311             :   // semi-colons. This allows code such as 'do;while(0)return' to
    5312             :   // parse, which would not be the case if we had used the
    5313             :   // ExpectSemicolon() functionality here.
    5314       33683 :   Check(Token::SEMICOLON);
    5315             : 
    5316             :   loop->Initialize(cond, body);
    5317       33683 :   return loop;
    5318             : }
    5319             : 
    5320             : template <typename Impl>
    5321      126149 : typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseWhileStatement(
    5322      101339 :     ZoneList<const AstRawString*>* labels, bool* ok) {
    5323             :   // WhileStatement ::
    5324             :   //   'while' '(' Expression ')' Statement
    5325             : 
    5326      101339 :   auto loop = factory()->NewWhileStatement(labels, peek_position());
    5327             :   typename Types::Target target(this, loop);
    5328             : 
    5329      126149 :   Expect(Token::WHILE, CHECK_OK);
    5330      126177 :   Expect(Token::LPAREN, CHECK_OK);
    5331      126093 :   ExpressionT cond = ParseExpression(true, CHECK_OK);
    5332      126093 :   Expect(Token::RPAREN, CHECK_OK);
    5333      126677 :   StatementT body = ParseStatement(nullptr, CHECK_OK);
    5334             : 
    5335             :   loop->Initialize(cond, body);
    5336      124812 :   return loop;
    5337             : }
    5338             : 
    5339             : template <typename Impl>
    5340      443978 : typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseThrowStatement(
    5341      443979 :     bool* ok) {
    5342             :   // ThrowStatement ::
    5343             :   //   'throw' Expression ';'
    5344             : 
    5345      443978 :   Expect(Token::THROW, CHECK_OK);
    5346             :   int pos = position();
    5347      887958 :   if (scanner()->HasAnyLineTerminatorBeforeNext()) {
    5348         182 :     ReportMessage(MessageTemplate::kNewlineAfterThrow);
    5349         182 :     *ok = false;
    5350         182 :     return impl()->NullStatement();
    5351             :   }
    5352      443847 :   ExpressionT exception = ParseExpression(true, CHECK_OK);
    5353      443699 :   ExpectSemicolon(CHECK_OK);
    5354             : 
    5355      378107 :   return impl()->NewThrowStatement(exception, pos);
    5356             : }
    5357             : 
    5358             : template <typename Impl>
    5359      184824 : typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseSwitchStatement(
    5360     2750556 :     ZoneList<const AstRawString*>* labels, bool* ok) {
    5361             :   // SwitchStatement ::
    5362             :   //   'switch' '(' Expression ')' '{' CaseClause* '}'
    5363             :   // CaseClause ::
    5364             :   //   'case' Expression ':' StatementList
    5365             :   //   'default' ':' StatementList
    5366             : 
    5367             :   int switch_pos = peek_position();
    5368             : 
    5369      184824 :   Expect(Token::SWITCH, CHECK_OK);
    5370      184838 :   Expect(Token::LPAREN, CHECK_OK);
    5371      184872 :   ExpressionT tag = ParseExpression(true, CHECK_OK);
    5372      184539 :   Expect(Token::RPAREN, CHECK_OK);
    5373             : 
    5374       89755 :   auto switch_statement = factory()->NewSwitchStatement(labels, switch_pos);
    5375             : 
    5376             :   {
    5377      369078 :     BlockState cases_block_state(zone(), &scope_);
    5378             :     scope()->set_start_position(switch_pos);
    5379             :     scope()->SetNonlinear();
    5380             :     typename Types::Target target(this, switch_statement);
    5381             : 
    5382             :     bool default_seen = false;
    5383             :     auto cases = impl()->NewCaseClauseList(4);
    5384      184567 :     Expect(Token::LBRACE, CHECK_OK);
    5385     1629526 :     while (peek() != Token::RBRACE) {
    5386             :       // An empty label indicates the default case.
    5387             :       ExpressionT label = impl()->EmptyExpression();
    5388     1446140 :       if (Check(Token::CASE)) {
    5389     1299887 :         label = ParseExpression(true, CHECK_OK);
    5390             :       } else {
    5391      146600 :         Expect(Token::DEFAULT, CHECK_OK);
    5392      145601 :         if (default_seen) {
    5393          28 :           ReportMessage(MessageTemplate::kMultipleDefaultsInSwitch);
    5394          28 :           *ok = false;
    5395          28 :           return impl()->NullStatement();
    5396             :         }
    5397             :         default_seen = true;
    5398             :       }
    5399     1445372 :       Expect(Token::COLON, CHECK_OK);
    5400             :       int clause_pos = position();
    5401             :       StatementListT statements = impl()->NewStatementList(5);
    5402     7486610 :       while (peek() != Token::CASE && peek() != Token::DEFAULT &&
    5403             :              peek() != Token::RBRACE) {
    5404     1361907 :         StatementT stat = ParseStatementListItem(CHECK_OK);
    5405             :         statements->Add(stat, zone());
    5406             :       }
    5407      527426 :       auto clause = factory()->NewCaseClause(label, statements, clause_pos);
    5408             :       cases->Add(clause, zone());
    5409             :     }
    5410      183386 :     Expect(Token::RBRACE, CHECK_OK);
    5411             : 
    5412             :     scope()->set_end_position(scanner()->location().end_pos);
    5413             :     return impl()->RewriteSwitchStatement(tag, switch_statement, cases,
    5414      183386 :                                           scope()->FinalizeBlockScope());
    5415             :   }
    5416             : }
    5417             : 
    5418             : template <typename Impl>
    5419      424743 : typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseTryStatement(
    5420     2984552 :     bool* ok) {
    5421             :   // TryStatement ::
    5422             :   //   'try' Block Catch
    5423             :   //   'try' Block Finally
    5424             :   //   'try' Block Catch Finally
    5425             :   //
    5426             :   // Catch ::
    5427             :   //   'catch' '(' Identifier ')' Block
    5428             :   //
    5429             :   // Finally ::
    5430             :   //   'finally' Block
    5431             : 
    5432      424743 :   Expect(Token::TRY, CHECK_OK);
    5433             :   int pos = position();
    5434             : 
    5435             :   BlockT try_block = impl()->NullBlock();
    5436             :   {
    5437             :     ReturnExprScope no_tail_calls(function_state_,
    5438      424743 :                                   ReturnExprContext::kInsideTryBlock);
    5439      424967 :     try_block = ParseBlock(nullptr, CHECK_OK);
    5440             :   }
    5441             : 
    5442      423984 :   CatchInfo catch_info(this);
    5443             : 
    5444      443139 :   if (peek() != Token::CATCH && peek() != Token::FINALLY) {
    5445         311 :     ReportMessage(MessageTemplate::kNoCatchOrFinally);
    5446         311 :     *ok = false;
    5447         311 :     return impl()->NullStatement();
    5448             :   }
    5449             : 
    5450             :   BlockT catch_block = impl()->NullBlock();
    5451      423673 :   if (Check(Token::CATCH)) {
    5452      404867 :     Expect(Token::LPAREN, CHECK_OK);
    5453      404753 :     catch_info.scope = NewScope(CATCH_SCOPE);
    5454             :     catch_info.scope->set_start_position(scanner()->location().beg_pos);
    5455             : 
    5456             :     {
    5457             :       CollectExpressionsInTailPositionToListScope
    5458             :           collect_tail_call_expressions_scope(
    5459      404753 :               function_state_, &catch_info.tail_call_expressions);
    5460      404753 :       BlockState catch_block_state(&scope_, catch_info.scope);
    5461             : 
    5462      291165 :       catch_block = factory()->NewBlock(nullptr, 16, false, kNoSourcePosition);
    5463             : 
    5464             :       // Create a block scope to hold any lexical declarations created
    5465             :       // as part of destructuring the catch parameter.
    5466             :       {
    5467      404753 :         BlockState catch_variable_block_state(zone(), &scope_);
    5468             :         scope()->set_start_position(scanner()->location().beg_pos);
    5469             :         typename Types::Target target(this, catch_block);
    5470             : 
    5471             :         // This does not simply call ParsePrimaryExpression to avoid
    5472             :         // ExpressionFromIdentifier from being called in the first
    5473             :         // branch, which would introduce an unresolved symbol and mess
    5474             :         // with arrow function names.
    5475      404753 :         if (peek_any_identifier()) {
    5476      388663 :           catch_info.name =
    5477      672368 :               ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK);
    5478             :         } else {
    5479       16090 :           ExpressionClassifier pattern_classifier(this);
    5480       18612 :           catch_info.pattern = ParsePrimaryExpression(CHECK_OK);
    5481       12852 :           ValidateBindingPattern(CHECK_OK);
    5482             :         }
    5483             : 
    5484      395549 :         Expect(Token::RPAREN, CHECK_OK);
    5485      393389 :         impl()->RewriteCatchPattern(&catch_info, CHECK_OK);
    5486      285737 :         if (!impl()->IsNullStatement(catch_info.init_block)) {
    5487             :           catch_block->statements()->Add(catch_info.init_block, zone());
    5488             :         }
    5489             : 
    5490      393441 :         catch_info.inner_block = ParseBlock(nullptr, CHECK_OK);
    5491             :         catch_block->statements()->Add(catch_info.inner_block, zone());
    5492      392838 :         impl()->ValidateCatchBlock(catch_info, CHECK_OK);
    5493             :         scope()->set_end_position(scanner()->location().end_pos);
    5494      392306 :         catch_block->set_scope(scope()->FinalizeBlockScope());
    5495             :       }
    5496             :     }
    5497             : 
    5498      392306 :     catch_info.scope->set_end_position(scanner()->location().end_pos);
    5499             :   }
    5500             : 
    5501             :   BlockT finally_block = impl()->NullBlock();
    5502             :   DCHECK(peek() == Token::FINALLY || !impl()->IsNullStatement(catch_block));
    5503      411150 :   if (Check(Token::FINALLY)) {
    5504       20952 :     finally_block = ParseBlock(nullptr, CHECK_OK);
    5505             :   }
    5506             : 
    5507             :   return impl()->RewriteTryStatement(try_block, catch_block, finally_block,
    5508      296564 :                                      catch_info, pos);
    5509             : }
    5510             : 
    5511             : template <typename Impl>
    5512     1271511 : typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseForStatement(
    5513     5235201 :     ZoneList<const AstRawString*>* labels, bool* ok) {
    5514             :   typename FunctionState::FunctionOrEvalRecordingScope recording_scope(
    5515     1271511 :       function_state_);
    5516             :   int stmt_pos = peek_position();
    5517     1271511 :   ForInfo for_info(this);
    5518             :   bool bound_names_are_lexical = false;
    5519             : 
    5520             :   // Create an in-between scope for let-bound iteration variables.
    5521     2543022 :   BlockState for_state(zone(), &scope_);
    5522     1271511 :   Expect(Token::FOR, CHECK_OK);
    5523     1271525 :   Expect(Token::LPAREN, CHECK_OK);
    5524             :   scope()->set_start_position(scanner()->location().beg_pos);
    5525             : 
    5526      321509 :   StatementT init = impl()->NullStatement();
    5527             : 
    5528     2095253 :   if (peek() == Token::VAR || peek() == Token::CONST ||
    5529      123467 :       (peek() == Token::LET && IsNextLetKeyword())) {
    5530             :     // The initializer contains declarations.
    5531     1068334 :     ParseVariableDeclarations(kForStatement, &for_info.parsing_result, nullptr,
    5532     1073418 :                               CHECK_OK);
    5533             :     bound_names_are_lexical =
    5534     1059862 :         IsLexicalVariableMode(for_info.parsing_result.descriptor.mode);
    5535     1059862 :     for_info.position = scanner()->location().beg_pos;
    5536             : 
    5537     1059862 :     if (CheckInOrOf(&for_info.mode)) {
    5538             :       return ParseForEachStatementWithDeclarations(stmt_pos, &for_info, labels,
    5539      148448 :                                                    ok);
    5540             :     }
    5541             : 
    5542             :     // One or more declaration not followed by in/of.
    5543     1101891 :     init = impl()->BuildInitializationBlock(
    5544             :         &for_info.parsing_result,
    5545      911414 :         bound_names_are_lexical ? &for_info.bound_names : nullptr, CHECK_OK);
    5546      203149 :   } else if (peek() != Token::SEMICOLON) {
    5547             :     // The initializer does not contain declarations.
    5548             :     int lhs_beg_pos = peek_position();
    5549      181596 :     ExpressionClassifier classifier(this);
    5550      182636 :     ExpressionT expression = ParseExpressionCoverGrammar(false, CHECK_OK);
    5551             :     int lhs_end_pos = scanner()->location().end_pos;
    5552             : 
    5553      179238 :     bool is_for_each = CheckInOrOf(&for_info.mode);
    5554             :     bool is_destructuring = is_for_each && (expression->IsArrayLiteral() ||
    5555      377452 :                                             expression->IsObjectLiteral());
    5556             : 
    5557      179238 :     if (is_destructuring) {
    5558       28796 :       ValidateAssignmentPattern(CHECK_OK);
    5559             :     } else {
    5560      151138 :       impl()->RewriteNonPattern(CHECK_OK);
    5561             :     }
    5562             : 
    5563      177846 :     if (is_for_each) {
    5564             :       return ParseForEachStatementWithoutDeclarations(stmt_pos, expression,
    5565             :                                                       lhs_beg_pos, lhs_end_pos,
    5566      134511 :                                                       &for_info, labels, ok);
    5567             :     }
    5568             :     // Initializer is just an expression.
    5569       43335 :     init = factory()->NewExpressionStatement(expression, lhs_beg_pos);
    5570             :   }
    5571             : 
    5572             :   // Standard 'for' loop, we have parsed the initializer at this point.
    5573             :   return ParseStandardForLoop(stmt_pos, init, bound_names_are_lexical,
    5574      976274 :                               &for_info, &for_state, labels, ok);
    5575             : }
    5576             : 
    5577             : template <typename Impl>
    5578             : typename ParserBase<Impl>::StatementT
    5579      148448 : ParserBase<Impl>::ParseForEachStatementWithDeclarations(
    5580             :     int stmt_pos, ForInfo* for_info, ZoneList<const AstRawString*>* labels,
    5581     1270595 :     bool* ok) {
    5582             :   scope()->set_is_hidden();
    5583             :   // Just one declaration followed by in/of.
    5584      148809 :   if (for_info->parsing_result.declarations.length() != 1) {
    5585        5966 :     impl()->ReportMessageAt(for_info->parsing_result.bindings_loc,
    5586             :                             MessageTemplate::kForInOfLoopMultiBindings,
    5587             :                             ForEachStatement::VisitModeString(for_info->mode));
    5588        3652 :     *ok = false;
    5589        3652 :     return impl()->NullStatement();
    5590             :   }
    5591      148026 :   if (for_info->parsing_result.first_initializer_loc.IsValid() &&
    5592             :       (is_strict(language_mode()) ||
    5593             :        for_info->mode == ForEachStatement::ITERATE ||
    5594         583 :        IsLexicalVariableMode(for_info->parsing_result.descriptor.mode) ||
    5595         149 :        !impl()->IsIdentifier(
    5596             :            for_info->parsing_result.declarations[0].pattern))) {
    5597        3109 :     impl()->ReportMessageAt(for_info->parsing_result.first_initializer_loc,
    5598             :                             MessageTemplate::kForInOfLoopInitializer,
    5599             :                             ForEachStatement::VisitModeString(for_info->mode));
    5600        1925 :     *ok = false;
    5601        1925 :     return impl()->NullStatement();
    5602             :   }
    5603             : 
    5604      112037 :   BlockT init_block = impl()->RewriteForVarInLegacy(*for_info);
    5605             : 
    5606      112037 :   auto loop = factory()->NewForEachStatement(for_info->mode, labels, stmt_pos);
    5607             :   typename Types::Target target(this, loop);
    5608             : 
    5609             :   int each_keyword_pos = scanner()->location().beg_pos;
    5610             : 
    5611             :   ExpressionT enumerable = impl()->EmptyExpression();
    5612      142871 :   if (for_info->mode == ForEachStatement::ITERATE) {
    5613       86997 :     ExpressionClassifier classifier(this);
    5614       87053 :     enumerable = ParseAssignmentExpression(true, CHECK_OK);
    5615       87193 :     impl()->RewriteNonPattern(CHECK_OK);
    5616             :   } else {
    5617       55874 :     enumerable = ParseExpression(true, CHECK_OK);
    5618             :   }
    5619             : 
    5620      142691 :   Expect(Token::RPAREN, CHECK_OK);
    5621             : 
    5622             :   StatementT final_loop = impl()->NullStatement();
    5623             :   {
    5624             :     ReturnExprScope no_tail_calls(function_state_,
    5625      141895 :                                   ReturnExprContext::kInsideForInOfBody);
    5626      283790 :     BlockState block_state(zone(), &scope_);
    5627             :     scope()->set_start_position(scanner()->location().beg_pos);
    5628             : 
    5629      143047 :     StatementT body = ParseStatement(nullptr, CHECK_OK);
    5630             : 
    5631      110525 :     BlockT body_block = impl()->NullBlock();
    5632      110525 :     ExpressionT each_variable = impl()->EmptyExpression();
    5633      110525 :     impl()->DesugarBindingInForEachStatement(for_info, &body_block,
    5634      139591 :                                              &each_variable, CHECK_OK);
    5635      110343 :     body_block->statements()->Add(body, zone());
    5636      110343 :     final_loop = impl()->InitializeForEachStatement(
    5637             :         loop, each_variable, enumerable, body_block, each_keyword_pos);
    5638             : 
    5639             :     scope()->set_end_position(scanner()->location().end_pos);
    5640      139409 :     body_block->set_scope(scope()->FinalizeBlockScope());
    5641             :   }
    5642             : 
    5643      110343 :   init_block = impl()->CreateForEachStatementTDZ(init_block, *for_info, ok);
    5644             : 
    5645             :   scope()->set_end_position(scanner()->location().end_pos);
    5646      139409 :   Scope* for_scope = scope()->FinalizeBlockScope();
    5647             :   // Parsed for-in loop w/ variable declarations.
    5648      139409 :   if (!impl()->IsNullStatement(init_block)) {
    5649             :     init_block->statements()->Add(final_loop, zone());
    5650             :     init_block->set_scope(for_scope);
    5651       60381 :     return init_block;
    5652             :   }
    5653             : 
    5654             :   DCHECK_NULL(for_scope);
    5655       27026 :   return final_loop;
    5656             : }
    5657             : 
    5658             : template <typename Impl>
    5659             : typename ParserBase<Impl>::StatementT
    5660      134511 : ParserBase<Impl>::ParseForEachStatementWithoutDeclarations(
    5661       56226 :     int stmt_pos, ExpressionT expression, int lhs_beg_pos, int lhs_end_pos,
    5662      782559 :     ForInfo* for_info, ZoneList<const AstRawString*>* labels, bool* ok) {
    5663             :   scope()->set_is_hidden();
    5664             :   // Initializer is reference followed by in/of.
    5665      196486 :   if (!expression->IsArrayLiteral() && !expression->IsObjectLiteral()) {
    5666      107731 :     expression = impl()->CheckAndRewriteReferenceExpression(
    5667             :         expression, lhs_beg_pos, lhs_end_pos, MessageTemplate::kInvalidLhsInFor,
    5668      108817 :         kSyntaxError, CHECK_OK);
    5669             :   }
    5670             : 
    5671       67444 :   auto loop = factory()->NewForEachStatement(for_info->mode, labels, stmt_pos);
    5672             :   typename Types::Target target(this, loop);
    5673             : 
    5674             :   int each_keyword_pos = scanner()->location().beg_pos;
    5675             : 
    5676             :   ExpressionT enumerable = impl()->EmptyExpression();
    5677      132750 :   if (for_info->mode == ForEachStatement::ITERATE) {
    5678       64358 :     ExpressionClassifier classifier(this);
    5679       68226 :     enumerable = ParseAssignmentExpression(true, CHECK_OK);
    5680       56734 :     impl()->RewriteNonPattern(CHECK_OK);
    5681             :   } else {
    5682       72184 :     enumerable = ParseExpression(true, CHECK_OK);
    5683             :   }
    5684             : 
    5685      117396 :   Expect(Token::RPAREN, CHECK_OK);
    5686             :   Scope* for_scope = scope();
    5687             : 
    5688             :   {
    5689             :     ReturnExprScope no_tail_calls(function_state_,
    5690      117112 :                                   ReturnExprContext::kInsideForInOfBody);
    5691      234224 :     BlockState block_state(zone(), &scope_);
    5692             :     scope()->set_start_position(scanner()->location().beg_pos);
    5693             : 
    5694      118336 :     StatementT body = ParseStatement(nullptr, CHECK_OK);
    5695             :     scope()->set_end_position(scanner()->location().end_pos);
    5696             :     StatementT final_loop = impl()->InitializeForEachStatement(
    5697       58408 :         loop, expression, enumerable, body, each_keyword_pos);
    5698             : 
    5699      114634 :     for_scope = for_scope->FinalizeBlockScope();
    5700             :     USE(for_scope);
    5701             :     DCHECK_NULL(for_scope);
    5702      114634 :     Scope* block_scope = scope()->FinalizeBlockScope();
    5703             :     USE(block_scope);
    5704             :     DCHECK_NULL(block_scope);
    5705      114634 :     return final_loop;
    5706             :   }
    5707             : }
    5708             : 
    5709             : template <typename Impl>
    5710      976274 : typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseStandardForLoop(
    5711             :     int stmt_pos, StatementT init, bool bound_names_are_lexical,
    5712             :     ForInfo* for_info, BlockState* for_state,
    5713     4171856 :     ZoneList<const AstRawString*>* labels, bool* ok) {
    5714      762309 :   auto loop = factory()->NewForStatement(labels, stmt_pos);
    5715             :   typename Types::Target target(this, loop);
    5716             : 
    5717      976952 :   Expect(Token::SEMICOLON, CHECK_OK);
    5718             : 
    5719             :   ExpressionT cond = impl()->EmptyExpression();
    5720             :   StatementT next = impl()->NullStatement();
    5721             :   StatementT body = impl()->NullStatement();
    5722             : 
    5723             :   // If there are let bindings, then condition and the next statement of the
    5724             :   // for loop must be parsed in a new scope.
    5725             :   Scope* inner_scope = scope();
    5726     1066273 :   if (bound_names_are_lexical && for_info->bound_names.length() > 0) {
    5727       87001 :     inner_scope = NewScopeWithParent(inner_scope, BLOCK_SCOPE);
    5728             :     inner_scope->set_start_position(scanner()->location().beg_pos);
    5729             :   }
    5730             :   {
    5731      975032 :     BlockState block_state(&scope_, inner_scope);
    5732             : 
    5733      975032 :     if (peek() != Token::SEMICOLON) {
    5734      956297 :       cond = ParseExpression(true, CHECK_OK);
    5735             :     }
    5736      974976 :     Expect(Token::SEMICOLON, CHECK_OK);
    5737             : 
    5738      974892 :     if (peek() != Token::RPAREN) {
    5739      898697 :       ExpressionT exp = ParseExpression(true, CHECK_OK);
    5740      692082 :       next = factory()->NewExpressionStatement(exp, exp->position());
    5741             :     }
    5742      974864 :     Expect(Token::RPAREN, CHECK_OK);
    5743             : 
    5744      976377 :     body = ParseStatement(nullptr, CHECK_OK);
    5745             :   }
    5746             : 
    5747             :   scope()->set_end_position(scanner()->location().end_pos);
    5748             :   inner_scope->set_end_position(scanner()->location().end_pos);
    5749     1236609 :   if (bound_names_are_lexical && for_info->bound_names.length() > 0 &&
    5750      173726 :       (is_resumable() || function_state_->contains_function_or_eval())) {
    5751             :     scope()->set_is_hidden();
    5752             :     return impl()->DesugarLexicalBindingsInForStatement(
    5753       25440 :         loop, init, cond, next, body, inner_scope, *for_info, CHECK_OK);
    5754             :   }
    5755             : 
    5756      946202 :   Scope* for_scope = scope()->FinalizeBlockScope();
    5757      946202 :   if (for_scope != nullptr) {
    5758             :     // Rewrite a for statement of the form
    5759             :     //   for (const x = i; c; n) b
    5760             :     //
    5761             :     // into
    5762             :     //
    5763             :     //   {
    5764             :     //     const x = i;
    5765             :     //     for (; c; n) b
    5766             :     //   }
    5767             :     //
    5768             :     // or, desugar
    5769             :     //   for (; c; n) b
    5770             :     // into
    5771             :     //   {
    5772             :     //     for (; c; n) b
    5773             :     //   }
    5774             :     // just in case b introduces a lexical binding some other way, e.g., if b
    5775             :     // is a FunctionDeclaration.
    5776       53948 :     BlockT block = factory()->NewBlock(nullptr, 2, false, kNoSourcePosition);
    5777       61561 :     if (!impl()->IsNullStatement(init)) {
    5778             :       block->statements()->Add(init, zone());
    5779             :       init = impl()->NullStatement();
    5780             :     }
    5781             :     block->statements()->Add(loop, zone());
    5782             :     block->set_scope(for_scope);
    5783             :     loop->Initialize(init, cond, next, body);
    5784       61561 :     return block;
    5785             :   }
    5786             : 
    5787             :   loop->Initialize(init, cond, next, body);
    5788      884641 :   return loop;
    5789             : }
    5790             : 
    5791             : template <typename Impl>
    5792    22740062 : void ParserBase<Impl>::MarkLoopVariableAsAssigned(Scope* scope, Variable* var) {
    5793    22740062 :   if (!IsLexicalVariableMode(var->mode()) && !scope->is_function_scope()) {
    5794             :     var->set_maybe_assigned();
    5795             :   }
    5796             : }
    5797             : 
    5798             : template <typename Impl>
    5799      150431 : typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseForAwaitStatement(
    5800     1289428 :     ZoneList<const AstRawString*>* labels, bool* ok) {
    5801             :   // for await '(' ForDeclaration of AssignmentExpression ')'
    5802             :   DCHECK(is_async_function());
    5803             :   DCHECK(allow_harmony_async_iteration());
    5804             : 
    5805             :   int stmt_pos = peek_position();
    5806             : 
    5807      150431 :   ForInfo for_info(this);
    5808      150431 :   for_info.mode = ForEachStatement::ITERATE;
    5809             : 
    5810             :   // Create an in-between scope for let-bound iteration variables.
    5811      300862 :   BlockState for_state(zone(), &scope_);
    5812      150431 :   Expect(Token::FOR, CHECK_OK);
    5813      150431 :   Expect(Token::AWAIT, CHECK_OK);
    5814      150431 :   Expect(Token::LPAREN, CHECK_OK);
    5815             :   scope()->set_start_position(scanner()->location().beg_pos);
    5816             :   scope()->set_is_hidden();
    5817             : 
    5818       37790 :   auto loop = factory()->NewForOfStatement(labels, stmt_pos);
    5819             :   typename Types::Target target(this, loop);
    5820             : 
    5821       37790 :   ExpressionT each_variable = impl()->EmptyExpression();
    5822             : 
    5823             :   bool has_declarations = false;
    5824             : 
    5825      399587 :   if (peek() == Token::VAR || peek() == Token::CONST ||
    5826       40343 :       (peek() == Token::LET && IsNextLetKeyword())) {
    5827             :     // The initializer contains declarations
    5828             :     // 'for' 'await' '(' ForDeclaration 'of' AssignmentExpression ')'
    5829             :     //     Statement
    5830             :     // 'for' 'await' '(' 'var' ForBinding 'of' AssignmentExpression ')'
    5831             :     //     Statement
    5832             :     has_declarations = true;
    5833      106391 :     ParseVariableDeclarations(kForStatement, &for_info.parsing_result, nullptr,
    5834      119927 :                               CHECK_OK);
    5835       88343 :     for_info.position = scanner()->location().beg_pos;
    5836             : 
    5837             :     // Only a single declaration is allowed in for-await-of loops
    5838       88343 :     if (for_info.parsing_result.declarations.length() != 1) {
    5839         576 :       impl()->ReportMessageAt(for_info.parsing_result.bindings_loc,
    5840             :                               MessageTemplate::kForInOfLoopMultiBindings,
    5841             :                               "for-await-of");
    5842         768 :       *ok = false;
    5843         768 :       return impl()->NullStatement();
    5844             :     }
    5845             : 
    5846             :     // for-await-of's declarations do not permit initializers.
    5847       87575 :     if (for_info.parsing_result.first_initializer_loc.IsValid()) {
    5848       13248 :       impl()->ReportMessageAt(for_info.parsing_result.first_initializer_loc,
    5849             :                               MessageTemplate::kForInOfLoopInitializer,
    5850             :                               "for-await-of");
    5851       17664 :       *ok = false;
    5852       17664 :       return impl()->NullStatement();
    5853             :     }
    5854             :   } else {
    5855             :     // The initializer does not contain declarations.
    5856             :     // 'for' 'await' '(' LeftHandSideExpression 'of' AssignmentExpression ')'
    5857             :     //     Statement
    5858             :     int lhs_beg_pos = peek_position();
    5859       44040 :     ExpressionClassifier classifier(this);
    5860       44616 :     ExpressionT lhs = each_variable = ParseLeftHandSideExpression(CHECK_OK);
    5861             :     int lhs_end_pos = scanner()->location().end_pos;
    5862             : 
    5863       52512 :     if (lhs->IsArrayLiteral() || lhs->IsObjectLiteral()) {
    5864       32692 :       ValidateAssignmentPattern(CHECK_OK);
    5865             :     } else {
    5866       11156 :       impl()->RewriteNonPattern(CHECK_OK);
    5867       11156 :       each_variable = impl()->CheckAndRewriteReferenceExpression(
    5868             :           lhs, lhs_beg_pos, lhs_end_pos, MessageTemplate::kInvalidLhsInFor,
    5869       15764 :           kSyntaxError, CHECK_OK);
    5870             :     }
    5871             :   }
    5872             : 
    5873      111167 :   ExpectContextualKeyword(Token::OF, CHECK_OK);
    5874             :   int each_keyword_pos = scanner()->location().beg_pos;
    5875             : 
    5876             :   const bool kAllowIn = true;
    5877             :   ExpressionT iterable = impl()->EmptyExpression();
    5878             : 
    5879             :   {
    5880       99743 :     ExpressionClassifier classifier(this);
    5881       99743 :     iterable = ParseAssignmentExpression(kAllowIn, CHECK_OK);
    5882       99743 :     impl()->RewriteNonPattern(CHECK_OK);
    5883             :   }
    5884             : 
    5885       99743 :   Expect(Token::RPAREN, CHECK_OK);
    5886             : 
    5887             :   StatementT final_loop = impl()->NullStatement();
    5888             :   Scope* for_scope = scope();
    5889             :   {
    5890             :     ReturnExprScope no_tail_calls(function_state_,
    5891       99743 :                                   ReturnExprContext::kInsideForInOfBody);
    5892       99743 :     BlockState block_state(zone(), &scope_);
    5893             :     scope()->set_start_position(scanner()->location().beg_pos);
    5894             : 
    5895      100031 :     StatementT body = ParseStatement(nullptr, CHECK_OK);
    5896             :     scope()->set_end_position(scanner()->location().end_pos);
    5897             : 
    5898       99359 :     if (has_declarations) {
    5899       17648 :       BlockT body_block = impl()->NullBlock();
    5900       17648 :       impl()->DesugarBindingInForEachStatement(&for_info, &body_block,
    5901       69911 :                                                &each_variable, CHECK_OK);
    5902       17648 :       body_block->statements()->Add(body, zone());
    5903       69911 :       body_block->set_scope(scope()->FinalizeBlockScope());
    5904             : 
    5905             :       const bool finalize = true;
    5906       17648 :       final_loop = impl()->InitializeForOfStatement(
    5907             :           loop, each_variable, iterable, body_block, finalize,
    5908             :           IteratorType::kAsync, each_keyword_pos);
    5909             :     } else {
    5910             :       const bool finalize = true;
    5911        7374 :       final_loop = impl()->InitializeForOfStatement(
    5912             :           loop, each_variable, iterable, body, finalize, IteratorType::kAsync,
    5913             :           each_keyword_pos);
    5914             : 
    5915       29448 :       for_scope = for_scope->FinalizeBlockScope();
    5916             :       DCHECK_NULL(for_scope);
    5917             :       USE(for_scope);
    5918       29448 :       Scope* block_scope = scope()->FinalizeBlockScope();
    5919             :       DCHECK_NULL(block_scope);
    5920             :       USE(block_scope);
    5921       29448 :       return final_loop;
    5922             :     }
    5923             :   }
    5924             : 
    5925             :   DCHECK(has_declarations);
    5926             :   BlockT init_block =
    5927       17648 :       impl()->CreateForEachStatementTDZ(impl()->NullBlock(), for_info, ok);
    5928             : 
    5929             :   for_scope->set_end_position(scanner()->location().end_pos);
    5930       69911 :   for_scope = for_scope->FinalizeBlockScope();
    5931             :   // Parsed for-in loop w/ variable declarations.
    5932       69911 :   if (!impl()->IsNullStatement(init_block)) {
    5933             :     init_block->statements()->Add(final_loop, zone());
    5934             :     init_block->set_scope(for_scope);
    5935       14084 :     return init_block;
    5936             :   }
    5937             :   DCHECK_NULL(for_scope);
    5938       52245 :   return final_loop;
    5939             : }
    5940             : 
    5941             : template <typename Impl>
    5942     6169542 : void ParserBase<Impl>::ObjectLiteralChecker::CheckDuplicateProto(
    5943        3390 :     Token::Value property) {
    5944     6169542 :   if (property == Token::SMI || property == Token::NUMBER) return;
    5945             : 
    5946     4549209 :   if (IsProto()) {
    5947      107245 :     if (has_seen_proto_) {
    5948        3390 :       this->parser()->classifier()->RecordExpressionError(
    5949             :           this->scanner()->location(), MessageTemplate::kDuplicateProto);
    5950        3390 :       return;
    5951             :     }
    5952      103855 :     has_seen_proto_ = true;
    5953             :   }
    5954             : }
    5955             : 
    5956             : template <typename Impl>
    5957      372045 : void ParserBase<Impl>::ClassLiteralChecker::CheckClassMethodName(
    5958             :     Token::Value property, PropertyKind type, bool is_generator, bool is_async,
    5959        2664 :     bool is_static, bool* ok) {
    5960             :   DCHECK(type == PropertyKind::kMethodProperty ||
    5961             :          type == PropertyKind::kAccessorProperty);
    5962             : 
    5963      372045 :   if (property == Token::SMI || property == Token::NUMBER) return;
    5964             : 
    5965      371544 :   if (is_static) {
    5966       24022 :     if (IsPrototype()) {
    5967        1332 :       this->parser()->ReportMessage(MessageTemplate::kStaticPrototype);
    5968        1332 :       *ok = false;
    5969        1332 :       return;
    5970             :     }
    5971      347522 :   } else if (IsConstructor()) {
    5972       16607 :     if (is_generator || is_async || type == PropertyKind::kAccessorProperty) {
    5973             :       MessageTemplate::Template msg =
    5974             :           is_generator ? MessageTemplate::kConstructorIsGenerator
    5975             :                        : is_async ? MessageTemplate::kConstructorIsAsync
    5976        1208 :                                   : MessageTemplate::kConstructorIsAccessor;
    5977        1208 :       this->parser()->ReportMessage(msg);
    5978        1208 :       *ok = false;
    5979        1208 :       return;
    5980             :     }
    5981       15399 :     if (has_seen_constructor_) {
    5982         124 :       this->parser()->ReportMessage(MessageTemplate::kDuplicateConstructor);
    5983         124 :       *ok = false;
    5984         124 :       return;
    5985             :     }
    5986       15275 :     has_seen_constructor_ = true;
    5987       15275 :     return;
    5988             :   }
    5989             : }
    5990             : 
    5991             : #undef CHECK_OK
    5992             : #undef CHECK_OK_CUSTOM
    5993             : #undef CHECK_OK_VOID
    5994             : 
    5995             : }  // namespace internal
    5996             : }  // namespace v8
    5997             : 
    5998             : #endif  // V8_PARSING_PARSER_BASE_H

Generated by: LCOV version 1.10