diff options
Diffstat (limited to 'deps/v8/src/parsing/parser.h')
-rw-r--r-- | deps/v8/src/parsing/parser.h | 457 |
1 files changed, 204 insertions, 253 deletions
diff --git a/deps/v8/src/parsing/parser.h b/deps/v8/src/parsing/parser.h index 35de0656d3..cc0ceb2607 100644 --- a/deps/v8/src/parsing/parser.h +++ b/deps/v8/src/parsing/parser.h @@ -16,6 +16,7 @@ #include "src/parsing/parser-base.h" #include "src/parsing/parsing.h" #include "src/parsing/preparser.h" +#include "src/pointer-with-payload.h" #include "src/zone/zone-chunk-list.h" namespace v8 { @@ -24,12 +25,12 @@ class ScriptCompiler; namespace internal { -class ConsumedPreParsedScopeData; +class ConsumedPreparseData; class ParseInfo; class ParserTarget; class ParserTargetScope; class PendingCompilationErrorHandler; -class PreParsedScopeData; +class PreparseData; class FunctionEntry { public: @@ -83,33 +84,55 @@ class Parser; struct ParserFormalParameters : FormalParametersBase { struct Parameter : public ZoneObject { - Parameter(const AstRawString* name, Expression* pattern, - Expression* initializer, int position, + Parameter(Expression* pattern, Expression* initializer, int position, int initializer_end_position, bool is_rest) - : name(name), + : initializer_and_is_rest(initializer, is_rest), pattern(pattern), - initializer(initializer), position(position), - initializer_end_position(initializer_end_position), - is_rest(is_rest) {} - const AstRawString* name; + initializer_end_position(initializer_end_position) {} + + PointerWithPayload<Expression, bool, 1> initializer_and_is_rest; + Expression* pattern; - Expression* initializer; + Expression* initializer() const { + return initializer_and_is_rest.GetPointer(); + } int position; int initializer_end_position; - bool is_rest; + inline bool is_rest() const { return initializer_and_is_rest.GetPayload(); } + Parameter* next_parameter = nullptr; bool is_simple() const { - return pattern->IsVariableProxy() && initializer == nullptr && !is_rest; + return pattern->IsVariableProxy() && initializer() == nullptr && + !is_rest(); + } + + const AstRawString* name() const { + DCHECK(is_simple()); + return pattern->AsVariableProxy()->raw_name(); } Parameter** next() { return &next_parameter; } Parameter* const* next() const { return &next_parameter; } }; + void set_strict_parameter_error(const Scanner::Location& loc, + MessageTemplate message) { + strict_error_loc = loc; + strict_error_message = message; + } + + bool has_duplicate() const { return duplicate_loc.IsValid(); } + void ValidateDuplicate(Parser* parser) const; + void ValidateStrictMode(Parser* parser) const; + explicit ParserFormalParameters(DeclarationScope* scope) : FormalParametersBase(scope) {} + base::ThreadedList<Parameter> params; + Scanner::Location duplicate_loc = Scanner::Location::invalid(); + Scanner::Location strict_error_loc = Scanner::Location::invalid(); + MessageTemplate strict_error_message = MessageTemplate::kNone; }; template <> @@ -118,34 +141,32 @@ struct ParserTypes<Parser> { typedef Parser Impl; // Return types for traversing functions. - typedef const AstRawString* Identifier; - typedef v8::internal::Expression* Expression; - typedef v8::internal::FunctionLiteral* FunctionLiteral; - typedef ObjectLiteral::Property* ObjectLiteralProperty; + typedef v8::internal::Block* Block; + typedef v8::internal::BreakableStatement* BreakableStatement; typedef ClassLiteral::Property* ClassLiteralProperty; - typedef v8::internal::Suspend* Suspend; - typedef v8::internal::RewritableExpression* RewritableExpression; - typedef ZonePtrList<v8::internal::Expression>* ExpressionList; - typedef ZonePtrList<ObjectLiteral::Property>* ObjectPropertyList; typedef ZonePtrList<ClassLiteral::Property>* ClassPropertyList; + typedef v8::internal::Expression* Expression; + typedef ScopedPtrList<v8::internal::Expression> ExpressionList; typedef ParserFormalParameters FormalParameters; - typedef v8::internal::Statement* Statement; - typedef ZonePtrList<v8::internal::Statement>* StatementList; - typedef v8::internal::Block* Block; - typedef v8::internal::BreakableStatement* BreakableStatement; typedef v8::internal::ForStatement* ForStatement; + typedef v8::internal::FunctionLiteral* FunctionLiteral; + typedef const AstRawString* Identifier; typedef v8::internal::IterationStatement* IterationStatement; - typedef v8::internal::FuncNameInferrer FuncNameInferrer; - typedef v8::internal::SourceRange SourceRange; - typedef v8::internal::SourceRangeScope SourceRangeScope; + typedef ObjectLiteral::Property* ObjectLiteralProperty; + typedef ScopedPtrList<v8::internal::ObjectLiteralProperty> ObjectPropertyList; + typedef v8::internal::Statement* Statement; + typedef ScopedPtrList<v8::internal::Statement> StatementList; + typedef v8::internal::Suspend* Suspend; // For constructing objects returned by the traversing functions. typedef AstNodeFactory Factory; + // Other implementation-specific functions. + typedef v8::internal::FuncNameInferrer FuncNameInferrer; + typedef v8::internal::SourceRange SourceRange; + typedef v8::internal::SourceRangeScope SourceRangeScope; typedef ParserTarget Target; typedef ParserTargetScope TargetScope; - - static constexpr bool ExpressionClassifierReportErrors = true; }; class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { @@ -173,7 +194,9 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { // their corresponding scope infos. Therefore, looking up variables in the // deserialized scopes is not possible. void DeserializeScopeChain(Isolate* isolate, ParseInfo* info, - MaybeHandle<ScopeInfo> maybe_outer_scope_info); + MaybeHandle<ScopeInfo> maybe_outer_scope_info, + Scope::DeserializationMode mode = + Scope::DeserializationMode::kScopesOnly); // Move statistics to Isolate void UpdateStatistics(Isolate* isolate, Handle<Script> script); @@ -181,8 +204,11 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { private: friend class ParserBase<Parser>; - friend class v8::internal::ExpressionClassifierErrorTracker< - ParserTypes<Parser>>; + friend struct ParserFormalParameters; + friend class i::ExpressionScope<ParserTypes<Parser>>; + friend class i::VariableDeclarationParsingScope<ParserTypes<Parser>>; + friend class i::ParameterDeclarationParsingScope<ParserTypes<Parser>>; + friend class i::ArrowHeadParsingScope<ParserTypes<Parser>>; friend bool v8::internal::parsing::ParseProgram(ParseInfo*, Isolate*); friend bool v8::internal::parsing::ParseFunction( ParseInfo*, Handle<SharedFunctionInfo> shared_info, Isolate*); @@ -236,8 +262,8 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { // We manually construct the AST and scopes for a top-level function and the // function wrapper. void ParseWrapped(Isolate* isolate, ParseInfo* info, - ZonePtrList<Statement>* body, DeclarationScope* scope, - Zone* zone, bool* ok); + ScopedPtrList<Statement>* body, DeclarationScope* scope, + Zone* zone); ZonePtrList<const AstRawString>* PrepareWrappedArguments(Isolate* isolate, ParseInfo* info, @@ -251,31 +277,33 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { parsing_module_, parsing_on_main_thread_); #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name()); SET_ALLOW(natives); - SET_ALLOW(harmony_do_expressions); SET_ALLOW(harmony_public_fields); SET_ALLOW(harmony_static_fields); SET_ALLOW(harmony_dynamic_import); SET_ALLOW(harmony_import_meta); SET_ALLOW(harmony_private_fields); + SET_ALLOW(harmony_private_methods); SET_ALLOW(eval_cache); #undef SET_ALLOW + preparse_data_buffer_.reserve(128); } return reusable_preparser_; } - void ParseModuleItemList(ZonePtrList<Statement>* body, bool* ok); - Statement* ParseModuleItem(bool* ok); - const AstRawString* ParseModuleSpecifier(bool* ok); - void ParseImportDeclaration(bool* ok); - Statement* ParseExportDeclaration(bool* ok); - Statement* ParseExportDefault(bool* ok); + void ParseModuleItemList(ScopedPtrList<Statement>* body); + Statement* ParseModuleItem(); + const AstRawString* ParseModuleSpecifier(); + void ParseImportDeclaration(); + Statement* ParseExportDeclaration(); + Statement* ParseExportDefault(); + void ParseExportStar(); struct ExportClauseData { const AstRawString* export_name; const AstRawString* local_name; Scanner::Location location; }; ZoneChunkList<ExportClauseData>* ParseExportClause( - Scanner::Location* reserved_loc, bool* ok); + Scanner::Location* reserved_loc); struct NamedImport : public ZoneObject { const AstRawString* import_name; const AstRawString* local_name; @@ -286,117 +314,87 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { local_name(local_name), location(location) {} }; - ZonePtrList<const NamedImport>* ParseNamedImports(int pos, bool* ok); - Block* BuildInitializationBlock(DeclarationParsingResult* parsing_result, - ZonePtrList<const AstRawString>* names, - bool* ok); + ZonePtrList<const NamedImport>* ParseNamedImports(int pos); + Statement* BuildInitializationBlock(DeclarationParsingResult* parsing_result); void DeclareLabel(ZonePtrList<const AstRawString>** labels, ZonePtrList<const AstRawString>** own_labels, - VariableProxy* expr, bool* ok); + VariableProxy* expr); bool ContainsLabel(ZonePtrList<const AstRawString>* labels, const AstRawString* label); Expression* RewriteReturn(Expression* return_value, int pos); Statement* RewriteSwitchStatement(SwitchStatement* switch_statement, Scope* scope); - void RewriteCatchPattern(CatchInfo* catch_info, bool* ok); - void ValidateCatchBlock(const CatchInfo& catch_info, bool* ok); + Block* RewriteCatchPattern(CatchInfo* catch_info); + void ReportVarRedeclarationIn(const AstRawString* name, Scope* scope); Statement* RewriteTryStatement(Block* try_block, Block* catch_block, const SourceRange& catch_range, Block* finally_block, const SourceRange& finally_range, const CatchInfo& catch_info, int pos); void ParseAndRewriteGeneratorFunctionBody(int pos, FunctionKind kind, - ZonePtrList<Statement>* body, - bool* ok); - void ParseAndRewriteAsyncGeneratorFunctionBody(int pos, FunctionKind kind, - ZonePtrList<Statement>* body, - bool* ok); + ScopedPtrList<Statement>* body); + void ParseAndRewriteAsyncGeneratorFunctionBody( + int pos, FunctionKind kind, ScopedPtrList<Statement>* body); void DeclareFunctionNameVar(const AstRawString* function_name, FunctionLiteral::FunctionType function_type, DeclarationScope* function_scope); Statement* DeclareFunction(const AstRawString* variable_name, FunctionLiteral* function, VariableMode mode, - int pos, bool is_sloppy_block_function, - ZonePtrList<const AstRawString>* names, bool* ok); - Variable* CreateSyntheticContextVariable(const AstRawString* synthetic_name, - bool* ok); + int beg_pos, int end_pos, + bool is_sloppy_block_function, + ZonePtrList<const AstRawString>* names); + Variable* CreateSyntheticContextVariable(const AstRawString* synthetic_name); FunctionLiteral* CreateInitializerFunction( const char* name, DeclarationScope* scope, ZonePtrList<ClassLiteral::Property>* fields); - V8_INLINE Statement* DeclareClass(const AstRawString* variable_name, - Expression* value, - ZonePtrList<const AstRawString>* names, - int class_token_pos, int end_pos, bool* ok); - V8_INLINE void DeclareClassVariable(const AstRawString* name, - ClassInfo* class_info, - int class_token_pos, bool* ok); - V8_INLINE void DeclareClassProperty(const AstRawString* class_name, - ClassLiteralProperty* property, - const AstRawString* property_name, - ClassLiteralProperty::Kind kind, - bool is_static, bool is_constructor, - bool is_computed_name, - ClassInfo* class_info, bool* ok); - V8_INLINE Expression* RewriteClassLiteral(Scope* block_scope, - const AstRawString* name, - ClassInfo* class_info, int pos, - int end_pos, bool* ok); - V8_INLINE Statement* DeclareNative(const AstRawString* name, int pos, - bool* ok); - - V8_INLINE Block* IgnoreCompletion(Statement* statement); - - V8_INLINE Scope* NewHiddenCatchScope(); + + bool IdentifierEquals(const AstRawString* identifier, + const AstRawString* other) { + return identifier == other; + } + + Statement* DeclareClass(const AstRawString* variable_name, Expression* value, + ZonePtrList<const AstRawString>* names, + int class_token_pos, int end_pos); + void DeclareClassVariable(const AstRawString* name, ClassInfo* class_info, + int class_token_pos); + void DeclareClassProperty(const AstRawString* class_name, + ClassLiteralProperty* property, bool is_constructor, + ClassInfo* class_info); + void DeclareClassField(ClassLiteralProperty* property, + const AstRawString* property_name, bool is_static, + bool is_computed_name, bool is_private, + ClassInfo* class_info); + Expression* RewriteClassLiteral(Scope* block_scope, const AstRawString* name, + ClassInfo* class_info, int pos, int end_pos); + Statement* DeclareNative(const AstRawString* name, int pos); + + Block* IgnoreCompletion(Statement* statement); + + Scope* NewHiddenCatchScope(); // PatternRewriter and associated methods defined in pattern-rewriter.cc. friend class PatternRewriter; - void DeclareAndInitializeVariables( - Block* block, const DeclarationDescriptor* declaration_descriptor, - const DeclarationParsingResult::Declaration* declaration, - ZonePtrList<const AstRawString>* names, bool* ok); - void RewriteDestructuringAssignment(RewritableExpression* expr); - Expression* RewriteDestructuringAssignment(Assignment* assignment); - - // [if (IteratorType == kAsync)] - // !%_IsJSReceiver(result = Await(next.[[Call]](iterator, « »)) && - // %ThrowIteratorResultNotAnObject(result) - // [else] - // !%_IsJSReceiver(result = next.[[Call]](iterator, « »)) && - // %ThrowIteratorResultNotAnObject(result) - // [endif] - Expression* BuildIteratorNextResult(VariableProxy* iterator, - VariableProxy* next, Variable* result, - IteratorType type, int pos); - - // Initialize the components of a for-in / for-of statement. - Statement* InitializeForEachStatement(ForEachStatement* stmt, - Expression* each, Expression* subject, - Statement* body); - Statement* InitializeForOfStatement(ForOfStatement* stmt, Expression* each, - Expression* iterable, Statement* body, - bool finalize, IteratorType type, - int next_result_pos = kNoSourcePosition); + void InitializeVariables( + ScopedPtrList<Statement>* statements, VariableKind kind, + const DeclarationParsingResult::Declaration* declaration); Block* RewriteForVarInLegacy(const ForInfo& for_info); void DesugarBindingInForEachStatement(ForInfo* for_info, Block** body_block, - Expression** each_variable, bool* ok); - Block* CreateForEachStatementTDZ(Block* init_block, const ForInfo& for_info, - bool* ok); + Expression** each_variable); + Block* CreateForEachStatementTDZ(Block* init_block, const ForInfo& for_info); Statement* DesugarLexicalBindingsInForStatement( ForStatement* loop, Statement* init, Expression* cond, Statement* next, - Statement* body, Scope* inner_scope, const ForInfo& for_info, bool* ok); - - Expression* RewriteDoExpression(Block* body, int pos, bool* ok); + Statement* body, Scope* inner_scope, const ForInfo& for_info); FunctionLiteral* ParseFunctionLiteral( const AstRawString* name, Scanner::Location function_name_location, FunctionNameValidity function_name_validity, FunctionKind kind, int function_token_position, FunctionLiteral::FunctionType type, LanguageMode language_mode, - ZonePtrList<const AstRawString>* arguments_for_wrapped_function, - bool* ok); + ZonePtrList<const AstRawString>* arguments_for_wrapped_function); ObjectLiteral* InitializeObjectLiteral(ObjectLiteral* object_literal) { object_literal->CalculateEmitStore(main_zone()); @@ -412,7 +410,7 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { // The var declarations are hoisted to the function scope, but originate from // a scope where the name has also been let bound or the var declaration is // hoisted over such a scope. - void CheckConflictingVarDeclarations(Scope* scope, bool* ok); + void CheckConflictingVarDeclarations(Scope* scope); bool IsPropertyWithPrivateFieldKey(Expression* property); @@ -423,22 +421,22 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { // Implement sloppy block-scoped functions, ES2015 Annex B 3.3 void InsertSloppyBlockFunctionVarBindings(DeclarationScope* scope); - VariableProxy* NewUnresolved(const AstRawString* name, int begin_pos, - VariableKind kind = NORMAL_VARIABLE); - VariableProxy* NewUnresolved(const AstRawString* name); - Variable* Declare(Declaration* declaration, - DeclarationDescriptor::Kind declaration_kind, - VariableMode mode, InitializationFlag init, bool* ok, - Scope* declaration_scope = nullptr, - int var_end_pos = kNoSourcePosition); - Declaration* DeclareVariable(const AstRawString* name, VariableMode mode, - int pos, bool* ok); - Declaration* DeclareVariable(const AstRawString* name, VariableMode mode, - InitializationFlag init, int pos, bool* ok); + VariableProxy* DeclareVariable(const AstRawString* name, VariableMode mode, + int pos); + VariableProxy* DeclareVariable(const AstRawString* name, VariableMode mode, + InitializationFlag init, int pos); + void DeclareVariable(VariableProxy* proxy, VariableKind kind, + VariableMode mode, InitializationFlag init, + Scope* declaration_scope, bool* added, int begin, + int end = kNoSourcePosition); + void Declare(Declaration* declaration, VariableProxy* proxy, + VariableKind kind, VariableMode mode, InitializationFlag init, + Scope* declaration_scope, bool* added, + int var_end_pos = kNoSourcePosition); bool TargetStackContainsLabel(const AstRawString* label); - BreakableStatement* LookupBreakTarget(const AstRawString* label, bool* ok); - IterationStatement* LookupContinueTarget(const AstRawString* label, bool* ok); + BreakableStatement* LookupBreakTarget(const AstRawString* label); + IterationStatement* LookupContinueTarget(const AstRawString* label); Statement* BuildAssertIsCoercible(Variable* var, ObjectLiteral* pattern); @@ -448,8 +446,6 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { // Skip over a lazy function, either using cached data if we have it, or // by parsing the function with PreParser. Consumes the ending }. - // If may_abort == true, the (pre-)parser may decide to abort skipping - // in order to force the function to be eagerly parsed, after all. // In case the preparser detects an error it cannot identify, it resets the // scanner- and preparser state to the initial one, before PreParsing the // function. @@ -460,22 +456,19 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { bool SkipFunction(const AstRawString* function_name, FunctionKind kind, FunctionLiteral::FunctionType function_type, DeclarationScope* function_scope, int* num_parameters, - ProducedPreParsedScopeData** produced_preparsed_scope_data, - bool is_inner_function, bool may_abort, - FunctionLiteral::EagerCompileHint* hint, bool* ok); + ProducedPreparseData** produced_preparsed_scope_data); Block* BuildParameterInitializationBlock( - const ParserFormalParameters& parameters, bool* ok); + const ParserFormalParameters& parameters); Block* BuildRejectPromiseOnException(Block* block); - ZonePtrList<Statement>* ParseFunction( - const AstRawString* function_name, int pos, FunctionKind kind, - FunctionLiteral::FunctionType function_type, + void ParseFunction( + ScopedPtrList<Statement>* body, const AstRawString* function_name, + int pos, FunctionKind kind, FunctionLiteral::FunctionType function_type, DeclarationScope* function_scope, int* num_parameters, int* function_length, bool* has_duplicate_parameters, int* expected_property_count, int* suspend_count, - ZonePtrList<const AstRawString>* arguments_for_wrapped_function, - bool* ok); + ZonePtrList<const AstRawString>* arguments_for_wrapped_function); void ThrowPendingError(Isolate* isolate, Handle<Script> script); @@ -497,7 +490,6 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { } void AddExpression(Expression* expression, Zone* zone) { - DCHECK_NOT_NULL(expression); expressions_.Add(expression, zone); } @@ -524,60 +516,40 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { Expression* CloseTemplateLiteral(TemplateLiteralState* state, int start, Expression* tag); - ArrayLiteral* ArrayLiteralFromListWithSpread(ZonePtrList<Expression>* list); - Expression* SpreadCall(Expression* function, ZonePtrList<Expression>* args, - int pos, Call::PossiblyEval is_possibly_eval); - Expression* SpreadCallNew(Expression* function, ZonePtrList<Expression>* args, - int pos); + ArrayLiteral* ArrayLiteralFromListWithSpread( + const ScopedPtrList<Expression>& list); + Expression* SpreadCall(Expression* function, + const ScopedPtrList<Expression>& args, int pos, + Call::PossiblyEval is_possibly_eval); + Expression* SpreadCallNew(Expression* function, + const ScopedPtrList<Expression>& args, int pos); Expression* RewriteSuperCall(Expression* call_expression); void SetLanguageMode(Scope* scope, LanguageMode mode); void SetAsmModule(); - // Rewrite all DestructuringAssignments in the current FunctionState. - V8_INLINE void RewriteDestructuringAssignments(); - Expression* RewriteSpreads(ArrayLiteral* lit); - V8_INLINE void QueueDestructuringAssignmentForRewriting( - RewritableExpression* assignment); - friend class InitializerRewriter; void RewriteParameterInitializer(Expression* expr); Expression* BuildInitialYield(int pos, FunctionKind kind); Assignment* BuildCreateJSGeneratorObject(int pos, FunctionKind kind); - Expression* BuildRejectPromise(Expression* value, int pos); - Variable* PromiseVariable(); - Variable* AsyncGeneratorAwaitVariable(); // Generic AST generator for throwing errors from compiled code. Expression* NewThrowError(Runtime::FunctionId function_id, - MessageTemplate::Template message, - const AstRawString* arg, int pos); - - void FinalizeIteratorUse(Variable* completion, Expression* condition, - Variable* iter, Block* iterator_use, Block* result, - IteratorType type); + MessageTemplate message, const AstRawString* arg, + int pos); Statement* FinalizeForOfStatement(ForOfStatement* loop, Variable* completion, IteratorType type, int pos); - void BuildIteratorClose(ZonePtrList<Statement>* statements, - Variable* iterator, Variable* input, Variable* output, - IteratorType type); - void BuildIteratorCloseForCompletion(ZonePtrList<Statement>* statements, - Variable* iterator, - Expression* completion, - IteratorType type); Statement* CheckCallable(Variable* var, Expression* error, int pos); - V8_INLINE void RewriteAsyncFunctionBody(ZonePtrList<Statement>* body, - Block* block, - Expression* return_value, bool* ok); + void RewriteAsyncFunctionBody(ScopedPtrList<Statement>* body, Block* block, + Expression* return_value); void AddArrowFunctionFormalParameters(ParserFormalParameters* parameters, - Expression* params, int end_pos, - bool* ok); + Expression* params, int end_pos); void SetFunctionName(Expression* value, const AstRawString* name, const AstRawString* prefix = nullptr); @@ -586,6 +558,10 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { return identifier == ast_value_factory()->eval_string(); } + V8_INLINE bool IsAsync(const AstRawString* identifier) const { + return identifier == ast_value_factory()->async_string(); + } + V8_INLINE bool IsArguments(const AstRawString* identifier) const { return identifier == ast_value_factory()->arguments_string(); } @@ -606,7 +582,6 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { // inside a variable proxy). We exclude the case of 'this', which // has been converted to a variable proxy. V8_INLINE static bool IsIdentifier(Expression* expression) { - DCHECK_NOT_NULL(expression); VariableProxy* operand = expression->AsVariableProxy(); return operand != nullptr && !operand->is_this() && !operand->is_new_target(); @@ -646,14 +621,6 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { return string->AsArrayIndex(index); } - V8_INLINE bool IsUseStrictDirective(Statement* statement) const { - return IsStringLiteral(statement, ast_value_factory()->use_strict_string()); - } - - V8_INLINE bool IsUseAsmDirective(Statement* statement) const { - return IsStringLiteral(statement, ast_value_factory()->use_asm_string()); - } - // Returns true if the statement is an expression statement containing // a single string literal. If a second argument is given, the literal // is also compared with it and the result is true only if they are equal. @@ -711,21 +678,11 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { } } - // Determine if the expression is a variable proxy and mark it as being used - // in an assignment or with a increment/decrement operator. - V8_INLINE static void MarkExpressionAsAssigned(Expression* expression) { - DCHECK_NOT_NULL(expression); - if (expression->IsVariableProxy()) { - expression->AsVariableProxy()->set_is_assigned(); - } - } - // A shortcut for performing a ToString operation V8_INLINE Expression* ToString(Expression* expr) { if (expr->IsStringLiteral()) return expr; - ZonePtrList<Expression>* args = - new (zone()) ZonePtrList<Expression>(1, zone()); - args->Add(expr, zone()); + ScopedPtrList<Expression> args(pointer_buffer()); + args.Add(expr); return factory()->NewCallRuntime(Runtime::kInlineToString, args, expr->position()); } @@ -752,8 +709,8 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { int pos); // Generate AST node that throws a ReferenceError with the given type. - V8_INLINE Expression* NewThrowReferenceError( - MessageTemplate::Template message, int pos) { + V8_INLINE Expression* NewThrowReferenceError(MessageTemplate message, + int pos) { return NewThrowError(Runtime::kNewReferenceError, message, ast_value_factory()->empty_string(), pos); } @@ -761,33 +718,26 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { // Generate AST node that throws a SyntaxError with the given // type. The first argument may be null (in the handle sense) in // which case no arguments are passed to the constructor. - V8_INLINE Expression* NewThrowSyntaxError(MessageTemplate::Template message, + V8_INLINE Expression* NewThrowSyntaxError(MessageTemplate message, const AstRawString* arg, int pos) { return NewThrowError(Runtime::kNewSyntaxError, message, arg, pos); } // Generate AST node that throws a TypeError with the given // type. Both arguments must be non-null (in the handle sense). - V8_INLINE Expression* NewThrowTypeError(MessageTemplate::Template message, + V8_INLINE Expression* NewThrowTypeError(MessageTemplate message, const AstRawString* arg, int pos) { return NewThrowError(Runtime::kNewTypeError, message, arg, pos); } // Reporting errors. void ReportMessageAt(Scanner::Location source_location, - MessageTemplate::Template message, - const char* arg = nullptr, + MessageTemplate message, const char* arg = nullptr, ParseErrorType error_type = kSyntaxError) { - if (stack_overflow()) { - // Suppress the error message (syntax error or such) in the presence of a - // stack overflow. The isolate allows only one pending exception at at - // time - // and we want to report the stack overflow later. - return; - } pending_error_handler()->ReportMessageAt(source_location.beg_pos, source_location.end_pos, message, arg, error_type); + scanner_.set_parser_error(); } // Dummy implementation. The parser should never have a unidentifiable @@ -795,21 +745,18 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { V8_INLINE void ReportUnidentifiableError() { UNREACHABLE(); } void ReportMessageAt(Scanner::Location source_location, - MessageTemplate::Template message, - const AstRawString* arg, + MessageTemplate message, const AstRawString* arg, ParseErrorType error_type = kSyntaxError) { - if (stack_overflow()) { - // Suppress the error message (syntax error or such) in the presence of a - // stack overflow. The isolate allows only one pending exception at at - // time - // and we want to report the stack overflow later. - return; - } pending_error_handler()->ReportMessageAt(source_location.beg_pos, source_location.end_pos, message, arg, error_type); + scanner_.set_parser_error(); } + void ReportUnexpectedTokenAt( + Scanner::Location location, Token::Value token, + MessageTemplate message = MessageTemplate::kUnexpectedToken); + // "null" return type creators. V8_INLINE static std::nullptr_t NullIdentifier() { return nullptr; } V8_INLINE static std::nullptr_t NullExpression() { return nullptr; } @@ -821,6 +768,8 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { return nullptr; } V8_INLINE static std::nullptr_t NullStatement() { return nullptr; } + V8_INLINE static std::nullptr_t NullBlock() { return nullptr; } + Expression* FailureExpression() { return factory()->FailureExpression(); } template <typename T> V8_INLINE static bool IsNull(T subject) { @@ -860,7 +809,7 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { Expression* NewTargetExpression(int pos); Expression* ImportMetaExpression(int pos); - Literal* ExpressionFromLiteral(Token::Value token, int pos); + Expression* ExpressionFromLiteral(Token::Value token, int pos); V8_INLINE VariableProxy* ExpressionFromIdentifier( const AstRawString* name, int start_position, @@ -868,13 +817,12 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { if (infer == InferName::kYes) { fni_.PushVariableName(name); } - return NewUnresolved(name, start_position); + return expression_scope()->NewVariable(name, start_position); } - V8_INLINE Expression* ExpressionFromString(int pos) { - const AstRawString* symbol = GetSymbol(); - fni_.PushLiteralName(symbol); - return factory()->NewStringLiteral(symbol, pos); + V8_INLINE Variable* DeclareCatchVariableName(Scope* scope, + const AstRawString* name) { + return scope->DeclareCatchVariableName(name); } V8_INLINE ZonePtrList<Expression>* NewExpressionList(int size) const { @@ -892,9 +840,8 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { return new (zone()) ZonePtrList<Statement>(size, zone()); } - V8_INLINE Expression* NewV8Intrinsic(const AstRawString* name, - ZonePtrList<Expression>* args, int pos, - bool* ok); + Expression* NewV8Intrinsic(const AstRawString* name, + const ScopedPtrList<Expression>& args, int pos); V8_INLINE Statement* NewThrowStatement(Expression* exception, int pos) { return factory()->NewExpressionStatement( @@ -907,44 +854,37 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { int initializer_end_position, bool is_rest) { parameters->UpdateArityAndFunctionLength(initializer != nullptr, is_rest); - bool has_simple_name = pattern->IsVariableProxy() && initializer == nullptr; - const AstRawString* name = has_simple_name - ? pattern->AsVariableProxy()->raw_name() - : ast_value_factory()->empty_string(); auto parameter = new (parameters->scope->zone()) - ParserFormalParameters::Parameter(name, pattern, initializer, + ParserFormalParameters::Parameter(pattern, initializer, scanner()->location().beg_pos, initializer_end_position, is_rest); parameters->params.Add(parameter); } - V8_INLINE void DeclareFormalParameters( - DeclarationScope* scope, - const base::ThreadedList<ParserFormalParameters::Parameter>& parameters, - bool is_simple, bool* has_duplicate = nullptr) { - if (!is_simple) scope->SetHasNonSimpleParameters(); - for (auto parameter : parameters) { - bool is_optional = parameter->initializer != nullptr; + V8_INLINE void DeclareFormalParameters(ParserFormalParameters* parameters) { + bool is_simple = parameters->is_simple; + DeclarationScope* scope = parameters->scope; + if (!is_simple) scope->MakeParametersNonSimple(); + for (auto parameter : parameters->params) { + bool is_optional = parameter->initializer() != nullptr; // If the parameter list is simple, declare the parameters normally with // their names. If the parameter list is not simple, declare a temporary // for each parameter - the corresponding named variable is declared by // BuildParamerterInitializationBlock. scope->DeclareParameter( - is_simple ? parameter->name : ast_value_factory()->empty_string(), + is_simple ? parameter->name() : ast_value_factory()->empty_string(), is_simple ? VariableMode::kVar : VariableMode::kTemporary, - is_optional, parameter->is_rest, has_duplicate, ast_value_factory(), + is_optional, parameter->is_rest(), ast_value_factory(), parameter->position); } } - void DeclareArrowFunctionFormalParameters(ParserFormalParameters* parameters, - Expression* params, - const Scanner::Location& params_loc, - Scanner::Location* duplicate_loc, - bool* ok); + void DeclareArrowFunctionFormalParameters( + ParserFormalParameters* parameters, Expression* params, + const Scanner::Location& params_loc); - Expression* ExpressionListToExpression(ZonePtrList<Expression>* args); + Expression* ExpressionListToExpression(const ScopedPtrList<Expression>& args); void SetFunctionNameFromPropertyName(LiteralProperty* property, const AstRawString* name, @@ -956,11 +896,6 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { void SetFunctionNameFromIdentifierRef(Expression* value, Expression* identifier); - V8_INLINE ZoneList<typename ExpressionClassifier::Error>* - GetReportedErrorList() const { - return function_state_->GetReportedErrorList(); - } - V8_INLINE void CountUsage(v8::Isolate::UseCounterFeature feature) { ++use_counts_[feature]; } @@ -1091,9 +1026,21 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { node, new (zone()) TryFinallyStatementSourceRanges(body_range)); } + // Generate the next internal variable name for binding an exported namespace + // object (used to implement the "export * as" syntax). + const AstRawString* NextInternalNamespaceExportName(); + + ParseInfo* info() const { return info_; } + + std::vector<uint8_t>* preparse_data_buffer() { + return &preparse_data_buffer_; + } + // Parser's private field members. friend class PreParserZoneScope; // Uses reusable_preparser(). + friend class PreparseDataBuilder; // Uses preparse_data_buffer() + ParseInfo* info_; Scanner scanner_; Zone preparser_zone_; PreParser* reusable_preparser_; @@ -1107,13 +1054,17 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { ScriptCompiler::CompileOptions compile_options_; + // For NextInternalNamespaceExportName(). + int number_of_named_namespace_exports_ = 0; + // Other information which will be stored in Parser and moved to Isolate after // parsing. int use_counts_[v8::Isolate::kUseCounterFeatureCount]; int total_preparse_skipped_; bool allow_lazy_; bool temp_zoned_; - ConsumedPreParsedScopeData* consumed_preparsed_scope_data_; + ConsumedPreparseData* consumed_preparse_data_; + std::vector<uint8_t> preparse_data_buffer_; // If not kNoSourcePosition, indicates that the first function literal // encountered is a dynamic function, see CreateDynamicFunction(). This field |