File indexing completed on 2024-04-28 15:28:38
0001 // 12.6.1 0002 var count = 0; 0003 do { 0004 count++; 0005 } while (count < 10); 0006 shouldBe("count", "10"); 0007 0008 count = 0; 0009 for (var i = 0; i < 10; i++) { 0010 if (i == 5) 0011 break; 0012 count++; 0013 } 0014 shouldBe("count", "5"); 0015 0016 // 12.6.3 0017 count = 0; 0018 for (i = 0; i < 10; i++) { 0019 count++; 0020 } 0021 shouldBe("count", "10"); 0022 0023 // 12.6.4 0024 obj = new Object(); 0025 obj.a = 11; 0026 obj.b = 22; 0027 0028 properties = ""; 0029 for ( prop in obj ) 0030 properties += (prop + "=" + obj[prop] + ";"); 0031 0032 shouldBe("properties", "'a=11;b=22;'"); 0033 0034 // now a test verifying the order. not standardized but common. 0035 obj.y = 33; 0036 obj.x = 44; 0037 properties = ""; 0038 for ( prop in obj ) 0039 properties += prop; 0040 // shouldBe("properties", "'abyx'"); 0041 0042 arr = new Array; 0043 arr[0] = 100; 0044 arr[1] = 101; 0045 list = ""; 0046 for ( var j in arr ) { 0047 list += "[" + j + "]=" + arr[j] + ";"; 0048 } 0049 shouldBe("list","'[0]=100;[1]=101;'"); 0050 0051 list = ""; 0052 for (var a = [1,2,3], length = a.length, i = 0; i < length; i++) { 0053 list += a[i]; 0054 } 0055 shouldBe("list", "'123'"); 0056 0057 // completion values 0058 var immediateWhileBreak = eval("while (true) { break; }"); 0059 shouldBeUndefined("immediateWhileBreak", "'foo'"); 0060 var laterWhileBreak = eval("while (true) { 'foo'; break; }"); 0061 shouldBe("laterWhileBreak", "'foo'"); 0062 var whileEnd = eval("var y = 0; while (y < 2) { ++y }"); 0063 shouldBe("whileEnd", "2"); 0064 0065 var immediateDoWhileBreak = eval("do { break; } while(false); "); 0066 shouldBeUndefined("immediateDoWhileBreak", "'foo'"); 0067 var laterDoWhileBreak = eval("do { 'bar'; break; } while(true);"); 0068 shouldBe("laterDoWhileBreak", "'bar'"); 0069 var doWhileEnd = eval("var y = 0; do { ++y } while (y < 3);"); 0070 shouldBe("doWhileEnd", "3"); 0071 0072 var immediateForBreak = eval("for(;;) { break; }"); 0073 shouldBeUndefined("immediateForBreak", "'foo'"); 0074 var laterForBreak = eval("for(;;) { 'zilch'; break; }"); 0075 shouldBe("laterForBreak", "'zilch'"); 0076 var forEnd = eval("for(var y = 0; y < 4; ++y) { 'quark' }"); 0077 shouldBe("forEnd", "'quark'"); 0078 0079 // Various stuff for control flow and error handling of break/continue 0080 var iters; 0081 0082 // Test whether we handle multiple labels on the same statement right 0083 // Note: this is in a function since konq 3.x just breaks out of the whole thing. 0084 function testLabelNest() { 0085 iters = 0; 0086 foo: bar: while (true) { 0087 ++iters; 0088 if (iters < 10) 0089 continue foo; 0090 else 0091 break; 0092 } 0093 } 0094 0095 testLabelNest(); 0096 shouldBe('iters', '10'); 0097 0098 // Test to make sure doing continue outside a loop 0099 // throws properly. (3.x didn't), and so does a label-less 0100 // break outside of it. 0101 shouldThrow('foo: continue foo; '); 0102 shouldThrow('continue; '); 0103 shouldThrow('break;'); 0104 0105 // These ones should be fine OTOH 0106 shouldBeUndefined('foo: break foo; '); 0107 shouldBe('foo: { a = 1; break foo; a = 2; }', '1'); 0108 0109 // Make sure we don't break out too far. 0110 function testLocalBreak() { 0111 l: break l; 0112 } 0113 0114 for (iters = 0; iters < 10; ++iters) 0115 testLocalBreak(); 0116 0117 shouldBe('iters', '10'); 0118 0119 // Regression test, bug during FB development. 0120 var o = {a: 0, b: 1} 0121 for (p in o) { 0122 if (p == "b") 0123 break; 0124 continue; 0125 } 0126 0127 testPassed("Didn't crash on continue in for .. in"); 0128 0129 /** Regression test for #165847: making sure that break 0130 out of a for ... in cleans stuff up properly from the for ... in stack 0131 */ 0132 var list = []; 0133 for (var i = 0; i < 10; ++i) 0134 list.push(i); 0135 0136 done = false; 0137 for (i in list) { 0138 for (j in list) { 0139 if (i == 0 && j == 1) { 0140 done = true; 0141 break; 0142 } 0143 0144 if (done) 0145 break; 0146 } 0147 } 0148 0149 0150 0151 debug("Done.");