V8 Project
v8::internal::PreParser Class Reference

#include <preparser.h>

+ Inheritance diagram for v8::internal::PreParser:
+ Collaboration diagram for v8::internal::PreParser:

Public Types

enum  PreParseResult { kPreParseStackOverflow , kPreParseSuccess }
 
typedef PreParserIdentifier Identifier
 
typedef PreParserExpression Expression
 
typedef PreParserStatement Statement
 
- Public Types inherited from v8::internal::ParserBase< PreParserTraits >
typedef Traits::Type::Expression ExpressionT
 
typedef Traits::Type::Identifier IdentifierT
 
typedef Traits::Type::FunctionLiteral FunctionLiteralT
 
typedef Traits::Type::Literal LiteralT
 
typedef Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT
 

Public Member Functions

 PreParser (Scanner *scanner, ParserRecorder *log, uintptr_t stack_limit)
 
PreParseResult PreParseProgram ()
 
PreParseResult PreParseLazyFunction (StrictMode strict_mode, bool is_generator, ParserRecorder *log)
 
- Public Member Functions inherited from v8::internal::ParserBase< PreParserTraits >
 ParserBase (Scanner *scanner, uintptr_t stack_limit, v8::Extension *extension, ParserRecorder *log, typename Traits::Type::Zone *zone, AstNode::IdGen *ast_node_id_gen, typename Traits::Type::Parser this_object)
 
bool allow_lazy () const
 
bool allow_natives_syntax () const
 
bool allow_arrow_functions () const
 
bool allow_modules () const
 
bool allow_harmony_scoping () const
 
bool allow_harmony_numeric_literals () const
 
bool allow_classes () const
 
bool allow_harmony_object_literals () const
 
void set_allow_lazy (bool allow)
 
void set_allow_natives_syntax (bool allow)
 
void set_allow_arrow_functions (bool allow)
 
void set_allow_modules (bool allow)
 
void set_allow_harmony_scoping (bool allow)
 
void set_allow_harmony_numeric_literals (bool allow)
 
void set_allow_classes (bool allow)
 
void set_allow_harmony_object_literals (bool allow)
 
- Public Member Functions inherited from v8::internal::PreParserTraits
 PreParserTraits (PreParser *pre_parser)
 
bool ShortcutNumericLiteralBinaryExpression (PreParserExpression *x, PreParserExpression y, Token::Value op, int pos, PreParserFactory *factory)
 
PreParserExpression BuildUnaryExpression (PreParserExpression expression, Token::Value op, int pos, PreParserFactory *factory)
 
PreParserExpression NewThrowReferenceError (const char *type, int pos)
 
PreParserExpression NewThrowSyntaxError (const char *type, Handle< Object > arg, int pos)
 
PreParserExpression NewThrowTypeError (const char *type, Handle< Object > arg, int pos)
 
PreParserScope NewScope (PreParserScope *outer_scope, ScopeType scope_type)
 
void ReportMessageAt (Scanner::Location location, const char *message, const char *arg=NULL, bool is_reference_error=false)
 
void ReportMessageAt (int start_pos, int end_pos, const char *message, const char *arg=NULL, bool is_reference_error=false)
 
PreParserIdentifier GetSymbol (Scanner *scanner)
 
PreParserIdentifier GetNumberAsSymbol (Scanner *scanner)
 
PreParserExpression ExpressionFromString (int pos, Scanner *scanner, PreParserFactory *factory=NULL)
 
PreParserExpression GetIterator (PreParserExpression iterable, PreParserFactory *factory)
 
void SkipLazyFunctionBody (PreParserIdentifier function_name, int *materialized_literal_count, int *expected_property_count, bool *ok)
 
PreParserStatementList ParseEagerFunctionBody (PreParserIdentifier function_name, int pos, Variable *fvar, Token::Value fvar_init_op, bool is_generator, bool *ok)
 
int DeclareArrowParametersFromExpression (PreParserExpression expression, PreParserScope *scope, Scanner::Location *dupe_loc, bool *ok)
 
void CheckConflictingVarDeclarations (PreParserScope scope, bool *ok)
 
PreParserExpression ParseV8Intrinsic (bool *ok)
 
PreParserExpression ParseFunctionLiteral (PreParserIdentifier name, Scanner::Location function_name_location, bool name_is_strict_reserved, FunctionKind kind, int function_token_position, FunctionLiteral::FunctionType type, FunctionLiteral::ArityRestriction arity_restriction, bool *ok)
 

Private Types

enum  VariableDeclarationContext { kSourceElement , kStatement , kForStatement }
 
enum  VariableDeclarationProperties { kHasInitializers , kHasNoInitializers }
 
enum  SourceElements { kUnknownSourceElements }
 

Private Member Functions

Statement ParseSourceElement (bool *ok)
 
SourceElements ParseSourceElements (int end_token, bool *ok)
 
Statement ParseStatement (bool *ok)
 
Statement ParseFunctionDeclaration (bool *ok)
 
Statement ParseClassDeclaration (bool *ok)
 
Statement ParseBlock (bool *ok)
 
Statement ParseVariableStatement (VariableDeclarationContext var_context, bool *ok)
 
Statement ParseVariableDeclarations (VariableDeclarationContext var_context, VariableDeclarationProperties *decl_props, int *num_decl, bool *ok)
 
Statement ParseExpressionOrLabelledStatement (bool *ok)
 
Statement ParseIfStatement (bool *ok)
 
Statement ParseContinueStatement (bool *ok)
 
Statement ParseBreakStatement (bool *ok)
 
Statement ParseReturnStatement (bool *ok)
 
Statement ParseWithStatement (bool *ok)
 
Statement ParseSwitchStatement (bool *ok)
 
Statement ParseDoWhileStatement (bool *ok)
 
Statement ParseWhileStatement (bool *ok)
 
Statement ParseForStatement (bool *ok)
 
Statement ParseThrowStatement (bool *ok)
 
Statement ParseTryStatement (bool *ok)
 
Statement ParseDebuggerStatement (bool *ok)
 
Expression ParseConditionalExpression (bool accept_IN, bool *ok)
 
Expression ParseObjectLiteral (bool *ok)
 
Expression ParseV8Intrinsic (bool *ok)
 
void SkipLazyFunctionBody (PreParserIdentifier function_name, int *materialized_literal_count, int *expected_property_count, bool *ok)
 
PreParserStatementList ParseEagerFunctionBody (PreParserIdentifier function_name, int pos, Variable *fvar, Token::Value fvar_init_op, bool is_generator, bool *ok)
 
Expression ParseFunctionLiteral (Identifier name, Scanner::Location function_name_location, bool name_is_strict_reserved, FunctionKind kind, int function_token_pos, FunctionLiteral::FunctionType function_type, FunctionLiteral::ArityRestriction arity_restriction, bool *ok)
 
void ParseLazyFunctionLiteralBody (bool *ok)
 
bool CheckInOrOf (bool accept_OF)
 

Friends

class PreParserTraits
 

Additional Inherited Members

- Static Public Member Functions inherited from v8::internal::PreParserTraits
template<typename FunctionState >
static void SetUpFunctionState (FunctionState *function_state)
 
template<typename FunctionState >
static void TearDownFunctionState (FunctionState *function_state)
 
static bool IsEvalOrArguments (PreParserIdentifier identifier)
 
static bool IsPrototype (PreParserIdentifier identifier)
 
static bool IsConstructor (PreParserIdentifier identifier)
 
static bool IsThisProperty (PreParserExpression expression)
 
static bool IsIdentifier (PreParserExpression expression)
 
static PreParserIdentifier AsIdentifier (PreParserExpression expression)
 
static bool IsFutureStrictReserved (PreParserIdentifier identifier)
 
static bool IsBoilerplateProperty (PreParserExpression property)
 
static bool IsArrayIndex (PreParserIdentifier string, uint32_t *index)
 
static void PushLiteralName (FuncNameInferrer *fni, PreParserIdentifier id)
 
static void PushPropertyName (FuncNameInferrer *fni, PreParserExpression expression)
 
static void InferFunctionName (FuncNameInferrer *fni, PreParserExpression expression)
 
static void CheckFunctionLiteralInsideTopLevelObjectLiteral (PreParserScope *scope, PreParserExpression property, bool *has_function)
 
static void CheckAssigningFunctionLiteralToProperty (PreParserExpression left, PreParserExpression right)
 
static void CheckPossibleEvalCall (PreParserExpression expression, PreParserScope *scope)
 
static PreParserExpression MarkExpressionAsAssigned (PreParserExpression expression)
 
static PreParserIdentifier EmptyIdentifier ()
 
static PreParserIdentifier EmptyIdentifierString ()
 
static PreParserExpression EmptyExpression ()
 
static PreParserExpression EmptyArrowParamList ()
 
static PreParserExpression EmptyLiteral ()
 
static PreParserExpression EmptyObjectLiteralProperty ()
 
static PreParserExpression EmptyFunctionLiteral ()
 
static PreParserExpressionList NullExpressionList ()
 
static PreParserExpression GetLiteralTheHole (int position, PreParserFactory *factory)
 
static PreParserIdentifier GetNextSymbol (Scanner *scanner)
 
static PreParserExpression ThisExpression (PreParserScope *scope, PreParserFactory *factory)
 
static PreParserExpression SuperReference (PreParserScope *scope, PreParserFactory *factory)
 
static PreParserExpression ClassLiteral (PreParserIdentifier name, PreParserExpression extends, PreParserExpression constructor, PreParserExpressionList properties, int position, PreParserFactory *factory)
 
static PreParserExpression ExpressionFromLiteral (Token::Value token, int pos, Scanner *scanner, PreParserFactory *factory)
 
static PreParserExpression ExpressionFromIdentifier (PreParserIdentifier name, int pos, PreParserScope *scope, PreParserFactory *factory)
 
static PreParserExpressionList NewExpressionList (int size, void *zone)
 
static PreParserStatementList NewStatementList (int size, void *zone)
 
static PreParserExpressionList NewPropertyList (int size, void *zone)
 
static AstValueFactoryast_value_factory ()
 
- Protected Types inherited from v8::internal::ParserBase< PreParserTraits >
enum  AllowEvalOrArgumentsAsIdentifier
 
enum  Mode
 
enum  PropertyKind
 
- Protected Member Functions inherited from v8::internal::ParserBase< PreParserTraits >
Scannerscanner () const
 
int position ()
 
int peek_position ()
 
bool stack_overflow () const
 
void set_stack_overflow ()
 
Mode mode () const
 
Traits::Type::Zone * zone () const
 
AstNode::IdGenast_node_id_gen () const
 
 INLINE (Token::Value peek())
 
 INLINE (Token::Value Next())
 
void Consume (Token::Value token)
 
bool Check (Token::Value token)
 
void Expect (Token::Value token, bool *ok)
 
void ExpectSemicolon (bool *ok)
 
bool peek_any_identifier ()
 
bool CheckContextualKeyword (Vector< const char > keyword)
 
void ExpectContextualKeyword (Vector< const char > keyword, bool *ok)
 
void CheckOctalLiteral (int beg_pos, int end_pos, bool *ok)
 
void CheckStrictFunctionNameAndParameters (IdentifierT function_name, bool function_name_is_strict_reserved, const Scanner::Location &function_name_loc, const Scanner::Location &eval_args_error_loc, const Scanner::Location &dupe_error_loc, const Scanner::Location &reserved_loc, bool *ok)
 
Traits::Type::Factory * factory ()
 
StrictMode strict_mode ()
 
bool is_generator () const
 
void ReportMessage (const char *message, const char *arg=NULL, bool is_reference_error=false)
 
void ReportMessageAt (Scanner::Location location, const char *message, bool is_reference_error=false)
 
void ReportUnexpectedToken (Token::Value token)
 
IdentifierT ParseIdentifier (AllowEvalOrArgumentsAsIdentifier, bool *ok)
 
IdentifierT ParseIdentifierOrStrictReservedWord (bool *is_strict_reserved, bool *ok)
 
IdentifierT ParseIdentifierName (bool *ok)
 
IdentifierT ParseIdentifierNameOrGetOrSet (bool *is_get, bool *is_set, bool *ok)
 
ExpressionT ParseRegExpLiteral (bool seen_equal, bool *ok)
 
ExpressionT ParsePrimaryExpression (bool *ok)
 
ExpressionT ParseExpression (bool accept_IN, bool *ok)
 
ExpressionT ParseArrayLiteral (bool *ok)
 
IdentifierT ParsePropertyName (bool *is_get, bool *is_set, bool *is_static, bool *ok)
 
ExpressionT ParseObjectLiteral (bool *ok)
 
ObjectLiteralPropertyT ParsePropertyDefinition (ObjectLiteralChecker *checker, bool in_class, bool is_static, bool *ok)
 
Traits::Type::ExpressionList ParseArguments (bool *ok)
 
ExpressionT ParseAssignmentExpression (bool accept_IN, bool *ok)
 
ExpressionT ParseYieldExpression (bool *ok)
 
ExpressionT ParseConditionalExpression (bool accept_IN, bool *ok)
 
ExpressionT ParseBinaryExpression (int prec, bool accept_IN, bool *ok)
 
ExpressionT ParseUnaryExpression (bool *ok)
 
ExpressionT ParsePostfixExpression (bool *ok)
 
ExpressionT ParseLeftHandSideExpression (bool *ok)
 
ExpressionT ParseMemberWithNewPrefixesExpression (bool *ok)
 
ExpressionT ParseMemberExpression (bool *ok)
 
ExpressionT ParseMemberExpressionContinuation (ExpressionT expression, bool *ok)
 
ExpressionT ParseArrowFunctionLiteral (int start_pos, ExpressionT params_ast, bool *ok)
 
ExpressionT ParseClassLiteral (IdentifierT name, Scanner::Location function_name_location, bool name_is_strict_reserved, int pos, bool *ok)
 
ExpressionT CheckAndRewriteReferenceExpression (ExpressionT expression, Scanner::Location location, const char *message, bool *ok)
 
- Static Protected Member Functions inherited from v8::internal::ParserBase< PreParserTraits >
static int Precedence (Token::Value token, bool accept_IN)
 
- Protected Attributes inherited from v8::internal::ParserBase< PreParserTraits >
bool parenthesized_function_
 
Traits::Type::Scope * scope_
 
FunctionState * function_state_
 
v8::Extensionextension_
 
FuncNameInferrerfni_
 
ParserRecorderlog_
 
Mode mode_
 
uintptr_t stack_limit_
 

Detailed Description

Definition at line 1409 of file preparser.h.

Member Typedef Documentation

◆ Expression

◆ Identifier

◆ Statement

Member Enumeration Documentation

◆ PreParseResult

Enumerator
kPreParseStackOverflow 
kPreParseSuccess 

Definition at line 1415 of file preparser.h.

◆ SourceElements

Enumerator
kUnknownSourceElements 

Definition at line 1476 of file preparser.h.

1476  {
1478  };

◆ VariableDeclarationContext

Enumerator
kSourceElement 
kStatement 
kForStatement 

Definition at line 1463 of file preparser.h.

◆ VariableDeclarationProperties

Enumerator
kHasInitializers 
kHasNoInitializers 

Definition at line 1470 of file preparser.h.

1470  {
1473  };

Constructor & Destructor Documentation

◆ PreParser()

v8::internal::PreParser::PreParser ( Scanner scanner,
ParserRecorder log,
uintptr_t  stack_limit 
)
inline

Definition at line 1420 of file preparser.h.

1421  : ParserBase<PreParserTraits>(scanner, stack_limit, NULL, log, NULL, NULL,
1422  this) {}
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL

Member Function Documentation

◆ CheckInOrOf()

bool v8::internal::PreParser::CheckInOrOf ( bool  accept_OF)
private

Definition at line 681 of file preparser.cc.

681  {
682  if (Check(Token::IN) ||
683  (accept_OF && CheckContextualKeyword(CStrVector("of")))) {
684  return true;
685  }
686  return false;
687 }
bool CheckContextualKeyword(Vector< const char > keyword)
Definition: preparser.h:361
Vector< const char > CStrVector(const char *data)
Definition: vector.h:158
#define IN

References v8::internal::ParserBase< PreParserTraits >::Check(), v8::internal::ParserBase< PreParserTraits >::CheckContextualKeyword(), v8::internal::CStrVector(), and IN.

Referenced by ParseForStatement().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ParseBlock()

PreParser::Statement v8::internal::PreParser::ParseBlock ( bool ok)
private

Definition at line 371 of file preparser.cc.

371  {
372  // Block ::
373  // '{' Statement* '}'
374 
375  // Note that a Block does not introduce a new execution scope!
376  // (ECMA-262, 3rd, 12.2)
377  //
378  Expect(Token::LBRACE, CHECK_OK);
379  while (peek() != Token::RBRACE) {
380  if (allow_harmony_scoping() && strict_mode() == STRICT) {
382  } else {
384  }
385  }
386  Expect(Token::RBRACE, ok);
387  return Statement::Default();
388 }
void Expect(Token::Value token, bool *ok)
Definition: preparser.h:328
static PreParserStatement Default()
Definition: preparser.h:880
Statement ParseStatement(bool *ok)
Definition: preparser.cc:234
Statement ParseSourceElement(bool *ok)
Definition: preparser.cc:172
#define CHECK_OK
Definition: preparser.cc:816

References v8::internal::ParserBase< PreParserTraits >::allow_harmony_scoping(), CHECK_OK, v8::internal::PreParserStatement::Default(), v8::internal::ParserBase< PreParserTraits >::Expect(), ParseSourceElement(), ParseStatement(), v8::internal::STRICT, and v8::internal::ParserBase< PreParserTraits >::strict_mode().

Referenced by ParseStatement(), and ParseTryStatement().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ParseBreakStatement()

PreParser::Statement v8::internal::PreParser::ParseBreakStatement ( bool ok)
private

Definition at line 557 of file preparser.cc.

557  {
558  // BreakStatement ::
559  // 'break' [no line terminator] Identifier? ';'
560 
562  Token::Value tok = peek();
563  if (!scanner()->HasAnyLineTerminatorBeforeNext() &&
564  tok != Token::SEMICOLON &&
565  tok != Token::RBRACE &&
566  tok != Token::EOS) {
567  // ECMA allows "eval" or "arguments" as labels even in strict mode.
569  }
571  return Statement::Default();
572 }
IdentifierT ParseIdentifier(AllowEvalOrArgumentsAsIdentifier, bool *ok)
Definition: preparser.h:1637

References v8::internal::BREAK, CHECK_OK, v8::internal::PreParserStatement::Default(), v8::internal::ParserBase< PreParserTraits >::Expect(), v8::internal::ParserBase< PreParserTraits >::ExpectSemicolon(), v8::internal::ParserBase< PreParserTraits >::kAllowEvalOrArguments, v8::internal::ParserBase< PreParserTraits >::ParseIdentifier(), and v8::internal::ParserBase< PreParserTraits >::scanner().

Referenced by ParseStatement().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ParseClassDeclaration()

PreParser::Statement v8::internal::PreParser::ParseClassDeclaration ( bool ok)
private

Definition at line 359 of file preparser.cc.

359  {
360  Expect(Token::CLASS, CHECK_OK);
361  int pos = position();
362  bool is_strict_reserved = false;
363  Identifier name =
364  ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK);
365  ParseClassLiteral(name, scanner()->location(), is_strict_reserved, pos,
366  CHECK_OK);
367  return Statement::Default();
368 }
ExpressionT ParseClassLiteral(IdentifierT name, Scanner::Location function_name_location, bool name_is_strict_reserved, int pos, bool *ok)
Definition: preparser.h:2721
IdentifierT ParseIdentifierOrStrictReservedWord(bool *is_strict_reserved, bool *ok)
Definition: preparser.h:1664
PreParserIdentifier Identifier
Definition: preparser.h:1411
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in name

References CHECK_OK, v8::internal::PreParserStatement::Default(), v8::internal::ParserBase< PreParserTraits >::Expect(), name, v8::internal::ParserBase< PreParserTraits >::ParseClassLiteral(), v8::internal::ParserBase< PreParserTraits >::ParseIdentifierOrStrictReservedWord(), v8::internal::ParserBase< PreParserTraits >::position(), and v8::internal::ParserBase< PreParserTraits >::scanner().

Referenced by ParseSourceElement(), and ParseStatement().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ParseConditionalExpression()

Expression v8::internal::PreParser::ParseConditionalExpression ( bool  accept_IN,
bool ok 
)
private

◆ ParseContinueStatement()

PreParser::Statement v8::internal::PreParser::ParseContinueStatement ( bool ok)
private

Definition at line 539 of file preparser.cc.

539  {
540  // ContinueStatement ::
541  // 'continue' [no line terminator] Identifier? ';'
542 
543  Expect(Token::CONTINUE, CHECK_OK);
544  Token::Value tok = peek();
545  if (!scanner()->HasAnyLineTerminatorBeforeNext() &&
546  tok != Token::SEMICOLON &&
547  tok != Token::RBRACE &&
548  tok != Token::EOS) {
549  // ECMA allows "eval" or "arguments" as labels even in strict mode.
551  }
553  return Statement::Default();
554 }

References CHECK_OK, v8::internal::PreParserStatement::Default(), v8::internal::ParserBase< PreParserTraits >::Expect(), v8::internal::ParserBase< PreParserTraits >::ExpectSemicolon(), v8::internal::ParserBase< PreParserTraits >::kAllowEvalOrArguments, v8::internal::ParserBase< PreParserTraits >::ParseIdentifier(), and v8::internal::ParserBase< PreParserTraits >::scanner().

Referenced by ParseStatement().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ParseDebuggerStatement()

PreParser::Statement v8::internal::PreParser::ParseDebuggerStatement ( bool ok)
private

Definition at line 802 of file preparser.cc.

802  {
803  // In ECMA-262 'debugger' is defined as a reserved keyword. In some browser
804  // contexts this is used as a statement which invokes the debugger as if a
805  // break point is present.
806  // DebuggerStatement ::
807  // 'debugger' ';'
808 
809  Expect(Token::DEBUGGER, CHECK_OK);
810  ExpectSemicolon(ok);
811  return Statement::Default();
812 }

References CHECK_OK, v8::internal::PreParserStatement::Default(), v8::internal::ParserBase< PreParserTraits >::Expect(), and v8::internal::ParserBase< PreParserTraits >::ExpectSemicolon().

Referenced by ParseStatement().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ParseDoWhileStatement()

PreParser::Statement v8::internal::PreParser::ParseDoWhileStatement ( bool ok)
private

Definition at line 653 of file preparser.cc.

653  {
654  // DoStatement ::
655  // 'do' Statement 'while' '(' Expression ')' ';'
656 
657  Expect(Token::DO, CHECK_OK);
659  Expect(Token::WHILE, CHECK_OK);
660  Expect(Token::LPAREN, CHECK_OK);
661  ParseExpression(true, CHECK_OK);
662  Expect(Token::RPAREN, ok);
663  if (peek() == Token::SEMICOLON) Consume(Token::SEMICOLON);
664  return Statement::Default();
665 }
ExpressionT ParseExpression(bool accept_IN, bool *ok)
Definition: preparser.h:1870

References CHECK_OK, v8::internal::ParserBase< PreParserTraits >::Consume(), v8::internal::PreParserStatement::Default(), v8::internal::ParserBase< PreParserTraits >::Expect(), v8::internal::ParserBase< PreParserTraits >::ParseExpression(), and ParseStatement().

Referenced by ParseStatement().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ParseEagerFunctionBody()

PreParserStatementList v8::internal::PreParser::ParseEagerFunctionBody ( PreParserIdentifier  function_name,
int  pos,
Variable fvar,
Token::Value  fvar_init_op,
bool  is_generator,
bool ok 
)
inlineprivate

Definition at line 1532 of file preparser.h.

1534  {
1535  ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
1536 
1537  ParseSourceElements(Token::RBRACE, ok);
1538  if (!*ok) return PreParserStatementList();
1539 
1540  Expect(Token::RBRACE, ok);
1541  return PreParserStatementList();
1542 }
SourceElements ParseSourceElements(int end_token, bool *ok)
Definition: preparser.cc:203

References v8::internal::ParserBase< PreParserTraits >::Expect(), v8::internal::ParserBase< PreParserTraits >::PARSE_EAGERLY, and ParseSourceElements().

Referenced by v8::internal::PreParserTraits::ParseEagerFunctionBody().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ParseExpressionOrLabelledStatement()

PreParser::Statement v8::internal::PreParser::ParseExpressionOrLabelledStatement ( bool ok)
private

Definition at line 493 of file preparser.cc.

493  {
494  // ExpressionStatement | LabelledStatement ::
495  // Expression ';'
496  // Identifier ':' Statement
497 
498  bool starts_with_identifier = peek_any_identifier();
499  Expression expr = ParseExpression(true, CHECK_OK);
500  // Even if the expression starts with an identifier, it is not necessarily an
501  // identifier. For example, "foo + bar" starts with an identifier but is not
502  // an identifier.
503  if (starts_with_identifier && expr.IsIdentifier() && peek() == Token::COLON) {
504  // Expression is a single identifier, and not, e.g., a parenthesized
505  // identifier.
506  DCHECK(!expr.AsIdentifier().IsFutureReserved());
507  DCHECK(strict_mode() == SLOPPY ||
508  (!expr.AsIdentifier().IsFutureStrictReserved() &&
509  !expr.AsIdentifier().IsYield()));
510  Consume(Token::COLON);
511  return ParseStatement(ok);
512  // Preparsing is disabled for extensions (because the extension details
513  // aren't passed to lazily compiled functions), so we don't
514  // accept "native function" in the preparser.
515  }
516  // Parsed expression statement.
518  return Statement::ExpressionStatement(expr);
519 }
static PreParserStatement ExpressionStatement(PreParserExpression expression)
Definition: preparser.h:891
PreParserExpression Expression
Definition: preparser.h:1412
#define DCHECK(condition)
Definition: logging.h:205

References v8::internal::PreParserExpression::AsIdentifier(), CHECK_OK, v8::internal::ParserBase< PreParserTraits >::Consume(), DCHECK, v8::internal::ParserBase< PreParserTraits >::ExpectSemicolon(), v8::internal::PreParserStatement::ExpressionStatement(), v8::internal::PreParserIdentifier::IsFutureReserved(), v8::internal::PreParserIdentifier::IsFutureStrictReserved(), v8::internal::PreParserExpression::IsIdentifier(), v8::internal::PreParserIdentifier::IsYield(), v8::internal::ParserBase< PreParserTraits >::ParseExpression(), ParseStatement(), v8::internal::ParserBase< PreParserTraits >::peek_any_identifier(), v8::internal::SLOPPY, and v8::internal::ParserBase< PreParserTraits >::strict_mode().

Referenced by ParseStatement().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ParseForStatement()

PreParser::Statement v8::internal::PreParser::ParseForStatement ( bool ok)
private

Definition at line 690 of file preparser.cc.

690  {
691  // ForStatement ::
692  // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement
693 
694  Expect(Token::FOR, CHECK_OK);
695  Expect(Token::LPAREN, CHECK_OK);
696  if (peek() != Token::SEMICOLON) {
697  if (peek() == Token::VAR || peek() == Token::CONST ||
698  (peek() == Token::LET && strict_mode() == STRICT)) {
699  bool is_let = peek() == Token::LET;
700  int decl_count;
703  kForStatement, &decl_props, &decl_count, CHECK_OK);
704  bool has_initializers = decl_props == kHasInitializers;
705  bool accept_IN = decl_count == 1 && !(is_let && has_initializers);
706  bool accept_OF = !has_initializers;
707  if (accept_IN && CheckInOrOf(accept_OF)) {
708  ParseExpression(true, CHECK_OK);
709  Expect(Token::RPAREN, CHECK_OK);
710 
712  return Statement::Default();
713  }
714  } else {
715  Expression lhs = ParseExpression(false, CHECK_OK);
716  if (CheckInOrOf(lhs.IsIdentifier())) {
717  ParseExpression(true, CHECK_OK);
718  Expect(Token::RPAREN, CHECK_OK);
719 
721  return Statement::Default();
722  }
723  }
724  }
725 
726  // Parsed initializer at this point.
727  Expect(Token::SEMICOLON, CHECK_OK);
728 
729  if (peek() != Token::SEMICOLON) {
730  ParseExpression(true, CHECK_OK);
731  }
732  Expect(Token::SEMICOLON, CHECK_OK);
733 
734  if (peek() != Token::RPAREN) {
735  ParseExpression(true, CHECK_OK);
736  }
737  Expect(Token::RPAREN, CHECK_OK);
738 
739  ParseStatement(ok);
740  return Statement::Default();
741 }
bool CheckInOrOf(bool accept_OF)
Definition: preparser.cc:681
Statement ParseVariableDeclarations(VariableDeclarationContext var_context, VariableDeclarationProperties *decl_props, int *num_decl, bool *ok)
Definition: preparser.cc:411

References CHECK_OK, CheckInOrOf(), v8::internal::CONST, v8::internal::PreParserStatement::Default(), v8::internal::ParserBase< PreParserTraits >::Expect(), v8::internal::PreParserExpression::IsIdentifier(), kForStatement, kHasInitializers, kHasNoInitializers, v8::internal::LET, v8::internal::ParserBase< PreParserTraits >::ParseExpression(), ParseStatement(), ParseVariableDeclarations(), v8::internal::STRICT, v8::internal::ParserBase< PreParserTraits >::strict_mode(), and v8::internal::VAR.

Referenced by ParseStatement().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ParseFunctionDeclaration()

PreParser::Statement v8::internal::PreParser::ParseFunctionDeclaration ( bool ok)
private

Definition at line 338 of file preparser.cc.

338  {
339  // FunctionDeclaration ::
340  // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}'
341  // GeneratorDeclaration ::
342  // 'function' '*' Identifier '(' FormalParameterListopt ')'
343  // '{' FunctionBody '}'
344  Expect(Token::FUNCTION, CHECK_OK);
345  int pos = position();
346  bool is_generator = Check(Token::MUL);
347  bool is_strict_reserved = false;
349  &is_strict_reserved, CHECK_OK);
350  ParseFunctionLiteral(name, scanner()->location(), is_strict_reserved,
353  pos, FunctionLiteral::DECLARATION,
354  FunctionLiteral::NORMAL_ARITY, CHECK_OK);
356 }
static PreParserStatement FunctionDeclaration()
Definition: preparser.h:884
Expression ParseFunctionLiteral(Identifier name, Scanner::Location function_name_location, bool name_is_strict_reserved, FunctionKind kind, int function_token_pos, FunctionLiteral::FunctionType function_type, FunctionLiteral::ArityRestriction arity_restriction, bool *ok)
Definition: preparser.cc:823
@ kNormalFunction
Definition: globals.h:776
@ kGeneratorFunction
Definition: globals.h:778

References v8::internal::ParserBase< PreParserTraits >::Check(), CHECK_OK, v8::internal::ParserBase< PreParserTraits >::Expect(), v8::internal::PreParserStatement::FunctionDeclaration(), v8::internal::ParserBase< PreParserTraits >::is_generator(), v8::internal::kGeneratorFunction, v8::internal::kNormalFunction, v8::internal::MUL, name, ParseFunctionLiteral(), v8::internal::ParserBase< PreParserTraits >::ParseIdentifierOrStrictReservedWord(), v8::internal::ParserBase< PreParserTraits >::position(), and v8::internal::ParserBase< PreParserTraits >::scanner().

Referenced by ParseSourceElement(), and ParseStatement().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ParseFunctionLiteral()

PreParser::Expression v8::internal::PreParser::ParseFunctionLiteral ( Identifier  name,
Scanner::Location  function_name_location,
bool  name_is_strict_reserved,
FunctionKind  kind,
int  function_token_pos,
FunctionLiteral::FunctionType  function_type,
FunctionLiteral::ArityRestriction  arity_restriction,
bool ok 
)
private

Definition at line 823 of file preparser.cc.

827  {
828  // Function ::
829  // '(' FormalParameterList? ')' '{' FunctionBody '}'
830 
831  // Parse function body.
832  ScopeType outer_scope_type = scope_->type();
833  PreParserScope function_scope(scope_, FUNCTION_SCOPE);
834  FunctionState function_state(&function_state_, &scope_, &function_scope, NULL,
835  this->ast_value_factory());
836  function_state.set_is_generator(IsGeneratorFunction(kind));
837  // FormalParameterList ::
838  // '(' (Identifier)*[','] ')'
839  Expect(Token::LPAREN, CHECK_OK);
840  int start_position = position();
841  DuplicateFinder duplicate_finder(scanner()->unicode_cache());
842  // We don't yet know if the function will be strict, so we cannot yet produce
843  // errors for parameter names or duplicates. However, we remember the
844  // locations of these errors if they occur and produce the errors later.
845  Scanner::Location eval_args_error_loc = Scanner::Location::invalid();
846  Scanner::Location dupe_error_loc = Scanner::Location::invalid();
847  Scanner::Location reserved_error_loc = Scanner::Location::invalid();
848 
849  bool done = arity_restriction == FunctionLiteral::GETTER_ARITY ||
850  (peek() == Token::RPAREN &&
851  arity_restriction != FunctionLiteral::SETTER_ARITY);
852  while (!done) {
853  bool is_strict_reserved = false;
854  Identifier param_name =
855  ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK);
856  if (!eval_args_error_loc.IsValid() && param_name.IsEvalOrArguments()) {
857  eval_args_error_loc = scanner()->location();
858  }
859  if (!reserved_error_loc.IsValid() && is_strict_reserved) {
860  reserved_error_loc = scanner()->location();
861  }
862 
863  int prev_value = scanner()->FindSymbol(&duplicate_finder, 1);
864 
865  if (!dupe_error_loc.IsValid() && prev_value != 0) {
866  dupe_error_loc = scanner()->location();
867  }
868 
869  if (arity_restriction == FunctionLiteral::SETTER_ARITY) break;
870  done = (peek() == Token::RPAREN);
871  if (!done) Expect(Token::COMMA, CHECK_OK);
872  }
873  Expect(Token::RPAREN, CHECK_OK);
874 
875  // See Parser::ParseFunctionLiteral for more information about lazy parsing
876  // and lazy compilation.
877  bool is_lazily_parsed = (outer_scope_type == GLOBAL_SCOPE && allow_lazy() &&
879  parenthesized_function_ = false;
880 
881  Expect(Token::LBRACE, CHECK_OK);
882  if (is_lazily_parsed) {
884  } else {
885  ParseSourceElements(Token::RBRACE, ok);
886  }
887  Expect(Token::RBRACE, CHECK_OK);
888 
889  // Validate strict mode. We can do this only after parsing the function,
890  // since the function can declare itself strict.
891  // Concise methods use StrictFormalParameters.
892  if (strict_mode() == STRICT || IsConciseMethod(kind)) {
893  if (function_name.IsEvalOrArguments()) {
894  ReportMessageAt(function_name_location, "strict_eval_arguments");
895  *ok = false;
896  return Expression::Default();
897  }
898  if (name_is_strict_reserved) {
899  ReportMessageAt(function_name_location, "unexpected_strict_reserved");
900  *ok = false;
901  return Expression::Default();
902  }
903  if (eval_args_error_loc.IsValid()) {
904  ReportMessageAt(eval_args_error_loc, "strict_eval_arguments");
905  *ok = false;
906  return Expression::Default();
907  }
908  if (dupe_error_loc.IsValid()) {
909  ReportMessageAt(dupe_error_loc, "strict_param_dupe");
910  *ok = false;
911  return Expression::Default();
912  }
913  if (reserved_error_loc.IsValid()) {
914  ReportMessageAt(reserved_error_loc, "unexpected_strict_reserved");
915  *ok = false;
916  return Expression::Default();
917  }
918 
919  int end_position = scanner()->location().end_pos;
920  CheckOctalLiteral(start_position, end_position, CHECK_OK);
921  }
922 
923  return Expression::Default();
924 }
void ReportMessageAt(Scanner::Location location, const char *message, bool is_reference_error=false)
Definition: preparser.h:450
void CheckOctalLiteral(int beg_pos, int end_pos, bool *ok)
Definition: preparser.h:381
static PreParserExpression Default()
Definition: preparser.h:678
static AstValueFactory * ast_value_factory()
Definition: preparser.h:1380
void ParseLazyFunctionLiteralBody(bool *ok)
Definition: preparser.cc:927
int FindSymbol(DuplicateFinder *finder, int value)
Definition: scanner.cc:1225
Location location() const
Definition: scanner.h:356
#define COMMA
bool IsGeneratorFunction(FunctionKind kind)
Definition: globals.h:799
bool IsConciseMethod(FunctionKind kind)
Definition: globals.h:805
@ FUNCTION_SCOPE
Definition: globals.h:647
@ GLOBAL_SCOPE
Definition: globals.h:649
static Location invalid()
Definition: scanner.h:337

References v8::internal::ParserBase< PreParserTraits >::allow_lazy(), v8::internal::PreParserTraits::ast_value_factory(), CHECK_OK, v8::internal::ParserBase< PreParserTraits >::CheckOctalLiteral(), COMMA, v8::internal::PreParserExpression::Default(), v8::internal::Scanner::Location::end_pos, v8::internal::ParserBase< PreParserTraits >::Expect(), v8::internal::Scanner::FindSymbol(), v8::internal::FUNCTION_SCOPE, v8::internal::ParserBase< PreParserTraits >::function_state_, v8::internal::GLOBAL_SCOPE, v8::internal::Scanner::Location::invalid(), v8::internal::IsConciseMethod(), v8::internal::PreParserIdentifier::IsEvalOrArguments(), v8::internal::IsGeneratorFunction(), v8::internal::Scanner::Location::IsValid(), v8::internal::Scanner::location(), NULL, v8::internal::ParserBase< PreParserTraits >::parenthesized_function_, v8::internal::ParserBase< PreParserTraits >::ParseIdentifierOrStrictReservedWord(), ParseLazyFunctionLiteralBody(), ParseSourceElements(), v8::internal::ParserBase< PreParserTraits >::position(), v8::internal::ParserBase< PreParserTraits >::ReportMessageAt(), v8::internal::ParserBase< PreParserTraits >::scanner(), v8::internal::ParserBase< PreParserTraits >::scope_, v8::internal::STRICT, and v8::internal::ParserBase< PreParserTraits >::strict_mode().

Referenced by ParseFunctionDeclaration(), and v8::internal::PreParserTraits::ParseFunctionLiteral().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ParseIfStatement()

PreParser::Statement v8::internal::PreParser::ParseIfStatement ( bool ok)
private

Definition at line 522 of file preparser.cc.

522  {
523  // IfStatement ::
524  // 'if' '(' Expression ')' Statement ('else' Statement)?
525 
526  Expect(Token::IF, CHECK_OK);
527  Expect(Token::LPAREN, CHECK_OK);
528  ParseExpression(true, CHECK_OK);
529  Expect(Token::RPAREN, CHECK_OK);
531  if (peek() == Token::ELSE) {
532  Next();
534  }
535  return Statement::Default();
536 }

References CHECK_OK, v8::internal::PreParserStatement::Default(), v8::internal::ParserBase< PreParserTraits >::Expect(), v8::internal::ParserBase< PreParserTraits >::ParseExpression(), and ParseStatement().

Referenced by ParseStatement().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ParseLazyFunctionLiteralBody()

void v8::internal::PreParser::ParseLazyFunctionLiteralBody ( bool ok)
private

Definition at line 927 of file preparser.cc.

927  {
928  int body_start = position();
929  ParseSourceElements(Token::RBRACE, ok);
930  if (!*ok) return;
931 
932  // Position right after terminal '}'.
933  DCHECK_EQ(Token::RBRACE, scanner()->peek());
934  int body_end = scanner()->peek_location().end_pos;
935  log_->LogFunction(body_start, body_end,
936  function_state_->materialized_literal_count(),
937  function_state_->expected_property_count(),
938  strict_mode());
939 }
virtual void LogFunction(int start, int end, int literals, int properties, StrictMode strict_mode)=0
Location peek_location() const
Definition: scanner.h:363
#define DCHECK_EQ(v1, v2)
Definition: logging.h:206

References DCHECK_EQ, v8::internal::Scanner::Location::end_pos, v8::internal::ParserBase< PreParserTraits >::function_state_, v8::internal::ParserBase< PreParserTraits >::log_, v8::internal::ParserRecorder::LogFunction(), ParseSourceElements(), v8::internal::Scanner::peek_location(), v8::internal::ParserBase< PreParserTraits >::position(), v8::internal::ParserBase< PreParserTraits >::scanner(), and v8::internal::ParserBase< PreParserTraits >::strict_mode().

Referenced by ParseFunctionLiteral(), and PreParseLazyFunction().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ParseObjectLiteral()

Expression v8::internal::PreParser::ParseObjectLiteral ( bool ok)
private

◆ ParseReturnStatement()

PreParser::Statement v8::internal::PreParser::ParseReturnStatement ( bool ok)
private

Definition at line 575 of file preparser.cc.

575  {
576  // ReturnStatement ::
577  // 'return' [no line terminator] Expression? ';'
578 
579  // Consume the return token. It is necessary to do before
580  // reporting any errors on it, because of the way errors are
581  // reported (underlining).
582  Expect(Token::RETURN, CHECK_OK);
583 
584  // An ECMAScript program is considered syntactically incorrect if it
585  // contains a return statement that is not within the body of a
586  // function. See ECMA-262, section 12.9, page 67.
587  // This is not handled during preparsing.
588 
589  Token::Value tok = peek();
590  if (!scanner()->HasAnyLineTerminatorBeforeNext() &&
591  tok != Token::SEMICOLON &&
592  tok != Token::RBRACE &&
593  tok != Token::EOS) {
594  ParseExpression(true, CHECK_OK);
595  }
597  return Statement::Default();
598 }

References CHECK_OK, v8::internal::PreParserStatement::Default(), v8::internal::ParserBase< PreParserTraits >::Expect(), v8::internal::ParserBase< PreParserTraits >::ExpectSemicolon(), v8::internal::ParserBase< PreParserTraits >::ParseExpression(), and v8::internal::ParserBase< PreParserTraits >::scanner().

Referenced by ParseStatement().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ParseSourceElement()

PreParser::Statement v8::internal::PreParser::ParseSourceElement ( bool ok)
private

Definition at line 172 of file preparser.cc.

172  {
173  // (Ecma 262 5th Edition, clause 14):
174  // SourceElement:
175  // Statement
176  // FunctionDeclaration
177  //
178  // In harmony mode we allow additionally the following productions
179  // SourceElement:
180  // LetDeclaration
181  // ConstDeclaration
182  // GeneratorDeclaration
183 
184  switch (peek()) {
185  case Token::FUNCTION:
186  return ParseFunctionDeclaration(ok);
187  case Token::CLASS:
188  return ParseClassDeclaration(ok);
189  case Token::CONST:
191  case Token::LET:
193  if (strict_mode() == STRICT) {
195  }
196  // Fall through.
197  default:
198  return ParseStatement(ok);
199  }
200 }
Statement ParseVariableStatement(VariableDeclarationContext var_context, bool *ok)
Definition: preparser.cc:391
Statement ParseFunctionDeclaration(bool *ok)
Definition: preparser.cc:338
Statement ParseClassDeclaration(bool *ok)
Definition: preparser.cc:359

References v8::internal::ParserBase< PreParserTraits >::allow_harmony_scoping(), v8::internal::CONST, DCHECK, kSourceElement, v8::internal::LET, ParseClassDeclaration(), ParseFunctionDeclaration(), ParseStatement(), ParseVariableStatement(), v8::internal::STRICT, and v8::internal::ParserBase< PreParserTraits >::strict_mode().

Referenced by ParseBlock(), and ParseSourceElements().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ParseSourceElements()

PreParser::SourceElements v8::internal::PreParser::ParseSourceElements ( int  end_token,
bool ok 
)
private

Definition at line 203 of file preparser.cc.

204  {
205  // SourceElements ::
206  // (Statement)* <end_token>
207 
208  bool directive_prologue = true;
209  while (peek() != end_token) {
210  if (directive_prologue && peek() != Token::STRING) {
211  directive_prologue = false;
212  }
214  if (directive_prologue) {
215  if (statement.IsUseStrictLiteral()) {
216  scope_->SetStrictMode(STRICT);
217  } else if (!statement.IsStringLiteral()) {
218  directive_prologue = false;
219  }
220  }
221  }
222  return kUnknownSourceElements;
223 }
PreParserStatement Statement
Definition: preparser.h:1413
@ STRING

References CHECK_OK, v8::internal::PreParserStatement::IsStringLiteral(), v8::internal::PreParserStatement::IsUseStrictLiteral(), kUnknownSourceElements, ParseSourceElement(), v8::internal::ParserBase< PreParserTraits >::scope_, v8::internal::STRICT, and STRING.

Referenced by ParseEagerFunctionBody(), ParseFunctionLiteral(), ParseLazyFunctionLiteralBody(), and PreParseProgram().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ParseStatement()

PreParser::Statement v8::internal::PreParser::ParseStatement ( bool ok)
private

Definition at line 234 of file preparser.cc.

234  {
235  // Statement ::
236  // Block
237  // VariableStatement
238  // EmptyStatement
239  // ExpressionStatement
240  // IfStatement
241  // IterationStatement
242  // ContinueStatement
243  // BreakStatement
244  // ReturnStatement
245  // WithStatement
246  // LabelledStatement
247  // SwitchStatement
248  // ThrowStatement
249  // TryStatement
250  // DebuggerStatement
251 
252  // Note: Since labels can only be used by 'break' and 'continue'
253  // statements, which themselves are only valid within blocks,
254  // iterations or 'switch' statements (i.e., BreakableStatements),
255  // labels can be simply ignored in all other cases; except for
256  // trivial labeled break statements 'label: break label' which is
257  // parsed into an empty statement.
258 
259  // Keep the source position of the statement
260  switch (peek()) {
261  case Token::LBRACE:
262  return ParseBlock(ok);
263 
264  case Token::SEMICOLON:
265  Next();
266  return Statement::Default();
267 
268  case Token::IF:
269  return ParseIfStatement(ok);
270 
271  case Token::DO:
272  return ParseDoWhileStatement(ok);
273 
274  case Token::WHILE:
275  return ParseWhileStatement(ok);
276 
277  case Token::FOR:
278  return ParseForStatement(ok);
279 
280  case Token::CONTINUE:
281  return ParseContinueStatement(ok);
282 
283  case Token::BREAK:
284  return ParseBreakStatement(ok);
285 
286  case Token::RETURN:
287  return ParseReturnStatement(ok);
288 
289  case Token::WITH:
290  return ParseWithStatement(ok);
291 
292  case Token::SWITCH:
293  return ParseSwitchStatement(ok);
294 
295  case Token::THROW:
296  return ParseThrowStatement(ok);
297 
298  case Token::TRY:
299  return ParseTryStatement(ok);
300 
301  case Token::FUNCTION: {
302  Scanner::Location start_location = scanner()->peek_location();
304  Scanner::Location end_location = scanner()->location();
305  if (strict_mode() == STRICT) {
306  PreParserTraits::ReportMessageAt(start_location.beg_pos,
307  end_location.end_pos,
308  "strict_function");
309  *ok = false;
310  return Statement::Default();
311  } else {
312  return statement;
313  }
314  }
315 
316  case Token::CLASS:
318 
319  case Token::DEBUGGER:
320  return ParseDebuggerStatement(ok);
321 
322  case Token::VAR:
323  case Token::CONST:
325 
326  case Token::LET:
328  if (strict_mode() == STRICT) {
330  }
331  // Fall through.
332  default:
334  }
335 }
void ReportMessageAt(Scanner::Location location, const char *message, const char *arg=NULL, bool is_reference_error=false)
Definition: preparser.cc:42
Statement ParseReturnStatement(bool *ok)
Definition: preparser.cc:575
Statement ParseTryStatement(bool *ok)
Definition: preparser.cc:760
Statement ParseContinueStatement(bool *ok)
Definition: preparser.cc:539
Statement ParseWithStatement(bool *ok)
Definition: preparser.cc:601
Statement ParseWhileStatement(bool *ok)
Definition: preparser.cc:668
Statement ParseSwitchStatement(bool *ok)
Definition: preparser.cc:621
Statement ParseForStatement(bool *ok)
Definition: preparser.cc:690
Statement ParseExpressionOrLabelledStatement(bool *ok)
Definition: preparser.cc:493
Statement ParseDoWhileStatement(bool *ok)
Definition: preparser.cc:653
Statement ParseThrowStatement(bool *ok)
Definition: preparser.cc:744
Statement ParseBlock(bool *ok)
Definition: preparser.cc:371
Statement ParseDebuggerStatement(bool *ok)
Definition: preparser.cc:802
Statement ParseIfStatement(bool *ok)
Definition: preparser.cc:522
Statement ParseBreakStatement(bool *ok)
Definition: preparser.cc:557

References v8::internal::ParserBase< PreParserTraits >::allow_harmony_scoping(), v8::internal::Scanner::Location::beg_pos, v8::internal::BREAK, CHECK_OK, v8::internal::CONST, DCHECK, v8::internal::PreParserStatement::Default(), v8::internal::Scanner::Location::end_pos, kStatement, v8::internal::LET, v8::internal::Scanner::location(), ParseBlock(), ParseBreakStatement(), ParseClassDeclaration(), ParseContinueStatement(), ParseDebuggerStatement(), ParseDoWhileStatement(), ParseExpressionOrLabelledStatement(), ParseForStatement(), ParseFunctionDeclaration(), ParseIfStatement(), ParseReturnStatement(), ParseSwitchStatement(), ParseThrowStatement(), ParseTryStatement(), ParseVariableStatement(), ParseWhileStatement(), ParseWithStatement(), v8::internal::Scanner::peek_location(), v8::internal::PreParserTraits::ReportMessageAt(), v8::internal::ParserBase< PreParserTraits >::scanner(), v8::internal::STRICT, v8::internal::ParserBase< PreParserTraits >::strict_mode(), and v8::internal::VAR.

Referenced by ParseBlock(), ParseDoWhileStatement(), ParseExpressionOrLabelledStatement(), ParseForStatement(), ParseIfStatement(), ParseSourceElement(), ParseSwitchStatement(), ParseWhileStatement(), and ParseWithStatement().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ParseSwitchStatement()

PreParser::Statement v8::internal::PreParser::ParseSwitchStatement ( bool ok)
private

Definition at line 621 of file preparser.cc.

621  {
622  // SwitchStatement ::
623  // 'switch' '(' Expression ')' '{' CaseClause* '}'
624 
625  Expect(Token::SWITCH, CHECK_OK);
626  Expect(Token::LPAREN, CHECK_OK);
627  ParseExpression(true, CHECK_OK);
628  Expect(Token::RPAREN, CHECK_OK);
629 
630  Expect(Token::LBRACE, CHECK_OK);
631  Token::Value token = peek();
632  while (token != Token::RBRACE) {
633  if (token == Token::CASE) {
635  ParseExpression(true, CHECK_OK);
636  } else {
638  }
639  Expect(Token::COLON, CHECK_OK);
640  token = peek();
641  while (token != Token::CASE &&
642  token != Token::DEFAULT &&
643  token != Token::RBRACE) {
645  token = peek();
646  }
647  }
648  Expect(Token::RBRACE, ok);
649  return Statement::Default();
650 }
#define CASE(Name)

References CASE, CHECK_OK, v8::internal::DEFAULT, v8::internal::PreParserStatement::Default(), v8::internal::ParserBase< PreParserTraits >::Expect(), v8::internal::ParserBase< PreParserTraits >::ParseExpression(), and ParseStatement().

Referenced by ParseStatement().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ParseThrowStatement()

PreParser::Statement v8::internal::PreParser::ParseThrowStatement ( bool ok)
private

Definition at line 744 of file preparser.cc.

744  {
745  // ThrowStatement ::
746  // 'throw' [no line terminator] Expression ';'
747 
748  Expect(Token::THROW, CHECK_OK);
749  if (scanner()->HasAnyLineTerminatorBeforeNext()) {
750  ReportMessageAt(scanner()->location(), "newline_after_throw");
751  *ok = false;
752  return Statement::Default();
753  }
754  ParseExpression(true, CHECK_OK);
755  ExpectSemicolon(ok);
756  return Statement::Default();
757 }

References CHECK_OK, v8::internal::PreParserStatement::Default(), v8::internal::ParserBase< PreParserTraits >::Expect(), v8::internal::ParserBase< PreParserTraits >::ExpectSemicolon(), v8::internal::ParserBase< PreParserTraits >::ParseExpression(), v8::internal::ParserBase< PreParserTraits >::ReportMessageAt(), and v8::internal::ParserBase< PreParserTraits >::scanner().

Referenced by ParseStatement().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ParseTryStatement()

PreParser::Statement v8::internal::PreParser::ParseTryStatement ( bool ok)
private

Definition at line 760 of file preparser.cc.

760  {
761  // TryStatement ::
762  // 'try' Block Catch
763  // 'try' Block Finally
764  // 'try' Block Catch Finally
765  //
766  // Catch ::
767  // 'catch' '(' Identifier ')' Block
768  //
769  // Finally ::
770  // 'finally' Block
771 
772  Expect(Token::TRY, CHECK_OK);
773 
775 
776  Token::Value tok = peek();
777  if (tok != Token::CATCH && tok != Token::FINALLY) {
778  ReportMessageAt(scanner()->location(), "no_catch_or_finally");
779  *ok = false;
780  return Statement::Default();
781  }
782  if (tok == Token::CATCH) {
783  Consume(Token::CATCH);
784  Expect(Token::LPAREN, CHECK_OK);
786  Expect(Token::RPAREN, CHECK_OK);
787  {
788  PreParserScope with_scope(scope_, WITH_SCOPE);
789  BlockState block_state(&scope_, &with_scope);
791  }
792  tok = peek();
793  }
794  if (tok == Token::FINALLY) {
795  Consume(Token::FINALLY);
797  }
798  return Statement::Default();
799 }

References CHECK_OK, v8::internal::ParserBase< PreParserTraits >::Consume(), v8::internal::PreParserStatement::Default(), v8::internal::ParserBase< PreParserTraits >::Expect(), v8::internal::ParserBase< PreParserTraits >::kDontAllowEvalOrArguments, ParseBlock(), v8::internal::ParserBase< PreParserTraits >::ParseIdentifier(), v8::internal::ParserBase< PreParserTraits >::ReportMessageAt(), v8::internal::ParserBase< PreParserTraits >::scanner(), v8::internal::ParserBase< PreParserTraits >::scope_, and v8::internal::WITH_SCOPE.

Referenced by ParseStatement().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ParseV8Intrinsic()

PreParser::Expression v8::internal::PreParser::ParseV8Intrinsic ( bool ok)
private

Definition at line 942 of file preparser.cc.

942  {
943  // CallRuntime ::
944  // '%' Identifier Arguments
945  Expect(Token::MOD, CHECK_OK);
946  if (!allow_natives_syntax()) {
947  *ok = false;
948  return Expression::Default();
949  }
950  // Allow "eval" or "arguments" for backward compatibility.
952  ParseArguments(ok);
953 
954  return Expression::Default();
955 }
Traits::Type::ExpressionList ParseArguments(bool *ok)
Definition: preparser.h:2106

References v8::internal::ParserBase< PreParserTraits >::allow_natives_syntax(), CHECK_OK, v8::internal::PreParserExpression::Default(), v8::internal::ParserBase< PreParserTraits >::Expect(), v8::internal::ParserBase< PreParserTraits >::kAllowEvalOrArguments, v8::internal::ParserBase< PreParserTraits >::ParseArguments(), and v8::internal::ParserBase< PreParserTraits >::ParseIdentifier().

Referenced by v8::internal::PreParserTraits::ParseV8Intrinsic().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ParseVariableDeclarations()

PreParser::Statement v8::internal::PreParser::ParseVariableDeclarations ( VariableDeclarationContext  var_context,
VariableDeclarationProperties decl_props,
int num_decl,
bool ok 
)
private

Definition at line 411 of file preparser.cc.

415  {
416  // VariableDeclarations ::
417  // ('var' | 'const') (Identifier ('=' AssignmentExpression)?)+[',']
418  //
419  // The ES6 Draft Rev3 specifies the following grammar for const declarations
420  //
421  // ConstDeclaration ::
422  // const ConstBinding (',' ConstBinding)* ';'
423  // ConstBinding ::
424  // Identifier '=' AssignmentExpression
425  //
426  // TODO(ES6):
427  // ConstBinding ::
428  // BindingPattern '=' AssignmentExpression
429  bool require_initializer = false;
430  if (peek() == Token::VAR) {
432  } else if (peek() == Token::CONST) {
433  // TODO(ES6): The ES6 Draft Rev4 section 12.2.2 reads:
434  //
435  // ConstDeclaration : const ConstBinding (',' ConstBinding)* ';'
436  //
437  // * It is a Syntax Error if the code that matches this production is not
438  // contained in extended code.
439  //
440  // However disallowing const in sloppy mode will break compatibility with
441  // existing pages. Therefore we keep allowing const with the old
442  // non-harmony semantics in sloppy mode.
444  if (strict_mode() == STRICT) {
445  if (allow_harmony_scoping()) {
446  if (var_context != kSourceElement && var_context != kForStatement) {
447  ReportMessageAt(scanner()->peek_location(), "unprotected_const");
448  *ok = false;
449  return Statement::Default();
450  }
451  require_initializer = true;
452  } else {
453  Scanner::Location location = scanner()->peek_location();
454  ReportMessageAt(location, "strict_const");
455  *ok = false;
456  return Statement::Default();
457  }
458  }
459  } else if (peek() == Token::LET && strict_mode() == STRICT) {
461  if (var_context != kSourceElement && var_context != kForStatement) {
462  ReportMessageAt(scanner()->peek_location(), "unprotected_let");
463  *ok = false;
464  return Statement::Default();
465  }
466  } else {
467  *ok = false;
468  return Statement::Default();
469  }
470 
471  // The scope of a var/const declared variable anywhere inside a function
472  // is the entire function (ECMA-262, 3rd, 10.1.3, and 12.2). The scope
473  // of a let declared variable is the scope of the immediately enclosing
474  // block.
475  int nvars = 0; // the number of variables declared
476  do {
477  // Parse variable name.
478  if (nvars > 0) Consume(Token::COMMA);
480  nvars++;
481  if (peek() == Token::ASSIGN || require_initializer) {
482  Expect(Token::ASSIGN, CHECK_OK);
484  if (decl_props != NULL) *decl_props = kHasInitializers;
485  }
486  } while (peek() == Token::COMMA);
487 
488  if (num_decl != NULL) *num_decl = nvars;
489  return Statement::Default();
490 }
ExpressionT ParseAssignmentExpression(bool accept_IN, bool *ok)
Definition: preparser.h:2137

References v8::internal::ParserBase< PreParserTraits >::allow_harmony_scoping(), CHECK_OK, COMMA, v8::internal::CONST, v8::internal::ParserBase< PreParserTraits >::Consume(), v8::internal::PreParserStatement::Default(), v8::internal::ParserBase< PreParserTraits >::Expect(), v8::internal::ParserBase< PreParserTraits >::kDontAllowEvalOrArguments, kForStatement, kHasInitializers, kSourceElement, v8::internal::LET, NULL, v8::internal::ParserBase< PreParserTraits >::ParseAssignmentExpression(), v8::internal::ParserBase< PreParserTraits >::ParseIdentifier(), v8::internal::Scanner::peek_location(), v8::internal::ParserBase< PreParserTraits >::ReportMessageAt(), v8::internal::ParserBase< PreParserTraits >::scanner(), v8::internal::STRICT, v8::internal::ParserBase< PreParserTraits >::strict_mode(), and v8::internal::VAR.

Referenced by ParseForStatement(), and ParseVariableStatement().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ParseVariableStatement()

PreParser::Statement v8::internal::PreParser::ParseVariableStatement ( VariableDeclarationContext  var_context,
bool ok 
)
private

Definition at line 391 of file preparser.cc.

393  {
394  // VariableStatement ::
395  // VariableDeclarations ';'
396 
397  Statement result = ParseVariableDeclarations(var_context,
398  NULL,
399  NULL,
400  CHECK_OK);
402  return result;
403 }

References CHECK_OK, v8::internal::ParserBase< PreParserTraits >::ExpectSemicolon(), NULL, and ParseVariableDeclarations().

Referenced by ParseSourceElement(), and ParseStatement().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ParseWhileStatement()

PreParser::Statement v8::internal::PreParser::ParseWhileStatement ( bool ok)
private

Definition at line 668 of file preparser.cc.

668  {
669  // WhileStatement ::
670  // 'while' '(' Expression ')' Statement
671 
672  Expect(Token::WHILE, CHECK_OK);
673  Expect(Token::LPAREN, CHECK_OK);
674  ParseExpression(true, CHECK_OK);
675  Expect(Token::RPAREN, CHECK_OK);
676  ParseStatement(ok);
677  return Statement::Default();
678 }

References CHECK_OK, v8::internal::PreParserStatement::Default(), v8::internal::ParserBase< PreParserTraits >::Expect(), v8::internal::ParserBase< PreParserTraits >::ParseExpression(), and ParseStatement().

Referenced by ParseStatement().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ParseWithStatement()

PreParser::Statement v8::internal::PreParser::ParseWithStatement ( bool ok)
private

Definition at line 601 of file preparser.cc.

601  {
602  // WithStatement ::
603  // 'with' '(' Expression ')' Statement
604  Expect(Token::WITH, CHECK_OK);
605  if (strict_mode() == STRICT) {
606  ReportMessageAt(scanner()->location(), "strict_mode_with");
607  *ok = false;
608  return Statement::Default();
609  }
610  Expect(Token::LPAREN, CHECK_OK);
611  ParseExpression(true, CHECK_OK);
612  Expect(Token::RPAREN, CHECK_OK);
613 
614  PreParserScope with_scope(scope_, WITH_SCOPE);
615  BlockState block_state(&scope_, &with_scope);
617  return Statement::Default();
618 }

References CHECK_OK, v8::internal::PreParserStatement::Default(), v8::internal::ParserBase< PreParserTraits >::Expect(), v8::internal::ParserBase< PreParserTraits >::ParseExpression(), ParseStatement(), v8::internal::ParserBase< PreParserTraits >::ReportMessageAt(), v8::internal::ParserBase< PreParserTraits >::scanner(), v8::internal::ParserBase< PreParserTraits >::scope_, v8::internal::STRICT, v8::internal::ParserBase< PreParserTraits >::strict_mode(), and v8::internal::WITH_SCOPE.

Referenced by ParseStatement().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PreParseLazyFunction()

PreParser::PreParseResult v8::internal::PreParser::PreParseLazyFunction ( StrictMode  strict_mode,
bool  is_generator,
ParserRecorder log 
)

Definition at line 121 of file preparser.cc.

122  {
123  log_ = log;
124  // Lazy functions always have trivial outer scopes (no with/catch scopes).
125  PreParserScope top_scope(scope_, GLOBAL_SCOPE);
126  FunctionState top_state(&function_state_, &scope_, &top_scope, NULL,
127  this->ast_value_factory());
128  scope_->SetStrictMode(strict_mode);
129  PreParserScope function_scope(scope_, FUNCTION_SCOPE);
130  FunctionState function_state(&function_state_, &scope_, &function_scope, NULL,
131  this->ast_value_factory());
132  function_state.set_is_generator(is_generator);
133  DCHECK_EQ(Token::LBRACE, scanner()->current_token());
134  bool ok = true;
135  int start_position = peek_position();
138  if (!ok) {
139  ReportUnexpectedToken(scanner()->current_token());
140  } else {
141  DCHECK_EQ(Token::RBRACE, scanner()->peek());
142  if (scope_->strict_mode() == STRICT) {
143  int end_pos = scanner()->location().end_pos;
144  CheckOctalLiteral(start_position, end_pos, &ok);
145  }
146  }
147  return kPreParseSuccess;
148 }
void ReportUnexpectedToken(Token::Value token)
Definition: preparser.h:1608

References v8::internal::PreParserTraits::ast_value_factory(), v8::internal::ParserBase< PreParserTraits >::CheckOctalLiteral(), DCHECK_EQ, v8::internal::Scanner::Location::end_pos, v8::internal::FUNCTION_SCOPE, v8::internal::ParserBase< PreParserTraits >::function_state_, v8::internal::GLOBAL_SCOPE, v8::internal::ParserBase< PreParserTraits >::is_generator(), kPreParseStackOverflow, kPreParseSuccess, v8::internal::Scanner::location(), v8::internal::ParserBase< PreParserTraits >::log_, NULL, ParseLazyFunctionLiteralBody(), v8::internal::ParserBase< PreParserTraits >::peek_position(), v8::internal::ParserBase< PreParserTraits >::ReportUnexpectedToken(), v8::internal::ParserBase< PreParserTraits >::scanner(), v8::internal::ParserBase< PreParserTraits >::scope_, v8::internal::ParserBase< PreParserTraits >::stack_overflow(), and v8::internal::STRICT.

Referenced by v8::internal::Parser::ParseLazyFunctionBodyWithPreParser().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PreParseProgram()

PreParseResult v8::internal::PreParser::PreParseProgram ( )
inline

Definition at line 1428 of file preparser.h.

1428  {
1429  PreParserScope scope(scope_, GLOBAL_SCOPE);
1430  FunctionState top_scope(&function_state_, &scope_, &scope);
1431  bool ok = true;
1432  int start_position = scanner()->peek_location().beg_pos;
1433  ParseSourceElements(Token::EOS, &ok);
1434  if (stack_overflow()) return kPreParseStackOverflow;
1435  if (!ok) {
1436  ReportUnexpectedToken(scanner()->current_token());
1437  } else if (scope_->strict_mode() == STRICT) {
1438  CheckOctalLiteral(start_position, scanner()->location().end_pos, &ok);
1439  }
1440  return kPreParseSuccess;
1441  }

References v8::internal::Scanner::Location::beg_pos, v8::internal::ParserBase< PreParserTraits >::CheckOctalLiteral(), v8::internal::ParserBase< PreParserTraits >::function_state_, v8::internal::GLOBAL_SCOPE, kPreParseStackOverflow, kPreParseSuccess, ParseSourceElements(), v8::internal::Scanner::peek_location(), v8::internal::ParserBase< PreParserTraits >::ReportUnexpectedToken(), v8::internal::ParserBase< PreParserTraits >::scanner(), v8::internal::ParserBase< PreParserTraits >::scope_, v8::internal::ParserBase< PreParserTraits >::stack_overflow(), and v8::internal::STRICT.

+ Here is the call graph for this function:

◆ SkipLazyFunctionBody()

void v8::internal::PreParser::SkipLazyFunctionBody ( PreParserIdentifier  function_name,
int materialized_literal_count,
int expected_property_count,
bool ok 
)
inlineprivate

Friends And Related Function Documentation

◆ PreParserTraits

friend class PreParserTraits
friend

Definition at line 1456 of file preparser.h.


The documentation for this class was generated from the following files: