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

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: properly rebase 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
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 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 Expression* subject, Statement* body, 962 Expression* subject, Statement* body,
959 int each_keyword_pos); 963 int each_keyword_pos);
960 void InitializeForOfStatement(ForOfStatement* stmt, Expression* each, 964 void InitializeForOfStatement(ForOfStatement* stmt, Expression* each,
961 Expression* iterable, Statement* body, 965 Expression* iterable, Statement* body,
962 int next_result_pos = RelocInfo::kNoPosition); 966 int next_result_pos = RelocInfo::kNoPosition);
963 Statement* DesugarLexicalBindingsInForStatement( 967 Statement* DesugarLexicalBindingsInForStatement(
964 Scope* inner_scope, VariableMode mode, 968 Scope* inner_scope, VariableMode mode,
965 ZoneList<const AstRawString*>* names, ForStatement* loop, Statement* init, 969 ZoneList<const AstRawString*>* names, ForStatement* loop, Statement* init,
966 Expression* cond, Statement* next, Statement* body, bool* ok); 970 Expression* cond, Statement* next, Statement* body, bool* ok);
967 971
972 void DesugarAsyncFunctionBody(const AstRawString* function_name, Scope* scope,
973 ZoneList<Statement*>* body,
974 Type::ExpressionClassifier* classifier,
975 FunctionKind kind, FunctionBody type,
976 bool accept_IN, int pos, bool* ok);
977
968 void RewriteDoExpression(Expression* expr, bool* ok); 978 void RewriteDoExpression(Expression* expr, bool* ok);
969 979
970 FunctionLiteral* ParseFunctionLiteral( 980 FunctionLiteral* ParseFunctionLiteral(
971 const AstRawString* name, Scanner::Location function_name_location, 981 const AstRawString* name, Scanner::Location function_name_location,
972 FunctionNameValidity function_name_validity, FunctionKind kind, 982 FunctionNameValidity function_name_validity, FunctionKind kind,
973 int function_token_position, FunctionLiteral::FunctionType type, 983 int function_token_position, FunctionLiteral::FunctionType type,
974 LanguageMode language_mode, bool* ok); 984 LanguageMode language_mode, bool* ok);
975 985
976 ClassLiteral* ParseClassLiteral(ExpressionClassifier* classifier, 986 ClassLiteral* ParseClassLiteral(ExpressionClassifier* classifier,
977 const AstRawString* name, 987 const AstRawString* name,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 // In this case, it'll reset the scanner using the bookmark. 1038 // In this case, it'll reset the scanner using the bookmark.
1029 void SkipLazyFunctionBody(int* materialized_literal_count, 1039 void SkipLazyFunctionBody(int* materialized_literal_count,
1030 int* expected_property_count, bool* ok, 1040 int* expected_property_count, bool* ok,
1031 Scanner::BookmarkScope* bookmark = nullptr); 1041 Scanner::BookmarkScope* bookmark = nullptr);
1032 1042
1033 PreParser::PreParseResult ParseLazyFunctionBodyWithPreParser( 1043 PreParser::PreParseResult ParseLazyFunctionBodyWithPreParser(
1034 SingletonLogger* logger, Scanner::BookmarkScope* bookmark = nullptr); 1044 SingletonLogger* logger, Scanner::BookmarkScope* bookmark = nullptr);
1035 1045
1036 Block* BuildParameterInitializationBlock( 1046 Block* BuildParameterInitializationBlock(
1037 const ParserFormalParameters& parameters, bool* ok); 1047 const ParserFormalParameters& parameters, bool* ok);
1048 Block* BuildRejectPromiseOnException(Block* block);
1038 1049
1039 // Consumes the ending }. 1050 // Consumes the ending }.
1040 ZoneList<Statement*>* ParseEagerFunctionBody( 1051 ZoneList<Statement*>* ParseEagerFunctionBody(
1041 const AstRawString* function_name, int pos, 1052 const AstRawString* function_name, int pos,
1042 const ParserFormalParameters& parameters, FunctionKind kind, 1053 const ParserFormalParameters& parameters, FunctionKind kind,
1043 FunctionLiteral::FunctionType function_type, bool* ok); 1054 FunctionLiteral::FunctionType function_type, bool* ok);
1044 1055
1045 void ThrowPendingError(Isolate* isolate, Handle<Script> script); 1056 void ThrowPendingError(Isolate* isolate, Handle<Script> script);
1046 1057
1047 TemplateLiteralState OpenTemplateLiteral(int pos); 1058 TemplateLiteralState OpenTemplateLiteral(int pos);
(...skipping 24 matching lines...) Expand all
1072 Expression* right, int pos); 1083 Expression* right, int pos);
1073 1084
1074 friend class NonPatternRewriter; 1085 friend class NonPatternRewriter;
1075 V8_INLINE Expression* RewriteSpreads(ArrayLiteral* lit); 1086 V8_INLINE Expression* RewriteSpreads(ArrayLiteral* lit);
1076 1087
1077 V8_INLINE void RewriteNonPattern(ExpressionClassifier* classifier, bool* ok); 1088 V8_INLINE void RewriteNonPattern(ExpressionClassifier* classifier, bool* ok);
1078 1089
1079 friend class InitializerRewriter; 1090 friend class InitializerRewriter;
1080 void RewriteParameterInitializer(Expression* expr, Scope* scope); 1091 void RewriteParameterInitializer(Expression* expr, Scope* scope);
1081 1092
1093 Expression* EmitCreateJSGeneratorObject(int pos);
1094 Expression* EmitPromiseResolve(Expression* value, int pos);
1095 Expression* EmitPromiseReject(Expression* value, int pos);
1096
1082 Scanner scanner_; 1097 Scanner scanner_;
1083 PreParser* reusable_preparser_; 1098 PreParser* reusable_preparser_;
1084 Scope* original_scope_; // for ES5 function declarations in sloppy eval 1099 Scope* original_scope_; // for ES5 function declarations in sloppy eval
1085 Target* target_stack_; // for break, continue statements 1100 Target* target_stack_; // for break, continue statements
1086 ScriptCompiler::CompileOptions compile_options_; 1101 ScriptCompiler::CompileOptions compile_options_;
1087 ParseData* cached_parse_data_; 1102 ParseData* cached_parse_data_;
1088 1103
1089 PendingCompilationErrorHandler pending_error_handler_; 1104 PendingCompilationErrorHandler pending_error_handler_;
1090 1105
1091 // Other information which will be stored in Parser and moved to Isolate after 1106 // 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
1241 parser_->scanner()->location()); 1256 parser_->scanner()->location());
1242 } 1257 }
1243 if (is_sloppy(scope->language_mode())) { 1258 if (is_sloppy(scope->language_mode())) {
1244 // TODO(sigurds) Mark every parameter as maybe assigned. This is a 1259 // TODO(sigurds) Mark every parameter as maybe assigned. This is a
1245 // conservative approximation necessary to account for parameters 1260 // conservative approximation necessary to account for parameters
1246 // that are assigned via the arguments array. 1261 // that are assigned via the arguments array.
1247 var->set_maybe_assigned(); 1262 var->set_maybe_assigned();
1248 } 1263 }
1249 } 1264 }
1250 1265
1251
Dan Ehrenberg 2016/05/04 22:52:36 Nit: no need to delete the line
1252 void ParserTraits::AddParameterInitializationBlock( 1266 void ParserTraits::AddParameterInitializationBlock(
1253 const ParserFormalParameters& parameters, 1267 const ParserFormalParameters& parameters,
1254 ZoneList<v8::internal::Statement*>* body, bool* ok) { 1268 ZoneList<v8::internal::Statement*>* body, bool is_async, bool* ok) {
1255 if (!parameters.is_simple) { 1269 if (!parameters.is_simple) {
1256 auto* init_block = 1270 auto* init_block =
1257 parser_->BuildParameterInitializationBlock(parameters, ok); 1271 parser_->BuildParameterInitializationBlock(parameters, ok);
1258 if (!*ok) return; 1272 if (!*ok) return;
1273
1274 if (is_async) {
1275 init_block = parser_->BuildRejectPromiseOnException(init_block);
1276 }
1277
1259 if (init_block != nullptr) { 1278 if (init_block != nullptr) {
1260 body->Add(init_block, parser_->zone()); 1279 body->Add(init_block, parser_->zone());
1261 } 1280 }
1262 } 1281 }
1263 } 1282 }
1264 1283
1265 Expression* ParserTraits::ParseAsyncFunctionExpression(bool* ok) { 1284 Expression* ParserTraits::ParseAsyncFunctionExpression(bool* ok) {
1266 return parser_->ParseAsyncFunctionExpression(ok); 1285 return parser_->ParseAsyncFunctionExpression(ok);
1267 } 1286 }
1268 1287
1269 DoExpression* ParserTraits::ParseDoExpression(bool* ok) { 1288 DoExpression* ParserTraits::ParseDoExpression(bool* ok) {
1270 return parser_->ParseDoExpression(ok); 1289 return parser_->ParseDoExpression(ok);
1271 } 1290 }
1272 1291
1273 1292
1274 } // namespace internal 1293 } // namespace internal
1275 } // namespace v8 1294 } // namespace v8
1276 1295
1277 #endif // V8_PARSING_PARSER_H_ 1296 #endif // V8_PARSING_PARSER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698