| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/parameter-initializer-rewriter.h" | 5 #include "src/parsing/parameter-initializer-rewriter.h" |
| 6 | 6 |
| 7 #include "src/ast/ast.h" | 7 #include "src/ast/ast.h" |
| 8 #include "src/ast/ast-expression-visitor.h" | 8 #include "src/ast/ast-traversal-visitor.h" |
| 9 #include "src/ast/scopes.h" | 9 #include "src/ast/scopes.h" |
| 10 | 10 |
| 11 namespace v8 { | 11 namespace v8 { |
| 12 namespace internal { | 12 namespace internal { |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 | 16 |
| 17 class Rewriter final : public AstExpressionVisitor { | 17 class Rewriter final : public AstTraversalVisitor<Rewriter> { |
| 18 public: | 18 public: |
| 19 Rewriter(uintptr_t stack_limit, Expression* initializer, Scope* param_scope) | 19 Rewriter(uintptr_t stack_limit, Expression* initializer, Scope* param_scope) |
| 20 : AstExpressionVisitor(stack_limit, initializer), | 20 : AstTraversalVisitor(stack_limit, initializer), |
| 21 param_scope_(param_scope) {} | 21 param_scope_(param_scope) {} |
| 22 | 22 |
| 23 private: | 23 private: |
| 24 void VisitExpression(Expression* expr) override {} | 24 // This is required so that the overriden Visit* methods can be |
| 25 // called by the base class (template). |
| 26 friend class AstTraversalVisitor<Rewriter>; |
| 25 | 27 |
| 26 void VisitFunctionLiteral(FunctionLiteral* expr) override; | 28 void VisitFunctionLiteral(FunctionLiteral* expr); |
| 27 void VisitClassLiteral(ClassLiteral* expr) override; | 29 void VisitClassLiteral(ClassLiteral* expr); |
| 28 void VisitVariableProxy(VariableProxy* expr) override; | 30 void VisitVariableProxy(VariableProxy* expr); |
| 29 | 31 |
| 30 void VisitBlock(Block* stmt) override; | 32 void VisitBlock(Block* stmt); |
| 31 void VisitTryCatchStatement(TryCatchStatement* stmt) override; | 33 void VisitTryCatchStatement(TryCatchStatement* stmt); |
| 32 void VisitWithStatement(WithStatement* stmt) override; | 34 void VisitWithStatement(WithStatement* stmt); |
| 33 | 35 |
| 34 Scope* param_scope_; | 36 Scope* param_scope_; |
| 35 }; | 37 }; |
| 36 | 38 |
| 37 void Rewriter::VisitFunctionLiteral(FunctionLiteral* function_literal) { | 39 void Rewriter::VisitFunctionLiteral(FunctionLiteral* function_literal) { |
| 38 function_literal->scope()->ReplaceOuterScope(param_scope_); | 40 function_literal->scope()->ReplaceOuterScope(param_scope_); |
| 39 } | 41 } |
| 40 | 42 |
| 41 | 43 |
| 42 void Rewriter::VisitClassLiteral(ClassLiteral* class_literal) { | 44 void Rewriter::VisitClassLiteral(ClassLiteral* class_literal) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 DCHECK(param_scope->calls_sloppy_eval()); | 105 DCHECK(param_scope->calls_sloppy_eval()); |
| 104 DCHECK(param_scope->outer_scope()->is_function_scope()); | 106 DCHECK(param_scope->outer_scope()->is_function_scope()); |
| 105 | 107 |
| 106 Rewriter rewriter(stack_limit, expr, param_scope); | 108 Rewriter rewriter(stack_limit, expr, param_scope); |
| 107 rewriter.Run(); | 109 rewriter.Run(); |
| 108 } | 110 } |
| 109 | 111 |
| 110 | 112 |
| 111 } // namespace internal | 113 } // namespace internal |
| 112 } // namespace v8 | 114 } // namespace v8 |
| OLD | NEW |