diff options
Diffstat (limited to 'deps/v8/src/parsing/parser-base.h')
-rw-r--r-- | deps/v8/src/parsing/parser-base.h | 127 |
1 files changed, 48 insertions, 79 deletions
diff --git a/deps/v8/src/parsing/parser-base.h b/deps/v8/src/parsing/parser-base.h index 29e527ce2cc..903ce2bb7f8 100644 --- a/deps/v8/src/parsing/parser-base.h +++ b/deps/v8/src/parsing/parser-base.h @@ -23,6 +23,7 @@ #include "src/objects/function-kind.h" #include "src/parsing/expression-scope.h" #include "src/parsing/func-name-inferrer.h" +#include "src/parsing/parse-info.h" #include "src/parsing/scanner.h" #include "src/parsing/token.h" #include "src/utils/pointer-with-payload.h" @@ -241,7 +242,7 @@ class ParserBase { v8::Extension* extension, AstValueFactory* ast_value_factory, PendingCompilationErrorHandler* pending_error_handler, RuntimeCallStats* runtime_call_stats, Logger* logger, - int script_id, bool parsing_module, bool parsing_on_main_thread) + UnoptimizedCompileFlags flags, bool parsing_on_main_thread) : scope_(nullptr), original_scope_(nullptr), function_state_(nullptr), @@ -252,56 +253,25 @@ class ParserBase { runtime_call_stats_(runtime_call_stats), logger_(logger), parsing_on_main_thread_(parsing_on_main_thread), - parsing_module_(parsing_module), stack_limit_(stack_limit), pending_error_handler_(pending_error_handler), zone_(zone), expression_scope_(nullptr), scanner_(scanner), + flags_(flags), function_literal_id_(0), - script_id_(script_id), - default_eager_compile_hint_(FunctionLiteral::kShouldLazyCompile), - allow_natives_(false), - allow_harmony_dynamic_import_(false), - allow_harmony_import_meta_(false), - allow_harmony_private_methods_(false), - allow_harmony_top_level_await_(false), - allow_eval_cache_(true) { + default_eager_compile_hint_(FunctionLiteral::kShouldLazyCompile) { pointer_buffer_.reserve(32); variable_buffer_.reserve(32); } -#define ALLOW_ACCESSORS(name) \ - bool allow_##name() const { return allow_##name##_; } \ - void set_allow_##name(bool allow) { allow_##name##_ = allow; } + const UnoptimizedCompileFlags& flags() const { return flags_; } - ALLOW_ACCESSORS(natives) - ALLOW_ACCESSORS(harmony_dynamic_import) - ALLOW_ACCESSORS(harmony_import_meta) - ALLOW_ACCESSORS(harmony_private_methods) - ALLOW_ACCESSORS(harmony_top_level_await) - ALLOW_ACCESSORS(eval_cache) - -#undef ALLOW_ACCESSORS + bool allow_eval_cache() const { return allow_eval_cache_; } + void set_allow_eval_cache(bool allow) { allow_eval_cache_ = allow; } V8_INLINE bool has_error() const { return scanner()->has_parser_error(); } - bool allow_harmony_optional_chaining() const { - return scanner()->allow_harmony_optional_chaining(); - } - - void set_allow_harmony_optional_chaining(bool allow) { - scanner()->set_allow_harmony_optional_chaining(allow); - } - - bool allow_harmony_nullish() const { - return scanner()->allow_harmony_nullish(); - } - - void set_allow_harmony_nullish(bool allow) { - scanner()->set_allow_harmony_nullish(allow); - } - uintptr_t stack_limit() const { return stack_limit_; } void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; } @@ -885,8 +855,6 @@ class ParserBase { // Any further calls to Next or peek will return the illegal token. if (GetCurrentStackPosition() < stack_limit_) set_stack_overflow(); } - int script_id() { return script_id_; } - void set_script_id(int id) { script_id_ = id; } V8_INLINE Token::Value peek() { return scanner()->peek(); } @@ -1077,7 +1045,7 @@ class ParserBase { return IsResumableFunction(function_state_->kind()); } bool is_await_allowed() const { - return is_async_function() || (allow_harmony_top_level_await() && + return is_async_function() || (flags().allow_harmony_top_level_await() && IsModule(function_state_->kind())); } const PendingCompilationErrorHandler* pending_error_handler() const { @@ -1279,7 +1247,12 @@ class ParserBase { // hoisted over such a scope. void CheckConflictingVarDeclarations(DeclarationScope* scope) { if (has_error()) return; - Declaration* decl = scope->CheckConflictingVarDeclarations(); + bool allowed_catch_binding_var_redeclaration = false; + Declaration* decl = scope->CheckConflictingVarDeclarations( + &allowed_catch_binding_var_redeclaration); + if (allowed_catch_binding_var_redeclaration) { + impl()->CountUsage(v8::Isolate::kVarRedeclaredCatchBinding); + } if (decl != nullptr) { // In ES6, conflicting variable bindings are early errors. const AstRawString* name = decl->var()->raw_name(); @@ -1501,16 +1474,14 @@ class ParserBase { FormalParametersT* parent_parameters_; }; - class FunctionBodyParsingScope { + class FunctionParsingScope { public: - explicit FunctionBodyParsingScope(Impl* parser) + explicit FunctionParsingScope(Impl* parser) : parser_(parser), expression_scope_(parser_->expression_scope_) { parser_->expression_scope_ = nullptr; } - ~FunctionBodyParsingScope() { - parser_->expression_scope_ = expression_scope_; - } + ~FunctionParsingScope() { parser_->expression_scope_ = expression_scope_; } private: Impl* parser_; @@ -1534,7 +1505,6 @@ class ParserBase { RuntimeCallStats* runtime_call_stats_; internal::Logger* logger_; bool parsing_on_main_thread_; - const bool parsing_module_; uintptr_t stack_limit_; PendingCompilationErrorHandler* pending_error_handler_; @@ -1549,8 +1519,8 @@ class ParserBase { Scanner* scanner_; + const UnoptimizedCompileFlags flags_; int function_literal_id_; - int script_id_; FunctionLiteral::EagerCompileHint default_eager_compile_hint_; @@ -1589,12 +1559,7 @@ class ParserBase { bool accept_IN_ = true; - bool allow_natives_; - bool allow_harmony_dynamic_import_; - bool allow_harmony_import_meta_; - bool allow_harmony_private_methods_; - bool allow_harmony_top_level_await_; - bool allow_eval_cache_; + bool allow_eval_cache_ = true; }; template <typename Impl> @@ -1644,7 +1609,7 @@ ParserBase<Impl>::ParseAndClassifyIdentifier(Token::Value next) { } if (!Token::IsValidIdentifier(next, language_mode(), is_generator(), - parsing_module_ || is_async_function())) { + flags().is_module() || is_async_function())) { ReportUnexpectedToken(next); return impl()->EmptyIdentifierString(); } @@ -1668,7 +1633,7 @@ typename ParserBase<Impl>::IdentifierT ParserBase<Impl>::ParseIdentifier( if (!Token::IsValidIdentifier( next, language_mode(), IsGeneratorFunction(function_kind), - parsing_module_ || IsAsyncFunction(function_kind))) { + flags().is_module() || IsAsyncFunction(function_kind))) { ReportUnexpectedToken(next); return impl()->EmptyIdentifierString(); } @@ -1879,7 +1844,7 @@ ParserBase<Impl>::ParsePrimaryExpression() { return ParseSuperExpression(is_new); } case Token::IMPORT: - if (!allow_harmony_dynamic_import()) break; + if (!flags().allow_harmony_dynamic_import()) break; return ParseImportExpressions(); case Token::LBRACK: @@ -1942,7 +1907,7 @@ ParserBase<Impl>::ParsePrimaryExpression() { return ParseTemplateLiteral(impl()->NullExpression(), beg_pos, false); case Token::MOD: - if (allow_natives() || extension_ != nullptr) { + if (flags().allow_natives_syntax() || extension_ != nullptr) { return ParseV8Intrinsic(); } break; @@ -2188,7 +2153,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseProperty( prop_info->kind = ParsePropertyKind::kNotSet; return impl()->FailureExpression(); } - if (V8_UNLIKELY(!allow_harmony_private_methods() && + if (V8_UNLIKELY(!flags().allow_harmony_private_methods() && (IsAccessor(prop_info->kind) || prop_info->kind == ParsePropertyKind::kMethod))) { ReportUnexpectedToken(Next()); @@ -2437,7 +2402,7 @@ ParserBase<Impl>::ParseClassPropertyDefinition(ClassInfo* class_info, template <typename Impl> typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseMemberInitializer( ClassInfo* class_info, int beg_pos, bool is_static) { - FunctionBodyParsingScope body_parsing_scope(impl()); + FunctionParsingScope body_parsing_scope(impl()); DeclarationScope* initializer_scope = is_static ? class_info->static_fields_scope : class_info->instance_members_scope; @@ -2535,8 +2500,9 @@ ParserBase<Impl>::ParseObjectPropertyDefinition(ParsePropertyInfo* prop_info, // IdentifierReference Initializer? DCHECK_EQ(function_flags, ParseFunctionFlag::kIsNormal); - if (!Token::IsValidIdentifier(name_token, language_mode(), is_generator(), - parsing_module_ || is_async_function())) { + if (!Token::IsValidIdentifier( + name_token, language_mode(), is_generator(), + flags().is_module() || is_async_function())) { ReportUnexpectedToken(Next()); return impl()->NullLiteralProperty(); } @@ -2789,6 +2755,11 @@ ParserBase<Impl>::ParseAssignmentExpressionCoverGrammar() { Token::Value op = peek(); if (!Token::IsArrowOrAssignmentOp(op)) return expression; + if ((op == Token::ASSIGN_NULLISH || op == Token::ASSIGN_OR || + op == Token::ASSIGN_AND) && + !flags().allow_harmony_logical_assignment()) { + return expression; + } // Arrow functions. if (V8_UNLIKELY(op == Token::ARROW)) { @@ -3399,13 +3370,7 @@ ParserBase<Impl>::ParseLeftHandSideContinuation(ExpressionT result) { if (is_optional) { DCHECK_EQ(scanner()->current_token(), Token::QUESTION_PERIOD); int pos = position(); - Token::Value next = Next(); - if (V8_UNLIKELY(!Token::IsPropertyName(next))) { - ReportUnexpectedToken(next); - return impl()->FailureExpression(); - } - IdentifierT name = impl()->GetSymbol(); - ExpressionT key = factory()->NewStringLiteral(name, position()); + ExpressionT key = ParsePropertyOrPrivatePropertyName(); result = factory()->NewProperty(result, key, pos, is_optional); break; } @@ -3456,8 +3421,10 @@ ParserBase<Impl>::ParseMemberWithPresentNewPrefixesExpression() { if (peek() == Token::SUPER) { const bool is_new = true; result = ParseSuperExpression(is_new); - } else if (allow_harmony_dynamic_import() && peek() == Token::IMPORT && - (!allow_harmony_import_meta() || PeekAhead() == Token::LPAREN)) { + } else if (flags().allow_harmony_dynamic_import() && + peek() == Token::IMPORT && + (!flags().allow_harmony_import_meta() || + PeekAhead() == Token::LPAREN)) { impl()->ReportMessageAt(scanner()->peek_location(), MessageTemplate::kImportCallNotNewExpression); return impl()->FailureExpression(); @@ -3555,14 +3522,14 @@ ParserBase<Impl>::ParseMemberExpression() { template <typename Impl> typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseImportExpressions() { - DCHECK(allow_harmony_dynamic_import()); + DCHECK(flags().allow_harmony_dynamic_import()); Consume(Token::IMPORT); int pos = position(); - if (allow_harmony_import_meta() && Check(Token::PERIOD)) { + if (flags().allow_harmony_import_meta() && Check(Token::PERIOD)) { ExpectContextualKeyword(ast_value_factory()->meta_string(), "import.meta", pos); - if (!parsing_module_) { + if (!flags().is_module()) { impl()->ReportMessageAt(scanner()->location(), MessageTemplate::kImportMetaOutsideModule); return impl()->FailureExpression(); @@ -3572,7 +3539,7 @@ ParserBase<Impl>::ParseImportExpressions() { } if (V8_UNLIKELY(peek() != Token::LPAREN)) { - if (!parsing_module_) { + if (!flags().is_module()) { impl()->ReportMessageAt(scanner()->location(), MessageTemplate::kImportOutsideModule); } else { @@ -4157,8 +4124,6 @@ void ParserBase<Impl>::ParseFunctionBody( StatementListT* body, IdentifierT function_name, int pos, const FormalParametersT& parameters, FunctionKind kind, FunctionSyntaxKind function_syntax_kind, FunctionBodyType body_type) { - FunctionBodyParsingScope body_parsing_scope(impl()); - if (IsResumableFunction(kind)) impl()->PrepareGeneratorVariables(); DeclarationScope* function_scope = parameters.scope; @@ -4435,6 +4400,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral( Consume(Token::LBRACE); AcceptINScope scope(this, true); + FunctionParsingScope body_parsing_scope(impl()); ParseFunctionBody(&body, impl()->NullIdentifier(), kNoSourcePosition, parameters, kind, FunctionSyntaxKind::kAnonymousExpression, @@ -4445,6 +4411,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral( } else { Consume(Token::LBRACE); AcceptINScope scope(this, true); + FunctionParsingScope body_parsing_scope(impl()); ParseFunctionBody(&body, impl()->NullIdentifier(), kNoSourcePosition, formal_parameters, kind, FunctionSyntaxKind::kAnonymousExpression, @@ -4454,6 +4421,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral( } else { // Single-expression body has_braces = false; + FunctionParsingScope body_parsing_scope(impl()); ParseFunctionBody(&body, impl()->NullIdentifier(), kNoSourcePosition, formal_parameters, kind, FunctionSyntaxKind::kAnonymousExpression, @@ -4493,8 +4461,9 @@ ParserBase<Impl>::ParseArrowFunctionLiteral( const char* event_name = is_lazy_top_level_function ? "preparse-no-resolution" : "parse"; const char* name = "arrow function"; - logger_->FunctionEvent(event_name, script_id(), ms, scope->start_position(), - scope->end_position(), name, strlen(name)); + logger_->FunctionEvent(event_name, flags().script_id(), ms, + scope->start_position(), scope->end_position(), name, + strlen(name)); } return function_literal; |