OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 |
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
754 VariableProxy* result = scope->NewTemporary(Factory::result_symbol()); | 754 VariableProxy* result = scope->NewTemporary(Factory::result_symbol()); |
755 Processor processor(result); | 755 Processor processor(result); |
756 processor.Process(body); | 756 processor.Process(body); |
757 if (processor.HasStackOverflow()) return false; | 757 if (processor.HasStackOverflow()) return false; |
758 | 758 |
759 if (processor.result_assigned()) body->Add(new ReturnStatement(result)); | 759 if (processor.result_assigned()) body->Add(new ReturnStatement(result)); |
760 return true; | 760 return true; |
761 } | 761 } |
762 | 762 |
763 | 763 |
764 void Rewriter::Optimize(FunctionLiteral* function) { | 764 bool Rewriter::Optimize(FunctionLiteral* function) { |
765 ZoneList<Statement*>* body = function->body(); | 765 ZoneList<Statement*>* body = function->body(); |
766 if (body->is_empty()) return; | |
767 | 766 |
768 if (FLAG_optimize_ast) { | 767 if (FLAG_optimize_ast && !body->is_empty()) { |
769 Scope* scope = function->scope(); | 768 Scope* scope = function->scope(); |
770 if (!scope->is_global_scope()) { | 769 if (!scope->is_global_scope()) { |
771 AstOptimizer optimizer; | 770 AstOptimizer optimizer; |
772 optimizer.Optimize(body); | 771 optimizer.Optimize(body); |
| 772 if (optimizer.HasStackOverflow()) { |
| 773 return false; |
| 774 } |
773 } | 775 } |
774 } | 776 } |
| 777 return true; |
775 } | 778 } |
776 | 779 |
777 | 780 |
778 } } // namespace v8::internal | 781 } } // namespace v8::internal |
OLD | NEW |