Commit 451fa772 authored by nikolaos's avatar nikolaos Committed by Commit bot

Re-scope inner scopes in arrow parameter initializers

This patch correctly re-scopes inner scopes that can appear in do
expressions used as initializers to arrow parameters.

R=rossberg@chromium.org
BUG=v8:4904
LOG=N

Review URL: https://codereview.chromium.org/1887743002

Cr-Commit-Position: refs/heads/master@{#35542}
parent 62fb4775
...@@ -27,10 +27,10 @@ class AstExpressionVisitor : public AstVisitor { ...@@ -27,10 +27,10 @@ class AstExpressionVisitor : public AstVisitor {
virtual void VisitExpression(Expression* expression) = 0; virtual void VisitExpression(Expression* expression) = 0;
int depth() { return depth_; } int depth() { return depth_; }
private:
void VisitDeclarations(ZoneList<Declaration*>* d) override; void VisitDeclarations(ZoneList<Declaration*>* d) override;
void VisitStatements(ZoneList<Statement*>* s) override; void VisitStatements(ZoneList<Statement*>* s) override;
private:
DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); DEFINE_AST_VISITOR_SUBCLASS_MEMBERS();
#define DECLARE_VISIT(type) void Visit##type(type* node) override; #define DECLARE_VISIT(type) void Visit##type(type* node) override;
......
...@@ -29,6 +29,10 @@ class Rewriter final : public AstExpressionVisitor { ...@@ -29,6 +29,10 @@ class Rewriter final : public AstExpressionVisitor {
void VisitClassLiteral(ClassLiteral* expr) override; void VisitClassLiteral(ClassLiteral* expr) override;
void VisitVariableProxy(VariableProxy* expr) override; void VisitVariableProxy(VariableProxy* expr) override;
void VisitBlock(Block* stmt) override;
void VisitTryCatchStatement(TryCatchStatement* stmt) override;
void VisitWithStatement(WithStatement* stmt) override;
Scope* old_scope_; Scope* old_scope_;
Scope* new_scope_; Scope* new_scope_;
}; };
...@@ -73,6 +77,26 @@ void Rewriter::VisitVariableProxy(VariableProxy* proxy) { ...@@ -73,6 +77,26 @@ void Rewriter::VisitVariableProxy(VariableProxy* proxy) {
} }
void Rewriter::VisitBlock(Block* stmt) {
if (stmt->scope() != nullptr)
stmt->scope()->ReplaceOuterScope(new_scope_);
else
VisitStatements(stmt->statements());
}
void Rewriter::VisitTryCatchStatement(TryCatchStatement* stmt) {
Visit(stmt->try_block());
stmt->scope()->ReplaceOuterScope(new_scope_);
}
void Rewriter::VisitWithStatement(WithStatement* stmt) {
Visit(stmt->expression());
stmt->scope()->ReplaceOuterScope(new_scope_);
}
} // anonymous namespace } // anonymous namespace
......
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-do-expressions
(function testCatchScopeInDoExpression() {
var f = (s = 17, y = do { try { throw 25; } catch(e) { s += e; }; }) => s;
var result = f();
assertEquals(result, 42);
})();
(function testCatchScopeInDoExpression() {
var f = (s = 17, y = do { let t; try { throw 25; } catch(e) { s += e; }; }) => s;
var result = f();
assertEquals(result, 42);
})();
(function testCatchScopeInDoExpression() {
let t1;
var f = (s = 17, y = do { let t2; try { throw 25; } catch(e) { s += e; }; }) => s;
var result = f();
assertEquals(result, 42);
})();
...@@ -794,10 +794,6 @@ ...@@ -794,10 +794,6 @@
# objects. # objects.
'es6/mirror-collections': [FAIL], 'es6/mirror-collections': [FAIL],
# TODO(mythria, 4904): Parser bug. It creates incorrectly nested scopes
# for do expressions in arrow functions.
'harmony/regress/regress-4658': [FAIL, ['mode == release and dcheck_always_on == False', PASS],],
# TODO(rmcilroy, 4680): Script throws RangeError as expected, but does so during # TODO(rmcilroy, 4680): Script throws RangeError as expected, but does so during
# eager compile of the whole script instead of during lazy compile of the function # eager compile of the whole script instead of during lazy compile of the function
# f(), so we can't catch the exception in the try/catch. Skip because on some # f(), so we can't catch the exception in the try/catch. Skip because on some
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment