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 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 | 602 |
603 // Collect internals which are always allocated on the heap. | 603 // Collect internals which are always allocated on the heap. |
604 for (int i = 0; i < internals_.length(); i++) { | 604 for (int i = 0; i < internals_.length(); i++) { |
605 Variable* var = internals_[i]; | 605 Variable* var = internals_[i]; |
606 if (var->is_used()) { | 606 if (var->is_used()) { |
607 DCHECK(var->IsContextSlot()); | 607 DCHECK(var->IsContextSlot()); |
608 context_locals->Add(var, zone()); | 608 context_locals->Add(var, zone()); |
609 } | 609 } |
610 } | 610 } |
611 | 611 |
| 612 // Arrow functions can cause the receiver to be copied in the context. |
| 613 if (receiver_ && receiver_->has_forced_context_allocation()) { |
| 614 DCHECK(receiver_->IsContextSlot()); |
| 615 context_locals->Add(receiver_, zone()); |
| 616 } |
| 617 |
612 // Collect temporaries which are always allocated on the stack, unless the | 618 // Collect temporaries which are always allocated on the stack, unless the |
613 // context as a whole has forced context allocation. | 619 // context as a whole has forced context allocation. |
614 for (int i = 0; i < temps_.length(); i++) { | 620 for (int i = 0; i < temps_.length(); i++) { |
615 Variable* var = temps_[i]; | 621 Variable* var = temps_[i]; |
616 if (var->is_used()) { | 622 if (var->is_used()) { |
617 if (var->IsContextSlot()) { | 623 if (var->IsContextSlot()) { |
618 DCHECK(has_forced_context_allocation()); | 624 DCHECK(has_forced_context_allocation()); |
619 context_locals->Add(var, zone()); | 625 context_locals->Add(var, zone()); |
620 } else { | 626 } else { |
621 DCHECK(var->IsStackLocal()); | 627 DCHECK(var->IsStackLocal()); |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1171 } | 1177 } |
1172 | 1178 |
1173 bool calls_sloppy_eval = | 1179 bool calls_sloppy_eval = |
1174 this->calls_sloppy_eval() || outer_scope_calls_sloppy_eval_; | 1180 this->calls_sloppy_eval() || outer_scope_calls_sloppy_eval_; |
1175 for (int i = 0; i < inner_scopes_.length(); i++) { | 1181 for (int i = 0; i < inner_scopes_.length(); i++) { |
1176 Scope* inner = inner_scopes_[i]; | 1182 Scope* inner = inner_scopes_[i]; |
1177 inner->PropagateScopeInfo(calls_sloppy_eval); | 1183 inner->PropagateScopeInfo(calls_sloppy_eval); |
1178 if (inner->scope_calls_eval_ || inner->inner_scope_calls_eval_) { | 1184 if (inner->scope_calls_eval_ || inner->inner_scope_calls_eval_) { |
1179 inner_scope_calls_eval_ = true; | 1185 inner_scope_calls_eval_ = true; |
1180 } | 1186 } |
| 1187 |
1181 // If the inner scope is an arrow function, propagate the flags tracking | 1188 // If the inner scope is an arrow function, propagate the flags tracking |
1182 // usage of arguments/super/this, but do not propagate them out from normal | 1189 // usage of arguments/super/this, but do not propagate them out from normal |
1183 // functions. | 1190 // functions. |
1184 if (!inner->is_function_scope() || inner->is_arrow_scope()) { | 1191 if (inner->is_arrow_scope()) { |
1185 if (inner->scope_uses_arguments_ || inner->inner_scope_uses_arguments_) { | 1192 if (inner->scope_uses_this_ || inner->inner_scope_uses_this_) |
| 1193 inner_scope_uses_this_ = true; |
| 1194 if (inner->scope_uses_arguments_ || inner->inner_scope_uses_arguments_) |
1186 inner_scope_uses_arguments_ = true; | 1195 inner_scope_uses_arguments_ = true; |
1187 } | |
1188 if (inner->scope_uses_super_property_ || | 1196 if (inner->scope_uses_super_property_ || |
1189 inner->inner_scope_uses_super_property_) { | 1197 inner->inner_scope_uses_super_property_) |
1190 inner_scope_uses_super_property_ = true; | 1198 inner_scope_uses_super_property_ = true; |
1191 } | |
1192 if (inner->uses_super_constructor_call() || | 1199 if (inner->uses_super_constructor_call() || |
1193 inner->inner_scope_uses_super_constructor_call_) { | 1200 inner->inner_scope_uses_super_constructor_call_) |
1194 inner_scope_uses_super_constructor_call_ = true; | 1201 inner_scope_uses_super_constructor_call_ = true; |
1195 } | 1202 } else if (!inner->is_function_scope()) { |
1196 if (inner->scope_uses_this_ || inner->inner_scope_uses_this_) { | 1203 if (inner->scope_uses_this_) |
| 1204 scope_uses_this_ = true; |
| 1205 if (inner->scope_uses_arguments_) |
| 1206 scope_uses_arguments_ = true; |
| 1207 if (inner->scope_uses_super_property_) |
| 1208 scope_uses_super_property_ = true; |
| 1209 if (inner->scope_uses_super_constructor_call_) |
| 1210 scope_uses_super_constructor_call_ = true; |
| 1211 if (inner->inner_scope_uses_this_) |
1197 inner_scope_uses_this_ = true; | 1212 inner_scope_uses_this_ = true; |
1198 } | 1213 if (inner->inner_scope_uses_arguments_) |
| 1214 inner_scope_uses_arguments_ = true; |
| 1215 if (inner->inner_scope_uses_super_property_) |
| 1216 inner_scope_uses_super_property_ = true; |
| 1217 if (inner->inner_scope_uses_super_constructor_call_) |
| 1218 inner_scope_uses_super_constructor_call_ = true; |
1199 } | 1219 } |
| 1220 |
1200 if (inner->force_eager_compilation_) { | 1221 if (inner->force_eager_compilation_) { |
1201 force_eager_compilation_ = true; | 1222 force_eager_compilation_ = true; |
1202 } | 1223 } |
1203 if (asm_module_ && inner->scope_type() == FUNCTION_SCOPE) { | 1224 if (asm_module_ && inner->scope_type() == FUNCTION_SCOPE) { |
1204 inner->asm_function_ = true; | 1225 inner->asm_function_ = true; |
1205 } | 1226 } |
1206 } | 1227 } |
1207 } | 1228 } |
1208 | 1229 |
1209 | 1230 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1317 AllocateHeapSlot(var); | 1338 AllocateHeapSlot(var); |
1318 } | 1339 } |
1319 } else { | 1340 } else { |
1320 DCHECK(var->IsUnallocated() || var->IsParameter()); | 1341 DCHECK(var->IsUnallocated() || var->IsParameter()); |
1321 if (var->IsUnallocated()) { | 1342 if (var->IsUnallocated()) { |
1322 var->AllocateTo(Variable::PARAMETER, i); | 1343 var->AllocateTo(Variable::PARAMETER, i); |
1323 } | 1344 } |
1324 } | 1345 } |
1325 } | 1346 } |
1326 } | 1347 } |
| 1348 |
| 1349 // If the scope contains at least one inner arrow function which uses |
| 1350 // "this", the receiver must be copied to the context, from where it will |
| 1351 // be looked up by code emitted in the prologues of arrow functions. |
| 1352 if (inner_scope_uses_this_) { |
| 1353 DCHECK(receiver_); |
| 1354 if (receiver_->IsUnallocated() || !receiver_->IsContextSlot()) { |
| 1355 receiver_->ForceContextAllocation(); |
| 1356 AllocateHeapSlot(receiver_); |
| 1357 } |
| 1358 DCHECK(MustAllocateInContext(receiver_)); |
| 1359 } |
1327 } | 1360 } |
1328 | 1361 |
1329 | 1362 |
1330 void Scope::AllocateNonParameterLocal(Variable* var) { | 1363 void Scope::AllocateNonParameterLocal(Variable* var) { |
1331 DCHECK(var->scope() == this); | 1364 DCHECK(var->scope() == this); |
1332 DCHECK(!var->IsVariable(isolate_->factory()->dot_result_string()) || | 1365 DCHECK(!var->IsVariable(isolate_->factory()->dot_result_string()) || |
1333 !var->IsStackLocal()); | 1366 !var->IsStackLocal()); |
1334 if (var->IsUnallocated() && MustAllocate(var)) { | 1367 if (var->IsUnallocated() && MustAllocate(var)) { |
1335 if (MustAllocateInContext(var)) { | 1368 if (MustAllocateInContext(var)) { |
1336 AllocateHeapSlot(var); | 1369 AllocateHeapSlot(var); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1433 } | 1466 } |
1434 | 1467 |
1435 | 1468 |
1436 int Scope::ContextLocalCount() const { | 1469 int Scope::ContextLocalCount() const { |
1437 if (num_heap_slots() == 0) return 0; | 1470 if (num_heap_slots() == 0) return 0; |
1438 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1471 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
1439 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); | 1472 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); |
1440 } | 1473 } |
1441 | 1474 |
1442 } } // namespace v8::internal | 1475 } } // namespace v8::internal |
OLD | NEW |