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

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

Issue 2220293003: Remove two more special cases from Scope::MustAllocate(Variable*) (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebased Created 4 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
« no previous file with comments | « no previous file | no next file » | 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/bootstrapper.h" 10 #include "src/bootstrapper.h"
(...skipping 1284 matching lines...) Expand 10 before | Expand all | Expand 10 after
1295 *binding_kind = UNBOUND; 1295 *binding_kind = UNBOUND;
1296 var = 1296 var =
1297 is_function_scope() 1297 is_function_scope()
1298 ? AsDeclarationScope()->LookupFunctionVar(proxy->raw_name(), factory) 1298 ? AsDeclarationScope()->LookupFunctionVar(proxy->raw_name(), factory)
1299 : nullptr; 1299 : nullptr;
1300 if (var != NULL) { 1300 if (var != NULL) {
1301 *binding_kind = BOUND; 1301 *binding_kind = BOUND;
1302 } else if (outer_scope_ != nullptr && this != max_outer_scope) { 1302 } else if (outer_scope_ != nullptr && this != max_outer_scope) {
1303 var = outer_scope_->LookupRecursive(proxy, binding_kind, factory, 1303 var = outer_scope_->LookupRecursive(proxy, binding_kind, factory,
1304 max_outer_scope); 1304 max_outer_scope);
1305 if (*binding_kind == BOUND && (is_function_scope() || is_with_scope())) { 1305 if (*binding_kind == BOUND && is_function_scope()) {
1306 var->ForceContextAllocation(); 1306 var->ForceContextAllocation();
1307 } 1307 }
1308 } else { 1308 } else {
1309 DCHECK(is_script_scope() || this == max_outer_scope); 1309 DCHECK(is_script_scope() || this == max_outer_scope);
1310 } 1310 }
1311 1311
1312 // "this" can't be shadowed by "eval"-introduced bindings or by "with" scopes. 1312 // "this" can't be shadowed by "eval"-introduced bindings or by "with" scopes.
1313 // TODO(wingo): There are other variables in this category; add them. 1313 // TODO(wingo): There are other variables in this category; add them.
1314 bool name_can_be_shadowed = var == nullptr || !var->is_this(); 1314 bool name_can_be_shadowed = var == nullptr || !var->is_this();
1315 1315
1316 if (is_with_scope() && name_can_be_shadowed) { 1316 if (is_with_scope() && name_can_be_shadowed) {
1317 DCHECK(!already_resolved()); 1317 DCHECK(!already_resolved());
1318 // The current scope is a with scope, so the variable binding can not be 1318 // The current scope is a with scope, so the variable binding can not be
1319 // statically resolved. However, note that it was necessary to do a lookup 1319 // statically resolved. However, note that it was necessary to do a lookup
1320 // in the outer scope anyway, because if a binding exists in an outer scope, 1320 // in the outer scope anyway, because if a binding exists in an outer scope,
1321 // the associated variable has to be marked as potentially being accessed 1321 // the associated variable has to be marked as potentially being accessed
1322 // from inside of an inner with scope (the property may not be in the 'with' 1322 // from inside of an inner with scope (the property may not be in the 'with'
1323 // object). 1323 // object).
1324 if (var != NULL && proxy->is_assigned()) var->set_maybe_assigned(); 1324 if (var != NULL) {
1325 var->set_is_used();
1326 var->ForceContextAllocation();
1327 if (proxy->is_assigned()) var->set_maybe_assigned();
1328 }
1325 *binding_kind = DYNAMIC_LOOKUP; 1329 *binding_kind = DYNAMIC_LOOKUP;
1326 return NULL; 1330 return NULL;
1327 } else if (calls_sloppy_eval() && is_declaration_scope() && 1331 } else if (calls_sloppy_eval() && is_declaration_scope() &&
1328 !is_script_scope() && name_can_be_shadowed) { 1332 !is_script_scope() && name_can_be_shadowed) {
1329 // A variable binding may have been found in an outer scope, but the current 1333 // A variable binding may have been found in an outer scope, but the current
1330 // scope makes a sloppy 'eval' call, so the found variable may not be 1334 // scope makes a sloppy 'eval' call, so the found variable may not be
1331 // the correct one (the 'eval' may introduce a binding with the same name). 1335 // the correct one (the 'eval' may introduce a binding with the same name).
1332 // In that case, change the lookup result to reflect this situation. 1336 // In that case, change the lookup result to reflect this situation.
1333 // Only scopes that can host var bindings (declaration scopes) need be 1337 // Only scopes that can host var bindings (declaration scopes) need be
1334 // considered here (this excludes block and catch scopes), and variable 1338 // considered here (this excludes block and catch scopes), and variable
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1480 } 1484 }
1481 } 1485 }
1482 1486
1483 1487
1484 bool Scope::MustAllocate(Variable* var) { 1488 bool Scope::MustAllocate(Variable* var) {
1485 DCHECK(var->location() != VariableLocation::MODULE); 1489 DCHECK(var->location() != VariableLocation::MODULE);
1486 // Give var a read/write use if there is a chance it might be accessed 1490 // Give var a read/write use if there is a chance it might be accessed
1487 // via an eval() call. This is only possible if the variable has a 1491 // via an eval() call. This is only possible if the variable has a
1488 // visible name. 1492 // visible name.
1489 if ((var->is_this() || !var->raw_name()->IsEmpty()) && 1493 if ((var->is_this() || !var->raw_name()->IsEmpty()) &&
1490 (var->has_forced_context_allocation() || scope_calls_eval_ || 1494 (scope_calls_eval_ || inner_scope_calls_eval_ || is_catch_scope() ||
1491 inner_scope_calls_eval_ || is_catch_scope() || is_block_scope() ||
1492 is_script_scope())) { 1495 is_script_scope())) {
1493 var->set_is_used(); 1496 var->set_is_used();
1494 if (scope_calls_eval_ || inner_scope_calls_eval_) var->set_maybe_assigned(); 1497 if (scope_calls_eval_ || inner_scope_calls_eval_) var->set_maybe_assigned();
1495 } 1498 }
1499 DCHECK(!var->has_forced_context_allocation() || var->is_used());
1496 // Global variables do not need to be allocated. 1500 // Global variables do not need to be allocated.
1497 return !var->IsGlobalObjectProperty() && var->is_used(); 1501 return !var->IsGlobalObjectProperty() && var->is_used();
1498 } 1502 }
1499 1503
1500 1504
1501 bool Scope::MustAllocateInContext(Variable* var) { 1505 bool Scope::MustAllocateInContext(Variable* var) {
1502 // If var is accessed from an inner scope, or if there is a possibility 1506 // If var is accessed from an inner scope, or if there is a possibility
1503 // that it might be accessed from the current or an inner scope (through 1507 // that it might be accessed from the current or an inner scope (through
1504 // an eval() call or a runtime with lookup), it must be allocated in the 1508 // an eval() call or a runtime with lookup), it must be allocated in the
1505 // context. 1509 // context.
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
1774 function != NULL && function->proxy()->var()->IsContextSlot(); 1778 function != NULL && function->proxy()->var()->IsContextSlot();
1775 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - 1779 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() -
1776 (is_function_var_in_context ? 1 : 0); 1780 (is_function_var_in_context ? 1 : 0);
1777 } 1781 }
1778 1782
1779 1783
1780 int Scope::ContextGlobalCount() const { return num_global_slots(); } 1784 int Scope::ContextGlobalCount() const { return num_global_slots(); }
1781 1785
1782 } // namespace internal 1786 } // namespace internal
1783 } // namespace v8 1787 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698