OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Flags: --allow-natives-syntax --harmony-do-expressions |
| 6 |
| 7 (function TestDoForInDoBreak() { |
| 8 function f(o, i) { |
| 9 var a = "result@" + do { |
| 10 var r = "("; |
| 11 for (var x in o) { |
| 12 var b = "end@" + do { |
| 13 if (x == i) { break } else { r += o[x]; x } |
| 14 } |
| 15 } |
| 16 r + ")"; |
| 17 } |
| 18 return a + "," + b; |
| 19 } |
| 20 assertEquals("result@(3),end@0", f([3], 2)); |
| 21 assertEquals("result@(35),end@1", f([3,5], 2)); |
| 22 assertEquals("result@(35),end@1", f([3,5,7], 2)); |
| 23 assertEquals("result@(35),end@1", f([3,5,7,9], 2)); |
| 24 %OptimizeFunctionOnNextCall(f); |
| 25 assertEquals("result@(3),end@0", f([3], 2)); |
| 26 assertEquals("result@(35),end@1", f([3,5], 2)); |
| 27 assertEquals("result@(35),end@1", f([3,5,7], 2)); |
| 28 assertEquals("result@(35),end@1", f([3,5,7,9], 2)); |
| 29 })(); |
| 30 |
| 31 (function TestDoForInDoContinue() { |
| 32 function f(o, i) { |
| 33 var a = "result@" + do { |
| 34 var r = "(" |
| 35 for (var x in o) { |
| 36 var b = "end@" + do { |
| 37 if (x == i) { continue } else { r += o[x]; x } |
| 38 } |
| 39 } |
| 40 r + ")" |
| 41 } |
| 42 return a + "," + b |
| 43 } |
| 44 assertEquals("result@(3),end@0", f([3], 2)); |
| 45 assertEquals("result@(35),end@1", f([3,5], 2)); |
| 46 assertEquals("result@(35),end@1", f([3,5,7], 2)); |
| 47 assertEquals("result@(359),end@3", f([3,5,7,9], 2)); |
| 48 %OptimizeFunctionOnNextCall(f); |
| 49 assertEquals("result@(3),end@0", f([3], 2)); |
| 50 assertEquals("result@(35),end@1", f([3,5], 2)); |
| 51 assertEquals("result@(35),end@1", f([3,5,7], 2)); |
| 52 assertEquals("result@(359),end@3", f([3,5,7,9], 2)); |
| 53 })(); |
| 54 |
| 55 (function TestDoForNestedWithTargetLabels() { |
| 56 function f(mode) { |
| 57 var loop = true; |
| 58 var head = "<"; |
| 59 var tail = ">"; |
| 60 var middle = |
| 61 "1" + do { loop1: for(; loop; head += "A") { |
| 62 "2" + do { loop2: for(; loop; head += "B") { |
| 63 "3" + do { loop3: for(; loop; head += "C") { |
| 64 "4" + do { loop4: for(; loop; head += "D") { |
| 65 "5" + do { loop5: for(; loop; head += "E") { |
| 66 "6" + do { loop6: for(; loop; head += "F") { |
| 67 loop = false; |
| 68 switch (mode) { |
| 69 case "b1": break loop1; |
| 70 case "b2": break loop2; |
| 71 case "b3": break loop3; |
| 72 case "b4": break loop4; |
| 73 case "b5": break loop5; |
| 74 case "b6": break loop6; |
| 75 case "c1": continue loop1; |
| 76 case "c2": continue loop2; |
| 77 case "c3": continue loop3; |
| 78 case "c4": continue loop4; |
| 79 case "c5": continue loop5; |
| 80 case "c6": continue loop6; |
| 81 default: "7"; |
| 82 } |
| 83 }} |
| 84 }} |
| 85 }} |
| 86 }} |
| 87 }} |
| 88 }} |
| 89 return head + middle + tail; |
| 90 } |
| 91 function test() { |
| 92 assertEquals( "<1undefined>", f("b1")); |
| 93 assertEquals( "<A1undefined>", f("c1")); |
| 94 assertEquals( "<A12undefined>", f("b2")); |
| 95 assertEquals( "<BA12undefined>", f("c2")); |
| 96 assertEquals( "<BA123undefined>", f("b3")); |
| 97 assertEquals( "<CBA123undefined>", f("c3")); |
| 98 assertEquals( "<CBA1234undefined>", f("b4")); |
| 99 assertEquals( "<DCBA1234undefined>", f("c4")); |
| 100 assertEquals( "<DCBA12345undefined>", f("b5")); |
| 101 assertEquals( "<EDCBA12345undefined>", f("c5")); |
| 102 assertEquals( "<EDCBA123456undefined>", f("b6")); |
| 103 assertEquals("<FEDCBA123456undefined>", f("c6")); |
| 104 assertEquals("<FEDCBA1234567>", f("xx")); |
| 105 } |
| 106 test(); |
| 107 %OptimizeFunctionOnNextCall(f); |
| 108 test(); |
| 109 })(); |
OLD | NEW |