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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 is_module_scope() || is_script_scope(); | 162 is_module_scope() || is_script_scope(); |
163 function_kind_ = function_kind; | 163 function_kind_ = function_kind; |
164 scope_name_ = ast_value_factory_->empty_string(); | 164 scope_name_ = ast_value_factory_->empty_string(); |
165 dynamics_ = nullptr; | 165 dynamics_ = nullptr; |
166 receiver_ = nullptr; | 166 receiver_ = nullptr; |
167 new_target_ = nullptr; | 167 new_target_ = nullptr; |
168 function_ = nullptr; | 168 function_ = nullptr; |
169 arguments_ = nullptr; | 169 arguments_ = nullptr; |
170 this_function_ = nullptr; | 170 this_function_ = nullptr; |
171 scope_inside_with_ = false; | 171 scope_inside_with_ = false; |
| 172 scope_inside_module_ = false; |
172 scope_calls_eval_ = false; | 173 scope_calls_eval_ = false; |
173 scope_uses_arguments_ = false; | 174 scope_uses_arguments_ = false; |
174 scope_uses_super_property_ = false; | 175 scope_uses_super_property_ = false; |
175 asm_module_ = false; | 176 asm_module_ = false; |
176 asm_function_ = outer_scope != NULL && outer_scope->asm_module_; | 177 asm_function_ = outer_scope != NULL && outer_scope->asm_module_; |
177 // Inherit the language mode from the parent scope. | 178 // Inherit the language mode from the parent scope. |
178 language_mode_ = | 179 language_mode_ = |
179 is_module_scope() | 180 is_module_scope() |
180 ? STRICT | 181 ? STRICT |
181 : (outer_scope != NULL ? outer_scope->language_mode_ : SLOPPY); | 182 : (outer_scope != NULL ? outer_scope->language_mode_ : SLOPPY); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 } | 300 } |
300 | 301 |
301 | 302 |
302 void Scope::Initialize() { | 303 void Scope::Initialize() { |
303 DCHECK(!already_resolved()); | 304 DCHECK(!already_resolved()); |
304 | 305 |
305 // Add this scope as a new inner scope of the outer scope. | 306 // Add this scope as a new inner scope of the outer scope. |
306 if (outer_scope_ != NULL) { | 307 if (outer_scope_ != NULL) { |
307 outer_scope_->inner_scopes_.Add(this, zone()); | 308 outer_scope_->inner_scopes_.Add(this, zone()); |
308 scope_inside_with_ = outer_scope_->scope_inside_with_ || is_with_scope(); | 309 scope_inside_with_ = outer_scope_->scope_inside_with_ || is_with_scope(); |
| 310 scope_inside_module_ = |
| 311 outer_scope_->scope_inside_module_ || is_module_scope(); |
309 } else { | 312 } else { |
310 scope_inside_with_ = is_with_scope(); | 313 scope_inside_with_ = is_with_scope(); |
| 314 scope_inside_module_ = is_module_scope(); |
311 } | 315 } |
312 | 316 |
313 // Declare convenience variables and the receiver. | 317 // Declare convenience variables and the receiver. |
314 if (is_declaration_scope() && has_this_declaration()) { | 318 if (is_declaration_scope() && has_this_declaration()) { |
315 bool subclass_constructor = IsSubclassConstructor(function_kind_); | 319 bool subclass_constructor = IsSubclassConstructor(function_kind_); |
316 Variable* var = variables_.Declare( | 320 Variable* var = variables_.Declare( |
317 this, ast_value_factory_->this_string(), | 321 this, ast_value_factory_->this_string(), |
318 subclass_constructor ? CONST : VAR, Variable::THIS, | 322 subclass_constructor ? CONST : VAR, Variable::THIS, |
319 subclass_constructor ? kNeedsInitialization : kCreatedInitialized); | 323 subclass_constructor ? kNeedsInitialization : kCreatedInitialized); |
320 receiver_ = var; | 324 receiver_ = var; |
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
957 // Scope info. | 961 // Scope info. |
958 if (HasTrivialOuterContext()) { | 962 if (HasTrivialOuterContext()) { |
959 Indent(n1, "// scope has trivial outer context\n"); | 963 Indent(n1, "// scope has trivial outer context\n"); |
960 } | 964 } |
961 if (is_strict(language_mode())) { | 965 if (is_strict(language_mode())) { |
962 Indent(n1, "// strict mode scope\n"); | 966 Indent(n1, "// strict mode scope\n"); |
963 } | 967 } |
964 if (asm_module_) Indent(n1, "// scope is an asm module\n"); | 968 if (asm_module_) Indent(n1, "// scope is an asm module\n"); |
965 if (asm_function_) Indent(n1, "// scope is an asm function\n"); | 969 if (asm_function_) Indent(n1, "// scope is an asm function\n"); |
966 if (scope_inside_with_) Indent(n1, "// scope inside 'with'\n"); | 970 if (scope_inside_with_) Indent(n1, "// scope inside 'with'\n"); |
| 971 if (scope_inside_module_) Indent(n1, "// scope inside module\n"); |
967 if (scope_calls_eval_) Indent(n1, "// scope calls 'eval'\n"); | 972 if (scope_calls_eval_) Indent(n1, "// scope calls 'eval'\n"); |
968 if (scope_uses_arguments_) Indent(n1, "// scope uses 'arguments'\n"); | 973 if (scope_uses_arguments_) Indent(n1, "// scope uses 'arguments'\n"); |
969 if (scope_uses_super_property_) | 974 if (scope_uses_super_property_) |
970 Indent(n1, "// scope uses 'super' property\n"); | 975 Indent(n1, "// scope uses 'super' property\n"); |
971 if (outer_scope_calls_sloppy_eval_) { | 976 if (outer_scope_calls_sloppy_eval_) { |
972 Indent(n1, "// outer scope calls 'eval' in sloppy context\n"); | 977 Indent(n1, "// outer scope calls 'eval' in sloppy context\n"); |
973 } | 978 } |
974 if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n"); | 979 if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n"); |
975 if (num_stack_slots_ > 0) { | 980 if (num_stack_slots_ > 0) { |
976 Indent(n1, "// "); | 981 Indent(n1, "// "); |
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1529 function_ != NULL && function_->proxy()->var()->IsContextSlot(); | 1534 function_ != NULL && function_->proxy()->var()->IsContextSlot(); |
1530 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - | 1535 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
1531 (is_function_var_in_context ? 1 : 0); | 1536 (is_function_var_in_context ? 1 : 0); |
1532 } | 1537 } |
1533 | 1538 |
1534 | 1539 |
1535 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1540 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
1536 | 1541 |
1537 } // namespace internal | 1542 } // namespace internal |
1538 } // namespace v8 | 1543 } // namespace v8 |
OLD | NEW |