| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_PARSING_PARSER_H_ | 5 #ifndef V8_PARSING_PARSER_H_ |
| 6 #define V8_PARSING_PARSER_H_ | 6 #define V8_PARSING_PARSER_H_ |
| 7 | 7 |
| 8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
| 9 #include "src/ast/ast.h" | 9 #include "src/ast/ast.h" |
| 10 #include "src/ast/scopes.h" | 10 #include "src/ast/scopes.h" |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 } | 522 } |
| 523 ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, Zone* zone) { | 523 ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, Zone* zone) { |
| 524 return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone); | 524 return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone); |
| 525 } | 525 } |
| 526 ZoneList<v8::internal::Statement*>* NewStatementList(int size, Zone* zone) { | 526 ZoneList<v8::internal::Statement*>* NewStatementList(int size, Zone* zone) { |
| 527 return new(zone) ZoneList<v8::internal::Statement*>(size, zone); | 527 return new(zone) ZoneList<v8::internal::Statement*>(size, zone); |
| 528 } | 528 } |
| 529 | 529 |
| 530 V8_INLINE void AddParameterInitializationBlock( | 530 V8_INLINE void AddParameterInitializationBlock( |
| 531 const ParserFormalParameters& parameters, | 531 const ParserFormalParameters& parameters, |
| 532 ZoneList<v8::internal::Statement*>* body, bool* ok); | 532 ZoneList<v8::internal::Statement*>* body, bool is_async, bool* ok); |
| 533 |
| 534 void ParseAsyncArrowSingleExpressionBody( |
| 535 ZoneList<Statement*>* body, bool accept_IN, |
| 536 Type::ExpressionClassifier* classifier, int pos, bool* ok); |
| 533 | 537 |
| 534 V8_INLINE Scope* NewScope(Scope* parent_scope, ScopeType scope_type, | 538 V8_INLINE Scope* NewScope(Scope* parent_scope, ScopeType scope_type, |
| 535 FunctionKind kind = kNormalFunction); | 539 FunctionKind kind = kNormalFunction); |
| 536 | 540 |
| 537 V8_INLINE void AddFormalParameter(ParserFormalParameters* parameters, | 541 V8_INLINE void AddFormalParameter(ParserFormalParameters* parameters, |
| 538 Expression* pattern, | 542 Expression* pattern, |
| 539 Expression* initializer, | 543 Expression* initializer, |
| 540 int initializer_end_position, bool is_rest); | 544 int initializer_end_position, bool is_rest); |
| 541 V8_INLINE void DeclareFormalParameter( | 545 V8_INLINE void DeclareFormalParameter( |
| 542 Scope* scope, const ParserFormalParameters::Parameter& parameter, | 546 Scope* scope, const ParserFormalParameters::Parameter& parameter, |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 955 Expression* subject, Statement* body, | 959 Expression* subject, Statement* body, |
| 956 int each_keyword_pos); | 960 int each_keyword_pos); |
| 957 void InitializeForOfStatement(ForOfStatement* stmt, Expression* each, | 961 void InitializeForOfStatement(ForOfStatement* stmt, Expression* each, |
| 958 Expression* iterable, Statement* body, | 962 Expression* iterable, Statement* body, |
| 959 int next_result_pos = RelocInfo::kNoPosition); | 963 int next_result_pos = RelocInfo::kNoPosition); |
| 960 Statement* DesugarLexicalBindingsInForStatement( | 964 Statement* DesugarLexicalBindingsInForStatement( |
| 961 Scope* inner_scope, VariableMode mode, | 965 Scope* inner_scope, VariableMode mode, |
| 962 ZoneList<const AstRawString*>* names, ForStatement* loop, Statement* init, | 966 ZoneList<const AstRawString*>* names, ForStatement* loop, Statement* init, |
| 963 Expression* cond, Statement* next, Statement* body, bool* ok); | 967 Expression* cond, Statement* next, Statement* body, bool* ok); |
| 964 | 968 |
| 969 void DesugarAsyncFunctionBody(const AstRawString* function_name, Scope* scope, |
| 970 ZoneList<Statement*>* body, |
| 971 Type::ExpressionClassifier* classifier, |
| 972 FunctionKind kind, FunctionBody type, |
| 973 bool accept_IN, int pos, bool* ok); |
| 974 |
| 965 void RewriteDoExpression(Expression* expr, bool* ok); | 975 void RewriteDoExpression(Expression* expr, bool* ok); |
| 966 | 976 |
| 967 FunctionLiteral* ParseFunctionLiteral( | 977 FunctionLiteral* ParseFunctionLiteral( |
| 968 const AstRawString* name, Scanner::Location function_name_location, | 978 const AstRawString* name, Scanner::Location function_name_location, |
| 969 FunctionNameValidity function_name_validity, FunctionKind kind, | 979 FunctionNameValidity function_name_validity, FunctionKind kind, |
| 970 int function_token_position, FunctionLiteral::FunctionType type, | 980 int function_token_position, FunctionLiteral::FunctionType type, |
| 971 LanguageMode language_mode, bool* ok); | 981 LanguageMode language_mode, bool* ok); |
| 972 | 982 |
| 973 | 983 |
| 974 ClassLiteral* ParseClassLiteral(const AstRawString* name, | 984 ClassLiteral* ParseClassLiteral(const AstRawString* name, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1025 // In this case, it'll reset the scanner using the bookmark. | 1035 // In this case, it'll reset the scanner using the bookmark. |
| 1026 void SkipLazyFunctionBody(int* materialized_literal_count, | 1036 void SkipLazyFunctionBody(int* materialized_literal_count, |
| 1027 int* expected_property_count, bool* ok, | 1037 int* expected_property_count, bool* ok, |
| 1028 Scanner::BookmarkScope* bookmark = nullptr); | 1038 Scanner::BookmarkScope* bookmark = nullptr); |
| 1029 | 1039 |
| 1030 PreParser::PreParseResult ParseLazyFunctionBodyWithPreParser( | 1040 PreParser::PreParseResult ParseLazyFunctionBodyWithPreParser( |
| 1031 SingletonLogger* logger, Scanner::BookmarkScope* bookmark = nullptr); | 1041 SingletonLogger* logger, Scanner::BookmarkScope* bookmark = nullptr); |
| 1032 | 1042 |
| 1033 Block* BuildParameterInitializationBlock( | 1043 Block* BuildParameterInitializationBlock( |
| 1034 const ParserFormalParameters& parameters, bool* ok); | 1044 const ParserFormalParameters& parameters, bool* ok); |
| 1045 Block* BuildRejectPromiseOnException(Block* block); |
| 1035 | 1046 |
| 1036 // Consumes the ending }. | 1047 // Consumes the ending }. |
| 1037 ZoneList<Statement*>* ParseEagerFunctionBody( | 1048 ZoneList<Statement*>* ParseEagerFunctionBody( |
| 1038 const AstRawString* function_name, int pos, | 1049 const AstRawString* function_name, int pos, |
| 1039 const ParserFormalParameters& parameters, FunctionKind kind, | 1050 const ParserFormalParameters& parameters, FunctionKind kind, |
| 1040 FunctionLiteral::FunctionType function_type, bool* ok); | 1051 FunctionLiteral::FunctionType function_type, bool* ok); |
| 1041 | 1052 |
| 1042 void ThrowPendingError(Isolate* isolate, Handle<Script> script); | 1053 void ThrowPendingError(Isolate* isolate, Handle<Script> script); |
| 1043 | 1054 |
| 1044 TemplateLiteralState OpenTemplateLiteral(int pos); | 1055 TemplateLiteralState OpenTemplateLiteral(int pos); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1067 Expression* right, int pos); | 1078 Expression* right, int pos); |
| 1068 | 1079 |
| 1069 friend class NonPatternRewriter; | 1080 friend class NonPatternRewriter; |
| 1070 V8_INLINE Expression* RewriteSpreads(ArrayLiteral* lit); | 1081 V8_INLINE Expression* RewriteSpreads(ArrayLiteral* lit); |
| 1071 | 1082 |
| 1072 V8_INLINE void RewriteNonPattern(ExpressionClassifier* classifier, bool* ok); | 1083 V8_INLINE void RewriteNonPattern(ExpressionClassifier* classifier, bool* ok); |
| 1073 | 1084 |
| 1074 friend class InitializerRewriter; | 1085 friend class InitializerRewriter; |
| 1075 void RewriteParameterInitializer(Expression* expr, Scope* scope); | 1086 void RewriteParameterInitializer(Expression* expr, Scope* scope); |
| 1076 | 1087 |
| 1088 Expression* EmitCreateJSGeneratorObject(int pos); |
| 1089 Expression* EmitPromiseResolve(Expression* value, int pos); |
| 1090 Expression* EmitPromiseReject(Expression* value, int pos); |
| 1091 |
| 1077 Scanner scanner_; | 1092 Scanner scanner_; |
| 1078 PreParser* reusable_preparser_; | 1093 PreParser* reusable_preparser_; |
| 1079 Scope* original_scope_; // for ES5 function declarations in sloppy eval | 1094 Scope* original_scope_; // for ES5 function declarations in sloppy eval |
| 1080 Target* target_stack_; // for break, continue statements | 1095 Target* target_stack_; // for break, continue statements |
| 1081 ScriptCompiler::CompileOptions compile_options_; | 1096 ScriptCompiler::CompileOptions compile_options_; |
| 1082 ParseData* cached_parse_data_; | 1097 ParseData* cached_parse_data_; |
| 1083 | 1098 |
| 1084 PendingCompilationErrorHandler pending_error_handler_; | 1099 PendingCompilationErrorHandler pending_error_handler_; |
| 1085 | 1100 |
| 1086 // Other information which will be stored in Parser and moved to Isolate after | 1101 // Other information which will be stored in Parser and moved to Isolate after |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1236 parser_->scanner()->location()); | 1251 parser_->scanner()->location()); |
| 1237 } | 1252 } |
| 1238 if (is_sloppy(scope->language_mode())) { | 1253 if (is_sloppy(scope->language_mode())) { |
| 1239 // TODO(sigurds) Mark every parameter as maybe assigned. This is a | 1254 // TODO(sigurds) Mark every parameter as maybe assigned. This is a |
| 1240 // conservative approximation necessary to account for parameters | 1255 // conservative approximation necessary to account for parameters |
| 1241 // that are assigned via the arguments array. | 1256 // that are assigned via the arguments array. |
| 1242 var->set_maybe_assigned(); | 1257 var->set_maybe_assigned(); |
| 1243 } | 1258 } |
| 1244 } | 1259 } |
| 1245 | 1260 |
| 1246 | |
| 1247 void ParserTraits::AddParameterInitializationBlock( | 1261 void ParserTraits::AddParameterInitializationBlock( |
| 1248 const ParserFormalParameters& parameters, | 1262 const ParserFormalParameters& parameters, |
| 1249 ZoneList<v8::internal::Statement*>* body, bool* ok) { | 1263 ZoneList<v8::internal::Statement*>* body, bool is_async, bool* ok) { |
| 1250 if (!parameters.is_simple) { | 1264 if (!parameters.is_simple) { |
| 1251 auto* init_block = | 1265 auto* init_block = |
| 1252 parser_->BuildParameterInitializationBlock(parameters, ok); | 1266 parser_->BuildParameterInitializationBlock(parameters, ok); |
| 1253 if (!*ok) return; | 1267 if (!*ok) return; |
| 1268 |
| 1269 if (is_async) { |
| 1270 init_block = parser_->BuildRejectPromiseOnException(init_block); |
| 1271 } |
| 1272 |
| 1254 if (init_block != nullptr) { | 1273 if (init_block != nullptr) { |
| 1255 body->Add(init_block, parser_->zone()); | 1274 body->Add(init_block, parser_->zone()); |
| 1256 } | 1275 } |
| 1257 } | 1276 } |
| 1258 } | 1277 } |
| 1259 | 1278 |
| 1260 Expression* ParserTraits::ParseAsyncFunctionExpression(bool* ok) { | 1279 Expression* ParserTraits::ParseAsyncFunctionExpression(bool* ok) { |
| 1261 return parser_->ParseAsyncFunctionExpression(ok); | 1280 return parser_->ParseAsyncFunctionExpression(ok); |
| 1262 } | 1281 } |
| 1263 | 1282 |
| 1264 DoExpression* ParserTraits::ParseDoExpression(bool* ok) { | 1283 DoExpression* ParserTraits::ParseDoExpression(bool* ok) { |
| 1265 return parser_->ParseDoExpression(ok); | 1284 return parser_->ParseDoExpression(ok); |
| 1266 } | 1285 } |
| 1267 | 1286 |
| 1268 | 1287 |
| 1269 } // namespace internal | 1288 } // namespace internal |
| 1270 } // namespace v8 | 1289 } // namespace v8 |
| 1271 | 1290 |
| 1272 #endif // V8_PARSING_PARSER_H_ | 1291 #endif // V8_PARSING_PARSER_H_ |
| OLD | NEW |