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

Side by Side Diff: src/parser.cc

Issue 8847007: Merge r10201 to 3.6 branch: Sync parser and preparser on do-while and return statements. (Closed) Base URL: https://v8.googlecode.com/svn/branches/3.6
Patch Set: Created 9 years 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | src/preparser.cc » ('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 // 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 2018 matching lines...) Expand 10 before | Expand all | Expand 10 after
2029 2029
2030 Statement* Parser::ParseReturnStatement(bool* ok) { 2030 Statement* Parser::ParseReturnStatement(bool* ok) {
2031 // ReturnStatement :: 2031 // ReturnStatement ::
2032 // 'return' Expression? ';' 2032 // 'return' Expression? ';'
2033 2033
2034 // Consume the return token. It is necessary to do the before 2034 // Consume the return token. It is necessary to do the before
2035 // reporting any errors on it, because of the way errors are 2035 // reporting any errors on it, because of the way errors are
2036 // reported (underlining). 2036 // reported (underlining).
2037 Expect(Token::RETURN, CHECK_OK); 2037 Expect(Token::RETURN, CHECK_OK);
2038 2038
2039 Token::Value tok = peek();
2040 Statement* result;
2041 if (scanner().HasAnyLineTerminatorBeforeNext() ||
2042 tok == Token::SEMICOLON ||
2043 tok == Token::RBRACE ||
2044 tok == Token::EOS) {
2045 ExpectSemicolon(CHECK_OK);
2046 result = new(zone()) ReturnStatement(GetLiteralUndefined());
2047 } else {
2048 Expression* expr = ParseExpression(true, CHECK_OK);
2049 ExpectSemicolon(CHECK_OK);
2050 result = new(zone()) ReturnStatement(expr);
2051 }
2052
2039 // An ECMAScript program is considered syntactically incorrect if it 2053 // An ECMAScript program is considered syntactically incorrect if it
2040 // contains a return statement that is not within the body of a 2054 // contains a return statement that is not within the body of a
2041 // function. See ECMA-262, section 12.9, page 67. 2055 // function. See ECMA-262, section 12.9, page 67.
2042 // 2056 //
2043 // To be consistent with KJS we report the syntax error at runtime. 2057 // To be consistent with KJS we report the syntax error at runtime.
2044 Scope* declaration_scope = top_scope_->DeclarationScope(); 2058 Scope* declaration_scope = top_scope_->DeclarationScope();
2045 if (declaration_scope->is_global_scope() || 2059 if (declaration_scope->is_global_scope() ||
2046 declaration_scope->is_eval_scope()) { 2060 declaration_scope->is_eval_scope()) {
2047 Handle<String> type = isolate()->factory()->illegal_return_symbol(); 2061 Handle<String> type = isolate()->factory()->illegal_return_symbol();
2048 Expression* throw_error = NewThrowSyntaxError(type, Handle<Object>::null()); 2062 Expression* throw_error = NewThrowSyntaxError(type, Handle<Object>::null());
2049 return new(zone()) ExpressionStatement(throw_error); 2063 return new(zone()) ExpressionStatement(throw_error);
2050 } 2064 }
2051 2065 return result;
2052 Token::Value tok = peek();
2053 if (scanner().HasAnyLineTerminatorBeforeNext() ||
2054 tok == Token::SEMICOLON ||
2055 tok == Token::RBRACE ||
2056 tok == Token::EOS) {
2057 ExpectSemicolon(CHECK_OK);
2058 return new(zone()) ReturnStatement(GetLiteralUndefined());
2059 }
2060
2061 Expression* expr = ParseExpression(true, CHECK_OK);
2062 ExpectSemicolon(CHECK_OK);
2063 return new(zone()) ReturnStatement(expr);
2064 } 2066 }
2065 2067
2066 2068
2067 Statement* Parser::ParseWithStatement(ZoneStringList* labels, bool* ok) { 2069 Statement* Parser::ParseWithStatement(ZoneStringList* labels, bool* ok) {
2068 // WithStatement :: 2070 // WithStatement ::
2069 // 'with' '(' Expression ')' Statement 2071 // 'with' '(' Expression ')' Statement
2070 2072
2071 Expect(Token::WITH, CHECK_OK); 2073 Expect(Token::WITH, CHECK_OK);
2072 2074
2073 if (top_scope_->is_strict_mode()) { 2075 if (top_scope_->is_strict_mode()) {
(...skipping 3156 matching lines...) Expand 10 before | Expand all | Expand 10 after
5230 result = parser.ParseProgram(source, 5232 result = parser.ParseProgram(source,
5231 info->is_global(), 5233 info->is_global(),
5232 info->StrictMode()); 5234 info->StrictMode());
5233 } 5235 }
5234 } 5236 }
5235 info->SetFunction(result); 5237 info->SetFunction(result);
5236 return (result != NULL); 5238 return (result != NULL);
5237 } 5239 }
5238 5240
5239 } } // namespace v8::internal 5241 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698