Reviewers: rossberg, titzer,

Description:
Fix AstExpressionVisitor to correctly handle switch + for.

These were missed by the previous tests,
uncovered in another context.

BUG= https://code.google.com/p/v8/issues/detail?id=4203
TEST=test-ast-expression-visitor
[email protected],[email protected]
LOG=N

Please review this at https://codereview.chromium.org/1316633002/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+56, -5 lines):
  M src/ast-expression-visitor.cc
  M test/cctest/test-ast-expression-visitor.cc


Index: src/ast-expression-visitor.cc
diff --git a/src/ast-expression-visitor.cc b/src/ast-expression-visitor.cc
index 08f29501940a33642bb82bce62c3cc39a4ee5c7f..6a92fcf34032bda63fe5b4ccf7f12219a00819d2 100644
--- a/src/ast-expression-visitor.cc
+++ b/src/ast-expression-visitor.cc
@@ -111,8 +111,11 @@ void AstExpressionVisitor::VisitSwitchStatement(SwitchStatement* stmt) {

   for (int i = 0; i < clauses->length(); ++i) {
     CaseClause* clause = clauses->at(i);
-    Expression* label = clause->label();
-    RECURSE(Visit(label));
+    if (!clause->is_default()) {
+      Expression* label = clause->label();
+      VisitExpression(label);
+      RECURSE(Visit(label));
+    }
     ZoneList<Statement*>* stmts = clause->statements();
     RECURSE(VisitStatements(stmts));
   }
@@ -137,9 +140,15 @@ void AstExpressionVisitor::VisitWhileStatement(WhileStatement* stmt) {


 void AstExpressionVisitor::VisitForStatement(ForStatement* stmt) {
-  RECURSE(Visit(stmt->init()));
-  RECURSE(Visit(stmt->cond()));
-  RECURSE(Visit(stmt->next()));
+  if (stmt->init() != NULL) {
+    RECURSE(Visit(stmt->init()));
+  }
+  if (stmt->cond() != NULL) {
+    RECURSE(Visit(stmt->cond()));
+  }
+  if (stmt->next() != NULL) {
+    RECURSE(Visit(stmt->next()));
+  }
   RECURSE(Visit(stmt->body()));
 }

Index: test/cctest/test-ast-expression-visitor.cc
diff --git a/test/cctest/test-ast-expression-visitor.cc b/test/cctest/test-ast-expression-visitor.cc index f2709639e3570c402b423ad6646171ff1d5b3d0d..f85228a8c43fbee7cfcac5a72c949d4c2abb3590 100644
--- a/test/cctest/test-ast-expression-visitor.cc
+++ b/test/cctest/test-ast-expression-visitor.cc
@@ -256,3 +256,45 @@ TEST(VisitExpressions) {
   }
   CHECK_TYPES_END
 }
+
+
+TEST(VisitEmptyForStatment) {
+  v8::V8::Initialize();
+  HandleAndZoneScope handles;
+  ZoneVector<ExpressionTypeEntry> types(handles.main_zone());
+  // Check that traversing an empty for statement works.
+  const char test_function[] =
+      "function foo() {\n"
+      "  for (;;) {}\n"
+      "}\n";
+  CollectTypes(&handles, test_function, &types);
+  CHECK_TYPES_BEGIN {
+    CHECK_EXPR(FunctionLiteral, DEFAULT_TYPE) {}
+  }
+  CHECK_TYPES_END
+}
+
+
+TEST(VisitSwitchStatment) {
+  v8::V8::Initialize();
+  HandleAndZoneScope handles;
+  ZoneVector<ExpressionTypeEntry> types(handles.main_zone());
+  // Check that traversing a switch with a default works.
+  const char test_function[] =
+      "function foo() {\n"
+      "  switch (0) { case 1: break; default: break; }\n"
+      "}\n";
+  CollectTypes(&handles, test_function, &types);
+  CHECK_TYPES_BEGIN {
+    CHECK_EXPR(FunctionLiteral, DEFAULT_TYPE) {
+      CHECK_EXPR(Assignment, DEFAULT_TYPE) {
+        CHECK_VAR(.switch_tag, DEFAULT_TYPE);
+        CHECK_EXPR(Literal, DEFAULT_TYPE);
+      }
+      CHECK_VAR(.switch_tag, DEFAULT_TYPE);
+      CHECK_EXPR(Literal, DEFAULT_TYPE);
+      CHECK_EXPR(Literal, DEFAULT_TYPE);
+    }
+  }
+  CHECK_TYPES_END
+}


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to