Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1886)

Unified Diff: src/parsing/parser.cc

Issue 2110193002: Do all parsing for try/catch destructuring inside the appropriate scopes (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: One less scope Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-5106.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parsing/parser.cc
diff --git a/src/parsing/parser.cc b/src/parsing/parser.cc
index 413903b49a044d8880aa6dde996cf7783a7982a9..905997abcdfd24dc30f7057635bc310a5d9afab6 100644
--- a/src/parsing/parser.cc
+++ b/src/parsing/parser.cc
@@ -2999,40 +2999,40 @@ TryStatement* Parser::ParseTryStatement(bool* ok) {
catch_scope = NewScope(scope_, CATCH_SCOPE);
catch_scope->set_start_position(scanner()->location().beg_pos);
- ExpressionClassifier pattern_classifier(this);
- Expression* pattern = ParsePrimaryExpression(&pattern_classifier, CHECK_OK);
- ValidateBindingPattern(&pattern_classifier, CHECK_OK);
-
- const AstRawString* name = ast_value_factory()->dot_catch_string();
- bool is_simple = pattern->IsVariableProxy();
- if (is_simple) {
- auto proxy = pattern->AsVariableProxy();
- scope_->RemoveUnresolved(proxy);
- name = proxy->raw_name();
- }
-
- catch_variable = catch_scope->DeclareLocal(name, VAR, kCreatedInitialized,
- Variable::NORMAL);
-
- Expect(Token::RPAREN, CHECK_OK);
-
{
CollectExpressionsInTailPositionToListScope
collect_tail_call_expressions_scope(
function_state_, &tail_call_expressions_in_catch_block);
BlockState block_state(&scope_, catch_scope);
- // TODO(adamk): Make a version of ParseBlock that takes a scope and
- // a block.
catch_block =
factory()->NewBlock(nullptr, 16, false, RelocInfo::kNoPosition);
- Scope* block_scope = NewScope(scope_, BLOCK_SCOPE);
+ // Create a block scope to hold any lexical declarations created
+ // as part of destructuring the catch parameter.
+ Scope* block_scope = NewScope(scope_, BLOCK_SCOPE);
block_scope->set_start_position(scanner()->location().beg_pos);
{
BlockState block_state(&scope_, block_scope);
Target target(&this->target_stack_, catch_block);
+ ExpressionClassifier pattern_classifier(this);
+ Expression* pattern =
+ ParsePrimaryExpression(&pattern_classifier, CHECK_OK);
+ ValidateBindingPattern(&pattern_classifier, CHECK_OK);
+
+ const AstRawString* name = ast_value_factory()->dot_catch_string();
+ bool is_simple = pattern->IsVariableProxy();
+ if (is_simple) {
+ auto proxy = pattern->AsVariableProxy();
+ scope_->RemoveUnresolved(proxy);
+ name = proxy->raw_name();
+ }
+ catch_variable = catch_scope->DeclareLocal(
+ name, VAR, kCreatedInitialized, Variable::NORMAL);
+
+ Expect(Token::RPAREN, CHECK_OK);
+
if (!is_simple) {
DeclarationDescriptor descriptor;
descriptor.declaration_kind = DeclarationDescriptor::NORMAL;
@@ -3054,6 +3054,8 @@ TryStatement* Parser::ParseTryStatement(bool* ok) {
catch_block->statements()->Add(init_block, zone());
}
+ // TODO(adamk): This should call ParseBlock in order to properly
+ // add an additional block scope for the catch body.
neis 2016/06/30 06:47:05 Is this related to the remaining test262 failure?
adamk 2016/06/30 16:02:10 Yes, Kevin will fix this in his patch which fixes
Expect(Token::LBRACE, CHECK_OK);
while (peek() != Token::RBRACE) {
Statement* stat = ParseStatementListItem(CHECK_OK);
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-5106.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698