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 <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/ast/ast-expression-rewriter.h" | 10 #include "src/ast/ast-expression-rewriter.h" |
(...skipping 1650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1661 cases_block->set_scope(scope); | 1661 cases_block->set_scope(scope); |
1662 switch_block->statements()->Add(cases_block, zone()); | 1662 switch_block->statements()->Add(cases_block, zone()); |
1663 return switch_block; | 1663 return switch_block; |
1664 } | 1664 } |
1665 | 1665 |
1666 void Parser::RewriteCatchPattern(CatchInfo* catch_info, bool* ok) { | 1666 void Parser::RewriteCatchPattern(CatchInfo* catch_info, bool* ok) { |
1667 if (catch_info->name == nullptr) { | 1667 if (catch_info->name == nullptr) { |
1668 DCHECK_NOT_NULL(catch_info->pattern); | 1668 DCHECK_NOT_NULL(catch_info->pattern); |
1669 catch_info->name = ast_value_factory()->dot_catch_string(); | 1669 catch_info->name = ast_value_factory()->dot_catch_string(); |
1670 } | 1670 } |
1671 catch_info->variable = catch_info->scope->DeclareLocal( | 1671 catch_info->variable = catch_info->scope->DeclareLocal(catch_info->name, VAR); |
1672 catch_info->name, VAR, kCreatedInitialized, NORMAL_VARIABLE); | |
1673 if (catch_info->pattern != nullptr) { | 1672 if (catch_info->pattern != nullptr) { |
1674 DeclarationDescriptor descriptor; | 1673 DeclarationDescriptor descriptor; |
1675 descriptor.declaration_kind = DeclarationDescriptor::NORMAL; | 1674 descriptor.declaration_kind = DeclarationDescriptor::NORMAL; |
1676 descriptor.scope = scope(); | 1675 descriptor.scope = scope(); |
1677 descriptor.hoist_scope = nullptr; | 1676 descriptor.hoist_scope = nullptr; |
1678 descriptor.mode = LET; | 1677 descriptor.mode = LET; |
1679 descriptor.declaration_pos = catch_info->pattern->position(); | 1678 descriptor.declaration_pos = catch_info->pattern->position(); |
1680 descriptor.initialization_pos = catch_info->pattern->position(); | 1679 descriptor.initialization_pos = catch_info->pattern->position(); |
1681 | 1680 |
1682 // Initializer position for variables declared by the pattern. | 1681 // Initializer position for variables declared by the pattern. |
(...skipping 1260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2943 create_promise, kNoSourcePosition); | 2942 create_promise, kNoSourcePosition); |
2944 set_promise = | 2943 set_promise = |
2945 factory()->NewExpressionStatement(assign_promise, kNoSourcePosition); | 2944 factory()->NewExpressionStatement(assign_promise, kNoSourcePosition); |
2946 } | 2945 } |
2947 result->statements()->Add(set_promise, zone()); | 2946 result->statements()->Add(set_promise, zone()); |
2948 | 2947 |
2949 // catch (.catch) { return %RejectPromise(.promise, .catch), .promise } | 2948 // catch (.catch) { return %RejectPromise(.promise, .catch), .promise } |
2950 Scope* catch_scope = NewScope(CATCH_SCOPE); | 2949 Scope* catch_scope = NewScope(CATCH_SCOPE); |
2951 catch_scope->set_is_hidden(); | 2950 catch_scope->set_is_hidden(); |
2952 Variable* catch_variable = | 2951 Variable* catch_variable = |
2953 catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR, | 2952 catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR); |
2954 kCreatedInitialized, NORMAL_VARIABLE); | |
2955 Block* catch_block = factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); | 2953 Block* catch_block = factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); |
2956 | 2954 |
2957 Expression* promise_reject = BuildRejectPromise( | 2955 Expression* promise_reject = BuildRejectPromise( |
2958 factory()->NewVariableProxy(catch_variable), kNoSourcePosition); | 2956 factory()->NewVariableProxy(catch_variable), kNoSourcePosition); |
2959 ReturnStatement* return_promise_reject = | 2957 ReturnStatement* return_promise_reject = |
2960 factory()->NewReturnStatement(promise_reject, kNoSourcePosition); | 2958 factory()->NewReturnStatement(promise_reject, kNoSourcePosition); |
2961 catch_block->statements()->Add(return_promise_reject, zone()); | 2959 catch_block->statements()->Add(return_promise_reject, zone()); |
2962 | 2960 |
2963 TryStatement* try_catch_statement = | 2961 TryStatement* try_catch_statement = |
2964 factory()->NewTryCatchStatementForAsyncAwait(inner_block, catch_scope, | 2962 factory()->NewTryCatchStatementForAsyncAwait(inner_block, catch_scope, |
(...skipping 1613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4578 Block* try_block = factory()->NewBlock(nullptr, 2, false, nopos); | 4576 Block* try_block = factory()->NewBlock(nullptr, 2, false, nopos); |
4579 try_block->statements()->Add(yield_output, zone()); | 4577 try_block->statements()->Add(yield_output, zone()); |
4580 try_block->statements()->Add(set_mode_next, zone()); | 4578 try_block->statements()->Add(set_mode_next, zone()); |
4581 | 4579 |
4582 Block* catch_block = factory()->NewBlock(nullptr, 1, false, nopos); | 4580 Block* catch_block = factory()->NewBlock(nullptr, 1, false, nopos); |
4583 catch_block->statements()->Add(set_mode_throw, zone()); | 4581 catch_block->statements()->Add(set_mode_throw, zone()); |
4584 | 4582 |
4585 Scope* catch_scope = NewScope(CATCH_SCOPE); | 4583 Scope* catch_scope = NewScope(CATCH_SCOPE); |
4586 catch_scope->set_is_hidden(); | 4584 catch_scope->set_is_hidden(); |
4587 const AstRawString* name = ast_value_factory()->dot_catch_string(); | 4585 const AstRawString* name = ast_value_factory()->dot_catch_string(); |
4588 Variable* catch_variable = catch_scope->DeclareLocal( | 4586 Variable* catch_variable = catch_scope->DeclareLocal(name, VAR); |
4589 name, VAR, kCreatedInitialized, NORMAL_VARIABLE); | |
4590 | 4587 |
4591 try_catch = factory()->NewTryCatchStatementForDesugaring( | 4588 try_catch = factory()->NewTryCatchStatementForDesugaring( |
4592 try_block, catch_scope, catch_variable, catch_block, nopos); | 4589 try_block, catch_scope, catch_variable, catch_block, nopos); |
4593 } | 4590 } |
4594 | 4591 |
4595 // try { ... } finally { ... } | 4592 // try { ... } finally { ... } |
4596 Statement* try_finally; | 4593 Statement* try_finally; |
4597 { | 4594 { |
4598 Block* try_block = factory()->NewBlock(nullptr, 1, false, nopos); | 4595 Block* try_block = factory()->NewBlock(nullptr, 1, false, nopos); |
4599 try_block->statements()->Add(try_catch, zone()); | 4596 try_block->statements()->Add(try_catch, zone()); |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4865 | 4862 |
4866 // try { #try_block } | 4863 // try { #try_block } |
4867 // catch(e) { | 4864 // catch(e) { |
4868 // #set_completion_throw; | 4865 // #set_completion_throw; |
4869 // %ReThrow(e); | 4866 // %ReThrow(e); |
4870 // } | 4867 // } |
4871 Statement* try_catch; | 4868 Statement* try_catch; |
4872 { | 4869 { |
4873 Scope* catch_scope = NewScopeWithParent(use_scope, CATCH_SCOPE); | 4870 Scope* catch_scope = NewScopeWithParent(use_scope, CATCH_SCOPE); |
4874 Variable* catch_variable = | 4871 Variable* catch_variable = |
4875 catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR, | 4872 catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR); |
4876 kCreatedInitialized, NORMAL_VARIABLE); | |
4877 catch_scope->set_is_hidden(); | 4873 catch_scope->set_is_hidden(); |
4878 | 4874 |
4879 Statement* rethrow; | 4875 Statement* rethrow; |
4880 // We use %ReThrow rather than the ordinary throw because we want to | 4876 // We use %ReThrow rather than the ordinary throw because we want to |
4881 // preserve the original exception message. This is also why we create a | 4877 // preserve the original exception message. This is also why we create a |
4882 // TryCatchStatementForReThrow below (which does not clear the pending | 4878 // TryCatchStatementForReThrow below (which does not clear the pending |
4883 // message), rather than a TryCatchStatement. | 4879 // message), rather than a TryCatchStatement. |
4884 { | 4880 { |
4885 auto args = new (zone()) ZoneList<Expression*>(1, zone()); | 4881 auto args = new (zone()) ZoneList<Expression*>(1, zone()); |
4886 args->Add(factory()->NewVariableProxy(catch_variable), zone()); | 4882 args->Add(factory()->NewVariableProxy(catch_variable), zone()); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4972 factory()->NewCallRuntime(Runtime::kInlineCall, args, nopos); | 4968 factory()->NewCallRuntime(Runtime::kInlineCall, args, nopos); |
4973 | 4969 |
4974 Block* try_block = factory()->NewBlock(nullptr, 1, false, nopos); | 4970 Block* try_block = factory()->NewBlock(nullptr, 1, false, nopos); |
4975 try_block->statements()->Add(factory()->NewExpressionStatement(call, nopos), | 4971 try_block->statements()->Add(factory()->NewExpressionStatement(call, nopos), |
4976 zone()); | 4972 zone()); |
4977 | 4973 |
4978 Block* catch_block = factory()->NewBlock(nullptr, 0, false, nopos); | 4974 Block* catch_block = factory()->NewBlock(nullptr, 0, false, nopos); |
4979 | 4975 |
4980 Scope* catch_scope = NewScopeWithParent(scope, CATCH_SCOPE); | 4976 Scope* catch_scope = NewScopeWithParent(scope, CATCH_SCOPE); |
4981 Variable* catch_variable = | 4977 Variable* catch_variable = |
4982 catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR, | 4978 catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR); |
4983 kCreatedInitialized, NORMAL_VARIABLE); | |
4984 catch_scope->set_is_hidden(); | 4979 catch_scope->set_is_hidden(); |
4985 | 4980 |
4986 try_call_return = factory()->NewTryCatchStatement( | 4981 try_call_return = factory()->NewTryCatchStatement( |
4987 try_block, catch_scope, catch_variable, catch_block, nopos); | 4982 try_block, catch_scope, catch_variable, catch_block, nopos); |
4988 } | 4983 } |
4989 | 4984 |
4990 // let output = %_Call(iteratorReturn, iterator); | 4985 // let output = %_Call(iteratorReturn, iterator); |
4991 // if (!IS_RECEIVER(output)) { | 4986 // if (!IS_RECEIVER(output)) { |
4992 // %ThrowIteratorResultNotAnObject(output); | 4987 // %ThrowIteratorResultNotAnObject(output); |
4993 // } | 4988 // } |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5120 | 5115 |
5121 return final_loop; | 5116 return final_loop; |
5122 } | 5117 } |
5123 | 5118 |
5124 #undef CHECK_OK | 5119 #undef CHECK_OK |
5125 #undef CHECK_OK_VOID | 5120 #undef CHECK_OK_VOID |
5126 #undef CHECK_FAILED | 5121 #undef CHECK_FAILED |
5127 | 5122 |
5128 } // namespace internal | 5123 } // namespace internal |
5129 } // namespace v8 | 5124 } // namespace v8 |
OLD | NEW |