| 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 "src/accessors.h" |     7 #include "src/accessors.h" | 
|     8 #include "src/ast/scopeinfo.h" |     8 #include "src/ast/scopeinfo.h" | 
|     9 #include "src/bootstrapper.h" |     9 #include "src/bootstrapper.h" | 
|    10 #include "src/messages.h" |    10 #include "src/messages.h" | 
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|    77   Vector* delegates = static_cast<Vector*>(p->value); |    77   Vector* delegates = static_cast<Vector*>(p->value); | 
|    78   delegates->push_back(stmt); |    78   delegates->push_back(stmt); | 
|    79 } |    79 } | 
|    80  |    80  | 
|    81  |    81  | 
|    82 // ---------------------------------------------------------------------------- |    82 // ---------------------------------------------------------------------------- | 
|    83 // Implementation of Scope |    83 // Implementation of Scope | 
|    84  |    84  | 
|    85 Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type, |    85 Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type, | 
|    86              FunctionKind function_kind) |    86              FunctionKind function_kind) | 
|    87     : inner_scopes_(4, zone), |    87     : outer_scope_(outer_scope), | 
 |    88       inner_scopes_(4, zone), | 
 |    89       scope_type_(scope_type), | 
 |    90       function_kind_(function_kind), | 
|    88       variables_(zone), |    91       variables_(zone), | 
|    89       temps_(4, zone), |    92       temps_(4, zone), | 
|    90       params_(4, zone), |    93       params_(4, zone), | 
|    91       unresolved_(nullptr), |  | 
|    92       decls_(4, zone), |    94       decls_(4, zone), | 
|    93       module_descriptor_(scope_type == MODULE_SCOPE ? new (zone) |    95       module_descriptor_(scope_type == MODULE_SCOPE ? new (zone) | 
|    94                                                           ModuleDescriptor(zone) |    96                                                           ModuleDescriptor(zone) | 
|    95                                                     : NULL), |    97                                                     : NULL), | 
|    96       sloppy_block_function_map_(zone), |    98       sloppy_block_function_map_(zone), | 
|    97       already_resolved_(false), |    99       already_resolved_(false) { | 
|    98       zone_(zone) { |   100   SetDefaults(); | 
|    99   SetDefaults(scope_type, outer_scope, Handle<ScopeInfo>::null(), |   101   if (outer_scope != nullptr) { | 
|   100               function_kind); |   102     asm_function_ = outer_scope_->asm_module_; | 
 |   103     // Inherit the language mode from the parent scope unless we're a module | 
 |   104     // scope. | 
 |   105     if (!is_module_scope()) language_mode_ = outer_scope->language_mode_; | 
 |   106     force_context_allocation_ = | 
 |   107         !is_function_scope() && outer_scope->has_forced_context_allocation(); | 
 |   108   } | 
 |   109  | 
|   101   // The outermost scope must be a script scope. |   110   // The outermost scope must be a script scope. | 
|   102   DCHECK(scope_type == SCRIPT_SCOPE || outer_scope != NULL); |   111   DCHECK(scope_type == SCRIPT_SCOPE || outer_scope != nullptr); | 
|   103 } |   112 } | 
|   104  |   113  | 
|   105 Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type, |   114 Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type, | 
|   106              Handle<ScopeInfo> scope_info) |   115              Handle<ScopeInfo> scope_info) | 
|   107     : inner_scopes_(4, zone), |   116     : outer_scope_(nullptr), | 
 |   117       inner_scopes_(4, zone), | 
 |   118       scope_type_(scope_type), | 
 |   119       function_kind_(scope_info.is_null() ? kNormalFunction | 
 |   120                                           : scope_info->function_kind()), | 
|   108       variables_(zone), |   121       variables_(zone), | 
|   109       temps_(4, zone), |   122       temps_(4, zone), | 
|   110       params_(4, zone), |   123       params_(4, zone), | 
|   111       unresolved_(nullptr), |  | 
|   112       decls_(4, zone), |   124       decls_(4, zone), | 
|   113       module_descriptor_(NULL), |   125       module_descriptor_(nullptr), | 
|   114       sloppy_block_function_map_(zone), |   126       sloppy_block_function_map_(zone), | 
|   115       already_resolved_(true), |   127       already_resolved_(true), | 
|   116       zone_(zone) { |   128       scope_info_(scope_info) { | 
|   117   SetDefaults(scope_type, NULL, scope_info); |   129   SetDefaults(); | 
|   118   if (!scope_info.is_null()) { |   130   if (!scope_info.is_null()) { | 
 |   131     scope_calls_eval_ = scope_info->CallsEval(); | 
 |   132     language_mode_ = scope_info->language_mode(); | 
 |   133     is_declaration_scope_ = scope_info->is_declaration_scope(); | 
|   119     num_heap_slots_ = scope_info_->ContextLength(); |   134     num_heap_slots_ = scope_info_->ContextLength(); | 
|   120   } |   135   } | 
|   121   // Ensure at least MIN_CONTEXT_SLOTS to indicate a materialized context. |   136   // Ensure at least MIN_CONTEXT_SLOTS to indicate a materialized context. | 
|   122   num_heap_slots_ = Max(num_heap_slots_, |   137   num_heap_slots_ = Max(num_heap_slots_, | 
|   123                         static_cast<int>(Context::MIN_CONTEXT_SLOTS)); |   138                         static_cast<int>(Context::MIN_CONTEXT_SLOTS)); | 
|   124   AddInnerScope(inner_scope); |   139   AddInnerScope(inner_scope); | 
|   125 } |   140 } | 
|   126  |   141  | 
|   127 Scope::Scope(Zone* zone, Scope* inner_scope, |   142 Scope::Scope(Zone* zone, Scope* inner_scope, | 
|   128              const AstRawString* catch_variable_name) |   143              const AstRawString* catch_variable_name) | 
|   129     : inner_scopes_(1, zone), |   144     : outer_scope_(nullptr), | 
 |   145       inner_scopes_(1, zone), | 
 |   146       scope_type_(CATCH_SCOPE), | 
 |   147       function_kind_(kNormalFunction), | 
|   130       variables_(zone), |   148       variables_(zone), | 
|   131       temps_(0, zone), |   149       temps_(0, zone), | 
|   132       params_(0, zone), |   150       params_(0, zone), | 
|   133       unresolved_(nullptr), |  | 
|   134       decls_(0, zone), |   151       decls_(0, zone), | 
|   135       module_descriptor_(NULL), |   152       module_descriptor_(nullptr), | 
|   136       sloppy_block_function_map_(zone), |   153       sloppy_block_function_map_(zone), | 
|   137       already_resolved_(true), |   154       already_resolved_(true) { | 
|   138       zone_(zone) { |   155   SetDefaults(); | 
|   139   SetDefaults(CATCH_SCOPE, NULL, Handle<ScopeInfo>::null()); |  | 
|   140   AddInnerScope(inner_scope); |   156   AddInnerScope(inner_scope); | 
|   141   ++num_var_; |   157   ++num_var_; | 
|   142   num_heap_slots_ = Context::MIN_CONTEXT_SLOTS; |   158   num_heap_slots_ = Context::MIN_CONTEXT_SLOTS; | 
|   143   Variable* variable = variables_.Declare(this, |   159   Variable* variable = variables_.Declare(this, | 
|   144                                           catch_variable_name, |   160                                           catch_variable_name, | 
|   145                                           VAR, |   161                                           VAR, | 
|   146                                           Variable::NORMAL, |   162                                           Variable::NORMAL, | 
|   147                                           kCreatedInitialized); |   163                                           kCreatedInitialized); | 
|   148   AllocateHeapSlot(variable); |   164   AllocateHeapSlot(variable); | 
|   149 } |   165 } | 
|   150  |   166  | 
|   151  |   167 void Scope::SetDefaults() { | 
|   152 void Scope::SetDefaults(ScopeType scope_type, Scope* outer_scope, |  | 
|   153                         Handle<ScopeInfo> scope_info, |  | 
|   154                         FunctionKind function_kind) { |  | 
|   155   outer_scope_ = outer_scope; |  | 
|   156   scope_type_ = scope_type; |  | 
|   157   is_declaration_scope_ = |   168   is_declaration_scope_ = | 
|   158       is_eval_scope() || is_function_scope() || |   169       is_eval_scope() || is_function_scope() || | 
|   159       is_module_scope() || is_script_scope(); |   170       is_module_scope() || is_script_scope(); | 
|   160   function_kind_ = function_kind; |   171   unresolved_ = nullptr; | 
|   161   scope_name_ = nullptr; |   172   scope_name_ = nullptr; | 
|   162   dynamics_ = nullptr; |   173   dynamics_ = nullptr; | 
|   163   receiver_ = nullptr; |   174   receiver_ = nullptr; | 
|   164   new_target_ = nullptr; |   175   new_target_ = nullptr; | 
|   165   function_ = nullptr; |   176   function_ = nullptr; | 
|   166   arguments_ = nullptr; |   177   arguments_ = nullptr; | 
|   167   this_function_ = nullptr; |   178   this_function_ = nullptr; | 
|   168   scope_inside_with_ = false; |   179   scope_inside_with_ = false; | 
|   169   scope_calls_eval_ = false; |   180   scope_calls_eval_ = false; | 
|   170   scope_uses_arguments_ = false; |   181   scope_uses_arguments_ = false; | 
|   171   scope_uses_super_property_ = false; |   182   scope_uses_super_property_ = false; | 
|   172   asm_module_ = false; |   183   asm_module_ = false; | 
|   173   asm_function_ = outer_scope != NULL && outer_scope->asm_module_; |   184   asm_function_ = false; | 
|   174   // Inherit the language mode from the parent scope. |   185   language_mode_ = is_module_scope() ? STRICT : SLOPPY; | 
|   175   language_mode_ = |  | 
|   176       is_module_scope() |  | 
|   177           ? STRICT |  | 
|   178           : (outer_scope != NULL ? outer_scope->language_mode_ : SLOPPY); |  | 
|   179   outer_scope_calls_sloppy_eval_ = false; |   186   outer_scope_calls_sloppy_eval_ = false; | 
|   180   inner_scope_calls_eval_ = false; |   187   inner_scope_calls_eval_ = false; | 
|   181   scope_nonlinear_ = false; |   188   scope_nonlinear_ = false; | 
|   182   force_eager_compilation_ = false; |   189   force_eager_compilation_ = false; | 
|   183   force_context_allocation_ = (outer_scope != NULL && !is_function_scope()) |   190   force_context_allocation_ = false; | 
|   184       ? outer_scope->has_forced_context_allocation() : false; |  | 
|   185   num_var_ = 0; |   191   num_var_ = 0; | 
|   186   num_stack_slots_ = 0; |   192   num_stack_slots_ = 0; | 
|   187   num_heap_slots_ = 0; |   193   num_heap_slots_ = 0; | 
|   188   num_global_slots_ = 0; |   194   num_global_slots_ = 0; | 
|   189   arity_ = 0; |   195   arity_ = 0; | 
|   190   has_simple_parameters_ = true; |   196   has_simple_parameters_ = true; | 
|   191   rest_parameter_ = NULL; |   197   rest_parameter_ = NULL; | 
|   192   rest_index_ = -1; |   198   rest_index_ = -1; | 
|   193   scope_info_ = scope_info; |  | 
|   194   start_position_ = kNoSourcePosition; |   199   start_position_ = kNoSourcePosition; | 
|   195   end_position_ = kNoSourcePosition; |   200   end_position_ = kNoSourcePosition; | 
|   196   is_hidden_ = false; |   201   is_hidden_ = false; | 
|   197   if (!scope_info.is_null()) { |  | 
|   198     scope_calls_eval_ = scope_info->CallsEval(); |  | 
|   199     language_mode_ = scope_info->language_mode(); |  | 
|   200     is_declaration_scope_ = scope_info->is_declaration_scope(); |  | 
|   201     function_kind_ = scope_info->function_kind(); |  | 
|   202   } |  | 
|   203 } |   202 } | 
|   204  |   203  | 
|   205 Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone, |   204 Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone, | 
|   206                                     Context* context, Scope* script_scope, |   205                                     Context* context, Scope* script_scope, | 
|   207                                     AstValueFactory* ast_value_factory) { |   206                                     AstValueFactory* ast_value_factory) { | 
|   208   // Reconstruct the outer scope chain from a closure's context chain. |   207   // Reconstruct the outer scope chain from a closure's context chain. | 
|   209   Scope* current_scope = NULL; |   208   Scope* current_scope = NULL; | 
|   210   Scope* innermost_scope = NULL; |   209   Scope* innermost_scope = NULL; | 
|   211   while (!context->IsNativeContext()) { |   210   while (!context->IsNativeContext()) { | 
|   212     if (context->IsWithContext() || context->IsDebugEvaluateContext()) { |   211     if (context->IsWithContext() || context->IsDebugEvaluateContext()) { | 
| (...skipping 1333 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1546       function_ != NULL && function_->proxy()->var()->IsContextSlot(); |  1545       function_ != NULL && function_->proxy()->var()->IsContextSlot(); | 
|  1547   return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |  1546   return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - | 
|  1548          (is_function_var_in_context ? 1 : 0); |  1547          (is_function_var_in_context ? 1 : 0); | 
|  1549 } |  1548 } | 
|  1550  |  1549  | 
|  1551  |  1550  | 
|  1552 int Scope::ContextGlobalCount() const { return num_global_slots(); } |  1551 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 
|  1553  |  1552  | 
|  1554 }  // namespace internal |  1553 }  // namespace internal | 
|  1555 }  // namespace v8 |  1554 }  // namespace v8 | 
| OLD | NEW |