Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(300)

Side by Side Diff: src/parsing/parser.h

Issue 1895603002: [esnext] prototype runtime implementation for async functions (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@AsyncFunction
Patch Set: fix some nits Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/objects.cc ('k') | src/parsing/parser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 } 528 }
529 ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, Zone* zone) { 529 ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, Zone* zone) {
530 return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone); 530 return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone);
531 } 531 }
532 ZoneList<v8::internal::Statement*>* NewStatementList(int size, Zone* zone) { 532 ZoneList<v8::internal::Statement*>* NewStatementList(int size, Zone* zone) {
533 return new(zone) ZoneList<v8::internal::Statement*>(size, zone); 533 return new(zone) ZoneList<v8::internal::Statement*>(size, zone);
534 } 534 }
535 535
536 V8_INLINE void AddParameterInitializationBlock( 536 V8_INLINE void AddParameterInitializationBlock(
537 const ParserFormalParameters& parameters, 537 const ParserFormalParameters& parameters,
538 ZoneList<v8::internal::Statement*>* body, bool* ok); 538 ZoneList<v8::internal::Statement*>* body, bool is_async, bool* ok);
539
540 void ParseAsyncArrowSingleExpressionBody(
541 ZoneList<Statement*>* body, bool accept_IN,
542 Type::ExpressionClassifier* classifier, int pos, bool* ok);
539 543
540 V8_INLINE Scope* NewScope(Scope* parent_scope, ScopeType scope_type, 544 V8_INLINE Scope* NewScope(Scope* parent_scope, ScopeType scope_type,
541 FunctionKind kind = kNormalFunction); 545 FunctionKind kind = kNormalFunction);
542 546
543 V8_INLINE void AddFormalParameter(ParserFormalParameters* parameters, 547 V8_INLINE void AddFormalParameter(ParserFormalParameters* parameters,
544 Expression* pattern, 548 Expression* pattern,
545 Expression* initializer, 549 Expression* initializer,
546 int initializer_end_position, bool is_rest); 550 int initializer_end_position, bool is_rest);
547 V8_INLINE void DeclareFormalParameter( 551 V8_INLINE void DeclareFormalParameter(
548 Scope* scope, const ParserFormalParameters::Parameter& parameter, 552 Scope* scope, const ParserFormalParameters::Parameter& parameter,
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 Expression* subject, Statement* body, 968 Expression* subject, Statement* body,
965 int each_keyword_pos); 969 int each_keyword_pos);
966 void InitializeForOfStatement(ForOfStatement* stmt, Expression* each, 970 void InitializeForOfStatement(ForOfStatement* stmt, Expression* each,
967 Expression* iterable, Statement* body, 971 Expression* iterable, Statement* body,
968 int next_result_pos = RelocInfo::kNoPosition); 972 int next_result_pos = RelocInfo::kNoPosition);
969 Statement* DesugarLexicalBindingsInForStatement( 973 Statement* DesugarLexicalBindingsInForStatement(
970 Scope* inner_scope, VariableMode mode, 974 Scope* inner_scope, VariableMode mode,
971 ZoneList<const AstRawString*>* names, ForStatement* loop, Statement* init, 975 ZoneList<const AstRawString*>* names, ForStatement* loop, Statement* init,
972 Expression* cond, Statement* next, Statement* body, bool* ok); 976 Expression* cond, Statement* next, Statement* body, bool* ok);
973 977
978 void DesugarAsyncFunctionBody(const AstRawString* function_name, Scope* scope,
979 ZoneList<Statement*>* body,
980 Type::ExpressionClassifier* classifier,
981 FunctionKind kind, FunctionBody type,
982 bool accept_IN, int pos, bool* ok);
983
974 void RewriteDoExpression(Expression* expr, bool* ok); 984 void RewriteDoExpression(Expression* expr, bool* ok);
975 985
976 FunctionLiteral* ParseFunctionLiteral( 986 FunctionLiteral* ParseFunctionLiteral(
977 const AstRawString* name, Scanner::Location function_name_location, 987 const AstRawString* name, Scanner::Location function_name_location,
978 FunctionNameValidity function_name_validity, FunctionKind kind, 988 FunctionNameValidity function_name_validity, FunctionKind kind,
979 int function_token_position, FunctionLiteral::FunctionType type, 989 int function_token_position, FunctionLiteral::FunctionType type,
980 LanguageMode language_mode, bool* ok); 990 LanguageMode language_mode, bool* ok);
981 991
982 ClassLiteral* ParseClassLiteral(ExpressionClassifier* classifier, 992 ClassLiteral* ParseClassLiteral(ExpressionClassifier* classifier,
983 const AstRawString* name, 993 const AstRawString* name,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 // In this case, it'll reset the scanner using the bookmark. 1044 // In this case, it'll reset the scanner using the bookmark.
1035 void SkipLazyFunctionBody(int* materialized_literal_count, 1045 void SkipLazyFunctionBody(int* materialized_literal_count,
1036 int* expected_property_count, bool* ok, 1046 int* expected_property_count, bool* ok,
1037 Scanner::BookmarkScope* bookmark = nullptr); 1047 Scanner::BookmarkScope* bookmark = nullptr);
1038 1048
1039 PreParser::PreParseResult ParseLazyFunctionBodyWithPreParser( 1049 PreParser::PreParseResult ParseLazyFunctionBodyWithPreParser(
1040 SingletonLogger* logger, Scanner::BookmarkScope* bookmark = nullptr); 1050 SingletonLogger* logger, Scanner::BookmarkScope* bookmark = nullptr);
1041 1051
1042 Block* BuildParameterInitializationBlock( 1052 Block* BuildParameterInitializationBlock(
1043 const ParserFormalParameters& parameters, bool* ok); 1053 const ParserFormalParameters& parameters, bool* ok);
1054 Block* BuildRejectPromiseOnException(Block* block);
1044 1055
1045 // Consumes the ending }. 1056 // Consumes the ending }.
1046 ZoneList<Statement*>* ParseEagerFunctionBody( 1057 ZoneList<Statement*>* ParseEagerFunctionBody(
1047 const AstRawString* function_name, int pos, 1058 const AstRawString* function_name, int pos,
1048 const ParserFormalParameters& parameters, FunctionKind kind, 1059 const ParserFormalParameters& parameters, FunctionKind kind,
1049 FunctionLiteral::FunctionType function_type, bool* ok); 1060 FunctionLiteral::FunctionType function_type, bool* ok);
1050 1061
1051 void ThrowPendingError(Isolate* isolate, Handle<Script> script); 1062 void ThrowPendingError(Isolate* isolate, Handle<Script> script);
1052 1063
1053 TemplateLiteralState OpenTemplateLiteral(int pos); 1064 TemplateLiteralState OpenTemplateLiteral(int pos);
(...skipping 24 matching lines...) Expand all
1078 Expression* right, int pos); 1089 Expression* right, int pos);
1079 1090
1080 friend class NonPatternRewriter; 1091 friend class NonPatternRewriter;
1081 V8_INLINE Expression* RewriteSpreads(ArrayLiteral* lit); 1092 V8_INLINE Expression* RewriteSpreads(ArrayLiteral* lit);
1082 1093
1083 V8_INLINE void RewriteNonPattern(ExpressionClassifier* classifier, bool* ok); 1094 V8_INLINE void RewriteNonPattern(ExpressionClassifier* classifier, bool* ok);
1084 1095
1085 friend class InitializerRewriter; 1096 friend class InitializerRewriter;
1086 void RewriteParameterInitializer(Expression* expr, Scope* scope); 1097 void RewriteParameterInitializer(Expression* expr, Scope* scope);
1087 1098
1099 Expression* BuildCreateJSGeneratorObject(int pos);
1100 Expression* BuildPromiseResolve(Expression* value, int pos);
1101 Expression* BuildPromiseReject(Expression* value, int pos);
1102
1088 Scanner scanner_; 1103 Scanner scanner_;
1089 PreParser* reusable_preparser_; 1104 PreParser* reusable_preparser_;
1090 Scope* original_scope_; // for ES5 function declarations in sloppy eval 1105 Scope* original_scope_; // for ES5 function declarations in sloppy eval
1091 Target* target_stack_; // for break, continue statements 1106 Target* target_stack_; // for break, continue statements
1092 ScriptCompiler::CompileOptions compile_options_; 1107 ScriptCompiler::CompileOptions compile_options_;
1093 ParseData* cached_parse_data_; 1108 ParseData* cached_parse_data_;
1094 1109
1095 PendingCompilationErrorHandler pending_error_handler_; 1110 PendingCompilationErrorHandler pending_error_handler_;
1096 1111
1097 // Other information which will be stored in Parser and moved to Isolate after 1112 // 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
1247 parser_->scanner()->location()); 1262 parser_->scanner()->location());
1248 } 1263 }
1249 if (is_sloppy(scope->language_mode())) { 1264 if (is_sloppy(scope->language_mode())) {
1250 // TODO(sigurds) Mark every parameter as maybe assigned. This is a 1265 // TODO(sigurds) Mark every parameter as maybe assigned. This is a
1251 // conservative approximation necessary to account for parameters 1266 // conservative approximation necessary to account for parameters
1252 // that are assigned via the arguments array. 1267 // that are assigned via the arguments array.
1253 var->set_maybe_assigned(); 1268 var->set_maybe_assigned();
1254 } 1269 }
1255 } 1270 }
1256 1271
1257
1258 void ParserTraits::AddParameterInitializationBlock( 1272 void ParserTraits::AddParameterInitializationBlock(
1259 const ParserFormalParameters& parameters, 1273 const ParserFormalParameters& parameters,
1260 ZoneList<v8::internal::Statement*>* body, bool* ok) { 1274 ZoneList<v8::internal::Statement*>* body, bool is_async, bool* ok) {
1261 if (!parameters.is_simple) { 1275 if (!parameters.is_simple) {
1262 auto* init_block = 1276 auto* init_block =
1263 parser_->BuildParameterInitializationBlock(parameters, ok); 1277 parser_->BuildParameterInitializationBlock(parameters, ok);
1264 if (!*ok) return; 1278 if (!*ok) return;
1279
1280 if (is_async) {
1281 init_block = parser_->BuildRejectPromiseOnException(init_block);
1282 }
1283
1265 if (init_block != nullptr) { 1284 if (init_block != nullptr) {
1266 body->Add(init_block, parser_->zone()); 1285 body->Add(init_block, parser_->zone());
1267 } 1286 }
1268 } 1287 }
1269 } 1288 }
1270 1289
1271 Expression* ParserTraits::ParseAsyncFunctionExpression(bool* ok) { 1290 Expression* ParserTraits::ParseAsyncFunctionExpression(bool* ok) {
1272 return parser_->ParseAsyncFunctionExpression(ok); 1291 return parser_->ParseAsyncFunctionExpression(ok);
1273 } 1292 }
1274 1293
1275 DoExpression* ParserTraits::ParseDoExpression(bool* ok) { 1294 DoExpression* ParserTraits::ParseDoExpression(bool* ok) {
1276 return parser_->ParseDoExpression(ok); 1295 return parser_->ParseDoExpression(ok);
1277 } 1296 }
1278 1297
1279 1298
1280 } // namespace internal 1299 } // namespace internal
1281 } // namespace v8 1300 } // namespace v8
1282 1301
1283 #endif // V8_PARSING_PARSER_H_ 1302 #endif // V8_PARSING_PARSER_H_
OLDNEW
« no previous file with comments | « src/objects.cc ('k') | src/parsing/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698