OLD | NEW |
---|---|
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 Loading... | |
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->scope_type() != SCRIPT_SCOPE && | |
417 scope->outer_scope()->GetReceiverScope()->is_script_scope()) { | |
Toon Verwaest
2016/08/31 08:56:55
Shouldn't this just be scope->GetReceiverScope()?
| |
418 info->script_scope()->DeclareDynamicGlobal( | |
419 info->ast_value_factory()->this_string(), Variable::THIS); | |
420 } | |
421 | |
414 scope->AllocateVariables(info, mode); | 422 scope->AllocateVariables(info, mode); |
415 | 423 |
416 #ifdef DEBUG | 424 #ifdef DEBUG |
417 if (info->script_is_native() ? FLAG_print_builtin_scopes | 425 if (info->script_is_native() ? FLAG_print_builtin_scopes |
418 : FLAG_print_scopes) { | 426 : FLAG_print_scopes) { |
419 scope->Print(); | 427 scope->Print(); |
420 } | 428 } |
421 scope->CheckScopePositions(); | 429 scope->CheckScopePositions(); |
422 scope->CheckZones(); | 430 scope->CheckZones(); |
423 #endif | 431 #endif |
(...skipping 1229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1653 Variable* function = | 1661 Variable* function = |
1654 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; | 1662 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; |
1655 bool is_function_var_in_context = | 1663 bool is_function_var_in_context = |
1656 function != nullptr && function->IsContextSlot(); | 1664 function != nullptr && function->IsContextSlot(); |
1657 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1665 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
1658 (is_function_var_in_context ? 1 : 0); | 1666 (is_function_var_in_context ? 1 : 0); |
1659 } | 1667 } |
1660 | 1668 |
1661 } // namespace internal | 1669 } // namespace internal |
1662 } // namespace v8 | 1670 } // namespace v8 |
OLD | NEW |