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

Side by Side Diff: src/ast/scopes.cc

Issue 2583163002: Force ctxt allocation in eval scopes. (Closed)
Patch Set: moar Created 3 years, 11 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
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-5736.js » ('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/ast/scopes.h" 5 #include "src/ast/scopes.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "src/accessors.h" 9 #include "src/accessors.h"
10 #include "src/ast/ast.h" 10 #include "src/ast/ast.h"
(...skipping 1160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1171 1171
1172 bool Scope::AllowsLazyParsingWithoutUnresolvedVariables( 1172 bool Scope::AllowsLazyParsingWithoutUnresolvedVariables(
1173 const Scope* outer) const { 1173 const Scope* outer) const {
1174 // If none of the outer scopes need to decide whether to context allocate 1174 // If none of the outer scopes need to decide whether to context allocate
1175 // specific variables, we can preparse inner functions without unresolved 1175 // specific variables, we can preparse inner functions without unresolved
1176 // variables. Otherwise we need to find unresolved variables to force context 1176 // variables. Otherwise we need to find unresolved variables to force context
1177 // allocation of the matching declarations. We can stop at the outer scope for 1177 // allocation of the matching declarations. We can stop at the outer scope for
1178 // the parse, since context allocation of those variables is already 1178 // the parse, since context allocation of those variables is already
1179 // guaranteed to be correct. 1179 // guaranteed to be correct.
1180 for (const Scope* s = this; s != outer; s = s->outer_scope_) { 1180 for (const Scope* s = this; s != outer; s = s->outer_scope_) {
1181 if (s->is_eval_scope()) return false; 1181 // Eval forces context allocation on all outer scopes, so we don't need to
1182 // look at those scopes. Sloppy eval makes top-level non-lexical variables
1183 // dynamic, whereas strict-mode requires context allocation.
1184 if (s->is_eval_scope()) return is_sloppy(s->language_mode());
1182 // Catch scopes force context allocation of all variables. 1185 // Catch scopes force context allocation of all variables.
1183 if (s->is_catch_scope()) continue; 1186 if (s->is_catch_scope()) continue;
1184 // With scopes do not introduce variables that need allocation. 1187 // With scopes do not introduce variables that need allocation.
1185 if (s->is_with_scope()) continue; 1188 if (s->is_with_scope()) continue;
1186 // If everything is guaranteed to be context allocated we can ignore the 1189 // If everything is guaranteed to be context allocated we can ignore the
1187 // scope. 1190 // scope.
1188 if (s->has_forced_context_allocation()) continue; 1191 if (s->has_forced_context_allocation()) continue;
1189 // Only block scopes and function scopes should disallow preparsing. 1192 // Only block scopes and function scopes should disallow preparsing.
1190 DCHECK(s->is_block_scope() || s->is_function_scope()); 1193 DCHECK(s->is_block_scope() || s->is_function_scope());
1191 return false; 1194 return false;
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after
1881 // an eval() call or a runtime with lookup), it must be allocated in the 1884 // an eval() call or a runtime with lookup), it must be allocated in the
1882 // context. 1885 // context.
1883 // 1886 //
1884 // Exceptions: If the scope as a whole has forced context allocation, all 1887 // Exceptions: If the scope as a whole has forced context allocation, all
1885 // variables will have context allocation, even temporaries. Otherwise 1888 // variables will have context allocation, even temporaries. Otherwise
1886 // temporary variables are always stack-allocated. Catch-bound variables are 1889 // temporary variables are always stack-allocated. Catch-bound variables are
1887 // always context-allocated. 1890 // always context-allocated.
1888 if (has_forced_context_allocation()) return true; 1891 if (has_forced_context_allocation()) return true;
1889 if (var->mode() == TEMPORARY) return false; 1892 if (var->mode() == TEMPORARY) return false;
1890 if (is_catch_scope()) return true; 1893 if (is_catch_scope()) return true;
1891 if (is_script_scope() && IsLexicalVariableMode(var->mode())) return true; 1894 if ((is_script_scope() || is_eval_scope()) &&
1895 IsLexicalVariableMode(var->mode())) {
1896 return true;
1897 }
1892 return var->has_forced_context_allocation() || inner_scope_calls_eval_; 1898 return var->has_forced_context_allocation() || inner_scope_calls_eval_;
1893 } 1899 }
1894 1900
1895 1901
1896 void Scope::AllocateStackSlot(Variable* var) { 1902 void Scope::AllocateStackSlot(Variable* var) {
1897 if (is_block_scope()) { 1903 if (is_block_scope()) {
1898 outer_scope()->GetDeclarationScope()->AllocateStackSlot(var); 1904 outer_scope()->GetDeclarationScope()->AllocateStackSlot(var);
1899 } else { 1905 } else {
1900 var->AllocateTo(VariableLocation::LOCAL, num_stack_slots_++); 1906 var->AllocateTo(VariableLocation::LOCAL, num_stack_slots_++);
1901 } 1907 }
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
2122 Variable* function = 2128 Variable* function =
2123 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; 2129 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr;
2124 bool is_function_var_in_context = 2130 bool is_function_var_in_context =
2125 function != nullptr && function->IsContextSlot(); 2131 function != nullptr && function->IsContextSlot();
2126 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - 2132 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS -
2127 (is_function_var_in_context ? 1 : 0); 2133 (is_function_var_in_context ? 1 : 0);
2128 } 2134 }
2129 2135
2130 } // namespace internal 2136 } // namespace internal
2131 } // namespace v8 2137 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-5736.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698