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

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: Try new strategy (Option C) Created 4 years, 8 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
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 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
955 void InitializeForEachStatement(ForEachStatement* stmt, Expression* each, 959 void InitializeForEachStatement(ForEachStatement* stmt, Expression* each,
956 Expression* subject, Statement* body); 960 Expression* subject, Statement* body);
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 iterable_pos); 963 int iterable_pos);
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
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
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* EmitYieldJSGeneratorObject(Expression* generator_object);
1090
1091 Expression* EmitPromiseResolve(Expression* value, int pos);
1092 Expression* EmitPromiseReject(Expression* value, int pos);
1093
1077 Scanner scanner_; 1094 Scanner scanner_;
1078 PreParser* reusable_preparser_; 1095 PreParser* reusable_preparser_;
1079 Scope* original_scope_; // for ES5 function declarations in sloppy eval 1096 Scope* original_scope_; // for ES5 function declarations in sloppy eval
1080 Target* target_stack_; // for break, continue statements 1097 Target* target_stack_; // for break, continue statements
1081 ScriptCompiler::CompileOptions compile_options_; 1098 ScriptCompiler::CompileOptions compile_options_;
1082 ParseData* cached_parse_data_; 1099 ParseData* cached_parse_data_;
1083 1100
1084 PendingCompilationErrorHandler pending_error_handler_; 1101 PendingCompilationErrorHandler pending_error_handler_;
1085 1102
1086 // Other information which will be stored in Parser and moved to Isolate after 1103 // 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
1236 parser_->scanner()->location()); 1253 parser_->scanner()->location());
1237 } 1254 }
1238 if (is_sloppy(scope->language_mode())) { 1255 if (is_sloppy(scope->language_mode())) {
1239 // TODO(sigurds) Mark every parameter as maybe assigned. This is a 1256 // TODO(sigurds) Mark every parameter as maybe assigned. This is a
1240 // conservative approximation necessary to account for parameters 1257 // conservative approximation necessary to account for parameters
1241 // that are assigned via the arguments array. 1258 // that are assigned via the arguments array.
1242 var->set_maybe_assigned(); 1259 var->set_maybe_assigned();
1243 } 1260 }
1244 } 1261 }
1245 1262
1246
1247 void ParserTraits::AddParameterInitializationBlock( 1263 void ParserTraits::AddParameterInitializationBlock(
1248 const ParserFormalParameters& parameters, 1264 const ParserFormalParameters& parameters,
1249 ZoneList<v8::internal::Statement*>* body, bool* ok) { 1265 ZoneList<v8::internal::Statement*>* body, bool is_async, bool* ok) {
1250 if (!parameters.is_simple) { 1266 if (!parameters.is_simple) {
1251 auto* init_block = 1267 auto* init_block =
1252 parser_->BuildParameterInitializationBlock(parameters, ok); 1268 parser_->BuildParameterInitializationBlock(parameters, ok);
1253 if (!*ok) return; 1269 if (!*ok) return;
1270
1271 if (is_async) {
1272 init_block = parser_->BuildRejectPromiseOnException(init_block);
1273 }
1274
1254 if (init_block != nullptr) { 1275 if (init_block != nullptr) {
1255 body->Add(init_block, parser_->zone()); 1276 body->Add(init_block, parser_->zone());
1256 } 1277 }
1257 } 1278 }
1258 } 1279 }
1259 1280
1260 Expression* ParserTraits::ParseAsyncFunctionExpression(bool* ok) { 1281 Expression* ParserTraits::ParseAsyncFunctionExpression(bool* ok) {
1261 return parser_->ParseAsyncFunctionExpression(ok); 1282 return parser_->ParseAsyncFunctionExpression(ok);
1262 } 1283 }
1263 1284
1264 DoExpression* ParserTraits::ParseDoExpression(bool* ok) { 1285 DoExpression* ParserTraits::ParseDoExpression(bool* ok) {
1265 return parser_->ParseDoExpression(ok); 1286 return parser_->ParseDoExpression(ok);
1266 } 1287 }
1267 1288
1268 1289
1269 } // namespace internal 1290 } // namespace internal
1270 } // namespace v8 1291 } // namespace v8
1271 1292
1272 #endif // V8_PARSING_PARSER_H_ 1293 #endif // V8_PARSING_PARSER_H_
OLDNEW
« src/isolate.cc ('K') | « src/objects-inl.h ('k') | src/parsing/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698