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

Side by Side Diff: src/scopes.cc

Issue 422923004: Track usage of "this" and "arguments" in Scope (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased Created 6 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/scopes.h" 7 #include "src/scopes.h"
8 8
9 #include "src/accessors.h" 9 #include "src/accessors.h"
10 #include "src/bootstrapper.h" 10 #include "src/bootstrapper.h"
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 scope_type_ = scope_type; 153 scope_type_ = scope_type;
154 scope_name_ = ast_value_factory_->empty_string(); 154 scope_name_ = ast_value_factory_->empty_string();
155 dynamics_ = NULL; 155 dynamics_ = NULL;
156 receiver_ = NULL; 156 receiver_ = NULL;
157 function_ = NULL; 157 function_ = NULL;
158 arguments_ = NULL; 158 arguments_ = NULL;
159 illegal_redecl_ = NULL; 159 illegal_redecl_ = NULL;
160 scope_inside_with_ = false; 160 scope_inside_with_ = false;
161 scope_contains_with_ = false; 161 scope_contains_with_ = false;
162 scope_calls_eval_ = false; 162 scope_calls_eval_ = false;
163 scope_uses_this_ = false;
164 scope_uses_arguments_ = false;
163 // Inherit the strict mode from the parent scope. 165 // Inherit the strict mode from the parent scope.
164 strict_mode_ = outer_scope != NULL ? outer_scope->strict_mode_ : SLOPPY; 166 strict_mode_ = outer_scope != NULL ? outer_scope->strict_mode_ : SLOPPY;
165 outer_scope_calls_sloppy_eval_ = false; 167 outer_scope_calls_sloppy_eval_ = false;
166 inner_scope_calls_eval_ = false; 168 inner_scope_calls_eval_ = false;
169 inner_scope_uses_this_ = false;
170 inner_scope_uses_arguments_ = false;
167 force_eager_compilation_ = false; 171 force_eager_compilation_ = false;
168 force_context_allocation_ = (outer_scope != NULL && !is_function_scope()) 172 force_context_allocation_ = (outer_scope != NULL && !is_function_scope())
169 ? outer_scope->has_forced_context_allocation() : false; 173 ? outer_scope->has_forced_context_allocation() : false;
170 num_var_or_const_ = 0; 174 num_var_or_const_ = 0;
171 num_stack_slots_ = 0; 175 num_stack_slots_ = 0;
172 num_heap_slots_ = 0; 176 num_heap_slots_ = 0;
173 num_modules_ = 0; 177 num_modules_ = 0;
174 module_var_ = NULL, 178 module_var_ = NULL,
175 scope_info_ = scope_info; 179 scope_info_ = scope_info;
176 start_position_ = RelocInfo::kNoPosition; 180 start_position_ = RelocInfo::kNoPosition;
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 // Scope info. 879 // Scope info.
876 if (HasTrivialOuterContext()) { 880 if (HasTrivialOuterContext()) {
877 Indent(n1, "// scope has trivial outer context\n"); 881 Indent(n1, "// scope has trivial outer context\n");
878 } 882 }
879 if (strict_mode() == STRICT) { 883 if (strict_mode() == STRICT) {
880 Indent(n1, "// strict mode scope\n"); 884 Indent(n1, "// strict mode scope\n");
881 } 885 }
882 if (scope_inside_with_) Indent(n1, "// scope inside 'with'\n"); 886 if (scope_inside_with_) Indent(n1, "// scope inside 'with'\n");
883 if (scope_contains_with_) Indent(n1, "// scope contains 'with'\n"); 887 if (scope_contains_with_) Indent(n1, "// scope contains 'with'\n");
884 if (scope_calls_eval_) Indent(n1, "// scope calls 'eval'\n"); 888 if (scope_calls_eval_) Indent(n1, "// scope calls 'eval'\n");
889 if (scope_uses_this_) Indent(n1, "// scope uses 'this'\n");
890 if (scope_uses_arguments_) Indent(n1, "// scope uses 'arguments'\n");
891 if (inner_scope_uses_this_) Indent(n1, "// inner scope uses 'this'\n");
892 if (inner_scope_uses_arguments_) {
893 Indent(n1, "// inner scope uses 'arguments'\n");
894 }
885 if (outer_scope_calls_sloppy_eval_) { 895 if (outer_scope_calls_sloppy_eval_) {
886 Indent(n1, "// outer scope calls 'eval' in sloppy context\n"); 896 Indent(n1, "// outer scope calls 'eval' in sloppy context\n");
887 } 897 }
888 if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n"); 898 if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n");
889 if (num_stack_slots_ > 0) { Indent(n1, "// "); 899 if (num_stack_slots_ > 0) { Indent(n1, "// ");
890 PrintF("%d stack slots\n", num_stack_slots_); } 900 PrintF("%d stack slots\n", num_stack_slots_); }
891 if (num_heap_slots_ > 0) { Indent(n1, "// "); 901 if (num_heap_slots_ > 0) { Indent(n1, "// ");
892 PrintF("%d heap slots\n", num_heap_slots_); } 902 PrintF("%d heap slots\n", num_heap_slots_); }
893 903
894 // Print locals. 904 // Print locals.
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
1154 } 1164 }
1155 1165
1156 bool calls_sloppy_eval = 1166 bool calls_sloppy_eval =
1157 this->calls_sloppy_eval() || outer_scope_calls_sloppy_eval_; 1167 this->calls_sloppy_eval() || outer_scope_calls_sloppy_eval_;
1158 for (int i = 0; i < inner_scopes_.length(); i++) { 1168 for (int i = 0; i < inner_scopes_.length(); i++) {
1159 Scope* inner = inner_scopes_[i]; 1169 Scope* inner = inner_scopes_[i];
1160 inner->PropagateScopeInfo(calls_sloppy_eval); 1170 inner->PropagateScopeInfo(calls_sloppy_eval);
1161 if (inner->scope_calls_eval_ || inner->inner_scope_calls_eval_) { 1171 if (inner->scope_calls_eval_ || inner->inner_scope_calls_eval_) {
1162 inner_scope_calls_eval_ = true; 1172 inner_scope_calls_eval_ = true;
1163 } 1173 }
1174 if (inner->scope_uses_this_ || inner->inner_scope_uses_this_) {
1175 inner_scope_uses_this_ = true;
1176 }
1177 if (inner->scope_uses_arguments_ || inner->inner_scope_uses_arguments_) {
1178 inner_scope_uses_arguments_ = true;
1179 }
1164 if (inner->force_eager_compilation_) { 1180 if (inner->force_eager_compilation_) {
1165 force_eager_compilation_ = true; 1181 force_eager_compilation_ = true;
1166 } 1182 }
1167 } 1183 }
1168 } 1184 }
1169 1185
1170 1186
1171 bool Scope::MustAllocate(Variable* var) { 1187 bool Scope::MustAllocate(Variable* var) {
1172 // Give var a read/write use if there is a chance it might be accessed 1188 // Give var a read/write use if there is a chance it might be accessed
1173 // via an eval() call. This is only possible if the variable has a 1189 // via an eval() call. This is only possible if the variable has a
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1394 } 1410 }
1395 1411
1396 1412
1397 int Scope::ContextLocalCount() const { 1413 int Scope::ContextLocalCount() const {
1398 if (num_heap_slots() == 0) return 0; 1414 if (num_heap_slots() == 0) return 0;
1399 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - 1415 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS -
1400 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); 1416 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0);
1401 } 1417 }
1402 1418
1403 } } // namespace v8::internal 1419 } } // namespace v8::internal
OLDNEW
« src/ast-value-factory.h ('K') | « src/scopes.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698