| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2010 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. |
| 27 |
| 28 // Test deopt with count operation on parameter. |
| 29 var max_smi = 1073741823; |
| 30 var o = {x:0}; |
| 31 |
| 32 function inc1(x) { x++; o.x = x; } |
| 33 inc1(max_smi); |
| 34 assertEquals(max_smi + 1, o.x); |
| 35 |
| 36 inc1(1.1); |
| 37 assertEquals(2.1, o.x); |
| 38 |
| 39 |
| 40 // Test deopt with count operation on named property. |
| 41 function inc2(p) { p.x++ } |
| 42 |
| 43 o.x = "42"; |
| 44 inc2(o); |
| 45 assertEquals(43, o.x); |
| 46 |
| 47 var s = max_smi - 10000; |
| 48 o.x = s; |
| 49 for(var i = 0; i < 20000; i++) { |
| 50 inc2(o); |
| 51 } |
| 52 assertEquals(max_smi + 10000, o.x); |
| 53 |
| 54 |
| 55 // Test deopt with count operation on keyed property. |
| 56 function inc3(a, b) { a[b]++; } |
| 57 |
| 58 o = ["42"]; |
| 59 inc3(o, 0); |
| 60 assertEquals(43, o[0]); |
| 61 |
| 62 var s = max_smi - 10000; |
| 63 o[0] = s; |
| 64 for(var i = 0; i < 20000; i++) { |
| 65 inc3(o, 0); |
| 66 } |
| 67 assertEquals(max_smi + 10000, o[0]); |
| 68 |
| 69 inc3(o,"0"); |
| 70 |
| 71 assertEquals(max_smi + 10001, o[0]); |
| 72 |
| 73 // Test bailout when accessing a non-existing array element. |
| 74 o[0] = 0; |
| 75 for(var i = 0; i < 10000; i++) { |
| 76 inc3(o, 0); |
| 77 } |
| 78 inc3(o,1); |
| 79 |
| 80 // Test bailout with count operation in a value context. |
| 81 function inc4(x,y) { return (x++) + y; } |
| 82 for (var i = 0; i < 100000; ++i) assertEquals(3, inc4(2, 1)); |
| 83 assertEquals(3.1, inc4(2, 1.1)); |
| 84 |
| 85 function inc5(x,y) { return (++x) + y; } |
| 86 for (var i = 0; i < 100000; ++i) assertEquals(4, inc5(2, 1)); |
| 87 assertEquals(4.1, inc5(2, 1.1)); |
| 88 assertEquals(4.1, inc5(2.1, 1)); |
| 89 |
| 90 function inc6(o,y) { return (o.x++) + y; } |
| 91 o = {x:0}; |
| 92 for (var i = 0; i < 10000; ++i) { |
| 93 o.x = 42; |
| 94 assertEquals(43, inc6(o, 1)); |
| 95 } |
| 96 o.x = 42; |
| 97 assertEquals(43.1, inc6(o, 1.1)); |
| 98 o.x = 42.1; |
| 99 assertEquals(43.1, inc6(o, 1)); |
| 100 |
| 101 function inc7(o,y) { return (++o.x) + y; } |
| 102 o = {x:0}; |
| 103 for (var i = 0; i < 10000; ++i) { |
| 104 o.x = 42; |
| 105 assertEquals(44, inc7(o, 1)); |
| 106 } |
| 107 o.x = 42; |
| 108 assertEquals(44.1, inc7(o, 1.1)); |
| 109 o.x = 42.1; |
| 110 assertEquals(44.1, inc7(o, 1)); |
| 111 |
| 112 function inc8(o,y) { return (o[0]++) + y; } |
| 113 var q = [0]; |
| 114 for (var i = 0; i < 100000; ++i) { |
| 115 q[0] = 42; |
| 116 assertEquals(43, inc8(q, 1)); |
| 117 } |
| 118 q[0] = 42; |
| 119 assertEquals(43.1, inc8(q, 1.1)); |
| 120 q[0] = 42.1; |
| 121 assertEquals(43.1, inc8(q, 1)); |
| 122 |
| 123 function inc9(o,y) { return (++o[0]) + y; } |
| 124 q = [0]; |
| 125 for (var i = 0; i < 100000; ++i) { |
| 126 q[0] = 42; |
| 127 assertEquals(44, inc9(q, 1)); |
| 128 } |
| 129 q[0] = 42; |
| 130 assertEquals(44.1, inc9(q, 1.1)); |
| 131 q[0] = 42.1; |
| 132 assertEquals(44.1, inc9(q, 1)); |
| 133 |
| 134 // Test deopt because of a failed map check. |
| 135 function inc10(p) { return p.x++ } |
| 136 var g1 = {x:0}; |
| 137 var g2 = {y:0, x:42} |
| 138 for (var i = 0; i < 10000; ++i) { |
| 139 g1.x = 42; |
| 140 assertEquals(42, inc10(g1)); |
| 141 assertEquals(43, g1.x); |
| 142 } |
| 143 assertEquals(42, inc10(g2)); |
| 144 assertEquals(43, g2.x); |
| 145 |
| 146 // Test deoptimization with postfix operation in a value context. |
| 147 function inc11(a) { return a[this.x++]; } |
| 148 var g3 = {x:null, f:inc11}; |
| 149 var g4 = [42]; |
| 150 assertEquals(42, g3.f(g4)); |
| OLD | NEW |