Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1 | // Copyright 2014 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 | // Flags: --allow-natives-syntax |
| 29 | |
| 30 | (function DeoptimizeArgCallFunctionGeneric() { |
| 31 | var a = []; |
| 32 | |
| 33 | function f1(method, array, elem, deopt) { |
| 34 | assertEquals('push', method); |
| 35 | } |
| 36 | |
| 37 | function f2() { } |
| 38 | |
| 39 | function bar(x, deopt, f) { |
| 40 | f('push', a, [x], deopt + 0); |
| 41 | } |
| 42 | |
| 43 | function foo() { return bar(arguments[0], arguments[1], arguments[2]); } |
| 44 | function baz(f, deopt) { return foo("x", deopt, f); } |
| 45 | |
| 46 | baz(f1, 0); |
| 47 | baz(f2, 0); |
| 48 | %OptimizeFunctionOnNextCall(baz); |
| 49 | baz(f1, "deopt"); |
| 50 | })(); |
| 51 | |
| 52 | |
| 53 | (function DeoptimizeArgGlobalFunctionGeneric() { |
| 54 | var a = []; |
| 55 | |
| 56 | var f1; |
| 57 | |
| 58 | f1 = function(method, array, elem, deopt) { |
| 59 | assertEquals('push', method); |
| 60 | } |
| 61 | |
| 62 | function bar(x, deopt, f) { |
| 63 | f1('push', a, [x], deopt + 0); |
| 64 | } |
| 65 | |
| 66 | function foo() { return bar(arguments[0], arguments[1]); } |
| 67 | function baz(deopt) { return foo("x", deopt); } |
| 68 | |
| 69 | baz(0); |
| 70 | baz(0); |
| 71 | %OptimizeFunctionOnNextCall(baz); |
| 72 | baz("deopt"); |
| 73 | })(); |
| 74 | |
| 75 | |
| 76 | (function DeoptimizeArgCallFunctionRuntime() { |
| 77 | var a = []; |
| 78 | |
| 79 | var f1; |
| 80 | |
| 81 | f1 = function(method, array, elem, deopt) { |
| 82 | assertEquals('push', method); |
| 83 | } |
| 84 | |
| 85 | function bar(x, deopt) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 86 | %_Call(f1, null, 'push', [x][0], ((deopt + 0), 1)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | function foo() { return bar(arguments[0], arguments[1]); } |
| 90 | function baz(deopt) { return foo(0, deopt); } |
| 91 | |
| 92 | baz(0); |
| 93 | baz(0); |
| 94 | %OptimizeFunctionOnNextCall(baz); |
| 95 | baz("deopt"); |
| 96 | })(); |