Index: src/parser.cc |
diff --git a/src/parser.cc b/src/parser.cc |
index b4ab623829b9657382ab58bcbe347ce4b31d3dff..2c0f3a6d08a11c70543630a279e89fb55b53e103 100644 |
--- a/src/parser.cc |
+++ b/src/parser.cc |
@@ -2510,16 +2510,24 @@ Statement* Parser::ParseReturnStatement(bool* ok) { |
Token::Value tok = peek(); |
Statement* result; |
+ Expression* return_value; |
if (scanner().HasAnyLineTerminatorBeforeNext() || |
tok == Token::SEMICOLON || |
tok == Token::RBRACE || |
tok == Token::EOS) { |
- ExpectSemicolon(CHECK_OK); |
- result = factory()->NewReturnStatement(GetLiteralUndefined()); |
+ return_value = GetLiteralUndefined(); |
} else { |
- Expression* expr = ParseExpression(true, CHECK_OK); |
- ExpectSemicolon(CHECK_OK); |
- result = factory()->NewReturnStatement(expr); |
+ return_value = ParseExpression(true, CHECK_OK); |
+ } |
+ ExpectSemicolon(CHECK_OK); |
+ if (is_generator()) { |
+ Expression* generator = factory()->NewVariableProxy( |
+ current_function_state_->generator_object_variable()); |
+ Expression* yield = factory()->NewYield( |
+ generator, return_value, Yield::FINAL, RelocInfo::kNoPosition); |
+ result = factory()->NewExpressionStatement(yield); |
+ } else { |
+ result = factory()->NewReturnStatement(return_value); |
} |
// An ECMAScript program is considered syntactically incorrect if it |
@@ -3099,12 +3107,12 @@ Expression* Parser::ParseYieldExpression(bool* ok) { |
// 'yield' '*'? AssignmentExpression |
int position = scanner().peek_location().beg_pos; |
Expect(Token::YIELD, CHECK_OK); |
- bool is_yield_star = Check(Token::MUL); |
+ Yield::Kind kind = |
+ Check(Token::MUL) ? Yield::DELEGATING : Yield::SUSPEND; |
Expression* generator_object = factory()->NewVariableProxy( |
current_function_state_->generator_object_variable()); |
Expression* expression = ParseAssignmentExpression(false, CHECK_OK); |
- return factory()->NewYield(generator_object, expression, is_yield_star, |
- position); |
+ return factory()->NewYield(generator_object, expression, kind, position); |
} |
@@ -4580,12 +4588,22 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> function_name, |
VariableProxy* get_proxy = factory()->NewVariableProxy( |
current_function_state_->generator_object_variable()); |
Yield* yield = factory()->NewYield( |
- get_proxy, assignment, false, RelocInfo::kNoPosition); |
+ get_proxy, assignment, Yield::INITIAL, RelocInfo::kNoPosition); |
body->Add(factory()->NewExpressionStatement(yield), zone()); |
} |
ParseSourceElements(body, Token::RBRACE, false, false, CHECK_OK); |
+ if (is_generator) { |
+ VariableProxy* get_proxy = factory()->NewVariableProxy( |
+ current_function_state_->generator_object_variable()); |
+ Expression *undefined = factory()->NewLiteral( |
+ isolate()->factory()->undefined_value()); |
+ Yield* yield = factory()->NewYield( |
+ get_proxy, undefined, Yield::FINAL, RelocInfo::kNoPosition); |
+ body->Add(factory()->NewExpressionStatement(yield), zone()); |
+ } |
+ |
materialized_literal_count = function_state.materialized_literal_count(); |
expected_property_count = function_state.expected_property_count(); |
handler_count = function_state.handler_count(); |