From 0bf838456f40cbb27aa58351c9e81ecd2c45a649 Mon Sep 17 00:00:00 2001 From: "mstarzinger@chromium.org" Date: Mon, 25 Aug 2014 16:32:35 +0000 Subject: [PATCH] Fix continue statements within for-in loops. R=titzer@chromium.org TEST=cctest/test-run-jsbranches/ForInContinueStatement BUG=v8:3522 LOG=N Review URL: https://codereview.chromium.org/502043002 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23369 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/compiler/ast-graph-builder.cc | 2 +- test/cctest/compiler/test-run-jsbranches.cc | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/compiler/ast-graph-builder.cc b/src/compiler/ast-graph-builder.cc index 66a371b..0e642c9 100644 --- a/src/compiler/ast-graph-builder.cc +++ b/src/compiler/ast-graph-builder.cc @@ -744,13 +744,13 @@ void AstGraphBuilder::VisitForInStatement(ForInStatement* stmt) { // Bind value and do loop body. VisitForInAssignment(stmt->each(), value); VisitIterationBody(stmt, &for_loop, 5); + for_loop.EndBody(); // Inc counter and continue. Node* index_inc = NewNode(javascript()->Add(), index, jsgraph()->OneConstant()); // TODO(jarin): provide real bailout id. PrepareFrameState(index_inc, BailoutId::None()); environment()->Poke(0, index_inc); - for_loop.EndBody(); for_loop.EndLoop(); environment()->Drop(5); // PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); diff --git a/test/cctest/compiler/test-run-jsbranches.cc b/test/cctest/compiler/test-run-jsbranches.cc index 2eb4fa6..df2fcdc 100644 --- a/test/cctest/compiler/test-run-jsbranches.cc +++ b/test/cctest/compiler/test-run-jsbranches.cc @@ -148,6 +148,26 @@ TEST(ForInStatement) { } +TEST(ForInContinueStatement) { + const char* src = + "(function(a,b) {" + " var r = '-';" + " for (var x in a) {" + " r += 'A-';" + " if (b) continue;" + " r += 'B-';" + " }" + " return r;" + "})"; + FunctionTester T(src); + + T.CheckCall(T.Val("-A-B-"), T.NewObject("({x:1})"), T.false_value()); + T.CheckCall(T.Val("-A-B-A-B-"), T.NewObject("({x:1,y:2})"), T.false_value()); + T.CheckCall(T.Val("-A-"), T.NewObject("({x:1})"), T.true_value()); + T.CheckCall(T.Val("-A-A-"), T.NewObject("({x:1,y:2})"), T.true_value()); +} + + TEST(SwitchStatement) { const char* src = "(function(a,b) {" -- 2.7.4