Chromium Code Reviews| Index: src/rewriter.cc |
| diff --git a/src/rewriter.cc b/src/rewriter.cc |
| index 9df46c9beef236551026f893d1c89da3cefb970d..4f6e74558a9abb1b2a1ea9e276c78d1430d5347b 100644 |
| --- a/src/rewriter.cc |
| +++ b/src/rewriter.cc |
| @@ -24,6 +24,18 @@ class Processor: public AstVisitor { |
| InitializeAstVisitor(isolate, ast_value_factory->zone()); |
| } |
| + Processor(Parser* parser, Scope* scope, Variable* result, |
| + AstValueFactory* ast_value_factory) |
| + : result_(result), |
| + result_assigned_(false), |
| + replacement_(nullptr), |
| + is_set_(false), |
| + scope_(scope), |
| + factory_(ast_value_factory) { |
| + InitializeAstVisitor(nullptr, ast_value_factory->zone()); |
| + parser_ = parser; |
| + } |
| + |
| virtual ~Processor() { } |
| void Process(ZoneList<Statement*>* statements); |
| @@ -72,7 +84,41 @@ class Processor: public AstVisitor { |
| void VisitIterationStatement(IterationStatement* stmt); |
| - DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); |
|
rossberg
2015/10/12 13:52:40
I think Adam is working on a refactoring for separ
caitp (gmail)
2015/10/12 18:23:00
If that lands first, that would be helpful.
adamk
2015/10/12 19:02:21
I was hoping to get some answers on my v8-dev thre
|
| + public: |
| + void Visit(AstNode* node) final { |
| + if (!CheckStackOverflow()) node->Accept(this); |
| + } |
| + |
| + void SetStackOverflow() { stack_overflow_ = true; } |
| + void ClearStackOverflow() { stack_overflow_ = false; } |
| + bool HasStackOverflow() const { return stack_overflow_; } |
| + |
| + bool CheckStackOverflow() { |
| + if (stack_overflow_) return true; |
| + if (isolate_) { |
| + StackLimitCheck check(isolate_); |
| + if (!check.HasOverflowed()) return false; |
| + stack_overflow_ = true; |
| + } else { |
| + if (!parser_->CheckStackOverflow()) return false; |
| + stack_overflow_ = true; |
| + } |
| + return true; |
| + } |
| + |
| + private: |
| + void InitializeAstVisitor(Isolate* isolate, Zone* zone) { |
| + isolate_ = isolate; |
| + zone_ = zone; |
| + stack_overflow_ = false; |
| + } |
| + Zone* zone() { return zone_; } |
| + Isolate* isolate() { return isolate_; } |
| + |
| + Isolate* isolate_; |
| + Parser* parser_; |
| + Zone* zone_; |
| + bool stack_overflow_; |
| }; |
| @@ -359,5 +405,26 @@ bool Rewriter::Rewrite(ParseInfo* info) { |
| } |
| +bool Rewriter::Rewrite(Parser* parser, DoExpression* expr, |
| + AstValueFactory* factory) { |
| + Scope* scope = expr->scope(); |
| + ZoneList<Statement*>* body = expr->statements(); |
| + VariableProxy* result = expr->result(); |
| + Variable* result_var = result->var(); |
| + |
| + if (!body->is_empty()) { |
| + Processor processor(parser, scope, result_var, factory); |
| + processor.Process(body); |
| + if (processor.HasStackOverflow()) return false; |
| + |
| + if (processor.result_assigned()) { |
| + DCHECK(!result->is_assigned()); |
| + result->set_is_assigned(); |
| + } |
| + } |
| + return true; |
| +} |
| + |
| + |
| } // namespace internal |
| } // namespace v8 |