| 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/parser.h" | 5 #include "src/parsing/parser.h" |
| 6 | 6 |
| 7 #include "src/api.h" | 7 #include "src/api.h" |
| 8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
| 9 #include "src/ast/ast-expression-rewriter.h" | 9 #include "src/ast/ast-expression-rewriter.h" |
| 10 #include "src/ast/ast-expression-visitor.h" | 10 #include "src/ast/ast-expression-visitor.h" |
| (...skipping 6446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6457 // | 6457 // |
| 6458 // This function adds two statements to [target], corresponding to the | 6458 // This function adds two statements to [target], corresponding to the |
| 6459 // following code: | 6459 // following code: |
| 6460 // | 6460 // |
| 6461 // completion = kNormalCompletion; | 6461 // completion = kNormalCompletion; |
| 6462 // try { | 6462 // try { |
| 6463 // try { | 6463 // try { |
| 6464 // iterator_use | 6464 // iterator_use |
| 6465 // } catch(e) { | 6465 // } catch(e) { |
| 6466 // if (completion === kAbruptCompletion) completion = kThrowCompletion; | 6466 // if (completion === kAbruptCompletion) completion = kThrowCompletion; |
| 6467 // throw e; | 6467 // %ReThrow(e); |
| 6468 // } | 6468 // } |
| 6469 // } finally { | 6469 // } finally { |
| 6470 // if (condition) { | 6470 // if (condition) { |
| 6471 // #BuildIteratorCloseForCompletion(iter, completion) | 6471 // #BuildIteratorCloseForCompletion(iter, completion) |
| 6472 // } | 6472 // } |
| 6473 // } | 6473 // } |
| 6474 // | 6474 // |
| 6475 | 6475 |
| 6476 const int nopos = RelocInfo::kNoPosition; | 6476 const int nopos = RelocInfo::kNoPosition; |
| 6477 auto factory = parser_->factory(); | 6477 auto factory = parser_->factory(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6518 maybe_close = factory->NewBlock(nullptr, 1, true, nopos); | 6518 maybe_close = factory->NewBlock(nullptr, 1, true, nopos); |
| 6519 maybe_close->statements()->Add( | 6519 maybe_close->statements()->Add( |
| 6520 factory->NewIfStatement(condition, block, | 6520 factory->NewIfStatement(condition, block, |
| 6521 factory->NewEmptyStatement(nopos), nopos), | 6521 factory->NewEmptyStatement(nopos), nopos), |
| 6522 zone); | 6522 zone); |
| 6523 } | 6523 } |
| 6524 | 6524 |
| 6525 // try { #try_block } | 6525 // try { #try_block } |
| 6526 // catch(e) { | 6526 // catch(e) { |
| 6527 // #set_completion_throw; | 6527 // #set_completion_throw; |
| 6528 // throw e; | 6528 // %ReThrow(e); |
| 6529 // } | 6529 // } |
| 6530 Statement* try_catch; | 6530 Statement* try_catch; |
| 6531 { | 6531 { |
| 6532 Scope* catch_scope = parser_->NewScope(scope, CATCH_SCOPE); | 6532 Scope* catch_scope = parser_->NewScope(scope, CATCH_SCOPE); |
| 6533 Variable* catch_variable = | 6533 Variable* catch_variable = |
| 6534 catch_scope->DeclareLocal(avfactory->dot_catch_string(), VAR, | 6534 catch_scope->DeclareLocal(avfactory->dot_catch_string(), VAR, |
| 6535 kCreatedInitialized, Variable::NORMAL); | 6535 kCreatedInitialized, Variable::NORMAL); |
| 6536 | 6536 |
| 6537 Statement* rethrow; | 6537 Statement* rethrow; |
| 6538 // We use %ReThrow rather than the ordinary throw because we want to |
| 6539 // preserve the original exception message. This is also why we create a |
| 6540 // TryCatchStatementForReThrow below (which does not clear the pending |
| 6541 // message), rather than a TryCatchStatement. |
| 6538 { | 6542 { |
| 6539 Expression* proxy = factory->NewVariableProxy(catch_variable); | 6543 auto args = new (zone) ZoneList<Expression*>(1, zone); |
| 6540 rethrow = factory->NewExpressionStatement(factory->NewThrow(proxy, nopos), | 6544 args->Add(factory->NewVariableProxy(catch_variable), zone); |
| 6541 nopos); | 6545 rethrow = factory->NewExpressionStatement( |
| 6546 factory->NewCallRuntime(Runtime::kReThrow, args, nopos), nopos); |
| 6542 } | 6547 } |
| 6543 | 6548 |
| 6544 Block* catch_block = factory->NewBlock(nullptr, 2, false, nopos); | 6549 Block* catch_block = factory->NewBlock(nullptr, 2, false, nopos); |
| 6545 catch_block->statements()->Add(set_completion_throw, zone); | 6550 catch_block->statements()->Add(set_completion_throw, zone); |
| 6546 catch_block->statements()->Add(rethrow, zone); | 6551 catch_block->statements()->Add(rethrow, zone); |
| 6547 | 6552 |
| 6548 try_catch = factory->NewTryCatchStatement( | 6553 try_catch = factory->NewTryCatchStatementForReThrow( |
| 6549 iterator_use, catch_scope, catch_variable, catch_block, nopos); | 6554 iterator_use, catch_scope, catch_variable, catch_block, nopos); |
| 6550 } | 6555 } |
| 6551 | 6556 |
| 6552 // try { #try_catch } finally { #maybe_close } | 6557 // try { #try_catch } finally { #maybe_close } |
| 6553 Statement* try_finally; | 6558 Statement* try_finally; |
| 6554 { | 6559 { |
| 6555 Block* try_block = factory->NewBlock(nullptr, 1, false, nopos); | 6560 Block* try_block = factory->NewBlock(nullptr, 1, false, nopos); |
| 6556 try_block->statements()->Add(try_catch, zone); | 6561 try_block->statements()->Add(try_catch, zone); |
| 6557 | 6562 |
| 6558 try_finally = | 6563 try_finally = |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6734 // | 6739 // |
| 6735 // This function replaces the loop with the following wrapping: | 6740 // This function replaces the loop with the following wrapping: |
| 6736 // | 6741 // |
| 6737 // let each; | 6742 // let each; |
| 6738 // let completion = kNormalCompletion; | 6743 // let completion = kNormalCompletion; |
| 6739 // try { | 6744 // try { |
| 6740 // try { | 6745 // try { |
| 6741 // #loop; | 6746 // #loop; |
| 6742 // } catch(e) { | 6747 // } catch(e) { |
| 6743 // if (completion === kAbruptCompletion) completion = kThrowCompletion; | 6748 // if (completion === kAbruptCompletion) completion = kThrowCompletion; |
| 6744 // throw e; | 6749 // %ReThrow(e); |
| 6745 // } | 6750 // } |
| 6746 // } finally { | 6751 // } finally { |
| 6747 // if (!(completion === kNormalCompletion || IS_UNDEFINED(#iterator))) { | 6752 // if (!(completion === kNormalCompletion || IS_UNDEFINED(#iterator))) { |
| 6748 // #BuildIteratorCloseForCompletion(#iterator, completion) | 6753 // #BuildIteratorCloseForCompletion(#iterator, completion) |
| 6749 // } | 6754 // } |
| 6750 // } | 6755 // } |
| 6751 // | 6756 // |
| 6752 // where the loop's body is wrapped as follows: | 6757 // where the loop's body is wrapped as follows: |
| 6753 // | 6758 // |
| 6754 // { | 6759 // { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6859 try_block, target); | 6864 try_block, target); |
| 6860 final_loop = target; | 6865 final_loop = target; |
| 6861 } | 6866 } |
| 6862 | 6867 |
| 6863 return final_loop; | 6868 return final_loop; |
| 6864 } | 6869 } |
| 6865 | 6870 |
| 6866 | 6871 |
| 6867 } // namespace internal | 6872 } // namespace internal |
| 6868 } // namespace v8 | 6873 } // namespace v8 |
| OLD | NEW |