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
#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<Code>::null();
+ }
// Generate code and return it.
Handle<Code> result = CodeGenerator::MakeCode(literal, script, is_eval);
}
-void Rewriter::Optimize(FunctionLiteral* function) {
+bool Rewriter::Optimize(FunctionLiteral* function) {
ZoneList<Statement*>* 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;
}
class Rewriter {
public:
static bool Process(FunctionLiteral* function);
- static void Optimize(FunctionLiteral* function);
+ static bool Optimize(FunctionLiteral* function);
};