 Chromium Code Reviews
 Chromium Code Reviews Issue 1127063003:
  [es6] implement default parameters via desugaring  (Closed) 
  Base URL: https://chromium.googlesource.com/v8/v8.git@master
    
  
    Issue 1127063003:
  [es6] implement default parameters via desugaring  (Closed) 
  Base URL: https://chromium.googlesource.com/v8/v8.git@master| 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/v8.h" | 5 #include "src/v8.h" | 
| 6 | 6 | 
| 7 #include "src/accessors.h" | 7 #include "src/accessors.h" | 
| 8 #include "src/bootstrapper.h" | 8 #include "src/bootstrapper.h" | 
| 9 #include "src/messages.h" | 9 #include "src/messages.h" | 
| 10 #include "src/parser.h" | 10 #include "src/parser.h" | 
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 // ---------------------------------------------------------------------------- | 70 // ---------------------------------------------------------------------------- | 
| 71 // Implementation of Scope | 71 // Implementation of Scope | 
| 72 | 72 | 
| 73 Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type, | 73 Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type, | 
| 74 AstValueFactory* ast_value_factory, FunctionKind function_kind) | 74 AstValueFactory* ast_value_factory, FunctionKind function_kind) | 
| 75 : inner_scopes_(4, zone), | 75 : inner_scopes_(4, zone), | 
| 76 variables_(zone), | 76 variables_(zone), | 
| 77 internals_(4, zone), | 77 internals_(4, zone), | 
| 78 temps_(4, zone), | 78 temps_(4, zone), | 
| 79 params_(4, zone), | 79 params_(4, zone), | 
| 80 param_positions_(4, zone), | |
| 80 unresolved_(16, zone), | 81 unresolved_(16, zone), | 
| 81 decls_(4, zone), | 82 decls_(4, zone), | 
| 82 module_descriptor_( | 83 module_descriptor_( | 
| 83 scope_type == MODULE_SCOPE ? ModuleDescriptor::New(zone) : NULL), | 84 scope_type == MODULE_SCOPE ? ModuleDescriptor::New(zone) : NULL), | 
| 84 already_resolved_(false), | 85 already_resolved_(false), | 
| 85 ast_value_factory_(ast_value_factory), | 86 ast_value_factory_(ast_value_factory), | 
| 86 zone_(zone), | 87 zone_(zone), | 
| 87 class_declaration_group_start_(-1) { | 88 class_declaration_group_start_(-1) { | 
| 88 SetDefaults(scope_type, outer_scope, Handle<ScopeInfo>::null(), | 89 SetDefaults(scope_type, outer_scope, Handle<ScopeInfo>::null(), | 
| 89 function_kind); | 90 function_kind); | 
| 90 // The outermost scope must be a script scope. | 91 // The outermost scope must be a script scope. | 
| 91 DCHECK(scope_type == SCRIPT_SCOPE || outer_scope != NULL); | 92 DCHECK(scope_type == SCRIPT_SCOPE || outer_scope != NULL); | 
| 92 DCHECK(!HasIllegalRedeclaration()); | 93 DCHECK(!HasIllegalRedeclaration()); | 
| 93 } | 94 } | 
| 94 | 95 | 
| 95 | 96 | 
| 96 Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type, | 97 Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type, | 
| 97 Handle<ScopeInfo> scope_info, AstValueFactory* value_factory) | 98 Handle<ScopeInfo> scope_info, AstValueFactory* value_factory) | 
| 98 : inner_scopes_(4, zone), | 99 : inner_scopes_(4, zone), | 
| 99 variables_(zone), | 100 variables_(zone), | 
| 100 internals_(4, zone), | 101 internals_(4, zone), | 
| 101 temps_(4, zone), | 102 temps_(4, zone), | 
| 102 params_(4, zone), | 103 params_(4, zone), | 
| 104 param_positions_(4, zone), | |
| 103 unresolved_(16, zone), | 105 unresolved_(16, zone), | 
| 104 decls_(4, zone), | 106 decls_(4, zone), | 
| 105 module_descriptor_(NULL), | 107 module_descriptor_(NULL), | 
| 106 already_resolved_(true), | 108 already_resolved_(true), | 
| 107 ast_value_factory_(value_factory), | 109 ast_value_factory_(value_factory), | 
| 108 zone_(zone), | 110 zone_(zone), | 
| 109 class_declaration_group_start_(-1) { | 111 class_declaration_group_start_(-1) { | 
| 110 SetDefaults(scope_type, NULL, scope_info); | 112 SetDefaults(scope_type, NULL, scope_info); | 
| 111 if (!scope_info.is_null()) { | 113 if (!scope_info.is_null()) { | 
| 112 num_heap_slots_ = scope_info_->ContextLength(); | 114 num_heap_slots_ = scope_info_->ContextLength(); | 
| 113 } | 115 } | 
| 114 // Ensure at least MIN_CONTEXT_SLOTS to indicate a materialized context. | 116 // Ensure at least MIN_CONTEXT_SLOTS to indicate a materialized context. | 
| 115 num_heap_slots_ = Max(num_heap_slots_, | 117 num_heap_slots_ = Max(num_heap_slots_, | 
| 116 static_cast<int>(Context::MIN_CONTEXT_SLOTS)); | 118 static_cast<int>(Context::MIN_CONTEXT_SLOTS)); | 
| 117 AddInnerScope(inner_scope); | 119 AddInnerScope(inner_scope); | 
| 118 } | 120 } | 
| 119 | 121 | 
| 120 | 122 | 
| 121 Scope::Scope(Zone* zone, Scope* inner_scope, | 123 Scope::Scope(Zone* zone, Scope* inner_scope, | 
| 122 const AstRawString* catch_variable_name, | 124 const AstRawString* catch_variable_name, | 
| 123 AstValueFactory* value_factory) | 125 AstValueFactory* value_factory) | 
| 124 : inner_scopes_(1, zone), | 126 : inner_scopes_(1, zone), | 
| 125 variables_(zone), | 127 variables_(zone), | 
| 126 internals_(0, zone), | 128 internals_(0, zone), | 
| 127 temps_(0, zone), | 129 temps_(0, zone), | 
| 128 params_(0, zone), | 130 params_(0, zone), | 
| 131 param_positions_(0, zone), | |
| 129 unresolved_(0, zone), | 132 unresolved_(0, zone), | 
| 130 decls_(0, zone), | 133 decls_(0, zone), | 
| 131 module_descriptor_(NULL), | 134 module_descriptor_(NULL), | 
| 132 already_resolved_(true), | 135 already_resolved_(true), | 
| 133 ast_value_factory_(value_factory), | 136 ast_value_factory_(value_factory), | 
| 134 zone_(zone), | 137 zone_(zone), | 
| 135 class_declaration_group_start_(-1) { | 138 class_declaration_group_start_(-1) { | 
| 136 SetDefaults(CATCH_SCOPE, NULL, Handle<ScopeInfo>::null()); | 139 SetDefaults(CATCH_SCOPE, NULL, Handle<ScopeInfo>::null()); | 
| 137 AddInnerScope(inner_scope); | 140 AddInnerScope(inner_scope); | 
| 138 ++num_var_or_const_; | 141 ++num_var_or_const_; | 
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 452 scope != NULL; | 455 scope != NULL; | 
| 453 scope = scope->outer_scope()) { | 456 scope = scope->outer_scope()) { | 
| 454 Variable* var = scope->LookupLocal(name); | 457 Variable* var = scope->LookupLocal(name); | 
| 455 if (var != NULL) return var; | 458 if (var != NULL) return var; | 
| 456 } | 459 } | 
| 457 return NULL; | 460 return NULL; | 
| 458 } | 461 } | 
| 459 | 462 | 
| 460 | 463 | 
| 461 Variable* Scope::DeclareParameter(const AstRawString* name, VariableMode mode, | 464 Variable* Scope::DeclareParameter(const AstRawString* name, VariableMode mode, | 
| 462 bool is_rest, bool* is_duplicate) { | 465 bool is_rest, bool* is_duplicate, int pos) { | 
| 463 DCHECK(!already_resolved()); | 466 DCHECK(!already_resolved()); | 
| 464 DCHECK(is_function_scope()); | 467 DCHECK(is_function_scope()); | 
| 465 Variable* var = variables_.Declare(this, name, mode, Variable::NORMAL, | 468 Variable* var = variables_.Declare(this, name, mode, Variable::NORMAL, | 
| 466 kCreatedInitialized); | 469 kCreatedInitialized); | 
| 467 if (is_rest) { | 470 if (is_rest) { | 
| 468 DCHECK_NULL(rest_parameter_); | 471 DCHECK_NULL(rest_parameter_); | 
| 469 rest_parameter_ = var; | 472 rest_parameter_ = var; | 
| 470 rest_index_ = num_parameters(); | 473 rest_index_ = num_parameters(); | 
| 471 } | 474 } | 
| 472 // TODO(wingo): Avoid O(n^2) check. | 475 // TODO(wingo): Avoid O(n^2) check. | 
| 473 *is_duplicate = IsDeclaredParameter(name); | 476 *is_duplicate = IsDeclaredParameter(name); | 
| 474 params_.Add(var, zone()); | 477 params_.Add(var, zone()); | 
| 478 param_positions_.Add(pos, zone()); | |
| 475 return var; | 479 return var; | 
| 476 } | 480 } | 
| 477 | 481 | 
| 478 | 482 | 
| 479 Variable* Scope::DeclareLocal(const AstRawString* name, VariableMode mode, | 483 Variable* Scope::DeclareLocal(const AstRawString* name, VariableMode mode, | 
| 480 InitializationFlag init_flag, Variable::Kind kind, | 484 InitializationFlag init_flag, Variable::Kind kind, | 
| 481 MaybeAssignedFlag maybe_assigned_flag, | 485 MaybeAssignedFlag maybe_assigned_flag, | 
| 482 int declaration_group_start) { | 486 int declaration_group_start) { | 
| 483 DCHECK(!already_resolved()); | 487 DCHECK(!already_resolved()); | 
| 484 // This function handles VAR, LET, and CONST modes. DYNAMIC variables are | 488 // This function handles VAR, LET, and CONST modes. DYNAMIC variables are | 
| (...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1419 void Scope::AllocateParameter(Variable* var, int index) { | 1423 void Scope::AllocateParameter(Variable* var, int index) { | 
| 1420 if (MustAllocate(var)) { | 1424 if (MustAllocate(var)) { | 
| 1421 if (MustAllocateInContext(var)) { | 1425 if (MustAllocateInContext(var)) { | 
| 1422 DCHECK(var->IsUnallocated() || var->IsContextSlot()); | 1426 DCHECK(var->IsUnallocated() || var->IsContextSlot()); | 
| 1423 if (var->IsUnallocated()) { | 1427 if (var->IsUnallocated()) { | 
| 1424 AllocateHeapSlot(var); | 1428 AllocateHeapSlot(var); | 
| 1425 } | 1429 } | 
| 1426 } else { | 1430 } else { | 
| 1427 DCHECK(var->IsUnallocated() || var->IsParameter()); | 1431 DCHECK(var->IsUnallocated() || var->IsParameter()); | 
| 1428 if (var->IsUnallocated()) { | 1432 if (var->IsUnallocated()) { | 
| 1429 var->AllocateTo(Variable::PARAMETER, index); | 1433 if (IsLexicalVariableMode(var->mode())) { | 
| 
caitp (gmail)
2015/05/20 17:05:16
So this approach doesn't work --- it causes the `D
 | |
| 1434 AllocateStackSlot(var); | |
| 1435 } else { | |
| 1436 var->AllocateTo(Variable::PARAMETER, index); | |
| 1437 } | |
| 1430 } | 1438 } | 
| 1431 } | 1439 } | 
| 1432 } | 1440 } | 
| 1433 } | 1441 } | 
| 1434 | 1442 | 
| 1435 | 1443 | 
| 1436 void Scope::AllocateReceiver() { | 1444 void Scope::AllocateReceiver() { | 
| 1437 DCHECK_NOT_NULL(receiver()); | 1445 DCHECK_NOT_NULL(receiver()); | 
| 1438 DCHECK_EQ(receiver()->scope(), this); | 1446 DCHECK_EQ(receiver()->scope(), this); | 
| 1439 | 1447 | 
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1556 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0); | 1564 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0); | 
| 1557 } | 1565 } | 
| 1558 | 1566 | 
| 1559 | 1567 | 
| 1560 int Scope::ContextLocalCount() const { | 1568 int Scope::ContextLocalCount() const { | 
| 1561 if (num_heap_slots() == 0) return 0; | 1569 if (num_heap_slots() == 0) return 0; | 
| 1562 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1570 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 
| 1563 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); | 1571 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); | 
| 1564 } | 1572 } | 
| 1565 } } // namespace v8::internal | 1573 } } // namespace v8::internal | 
| OLD | NEW |