OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "src/v8.h" |
| 6 |
| 7 #include "src/parameter-initializer-rewriter.h" |
| 8 |
| 9 #include "src/ast.h" |
| 10 #include "src/ast-expression-visitor.h" |
| 11 #include "src/scopes.h" |
| 12 |
| 13 namespace v8 { |
| 14 namespace internal { |
| 15 |
| 16 namespace { |
| 17 |
| 18 |
| 19 class Rewriter final : public AstExpressionVisitor { |
| 20 public: |
| 21 Rewriter(uintptr_t stack_limit, Expression* initializer, Scope* old_scope, |
| 22 Scope* new_scope) |
| 23 : AstExpressionVisitor(stack_limit, initializer), |
| 24 old_scope_(old_scope), |
| 25 new_scope_(new_scope) {} |
| 26 |
| 27 private: |
| 28 void VisitExpression(Expression* expr) override {} |
| 29 |
| 30 void VisitFunctionLiteral(FunctionLiteral* expr) override; |
| 31 void VisitVariableProxy(VariableProxy* expr) override; |
| 32 |
| 33 // TODO(adamk): Need to fix up the scope chain of class literals. |
| 34 // void VisitClassLiteral(ClassLiteral* expr) override; |
| 35 |
| 36 Scope* old_scope_; |
| 37 Scope* new_scope_; |
| 38 }; |
| 39 |
| 40 |
| 41 void Rewriter::VisitFunctionLiteral(FunctionLiteral* function_literal) { |
| 42 function_literal->scope()->set_outer_scope(new_scope_); |
| 43 } |
| 44 |
| 45 |
| 46 void Rewriter::VisitVariableProxy(VariableProxy* proxy) { |
| 47 CHECK(!proxy->is_resolved()); |
| 48 if (old_scope_->RemoveUnresolved(proxy)) { |
| 49 new_scope_->AddUnresolved(proxy); |
| 50 } |
| 51 } |
| 52 |
| 53 |
| 54 } // anonymous namespace |
| 55 |
| 56 |
| 57 void RewriteParameterInitializerScope(uintptr_t stack_limit, |
| 58 Expression* initializer, Scope* old_scope, |
| 59 Scope* new_scope) { |
| 60 Rewriter rewriter(stack_limit, initializer, old_scope, new_scope); |
| 61 rewriter.Run(); |
| 62 } |
| 63 |
| 64 |
| 65 } // namespace internal |
| 66 } // namespace v8 |
OLD | NEW |