Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(677)

Side by Side Diff: src/scopes.cc

Issue 1053773006: [es6] implement default/optional parameters (WIP / comments) (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Experimental not-quite-TDZ support Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/scopes.h ('k') | src/variables.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 num_heap_slots_ = Context::MIN_CONTEXT_SLOTS; 129 num_heap_slots_ = Context::MIN_CONTEXT_SLOTS;
130 Variable* variable = variables_.Declare(this, 130 Variable* variable = variables_.Declare(this,
131 catch_variable_name, 131 catch_variable_name,
132 VAR, 132 VAR,
133 Variable::NORMAL, 133 Variable::NORMAL,
134 kCreatedInitialized); 134 kCreatedInitialized);
135 AllocateHeapSlot(variable); 135 AllocateHeapSlot(variable);
136 } 136 }
137 137
138 138
139 void Scope::SetParameterExpressionsScopeFor(Scope* function_scope) {
140 DCHECK(function_scope->outer_scope() == outer_scope());
141 DCHECK(function_scope->is_function_scope());
142 DCHECK_NULL(parameter_scope_);
143 SetScopeName(ast_value_factory_->GetOneByteString("parameter expressions"));
144 parameter_scope_ = function_scope;
145 }
146
147
139 void Scope::SetDefaults(ScopeType scope_type, Scope* outer_scope, 148 void Scope::SetDefaults(ScopeType scope_type, Scope* outer_scope,
140 Handle<ScopeInfo> scope_info, 149 Handle<ScopeInfo> scope_info,
141 FunctionKind function_kind) { 150 FunctionKind function_kind) {
142 outer_scope_ = outer_scope; 151 outer_scope_ = outer_scope;
143 scope_type_ = scope_type; 152 scope_type_ = scope_type;
153 parameter_scope_ = nullptr;
144 function_kind_ = function_kind; 154 function_kind_ = function_kind;
145 block_scope_is_class_scope_ = false; 155 block_scope_is_class_scope_ = false;
146 scope_name_ = ast_value_factory_->empty_string(); 156 scope_name_ = ast_value_factory_->empty_string();
147 dynamics_ = NULL; 157 dynamics_ = NULL;
148 receiver_ = NULL; 158 receiver_ = NULL;
149 new_target_ = nullptr; 159 new_target_ = nullptr;
150 function_ = NULL; 160 function_ = NULL;
151 arguments_ = NULL; 161 arguments_ = NULL;
152 illegal_redecl_ = NULL; 162 illegal_redecl_ = NULL;
153 scope_inside_with_ = false; 163 scope_inside_with_ = false;
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 // Propagate usage flags to outer scope. 380 // Propagate usage flags to outer scope.
371 if (uses_arguments()) outer_scope_->RecordArgumentsUsage(); 381 if (uses_arguments()) outer_scope_->RecordArgumentsUsage();
372 if (uses_super_property()) outer_scope_->RecordSuperPropertyUsage(); 382 if (uses_super_property()) outer_scope_->RecordSuperPropertyUsage();
373 if (uses_this()) outer_scope_->RecordThisUsage(); 383 if (uses_this()) outer_scope_->RecordThisUsage();
374 384
375 return NULL; 385 return NULL;
376 } 386 }
377 387
378 388
379 Variable* Scope::LookupLocal(const AstRawString* name) { 389 Variable* Scope::LookupLocal(const AstRawString* name) {
390 if (parameter_scope_) {
391 Variable* result = parameter_scope_->variables_.Lookup(name);
392 if (result != nullptr && parameter_scope_->params_.Contains(result)) {
393 return result;
394 }
395 }
396
380 Variable* result = variables_.Lookup(name); 397 Variable* result = variables_.Lookup(name);
381 if (result != NULL || scope_info_.is_null()) { 398 if (result != NULL || scope_info_.is_null()) {
382 return result; 399 return result;
383 } 400 }
384 // The Scope is backed up by ScopeInfo. This means it cannot operate in a 401 // The Scope is backed up by ScopeInfo. This means it cannot operate in a
385 // heap-independent mode, and all strings must be internalized immediately. So 402 // heap-independent mode, and all strings must be internalized immediately. So
386 // it's ok to get the Handle<String> here. 403 // it's ok to get the Handle<String> here.
387 Handle<String> name_handle = name->string(); 404 Handle<String> name_handle = name->string();
388 // If we have a serialized scope info, we might find the variable there. 405 // If we have a serialized scope info, we might find the variable there.
389 // There should be no local slot with the given name. 406 // There should be no local slot with the given name.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 scope != NULL; 462 scope != NULL;
446 scope = scope->outer_scope()) { 463 scope = scope->outer_scope()) {
447 Variable* var = scope->LookupLocal(name); 464 Variable* var = scope->LookupLocal(name);
448 if (var != NULL) return var; 465 if (var != NULL) return var;
449 } 466 }
450 return NULL; 467 return NULL;
451 } 468 }
452 469
453 470
454 Variable* Scope::DeclareParameter(const AstRawString* name, VariableMode mode, 471 Variable* Scope::DeclareParameter(const AstRawString* name, VariableMode mode,
455 bool is_rest) { 472 ParameterKind kind) {
456 DCHECK(!already_resolved()); 473 DCHECK(!already_resolved());
457 DCHECK(is_function_scope()); 474 DCHECK(is_function_scope());
458 Variable* var = variables_.Declare(this, name, mode, Variable::NORMAL, 475 Variable* var = variables_.Declare(this, name, mode, Variable::NORMAL,
459 kCreatedInitialized); 476 kCreatedInitialized);
460 if (is_rest) { 477 var->set_parameter_kind(kind);
478 if (kind == RestParameter) {
461 DCHECK_NULL(rest_parameter_); 479 DCHECK_NULL(rest_parameter_);
462 rest_parameter_ = var; 480 rest_parameter_ = var;
463 rest_index_ = num_parameters(); 481 rest_index_ = num_parameters();
464 } 482 }
465 params_.Add(var, zone()); 483 params_.Add(var, zone());
466 return var; 484 return var;
467 } 485 }
468 486
469 487
470 Variable* Scope::DeclareLocal(const AstRawString* name, VariableMode mode, 488 Variable* Scope::DeclareLocal(const AstRawString* name, VariableMode mode,
(...skipping 993 matching lines...) Expand 10 before | Expand all | Expand 10 after
1464 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0); 1482 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0);
1465 } 1483 }
1466 1484
1467 1485
1468 int Scope::ContextLocalCount() const { 1486 int Scope::ContextLocalCount() const {
1469 if (num_heap_slots() == 0) return 0; 1487 if (num_heap_slots() == 0) return 0;
1470 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - 1488 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS -
1471 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); 1489 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0);
1472 } 1490 }
1473 } } // namespace v8::internal 1491 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/scopes.h ('k') | src/variables.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698