@@ -2923,40 +2923,40 @@ TryStatement* Parser::ParseTryStatement(bool* ok) {
2923
2923
catch_scope = NewScope (scope_, CATCH_SCOPE);
2924
2924
catch_scope->set_start_position (scanner ()->location ().beg_pos );
2925
2925
2926
- ExpressionClassifier pattern_classifier (this );
2927
- Expression* pattern = ParsePrimaryExpression (&pattern_classifier, CHECK_OK);
2928
- ValidateBindingPattern (&pattern_classifier, CHECK_OK);
2929
-
2930
- const AstRawString* name = ast_value_factory ()->dot_catch_string ();
2931
- bool is_simple = pattern->IsVariableProxy ();
2932
- if (is_simple) {
2933
- auto proxy = pattern->AsVariableProxy ();
2934
- scope_->RemoveUnresolved (proxy);
2935
- name = proxy->raw_name ();
2936
- }
2937
-
2938
- catch_variable = catch_scope->DeclareLocal (name, VAR, kCreatedInitialized ,
2939
- Variable::NORMAL);
2940
-
2941
- Expect (Token::RPAREN, CHECK_OK);
2942
-
2943
2926
{
2944
2927
CollectExpressionsInTailPositionToListScope
2945
2928
collect_expressions_in_tail_position_scope (
2946
2929
function_state_, &expressions_in_tail_position_in_catch_block);
2947
2930
BlockState block_state (&scope_, catch_scope);
2948
2931
2949
- // TODO(adamk): Make a version of ParseBlock that takes a scope and
2950
- // a block.
2951
2932
catch_block =
2952
2933
factory ()->NewBlock (nullptr , 16 , false , RelocInfo::kNoPosition );
2953
- Scope* block_scope = NewScope (scope_, BLOCK_SCOPE);
2954
2934
2935
+ // Create a block scope to hold any lexical declarations created
2936
+ // as part of destructuring the catch parameter.
2937
+ Scope* block_scope = NewScope (scope_, BLOCK_SCOPE);
2955
2938
block_scope->set_start_position (scanner ()->location ().beg_pos );
2956
2939
{
2957
2940
BlockState block_state (&scope_, block_scope);
2958
2941
Target target (&this ->target_stack_ , catch_block);
2959
2942
2943
+ ExpressionClassifier pattern_classifier (this );
2944
+ Expression* pattern =
2945
+ ParsePrimaryExpression (&pattern_classifier, CHECK_OK);
2946
+ ValidateBindingPattern (&pattern_classifier, CHECK_OK);
2947
+
2948
+ const AstRawString* name = ast_value_factory ()->dot_catch_string ();
2949
+ bool is_simple = pattern->IsVariableProxy ();
2950
+ if (is_simple) {
2951
+ auto proxy = pattern->AsVariableProxy ();
2952
+ scope_->RemoveUnresolved (proxy);
2953
+ name = proxy->raw_name ();
2954
+ }
2955
+ catch_variable = catch_scope->DeclareLocal (
2956
+ name, VAR, kCreatedInitialized , Variable::NORMAL);
2957
+
2958
+ Expect (Token::RPAREN, CHECK_OK);
2959
+
2960
2960
if (!is_simple) {
2961
2961
DeclarationDescriptor descriptor;
2962
2962
descriptor.declaration_kind = DeclarationDescriptor::NORMAL;
@@ -2978,6 +2978,8 @@ TryStatement* Parser::ParseTryStatement(bool* ok) {
2978
2978
catch_block->statements ()->Add (init_block, zone ());
2979
2979
}
2980
2980
2981
+ // TODO(adamk): This should call ParseBlock in order to properly
2982
+ // add an additional block scope for the catch body.
2981
2983
Expect (Token::LBRACE, CHECK_OK);
2982
2984
while (peek () != Token::RBRACE) {
2983
2985
Statement* stat = ParseStatementListItem (CHECK_OK);
0 commit comments