// Copyright 2016 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // Flags: --allow-natives-syntax --harmony-do-expressions (function TestDoForInDoBreak() { function f(o, i) { var a = "result@" + do { var r = "("; for (var x in o) { var b = "end@" + do { if (x == i) { break } else { r += o[x]; x } } } r + ")"; } return a + "," + b; } assertEquals("result@(3),end@0", f([3], 2)); assertEquals("result@(35),end@1", f([3,5], 2)); assertEquals("result@(35),end@1", f([3,5,7], 2)); assertEquals("result@(35),end@1", f([3,5,7,9], 2)); %OptimizeFunctionOnNextCall(f); assertEquals("result@(3),end@0", f([3], 2)); assertEquals("result@(35),end@1", f([3,5], 2)); assertEquals("result@(35),end@1", f([3,5,7], 2)); assertEquals("result@(35),end@1", f([3,5,7,9], 2)); })(); (function TestDoForInDoContinue() { function f(o, i) { var a = "result@" + do { var r = "(" for (var x in o) { var b = "end@" + do { if (x == i) { continue } else { r += o[x]; x } } } r + ")" } return a + "," + b } assertEquals("result@(3),end@0", f([3], 2)); assertEquals("result@(35),end@1", f([3,5], 2)); assertEquals("result@(35),end@1", f([3,5,7], 2)); assertEquals("result@(359),end@3", f([3,5,7,9], 2)); %OptimizeFunctionOnNextCall(f); assertEquals("result@(3),end@0", f([3], 2)); assertEquals("result@(35),end@1", f([3,5], 2)); assertEquals("result@(35),end@1", f([3,5,7], 2)); assertEquals("result@(359),end@3", f([3,5,7,9], 2)); })(); (function TestDoForNestedWithTargetLabels() { function f(mode) { var loop = true; var head = "<"; var tail = ">"; var middle = "1" + do { loop1: for(; loop; head += "A") { "2" + do { loop2: for(; loop; head += "B") { "3" + do { loop3: for(; loop; head += "C") { "4" + do { loop4: for(; loop; head += "D") { "5" + do { loop5: for(; loop; head += "E") { "6" + do { loop6: for(; loop; head += "F") { loop = false; switch (mode) { case "b1": break loop1; case "b2": break loop2; case "b3": break loop3; case "b4": break loop4; case "b5": break loop5; case "b6": break loop6; case "c1": continue loop1; case "c2": continue loop2; case "c3": continue loop3; case "c4": continue loop4; case "c5": continue loop5; case "c6": continue loop6; default: "7"; } }} }} }} }} }} }} return head + middle + tail; } function test() { assertEquals( "<1undefined>", f("b1")); assertEquals( "", f("c1")); assertEquals( "", f("b2")); assertEquals( "", f("c2")); assertEquals( "", f("b3")); assertEquals( "", f("c3")); assertEquals( "", f("b4")); assertEquals( "", f("c4")); assertEquals( "", f("b5")); assertEquals( "", f("c5")); assertEquals( "", f("b6")); assertEquals("", f("c6")); assertEquals("", f("xx")); } test(); %OptimizeFunctionOnNextCall(f); test(); })();