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

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: Do not propagate inner_uses_$foo out of normal functions, more tests 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
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:
rossberg 2014/10/15 12:56:32 Nit: no newline
aperez 2014/10/15 17:09:51 Acknowledged.
787 return "arrow";
782 } 788 }
783 UNREACHABLE(); 789 UNREACHABLE();
784 return NULL; 790 return NULL;
785 } 791 }
786 792
787 793
788 static void Indent(int n, const char* str) { 794 static void Indent(int n, const char* str) {
789 PrintF("%*s%s", n, "", str); 795 PrintF("%*s%s", n, "", str);
790 } 796 }
791 797
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 // Scope info. 884 // Scope info.
879 if (HasTrivialOuterContext()) { 885 if (HasTrivialOuterContext()) {
880 Indent(n1, "// scope has trivial outer context\n"); 886 Indent(n1, "// scope has trivial outer context\n");
881 } 887 }
882 if (strict_mode() == STRICT) { 888 if (strict_mode() == STRICT) {
883 Indent(n1, "// strict mode scope\n"); 889 Indent(n1, "// strict mode scope\n");
884 } 890 }
885 if (scope_inside_with_) Indent(n1, "// scope inside 'with'\n"); 891 if (scope_inside_with_) Indent(n1, "// scope inside 'with'\n");
886 if (scope_contains_with_) Indent(n1, "// scope contains 'with'\n"); 892 if (scope_contains_with_) Indent(n1, "// scope contains 'with'\n");
887 if (scope_calls_eval_) Indent(n1, "// scope calls 'eval'\n"); 893 if (scope_calls_eval_) Indent(n1, "// scope calls 'eval'\n");
894 if (scope_uses_this_) Indent(n1, "// scope uses 'this'\n");
895 if (scope_uses_arguments_) Indent(n1, "// scope uses 'arguments'\n");
896 if (inner_scope_uses_this_) Indent(n1, "// inner scope uses 'this'\n");
897 if (inner_scope_uses_arguments_) {
898 Indent(n1, "// inner scope uses 'arguments'\n");
899 }
888 if (outer_scope_calls_sloppy_eval_) { 900 if (outer_scope_calls_sloppy_eval_) {
889 Indent(n1, "// outer scope calls 'eval' in sloppy context\n"); 901 Indent(n1, "// outer scope calls 'eval' in sloppy context\n");
890 } 902 }
891 if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n"); 903 if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n");
892 if (num_stack_slots_ > 0) { Indent(n1, "// "); 904 if (num_stack_slots_ > 0) { Indent(n1, "// ");
893 PrintF("%d stack slots\n", num_stack_slots_); } 905 PrintF("%d stack slots\n", num_stack_slots_); }
894 if (num_heap_slots_ > 0) { Indent(n1, "// "); 906 if (num_heap_slots_ > 0) { Indent(n1, "// ");
895 PrintF("%d heap slots\n", num_heap_slots_); } 907 PrintF("%d heap slots\n", num_heap_slots_); }
896 908
897 // Print locals. 909 // Print locals.
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 } 1171 }
1160 1172
1161 bool calls_sloppy_eval = 1173 bool calls_sloppy_eval =
1162 this->calls_sloppy_eval() || outer_scope_calls_sloppy_eval_; 1174 this->calls_sloppy_eval() || outer_scope_calls_sloppy_eval_;
1163 for (int i = 0; i < inner_scopes_.length(); i++) { 1175 for (int i = 0; i < inner_scopes_.length(); i++) {
1164 Scope* inner = inner_scopes_[i]; 1176 Scope* inner = inner_scopes_[i];
1165 inner->PropagateScopeInfo(calls_sloppy_eval); 1177 inner->PropagateScopeInfo(calls_sloppy_eval);
1166 if (inner->scope_calls_eval_ || inner->inner_scope_calls_eval_) { 1178 if (inner->scope_calls_eval_ || inner->inner_scope_calls_eval_) {
1167 inner_scope_calls_eval_ = true; 1179 inner_scope_calls_eval_ = true;
1168 } 1180 }
1181 // If the inner scope is an arrow function, propagate the flags tracking
1182 // usage of this/arguments, but do not propagate them out from normal
1183 // functions.
1184 if (inner->is_arrow_scope() || !inner->is_function_scope()) {
rossberg 2014/10/15 12:56:32 Nit: switch around the two conditions (the more ge
aperez 2014/10/15 17:09:51 Acknowledged.
1185 if (inner->scope_uses_this_ || inner->inner_scope_uses_this_) {
1186 inner_scope_uses_this_ = true;
1187 }
1188 if (inner->scope_uses_arguments_ || inner->inner_scope_uses_arguments_) {
1189 inner_scope_uses_arguments_ = true;
1190 }
1191 }
1169 if (inner->force_eager_compilation_) { 1192 if (inner->force_eager_compilation_) {
1170 force_eager_compilation_ = true; 1193 force_eager_compilation_ = true;
1171 } 1194 }
1172 if (asm_module_ && inner->scope_type() == FUNCTION_SCOPE) { 1195 if (asm_module_ && inner->scope_type() == FUNCTION_SCOPE) {
1173 inner->asm_function_ = true; 1196 inner->asm_function_ = true;
1174 } 1197 }
1175 } 1198 }
1176 } 1199 }
1177 1200
1178 1201
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
1402 } 1425 }
1403 1426
1404 1427
1405 int Scope::ContextLocalCount() const { 1428 int Scope::ContextLocalCount() const {
1406 if (num_heap_slots() == 0) return 0; 1429 if (num_heap_slots() == 0) return 0;
1407 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - 1430 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS -
1408 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); 1431 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0);
1409 } 1432 }
1410 1433
1411 } } // namespace v8::internal 1434 } } // namespace v8::internal
OLDNEW
« src/objects.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