Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | |
| 2 // Redistribution and use in source and binary forms, with or without | |
| 3 // modification, are permitted provided that the following conditions are | |
| 4 // met: | |
| 5 // | |
| 6 // * Redistributions of source code must retain the above copyright | |
| 7 // notice, this list of conditions and the following disclaimer. | |
| 8 // * Redistributions in binary form must reproduce the above | |
| 9 // copyright notice, this list of conditions and the following | |
| 10 // disclaimer in the documentation and/or other materials provided | |
| 11 // with the distribution. | |
| 12 // * Neither the name of Google Inc. nor the names of its | |
| 13 // contributors may be used to endorse or promote products derived | |
| 14 // from this software without specific prior written permission. | |
| 15 // | |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
|
Jarin
2016/08/22 07:27:20
Nit: you can use a shorter copyright. E.g., see te
Franzi
2016/08/22 09:06:30
Done.
| |
| 27 | |
| 28 // Flags: --allow-natives-syntax --turbo | |
| 29 | |
| 30 // TurboFan optimizes integer loops. These tests check that we compute | |
| 31 // the corret upper and lower bounds. | |
|
Jarin
2016/08/22 07:27:20
Nit: corret -> correct.
Franzi
2016/08/22 09:06:30
Done.
| |
| 32 function positive_increment() { | |
| 33 for (var i = 5; i < 10; i++) { | |
| 34 if (i < 0) break; | |
| 35 if (i > 20) break; | |
| 36 if (i === 7) return true; | |
| 37 } | |
| 38 return false; | |
| 39 } | |
| 40 | |
| 41 function positive_increment_strict() { | |
| 42 for (var i = 5; i < 10; i++) { | |
| 43 if (i < 0) break; | |
|
Jarin
2016/08/22 07:27:20
Could we change the i < 0 branches to return false
Franzi
2016/08/22 09:06:30
Done.
| |
| 44 if (i === 10) return false; | |
| 45 } | |
| 46 return true; | |
| 47 } | |
| 48 | |
| 49 function positive_increment_non_strict() { | |
| 50 for (var i = 5; i <= 10; i++) { | |
| 51 if (i < 0) break; | |
| 52 if (i === 10) return true; | |
| 53 } | |
| 54 return false; | |
| 55 } | |
| 56 | |
| 57 function negative_increment() { | |
| 58 for (var i = 10; i > 5;) { | |
| 59 if (i < 0) break; | |
| 60 if (i > 20) break; | |
| 61 if (i === 7) return true; | |
| 62 i -= 1; | |
| 63 } | |
| 64 return false; | |
| 65 } | |
| 66 | |
| 67 function positive_decrement() { | |
| 68 for (var i = 10; i > 5; i--) { | |
| 69 if (i < 0) break; | |
| 70 if (i === 7) return true; | |
| 71 } | |
| 72 return false; | |
| 73 } | |
| 74 | |
| 75 function positive_decrement_strict() { | |
| 76 for (var i = 10; i > 5; i--) { | |
| 77 if (i < 0) break; | |
| 78 if (i === 5) return false; | |
| 79 } | |
| 80 return true; | |
| 81 } | |
| 82 function positive_decrement_non_strict() { | |
| 83 for (var i = 10; i >= 5; i--) { | |
| 84 if (i < 0) break; | |
| 85 if (i === 5) return true; | |
| 86 } | |
| 87 return false; | |
| 88 } | |
| 89 | |
| 90 function negative_decrement() { | |
| 91 for (var i = 5; i < 10;) { | |
| 92 if (i < 0) break; | |
| 93 if (i === 7) return true; | |
| 94 i -= -1; | |
| 95 } | |
| 96 return false; | |
| 97 } | |
| 98 | |
| 99 function variable_bound() { | |
| 100 for (var i = 5; i < 10; i++) { | |
| 101 for (var j = 5; j < i; j++) { | |
| 102 if (j < 0) break; | |
| 103 if (j === 7) return true; | |
| 104 } | |
| 105 } | |
| 106 return false; | |
| 107 | |
| 108 } | |
| 109 | |
| 110 function test(f) { | |
| 111 f(); | |
| 112 assertTrue(f()); | |
| 113 %OptimizeFunctionOnNextCall(f); | |
| 114 assertTrue(f()); | |
| 115 } | |
| 116 | |
| 117 test(positive_increment); | |
| 118 test(positive_increment_strict); | |
| 119 test(positive_increment_non_strict); | |
| 120 test(negative_increment); | |
| 121 test(positive_decrement); | |
| 122 test(positive_decrement_strict); | |
| 123 test(positive_decrement_non_strict); | |
| 124 test(negative_decrement); | |
| 125 test(variable_bound); | |
| OLD | NEW |