1 // Copyright 2013 the V8 project authors. All rights reserved. 2 // Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 3 // 4 // Redistribution and use in source and binary forms, with or without 5 // modification, are permitted provided that the following conditions 6 // are met: 7 // 1. Redistributions of source code must retain the above copyright 8 // notice, this list of conditions and the following disclaimer. 9 // 2. Redistributions in binary form must reproduce the above copyright 10 // notice, this list of conditions and the following disclaimer in the 11 // documentation and/or other materials provided with the distribution. 12 // 13 // THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY 14 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16 // DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY 17 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 19 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 22 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 24 description( 25 'This test checks break and continue behaviour in the presence of multiple labels.' 26 ); 27 28 function test1() 29 { 30 var s = ""; 31 32 a: 33 b: 34 for (var i = 1; i < 10; i++) { 35 if (i == 4) 36 continue a; 37 s += i; 38 } 39 40 return s; 41 } 42 43 shouldBe("test1()", "'12356789'"); 44 45 function test2() 46 { 47 var s = ""; 48 49 a: 50 b: 51 for (var i = 1; i < 10; i++) { 52 if (i == 4) 53 break a; 54 s += i; 55 } 56 57 return s; 58 } 59 60 shouldBe("test2()", "'123'"); 61 62 function test3() 63 { 64 var i; 65 for (i = 1; i < 10; i++) { 66 try { 67 continue; 68 } finally { 69 innerLoop: 70 while (1) { 71 break innerLoop; 72 } 73 } 74 } 75 76 return i; 77 } 78 79 shouldBe("test3()", "10"); 80 81 function test4() 82 { 83 var i = 0; 84 85 a: 86 i++; 87 while (1) { 88 break; 89 } 90 91 return i; 92 } 93 94 shouldBe("test4()", "1"); 95 96 function test5() 97 { 98 var i = 0; 99 100 switch (1) { 101 default: 102 while (1) { 103 break; 104 } 105 i++; 106 } 107 108 return i; 109 } 110 111 shouldBe("test5()", "1"); 112