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" |
11 #include "src/messages.h" | 11 #include "src/messages.h" |
12 #include "src/parsing/parser.h" // for ParseInfo | 12 #include "src/parsing/parser.h" // for ParseInfo |
13 | 13 |
14 namespace v8 { | 14 namespace v8 { |
15 namespace internal { | 15 namespace internal { |
16 | 16 |
17 // ---------------------------------------------------------------------------- | 17 // ---------------------------------------------------------------------------- |
18 // Implementation of LocalsMap | 18 // Implementation of LocalsMap |
19 // | 19 // |
20 // Note: We are storing the handle locations as key values in the hash map. | 20 // Note: We are storing the handle locations as key values in the hash map. |
21 // When inserting a new variable via Declare(), we rely on the fact that | 21 // When inserting a new variable via Declare(), we rely on the fact that |
22 // the handle location remains alive for the duration of that variable | 22 // the handle location remains alive for the duration of that variable |
23 // use. Because a Variable holding a handle with the same location exists | 23 // use. Because a Variable holding a handle with the same location exists |
24 // this is ensured. | 24 // this is ensured. |
25 | 25 |
26 VariableMap::VariableMap(Zone* zone) | 26 VariableMap::VariableMap(Zone* zone) |
27 : ZoneHashMap(ZoneHashMap::PointersMatch, 8, ZoneAllocationPolicy(zone)), | 27 : ZoneHashMap(ZoneHashMap::PointersMatch, 8, ZoneAllocationPolicy(zone)) {} |
28 zone_(zone) {} | |
29 VariableMap::~VariableMap() {} | |
30 | 28 |
31 Variable* VariableMap::Declare(Scope* scope, const AstRawString* name, | 29 Variable* VariableMap::Declare(Zone* zone, Scope* scope, |
32 VariableMode mode, Variable::Kind kind, | 30 const AstRawString* name, VariableMode mode, |
| 31 Variable::Kind kind, |
33 InitializationFlag initialization_flag, | 32 InitializationFlag initialization_flag, |
34 MaybeAssignedFlag maybe_assigned_flag) { | 33 MaybeAssignedFlag maybe_assigned_flag) { |
35 // AstRawStrings are unambiguous, i.e., the same string is always represented | 34 // AstRawStrings are unambiguous, i.e., the same string is always represented |
36 // by the same AstRawString*. | 35 // by the same AstRawString*. |
37 // FIXME(marja): fix the type of Lookup. | 36 // FIXME(marja): fix the type of Lookup. |
38 Entry* p = | 37 Entry* p = |
39 ZoneHashMap::LookupOrInsert(const_cast<AstRawString*>(name), name->hash(), | 38 ZoneHashMap::LookupOrInsert(const_cast<AstRawString*>(name), name->hash(), |
40 ZoneAllocationPolicy(zone())); | 39 ZoneAllocationPolicy(zone)); |
41 if (p->value == NULL) { | 40 if (p->value == NULL) { |
42 // The variable has not been declared yet -> insert it. | 41 // The variable has not been declared yet -> insert it. |
43 DCHECK(p->key == name); | 42 DCHECK(p->key == name); |
44 p->value = new (zone()) Variable(scope, name, mode, kind, | 43 p->value = new (zone) Variable(scope, name, mode, kind, initialization_flag, |
45 initialization_flag, maybe_assigned_flag); | 44 maybe_assigned_flag); |
46 } | 45 } |
47 return reinterpret_cast<Variable*>(p->value); | 46 return reinterpret_cast<Variable*>(p->value); |
48 } | 47 } |
49 | 48 |
50 | 49 |
51 Variable* VariableMap::Lookup(const AstRawString* name) { | 50 Variable* VariableMap::Lookup(const AstRawString* name) { |
52 Entry* p = ZoneHashMap::Lookup(const_cast<AstRawString*>(name), name->hash()); | 51 Entry* p = ZoneHashMap::Lookup(const_cast<AstRawString*>(name), name->hash()); |
53 if (p != NULL) { | 52 if (p != NULL) { |
54 DCHECK(reinterpret_cast<const AstRawString*>(p->key) == name); | 53 DCHECK(reinterpret_cast<const AstRawString*>(p->key) == name); |
55 DCHECK(p->value != NULL); | 54 DCHECK(p->value != NULL); |
56 return reinterpret_cast<Variable*>(p->value); | 55 return reinterpret_cast<Variable*>(p->value); |
57 } | 56 } |
58 return NULL; | 57 return NULL; |
59 } | 58 } |
60 | 59 |
| 60 SloppyBlockFunctionMap::SloppyBlockFunctionMap(Zone* zone) |
| 61 : ZoneHashMap(ZoneHashMap::PointersMatch, 8, ZoneAllocationPolicy(zone)) {} |
61 | 62 |
62 SloppyBlockFunctionMap::SloppyBlockFunctionMap(Zone* zone) | 63 void SloppyBlockFunctionMap::Declare(Zone* zone, const AstRawString* name, |
63 : ZoneHashMap(ZoneHashMap::PointersMatch, 8, ZoneAllocationPolicy(zone)), | |
64 zone_(zone) {} | |
65 SloppyBlockFunctionMap::~SloppyBlockFunctionMap() {} | |
66 | |
67 | |
68 void SloppyBlockFunctionMap::Declare(const AstRawString* name, | |
69 SloppyBlockFunctionStatement* stmt) { | 64 SloppyBlockFunctionStatement* stmt) { |
70 // AstRawStrings are unambiguous, i.e., the same string is always represented | 65 // AstRawStrings are unambiguous, i.e., the same string is always represented |
71 // by the same AstRawString*. | 66 // by the same AstRawString*. |
72 Entry* p = | 67 Entry* p = |
73 ZoneHashMap::LookupOrInsert(const_cast<AstRawString*>(name), name->hash(), | 68 ZoneHashMap::LookupOrInsert(const_cast<AstRawString*>(name), name->hash(), |
74 ZoneAllocationPolicy(zone_)); | 69 ZoneAllocationPolicy(zone)); |
75 if (p->value == nullptr) { | 70 if (p->value == nullptr) { |
76 p->value = new (zone_->New(sizeof(Vector))) Vector(zone_); | 71 p->value = new (zone->New(sizeof(Vector))) Vector(zone); |
77 } | 72 } |
78 Vector* delegates = static_cast<Vector*>(p->value); | 73 Vector* delegates = static_cast<Vector*>(p->value); |
79 delegates->push_back(stmt); | 74 delegates->push_back(stmt); |
80 } | 75 } |
81 | 76 |
82 | 77 |
83 // ---------------------------------------------------------------------------- | 78 // ---------------------------------------------------------------------------- |
84 // Implementation of Scope | 79 // Implementation of Scope |
85 | 80 |
86 Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type) | 81 Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type) |
87 : outer_scope_(outer_scope), | 82 : zone_(zone), |
| 83 outer_scope_(outer_scope), |
88 variables_(zone), | 84 variables_(zone), |
89 decls_(4, zone), | 85 decls_(4, zone), |
90 scope_type_(scope_type), | 86 scope_type_(scope_type), |
91 already_resolved_(false) { | 87 already_resolved_(false) { |
92 SetDefaults(); | 88 SetDefaults(); |
93 if (outer_scope == nullptr) { | 89 if (outer_scope == nullptr) { |
94 // If the outer scope is null, this cannot be a with scope. The outermost | 90 // If the outer scope is null, this cannot be a with scope. The outermost |
95 // scope must be a script scope. | 91 // scope must be a script scope. |
96 DCHECK_EQ(SCRIPT_SCOPE, scope_type); | 92 DCHECK_EQ(SCRIPT_SCOPE, scope_type); |
97 } else { | 93 } else { |
(...skipping 23 matching lines...) Expand all Loading... |
121 params_(4, zone), | 117 params_(4, zone), |
122 sloppy_block_function_map_(zone), | 118 sloppy_block_function_map_(zone), |
123 module_descriptor_(scope_type == MODULE_SCOPE ? new (zone) | 119 module_descriptor_(scope_type == MODULE_SCOPE ? new (zone) |
124 ModuleDescriptor(zone) | 120 ModuleDescriptor(zone) |
125 : NULL) { | 121 : NULL) { |
126 SetDefaults(); | 122 SetDefaults(); |
127 } | 123 } |
128 | 124 |
129 Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type, | 125 Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type, |
130 Handle<ScopeInfo> scope_info) | 126 Handle<ScopeInfo> scope_info) |
131 : outer_scope_(nullptr), | 127 : zone_(zone), |
| 128 outer_scope_(nullptr), |
132 variables_(zone), | 129 variables_(zone), |
133 decls_(4, zone), | 130 decls_(4, zone), |
134 scope_info_(scope_info), | 131 scope_info_(scope_info), |
135 scope_type_(scope_type), | 132 scope_type_(scope_type), |
136 already_resolved_(true) { | 133 already_resolved_(true) { |
137 SetDefaults(); | 134 SetDefaults(); |
138 if (!scope_info.is_null()) { | 135 if (!scope_info.is_null()) { |
139 scope_calls_eval_ = scope_info->CallsEval(); | 136 scope_calls_eval_ = scope_info->CallsEval(); |
140 language_mode_ = scope_info->language_mode(); | 137 language_mode_ = scope_info->language_mode(); |
141 num_heap_slots_ = scope_info_->ContextLength(); | 138 num_heap_slots_ = scope_info_->ContextLength(); |
(...skipping 12 matching lines...) Expand all Loading... |
154 : scope_info->function_kind()), | 151 : scope_info->function_kind()), |
155 temps_(4, zone), | 152 temps_(4, zone), |
156 params_(4, zone), | 153 params_(4, zone), |
157 sloppy_block_function_map_(zone), | 154 sloppy_block_function_map_(zone), |
158 module_descriptor_(nullptr) { | 155 module_descriptor_(nullptr) { |
159 SetDefaults(); | 156 SetDefaults(); |
160 } | 157 } |
161 | 158 |
162 Scope::Scope(Zone* zone, Scope* inner_scope, | 159 Scope::Scope(Zone* zone, Scope* inner_scope, |
163 const AstRawString* catch_variable_name) | 160 const AstRawString* catch_variable_name) |
164 : outer_scope_(nullptr), | 161 : zone_(zone), |
| 162 outer_scope_(nullptr), |
165 variables_(zone), | 163 variables_(zone), |
166 decls_(0, zone), | 164 decls_(0, zone), |
167 scope_type_(CATCH_SCOPE), | 165 scope_type_(CATCH_SCOPE), |
168 already_resolved_(true) { | 166 already_resolved_(true) { |
169 SetDefaults(); | 167 SetDefaults(); |
170 AddInnerScope(inner_scope); | 168 AddInnerScope(inner_scope); |
171 num_heap_slots_ = Context::MIN_CONTEXT_SLOTS; | 169 num_heap_slots_ = Context::MIN_CONTEXT_SLOTS; |
172 Variable* variable = variables_.Declare(this, | 170 Variable* variable = |
173 catch_variable_name, | 171 variables_.Declare(zone, this, catch_variable_name, VAR, Variable::NORMAL, |
174 VAR, | 172 kCreatedInitialized); |
175 Variable::NORMAL, | |
176 kCreatedInitialized); | |
177 AllocateHeapSlot(variable); | 173 AllocateHeapSlot(variable); |
178 } | 174 } |
179 | 175 |
180 void DeclarationScope::SetDefaults() { | 176 void DeclarationScope::SetDefaults() { |
181 is_declaration_scope_ = true; | 177 is_declaration_scope_ = true; |
182 has_simple_parameters_ = true; | 178 has_simple_parameters_ = true; |
183 receiver_ = nullptr; | 179 receiver_ = nullptr; |
184 new_target_ = nullptr; | 180 new_target_ = nullptr; |
185 function_ = nullptr; | 181 function_ = nullptr; |
186 arguments_ = nullptr; | 182 arguments_ = nullptr; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 MaybeAssignedFlag maybe_assigned_flag = | 302 MaybeAssignedFlag maybe_assigned_flag = |
307 scope_info_->ContextLocalMaybeAssignedFlag(var); | 303 scope_info_->ContextLocalMaybeAssignedFlag(var); |
308 VariableLocation location = var < scope_info_->ContextLocalCount() | 304 VariableLocation location = var < scope_info_->ContextLocalCount() |
309 ? VariableLocation::CONTEXT | 305 ? VariableLocation::CONTEXT |
310 : VariableLocation::GLOBAL; | 306 : VariableLocation::GLOBAL; |
311 Variable::Kind kind = Variable::NORMAL; | 307 Variable::Kind kind = Variable::NORMAL; |
312 if (index == scope_info_->ReceiverContextSlotIndex()) { | 308 if (index == scope_info_->ReceiverContextSlotIndex()) { |
313 kind = Variable::THIS; | 309 kind = Variable::THIS; |
314 } | 310 } |
315 | 311 |
316 Variable* result = variables_.Declare(this, name, mode, kind, init_flag, | 312 Variable* result = variables_.Declare(zone(), this, name, mode, kind, |
317 maybe_assigned_flag); | 313 init_flag, maybe_assigned_flag); |
318 result->AllocateTo(location, index); | 314 result->AllocateTo(location, index); |
319 } | 315 } |
320 | 316 |
321 // We must read parameters from the end since for multiply declared | 317 // We must read parameters from the end since for multiply declared |
322 // parameters the value of the last declaration of that parameter is used | 318 // parameters the value of the last declaration of that parameter is used |
323 // inside a function (and thus we need to look at the last index). Was bug# | 319 // inside a function (and thus we need to look at the last index). Was bug# |
324 // 1110337. | 320 // 1110337. |
325 for (int index = scope_info_->ParameterCount() - 1; index >= 0; --index) { | 321 for (int index = scope_info_->ParameterCount() - 1; index >= 0; --index) { |
326 Handle<String> name_handle(scope_info_->ParameterName(index), isolate); | 322 Handle<String> name_handle(scope_info_->ParameterName(index), isolate); |
327 const AstRawString* name = ast_value_factory->GetString(name_handle); | 323 const AstRawString* name = ast_value_factory->GetString(name_handle); |
328 if (!names_seen.insert(name).second) continue; | 324 if (!names_seen.insert(name).second) continue; |
329 | 325 |
330 VariableMode mode = DYNAMIC; | 326 VariableMode mode = DYNAMIC; |
331 InitializationFlag init_flag = kCreatedInitialized; | 327 InitializationFlag init_flag = kCreatedInitialized; |
332 MaybeAssignedFlag maybe_assigned_flag = kMaybeAssigned; | 328 MaybeAssignedFlag maybe_assigned_flag = kMaybeAssigned; |
333 VariableLocation location = VariableLocation::LOOKUP; | 329 VariableLocation location = VariableLocation::LOOKUP; |
334 Variable::Kind kind = Variable::NORMAL; | 330 Variable::Kind kind = Variable::NORMAL; |
335 | 331 |
336 Variable* result = variables_.Declare(this, name, mode, kind, init_flag, | 332 Variable* result = variables_.Declare(zone(), this, name, mode, kind, |
337 maybe_assigned_flag); | 333 init_flag, maybe_assigned_flag); |
338 result->AllocateTo(location, index); | 334 result->AllocateTo(location, index); |
339 } | 335 } |
340 | 336 |
341 // Internalize function proxy for this scope. | 337 // Internalize function proxy for this scope. |
342 if (scope_info_->HasFunctionName()) { | 338 if (scope_info_->HasFunctionName()) { |
343 AstNodeFactory factory(ast_value_factory); | 339 AstNodeFactory factory(ast_value_factory); |
344 Handle<String> name_handle(scope_info_->FunctionName(), isolate); | 340 Handle<String> name_handle(scope_info_->FunctionName(), isolate); |
345 const AstRawString* name = ast_value_factory->GetString(name_handle); | 341 const AstRawString* name = ast_value_factory->GetString(name_handle); |
346 VariableMode mode; | 342 VariableMode mode; |
347 int index = scope_info_->FunctionContextSlotIndex(*name_handle, &mode); | 343 int index = scope_info_->FunctionContextSlotIndex(*name_handle, &mode); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 #endif | 397 #endif |
402 } | 398 } |
403 | 399 |
404 void DeclarationScope::DeclareThis(AstValueFactory* ast_value_factory) { | 400 void DeclarationScope::DeclareThis(AstValueFactory* ast_value_factory) { |
405 DCHECK(!already_resolved()); | 401 DCHECK(!already_resolved()); |
406 DCHECK(is_declaration_scope()); | 402 DCHECK(is_declaration_scope()); |
407 DCHECK(has_this_declaration()); | 403 DCHECK(has_this_declaration()); |
408 | 404 |
409 bool subclass_constructor = IsSubclassConstructor(function_kind_); | 405 bool subclass_constructor = IsSubclassConstructor(function_kind_); |
410 Variable* var = variables_.Declare( | 406 Variable* var = variables_.Declare( |
411 this, ast_value_factory->this_string(), | 407 zone(), this, ast_value_factory->this_string(), |
412 subclass_constructor ? CONST : VAR, Variable::THIS, | 408 subclass_constructor ? CONST : VAR, Variable::THIS, |
413 subclass_constructor ? kNeedsInitialization : kCreatedInitialized); | 409 subclass_constructor ? kNeedsInitialization : kCreatedInitialized); |
414 receiver_ = var; | 410 receiver_ = var; |
415 } | 411 } |
416 | 412 |
417 void DeclarationScope::DeclareDefaultFunctionVariables( | 413 void DeclarationScope::DeclareDefaultFunctionVariables( |
418 AstValueFactory* ast_value_factory) { | 414 AstValueFactory* ast_value_factory) { |
419 DCHECK(is_function_scope()); | 415 DCHECK(is_function_scope()); |
420 DCHECK(!is_arrow_scope()); | 416 DCHECK(!is_arrow_scope()); |
421 // Declare 'arguments' variable which exists in all non arrow functions. | 417 // Declare 'arguments' variable which exists in all non arrow functions. |
422 // Note that it might never be accessed, in which case it won't be | 418 // Note that it might never be accessed, in which case it won't be |
423 // allocated during variable allocation. | 419 // allocated during variable allocation. |
424 arguments_ = | 420 arguments_ = |
425 variables_.Declare(this, ast_value_factory->arguments_string(), VAR, | 421 variables_.Declare(zone(), this, ast_value_factory->arguments_string(), |
426 Variable::ARGUMENTS, kCreatedInitialized); | 422 VAR, Variable::ARGUMENTS, kCreatedInitialized); |
427 | 423 |
428 new_target_ = | 424 new_target_ = |
429 variables_.Declare(this, ast_value_factory->new_target_string(), CONST, | 425 variables_.Declare(zone(), this, ast_value_factory->new_target_string(), |
430 Variable::NORMAL, kCreatedInitialized); | 426 CONST, Variable::NORMAL, kCreatedInitialized); |
431 | 427 |
432 if (IsConciseMethod(function_kind_) || IsClassConstructor(function_kind_) || | 428 if (IsConciseMethod(function_kind_) || IsClassConstructor(function_kind_) || |
433 IsAccessorFunction(function_kind_)) { | 429 IsAccessorFunction(function_kind_)) { |
434 this_function_ = | 430 this_function_ = variables_.Declare( |
435 variables_.Declare(this, ast_value_factory->this_function_string(), | 431 zone(), this, ast_value_factory->this_function_string(), CONST, |
436 CONST, Variable::NORMAL, kCreatedInitialized); | 432 Variable::NORMAL, kCreatedInitialized); |
437 } | 433 } |
438 } | 434 } |
439 | 435 |
440 | 436 |
441 Scope* Scope::FinalizeBlockScope() { | 437 Scope* Scope::FinalizeBlockScope() { |
442 DCHECK(is_block_scope()); | 438 DCHECK(is_block_scope()); |
443 | 439 |
444 if (variables_.occupancy() > 0 || | 440 if (variables_.occupancy() > 0 || |
445 (is_declaration_scope() && calls_sloppy_eval())) { | 441 (is_declaration_scope() && calls_sloppy_eval())) { |
446 return this; | 442 return this; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 } | 587 } |
592 | 588 |
593 Variable::Kind kind = Variable::NORMAL; | 589 Variable::Kind kind = Variable::NORMAL; |
594 if (location == VariableLocation::CONTEXT && | 590 if (location == VariableLocation::CONTEXT && |
595 index == scope_info_->ReceiverContextSlotIndex()) { | 591 index == scope_info_->ReceiverContextSlotIndex()) { |
596 kind = Variable::THIS; | 592 kind = Variable::THIS; |
597 } | 593 } |
598 // TODO(marja, rossberg): Correctly declare FUNCTION, CLASS, NEW_TARGET, and | 594 // TODO(marja, rossberg): Correctly declare FUNCTION, CLASS, NEW_TARGET, and |
599 // ARGUMENTS bindings as their corresponding Variable::Kind. | 595 // ARGUMENTS bindings as their corresponding Variable::Kind. |
600 | 596 |
601 Variable* var = variables_.Declare(this, name, mode, kind, init_flag, | 597 Variable* var = variables_.Declare(zone(), this, name, mode, kind, init_flag, |
602 maybe_assigned_flag); | 598 maybe_assigned_flag); |
603 var->AllocateTo(location, index); | 599 var->AllocateTo(location, index); |
604 return var; | 600 return var; |
605 } | 601 } |
606 | 602 |
607 Variable* DeclarationScope::LookupFunctionVar(const AstRawString* name, | 603 Variable* DeclarationScope::LookupFunctionVar(const AstRawString* name, |
608 AstNodeFactory* factory) { | 604 AstNodeFactory* factory) { |
609 if (function_ != NULL && function_->proxy()->raw_name() == name) { | 605 if (function_ != NULL && function_->proxy()->raw_name() == name) { |
610 return function_->proxy()->var(); | 606 return function_->proxy()->var(); |
611 } else if (!scope_info_.is_null()) { | 607 } else if (!scope_info_.is_null()) { |
(...skipping 30 matching lines...) Expand all Loading... |
642 Variable* DeclarationScope::DeclareParameter( | 638 Variable* DeclarationScope::DeclareParameter( |
643 const AstRawString* name, VariableMode mode, bool is_optional, bool is_rest, | 639 const AstRawString* name, VariableMode mode, bool is_optional, bool is_rest, |
644 bool* is_duplicate, AstValueFactory* ast_value_factory) { | 640 bool* is_duplicate, AstValueFactory* ast_value_factory) { |
645 DCHECK(!already_resolved()); | 641 DCHECK(!already_resolved()); |
646 DCHECK(is_function_scope()); | 642 DCHECK(is_function_scope()); |
647 DCHECK(!is_optional || !is_rest); | 643 DCHECK(!is_optional || !is_rest); |
648 Variable* var; | 644 Variable* var; |
649 if (mode == TEMPORARY) { | 645 if (mode == TEMPORARY) { |
650 var = NewTemporary(name); | 646 var = NewTemporary(name); |
651 } else { | 647 } else { |
652 var = variables_.Declare(this, name, mode, Variable::NORMAL, | 648 var = variables_.Declare(zone(), this, name, mode, Variable::NORMAL, |
653 kCreatedInitialized); | 649 kCreatedInitialized); |
654 // TODO(wingo): Avoid O(n^2) check. | 650 // TODO(wingo): Avoid O(n^2) check. |
655 *is_duplicate = IsDeclaredParameter(name); | 651 *is_duplicate = IsDeclaredParameter(name); |
656 } | 652 } |
657 if (!is_optional && !is_rest && arity_ == params_.length()) { | 653 if (!is_optional && !is_rest && arity_ == params_.length()) { |
658 ++arity_; | 654 ++arity_; |
659 } | 655 } |
660 if (is_rest) { | 656 if (is_rest) { |
661 DCHECK_NULL(rest_parameter_); | 657 DCHECK_NULL(rest_parameter_); |
662 rest_parameter_ = var; | 658 rest_parameter_ = var; |
663 rest_index_ = num_parameters(); | 659 rest_index_ = num_parameters(); |
664 } | 660 } |
665 params_.Add(var, zone()); | 661 params_.Add(var, zone()); |
666 if (name == ast_value_factory->arguments_string()) { | 662 if (name == ast_value_factory->arguments_string()) { |
667 has_arguments_parameter_ = true; | 663 has_arguments_parameter_ = true; |
668 } | 664 } |
669 return var; | 665 return var; |
670 } | 666 } |
671 | 667 |
672 Variable* Scope::DeclareLocal(const AstRawString* name, VariableMode mode, | 668 Variable* Scope::DeclareLocal(const AstRawString* name, VariableMode mode, |
673 InitializationFlag init_flag, Variable::Kind kind, | 669 InitializationFlag init_flag, Variable::Kind kind, |
674 MaybeAssignedFlag maybe_assigned_flag) { | 670 MaybeAssignedFlag maybe_assigned_flag) { |
675 DCHECK(!already_resolved()); | 671 DCHECK(!already_resolved()); |
676 // This function handles VAR, LET, and CONST modes. DYNAMIC variables are | 672 // This function handles VAR, LET, and CONST modes. DYNAMIC variables are |
677 // introduced during variable allocation, and TEMPORARY variables are | 673 // introduced during variable allocation, and TEMPORARY variables are |
678 // allocated via NewTemporary(). | 674 // allocated via NewTemporary(). |
679 DCHECK(IsDeclaredVariableMode(mode)); | 675 DCHECK(IsDeclaredVariableMode(mode)); |
680 return variables_.Declare(this, name, mode, kind, init_flag, | 676 return variables_.Declare(zone(), this, name, mode, kind, init_flag, |
681 maybe_assigned_flag); | 677 maybe_assigned_flag); |
682 } | 678 } |
683 | 679 |
684 Variable* DeclarationScope::DeclareDynamicGlobal(const AstRawString* name) { | 680 Variable* DeclarationScope::DeclareDynamicGlobal(const AstRawString* name) { |
685 DCHECK(is_script_scope()); | 681 DCHECK(is_script_scope()); |
686 return variables_.Declare(this, | 682 return variables_.Declare(zone(), this, name, DYNAMIC_GLOBAL, |
687 name, | 683 Variable::NORMAL, kCreatedInitialized); |
688 DYNAMIC_GLOBAL, | |
689 Variable::NORMAL, | |
690 kCreatedInitialized); | |
691 } | 684 } |
692 | 685 |
693 | 686 |
694 bool Scope::RemoveUnresolved(VariableProxy* var) { | 687 bool Scope::RemoveUnresolved(VariableProxy* var) { |
695 if (unresolved_ == var) { | 688 if (unresolved_ == var) { |
696 unresolved_ = var->next_unresolved(); | 689 unresolved_ = var->next_unresolved(); |
697 var->set_next_unresolved(nullptr); | 690 var->set_next_unresolved(nullptr); |
698 return true; | 691 return true; |
699 } | 692 } |
700 VariableProxy* current = unresolved_; | 693 VariableProxy* current = unresolved_; |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1259 | 1252 |
1260 | 1253 |
1261 Variable* Scope::NonLocal(const AstRawString* name, VariableMode mode) { | 1254 Variable* Scope::NonLocal(const AstRawString* name, VariableMode mode) { |
1262 if (dynamics_ == NULL) dynamics_ = new (zone()) DynamicScopePart(zone()); | 1255 if (dynamics_ == NULL) dynamics_ = new (zone()) DynamicScopePart(zone()); |
1263 VariableMap* map = dynamics_->GetMap(mode); | 1256 VariableMap* map = dynamics_->GetMap(mode); |
1264 Variable* var = map->Lookup(name); | 1257 Variable* var = map->Lookup(name); |
1265 if (var == NULL) { | 1258 if (var == NULL) { |
1266 // Declare a new non-local. | 1259 // Declare a new non-local. |
1267 InitializationFlag init_flag = (mode == VAR) | 1260 InitializationFlag init_flag = (mode == VAR) |
1268 ? kCreatedInitialized : kNeedsInitialization; | 1261 ? kCreatedInitialized : kNeedsInitialization; |
1269 var = map->Declare(NULL, | 1262 var = map->Declare(zone(), NULL, name, mode, Variable::NORMAL, init_flag); |
1270 name, | |
1271 mode, | |
1272 Variable::NORMAL, | |
1273 init_flag); | |
1274 // Allocate it by giving it a dynamic lookup. | 1263 // Allocate it by giving it a dynamic lookup. |
1275 var->AllocateTo(VariableLocation::LOOKUP, -1); | 1264 var->AllocateTo(VariableLocation::LOOKUP, -1); |
1276 } | 1265 } |
1277 return var; | 1266 return var; |
1278 } | 1267 } |
1279 | 1268 |
1280 Variable* Scope::LookupRecursive(VariableProxy* proxy, | 1269 Variable* Scope::LookupRecursive(VariableProxy* proxy, |
1281 BindingKind* binding_kind, | 1270 BindingKind* binding_kind, |
1282 AstNodeFactory* factory, | 1271 AstNodeFactory* factory, |
1283 Scope* max_outer_scope) { | 1272 Scope* max_outer_scope) { |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1770 function != NULL && function->proxy()->var()->IsContextSlot(); | 1759 function != NULL && function->proxy()->var()->IsContextSlot(); |
1771 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - | 1760 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
1772 (is_function_var_in_context ? 1 : 0); | 1761 (is_function_var_in_context ? 1 : 0); |
1773 } | 1762 } |
1774 | 1763 |
1775 | 1764 |
1776 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1765 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
1777 | 1766 |
1778 } // namespace internal | 1767 } // namespace internal |
1779 } // namespace v8 | 1768 } // namespace v8 |
OLD | NEW |