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/scopes.h" | 7 #include "src/scopes.h" |
8 | 8 |
9 #include "src/accessors.h" | 9 #include "src/accessors.h" |
10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 inner_scope_uses_super_property_ = false; | 173 inner_scope_uses_super_property_ = false; |
174 inner_scope_uses_super_constructor_call_ = false; | 174 inner_scope_uses_super_constructor_call_ = false; |
175 force_eager_compilation_ = false; | 175 force_eager_compilation_ = false; |
176 force_context_allocation_ = (outer_scope != NULL && !is_function_scope()) | 176 force_context_allocation_ = (outer_scope != NULL && !is_function_scope()) |
177 ? outer_scope->has_forced_context_allocation() : false; | 177 ? outer_scope->has_forced_context_allocation() : false; |
178 num_var_or_const_ = 0; | 178 num_var_or_const_ = 0; |
179 num_stack_slots_ = 0; | 179 num_stack_slots_ = 0; |
180 num_heap_slots_ = 0; | 180 num_heap_slots_ = 0; |
181 num_modules_ = 0; | 181 num_modules_ = 0; |
182 module_var_ = NULL, | 182 module_var_ = NULL, |
| 183 rest_parameter_ = NULL; |
| 184 rest_index_ = -1; |
183 scope_info_ = scope_info; | 185 scope_info_ = scope_info; |
184 start_position_ = RelocInfo::kNoPosition; | 186 start_position_ = RelocInfo::kNoPosition; |
185 end_position_ = RelocInfo::kNoPosition; | 187 end_position_ = RelocInfo::kNoPosition; |
186 if (!scope_info.is_null()) { | 188 if (!scope_info.is_null()) { |
187 scope_calls_eval_ = scope_info->CallsEval(); | 189 scope_calls_eval_ = scope_info->CallsEval(); |
188 strict_mode_ = scope_info->strict_mode(); | 190 strict_mode_ = scope_info->strict_mode(); |
189 } | 191 } |
190 } | 192 } |
191 | 193 |
192 | 194 |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 for (Scope* scope = this; | 445 for (Scope* scope = this; |
444 scope != NULL; | 446 scope != NULL; |
445 scope = scope->outer_scope()) { | 447 scope = scope->outer_scope()) { |
446 Variable* var = scope->LookupLocal(name); | 448 Variable* var = scope->LookupLocal(name); |
447 if (var != NULL) return var; | 449 if (var != NULL) return var; |
448 } | 450 } |
449 return NULL; | 451 return NULL; |
450 } | 452 } |
451 | 453 |
452 | 454 |
453 Variable* Scope::DeclareParameter(const AstRawString* name, VariableMode mode) { | 455 Variable* Scope::DeclareParameter(const AstRawString* name, VariableMode mode, |
| 456 bool is_rest) { |
454 DCHECK(!already_resolved()); | 457 DCHECK(!already_resolved()); |
455 DCHECK(is_function_scope()); | 458 DCHECK(is_function_scope()); |
456 Variable* var = variables_.Declare(this, name, mode, true, Variable::NORMAL, | 459 Variable* var = variables_.Declare(this, name, mode, true, Variable::NORMAL, |
457 kCreatedInitialized); | 460 kCreatedInitialized); |
| 461 if (is_rest) { |
| 462 DCHECK_EQ(NULL, rest_parameter_); |
| 463 rest_parameter_ = var; |
| 464 rest_index_ = num_parameters(); |
| 465 } |
458 params_.Add(var, zone()); | 466 params_.Add(var, zone()); |
459 return var; | 467 return var; |
460 } | 468 } |
461 | 469 |
462 | 470 |
463 Variable* Scope::DeclareLocal(const AstRawString* name, VariableMode mode, | 471 Variable* Scope::DeclareLocal(const AstRawString* name, VariableMode mode, |
464 InitializationFlag init_flag, | 472 InitializationFlag init_flag, |
465 MaybeAssignedFlag maybe_assigned_flag, | 473 MaybeAssignedFlag maybe_assigned_flag, |
466 Interface* interface) { | 474 Interface* interface) { |
467 DCHECK(!already_resolved()); | 475 DCHECK(!already_resolved()); |
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1279 // We are using 'arguments'. Tell the code generator that is needs to | 1287 // We are using 'arguments'. Tell the code generator that is needs to |
1280 // allocate the arguments object by setting 'arguments_'. | 1288 // allocate the arguments object by setting 'arguments_'. |
1281 arguments_ = arguments; | 1289 arguments_ = arguments; |
1282 | 1290 |
1283 // In strict mode 'arguments' does not alias formal parameters. | 1291 // In strict mode 'arguments' does not alias formal parameters. |
1284 // Therefore in strict mode we allocate parameters as if 'arguments' | 1292 // Therefore in strict mode we allocate parameters as if 'arguments' |
1285 // were not used. | 1293 // were not used. |
1286 uses_sloppy_arguments = strict_mode() == SLOPPY; | 1294 uses_sloppy_arguments = strict_mode() == SLOPPY; |
1287 } | 1295 } |
1288 | 1296 |
| 1297 if (rest_parameter_ && !MustAllocate(rest_parameter_)) { |
| 1298 rest_parameter_ = NULL; |
| 1299 } |
| 1300 |
1289 // The same parameter may occur multiple times in the parameters_ list. | 1301 // The same parameter may occur multiple times in the parameters_ list. |
1290 // If it does, and if it is not copied into the context object, it must | 1302 // If it does, and if it is not copied into the context object, it must |
1291 // receive the highest parameter index for that parameter; thus iteration | 1303 // receive the highest parameter index for that parameter; thus iteration |
1292 // order is relevant! | 1304 // order is relevant! |
1293 for (int i = params_.length() - 1; i >= 0; --i) { | 1305 for (int i = params_.length() - 1; i >= 0; --i) { |
1294 Variable* var = params_[i]; | 1306 Variable* var = params_[i]; |
| 1307 if (var == rest_parameter_) continue; |
| 1308 |
1295 DCHECK(var->scope() == this); | 1309 DCHECK(var->scope() == this); |
1296 if (uses_sloppy_arguments || has_forced_context_allocation()) { | 1310 if (uses_sloppy_arguments || has_forced_context_allocation()) { |
1297 // Force context allocation of the parameter. | 1311 // Force context allocation of the parameter. |
1298 var->ForceContextAllocation(); | 1312 var->ForceContextAllocation(); |
1299 } | 1313 } |
1300 | 1314 |
1301 if (MustAllocate(var)) { | 1315 if (MustAllocate(var)) { |
1302 if (MustAllocateInContext(var)) { | 1316 if (MustAllocateInContext(var)) { |
1303 DCHECK(var->IsUnallocated() || var->IsContextSlot()); | 1317 DCHECK(var->IsUnallocated() || var->IsContextSlot()); |
1304 if (var->IsUnallocated()) { | 1318 if (var->IsUnallocated()) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1352 AllocateNonParameterLocal(vars[i].var()); | 1366 AllocateNonParameterLocal(vars[i].var()); |
1353 } | 1367 } |
1354 | 1368 |
1355 // For now, function_ must be allocated at the very end. If it gets | 1369 // For now, function_ must be allocated at the very end. If it gets |
1356 // allocated in the context, it must be the last slot in the context, | 1370 // allocated in the context, it must be the last slot in the context, |
1357 // because of the current ScopeInfo implementation (see | 1371 // because of the current ScopeInfo implementation (see |
1358 // ScopeInfo::ScopeInfo(FunctionScope* scope) constructor). | 1372 // ScopeInfo::ScopeInfo(FunctionScope* scope) constructor). |
1359 if (function_ != NULL) { | 1373 if (function_ != NULL) { |
1360 AllocateNonParameterLocal(function_->proxy()->var()); | 1374 AllocateNonParameterLocal(function_->proxy()->var()); |
1361 } | 1375 } |
| 1376 |
| 1377 if (rest_parameter_) { |
| 1378 AllocateNonParameterLocal(rest_parameter_); |
| 1379 } |
1362 } | 1380 } |
1363 | 1381 |
1364 | 1382 |
1365 void Scope::AllocateVariablesRecursively() { | 1383 void Scope::AllocateVariablesRecursively() { |
1366 // Allocate variables for inner scopes. | 1384 // Allocate variables for inner scopes. |
1367 for (int i = 0; i < inner_scopes_.length(); i++) { | 1385 for (int i = 0; i < inner_scopes_.length(); i++) { |
1368 inner_scopes_[i]->AllocateVariablesRecursively(); | 1386 inner_scopes_[i]->AllocateVariablesRecursively(); |
1369 } | 1387 } |
1370 | 1388 |
1371 // If scope is already resolved, we still need to allocate | 1389 // If scope is already resolved, we still need to allocate |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1421 } | 1439 } |
1422 | 1440 |
1423 | 1441 |
1424 int Scope::ContextLocalCount() const { | 1442 int Scope::ContextLocalCount() const { |
1425 if (num_heap_slots() == 0) return 0; | 1443 if (num_heap_slots() == 0) return 0; |
1426 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1444 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
1427 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); | 1445 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); |
1428 } | 1446 } |
1429 | 1447 |
1430 } } // namespace v8::internal | 1448 } } // namespace v8::internal |
OLD | NEW |