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

Unified Diff: src/scopes.cc

Issue 1404793004: Add support for calculating a scopes maximum nested context chain. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 5 years, 2 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 | « src/scopes.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/scopes.cc
diff --git a/src/scopes.cc b/src/scopes.cc
index dbcc4b60832bf33d5e096bab9f2634128263b25b..4e6acca5fc64ba5f6be60a0e70d6f739aa87dea4 100644
--- a/src/scopes.cc
+++ b/src/scopes.cc
@@ -765,15 +765,26 @@ int Scope::ContextChainLength(Scope* scope) {
int n = 0;
for (Scope* s = this; s != scope; s = s->outer_scope_) {
DCHECK(s != NULL); // scope must be in the scope chain
- if (s->is_with_scope() || s->num_heap_slots() > 0) n++;
- // Catch and module scopes always have heap slots.
- DCHECK(!s->is_catch_scope() || s->num_heap_slots() > 0);
- DCHECK(!s->is_module_scope() || s->num_heap_slots() > 0);
+ if (s->NeedsContext()) n++;
}
return n;
}
+int Scope::MaxNestedContextChainLength() {
+ int max_context_chain_length = 0;
+ for (int i = 0; i < inner_scopes_.length(); i++) {
+ Scope* scope = inner_scopes_[i];
+ max_context_chain_length = std::max(scope->MaxNestedContextChainLength(),
+ max_context_chain_length);
+ }
+ if (NeedsContext()) {
+ max_context_chain_length += 1;
+ }
+ return max_context_chain_length;
+}
+
+
Scope* Scope::DeclarationScope() {
Scope* scope = this;
while (!scope->is_declaration_scope()) {
« no previous file with comments | « src/scopes.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698