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

Side by Side Diff: src/parser.cc

Issue 1250513004: [es6] Make sure temporaries are not allocated in block scope (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 5 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 | « src/globals.h ('k') | src/pattern-rewriter.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 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/v8.h" 5 #include "src/v8.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 2809 matching lines...) Expand 10 before | Expand all | Expand 10 after
2820 if (IsSubclassConstructor(function_state_->kind())) { 2820 if (IsSubclassConstructor(function_state_->kind())) {
2821 // For subclass constructors we need to return this in case of undefined 2821 // For subclass constructors we need to return this in case of undefined
2822 // and throw an exception in case of a non object. 2822 // and throw an exception in case of a non object.
2823 // 2823 //
2824 // return expr; 2824 // return expr;
2825 // 2825 //
2826 // Is rewritten as: 2826 // Is rewritten as:
2827 // 2827 //
2828 // return (temp = expr) === undefined ? this : 2828 // return (temp = expr) === undefined ? this :
2829 // %_IsSpecObject(temp) ? temp : throw new TypeError(...); 2829 // %_IsSpecObject(temp) ? temp : throw new TypeError(...);
2830 Variable* temp = scope_->DeclarationScope()->NewTemporary( 2830 Variable* temp = scope_->NewTemporary(
2831 ast_value_factory()->empty_string()); 2831 ast_value_factory()->empty_string());
2832 Assignment* assign = factory()->NewAssignment( 2832 Assignment* assign = factory()->NewAssignment(
2833 Token::ASSIGN, factory()->NewVariableProxy(temp), return_value, pos); 2833 Token::ASSIGN, factory()->NewVariableProxy(temp), return_value, pos);
2834 2834
2835 Expression* throw_expression = 2835 Expression* throw_expression =
2836 NewThrowTypeError(MessageTemplate::kDerivedConstructorReturn, 2836 NewThrowTypeError(MessageTemplate::kDerivedConstructorReturn,
2837 ast_value_factory()->empty_string(), pos); 2837 ast_value_factory()->empty_string(), pos);
2838 2838
2839 // %_IsSpecObject(temp) 2839 // %_IsSpecObject(temp)
2840 ZoneList<Expression*>* is_spec_object_args = 2840 ZoneList<Expression*>* is_spec_object_args =
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
3174 } 3174 }
3175 3175
3176 3176
3177 void Parser::InitializeForEachStatement(ForEachStatement* stmt, 3177 void Parser::InitializeForEachStatement(ForEachStatement* stmt,
3178 Expression* each, 3178 Expression* each,
3179 Expression* subject, 3179 Expression* subject,
3180 Statement* body) { 3180 Statement* body) {
3181 ForOfStatement* for_of = stmt->AsForOfStatement(); 3181 ForOfStatement* for_of = stmt->AsForOfStatement();
3182 3182
3183 if (for_of != NULL) { 3183 if (for_of != NULL) {
3184 Variable* iterator = scope_->DeclarationScope()->NewTemporary( 3184 Variable* iterator = scope_->NewTemporary(
3185 ast_value_factory()->dot_iterator_string()); 3185 ast_value_factory()->dot_iterator_string());
3186 Variable* result = scope_->DeclarationScope()->NewTemporary( 3186 Variable* result = scope_->NewTemporary(
3187 ast_value_factory()->dot_result_string()); 3187 ast_value_factory()->dot_result_string());
3188 3188
3189 Expression* assign_iterator; 3189 Expression* assign_iterator;
3190 Expression* next_result; 3190 Expression* next_result;
3191 Expression* result_done; 3191 Expression* result_done;
3192 Expression* assign_each; 3192 Expression* assign_each;
3193 3193
3194 // iterator = subject[Symbol.iterator]() 3194 // iterator = subject[Symbol.iterator]()
3195 assign_iterator = factory()->NewAssignment( 3195 assign_iterator = factory()->NewAssignment(
3196 Token::ASSIGN, factory()->NewVariableProxy(iterator), 3196 Token::ASSIGN, factory()->NewVariableProxy(iterator),
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
3292 3292
3293 // Add statement: let/const x = i. 3293 // Add statement: let/const x = i.
3294 outer_block->AddStatement(init, zone()); 3294 outer_block->AddStatement(init, zone());
3295 3295
3296 const AstRawString* temp_name = ast_value_factory()->dot_for_string(); 3296 const AstRawString* temp_name = ast_value_factory()->dot_for_string();
3297 3297
3298 // For each lexical variable x: 3298 // For each lexical variable x:
3299 // make statement: temp_x = x. 3299 // make statement: temp_x = x.
3300 for (int i = 0; i < names->length(); i++) { 3300 for (int i = 0; i < names->length(); i++) {
3301 VariableProxy* proxy = NewUnresolved(names->at(i), LET); 3301 VariableProxy* proxy = NewUnresolved(names->at(i), LET);
3302 Variable* temp = scope_->DeclarationScope()->NewTemporary(temp_name); 3302 Variable* temp = scope_->NewTemporary(temp_name);
3303 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); 3303 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp);
3304 Assignment* assignment = factory()->NewAssignment( 3304 Assignment* assignment = factory()->NewAssignment(
3305 Token::ASSIGN, temp_proxy, proxy, RelocInfo::kNoPosition); 3305 Token::ASSIGN, temp_proxy, proxy, RelocInfo::kNoPosition);
3306 Statement* assignment_statement = factory()->NewExpressionStatement( 3306 Statement* assignment_statement = factory()->NewExpressionStatement(
3307 assignment, RelocInfo::kNoPosition); 3307 assignment, RelocInfo::kNoPosition);
3308 outer_block->AddStatement(assignment_statement, zone()); 3308 outer_block->AddStatement(assignment_statement, zone());
3309 temps.Add(temp, zone()); 3309 temps.Add(temp, zone());
3310 } 3310 }
3311 3311
3312 Variable* first = NULL; 3312 Variable* first = NULL;
3313 // Make statement: first = 1. 3313 // Make statement: first = 1.
3314 if (next) { 3314 if (next) {
3315 first = scope_->DeclarationScope()->NewTemporary(temp_name); 3315 first = scope_->NewTemporary(temp_name);
3316 VariableProxy* first_proxy = factory()->NewVariableProxy(first); 3316 VariableProxy* first_proxy = factory()->NewVariableProxy(first);
3317 Expression* const1 = factory()->NewSmiLiteral(1, RelocInfo::kNoPosition); 3317 Expression* const1 = factory()->NewSmiLiteral(1, RelocInfo::kNoPosition);
3318 Assignment* assignment = factory()->NewAssignment( 3318 Assignment* assignment = factory()->NewAssignment(
3319 Token::ASSIGN, first_proxy, const1, RelocInfo::kNoPosition); 3319 Token::ASSIGN, first_proxy, const1, RelocInfo::kNoPosition);
3320 Statement* assignment_statement = 3320 Statement* assignment_statement =
3321 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition); 3321 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition);
3322 outer_block->AddStatement(assignment_statement, zone()); 3322 outer_block->AddStatement(assignment_statement, zone());
3323 } 3323 }
3324 3324
3325 // make statement: undefined; 3325 // make statement: undefined;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
3385 Assignment* assignment = factory()->NewAssignment( 3385 Assignment* assignment = factory()->NewAssignment(
3386 Token::ASSIGN, first_proxy, const0, RelocInfo::kNoPosition); 3386 Token::ASSIGN, first_proxy, const0, RelocInfo::kNoPosition);
3387 clear_first = 3387 clear_first =
3388 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition); 3388 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition);
3389 } 3389 }
3390 Statement* clear_first_or_next = factory()->NewIfStatement( 3390 Statement* clear_first_or_next = factory()->NewIfStatement(
3391 compare, clear_first, next, RelocInfo::kNoPosition); 3391 compare, clear_first, next, RelocInfo::kNoPosition);
3392 ignore_completion_block->AddStatement(clear_first_or_next, zone()); 3392 ignore_completion_block->AddStatement(clear_first_or_next, zone());
3393 } 3393 }
3394 3394
3395 Variable* flag = scope_->DeclarationScope()->NewTemporary(temp_name); 3395 Variable* flag = scope_->NewTemporary(temp_name);
3396 // Make statement: flag = 1. 3396 // Make statement: flag = 1.
3397 { 3397 {
3398 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); 3398 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag);
3399 Expression* const1 = factory()->NewSmiLiteral(1, RelocInfo::kNoPosition); 3399 Expression* const1 = factory()->NewSmiLiteral(1, RelocInfo::kNoPosition);
3400 Assignment* assignment = factory()->NewAssignment( 3400 Assignment* assignment = factory()->NewAssignment(
3401 Token::ASSIGN, flag_proxy, const1, RelocInfo::kNoPosition); 3401 Token::ASSIGN, flag_proxy, const1, RelocInfo::kNoPosition);
3402 Statement* assignment_statement = 3402 Statement* assignment_statement =
3403 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition); 3403 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition);
3404 ignore_completion_block->AddStatement(assignment_statement, zone()); 3404 ignore_completion_block->AddStatement(assignment_statement, zone());
3405 } 3405 }
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
3571 // { 3571 // {
3572 // <let x' be a temporary variable> 3572 // <let x' be a temporary variable>
3573 // for (x' in/of e) { 3573 // for (x' in/of e) {
3574 // let/const/var x; 3574 // let/const/var x;
3575 // x = x'; 3575 // x = x';
3576 // b; 3576 // b;
3577 // } 3577 // }
3578 // let x; // for TDZ 3578 // let x; // for TDZ
3579 // } 3579 // }
3580 3580
3581 Variable* temp = scope_->DeclarationScope()->NewTemporary( 3581 Variable* temp = scope_->NewTemporary(
3582 ast_value_factory()->dot_for_string()); 3582 ast_value_factory()->dot_for_string());
3583 ForEachStatement* loop = 3583 ForEachStatement* loop =
3584 factory()->NewForEachStatement(mode, labels, stmt_pos); 3584 factory()->NewForEachStatement(mode, labels, stmt_pos);
3585 Target target(&this->target_stack_, loop); 3585 Target target(&this->target_stack_, loop);
3586 3586
3587 Expression* enumerable = ParseExpression(true, CHECK_OK); 3587 Expression* enumerable = ParseExpression(true, CHECK_OK);
3588 3588
3589 Expect(Token::RPAREN, CHECK_OK); 3589 Expect(Token::RPAREN, CHECK_OK);
3590 3590
3591 Scope* body_scope = NewScope(scope_, BLOCK_SCOPE); 3591 Scope* body_scope = NewScope(scope_, BLOCK_SCOPE);
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
4000 4000
4001 if (is_generator) { 4001 if (is_generator) {
4002 // For generators, allocating variables in contexts is currently a win 4002 // For generators, allocating variables in contexts is currently a win
4003 // because it minimizes the work needed to suspend and resume an 4003 // because it minimizes the work needed to suspend and resume an
4004 // activation. 4004 // activation.
4005 scope_->ForceContextAllocation(); 4005 scope_->ForceContextAllocation();
4006 4006
4007 // Calling a generator returns a generator object. That object is stored 4007 // Calling a generator returns a generator object. That object is stored
4008 // in a temporary variable, a definition that is used by "yield" 4008 // in a temporary variable, a definition that is used by "yield"
4009 // expressions. This also marks the FunctionState as a generator. 4009 // expressions. This also marks the FunctionState as a generator.
4010 Variable* temp = scope_->DeclarationScope()->NewTemporary( 4010 Variable* temp = scope_->NewTemporary(
4011 ast_value_factory()->dot_generator_object_string()); 4011 ast_value_factory()->dot_generator_object_string());
4012 function_state.set_generator_object_variable(temp); 4012 function_state.set_generator_object_variable(temp);
4013 } 4013 }
4014 4014
4015 Expect(Token::LPAREN, CHECK_OK); 4015 Expect(Token::LPAREN, CHECK_OK);
4016 int start_position = scanner()->location().beg_pos; 4016 int start_position = scanner()->location().beg_pos;
4017 scope_->set_start_position(start_position); 4017 scope_->set_start_position(start_position);
4018 ParserFormalParameters formals(scope); 4018 ParserFormalParameters formals(scope);
4019 arity = ParseFormalParameterList(&formals, &formals_classifier, CHECK_OK); 4019 arity = ParseFormalParameterList(&formals, &formals_classifier, CHECK_OK);
4020 Expect(Token::RPAREN, CHECK_OK); 4020 Expect(Token::RPAREN, CHECK_OK);
(...skipping 1962 matching lines...) Expand 10 before | Expand all | Expand 10 after
5983 Expression* Parser::SpreadCallNew(Expression* function, 5983 Expression* Parser::SpreadCallNew(Expression* function,
5984 ZoneList<v8::internal::Expression*>* args, 5984 ZoneList<v8::internal::Expression*>* args,
5985 int pos) { 5985 int pos) {
5986 args->InsertAt(0, function, zone()); 5986 args->InsertAt(0, function, zone());
5987 5987
5988 return factory()->NewCallRuntime( 5988 return factory()->NewCallRuntime(
5989 ast_value_factory()->reflect_construct_string(), NULL, args, pos); 5989 ast_value_factory()->reflect_construct_string(), NULL, args, pos);
5990 } 5990 }
5991 } // namespace internal 5991 } // namespace internal
5992 } // namespace v8 5992 } // namespace v8
OLDNEW
« no previous file with comments | « src/globals.h ('k') | src/pattern-rewriter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698