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

Side by Side Diff: src/parser.cc

Issue 1404803002: Add a lexical scope for the body of a with statement (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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-542100.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 2938 matching lines...) Expand 10 before | Expand all | Expand 10 after
2949 *ok = false; 2949 *ok = false;
2950 return NULL; 2950 return NULL;
2951 } 2951 }
2952 2952
2953 Expect(Token::LPAREN, CHECK_OK); 2953 Expect(Token::LPAREN, CHECK_OK);
2954 Expression* expr = ParseExpression(true, CHECK_OK); 2954 Expression* expr = ParseExpression(true, CHECK_OK);
2955 Expect(Token::RPAREN, CHECK_OK); 2955 Expect(Token::RPAREN, CHECK_OK);
2956 2956
2957 scope_->DeclarationScope()->RecordWithStatement(); 2957 scope_->DeclarationScope()->RecordWithStatement();
2958 Scope* with_scope = NewScope(scope_, WITH_SCOPE); 2958 Scope* with_scope = NewScope(scope_, WITH_SCOPE);
2959 Statement* stmt; 2959 Block* body;
2960 { BlockState block_state(&scope_, with_scope); 2960 { BlockState block_state(&scope_, with_scope);
2961 with_scope->set_start_position(scanner()->peek_location().beg_pos); 2961 with_scope->set_start_position(scanner()->peek_location().beg_pos);
2962 stmt = ParseSubStatement(labels, CHECK_OK); 2962
2963 // The body of the with statement must be enclosed in an additional
2964 // lexical scope in case the body is a FunctionDeclaration.
2965 body = factory()->NewBlock(labels, 1, false, RelocInfo::kNoPosition);
2966 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE);
2967 block_scope->set_start_position(scanner()->location().beg_pos);
2968 {
2969 BlockState block_state(&scope_, block_scope);
2970 Target target(&this->target_stack_, body);
2971 Statement* stmt = ParseSubStatement(labels, CHECK_OK);
2972 body->statements()->Add(stmt, zone());
2973 block_scope->set_end_position(scanner()->location().end_pos);
2974 block_scope = block_scope->FinalizeBlockScope();
2975 body->set_scope(block_scope);
2976 }
2977
2963 with_scope->set_end_position(scanner()->location().end_pos); 2978 with_scope->set_end_position(scanner()->location().end_pos);
2964 } 2979 }
2965 return factory()->NewWithStatement(with_scope, expr, stmt, pos); 2980 return factory()->NewWithStatement(with_scope, expr, body, pos);
2966 } 2981 }
2967 2982
2968 2983
2969 CaseClause* Parser::ParseCaseClause(bool* default_seen_ptr, bool* ok) { 2984 CaseClause* Parser::ParseCaseClause(bool* default_seen_ptr, bool* ok) {
2970 // CaseClause :: 2985 // CaseClause ::
2971 // 'case' Expression ':' StatementList 2986 // 'case' Expression ':' StatementList
2972 // 'default' ':' StatementList 2987 // 'default' ':' StatementList
2973 2988
2974 Expression* label = NULL; // NULL expression indicates default case 2989 Expression* label = NULL; // NULL expression indicates default case
2975 if (peek() == Token::CASE) { 2990 if (peek() == Token::CASE) {
(...skipping 3361 matching lines...) Expand 10 before | Expand all | Expand 10 after
6337 6352
6338 Expression* Parser::SpreadCallNew(Expression* function, 6353 Expression* Parser::SpreadCallNew(Expression* function,
6339 ZoneList<v8::internal::Expression*>* args, 6354 ZoneList<v8::internal::Expression*>* args,
6340 int pos) { 6355 int pos) {
6341 args->InsertAt(0, function, zone()); 6356 args->InsertAt(0, function, zone());
6342 6357
6343 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); 6358 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos);
6344 } 6359 }
6345 } // namespace internal 6360 } // namespace internal
6346 } // namespace v8 6361 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-542100.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698