| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 2140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2151 | 2151 |
| 2152 Statement* Parser::ParseReturnStatement(bool* ok) { | 2152 Statement* Parser::ParseReturnStatement(bool* ok) { |
| 2153 // ReturnStatement :: | 2153 // ReturnStatement :: |
| 2154 // 'return' Expression? ';' | 2154 // 'return' Expression? ';' |
| 2155 | 2155 |
| 2156 // Consume the return token. It is necessary to do the before | 2156 // Consume the return token. It is necessary to do the before |
| 2157 // reporting any errors on it, because of the way errors are | 2157 // reporting any errors on it, because of the way errors are |
| 2158 // reported (underlining). | 2158 // reported (underlining). |
| 2159 Expect(Token::RETURN, CHECK_OK); | 2159 Expect(Token::RETURN, CHECK_OK); |
| 2160 | 2160 |
| 2161 Token::Value tok = peek(); |
| 2162 Statement* result; |
| 2163 if (scanner().HasAnyLineTerminatorBeforeNext() || |
| 2164 tok == Token::SEMICOLON || |
| 2165 tok == Token::RBRACE || |
| 2166 tok == Token::EOS) { |
| 2167 ExpectSemicolon(CHECK_OK); |
| 2168 result = new(zone()) ReturnStatement(GetLiteralUndefined()); |
| 2169 } else { |
| 2170 Expression* expr = ParseExpression(true, CHECK_OK); |
| 2171 ExpectSemicolon(CHECK_OK); |
| 2172 result = new(zone()) ReturnStatement(expr); |
| 2173 } |
| 2174 |
| 2161 // An ECMAScript program is considered syntactically incorrect if it | 2175 // An ECMAScript program is considered syntactically incorrect if it |
| 2162 // contains a return statement that is not within the body of a | 2176 // contains a return statement that is not within the body of a |
| 2163 // function. See ECMA-262, section 12.9, page 67. | 2177 // function. See ECMA-262, section 12.9, page 67. |
| 2164 // | 2178 // |
| 2165 // To be consistent with KJS we report the syntax error at runtime. | 2179 // To be consistent with KJS we report the syntax error at runtime. |
| 2166 Scope* declaration_scope = top_scope_->DeclarationScope(); | 2180 Scope* declaration_scope = top_scope_->DeclarationScope(); |
| 2167 if (declaration_scope->is_global_scope() || | 2181 if (declaration_scope->is_global_scope() || |
| 2168 declaration_scope->is_eval_scope()) { | 2182 declaration_scope->is_eval_scope()) { |
| 2169 Handle<String> type = isolate()->factory()->illegal_return_symbol(); | 2183 Handle<String> type = isolate()->factory()->illegal_return_symbol(); |
| 2170 Expression* throw_error = NewThrowSyntaxError(type, Handle<Object>::null()); | 2184 Expression* throw_error = NewThrowSyntaxError(type, Handle<Object>::null()); |
| 2171 return new(zone()) ExpressionStatement(throw_error); | 2185 return new(zone()) ExpressionStatement(throw_error); |
| 2172 } | 2186 } |
| 2173 | 2187 return result; |
| 2174 Token::Value tok = peek(); | |
| 2175 if (scanner().HasAnyLineTerminatorBeforeNext() || | |
| 2176 tok == Token::SEMICOLON || | |
| 2177 tok == Token::RBRACE || | |
| 2178 tok == Token::EOS) { | |
| 2179 ExpectSemicolon(CHECK_OK); | |
| 2180 return new(zone()) ReturnStatement(GetLiteralUndefined()); | |
| 2181 } | |
| 2182 | |
| 2183 Expression* expr = ParseExpression(true, CHECK_OK); | |
| 2184 ExpectSemicolon(CHECK_OK); | |
| 2185 return new(zone()) ReturnStatement(expr); | |
| 2186 } | 2188 } |
| 2187 | 2189 |
| 2188 | 2190 |
| 2189 Statement* Parser::ParseWithStatement(ZoneStringList* labels, bool* ok) { | 2191 Statement* Parser::ParseWithStatement(ZoneStringList* labels, bool* ok) { |
| 2190 // WithStatement :: | 2192 // WithStatement :: |
| 2191 // 'with' '(' Expression ')' Statement | 2193 // 'with' '(' Expression ')' Statement |
| 2192 | 2194 |
| 2193 Expect(Token::WITH, CHECK_OK); | 2195 Expect(Token::WITH, CHECK_OK); |
| 2194 | 2196 |
| 2195 if (!top_scope_->is_classic_mode()) { | 2197 if (!top_scope_->is_classic_mode()) { |
| (...skipping 3479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5675 ASSERT(info->isolate()->has_pending_exception()); | 5677 ASSERT(info->isolate()->has_pending_exception()); |
| 5676 } else { | 5678 } else { |
| 5677 result = parser.ParseProgram(info); | 5679 result = parser.ParseProgram(info); |
| 5678 } | 5680 } |
| 5679 } | 5681 } |
| 5680 info->SetFunction(result); | 5682 info->SetFunction(result); |
| 5681 return (result != NULL); | 5683 return (result != NULL); |
| 5682 } | 5684 } |
| 5683 | 5685 |
| 5684 } } // namespace v8::internal | 5686 } } // namespace v8::internal |
| OLD | NEW |