diff options
Diffstat (limited to 'deps/v8/src/parsing/parser-base.h')
-rw-r--r-- | deps/v8/src/parsing/parser-base.h | 259 |
1 files changed, 144 insertions, 115 deletions
diff --git a/deps/v8/src/parsing/parser-base.h b/deps/v8/src/parsing/parser-base.h index 6f6cff8e20e..9d13724f060 100644 --- a/deps/v8/src/parsing/parser-base.h +++ b/deps/v8/src/parsing/parser-base.h @@ -21,6 +21,7 @@ #include "src/parsing/func-name-inferrer.h" #include "src/parsing/scanner.h" #include "src/parsing/token.h" +#include "src/zone/zone-chunk-list.h" namespace v8 { namespace internal { @@ -416,21 +417,23 @@ class ParserBase { void AdoptDestructuringAssignmentsFromParentState(int pos) { const auto& outer_assignments = outer_function_state_->destructuring_assignments_to_rewrite_; - DCHECK_GE(outer_assignments.length(), pos); - for (int i = pos; i < outer_assignments.length(); ++i) { - auto expr = outer_assignments[i]; + DCHECK_GE(outer_assignments.size(), pos); + auto it = outer_assignments.begin(); + it.Advance(pos); + for (; it != outer_assignments.end(); ++it) { + auto expr = *it; expr->set_scope(scope_); - destructuring_assignments_to_rewrite_.Add(expr, scope_->zone()); + destructuring_assignments_to_rewrite_.push_back(expr); } outer_function_state_->RewindDestructuringAssignments(pos); } - const ZoneList<RewritableExpressionT>& + const ZoneChunkList<RewritableExpressionT>& destructuring_assignments_to_rewrite() const { return destructuring_assignments_to_rewrite_; } - ZoneList<typename ExpressionClassifier::Error>* GetReportedErrorList() { + ZoneVector<typename ExpressionClassifier::Error>* GetReportedErrorList() { return &reported_errors_; } @@ -472,26 +475,27 @@ class ParserBase { private: void AddDestructuringAssignment(RewritableExpressionT expr) { - destructuring_assignments_to_rewrite_.Add(expr, scope_->zone()); + destructuring_assignments_to_rewrite_.push_back(expr); } // Properties count estimation. int expected_property_count_; + // How many suspends are needed for this function. + int suspend_count_; + FunctionState** function_state_stack_; FunctionState* outer_function_state_; DeclarationScope* scope_; - ZoneList<RewritableExpressionT> destructuring_assignments_to_rewrite_; + ZoneChunkList<RewritableExpressionT> destructuring_assignments_to_rewrite_; - ZoneList<typename ExpressionClassifier::Error> reported_errors_; + // We use a ZoneVector here because we need to do a lot of random access. + ZoneVector<typename ExpressionClassifier::Error> reported_errors_; // A reason, if any, why this function should not be optimized. BailoutReason dont_optimize_reason_; - // How many suspends are needed for this function. - int suspend_count_; - // Record whether the next (=== immediately following) function literal is // preceded by a parenthesis / exclamation mark. Also record the previous // state. @@ -594,7 +598,6 @@ class ParserBase { typename Types::ClassPropertyList instance_fields; FunctionLiteralT constructor; - // TODO(gsathya): Use a bitfield store all the booleans. bool has_seen_constructor; bool has_name_static_property; bool has_static_computed_names; @@ -745,8 +748,7 @@ class ParserBase { Next(); return; } - if (scanner()->HasAnyLineTerminatorBeforeNext() || - tok == Token::RBRACE || + if (scanner()->HasLineTerminatorBeforeNext() || tok == Token::RBRACE || tok == Token::EOS) { return; } @@ -959,8 +961,7 @@ class ParserBase { void ReportClassifierError( const typename ExpressionClassifier::Error& error) { - impl()->ReportMessageAt(error.location, error.message, error.arg, - error.type); + impl()->ReportMessageAt(error.location, error.message, error.arg); } void ValidateExpression(bool* ok) { @@ -1089,7 +1090,7 @@ class ParserBase { function_state_->kind(), is_strict_reserved, is_await, ok); } - IdentifierT ParseIdentifierName(bool* ok); + V8_INLINE IdentifierT ParseIdentifierName(bool* ok); ExpressionT ParseIdentifierNameOrPrivateName(bool* ok); @@ -1135,8 +1136,7 @@ class ParserBase { ClassLiteralPropertyT ParseClassPropertyDefinition( ClassLiteralChecker* checker, ClassInfo* class_info, IdentifierT* property_name, bool has_extends, bool* is_computed_name, - bool* has_seen_constructor, ClassLiteralProperty::Kind* property_kind, - bool* is_static, bool* has_name_static_property, bool* ok); + ClassLiteralProperty::Kind* property_kind, bool* is_static, bool* ok); ExpressionT ParseClassFieldInitializer(ClassInfo* class_info, bool is_static, bool* ok); ObjectLiteralPropertyT ParseObjectPropertyDefinition( @@ -1152,15 +1152,15 @@ class ParserBase { ExpressionT ParseAssignmentExpression(bool accept_IN, bool* ok); ExpressionT ParseYieldExpression(bool accept_IN, bool* ok); - ExpressionT ParseConditionalExpression(bool accept_IN, bool* ok); + V8_INLINE 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); + V8_INLINE ExpressionT ParsePostfixExpression(bool* ok); + V8_INLINE ExpressionT ParseLeftHandSideExpression(bool* ok); ExpressionT ParseMemberWithNewPrefixesExpression(bool* is_async, bool* ok); - ExpressionT ParseMemberExpression(bool* is_async, bool* ok); - ExpressionT ParseMemberExpressionContinuation(ExpressionT expression, - bool* is_async, bool* ok); + V8_INLINE ExpressionT ParseMemberExpression(bool* is_async, bool* ok); + V8_INLINE ExpressionT ParseMemberExpressionContinuation( + ExpressionT expression, bool* is_async, bool* ok); // `rewritable_length`: length of the destructuring_assignments_to_rewrite() // queue in the parent function state, prior to parsing of formal parameters. @@ -1183,7 +1183,7 @@ class ParserBase { ExpressionT ParseImportExpressions(bool* ok); ExpressionT ParseNewTargetExpression(bool* ok); - void ParseFormalParameter(FormalParametersT* parameters, bool* ok); + V8_INLINE void ParseFormalParameter(FormalParametersT* parameters, bool* ok); void ParseFormalParameterList(FormalParametersT* parameters, bool* ok); void CheckArityRestrictions(int param_count, FunctionKind function_type, bool has_rest, int formals_start_pos, @@ -1228,14 +1228,19 @@ class ParserBase { USE(result); DCHECK_EQ(result, kLazyParsingComplete); } - LazyParsingResult ParseStatementList(StatementListT body, - Token::Value end_token, bool may_abort, - bool* ok); + V8_INLINE LazyParsingResult ParseStatementList(StatementListT body, + Token::Value end_token, + bool may_abort, bool* ok); StatementT ParseStatementListItem(bool* ok); - StatementT ParseStatement(ZonePtrList<const AstRawString>* labels, bool* ok) { - return ParseStatement(labels, kDisallowLabelledFunctionStatement, ok); + + StatementT ParseStatement(ZonePtrList<const AstRawString>* labels, + ZonePtrList<const AstRawString>* own_labels, + bool* ok) { + return ParseStatement(labels, own_labels, + kDisallowLabelledFunctionStatement, ok); } StatementT ParseStatement(ZonePtrList<const AstRawString>* labels, + ZonePtrList<const AstRawString>* own_labels, AllowLabelledFunctionStatement allow_function, bool* ok); BlockT ParseBlock(ZonePtrList<const AstRawString>* labels, bool* ok); @@ -1259,6 +1264,7 @@ class ParserBase { StatementT ParseExpressionOrLabelledStatement( ZonePtrList<const AstRawString>* labels, + ZonePtrList<const AstRawString>* own_labels, AllowLabelledFunctionStatement allow_function, bool* ok); StatementT ParseIfStatement(ZonePtrList<const AstRawString>* labels, bool* ok); @@ -1269,34 +1275,41 @@ class ParserBase { StatementT ParseWithStatement(ZonePtrList<const AstRawString>* labels, bool* ok); StatementT ParseDoWhileStatement(ZonePtrList<const AstRawString>* labels, + ZonePtrList<const AstRawString>* own_labels, bool* ok); StatementT ParseWhileStatement(ZonePtrList<const AstRawString>* labels, + ZonePtrList<const AstRawString>* own_labels, bool* ok); StatementT ParseThrowStatement(bool* ok); StatementT ParseSwitchStatement(ZonePtrList<const AstRawString>* labels, bool* ok); - StatementT ParseTryStatement(bool* ok); + V8_INLINE StatementT ParseTryStatement(bool* ok); StatementT ParseForStatement(ZonePtrList<const AstRawString>* labels, + ZonePtrList<const AstRawString>* own_labels, bool* ok); StatementT ParseForEachStatementWithDeclarations( int stmt_pos, ForInfo* for_info, ZonePtrList<const AstRawString>* labels, - Scope* inner_block_scope, bool* ok); + ZonePtrList<const AstRawString>* own_labels, Scope* inner_block_scope, + bool* ok); StatementT ParseForEachStatementWithoutDeclarations( int stmt_pos, ExpressionT expression, int lhs_beg_pos, int lhs_end_pos, - ForInfo* for_info, ZonePtrList<const AstRawString>* labels, bool* ok); + ForInfo* for_info, ZonePtrList<const AstRawString>* labels, + ZonePtrList<const AstRawString>* own_labels, bool* ok); // Parse a C-style for loop: 'for (<init>; <cond>; <next>) { ... }' // "for (<init>;" is assumed to have been parser already. - ForStatementT ParseStandardForLoop(int stmt_pos, - ZonePtrList<const AstRawString>* labels, - ExpressionT* cond, StatementT* next, - StatementT* body, bool* ok); + ForStatementT ParseStandardForLoop( + int stmt_pos, ZonePtrList<const AstRawString>* labels, + ZonePtrList<const AstRawString>* own_labels, ExpressionT* cond, + StatementT* next, StatementT* body, bool* ok); // Same as the above, but handles those cases where <init> is a // lexical variable declaration. StatementT ParseStandardForLoopWithLexicalDeclarations( int stmt_pos, StatementT init, ForInfo* for_info, - ZonePtrList<const AstRawString>* labels, bool* ok); + ZonePtrList<const AstRawString>* labels, + ZonePtrList<const AstRawString>* own_labels, bool* ok); StatementT ParseForAwaitStatement(ZonePtrList<const AstRawString>* labels, + ZonePtrList<const AstRawString>* own_labels, bool* ok); bool IsNextLetKeyword(); @@ -1574,17 +1587,18 @@ ParserBase<Impl>::FunctionState::FunctionState( DeclarationScope* scope) : BlockState(scope_stack, scope), expected_property_count_(0), + suspend_count_(0), function_state_stack_(function_state_stack), outer_function_state_(*function_state_stack), scope_(scope), - destructuring_assignments_to_rewrite_(16, scope->zone()), - reported_errors_(16, scope->zone()), + destructuring_assignments_to_rewrite_(scope->zone()), + reported_errors_(scope_->zone()), dont_optimize_reason_(BailoutReason::kNoReason), - suspend_count_(0), next_function_is_likely_called_(false), previous_function_was_likely_called_(false), contains_function_or_eval_(false) { *function_state_stack = this; + reported_errors_.reserve(16); if (outer_function_state_) { outer_function_state_->previous_function_was_likely_called_ = outer_function_state_->next_function_is_likely_called_; @@ -1875,7 +1889,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePrimaryExpression( return impl()->ExpressionFromLiteral(Next(), beg_pos); case Token::ASYNC: - if (!scanner()->HasAnyLineTerminatorAfterNext() && + if (!scanner()->HasLineTerminatorAfterNext() && PeekAhead() == Token::FUNCTION) { BindingPatternUnexpectedToken(); Consume(Token::ASYNC); @@ -2179,10 +2193,10 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePropertyName( int pos = peek_position(); if (!*is_generator && token == Token::ASYNC && - !scanner()->HasAnyLineTerminatorAfterNext()) { + !scanner()->HasLineTerminatorAfterNext()) { Consume(Token::ASYNC); token = peek(); - if (token == Token::MUL && !scanner()->HasAnyLineTerminatorBeforeNext()) { + if (token == Token::MUL && !scanner()->HasLineTerminatorBeforeNext()) { Consume(Token::MUL); token = peek(); *is_generator = true; @@ -2300,11 +2314,9 @@ template <typename Impl> typename ParserBase<Impl>::ClassLiteralPropertyT ParserBase<Impl>::ParseClassPropertyDefinition( ClassLiteralChecker* checker, ClassInfo* class_info, IdentifierT* name, - bool has_extends, bool* is_computed_name, bool* has_seen_constructor, - ClassLiteralProperty::Kind* property_kind, bool* is_static, - bool* has_name_static_property, bool* ok) { - DCHECK_NOT_NULL(has_seen_constructor); - DCHECK_NOT_NULL(has_name_static_property); + bool has_extends, bool* is_computed_name, + ClassLiteralProperty::Kind* property_kind, bool* is_static, bool* ok) { + DCHECK_NOT_NULL(class_info); bool is_get = false; bool is_set = false; bool is_generator = false; @@ -2353,8 +2365,9 @@ ParserBase<Impl>::ParseClassPropertyDefinition( CHECK_OK_CUSTOM(NullLiteralProperty)); } - if (!*has_name_static_property && *is_static && impl()->IsName(*name)) { - *has_name_static_property = true; + if (!class_info->has_name_static_property && *is_static && + impl()->IsName(*name)) { + class_info->has_name_static_property = true; } switch (kind) { @@ -2416,7 +2429,7 @@ ParserBase<Impl>::ParseClassPropertyDefinition( FunctionKind kind = MethodKindFor(is_generator, is_async); if (!*is_static && impl()->IsConstructor(*name)) { - *has_seen_constructor = true; + class_info->has_seen_constructor = true; kind = has_extends ? FunctionKind::kDerivedConstructor : FunctionKind::kBaseConstructor; } @@ -2875,11 +2888,11 @@ ParserBase<Impl>::ParseAssignmentExpression(bool accept_IN, bool* ok) { this, classifier()->duplicate_finder()); Scope::Snapshot scope_snapshot(scope()); - int rewritable_length = - function_state_->destructuring_assignments_to_rewrite().length(); + int rewritable_length = static_cast<int>( + function_state_->destructuring_assignments_to_rewrite().size()); bool is_async = peek() == Token::ASYNC && - !scanner()->HasAnyLineTerminatorAfterNext() && + !scanner()->HasLineTerminatorAfterNext() && IsValidArrowFormalParametersStart(PeekAhead()); bool parenthesized_formals = peek() == Token::LPAREN; @@ -3056,7 +3069,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseYieldExpression( // The following initialization is necessary. ExpressionT expression = impl()->NullExpression(); bool delegating = false; // yield* - if (!scanner()->HasAnyLineTerminatorBeforeNext()) { + if (!scanner()->HasLineTerminatorBeforeNext()) { if (Check(Token::MUL)) delegating = true; switch (peek()) { case Token::EOS: @@ -3307,8 +3320,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePostfixExpression( int lhs_beg_pos = peek_position(); ExpressionT expression = ParseLeftHandSideExpression(CHECK_OK); - if (!scanner()->HasAnyLineTerminatorBeforeNext() && - Token::IsCountOp(peek())) { + if (!scanner()->HasLineTerminatorBeforeNext() && Token::IsCountOp(peek())) { BindingPatternUnexpectedToken(); ArrowFormalParametersUnexpectedToken(); @@ -3375,6 +3387,7 @@ ParserBase<Impl>::ParseLeftHandSideExpression(bool* ok) { // function literal eagerly, we can also compile it eagerly. if (result->IsFunctionLiteral()) { result->AsFunctionLiteral()->SetShouldEagerCompile(); + result->AsFunctionLiteral()->mark_as_iife(); } } Scanner::Location spread_pos; @@ -4168,7 +4181,7 @@ ParserBase<Impl>::ParseAsyncFunctionDeclaration( // ( FormalParameters[Await] ) { AsyncFunctionBody } DCHECK_EQ(scanner()->current_token(), Token::ASYNC); int pos = position(); - if (scanner()->HasAnyLineTerminatorBeforeNext()) { + if (scanner()->HasLineTerminatorBeforeNext()) { *ok = false; impl()->ReportUnexpectedToken(scanner()->current_token()); return impl()->NullStatement(); @@ -4360,7 +4373,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral( base::ElapsedTimer timer; if (V8_UNLIKELY(FLAG_log_function_events)) timer.Start(); - if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) { + if (peek() == Token::ARROW && scanner_->HasLineTerminatorBeforeNext()) { // ASI inserts `;` after arrow parameters if a line terminator is found. // `=> ...` is never a valid expression, so report as syntax error. // If next token is not `=>`, it's a syntax error anyways. @@ -4547,8 +4560,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseClassLiteral( bool is_constructor = !class_info.has_seen_constructor; ClassLiteralPropertyT property = ParseClassPropertyDefinition( &checker, &class_info, &property_name, has_extends, &is_computed_name, - &class_info.has_seen_constructor, &property_kind, &is_static, - &class_info.has_name_static_property, CHECK_OK); + &property_kind, &is_static, CHECK_OK); if (!class_info.has_static_computed_names && is_static && is_computed_name) { class_info.has_static_computed_names = true; @@ -4971,7 +4983,7 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseStatementListItem( break; case Token::ASYNC: if (PeekAhead() == Token::FUNCTION && - !scanner()->HasAnyLineTerminatorAfterNext()) { + !scanner()->HasLineTerminatorAfterNext()) { Consume(Token::ASYNC); return ParseAsyncFunctionDeclaration(nullptr, false, ok); } @@ -4979,12 +4991,13 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseStatementListItem( default: break; } - return ParseStatement(nullptr, kAllowLabelledFunctionStatement, ok); + return ParseStatement(nullptr, nullptr, kAllowLabelledFunctionStatement, ok); } template <typename Impl> typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseStatement( ZonePtrList<const AstRawString>* labels, + ZonePtrList<const AstRawString>* own_labels, AllowLabelledFunctionStatement allow_function, bool* ok) { // Statement :: // Block @@ -5003,6 +5016,9 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseStatement( // TryStatement // DebuggerStatement + // {own_labels} is always a subset of {labels}. + DCHECK_IMPLIES(labels == nullptr, own_labels == nullptr); + // Note: Since labels can only be used by 'break' and 'continue' // statements, which themselves are only valid within blocks, // iterations or 'switch' statements (i.e., BreakableStatements), @@ -5018,14 +5034,14 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseStatement( case Token::IF: return ParseIfStatement(labels, ok); case Token::DO: - return ParseDoWhileStatement(labels, ok); + return ParseDoWhileStatement(labels, own_labels, ok); case Token::WHILE: - return ParseWhileStatement(labels, ok); + return ParseWhileStatement(labels, own_labels, ok); case Token::FOR: if (V8_UNLIKELY(is_async_function() && PeekAhead() == Token::AWAIT)) { - return ParseForAwaitStatement(labels, ok); + return ParseForAwaitStatement(labels, own_labels, ok); } - return ParseForStatement(labels, ok); + return ParseForStatement(labels, own_labels, ok); case Token::CONTINUE: return ParseContinueStatement(ok); case Token::BREAK: @@ -5068,7 +5084,7 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseStatement( case Token::VAR: return ParseVariableStatement(kStatement, nullptr, ok); case Token::ASYNC: - if (!scanner()->HasAnyLineTerminatorAfterNext() && + if (!scanner()->HasLineTerminatorAfterNext() && PeekAhead() == Token::FUNCTION) { impl()->ReportMessageAt( scanner()->peek_location(), @@ -5078,7 +5094,8 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseStatement( } V8_FALLTHROUGH; default: - return ParseExpressionOrLabelledStatement(labels, allow_function, ok); + return ParseExpressionOrLabelledStatement(labels, own_labels, + allow_function, ok); } } @@ -5118,7 +5135,7 @@ template <typename Impl> typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseScopedStatement( ZonePtrList<const AstRawString>* labels, bool* ok) { if (is_strict(language_mode()) || peek() != Token::FUNCTION) { - return ParseStatement(labels, ok); + return ParseStatement(labels, nullptr, ok); } else { // Make a block around the statement for a lexical binding // is introduced by a FunctionDeclaration. @@ -5178,6 +5195,7 @@ template <typename Impl> typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseExpressionOrLabelledStatement( ZonePtrList<const AstRawString>* labels, + ZonePtrList<const AstRawString>* own_labels, AllowLabelledFunctionStatement allow_function, bool* ok) { // ExpressionStatement | LabelledStatement :: // Expression ';' @@ -5203,7 +5221,7 @@ ParserBase<Impl>::ParseExpressionOrLabelledStatement( // However, ASI may insert a line break before an identifier or a brace. if (next_next != Token::LBRACK && ((next_next != Token::LBRACE && next_next != Token::IDENTIFIER) || - scanner_->HasAnyLineTerminatorAfterNext())) { + scanner_->HasLineTerminatorAfterNext())) { break; } impl()->ReportMessageAt(scanner()->peek_location(), @@ -5221,22 +5239,22 @@ ParserBase<Impl>::ParseExpressionOrLabelledStatement( impl()->IsIdentifier(expr)) { // The whole expression was a single identifier, and not, e.g., // something starting with an identifier or a parenthesized identifier. - labels = impl()->DeclareLabel(labels, impl()->AsIdentifierExpression(expr), - CHECK_OK); + impl()->DeclareLabel(&labels, &own_labels, + impl()->AsIdentifierExpression(expr), CHECK_OK); Consume(Token::COLON); // ES#sec-labelled-function-declarations Labelled Function Declarations if (peek() == Token::FUNCTION && is_sloppy(language_mode()) && allow_function == kAllowLabelledFunctionStatement) { return ParseFunctionDeclaration(ok); } - return ParseStatement(labels, allow_function, ok); + return ParseStatement(labels, own_labels, allow_function, ok); } // If we have an extension, we allow a native function declaration. // A native function declaration starts with "native function" with // no line-terminator between the two words. if (extension_ != nullptr && peek() == Token::FUNCTION && - !scanner()->HasAnyLineTerminatorBeforeNext() && impl()->IsNative(expr) && + !scanner()->HasLineTerminatorBeforeNext() && impl()->IsNative(expr) && !scanner()->literal_contains_escapes()) { return ParseNativeDeclaration(ok); } @@ -5289,7 +5307,7 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseContinueStatement( Expect(Token::CONTINUE, CHECK_OK); IdentifierT label = impl()->NullIdentifier(); Token::Value tok = peek(); - if (!scanner()->HasAnyLineTerminatorBeforeNext() && tok != Token::SEMICOLON && + if (!scanner()->HasLineTerminatorBeforeNext() && tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { // ECMA allows "eval" or "arguments" as labels even in strict mode. label = ParseIdentifier(kAllowRestrictedIdentifiers, CHECK_OK); @@ -5326,7 +5344,7 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseBreakStatement( Expect(Token::BREAK, CHECK_OK); IdentifierT label = impl()->NullIdentifier(); Token::Value tok = peek(); - if (!scanner()->HasAnyLineTerminatorBeforeNext() && tok != Token::SEMICOLON && + if (!scanner()->HasLineTerminatorBeforeNext() && tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { // ECMA allows "eval" or "arguments" as labels even in strict mode. label = ParseIdentifier(kAllowRestrictedIdentifiers, CHECK_OK); @@ -5380,7 +5398,7 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseReturnStatement( Token::Value tok = peek(); ExpressionT return_value = impl()->NullExpression(); - if (scanner()->HasAnyLineTerminatorBeforeNext() || tok == Token::SEMICOLON || + if (scanner()->HasLineTerminatorBeforeNext() || tok == Token::SEMICOLON || tok == Token::RBRACE || tok == Token::EOS) { if (IsDerivedConstructor(function_state_->kind())) { return_value = impl()->ThisExpression(loc.beg_pos); @@ -5421,7 +5439,7 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseWithStatement( { BlockState block_state(&scope_, with_scope); with_scope->set_start_position(scanner()->peek_location().beg_pos); - body = ParseStatement(labels, CHECK_OK); + body = ParseStatement(labels, nullptr, CHECK_OK); with_scope->set_end_position(scanner()->location().end_pos); } return factory()->NewWithStatement(with_scope, expr, body, pos); @@ -5429,11 +5447,13 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseWithStatement( template <typename Impl> typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseDoWhileStatement( - ZonePtrList<const AstRawString>* labels, bool* ok) { + ZonePtrList<const AstRawString>* labels, + ZonePtrList<const AstRawString>* own_labels, bool* ok) { // DoStatement :: // 'do' Statement 'while' '(' Expression ')' ';' - auto loop = factory()->NewDoWhileStatement(labels, peek_position()); + auto loop = + factory()->NewDoWhileStatement(labels, own_labels, peek_position()); typename Types::Target target(this, loop); SourceRange body_range; @@ -5442,7 +5462,7 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseDoWhileStatement( Expect(Token::DO, CHECK_OK); { SourceRangeScope range_scope(scanner(), &body_range); - body = ParseStatement(nullptr, CHECK_OK); + body = ParseStatement(nullptr, nullptr, CHECK_OK); } Expect(Token::WHILE, CHECK_OK); Expect(Token::LPAREN, CHECK_OK); @@ -5464,11 +5484,12 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseDoWhileStatement( template <typename Impl> typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseWhileStatement( - ZonePtrList<const AstRawString>* labels, bool* ok) { + ZonePtrList<const AstRawString>* labels, + ZonePtrList<const AstRawString>* own_labels, bool* ok) { // WhileStatement :: // 'while' '(' Expression ')' Statement - auto loop = factory()->NewWhileStatement(labels, peek_position()); + auto loop = factory()->NewWhileStatement(labels, own_labels, peek_position()); typename Types::Target target(this, loop); SourceRange body_range; @@ -5480,7 +5501,7 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseWhileStatement( Expect(Token::RPAREN, CHECK_OK); { SourceRangeScope range_scope(scanner(), &body_range); - body = ParseStatement(nullptr, CHECK_OK); + body = ParseStatement(nullptr, nullptr, CHECK_OK); } loop->Initialize(cond, body); @@ -5497,7 +5518,7 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseThrowStatement( Expect(Token::THROW, CHECK_OK); int pos = position(); - if (scanner()->HasAnyLineTerminatorBeforeNext()) { + if (scanner()->HasLineTerminatorBeforeNext()) { ReportMessage(MessageTemplate::kNewlineAfterThrow); *ok = false; return impl()->NullStatement(); @@ -5679,7 +5700,8 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseTryStatement( template <typename Impl> typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseForStatement( - ZonePtrList<const AstRawString>* labels, bool* ok) { + ZonePtrList<const AstRawString>* labels, + ZonePtrList<const AstRawString>* own_labels, bool* ok) { // Either a standard for loop // for (<init>; <cond>; <next>) { ... } // or a for-each loop @@ -5719,8 +5741,8 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseForStatement( if (CheckInOrOf(&for_info.mode)) { scope()->set_is_hidden(); - return ParseForEachStatementWithDeclarations(stmt_pos, &for_info, labels, - inner_block_scope, ok); + return ParseForEachStatementWithDeclarations( + stmt_pos, &for_info, labels, own_labels, inner_block_scope, ok); } Expect(Token::SEMICOLON, CHECK_OK); @@ -5732,8 +5754,8 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseForStatement( // No variable declarations will have been created in inner_block_scope. DCHECK_NULL(finalized); USE(finalized); - return ParseStandardForLoopWithLexicalDeclarations(stmt_pos, init, - &for_info, labels, ok); + return ParseStandardForLoopWithLexicalDeclarations( + stmt_pos, init, &for_info, labels, own_labels, ok); } StatementT init = impl()->NullStatement(); @@ -5745,7 +5767,7 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseForStatement( if (CheckInOrOf(&for_info.mode)) { return ParseForEachStatementWithDeclarations(stmt_pos, &for_info, labels, - nullptr, ok); + own_labels, nullptr, ok); } init = impl()->BuildInitializationBlock(&for_info.parsing_result, nullptr, @@ -5768,9 +5790,9 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseForStatement( } if (is_for_each) { - return ParseForEachStatementWithoutDeclarations(stmt_pos, expression, - lhs_beg_pos, lhs_end_pos, - &for_info, labels, ok); + return ParseForEachStatementWithoutDeclarations( + stmt_pos, expression, lhs_beg_pos, lhs_end_pos, &for_info, labels, + own_labels, ok); } // Initializer is just an expression. init = factory()->NewExpressionStatement(expression, lhs_beg_pos); @@ -5782,8 +5804,8 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseForStatement( ExpressionT cond = impl()->NullExpression(); StatementT next = impl()->NullStatement(); StatementT body = impl()->NullStatement(); - ForStatementT loop = - ParseStandardForLoop(stmt_pos, labels, &cond, &next, &body, CHECK_OK); + ForStatementT loop = ParseStandardForLoop(stmt_pos, labels, own_labels, &cond, + &next, &body, CHECK_OK); loop->Initialize(init, cond, next, body); return loop; } @@ -5792,7 +5814,8 @@ template <typename Impl> typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseForEachStatementWithDeclarations( int stmt_pos, ForInfo* for_info, ZonePtrList<const AstRawString>* labels, - Scope* inner_block_scope, bool* ok) { + ZonePtrList<const AstRawString>* own_labels, Scope* inner_block_scope, + bool* ok) { // Just one declaration followed by in/of. if (for_info->parsing_result.declarations.size() != 1) { impl()->ReportMessageAt(for_info->parsing_result.bindings_loc, @@ -5820,7 +5843,8 @@ ParserBase<Impl>::ParseForEachStatementWithDeclarations( BlockT init_block = impl()->RewriteForVarInLegacy(*for_info); - auto loop = factory()->NewForEachStatement(for_info->mode, labels, stmt_pos); + auto loop = factory()->NewForEachStatement(for_info->mode, labels, own_labels, + stmt_pos); typename Types::Target target(this, loop); ExpressionT enumerable = impl()->NullExpression(); @@ -5850,7 +5874,7 @@ ParserBase<Impl>::ParseForEachStatementWithDeclarations( SourceRange body_range; SourceRangeScope range_scope(scanner(), &body_range); - StatementT body = ParseStatement(nullptr, CHECK_OK); + StatementT body = ParseStatement(nullptr, nullptr, CHECK_OK); impl()->RecordIterationStatementSourceRange(loop, range_scope.Finalize()); impl()->DesugarBindingInForEachStatement(for_info, &body_block, @@ -5888,7 +5912,8 @@ template <typename Impl> typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseForEachStatementWithoutDeclarations( int stmt_pos, ExpressionT expression, int lhs_beg_pos, int lhs_end_pos, - ForInfo* for_info, ZonePtrList<const AstRawString>* labels, bool* ok) { + ForInfo* for_info, ZonePtrList<const AstRawString>* labels, + ZonePtrList<const AstRawString>* own_labels, bool* ok) { // Initializer is reference followed by in/of. if (!expression->IsArrayLiteral() && !expression->IsObjectLiteral()) { expression = CheckAndRewriteReferenceExpression( @@ -5896,7 +5921,8 @@ ParserBase<Impl>::ParseForEachStatementWithoutDeclarations( kSyntaxError, CHECK_OK); } - auto loop = factory()->NewForEachStatement(for_info->mode, labels, stmt_pos); + auto loop = factory()->NewForEachStatement(for_info->mode, labels, own_labels, + stmt_pos); typename Types::Target target(this, loop); ExpressionT enumerable = impl()->NullExpression(); @@ -5915,7 +5941,7 @@ ParserBase<Impl>::ParseForEachStatementWithoutDeclarations( SourceRange body_range; SourceRangeScope range_scope(scanner(), &body_range); - body = ParseStatement(nullptr, CHECK_OK); + body = ParseStatement(nullptr, nullptr, CHECK_OK); impl()->RecordIterationStatementSourceRange(loop, range_scope.Finalize()); } return impl()->InitializeForEachStatement(loop, expression, enumerable, body); @@ -5925,7 +5951,8 @@ template <typename Impl> typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseStandardForLoopWithLexicalDeclarations( int stmt_pos, StatementT init, ForInfo* for_info, - ZonePtrList<const AstRawString>* labels, bool* ok) { + ZonePtrList<const AstRawString>* labels, + ZonePtrList<const AstRawString>* own_labels, bool* ok) { // The condition and the next statement of the for loop must be parsed // in a new scope. Scope* inner_scope = NewScope(BLOCK_SCOPE); @@ -5936,8 +5963,8 @@ ParserBase<Impl>::ParseStandardForLoopWithLexicalDeclarations( { BlockState block_state(&scope_, inner_scope); scope()->set_start_position(scanner()->location().beg_pos); - loop = - ParseStandardForLoop(stmt_pos, labels, &cond, &next, &body, CHECK_OK); + loop = ParseStandardForLoop(stmt_pos, labels, own_labels, &cond, &next, + &body, CHECK_OK); scope()->set_end_position(scanner()->location().end_pos); } @@ -5980,9 +6007,10 @@ ParserBase<Impl>::ParseStandardForLoopWithLexicalDeclarations( template <typename Impl> typename ParserBase<Impl>::ForStatementT ParserBase<Impl>::ParseStandardForLoop( - int stmt_pos, ZonePtrList<const AstRawString>* labels, ExpressionT* cond, + int stmt_pos, ZonePtrList<const AstRawString>* labels, + ZonePtrList<const AstRawString>* own_labels, ExpressionT* cond, StatementT* next, StatementT* body, bool* ok) { - ForStatementT loop = factory()->NewForStatement(labels, stmt_pos); + ForStatementT loop = factory()->NewForStatement(labels, own_labels, stmt_pos); typename Types::Target target(this, loop); if (peek() != Token::SEMICOLON) { @@ -5999,7 +6027,7 @@ typename ParserBase<Impl>::ForStatementT ParserBase<Impl>::ParseStandardForLoop( SourceRange body_range; { SourceRangeScope range_scope(scanner(), &body_range); - *body = ParseStatement(nullptr, CHECK_OK); + *body = ParseStatement(nullptr, nullptr, CHECK_OK); } impl()->RecordIterationStatementSourceRange(loop, body_range); @@ -6019,7 +6047,8 @@ void ParserBase<Impl>::MarkLoopVariableAsAssigned( template <typename Impl> typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseForAwaitStatement( - ZonePtrList<const AstRawString>* labels, bool* ok) { + ZonePtrList<const AstRawString>* labels, + ZonePtrList<const AstRawString>* own_labels, bool* ok) { // for await '(' ForDeclaration of AssignmentExpression ')' DCHECK(is_async_function()); @@ -6036,7 +6065,7 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseForAwaitStatement( scope()->set_start_position(scanner()->location().beg_pos); scope()->set_is_hidden(); - auto loop = factory()->NewForOfStatement(labels, stmt_pos); + auto loop = factory()->NewForOfStatement(labels, own_labels, stmt_pos); typename Types::Target target(this, loop); ExpressionT each_variable = impl()->NullExpression(); @@ -6119,7 +6148,7 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseForAwaitStatement( SourceRange body_range; SourceRangeScope range_scope(scanner(), &body_range); - body = ParseStatement(nullptr, CHECK_OK); + body = ParseStatement(nullptr, nullptr, CHECK_OK); scope()->set_end_position(scanner()->location().end_pos); impl()->RecordIterationStatementSourceRange(loop, range_scope.Finalize()); |