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

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

Issue 2298673002: Move pre-declaring the this variable to Scope::Analyze (Closed)
Patch Set: updates Created 4 years, 3 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 | src/parsing/parser.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/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 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 DeclarationScope* scope = info->literal()->scope(); 404 DeclarationScope* scope = info->literal()->scope();
405 405
406 // We are compiling one of three cases: 406 // We are compiling one of three cases:
407 // 1) top-level code, 407 // 1) top-level code,
408 // 2) a function/eval/module on the top-level 408 // 2) a function/eval/module on the top-level
409 // 3) a function/eval in a scope that was already resolved. 409 // 3) a function/eval in a scope that was already resolved.
410 DCHECK(scope->scope_type() == SCRIPT_SCOPE || 410 DCHECK(scope->scope_type() == SCRIPT_SCOPE ||
411 scope->outer_scope()->scope_type() == SCRIPT_SCOPE || 411 scope->outer_scope()->scope_type() == SCRIPT_SCOPE ||
412 scope->outer_scope()->already_resolved_); 412 scope->outer_scope()->already_resolved_);
413 413
414 // If there's a chance that there's a reference to global 'this', predeclare
415 // it as a dynamic global on the script scope.
416 if (scope->GetReceiverScope()->is_script_scope()) {
417 info->script_scope()->DeclareDynamicGlobal(
418 info->ast_value_factory()->this_string(), Variable::THIS);
419 }
420
414 scope->AllocateVariables(info, mode); 421 scope->AllocateVariables(info, mode);
415 422
416 #ifdef DEBUG 423 #ifdef DEBUG
417 if (info->script_is_native() ? FLAG_print_builtin_scopes 424 if (info->script_is_native() ? FLAG_print_builtin_scopes
418 : FLAG_print_scopes) { 425 : FLAG_print_scopes) {
419 scope->Print(); 426 scope->Print();
420 } 427 }
421 scope->CheckScopePositions(); 428 scope->CheckScopePositions();
422 scope->CheckZones(); 429 scope->CheckZones();
423 #endif 430 #endif
(...skipping 1229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1653 Variable* function = 1660 Variable* function =
1654 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; 1661 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr;
1655 bool is_function_var_in_context = 1662 bool is_function_var_in_context =
1656 function != nullptr && function->IsContextSlot(); 1663 function != nullptr && function->IsContextSlot();
1657 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - 1664 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS -
1658 (is_function_var_in_context ? 1 : 0); 1665 (is_function_var_in_context ? 1 : 0);
1659 } 1666 }
1660 1667
1661 } // namespace internal 1668 } // namespace internal
1662 } // namespace v8 1669 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/parsing/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698