Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/parsing/rewriter.h" | 5 #include "src/parsing/rewriter.h" |
| 6 | 6 |
| 7 #include "src/ast/ast.h" | 7 #include "src/ast/ast.h" |
| 8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
| 9 #include "src/parsing/parser.h" | 9 #include "src/parsing/parser.h" |
| 10 | 10 |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 355 processor.factory()->NewVariableProxy(result, pos); | 355 processor.factory()->NewVariableProxy(result, pos); |
| 356 Statement* result_statement = | 356 Statement* result_statement = |
| 357 processor.factory()->NewReturnStatement(result_proxy, pos); | 357 processor.factory()->NewReturnStatement(result_proxy, pos); |
| 358 body->Add(result_statement, info->zone()); | 358 body->Add(result_statement, info->zone()); |
| 359 } | 359 } |
| 360 } | 360 } |
| 361 | 361 |
| 362 return true; | 362 return true; |
| 363 } | 363 } |
| 364 | 364 |
| 365 | 365 bool Rewriter::Rewrite(Parser* parser, Scope* outer_scope, DoExpression* expr, |
| 366 bool Rewriter::Rewrite(Parser* parser, DoExpression* expr, | |
| 367 AstValueFactory* factory) { | 366 AstValueFactory* factory) { |
| 368 Block* block = expr->block(); | 367 Block* block = expr->block(); |
| 369 Scope* scope = block->scope(); | 368 Scope* scope = block->scope() == nullptr ? outer_scope : block->scope(); |
|
adamk
2016/07/21 17:15:41
Why should we ever use the block scope here? By yo
| |
| 370 ZoneList<Statement*>* body = block->statements(); | 369 ZoneList<Statement*>* body = block->statements(); |
| 371 VariableProxy* result = expr->result(); | 370 VariableProxy* result = expr->result(); |
| 372 Variable* result_var = result->var(); | 371 Variable* result_var = result->var(); |
| 373 | 372 |
| 374 if (!body->is_empty()) { | 373 if (!body->is_empty()) { |
| 375 Processor processor(parser, scope, result_var, factory); | 374 Processor processor(parser, scope, result_var, factory); |
| 376 processor.Process(body); | 375 processor.Process(body); |
| 377 if (processor.HasStackOverflow()) return false; | 376 if (processor.HasStackOverflow()) return false; |
| 378 | 377 |
| 379 if (!processor.result_assigned()) { | 378 if (!processor.result_assigned()) { |
| 380 AstNodeFactory* node_factory = processor.factory(); | 379 AstNodeFactory* node_factory = processor.factory(); |
| 381 Expression* undef = node_factory->NewUndefinedLiteral(kNoSourcePosition); | 380 Expression* undef = node_factory->NewUndefinedLiteral(kNoSourcePosition); |
| 382 Statement* completion = node_factory->NewExpressionStatement( | 381 Statement* completion = node_factory->NewExpressionStatement( |
| 383 processor.SetResult(undef), expr->position()); | 382 processor.SetResult(undef), expr->position()); |
| 384 body->Add(completion, factory->zone()); | 383 body->Add(completion, factory->zone()); |
| 385 } | 384 } |
| 386 } | 385 } |
| 387 return true; | 386 return true; |
| 388 } | 387 } |
| 389 | 388 |
| 390 | 389 |
| 391 } // namespace internal | 390 } // namespace internal |
| 392 } // namespace v8 | 391 } // namespace v8 |
| OLD | NEW |