From 1af131cbed9902fb6605cbdee0b550f340b1777b Mon Sep 17 00:00:00 2001 From: "iposva@chromium.org" Date: Wed, 5 Nov 2008 20:39:41 +0000 Subject: [PATCH] Handle stack overflow errors correctly when rewriting the AST for likely Smis. Review URL: http://codereview.chromium.org/9429 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@701 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/compiler.cc | 6 +++++- src/rewriter.cc | 9 ++++++--- src/rewriter.h | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/compiler.cc b/src/compiler.cc index 2a2bb8726..2078985bb 100644 --- a/src/compiler.cc +++ b/src/compiler.cc @@ -66,7 +66,11 @@ static Handle MakeCode(FunctionLiteral* literal, #endif // Optimize the AST. - Rewriter::Optimize(literal); + if (!Rewriter::Optimize(literal)) { + // Signal a stack overflow by returning a null handle. The stack + // overflow exception will be thrown by the caller. + return Handle::null(); + } // Generate code and return it. Handle result = CodeGenerator::MakeCode(literal, script, is_eval); diff --git a/src/rewriter.cc b/src/rewriter.cc index d391d5de4..c5ca7cd29 100644 --- a/src/rewriter.cc +++ b/src/rewriter.cc @@ -761,17 +761,20 @@ bool Rewriter::Process(FunctionLiteral* function) { } -void Rewriter::Optimize(FunctionLiteral* function) { +bool Rewriter::Optimize(FunctionLiteral* function) { ZoneList* body = function->body(); - if (body->is_empty()) return; - if (FLAG_optimize_ast) { + if (FLAG_optimize_ast && !body->is_empty()) { Scope* scope = function->scope(); if (!scope->is_global_scope()) { AstOptimizer optimizer; optimizer.Optimize(body); + if (optimizer.HasStackOverflow()) { + return false; + } } } + return true; } diff --git a/src/rewriter.h b/src/rewriter.h index d69ad5a10..aa2f981de 100644 --- a/src/rewriter.h +++ b/src/rewriter.h @@ -44,7 +44,7 @@ namespace v8 { namespace internal { class Rewriter { public: static bool Process(FunctionLiteral* function); - static void Optimize(FunctionLiteral* function); + static bool Optimize(FunctionLiteral* function); }; -- 2.34.1