| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 // Test compilation of loops. | 28 // Test compilation of loops. |
| 29 | 29 |
| 30 var n = 1; | 30 var n = 1; |
| 31 for (var i = 1; (6 - i); i++) { | 31 for (var i = 1; (6 - i); i++) { |
| 32 // Factorial! | 32 // Factorial! |
| 33 n = n * i; | 33 n = n * i; |
| 34 } | 34 } |
| 35 assertEquals(120, n); | 35 assertEquals(120, n); |
| 36 |
| 37 // Test assignments in the loop condition. |
| 38 function f(i, n) { |
| 39 while((n = n - 1) >= 0) { |
| 40 i = n + 1; |
| 41 } |
| 42 return i; |
| 43 } |
| 44 assertEquals(1, f(0, 42)); |
| 45 |
| 46 |
| 47 // Test do-while loop and continue. |
| 48 function g(a) { |
| 49 var x = 0, c = 0; |
| 50 do { |
| 51 x = x + 1; |
| 52 if (x < 5) continue; |
| 53 c = c + 1; |
| 54 } while(x < a); |
| 55 return c; |
| 56 } |
| 57 |
| 58 assertEquals(6, g(10)); |
| 59 |
| 60 // Test deoptimization in the loop condition. |
| 61 assertEquals(0, g("foo")); |
| OLD | NEW |