Lines Matching refs:scope

16 #include "src/logging/runtime-call-stats-scope.h"
19 #include "src/objects/scope-info.h"
49 Variable* VariableMap::Declare(Zone* zone, Scope* scope,
66 zone->New<Variable>(scope, name, mode, kind, initialization_flag,
253 // We don't really need to use the preparsed scope data; this is just to
300 // scope_info, as the parser expects that a catch scope always has the catch
385 DeclarationScope* scope = GetClosureScope();
386 return !scope->is_function_scope() || scope->has_simple_parameters();
404 for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) {
406 if (!scope->is_function_scope() ||
407 scope->AsDeclarationScope()->ShouldEagerCompile()) {
408 if (scope->ContainsAsmModule()) return true;
422 // Reconstruct the outer scope chain from a closure's context chain.
435 // For scope analysis, debug-evaluate is equivalent to a with scope.
441 // If we reach a script scope, it's the outermost scope. Install the
442 // scope info of this script context onto the existing script scope to
602 // In case of complex parameters the current scope is the body scope and the
603 // parameters are stored in the outer scope.
627 Scope* query_scope = sloppy_block_function->scope()->outer_scope();
634 // Don't use a generic cache scope, as the cache scope would be the outer
635 // scope and we terminate the iteration there anyway.
684 DeclarationScope* scope = info->literal()->scope();
688 if (scope->outer_scope() && !scope->outer_scope()->scope_info_.is_null()) {
693 if (scope->is_eval_scope() && is_sloppy(scope->language_mode())) {
695 scope->HoistSloppyBlockFunctions(&factory);
701 // 4) a class member initializer function scope
702 // 3) 4 function/eval in a scope that was already resolved.
703 DCHECK(scope->is_script_scope() || scope->outer_scope()->is_script_scope() ||
704 scope->IsReparsedMemberInitializerScope() ||
705 scope->outer_scope()->already_resolved_);
707 // The outer scope is never lazy.
708 scope->set_should_eager_compile();
710 if (scope->must_use_preparsed_scope_data_) {
711 DCHECK_EQ(scope->scope_type_, ScopeType::FUNCTION_SCOPE);
714 scope, info->ast_value_factory(), info->zone());
717 if (!scope->AllocateVariables(info)) return false;
718 scope->GetScriptScope()->RewriteReplGlobalVariables();
722 PrintF("Global scope:\n");
723 scope->Print();
725 scope->CheckScopePositions();
726 scope->CheckZones();
843 // Remove this scope from outer scope.
848 Scope* scope = inner_scope_;
849 scope->outer_scope_ = outer_scope();
850 while (scope->sibling_ != nullptr) {
851 scope = scope->sibling_;
852 scope->outer_scope_ = outer_scope();
854 scope->sibling_ = outer_scope()->inner_scope_;
868 // to this scope we would have had to bail out at the top.
875 // Mark scope as removed by making it its own sibling.
925 DCHECK_EQ(local->scope(), local->scope()->GetClosureScope());
926 DCHECK_NE(local->scope(), new_parent);
953 // The case where where the cache can be another scope is when the cache scope
954 // is the last scope that doesn't use an external cache.
1110 // Declare the variable in the declaration scope.
1115 // In a var binding in a sloppy direct eval, pollute the enclosing scope
1132 // The name was declared in this scope before; check for conflicting
1134 // not a var (in script scope, we also have to ignore legacy const for
1138 // for conflicting declarations within the same scope. This check also
1143 // because the var declaration is hoisted to the function scope where
1188 // Declare the variable in the declaration scope.
1251 DeclarationScope* scope = GetClosureScope();
1252 Variable* var = zone()->New<Variable>(scope, name, VariableMode::kTemporary,
1254 scope->AddLocal(var);
1263 // Lexical vs lexical conflicts within the same scope have already been
1268 Scope* current = decl->AsVariableDeclaration()->AsNested()->scope();
1271 // Iterate through all scopes until the declaration scope.
1293 // declaration scope. Check for conflicts between the eval scope that
1294 // declaration scope.
1300 // Iterate through all scopes until and including the declaration scope.
1303 // declaration scope in which this sloppy-eval runs.
1305 // Use the current scope as the cache, since the general cache would be
1306 // the end scope.
1323 const AstRawString* Scope::FindVariableDeclaredIn(Scope* scope,
1325 const VariableMap& variables = scope->variables_;
1362 if (!ResolveVariablesRecursively(info->scope())) {
1378 for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) {
1379 if (!scope->is_declaration_scope() ||
1380 !scope->AsDeclarationScope()->has_this_declaration()) {
1381 if (scope->HasThisReference()) return true;
1393 // allocation of the matching declarations. We can stop at the outer scope for
1419 int Scope::ContextChainLength(Scope* scope) const {
1421 for (const Scope* s = this; s != scope; s = s->outer_scope_) {
1422 DCHECK_NOT_NULL(s); // scope must be in the scope chain
1445 Scope* scope = this;
1446 while (!scope->is_declaration_scope()) {
1447 scope = scope->outer_scope();
1449 return scope->AsDeclarationScope();
1453 Scope* scope = this;
1454 while (!scope->is_declaration_scope() || scope->is_eval_scope()) {
1455 scope = scope->outer_scope();
1457 return scope->AsDeclarationScope();
1461 const Scope* scope = this;
1462 while (!scope->is_declaration_scope() || scope->is_block_scope()) {
1463 scope = scope->outer_scope();
1465 return scope->AsDeclarationScope();
1469 Scope* scope = this;
1470 while (!scope->is_declaration_scope() || scope->is_block_scope()) {
1471 scope = scope->outer_scope();
1473 return scope->AsDeclarationScope();
1479 // The debugger expects all functions to have scope infos.
1490 Scope* scope = this;
1491 while (!scope->is_declaration_scope() ||
1492 (!scope->is_script_scope() &&
1493 !scope->AsDeclarationScope()->has_this_declaration())) {
1494 scope = scope->outer_scope();
1496 return scope->AsDeclarationScope();
1500 Scope* scope = this;
1501 while (scope != nullptr && !scope->IsConstructorScope()) {
1502 scope = scope->outer_scope();
1504 if (scope == nullptr) {
1507 DCHECK(scope->IsConstructorScope());
1508 return scope->AsDeclarationScope();
1512 Scope* scope = this;
1513 while (scope != nullptr && !scope->is_home_object_scope()) {
1514 if (scope->is_function_scope()) {
1515 FunctionKind function_kind = scope->AsDeclarationScope()->function_kind();
1524 if (scope->private_name_lookup_skips_outer_class()) {
1525 DCHECK(scope->outer_scope()->is_class_scope());
1526 scope = scope->outer_scope()->outer_scope();
1528 scope = scope->outer_scope();
1531 return scope;
1535 Scope* scope = this;
1536 while (!scope->is_script_scope()) {
1537 scope = scope->outer_scope();
1539 return scope->AsDeclarationScope();
1543 Scope* scope = outer_scope_;
1544 while (scope && !scope->NeedsContext()) {
1545 scope = scope->outer_scope();
1547 return scope;
1551 bool WasLazilyParsed(Scope* scope) {
1552 return scope->is_declaration_scope() &&
1553 scope->AsDeclarationScope()->was_lazily_parsed();
1560 Scope* scope = this;
1562 Iteration iteration = callback(scope);
1564 if ((iteration == Iteration::kDescend) && scope->inner_scope_ != nullptr) {
1565 scope = scope->inner_scope_;
1567 // Find the next outer scope with a sibling.
1568 while (scope->sibling_ == nullptr) {
1569 if (scope == this) return;
1570 scope = scope->outer_scope_;
1572 if (scope == this) return;
1573 scope = scope->sibling_;
1584 Scope* scope = other;
1585 while (scope) {
1586 if (scope == this) return true;
1587 scope = scope->outer_scope();
1594 this->ForEach([max_outer_scope, isolate, non_locals](Scope* scope) {
1597 if (scope->is_module_scope()) {
1598 scope->AsModuleScope()->AllocateModuleVariables();
1604 Scope* lookup = WasLazilyParsed(scope) ? scope->outer_scope() : scope;
1606 for (VariableProxy* proxy : scope->unresolved_list_) {
1616 scope->ResolveTo(proxy, var);
1617 if (!var->is_dynamic() && lookup != scope)
1623 scope->unresolved_list_.Clear();
1633 maybe_in_arrowhead](Scope* scope) {
1634 DCHECK_IMPLIES(scope->is_declaration_scope(),
1635 !scope->AsDeclarationScope()->was_lazily_parsed());
1637 for (VariableProxy* proxy = scope->unresolved_list_.first();
1642 Lookup<kParsedScope>(proxy, scope, max_outer_scope->outer_scope());
1644 // Don't copy unresolved references to the script scope, unless it's a
1659 scope->unresolved_list_.Clear();
1686 // Make sure this scope and zone aren't used for allocation anymore.
1695 // Prepare scope for use in the outer zone.
1714 // logic ensures that the scope allocation data is consistent with the
1724 this->ForEach([parser](Scope* scope) {
1725 if (scope->IsSkippableFunctionScope()) {
1726 scope->AsDeclarationScope()->SavePreparseDataForDeclarationScope(parser);
1762 PrintF("Inner function scope:\n");
1935 Indent(n1, "// strict mode scope\n");
1938 if (IsAsmModule()) Indent(n1, "// scope is an asm module\n");
1942 Indent(n1, "// scope calls sloppy 'eval'\n");
1945 Indent(n1, "// scope skips outer class for #-names\n");
1947 if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n");
1949 DeclarationScope* scope = AsDeclarationScope();
1950 if (scope->was_lazily_parsed()) Indent(n1, "// lazily parsed\n");
1951 if (scope->ShouldEagerCompile()) Indent(n1, "// will be compiled\n");
1952 if (scope->needs_private_name_context_chain_recalc()) {
1956 PrintF("%s\n", FunctionKind2String(scope->function_kind()));
1957 if (scope->class_scope_has_private_brand()) {
1958 Indent(n1, "// class scope has private brand\n");
2018 for (Scope* scope = inner_scope_; scope != nullptr;
2019 scope = scope->sibling_) {
2021 scope->Print(n1);
2029 this->ForEach([](Scope* scope) {
2031 if (!scope->is_hidden() && scope->inner_scope_ == nullptr) {
2032 DCHECK_NE(kNoSourcePosition, scope->start_position());
2033 DCHECK_NE(kNoSourcePosition, scope->end_position());
2041 this->ForEach([](Scope* scope) {
2042 if (WasLazilyParsed(scope)) {
2043 DCHECK_NULL(scope->zone());
2044 DCHECK_NULL(scope->inner_scope_);
2066 Variable* Scope::Lookup(VariableProxy* proxy, Scope* scope,
2069 // If we have already passed the cache scope in earlier recursions, we should
2070 // first quickly check if the current scope uses the cache scope before
2073 scope->deserialized_scope_uses_external_cache()) {
2079 DCHECK_IMPLIES(mode == kParsedScope, !scope->is_debug_evaluate_scope_);
2080 // Short-cut: whenever we find a debug-evaluate scope, just look everything
2081 // up dynamically. Debug-evaluate doesn't properly create scope info for the
2088 V8_UNLIKELY(scope->is_debug_evaluate_scope_)) {
2089 DCHECK(scope->deserialized_scope_uses_external_cache() ||
2090 scope == cache_scope);
2094 // Try to find the variable in this scope.
2097 var = scope->LookupLocal(proxy->raw_name());
2100 bool external_cache = scope->deserialized_scope_uses_external_cache();
2102 // Check the cache on each deserialized scope, up to the main cache
2103 // scope when we get to it (we may still have deserialized scopes
2106 var = scope->variables_.Lookup(proxy->raw_name());
2109 var = scope->LookupInScopeInfo(proxy->raw_name(),
2110 external_cache ? cache_scope : scope);
2114 // scope which introduces the same variable again, the resulting variable
2124 // living in a different scope to the current one, or some other
2127 !(scope->is_eval_scope() && var->mode() == VariableMode::kDynamic)) {
2135 if (scope->outer_scope_ == outer_scope_end) break;
2137 DCHECK(!scope->is_script_scope());
2138 if (V8_UNLIKELY(scope->is_with_scope())) {
2139 return LookupWith(proxy, scope, outer_scope_end, cache_scope,
2143 scope->is_declaration_scope() &&
2144 scope->AsDeclarationScope()->sloppy_eval_can_extend_vars())) {
2145 return LookupSloppyEval(proxy, scope, outer_scope_end, cache_scope,
2149 force_context_allocation |= scope->is_function_scope();
2150 scope = scope->outer_scope_;
2153 if (mode == kParsedScope && !scope->scope_info_.is_null()) {
2155 cache_scope = scope->GetNonEvalDeclarationScope();
2156 return Lookup<kDeserializedScope>(proxy, scope, outer_scope_end,
2162 // declare them in the outer scope.
2164 if (mode == kParsedScope && !scope->is_script_scope()) {
2169 return scope->AsDeclarationScope()->DeclareDynamicGlobal(
2171 mode == kDeserializedScope ? cache_scope : scope);
2175 VariableProxy* proxy, Scope* scope, Scope* outer_scope_end,
2178 VariableProxy* proxy, Scope* scope, Scope* outer_scope_end,
2181 Variable* Scope::LookupWith(VariableProxy* proxy, Scope* scope,
2184 DCHECK(scope->is_with_scope());
2187 scope->outer_scope_->scope_info_.is_null()
2188 ? Lookup<kParsedScope>(proxy, scope->outer_scope_, outer_scope_end,
2190 : Lookup<kDeserializedScope>(proxy, scope->outer_scope_,
2195 // The current scope is a with scope, so the variable binding can not be
2197 // in the outer scope anyway, because if a binding exists in an outer
2198 // scope, the associated variable has to be marked as potentially being
2199 // accessed from inside of an inner with scope (the property may not be in
2202 DCHECK(!scope->already_resolved_);
2208 if (scope->deserialized_scope_uses_external_cache()) {
2213 target_scope = scope;
2221 Variable* Scope::LookupSloppyEval(VariableProxy* proxy, Scope* scope,
2224 DCHECK(scope->is_declaration_scope() &&
2225 scope->AsDeclarationScope()->sloppy_eval_can_extend_vars());
2227 // If we're compiling eval, it's possible that the outer scope is the first
2228 // ScopeInfo-backed scope. We use the next declaration scope as the cache for
2232 ? scope->outer_scope()->GetNonEvalDeclarationScope()
2235 scope->outer_scope_->scope_info_.is_null()
2236 ? Lookup<kParsedScope>(proxy, scope->outer_scope_, outer_scope_end,
2238 : Lookup<kDeserializedScope>(proxy, scope->outer_scope_,
2242 // We may not want to use the cache scope, change it back to the given scope
2244 if (!scope->deserialized_scope_uses_external_cache()) {
2245 // For a deserialized scope, we'll be replacing the cache_scope.
2246 DCHECK_IMPLIES(!scope->scope_info_.is_null(), cache_scope != nullptr);
2247 cache_scope = scope;
2250 // A variable binding may have been found in an outer scope, but the current
2251 // scope makes a sloppy 'eval' call, so the found variable may not be the
2256 // script scope are always dynamic.
2258 Scope* target = cache_scope == nullptr ? scope : cache_scope;
2267 Scope* target = cache_scope == nullptr ? scope : cache_scope;
2288 void UpdateNeedsHoleCheck(Variable* var, VariableProxy* proxy, Scope* scope) {
2295 return UpdateNeedsHoleCheck(var->local_if_not_shadowed(), proxy, scope);
2310 // the same declaration scope (i.e. they are both in global code, in the same
2313 // initializer cannot be skipped due to a nonlinear scope.
2323 // The scope of the variable needs to be checked, in case the use is
2325 if (var->scope()->GetClosureScope() != scope->GetClosureScope()) {
2333 if (var->scope()->is_nonlinear() ||
2347 void Scope::ResolvePreparsedVariable(VariableProxy* proxy, Scope* scope,
2350 for (; scope != end; scope = scope->outer_scope_) {
2351 Variable* var = scope->LookupLocal(proxy->raw_name());
2369 // Resolve in all parsed scopes except for the script scope.
2376 // Resolve unresolved variables for this scope.
2382 for (Scope* scope = inner_scope_; scope != nullptr;
2383 scope = scope->sibling_) {
2384 if (!scope->ResolveVariablesRecursively(end)) return false;
2407 // If var is accessed from an inner scope, or if there is a possibility
2408 // that it might be accessed from the current or an inner scope (through
2466 DCHECK_EQ(this, var->scope());
2493 DCHECK_EQ(receiver()->scope(), this);
2498 DCHECK_EQ(var->scope(), this);
2539 // ScopeInfo::ScopeInfo(FunctionScope* scope) constructor).
2572 this->ForEach([](Scope* scope) -> Iteration {
2573 DCHECK(!scope->already_resolved_);
2574 if (WasLazilyParsed(scope)) return Iteration::kContinue;
2575 if (scope->sloppy_eval_can_extend_vars_) {
2576 scope->num_heap_slots_ = Context::MIN_CONTEXT_EXTENDED_SLOTS;
2578 DCHECK_EQ(scope->ContextHeaderLength(), scope->num_heap_slots_);
2580 // Allocate variables for this scope.
2582 if (scope->is_declaration_scope()) {
2583 scope->AsDeclarationScope()->AllocateReceiver();
2584 if (scope->is_function_scope()) {
2585 scope->AsDeclarationScope()->AllocateParameterLocals();
2588 scope->AllocateNonParameterLocalsAndDeclaredGlobals();
2590 // Force allocation of a context for this scope if necessary. For a 'with'
2591 // scope and for a function scope that makes an 'eval' call we need a
2593 // scope. Likewise for modules and function scopes representing asm.js
2594 // modules. Also force a context, if the scope is stricter than the outer
2595 // scope.
2597 scope->is_with_scope() || scope->is_module_scope() ||
2599 scope->IsAsmModule() ||
2601 scope->ForceContextForLanguageMode() ||
2602 (scope->is_function_scope() &&
2603 scope->AsDeclarationScope()->sloppy_eval_can_extend_vars()) ||
2604 (scope->is_block_scope() && scope->is_declaration_scope() &&
2605 scope->AsDeclarationScope()->sloppy_eval_can_extend_vars());
2609 if (scope->num_heap_slots_ == scope->ContextHeaderLength() &&
2611 scope->num_heap_slots_ = 0;
2615 DCHECK(scope->num_heap_slots_ == 0 ||
2616 scope->num_heap_slots_ >= scope->ContextHeaderLength());
2630 // the next outer scope that needs a context.
2635 for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) {
2636 if (!scope->is_function_scope() ||
2637 scope->AsDeclarationScope()->ShouldEagerCompile()) {
2638 scope->AllocateScopeInfosRecursively(isolate, next_outer_scope);
2651 // The outermost scope in a class heritage expression is marked to skip the
2652 // class scope during private name resolution. It is possible, however, that
2653 // either the class scope won't require a Context and ScopeInfo, or the
2654 // outermost scope in the heritage position won't. Simply copying the bit from
2656 // case the scope that is marked to skip its outer scope will incorrectly skip
2657 // a different class scope than the one we intended to skip. In the latter
2658 // case variables resolved through an inner scope will incorrectly check the
2659 // class scope since we lost the skip bit from the outermost heritage scope.
2664 this->ForEach([](Scope* scope) {
2665 Scope* outer = scope->outer_scope();
2668 scope->private_name_lookup_skips_outer_class_ =
2671 if (!scope->is_function_scope() ||
2672 scope->AsDeclarationScope()->ShouldEagerCompile()) {
2681 DeclarationScope* scope;
2682 for (scope = this; scope != nullptr;
2683 scope = scope->outer_scope() != nullptr
2684 ? scope->outer_scope()->GetClosureScope()
2686 if (scope->needs_private_name_context_chain_recalc_) return;
2687 scope->needs_private_name_context_chain_recalc_ = true;
2694 DeclarationScope* scope = info->literal()->scope();
2696 // No one else should have allocated a scope info for this scope yet.
2697 DCHECK(scope->scope_info_.is_null());
2700 if (scope->outer_scope_ != nullptr) {
2702 outer_scope = scope->outer_scope_->scope_info_;
2705 if (scope->needs_private_name_context_chain_recalc()) {
2706 scope->RecalcPrivateNameContextChain();
2708 scope->AllocateScopeInfosRecursively(isolate, outer_scope);
2710 // The debugger expects all shared function infos to contain a scope info.
2711 // Since the top-most scope will end up in a shared function info, make sure
2712 // it has one, even if it doesn't need a scope info.
2714 if (scope->scope_info_.is_null()) {
2715 scope->scope_info_ =
2716 ScopeInfo::Create(isolate, scope->zone(), scope, outer_scope);
2719 // Ensuring that the outer script scope has a scope info avoids having
2749 // The super.foo property access is logically nested under C's class scope,
2751 // super.bar(). However, super.foo must resolve super in C's outer scope.
2754 // on the Scope that needs the home object instead of the innermost scope.
2775 // the unresolved list of the home object scope, which is not necessarily the
2776 // innermost scope.
2798 // the reparsed instance member initializer scope.
2808 // the class scope from ScopeInfo, so that we don't need to run
2946 ClassScope* scope = scope_iter.GetScope();
2948 // try the deseralized scope info.
2949 Variable* var = scope->LookupLocalPrivateName(proxy->raw_name());
2950 if (var == nullptr && !scope->scope_info_.is_null()) {
2951 var = scope->LookupPrivateNameInScopeInfo(proxy->raw_name());
3001 // an outer private name scope, then we are certain any private name access
3014 // If we can find private name in the current class scope, we can bind
3030 // If the current scope does not have declared private names,
3031 // try looking from the outer class scope later.
3033 // There's no outer private name scope so we are certain that the variable
3039 // The private name may be found later in the outer private name scope, so
3094 Scope* scope = inner->outer_scope();
3095 while (scope != nullptr) {
3096 if (scope->is_class_scope()) {
3098 current_scope_ = scope;
3103 inner = scope;
3104 scope = scope->outer_scope();
3111 // because the class scope is deserialized while the function scope inside may
3116 // Any closure scope that contain uses of private names that skips over a
3117 // class scope due to heritage expressions need private name context chain