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

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: Fix nits Created 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/scopes.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 asm_module_ = false; 165 asm_module_ = false;
164 asm_function_ = outer_scope != NULL && outer_scope->asm_module_; 166 asm_function_ = outer_scope != NULL && outer_scope->asm_module_;
165 // Inherit the strict mode from the parent scope. 167 // Inherit the strict mode from the parent scope.
166 strict_mode_ = outer_scope != NULL ? outer_scope->strict_mode_ : SLOPPY; 168 strict_mode_ = outer_scope != NULL ? outer_scope->strict_mode_ : SLOPPY;
167 outer_scope_calls_sloppy_eval_ = false; 169 outer_scope_calls_sloppy_eval_ = false;
168 inner_scope_calls_eval_ = false; 170 inner_scope_calls_eval_ = false;
171 inner_scope_uses_this_ = false;
172 inner_scope_uses_arguments_ = false;
169 force_eager_compilation_ = false; 173 force_eager_compilation_ = false;
170 force_context_allocation_ = (outer_scope != NULL && !is_function_scope()) 174 force_context_allocation_ = (outer_scope != NULL && !is_function_scope())
171 ? outer_scope->has_forced_context_allocation() : false; 175 ? outer_scope->has_forced_context_allocation() : false;
172 num_var_or_const_ = 0; 176 num_var_or_const_ = 0;
173 num_stack_slots_ = 0; 177 num_stack_slots_ = 0;
174 num_heap_slots_ = 0; 178 num_heap_slots_ = 0;
175 num_modules_ = 0; 179 num_modules_ = 0;
176 module_var_ = NULL, 180 module_var_ = NULL,
177 scope_info_ = scope_info; 181 scope_info_ = scope_info;
178 start_position_ = RelocInfo::kNoPosition; 182 start_position_ = RelocInfo::kNoPosition;
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 #ifdef DEBUG 776 #ifdef DEBUG
773 static const char* Header(ScopeType scope_type) { 777 static const char* Header(ScopeType scope_type) {
774 switch (scope_type) { 778 switch (scope_type) {
775 case EVAL_SCOPE: return "eval"; 779 case EVAL_SCOPE: return "eval";
776 case FUNCTION_SCOPE: return "function"; 780 case FUNCTION_SCOPE: return "function";
777 case MODULE_SCOPE: return "module"; 781 case MODULE_SCOPE: return "module";
778 case GLOBAL_SCOPE: return "global"; 782 case GLOBAL_SCOPE: return "global";
779 case CATCH_SCOPE: return "catch"; 783 case CATCH_SCOPE: return "catch";
780 case BLOCK_SCOPE: return "block"; 784 case BLOCK_SCOPE: return "block";
781 case WITH_SCOPE: return "with"; 785 case WITH_SCOPE: return "with";
786 case ARROW_SCOPE: return "arrow";
782 } 787 }
783 UNREACHABLE(); 788 UNREACHABLE();
784 return NULL; 789 return NULL;
785 } 790 }
786 791
787 792
788 static void Indent(int n, const char* str) { 793 static void Indent(int n, const char* str) {
789 PrintF("%*s%s", n, "", str); 794 PrintF("%*s%s", n, "", str);
790 } 795 }
791 796
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 // Scope info. 883 // Scope info.
879 if (HasTrivialOuterContext()) { 884 if (HasTrivialOuterContext()) {
880 Indent(n1, "// scope has trivial outer context\n"); 885 Indent(n1, "// scope has trivial outer context\n");
881 } 886 }
882 if (strict_mode() == STRICT) { 887 if (strict_mode() == STRICT) {
883 Indent(n1, "// strict mode scope\n"); 888 Indent(n1, "// strict mode scope\n");
884 } 889 }
885 if (scope_inside_with_) Indent(n1, "// scope inside 'with'\n"); 890 if (scope_inside_with_) Indent(n1, "// scope inside 'with'\n");
886 if (scope_contains_with_) Indent(n1, "// scope contains 'with'\n"); 891 if (scope_contains_with_) Indent(n1, "// scope contains 'with'\n");
887 if (scope_calls_eval_) Indent(n1, "// scope calls 'eval'\n"); 892 if (scope_calls_eval_) Indent(n1, "// scope calls 'eval'\n");
893 if (scope_uses_this_) Indent(n1, "// scope uses 'this'\n");
894 if (scope_uses_arguments_) Indent(n1, "// scope uses 'arguments'\n");
895 if (inner_scope_uses_this_) Indent(n1, "// inner scope uses 'this'\n");
896 if (inner_scope_uses_arguments_) {
897 Indent(n1, "// inner scope uses 'arguments'\n");
898 }
888 if (outer_scope_calls_sloppy_eval_) { 899 if (outer_scope_calls_sloppy_eval_) {
889 Indent(n1, "// outer scope calls 'eval' in sloppy context\n"); 900 Indent(n1, "// outer scope calls 'eval' in sloppy context\n");
890 } 901 }
891 if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n"); 902 if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n");
892 if (num_stack_slots_ > 0) { Indent(n1, "// "); 903 if (num_stack_slots_ > 0) { Indent(n1, "// ");
893 PrintF("%d stack slots\n", num_stack_slots_); } 904 PrintF("%d stack slots\n", num_stack_slots_); }
894 if (num_heap_slots_ > 0) { Indent(n1, "// "); 905 if (num_heap_slots_ > 0) { Indent(n1, "// ");
895 PrintF("%d heap slots\n", num_heap_slots_); } 906 PrintF("%d heap slots\n", num_heap_slots_); }
896 907
897 // Print locals. 908 // Print locals.
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 } 1170 }
1160 1171
1161 bool calls_sloppy_eval = 1172 bool calls_sloppy_eval =
1162 this->calls_sloppy_eval() || outer_scope_calls_sloppy_eval_; 1173 this->calls_sloppy_eval() || outer_scope_calls_sloppy_eval_;
1163 for (int i = 0; i < inner_scopes_.length(); i++) { 1174 for (int i = 0; i < inner_scopes_.length(); i++) {
1164 Scope* inner = inner_scopes_[i]; 1175 Scope* inner = inner_scopes_[i];
1165 inner->PropagateScopeInfo(calls_sloppy_eval); 1176 inner->PropagateScopeInfo(calls_sloppy_eval);
1166 if (inner->scope_calls_eval_ || inner->inner_scope_calls_eval_) { 1177 if (inner->scope_calls_eval_ || inner->inner_scope_calls_eval_) {
1167 inner_scope_calls_eval_ = true; 1178 inner_scope_calls_eval_ = true;
1168 } 1179 }
1180 // If the inner scope is an arrow function, propagate the flags tracking
1181 // usage of this/arguments, but do not propagate them out from normal
1182 // functions.
1183 if (!inner->is_function_scope() || inner->is_arrow_scope()) {
1184 if (inner->scope_uses_this_ || inner->inner_scope_uses_this_) {
1185 inner_scope_uses_this_ = true;
1186 }
1187 if (inner->scope_uses_arguments_ || inner->inner_scope_uses_arguments_) {
1188 inner_scope_uses_arguments_ = true;
1189 }
1190 }
1169 if (inner->force_eager_compilation_) { 1191 if (inner->force_eager_compilation_) {
1170 force_eager_compilation_ = true; 1192 force_eager_compilation_ = true;
1171 } 1193 }
1172 if (asm_module_ && inner->scope_type() == FUNCTION_SCOPE) { 1194 if (asm_module_ && inner->scope_type() == FUNCTION_SCOPE) {
1173 inner->asm_function_ = true; 1195 inner->asm_function_ = true;
1174 } 1196 }
1175 } 1197 }
1176 } 1198 }
1177 1199
1178 1200
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
1402 } 1424 }
1403 1425
1404 1426
1405 int Scope::ContextLocalCount() const { 1427 int Scope::ContextLocalCount() const {
1406 if (num_heap_slots() == 0) return 0; 1428 if (num_heap_slots() == 0) return 0;
1407 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - 1429 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS -
1408 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); 1430 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0);
1409 } 1431 }
1410 1432
1411 } } // namespace v8::internal 1433 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/scopes.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698