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

Side by Side Diff: src/preparser.cc

Issue 1423663006: [es7] Implement async functions parsing Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 1 month 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/preparser.h ('k') | src/runtime/runtime.h » ('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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 #include <cmath> 5 #include <cmath>
6 6
7 #include "src/allocation.h" 7 #include "src/allocation.h"
8 #include "src/base/logging.h" 8 #include "src/base/logging.h"
9 #include "src/conversions-inl.h" 9 #include "src/conversions-inl.h"
10 #include "src/conversions.h" 10 #include "src/conversions.h"
(...skipping 30 matching lines...) Expand all
41 return PreParserIdentifier::FutureReserved(); 41 return PreParserIdentifier::FutureReserved();
42 } else if (scanner->current_token() == 42 } else if (scanner->current_token() ==
43 Token::FUTURE_STRICT_RESERVED_WORD) { 43 Token::FUTURE_STRICT_RESERVED_WORD) {
44 return PreParserIdentifier::FutureStrictReserved(); 44 return PreParserIdentifier::FutureStrictReserved();
45 } else if (scanner->current_token() == Token::LET) { 45 } else if (scanner->current_token() == Token::LET) {
46 return PreParserIdentifier::Let(); 46 return PreParserIdentifier::Let();
47 } else if (scanner->current_token() == Token::STATIC) { 47 } else if (scanner->current_token() == Token::STATIC) {
48 return PreParserIdentifier::Static(); 48 return PreParserIdentifier::Static();
49 } else if (scanner->current_token() == Token::YIELD) { 49 } else if (scanner->current_token() == Token::YIELD) {
50 return PreParserIdentifier::Yield(); 50 return PreParserIdentifier::Yield();
51 } else if (scanner->current_token() == Token::ASYNC) {
52 return PreParserIdentifier::Async();
51 } 53 }
52 if (scanner->UnescapedLiteralMatches("eval", 4)) { 54 if (scanner->UnescapedLiteralMatches("eval", 4)) {
53 return PreParserIdentifier::Eval(); 55 return PreParserIdentifier::Eval();
54 } 56 }
55 if (scanner->UnescapedLiteralMatches("arguments", 9)) { 57 if (scanner->UnescapedLiteralMatches("arguments", 9)) {
56 return PreParserIdentifier::Arguments(); 58 return PreParserIdentifier::Arguments();
57 } 59 }
58 if (scanner->UnescapedLiteralMatches("undefined", 9)) { 60 if (scanner->UnescapedLiteralMatches("undefined", 9)) {
59 return PreParserIdentifier::Undefined(); 61 return PreParserIdentifier::Undefined();
60 } 62 }
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 // HoistableDeclaration[Yield, Default] : 185 // HoistableDeclaration[Yield, Default] :
184 // FunctionDeclaration[?Yield, ?Default] 186 // FunctionDeclaration[?Yield, ?Default]
185 // GeneratorDeclaration[?Yield, ?Default] 187 // GeneratorDeclaration[?Yield, ?Default]
186 // 188 //
187 // LexicalDeclaration[In, Yield] : 189 // LexicalDeclaration[In, Yield] :
188 // LetOrConst BindingList[?In, ?Yield] ; 190 // LetOrConst BindingList[?In, ?Yield] ;
189 191
190 switch (peek()) { 192 switch (peek()) {
191 case Token::FUNCTION: 193 case Token::FUNCTION:
192 return ParseFunctionDeclaration(ok); 194 return ParseFunctionDeclaration(ok);
195 case Token::ASYNC:
196 if (IsNextAsyncFunctionKeyword()) {
197 return ParseFunctionDeclaration(ok);
198 }
199 break;
193 case Token::CLASS: 200 case Token::CLASS:
194 return ParseClassDeclaration(ok); 201 return ParseClassDeclaration(ok);
195 case Token::CONST: 202 case Token::CONST:
196 if (allow_const()) { 203 if (allow_const()) {
197 return ParseVariableStatement(kStatementListItem, ok); 204 return ParseVariableStatement(kStatementListItem, ok);
198 } 205 }
199 break; 206 break;
200 case Token::LET: 207 case Token::LET:
201 if (IsNextLetKeyword()) { 208 if (IsNextLetKeyword()) {
202 return ParseVariableStatement(kStatementListItem, ok); 209 return ParseVariableStatement(kStatementListItem, ok);
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 397
391 case Token::SWITCH: 398 case Token::SWITCH:
392 return ParseSwitchStatement(ok); 399 return ParseSwitchStatement(ok);
393 400
394 case Token::THROW: 401 case Token::THROW:
395 return ParseThrowStatement(ok); 402 return ParseThrowStatement(ok);
396 403
397 case Token::TRY: 404 case Token::TRY:
398 return ParseTryStatement(ok); 405 return ParseTryStatement(ok);
399 406
407 case Token::ASYNC:
408 // Make sure async keyword is followed by a function keyword,
409 // otherwise parse 'async' as part of an expression or
410 // labelled statement (default case in this switch).
411 if (!allow_harmony_async_await() || !IsNextAsyncFunctionKeyword()) {
412 return ParseExpressionOrLabelledStatement(ok);
413 }
414
415 // Fall through.
400 case Token::FUNCTION: { 416 case Token::FUNCTION: {
401 Scanner::Location start_location = scanner()->peek_location(); 417 Scanner::Location start_location = scanner()->peek_location();
402 Statement statement = ParseFunctionDeclaration(CHECK_OK); 418 Statement statement = ParseFunctionDeclaration(CHECK_OK);
403 Scanner::Location end_location = scanner()->location(); 419 Scanner::Location end_location = scanner()->location();
404 if (is_strict(language_mode())) { 420 if (is_strict(language_mode())) {
405 PreParserTraits::ReportMessageAt(start_location.beg_pos, 421 PreParserTraits::ReportMessageAt(start_location.beg_pos,
406 end_location.end_pos, 422 end_location.end_pos,
407 MessageTemplate::kStrictFunction); 423 MessageTemplate::kStrictFunction);
408 *ok = false; 424 *ok = false;
409 return Statement::Default(); 425 return Statement::Default();
(...skipping 19 matching lines...) Expand all
429 // Fall through. 445 // Fall through.
430 default: 446 default:
431 return ParseExpressionOrLabelledStatement(ok); 447 return ParseExpressionOrLabelledStatement(ok);
432 } 448 }
433 } 449 }
434 450
435 451
436 PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) { 452 PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) {
437 // FunctionDeclaration :: 453 // FunctionDeclaration ::
438 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}' 454 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}'
455 // AsyncFunctionDeclaration ::
456 // 'async' 'function' Identifier '(' FormalParameterListopt ')'
457 // '{' FunctionBody '}'
439 // GeneratorDeclaration :: 458 // GeneratorDeclaration ::
440 // 'function' '*' Identifier '(' FormalParameterListopt ')' 459 // 'function' '*' Identifier '(' FormalParameterListopt ')'
441 // '{' FunctionBody '}' 460 // '{' FunctionBody '}'
461 bool is_async = allow_harmony_async_await() ? Check(Token::ASYNC) : false;
442 Expect(Token::FUNCTION, CHECK_OK); 462 Expect(Token::FUNCTION, CHECK_OK);
443 int pos = position(); 463 int pos = position();
444 bool is_generator = Check(Token::MUL); 464 bool is_generator = is_async ? false : Check(Token::MUL);
445 bool is_strict_reserved = false; 465 bool is_strict_reserved = false;
446 Identifier name = ParseIdentifierOrStrictReservedWord( 466 Identifier name = ParseIdentifierOrStrictReservedWord(
447 &is_strict_reserved, CHECK_OK); 467 &is_strict_reserved, CHECK_OK);
468
469 FunctionKind kind = FunctionKind::kNormalFunction;
470 if (is_generator) {
471 kind = FunctionKind::kGeneratorFunction;
472 } else if (is_async) {
473 kind = FunctionKind::kAsyncFunction;
474 }
475
448 ParseFunctionLiteral(name, scanner()->location(), 476 ParseFunctionLiteral(name, scanner()->location(),
449 is_strict_reserved ? kFunctionNameIsStrictReserved 477 is_strict_reserved ? kFunctionNameIsStrictReserved
450 : kFunctionNameValidityUnknown, 478 : kFunctionNameValidityUnknown,
451 is_generator ? FunctionKind::kGeneratorFunction 479 kind, pos, FunctionLiteral::DECLARATION,
452 : FunctionKind::kNormalFunction,
453 pos, FunctionLiteral::DECLARATION,
454 FunctionLiteral::NORMAL_ARITY, language_mode(), 480 FunctionLiteral::NORMAL_ARITY, language_mode(),
455 CHECK_OK); 481 CHECK_OK);
456 return Statement::FunctionDeclaration(); 482 return Statement::FunctionDeclaration();
457 } 483 }
458 484
459 485
460 PreParser::Statement PreParser::ParseClassDeclaration(bool* ok) { 486 PreParser::Statement PreParser::ParseClassDeclaration(bool* ok) {
461 Expect(Token::CLASS, CHECK_OK); 487 Expect(Token::CLASS, CHECK_OK);
462 if (!allow_harmony_sloppy() && is_sloppy(language_mode())) { 488 if (!allow_harmony_sloppy() && is_sloppy(language_mode())) {
463 ReportMessage(MessageTemplate::kSloppyLexical); 489 ReportMessage(MessageTemplate::kSloppyLexical);
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after
1254 Expect(Token::RBRACE, CHECK_OK); 1280 Expect(Token::RBRACE, CHECK_OK);
1255 return PreParserExpression::Default(); 1281 return PreParserExpression::Default();
1256 } 1282 }
1257 } 1283 }
1258 1284
1259 #undef CHECK_OK 1285 #undef CHECK_OK
1260 1286
1261 1287
1262 } // namespace internal 1288 } // namespace internal
1263 } // namespace v8 1289 } // namespace v8
OLDNEW
« no previous file with comments | « src/preparser.h ('k') | src/runtime/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698