Index: src/parser.cc |
diff --git a/src/parser.cc b/src/parser.cc |
index 35ed47b1298d7dd8677b3c13839f66ca5c2adfa5..c1681cfbd09da063960fedefac2572d059690a81 100644 |
--- a/src/parser.cc |
+++ b/src/parser.cc |
@@ -2158,6 +2158,20 @@ Statement* Parser::ParseReturnStatement(bool* ok) { |
// reported (underlining). |
Expect(Token::RETURN, CHECK_OK); |
+ Token::Value tok = peek(); |
+ Statement* result; |
+ if (scanner().HasAnyLineTerminatorBeforeNext() || |
+ tok == Token::SEMICOLON || |
+ tok == Token::RBRACE || |
+ tok == Token::EOS) { |
+ ExpectSemicolon(CHECK_OK); |
+ result = new(zone()) ReturnStatement(GetLiteralUndefined()); |
+ } else { |
+ Expression* expr = ParseExpression(true, CHECK_OK); |
+ ExpectSemicolon(CHECK_OK); |
+ result = new(zone()) ReturnStatement(expr); |
+ } |
+ |
// An ECMAScript program is considered syntactically incorrect if it |
// contains a return statement that is not within the body of a |
// function. See ECMA-262, section 12.9, page 67. |
@@ -2170,19 +2184,7 @@ Statement* Parser::ParseReturnStatement(bool* ok) { |
Expression* throw_error = NewThrowSyntaxError(type, Handle<Object>::null()); |
return new(zone()) ExpressionStatement(throw_error); |
} |
- |
- Token::Value tok = peek(); |
- if (scanner().HasAnyLineTerminatorBeforeNext() || |
- tok == Token::SEMICOLON || |
- tok == Token::RBRACE || |
- tok == Token::EOS) { |
- ExpectSemicolon(CHECK_OK); |
- return new(zone()) ReturnStatement(GetLiteralUndefined()); |
- } |
- |
- Expression* expr = ParseExpression(true, CHECK_OK); |
- ExpectSemicolon(CHECK_OK); |
- return new(zone()) ReturnStatement(expr); |
+ return result; |
} |