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

Side by Side Diff: src/parser.cc

Issue 1382123002: Ensure scopes are backed by blocks in the body of for loops (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: tests Created 5 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
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-536751.js » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/parser.h" 5 #include "src/parser.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast.h" 8 #include "src/ast.h"
9 #include "src/ast-literal-reindexer.h" 9 #include "src/ast-literal-reindexer.h"
10 #include "src/bailout-reason.h" 10 #include "src/bailout-reason.h"
(...skipping 3768 matching lines...) Expand 10 before | Expand all | Expand 10 after
3779 expression, lhs_beg_pos, lhs_end_pos, 3779 expression, lhs_beg_pos, lhs_end_pos,
3780 MessageTemplate::kInvalidLhsInFor, kSyntaxError, CHECK_OK); 3780 MessageTemplate::kInvalidLhsInFor, kSyntaxError, CHECK_OK);
3781 3781
3782 ForEachStatement* loop = 3782 ForEachStatement* loop =
3783 factory()->NewForEachStatement(mode, labels, stmt_pos); 3783 factory()->NewForEachStatement(mode, labels, stmt_pos);
3784 Target target(&this->target_stack_, loop); 3784 Target target(&this->target_stack_, loop);
3785 3785
3786 Expression* enumerable = ParseExpression(true, CHECK_OK); 3786 Expression* enumerable = ParseExpression(true, CHECK_OK);
3787 Expect(Token::RPAREN, CHECK_OK); 3787 Expect(Token::RPAREN, CHECK_OK);
3788 3788
3789 // Make a block around the statement in case a lexical binding
3790 // is introduced, e.g. by a FunctionDeclaration.
3791 Block* block =
3792 factory()->NewBlock(NULL, 1, false, RelocInfo::kNoPosition);
3789 Statement* body = ParseSubStatement(NULL, CHECK_OK); 3793 Statement* body = ParseSubStatement(NULL, CHECK_OK);
3790 InitializeForEachStatement(loop, expression, enumerable, body); 3794 block->statements()->Add(body, zone());
3795 InitializeForEachStatement(loop, expression, enumerable, block);
3791 scope_ = saved_scope; 3796 scope_ = saved_scope;
3792 for_scope->set_end_position(scanner()->location().end_pos); 3797 for_scope->set_end_position(scanner()->location().end_pos);
3793 for_scope = for_scope->FinalizeBlockScope(); 3798 for_scope = for_scope->FinalizeBlockScope();
3794 DCHECK(for_scope == NULL); 3799 if (for_scope != nullptr) {
3800 block->set_scope(for_scope);
3801 }
3795 // Parsed for-in loop. 3802 // Parsed for-in loop.
3796 return loop; 3803 return loop;
3797 3804
3798 } else { 3805 } else {
3799 init = factory()->NewExpressionStatement(expression, lhs_beg_pos); 3806 init = factory()->NewExpressionStatement(expression, lhs_beg_pos);
3800 } 3807 }
3801 } 3808 }
3802 } 3809 }
3803 3810
3804 // Standard 'for' loop 3811 // Standard 'for' loop
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
3854 if (for_scope) { 3861 if (for_scope) {
3855 // Rewrite a for statement of the form 3862 // Rewrite a for statement of the form
3856 // for (const x = i; c; n) b 3863 // for (const x = i; c; n) b
3857 // 3864 //
3858 // into 3865 // into
3859 // 3866 //
3860 // { 3867 // {
3861 // const x = i; 3868 // const x = i;
3862 // for (; c; n) b 3869 // for (; c; n) b
3863 // } 3870 // }
3864 DCHECK(init != NULL); 3871 //
3872 // or, desugar
3873 // for (; c; n) b
3874 // into
3875 // {
3876 // for (; c; n) b
3877 // }
3878 // just in case b introduces a lexical binding some other way, e.g., if b
3879 // is a FunctionDeclaration.
3865 Block* block = 3880 Block* block =
3866 factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition); 3881 factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition);
3867 block->statements()->Add(init, zone()); 3882 if (init != nullptr) {
3883 block->statements()->Add(init, zone());
3884 }
3868 block->statements()->Add(loop, zone()); 3885 block->statements()->Add(loop, zone());
3869 block->set_scope(for_scope); 3886 block->set_scope(for_scope);
3870 loop->Initialize(NULL, cond, next, body); 3887 loop->Initialize(NULL, cond, next, body);
3871 result = block; 3888 result = block;
3872 } else { 3889 } else {
3873 loop->Initialize(init, cond, next, body); 3890 loop->Initialize(init, cond, next, body);
3874 result = loop; 3891 result = loop;
3875 } 3892 }
3876 } 3893 }
3877 return result; 3894 return result;
(...skipping 2441 matching lines...) Expand 10 before | Expand all | Expand 10 after
6319 6336
6320 Expression* Parser::SpreadCallNew(Expression* function, 6337 Expression* Parser::SpreadCallNew(Expression* function,
6321 ZoneList<v8::internal::Expression*>* args, 6338 ZoneList<v8::internal::Expression*>* args,
6322 int pos) { 6339 int pos) {
6323 args->InsertAt(0, function, zone()); 6340 args->InsertAt(0, function, zone());
6324 6341
6325 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); 6342 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos);
6326 } 6343 }
6327 } // namespace internal 6344 } // namespace internal
6328 } // namespace v8 6345 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-536751.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698