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 6722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6733 } | 6733 } |
6734 | 6734 |
6735 | 6735 |
6736 Statement* ParserTraits::FinalizeForOfStatement(ForOfStatement* loop, int pos) { | 6736 Statement* ParserTraits::FinalizeForOfStatement(ForOfStatement* loop, int pos) { |
6737 if (!FLAG_harmony_iterator_close) return loop; | 6737 if (!FLAG_harmony_iterator_close) return loop; |
6738 | 6738 |
6739 // | 6739 // |
6740 // This function replaces the loop with the following wrapping: | 6740 // This function replaces the loop with the following wrapping: |
6741 // | 6741 // |
6742 // let completion = BODY_COMPLETED; | 6742 // let completion = BODY_COMPLETED; |
| 6743 // let each; |
6743 // try { | 6744 // try { |
6744 // #loop; | 6745 // #loop; |
6745 // } catch(e) { | 6746 // } catch(e) { |
6746 // if (completion === BODY_ABORTED) completion = BODY_THREW; | 6747 // if (completion === BODY_ABORTED) completion = BODY_THREW; |
6747 // throw e; | 6748 // throw e; |
6748 // } finally { | 6749 // } finally { |
6749 // if (!(completion === BODY_COMPLETED || IS_UNDEFINED(#iterator))) { | 6750 // if (!(completion === BODY_COMPLETED || IS_UNDEFINED(#iterator))) { |
6750 // #BuildIteratorCloseForCompletion(#iterator, completion) | 6751 // #BuildIteratorCloseForCompletion(#iterator, completion) |
6751 // } | 6752 // } |
6752 // } | 6753 // } |
6753 // | 6754 // |
6754 // where the loop's body is wrapped as follows: | 6755 // where the loop's body is wrapped as follows: |
6755 // | 6756 // |
6756 // { | 6757 // { |
6757 // {{completion = BODY_ABORTED;}} | |
6758 // #loop-body | 6758 // #loop-body |
6759 // {{completion = BODY_COMPLETED;}} | 6759 // {{completion = BODY_COMPLETED;}} |
6760 // } | 6760 // } |
| 6761 // |
| 6762 // and assign_each is wrapped as follows |
| 6763 // |
| 6764 // do { |
| 6765 // {{completion = BODY_ABORTED;}} |
| 6766 // #assign-each |
| 6767 // } into each |
6761 | 6768 |
6762 const int nopos = RelocInfo::kNoPosition; | 6769 const int nopos = RelocInfo::kNoPosition; |
6763 auto factory = parser_->factory(); | 6770 auto factory = parser_->factory(); |
6764 auto avfactory = parser_->ast_value_factory(); | 6771 auto avfactory = parser_->ast_value_factory(); |
6765 auto scope = parser_->scope_; | 6772 auto scope = parser_->scope_; |
6766 auto zone = parser_->zone(); | 6773 auto zone = parser_->zone(); |
6767 | 6774 |
6768 // let completion = BODY_COMPLETED; | 6775 // let completion = BODY_COMPLETED; |
6769 Variable* var_completion = scope->NewTemporary(avfactory->empty_string()); | 6776 Variable* var_completion = scope->NewTemporary(avfactory->empty_string()); |
6770 Statement* initialize_completion; | 6777 Statement* initialize_completion; |
6771 { | 6778 { |
6772 Expression* proxy = factory->NewVariableProxy(var_completion); | 6779 Expression* proxy = factory->NewVariableProxy(var_completion); |
6773 Expression* assignment = factory->NewAssignment( | 6780 Expression* assignment = factory->NewAssignment( |
6774 Token::ASSIGN, proxy, | 6781 Token::ASSIGN, proxy, |
6775 factory->NewSmiLiteral(BODY_COMPLETED, nopos), nopos); | 6782 factory->NewSmiLiteral(BODY_COMPLETED, nopos), nopos); |
6776 initialize_completion = | 6783 initialize_completion = |
6777 factory->NewExpressionStatement(assignment, nopos); | 6784 factory->NewExpressionStatement(assignment, nopos); |
6778 } | 6785 } |
6779 | 6786 |
| 6787 // let each; |
| 6788 Variable* var_each = scope->NewTemporary(avfactory->empty_string()); |
| 6789 Statement* initialize_each; |
| 6790 { |
| 6791 Expression* proxy = factory->NewVariableProxy(var_each); |
| 6792 Expression* assignment = factory->NewAssignment( |
| 6793 Token::ASSIGN, proxy, |
| 6794 factory->NewUndefinedLiteral(nopos), nopos); |
| 6795 initialize_each = |
| 6796 factory->NewExpressionStatement(assignment, nopos); |
| 6797 } |
| 6798 |
6780 // if (completion === BODY_ABORTED) completion = BODY_THREW; | 6799 // if (completion === BODY_ABORTED) completion = BODY_THREW; |
6781 Statement* set_completion_throw; | 6800 Statement* set_completion_throw; |
6782 { | 6801 { |
6783 Expression* condition = factory->NewCompareOperation( | 6802 Expression* condition = factory->NewCompareOperation( |
6784 Token::EQ_STRICT, factory->NewVariableProxy(var_completion), | 6803 Token::EQ_STRICT, factory->NewVariableProxy(var_completion), |
6785 factory->NewSmiLiteral(BODY_ABORTED, nopos), nopos); | 6804 factory->NewSmiLiteral(BODY_ABORTED, nopos), nopos); |
6786 | 6805 |
6787 Expression* proxy = factory->NewVariableProxy(var_completion); | 6806 Expression* proxy = factory->NewVariableProxy(var_completion); |
6788 Expression* assignment = factory->NewAssignment( | 6807 Expression* assignment = factory->NewAssignment( |
6789 Token::ASSIGN, proxy, factory->NewSmiLiteral(BODY_THREW, nopos), | 6808 Token::ASSIGN, proxy, factory->NewSmiLiteral(BODY_THREW, nopos), |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6851 Statement* try_finally; | 6870 Statement* try_finally; |
6852 { | 6871 { |
6853 Block* try_block = factory->NewBlock(nullptr, 1, false, nopos); | 6872 Block* try_block = factory->NewBlock(nullptr, 1, false, nopos); |
6854 try_block->statements()->Add(try_catch, zone); | 6873 try_block->statements()->Add(try_catch, zone); |
6855 | 6874 |
6856 try_finally = | 6875 try_finally = |
6857 factory->NewTryFinallyStatement(try_block, maybe_close, nopos); | 6876 factory->NewTryFinallyStatement(try_block, maybe_close, nopos); |
6858 } | 6877 } |
6859 | 6878 |
6860 // #initialize_completion; | 6879 // #initialize_completion; |
| 6880 // #initialize_each; |
6861 // #try_finally; | 6881 // #try_finally; |
6862 Statement* final_loop; | 6882 Statement* final_loop; |
6863 { | 6883 { |
6864 Block* block = factory->NewBlock(nullptr, 2, false, nopos); | 6884 Block* block = factory->NewBlock(nullptr, 2, false, nopos); |
6865 block->statements()->Add(initialize_completion, zone); | 6885 block->statements()->Add(initialize_completion, zone); |
| 6886 block->statements()->Add(initialize_each, zone); |
6866 block->statements()->Add(try_finally, zone); | 6887 block->statements()->Add(try_finally, zone); |
6867 final_loop = block; | 6888 final_loop = block; |
6868 } | 6889 } |
6869 | 6890 |
6870 // {{completion = BODY_ABORTED;}} | |
6871 Statement* set_completion_break; | |
6872 { | |
6873 Expression* proxy = factory->NewVariableProxy(var_completion); | |
6874 Expression* assignment = factory->NewAssignment( | |
6875 Token::ASSIGN, proxy, | |
6876 factory->NewSmiLiteral(BODY_ABORTED, nopos), nopos); | |
6877 | |
6878 Block* block = factory->NewBlock(nullptr, 1, true, nopos); | |
6879 block->statements()->Add( | |
6880 factory->NewExpressionStatement(assignment, nopos), zone); | |
6881 set_completion_break = block; | |
6882 } | |
6883 | |
6884 // {{completion = BODY_COMPLETED;}} | 6891 // {{completion = BODY_COMPLETED;}} |
6885 Statement* set_completion_normal; | 6892 Statement* set_completion_normal; |
6886 { | 6893 { |
6887 Expression* proxy = factory->NewVariableProxy(var_completion); | 6894 Expression* proxy = factory->NewVariableProxy(var_completion); |
6888 Expression* assignment = factory->NewAssignment( | 6895 Expression* assignment = factory->NewAssignment( |
6889 Token::ASSIGN, proxy, factory->NewSmiLiteral(BODY_COMPLETED, nopos), | 6896 Token::ASSIGN, proxy, factory->NewSmiLiteral(BODY_COMPLETED, nopos), |
6890 nopos); | 6897 nopos); |
6891 | 6898 |
6892 Block* block = factory->NewBlock(nullptr, 1, true, nopos); | 6899 Block* block = factory->NewBlock(nullptr, 1, true, nopos); |
6893 block->statements()->Add( | 6900 block->statements()->Add( |
6894 factory->NewExpressionStatement(assignment, nopos), zone); | 6901 factory->NewExpressionStatement(assignment, nopos), zone); |
6895 set_completion_normal = block; | 6902 set_completion_normal = block; |
6896 } | 6903 } |
6897 | 6904 |
6898 // { #set_completion_break; #loop-body; #set_completion_normal } | 6905 // { #loop-body; #set_completion_normal } |
6899 Block* new_body = factory->NewBlock(nullptr, 2, false, nopos); | 6906 Block* new_body = factory->NewBlock(nullptr, 2, false, nopos); |
6900 new_body->statements()->Add(set_completion_break, zone); | |
6901 new_body->statements()->Add(loop->body(), zone); | 6907 new_body->statements()->Add(loop->body(), zone); |
6902 new_body->statements()->Add(set_completion_normal, zone); | 6908 new_body->statements()->Add(set_completion_normal, zone); |
6903 | 6909 |
6904 loop->set_body(new_body); | 6910 loop->set_body(new_body); |
| 6911 |
| 6912 // {{completion = BODY_ABORTED;}} |
| 6913 Statement* set_completion_break; |
| 6914 { |
| 6915 Expression* proxy = factory->NewVariableProxy(var_completion); |
| 6916 Expression* assignment = factory->NewAssignment( |
| 6917 Token::ASSIGN, proxy, factory->NewSmiLiteral(BODY_ABORTED, nopos), |
| 6918 nopos); |
| 6919 |
| 6920 Block* block = factory->NewBlock(nullptr, 1, true, nopos); |
| 6921 block->statements()->Add(factory->NewExpressionStatement(assignment, nopos), |
| 6922 zone); |
| 6923 set_completion_break = block; |
| 6924 } |
| 6925 |
| 6926 // { #set_completion_break; #assign-each } |
| 6927 Block* new_assign_each = factory->NewBlock(nullptr, 2, false, nopos); |
| 6928 new_assign_each->statements()->Add(set_completion_break, zone); |
| 6929 new_assign_each->statements()->Add( |
| 6930 factory->NewExpressionStatement(loop->assign_each(), nopos), zone); |
| 6931 |
| 6932 Expression* do_each = |
| 6933 factory->NewDoExpression(new_assign_each, var_each, nopos); |
| 6934 loop->set_assign_each(do_each); |
| 6935 |
6905 return final_loop; | 6936 return final_loop; |
6906 } | 6937 } |
6907 | 6938 |
6908 | 6939 |
6909 } // namespace internal | 6940 } // namespace internal |
6910 } // namespace v8 | 6941 } // namespace v8 |
OLD | NEW |