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 <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 const std::pair<Variable*, int>& right) { | 48 const std::pair<Variable*, int>& right) { |
49 return left.second < right.second; | 49 return left.second < right.second; |
50 } | 50 } |
51 }; | 51 }; |
52 | 52 |
53 Rewriter::~Rewriter() { | 53 Rewriter::~Rewriter() { |
54 if (!temps_.empty()) { | 54 if (!temps_.empty()) { |
55 // Ensure that we add temporaries in the order they appeared in old_scope_. | 55 // Ensure that we add temporaries in the order they appeared in old_scope_. |
56 std::sort(temps_.begin(), temps_.end(), LessThanSecond()); | 56 std::sort(temps_.begin(), temps_.end(), LessThanSecond()); |
57 for (auto var_and_index : temps_) { | 57 for (auto var_and_index : temps_) { |
58 var_and_index.first->set_scope(new_scope_); | 58 Scope* scope = new_scope_->ClosureScope(); |
59 new_scope_->AddTemporary(var_and_index.first); | 59 var_and_index.first->set_scope(scope); |
60 scope->AddTemporary(var_and_index.first); | |
60 } | 61 } |
61 } | 62 } |
62 } | 63 } |
63 | 64 |
64 void Rewriter::VisitFunctionLiteral(FunctionLiteral* function_literal) { | 65 void Rewriter::VisitFunctionLiteral(FunctionLiteral* function_literal) { |
65 function_literal->scope()->ReplaceOuterScope(new_scope_); | 66 function_literal->scope()->ReplaceOuterScope(new_scope_); |
66 } | 67 } |
67 | 68 |
68 | 69 |
69 void Rewriter::VisitClassLiteral(ClassLiteral* class_literal) { | 70 void Rewriter::VisitClassLiteral(ClassLiteral* class_literal) { |
(...skipping 13 matching lines...) Expand all Loading... | |
83 // the class scope on their scope chain. | 84 // the class scope on their scope chain. |
84 DCHECK(prop->value()->IsFunctionLiteral()); | 85 DCHECK(prop->value()->IsFunctionLiteral()); |
85 } | 86 } |
86 } | 87 } |
87 | 88 |
88 | 89 |
89 void Rewriter::VisitVariableProxy(VariableProxy* proxy) { | 90 void Rewriter::VisitVariableProxy(VariableProxy* proxy) { |
90 if (proxy->is_resolved()) { | 91 if (proxy->is_resolved()) { |
91 Variable* var = proxy->var(); | 92 Variable* var = proxy->var(); |
92 if (var->mode() != TEMPORARY) return; | 93 if (var->mode() != TEMPORARY) return; |
93 // For rewriting inside the same ClosureScope (e.g., putting default | 94 // Temporaries are only placed in ClosureScopes. |
94 // parameter values in their own inner scope in certain cases), refrain | 95 DCHECK_EQ(var->scope(), var->scope()->ClosureScope()); |
95 // from invalidly moving temporaries to a block scope. | 96 // If the temporary is already where it should be, return quickly. |
96 if (var->scope()->ClosureScope() == new_scope_->ClosureScope()) return; | 97 if (var->scope() == new_scope_->ClosureScope()) return; |
97 int index = old_scope_->RemoveTemporary(var); | 98 int index = old_scope_->ClosureScope()->RemoveTemporary(var); |
adamk
2016/06/27 18:49:31
What if the rewriter computed the ClosureScopes of
nickie
2016/06/28 09:26:37
Done.
| |
98 if (index >= 0) { | 99 if (index >= 0) { |
99 temps_.push_back(std::make_pair(var, index)); | 100 temps_.push_back(std::make_pair(var, index)); |
100 } | 101 } |
101 } else if (old_scope_->RemoveUnresolved(proxy)) { | 102 } else if (old_scope_->RemoveUnresolved(proxy)) { |
102 new_scope_->AddUnresolved(proxy); | 103 new_scope_->AddUnresolved(proxy); |
103 } | 104 } |
104 } | 105 } |
105 | 106 |
106 | 107 |
107 void Rewriter::VisitBlock(Block* stmt) { | 108 void Rewriter::VisitBlock(Block* stmt) { |
(...skipping 22 matching lines...) Expand all Loading... | |
130 void RewriteParameterInitializerScope(uintptr_t stack_limit, | 131 void RewriteParameterInitializerScope(uintptr_t stack_limit, |
131 Expression* initializer, Scope* old_scope, | 132 Expression* initializer, Scope* old_scope, |
132 Scope* new_scope) { | 133 Scope* new_scope) { |
133 Rewriter rewriter(stack_limit, initializer, old_scope, new_scope); | 134 Rewriter rewriter(stack_limit, initializer, old_scope, new_scope); |
134 rewriter.Run(); | 135 rewriter.Run(); |
135 } | 136 } |
136 | 137 |
137 | 138 |
138 } // namespace internal | 139 } // namespace internal |
139 } // namespace v8 | 140 } // namespace v8 |
OLD | NEW |