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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 | 328 |
329 Variable* result = variables_.Declare(zone(), this, name, mode, kind, | 329 Variable* result = variables_.Declare(zone(), this, name, mode, kind, |
330 init_flag, maybe_assigned_flag); | 330 init_flag, maybe_assigned_flag); |
331 result->AllocateTo(location, index); | 331 result->AllocateTo(location, index); |
332 } | 332 } |
333 | 333 |
334 // Internalize function proxy for this scope. | 334 // Internalize function proxy for this scope. |
335 if (scope_info_->HasFunctionName()) { | 335 if (scope_info_->HasFunctionName()) { |
336 Handle<String> name_handle(scope_info_->FunctionName(), isolate); | 336 Handle<String> name_handle(scope_info_->FunctionName(), isolate); |
337 const AstRawString* name = ast_value_factory->GetString(name_handle); | 337 const AstRawString* name = ast_value_factory->GetString(name_handle); |
338 VariableMode mode; | 338 int index = scope_info_->FunctionContextSlotIndex(*name_handle); |
339 int index = scope_info_->FunctionContextSlotIndex(*name_handle, &mode); | |
340 if (index >= 0) { | 339 if (index >= 0) { |
341 Variable* result = AsDeclarationScope()->DeclareFunctionVar(name); | 340 Variable* result = AsDeclarationScope()->DeclareFunctionVar(name); |
342 DCHECK_EQ(mode, result->mode()); | |
343 result->AllocateTo(VariableLocation::CONTEXT, index); | 341 result->AllocateTo(VariableLocation::CONTEXT, index); |
344 } | 342 } |
345 } | 343 } |
346 | 344 |
347 scope_info_ = Handle<ScopeInfo>::null(); | 345 scope_info_ = Handle<ScopeInfo>::null(); |
348 } | 346 } |
349 | 347 |
350 DeclarationScope* Scope::AsDeclarationScope() { | 348 DeclarationScope* Scope::AsDeclarationScope() { |
351 DCHECK(is_declaration_scope()); | 349 DCHECK(is_declaration_scope()); |
352 return static_cast<DeclarationScope*>(this); | 350 return static_cast<DeclarationScope*>(this); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 IsAccessorFunction(function_kind_)) { | 419 IsAccessorFunction(function_kind_)) { |
422 this_function_ = variables_.Declare( | 420 this_function_ = variables_.Declare( |
423 zone(), this, ast_value_factory->this_function_string(), CONST, | 421 zone(), this, ast_value_factory->this_function_string(), CONST, |
424 Variable::NORMAL, kCreatedInitialized); | 422 Variable::NORMAL, kCreatedInitialized); |
425 } | 423 } |
426 } | 424 } |
427 | 425 |
428 Variable* DeclarationScope::DeclareFunctionVar(const AstRawString* name) { | 426 Variable* DeclarationScope::DeclareFunctionVar(const AstRawString* name) { |
429 DCHECK(is_function_scope()); | 427 DCHECK(is_function_scope()); |
430 DCHECK_NULL(function_); | 428 DCHECK_NULL(function_); |
431 VariableMode mode = is_strict(language_mode()) ? CONST : CONST_LEGACY; | 429 Variable::Kind kind = is_sloppy(language_mode()) |
432 function_ = new (zone()) | 430 ? Variable::SLOPPY_FUNCTION_NAME |
433 Variable(this, name, mode, Variable::NORMAL, kCreatedInitialized); | 431 : Variable::NORMAL; |
| 432 function_ = |
| 433 new (zone()) Variable(this, name, CONST, kind, kCreatedInitialized); |
434 return function_; | 434 return function_; |
435 } | 435 } |
436 | 436 |
437 Scope* Scope::FinalizeBlockScope() { | 437 Scope* Scope::FinalizeBlockScope() { |
438 DCHECK(is_block_scope()); | 438 DCHECK(is_block_scope()); |
439 | 439 |
440 if (variables_.occupancy() > 0 || | 440 if (variables_.occupancy() > 0 || |
441 (is_declaration_scope() && calls_sloppy_eval())) { | 441 (is_declaration_scope() && calls_sloppy_eval())) { |
442 return this; | 442 return this; |
443 } | 443 } |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 maybe_assigned_flag); | 598 maybe_assigned_flag); |
599 var->AllocateTo(location, index); | 599 var->AllocateTo(location, index); |
600 return var; | 600 return var; |
601 } | 601 } |
602 | 602 |
603 Variable* DeclarationScope::LookupFunctionVar(const AstRawString* name) { | 603 Variable* DeclarationScope::LookupFunctionVar(const AstRawString* name) { |
604 if (function_ != nullptr && function_->raw_name() == name) { | 604 if (function_ != nullptr && function_->raw_name() == name) { |
605 return function_; | 605 return function_; |
606 } else if (!scope_info_.is_null()) { | 606 } else if (!scope_info_.is_null()) { |
607 // If we are backed by a scope info, try to lookup the variable there. | 607 // If we are backed by a scope info, try to lookup the variable there. |
608 VariableMode mode; | 608 int index = scope_info_->FunctionContextSlotIndex(*(name->string())); |
609 int index = scope_info_->FunctionContextSlotIndex(*(name->string()), &mode); | |
610 if (index < 0) return nullptr; | 609 if (index < 0) return nullptr; |
611 Variable* var = DeclareFunctionVar(name); | 610 Variable* var = DeclareFunctionVar(name); |
612 DCHECK_EQ(mode, var->mode()); | |
613 var->AllocateTo(VariableLocation::CONTEXT, index); | 611 var->AllocateTo(VariableLocation::CONTEXT, index); |
614 return var; | 612 return var; |
615 } else { | 613 } else { |
616 return nullptr; | 614 return nullptr; |
617 } | 615 } |
618 } | 616 } |
619 | 617 |
620 | 618 |
621 Variable* Scope::Lookup(const AstRawString* name) { | 619 Variable* Scope::Lookup(const AstRawString* name) { |
622 for (Scope* scope = this; | 620 for (Scope* scope = this; |
(...skipping 1158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1781 function != nullptr && function->IsContextSlot(); | 1779 function != nullptr && function->IsContextSlot(); |
1782 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - | 1780 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
1783 (is_function_var_in_context ? 1 : 0); | 1781 (is_function_var_in_context ? 1 : 0); |
1784 } | 1782 } |
1785 | 1783 |
1786 | 1784 |
1787 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1785 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
1788 | 1786 |
1789 } // namespace internal | 1787 } // namespace internal |
1790 } // namespace v8 | 1788 } // namespace v8 |
OLD | NEW |