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

Side by Side Diff: src/parser.cc

Issue 11031045: Reject uses of lexical for-loop variable on the RHS. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 2773 matching lines...) Expand 10 before | Expand all | Expand 10 after
2784 if (peek() == Token::VAR || peek() == Token::CONST) { 2784 if (peek() == Token::VAR || peek() == Token::CONST) {
2785 bool is_const = peek() == Token::CONST; 2785 bool is_const = peek() == Token::CONST;
2786 Handle<String> name; 2786 Handle<String> name;
2787 Block* variable_statement = 2787 Block* variable_statement =
2788 ParseVariableDeclarations(kForStatement, NULL, NULL, &name, CHECK_OK); 2788 ParseVariableDeclarations(kForStatement, NULL, NULL, &name, CHECK_OK);
2789 2789
2790 if (peek() == Token::IN && !name.is_null()) { 2790 if (peek() == Token::IN && !name.is_null()) {
2791 Interface* interface = 2791 Interface* interface =
2792 is_const ? Interface::NewConst() : Interface::NewValue(); 2792 is_const ? Interface::NewConst() : Interface::NewValue();
2793 VariableProxy* each = 2793 VariableProxy* each =
2794 top_scope_->NewUnresolved(factory(), name, interface); 2794 top_scope_->NewUnresolved(factory(), name, interface);
Michael Starzinger 2012/10/05 08:42:36 For consistency we could also move this loop varia
rossberg 2012/10/05 09:15:02 Done.
2795 ForInStatement* loop = factory()->NewForInStatement(labels); 2795 ForInStatement* loop = factory()->NewForInStatement(labels);
2796 Target target(&this->target_stack_, loop); 2796 Target target(&this->target_stack_, loop);
2797 2797
2798 Expect(Token::IN, CHECK_OK); 2798 Expect(Token::IN, CHECK_OK);
2799 Expression* enumerable = ParseExpression(true, CHECK_OK); 2799 Expression* enumerable = ParseExpression(true, CHECK_OK);
2800 Expect(Token::RPAREN, CHECK_OK); 2800 Expect(Token::RPAREN, CHECK_OK);
2801 2801
2802 Statement* body = ParseStatement(NULL, CHECK_OK); 2802 Statement* body = ParseStatement(NULL, CHECK_OK);
2803 loop->Initialize(each, enumerable, body); 2803 loop->Initialize(each, enumerable, body);
2804 Block* result = factory()->NewBlock(NULL, 2, false); 2804 Block* result = factory()->NewBlock(NULL, 2, false);
(...skipping 26 matching lines...) Expand all
2831 // for (x' in e) { 2831 // for (x' in e) {
2832 // let x; 2832 // let x;
2833 // x = x'; 2833 // x = x';
2834 // b; 2834 // b;
2835 // } 2835 // }
2836 2836
2837 // TODO(keuchel): Move the temporary variable to the block scope, after 2837 // TODO(keuchel): Move the temporary variable to the block scope, after
2838 // implementing stack allocated block scoped variables. 2838 // implementing stack allocated block scoped variables.
2839 Variable* temp = top_scope_->DeclarationScope()->NewTemporary(name); 2839 Variable* temp = top_scope_->DeclarationScope()->NewTemporary(name);
2840 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); 2840 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp);
2841 Interface* interface = Interface::NewValue(); 2841 Interface* interface = Interface::NewValue();
Michael Starzinger 2012/10/05 08:42:36 Can we also move the interface down right before t
rossberg 2012/10/05 09:15:02 Inlined instead.
2842 VariableProxy* each =
2843 top_scope_->NewUnresolved(factory(), name, interface);
2844 ForInStatement* loop = factory()->NewForInStatement(labels); 2842 ForInStatement* loop = factory()->NewForInStatement(labels);
2845 Target target(&this->target_stack_, loop); 2843 Target target(&this->target_stack_, loop);
2846 2844
2845 // The expression does not see the loop variable.
2847 Expect(Token::IN, CHECK_OK); 2846 Expect(Token::IN, CHECK_OK);
2847 top_scope_ = saved_scope;
2848 Expression* enumerable = ParseExpression(true, CHECK_OK); 2848 Expression* enumerable = ParseExpression(true, CHECK_OK);
2849 top_scope_ = for_scope;
2849 Expect(Token::RPAREN, CHECK_OK); 2850 Expect(Token::RPAREN, CHECK_OK);
2850 2851
2851 Statement* body = ParseStatement(NULL, CHECK_OK); 2852 Statement* body = ParseStatement(NULL, CHECK_OK);
2852 Block* body_block = factory()->NewBlock(NULL, 3, false); 2853 Block* body_block = factory()->NewBlock(NULL, 3, false);
2854 VariableProxy* each =
2855 top_scope_->NewUnresolved(factory(), name, interface);
2853 Assignment* assignment = factory()->NewAssignment( 2856 Assignment* assignment = factory()->NewAssignment(
2854 Token::ASSIGN, each, temp_proxy, RelocInfo::kNoPosition); 2857 Token::ASSIGN, each, temp_proxy, RelocInfo::kNoPosition);
2855 Statement* assignment_statement = 2858 Statement* assignment_statement =
2856 factory()->NewExpressionStatement(assignment); 2859 factory()->NewExpressionStatement(assignment);
2857 body_block->AddStatement(variable_statement, zone()); 2860 body_block->AddStatement(variable_statement, zone());
2858 body_block->AddStatement(assignment_statement, zone()); 2861 body_block->AddStatement(assignment_statement, zone());
2859 body_block->AddStatement(body, zone()); 2862 body_block->AddStatement(body, zone());
2860 loop->Initialize(temp_proxy, enumerable, body_block); 2863 loop->Initialize(temp_proxy, enumerable, body_block);
2861 top_scope_ = saved_scope; 2864 top_scope_ = saved_scope;
2862 for_scope->set_end_position(scanner().location().end_pos); 2865 for_scope->set_end_position(scanner().location().end_pos);
(...skipping 3105 matching lines...) Expand 10 before | Expand all | Expand 10 after
5968 ASSERT(info->isolate()->has_pending_exception()); 5971 ASSERT(info->isolate()->has_pending_exception());
5969 } else { 5972 } else {
5970 result = parser.ParseProgram(); 5973 result = parser.ParseProgram();
5971 } 5974 }
5972 } 5975 }
5973 info->SetFunction(result); 5976 info->SetFunction(result);
5974 return (result != NULL); 5977 return (result != NULL);
5975 } 5978 }
5976 5979
5977 } } // namespace v8::internal 5980 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-2322.js » ('j') | test/mjsunit/regress/regress-2322.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698