OLD | NEW |
---|---|
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
11 // with the distribution. | 11 // with the distribution. |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 function_ = NULL; | 192 function_ = NULL; |
193 arguments_ = NULL; | 193 arguments_ = NULL; |
194 arguments_shadow_ = NULL; | 194 arguments_shadow_ = NULL; |
195 illegal_redecl_ = NULL; | 195 illegal_redecl_ = NULL; |
196 scope_inside_with_ = false; | 196 scope_inside_with_ = false; |
197 scope_contains_with_ = false; | 197 scope_contains_with_ = false; |
198 scope_calls_eval_ = false; | 198 scope_calls_eval_ = false; |
199 // Inherit the strict mode from the parent scope. | 199 // Inherit the strict mode from the parent scope. |
200 strict_mode_ = (outer_scope != NULL) && outer_scope->strict_mode_; | 200 strict_mode_ = (outer_scope != NULL) && outer_scope->strict_mode_; |
201 outer_scope_calls_eval_ = false; | 201 outer_scope_calls_eval_ = false; |
202 outer_scope_calls_non_strict_eval_ = false; | |
202 inner_scope_calls_eval_ = false; | 203 inner_scope_calls_eval_ = false; |
203 outer_scope_is_eval_scope_ = false; | 204 outer_scope_is_eval_scope_ = false; |
204 force_eager_compilation_ = false; | 205 force_eager_compilation_ = false; |
205 num_stack_slots_ = 0; | 206 num_stack_slots_ = 0; |
206 num_heap_slots_ = 0; | 207 num_heap_slots_ = 0; |
207 scope_info_ = scope_info; | 208 scope_info_ = scope_info; |
208 } | 209 } |
209 | 210 |
210 | 211 |
211 Scope* Scope::DeserializeScopeChain(CompilationInfo* info, | 212 Scope* Scope::DeserializeScopeChain(CompilationInfo* info, |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
476 | 477 |
477 void Scope::AllocateVariables(Handle<Context> context) { | 478 void Scope::AllocateVariables(Handle<Context> context) { |
478 ASSERT(outer_scope_ == NULL); // eval or global scopes only | 479 ASSERT(outer_scope_ == NULL); // eval or global scopes only |
479 | 480 |
480 // 1) Propagate scope information. | 481 // 1) Propagate scope information. |
481 // If we are in an eval scope, we may have other outer scopes about | 482 // If we are in an eval scope, we may have other outer scopes about |
482 // which we don't know anything at this point. Thus we must be conservative | 483 // which we don't know anything at this point. Thus we must be conservative |
483 // and assume they may invoke eval themselves. Eventually we could capture | 484 // and assume they may invoke eval themselves. Eventually we could capture |
484 // this information in the ScopeInfo and then use it here (by traversing | 485 // this information in the ScopeInfo and then use it here (by traversing |
485 // the call chain stack, at compile time). | 486 // the call chain stack, at compile time). |
487 | |
486 bool eval_scope = is_eval_scope(); | 488 bool eval_scope = is_eval_scope(); |
487 PropagateScopeInfo(eval_scope, eval_scope); | 489 bool outer_scope_calls_eval = false; |
490 bool outer_scope_calls_non_strict_eval = false; | |
491 if (!is_global_scope()) { | |
492 context->ComputeEvalScopeInfo(&outer_scope_calls_eval, | |
493 &outer_scope_calls_non_strict_eval); | |
494 } | |
495 PropagateScopeInfo(outer_scope_calls_eval, | |
496 outer_scope_calls_non_strict_eval, | |
497 eval_scope); | |
488 | 498 |
489 // 2) Resolve variables. | 499 // 2) Resolve variables. |
490 Scope* global_scope = NULL; | 500 Scope* global_scope = NULL; |
491 if (is_global_scope()) global_scope = this; | 501 if (is_global_scope()) global_scope = this; |
492 ResolveVariablesRecursively(global_scope, context); | 502 ResolveVariablesRecursively(global_scope, context); |
493 | 503 |
494 // 3) Allocate variables. | 504 // 3) Allocate variables. |
495 AllocateVariablesRecursively(); | 505 AllocateVariablesRecursively(); |
496 } | 506 } |
497 | 507 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
609 if (function_ != NULL) { | 619 if (function_ != NULL) { |
610 Indent(n1, "// (local) function name: "); | 620 Indent(n1, "// (local) function name: "); |
611 PrintName(function_->name()); | 621 PrintName(function_->name()); |
612 PrintF("\n"); | 622 PrintF("\n"); |
613 } | 623 } |
614 | 624 |
615 // Scope info. | 625 // Scope info. |
616 if (HasTrivialOuterContext()) { | 626 if (HasTrivialOuterContext()) { |
617 Indent(n1, "// scope has trivial outer context\n"); | 627 Indent(n1, "// scope has trivial outer context\n"); |
618 } | 628 } |
629 if (is_strict_mode()) Indent(n1, "// strict mode scope\n"); | |
619 if (scope_inside_with_) Indent(n1, "// scope inside 'with'\n"); | 630 if (scope_inside_with_) Indent(n1, "// scope inside 'with'\n"); |
620 if (scope_contains_with_) Indent(n1, "// scope contains 'with'\n"); | 631 if (scope_contains_with_) Indent(n1, "// scope contains 'with'\n"); |
621 if (scope_calls_eval_) Indent(n1, "// scope calls 'eval'\n"); | 632 if (scope_calls_eval_) Indent(n1, "// scope calls 'eval'\n"); |
622 if (outer_scope_calls_eval_) Indent(n1, "// outer scope calls 'eval'\n"); | 633 if (outer_scope_calls_eval_) Indent(n1, "// outer scope calls 'eval'\n"); |
634 if (outer_scope_calls_non_strict_eval_) { | |
635 Indent(n1, "// outer scope calls 'eval' in non-strict context\n"); | |
636 } | |
623 if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n"); | 637 if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n"); |
624 if (outer_scope_is_eval_scope_) { | 638 if (outer_scope_is_eval_scope_) { |
625 Indent(n1, "// outer scope is 'eval' scope\n"); | 639 Indent(n1, "// outer scope is 'eval' scope\n"); |
626 } | 640 } |
627 if (num_stack_slots_ > 0) { Indent(n1, "// "); | 641 if (num_stack_slots_ > 0) { Indent(n1, "// "); |
628 PrintF("%d stack slots\n", num_stack_slots_); } | 642 PrintF("%d stack slots\n", num_stack_slots_); } |
629 if (num_heap_slots_ > 0) { Indent(n1, "// "); | 643 if (num_heap_slots_ > 0) { Indent(n1, "// "); |
630 PrintF("%d heap slots\n", num_heap_slots_); } | 644 PrintF("%d heap slots\n", num_heap_slots_); } |
631 | 645 |
632 // Print locals. | 646 // Print locals. |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
839 } | 853 } |
840 | 854 |
841 // Resolve unresolved variables for inner scopes. | 855 // Resolve unresolved variables for inner scopes. |
842 for (int i = 0; i < inner_scopes_.length(); i++) { | 856 for (int i = 0; i < inner_scopes_.length(); i++) { |
843 inner_scopes_[i]->ResolveVariablesRecursively(global_scope, context); | 857 inner_scopes_[i]->ResolveVariablesRecursively(global_scope, context); |
844 } | 858 } |
845 } | 859 } |
846 | 860 |
847 | 861 |
848 bool Scope::PropagateScopeInfo(bool outer_scope_calls_eval, | 862 bool Scope::PropagateScopeInfo(bool outer_scope_calls_eval, |
863 bool outer_scope_calls_non_strict_eval, | |
849 bool outer_scope_is_eval_scope) { | 864 bool outer_scope_is_eval_scope) { |
850 if (outer_scope_calls_eval) { | 865 if (outer_scope_calls_eval) { |
851 outer_scope_calls_eval_ = true; | 866 outer_scope_calls_eval_ = true; |
852 } | 867 } |
853 | 868 |
869 if (outer_scope_calls_non_strict_eval) { | |
870 outer_scope_calls_non_strict_eval_ = true; | |
871 } | |
872 | |
854 if (outer_scope_is_eval_scope) { | 873 if (outer_scope_is_eval_scope) { |
855 outer_scope_is_eval_scope_ = true; | 874 outer_scope_is_eval_scope_ = true; |
856 } | 875 } |
857 | 876 |
858 bool calls_eval = scope_calls_eval_ || outer_scope_calls_eval_; | 877 bool calls_eval = scope_calls_eval_ || outer_scope_calls_eval_; |
859 bool is_eval = is_eval_scope() || outer_scope_is_eval_scope_; | 878 bool is_eval = is_eval_scope() || outer_scope_is_eval_scope_; |
879 bool calls_non_strict_eval = | |
880 (scope_calls_eval_ && !is_strict_mode()) || outer_scope_calls_non_strict_e val_; | |
fschneider
2011/05/11 10:35:11
Long line.
Mads Ager (chromium)
2011/05/11 11:24:11
Done.
| |
860 for (int i = 0; i < inner_scopes_.length(); i++) { | 881 for (int i = 0; i < inner_scopes_.length(); i++) { |
861 Scope* inner_scope = inner_scopes_[i]; | 882 Scope* inner_scope = inner_scopes_[i]; |
862 if (inner_scope->PropagateScopeInfo(calls_eval, is_eval)) { | 883 if (inner_scope->PropagateScopeInfo(calls_eval, |
884 calls_non_strict_eval, | |
885 is_eval)) { | |
863 inner_scope_calls_eval_ = true; | 886 inner_scope_calls_eval_ = true; |
864 } | 887 } |
865 if (inner_scope->force_eager_compilation_) { | 888 if (inner_scope->force_eager_compilation_) { |
866 force_eager_compilation_ = true; | 889 force_eager_compilation_ = true; |
867 } | 890 } |
868 } | 891 } |
869 | 892 |
870 return scope_calls_eval_ || inner_scope_calls_eval_; | 893 return scope_calls_eval_ || inner_scope_calls_eval_; |
871 } | 894 } |
872 | 895 |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1111 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && | 1134 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && |
1112 !must_have_local_context) { | 1135 !must_have_local_context) { |
1113 num_heap_slots_ = 0; | 1136 num_heap_slots_ = 0; |
1114 } | 1137 } |
1115 | 1138 |
1116 // Allocation done. | 1139 // Allocation done. |
1117 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); | 1140 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); |
1118 } | 1141 } |
1119 | 1142 |
1120 } } // namespace v8::internal | 1143 } } // namespace v8::internal |
OLD | NEW |