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 "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/ast/scopeinfo.h" | 8 #include "src/ast/scopeinfo.h" |
9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
10 #include "src/messages.h" | 10 #include "src/messages.h" |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 name, | 553 name, |
554 TEMPORARY, | 554 TEMPORARY, |
555 Variable::NORMAL, | 555 Variable::NORMAL, |
556 kCreatedInitialized); | 556 kCreatedInitialized); |
557 scope->AddTemporary(var); | 557 scope->AddTemporary(var); |
558 return var; | 558 return var; |
559 } | 559 } |
560 | 560 |
561 int Scope::RemoveTemporary(Variable* var) { | 561 int Scope::RemoveTemporary(Variable* var) { |
562 DCHECK_NOT_NULL(var); | 562 DCHECK_NOT_NULL(var); |
| 563 // Temporaries are only placed in ClosureScopes. |
| 564 DCHECK_EQ(ClosureScope(), this); |
| 565 DCHECK_EQ(var->scope()->ClosureScope(), var->scope()); |
| 566 // If the temporary is not here, return quickly. |
| 567 if (var->scope() != this) return -1; |
563 // Most likely (always?) any temporary variable we want to remove | 568 // Most likely (always?) any temporary variable we want to remove |
564 // was just added before, so we search backwards. | 569 // was just added before, so we search backwards. |
565 for (int i = temps_.length(); i-- > 0;) { | 570 for (int i = temps_.length(); i-- > 0;) { |
566 if (temps_[i] == var) { | 571 if (temps_[i] == var) { |
567 // Don't shrink temps_, as callers of this method expect | 572 // Don't shrink temps_, as callers of this method expect |
568 // the returned indices to be unique per-scope. | 573 // the returned indices to be unique per-scope. |
569 temps_[i] = nullptr; | 574 temps_[i] = nullptr; |
570 return i; | 575 return i; |
571 } | 576 } |
572 } | 577 } |
(...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1517 function_ != NULL && function_->proxy()->var()->IsContextSlot(); | 1522 function_ != NULL && function_->proxy()->var()->IsContextSlot(); |
1518 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - | 1523 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
1519 (is_function_var_in_context ? 1 : 0); | 1524 (is_function_var_in_context ? 1 : 0); |
1520 } | 1525 } |
1521 | 1526 |
1522 | 1527 |
1523 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1528 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
1524 | 1529 |
1525 } // namespace internal | 1530 } // namespace internal |
1526 } // namespace v8 | 1531 } // namespace v8 |
OLD | NEW |