| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 |
| 11 // with the distribution. | 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
| 15 // | 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 // Flags: --allow-natives-syntax --max-opt-count=100 | 28 // Flags: --allow-natives-syntax |
| 29 | 29 |
| 30 function A() { | 30 function A() { |
| 31 } | 31 } |
| 32 | 32 |
| 33 A.prototype.X = function (a, b, c) { | 33 A.prototype.X = function (a, b, c) { |
| 34 assertTrue(this instanceof A); | 34 assertTrue(this instanceof A); |
| 35 assertEquals(1, a); | 35 assertEquals(1, a); |
| 36 assertEquals(2, b); | 36 assertEquals(2, b); |
| 37 assertEquals(3, c); | 37 assertEquals(3, c); |
| 38 }; | 38 }; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 assertArrayEquals([3, 2, 1], toarr(marker, 2, 4, 6)); | 150 assertArrayEquals([3, 2, 1], toarr(marker, 2, 4, 6)); |
| 151 %OptimizeFunctionOnNextCall(toarr); | 151 %OptimizeFunctionOnNextCall(toarr); |
| 152 assertArrayEquals([3, 2, 1], toarr(marker, 2, 4, 6)); | 152 assertArrayEquals([3, 2, 1], toarr(marker, 2, 4, 6)); |
| 153 delete marker.x; | 153 delete marker.x; |
| 154 assertArrayEquals([3, 2, 1], toarr(marker, 2, 4, 6)); | 154 assertArrayEquals([3, 2, 1], toarr(marker, 2, 4, 6)); |
| 155 } | 155 } |
| 156 | 156 |
| 157 test_toarr(toarr1); | 157 test_toarr(toarr1); |
| 158 test_toarr(toarr2); | 158 test_toarr(toarr2); |
| 159 | 159 |
| 160 | |
| 161 // Test that arguments access from inlined function uses correct values. | 160 // Test that arguments access from inlined function uses correct values. |
| 161 // TODO(mstarzinger): Tests disabled, see bug 2261 |
| 162 /* |
| 162 (function () { | 163 (function () { |
| 163 function inner(x, y) { | 164 function inner(x, y) { |
| 164 "use strict"; | 165 "use strict"; |
| 165 x = 10; | 166 x = 10; |
| 166 y = 20; | 167 y = 20; |
| 167 for (var i = 0; i < 1; i++) { | 168 for (var i = 0; i < 1; i++) { |
| 168 for (var j = 1; j <= arguments.length; j++) { | 169 for (var j = 1; j <= arguments.length; j++) { |
| 169 return arguments[arguments.length - j]; | 170 return arguments[arguments.length - j]; |
| 170 } | 171 } |
| 171 } | 172 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 196 function outer(x, y) { | 197 function outer(x, y) { |
| 197 return inner(x, y); | 198 return inner(x, y); |
| 198 } | 199 } |
| 199 | 200 |
| 200 assertEquals(2, outer(1, 2)); | 201 assertEquals(2, outer(1, 2)); |
| 201 assertEquals(2, outer(1, 2)); | 202 assertEquals(2, outer(1, 2)); |
| 202 assertEquals(2, outer(1, 2)); | 203 assertEquals(2, outer(1, 2)); |
| 203 %OptimizeFunctionOnNextCall(outer); | 204 %OptimizeFunctionOnNextCall(outer); |
| 204 assertEquals(2, outer(1, 2)); | 205 assertEquals(2, outer(1, 2)); |
| 205 })(); | 206 })(); |
| 206 | 207 */ |
| 207 | |
| 208 // Test inlining and deoptimization of functions accessing and modifying | |
| 209 // the arguments object in strict mode with mismatched arguments count. | |
| 210 (function () { | |
| 211 "use strict"; | |
| 212 function test(outerCount, middleCount, innerCount) { | |
| 213 var forceDeopt = { deopt:false }; | |
| 214 function inner(x,y) { | |
| 215 x = 0; y = 0; | |
| 216 forceDeopt.deopt; | |
| 217 assertSame(innerCount, arguments.length); | |
| 218 for (var i = 0; i < arguments.length; i++) { | |
| 219 assertSame(30 + i, arguments[i]); | |
| 220 } | |
| 221 } | |
| 222 | |
| 223 function middle(x,y) { | |
| 224 x = 0; y = 0; | |
| 225 if (innerCount == 1) inner(30); | |
| 226 if (innerCount == 2) inner(30, 31); | |
| 227 if (innerCount == 3) inner(30, 31, 32); | |
| 228 assertSame(middleCount, arguments.length); | |
| 229 for (var i = 0; i < arguments.length; i++) { | |
| 230 assertSame(20 + i, arguments[i]); | |
| 231 } | |
| 232 } | |
| 233 | |
| 234 function outer(x,y) { | |
| 235 x = 0; y = 0; | |
| 236 if (middleCount == 1) middle(20); | |
| 237 if (middleCount == 2) middle(20, 21); | |
| 238 if (middleCount == 3) middle(20, 21, 22); | |
| 239 assertSame(outerCount, arguments.length); | |
| 240 for (var i = 0; i < arguments.length; i++) { | |
| 241 assertSame(10 + i, arguments[i]); | |
| 242 } | |
| 243 } | |
| 244 | |
| 245 for (var step = 0; step < 4; step++) { | |
| 246 if (outerCount == 1) outer(10); | |
| 247 if (outerCount == 2) outer(10, 11); | |
| 248 if (outerCount == 3) outer(10, 11, 12); | |
| 249 if (step == 1) %OptimizeFunctionOnNextCall(outer); | |
| 250 if (step == 2) delete forceDeopt.deopt; | |
| 251 } | |
| 252 | |
| 253 %DeoptimizeFunction(outer); | |
| 254 %DeoptimizeFunction(middle); | |
| 255 %DeoptimizeFunction(inner); | |
| 256 %ClearFunctionTypeFeedback(outer); | |
| 257 %ClearFunctionTypeFeedback(middle); | |
| 258 %ClearFunctionTypeFeedback(inner); | |
| 259 } | |
| 260 | |
| 261 for (var a = 1; a <= 3; a++) { | |
| 262 for (var b = 1; b <= 3; b++) { | |
| 263 for (var c = 1; c <= 3; c++) { | |
| 264 test(a,b,c); | |
| 265 } | |
| 266 } | |
| 267 } | |
| 268 })(); | |
| OLD | NEW |