Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1159)

Unified Diff: src/rewriter.cc

Issue 1399893002: [es7] implement |do| expressions proposal (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Disable CrankShaft Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/ast.h ('K') | « src/rewriter.h ('k') | src/typing-asm.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/rewriter.cc
diff --git a/src/rewriter.cc b/src/rewriter.cc
index 3c9c2fd0351bd3366a0003c80603490f949e0bd5..47843305390bd6506b2b9fa8079e569a5cb0828b 100644
--- a/src/rewriter.cc
+++ b/src/rewriter.cc
@@ -25,6 +25,17 @@ class Processor: public AstVisitor {
InitializeAstVisitor(isolate);
}
+ 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(parser->stack_limit());
+ }
+
virtual ~Processor() { }
void Process(ZoneList<Statement*>* statements);
@@ -34,6 +45,17 @@ class Processor: public AstVisitor {
Scope* scope() { return scope_; }
AstNodeFactory* factory() { return &factory_; }
+ // Returns ".result = value"
+ Expression* SetResult(Expression* value) {
+ result_assigned_ = true;
+ VariableProxy* result_proxy = factory()->NewVariableProxy(result_);
+ return factory()->NewAssignment(Token::ASSIGN, result_proxy, value,
+ RelocInfo::kNoPosition);
+ }
+
+ // Inserts '.result = undefined' in front of the given statement.
+ Statement* AssignUndefinedBefore(Statement* s);
+
private:
Variable* result_;
@@ -57,17 +79,6 @@ class Processor: public AstVisitor {
Scope* scope_;
AstNodeFactory factory_;
- // Returns ".result = value"
- Expression* SetResult(Expression* value) {
- result_assigned_ = true;
- VariableProxy* result_proxy = factory()->NewVariableProxy(result_);
- return factory()->NewAssignment(
- Token::ASSIGN, result_proxy, value, RelocInfo::kNoPosition);
- }
-
- // Inserts '.result = undefined' in front of the given statement.
- Statement* AssignUndefinedBefore(Statement* s);
-
// Node visitors.
#define DEF_VISIT(type) virtual void Visit##type(type* node) override;
AST_NODE_LIST(DEF_VISIT)
@@ -362,5 +373,31 @@ bool Rewriter::Rewrite(ParseInfo* info) {
}
+bool Rewriter::Rewrite(Parser* parser, DoExpression* expr,
+ AstValueFactory* factory) {
+ Block* block = expr->block();
+ Scope* scope = block->scope();
+ ZoneList<Statement*>* body = block->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()) {
+ AstNodeFactory* node_factory = processor.factory();
+ Expression* undef =
+ node_factory->NewUndefinedLiteral(RelocInfo::kNoPosition);
+ Statement* completion = node_factory->NewExpressionStatement(
+ processor.SetResult(undef), expr->position());
+ body->Add(completion, factory->zone());
+ }
+ }
+ return true;
+}
+
+
} // namespace internal
} // namespace v8
« src/ast.h ('K') | « src/rewriter.h ('k') | src/typing-asm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698