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

Unified Diff: src/preparser.h

Issue 348893007: Allow yield expressions without a RHS. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Update tests, fix function* () { yield* } Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/ast.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index 67990872c95a695d788b15273d13174f8cdc9f4e..d6be902713dc578af4e0f1e854736508db7b70b3 100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -1792,15 +1792,36 @@ template <class Traits>
typename ParserBase<Traits>::ExpressionT
ParserBase<Traits>::ParseYieldExpression(bool* ok) {
// YieldExpression ::
- // 'yield' '*'? AssignmentExpression
+ // 'yield' ([no line terminator] '*'? AssignmentExpression)?
int pos = peek_position();
Expect(Token::YIELD, CHECK_OK);
- Yield::Kind kind =
- Check(Token::MUL) ? Yield::DELEGATING : Yield::SUSPEND;
ExpressionT generator_object =
factory()->NewVariableProxy(function_state_->generator_object_variable());
- ExpressionT expression =
- ParseAssignmentExpression(false, CHECK_OK);
+ ExpressionT expression = Traits::EmptyExpression();
+ Yield::Kind kind = Yield::SUSPEND;
+ if (!scanner()->HasAnyLineTerminatorBeforeNext()) {
+ if (Check(Token::MUL)) kind = Yield::DELEGATING;
+ switch (peek()) {
+ case Token::EOS:
+ case Token::SEMICOLON:
+ case Token::RBRACE:
+ case Token::RBRACK:
+ case Token::RPAREN:
+ case Token::COLON:
+ case Token::COMMA:
+ // The above set of tokens is the complete set of tokens that can appear
+ // after an AssignmentExpression, and none of them can start an
+ // AssignmentExpression. This allows us to avoid looking for an RHS for
+ // a Yield::SUSPEND operation, given only one look-ahead token.
+ if (kind == Yield::SUSPEND)
+ break;
+ ASSERT(kind == Yield::DELEGATING);
+ // Delegating yields require an RHS; fall through.
+ default:
+ expression = ParseAssignmentExpression(false, CHECK_OK);
+ break;
+ }
+ }
typename Traits::Type::YieldExpression yield =
factory()->NewYield(generator_object, expression, kind, pos);
if (kind == Yield::DELEGATING) {
« no previous file with comments | « src/ast.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698