Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1 | // Copyright 2013 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 f_store(test, test2, a, i) { |
| 31 | var o = [0.5,1,,3]; |
| 32 | var d; |
| 33 | if (test) { |
| 34 | d = 1.5; |
| 35 | } else { |
| 36 | d = o[i]; |
| 37 | } |
| 38 | if (test2) { |
| 39 | d += 1; |
| 40 | } |
| 41 | a[i] = d; |
| 42 | return d; |
| 43 | } |
| 44 | |
| 45 | var a1 = [0, 0, 0, {}]; |
| 46 | f_store(true, false, a1, 0); |
| 47 | f_store(true, true, a1, 0); |
| 48 | f_store(false, false, a1, 1); |
| 49 | f_store(false, true, a1, 1); |
| 50 | %OptimizeFunctionOnNextCall(f_store); |
| 51 | f_store(false, false, a1, 2); |
| 52 | assertEquals(undefined, a1[2]); |
| 53 | |
| 54 | function test_arg(expected) { |
| 55 | return function(v) { |
| 56 | assertEquals(expected, v); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | function f_call(f, test, test2, i) { |
| 61 | var o = [0.5,1,,3]; |
| 62 | var d; |
| 63 | if (test) { |
| 64 | d = 1.5; |
| 65 | } else { |
| 66 | d = o[i]; |
| 67 | } |
| 68 | if (test2) { |
| 69 | d += 1; |
| 70 | } |
| 71 | f(d); |
| 72 | return d; |
| 73 | } |
| 74 | |
| 75 | f_call(test_arg(1.5), true, false, 0); |
| 76 | f_call(test_arg(2.5), true, true, 0); |
| 77 | f_call(test_arg(1), false, false, 1); |
| 78 | f_call(test_arg(2), false, true, 1); |
| 79 | %OptimizeFunctionOnNextCall(f_call); |
| 80 | f_call(test_arg(undefined), false, false, 2); |
| 81 | |
| 82 | |
| 83 | function f_external(test, test2, test3, a, i) { |
| 84 | var o = [0.5,1,,3]; |
| 85 | var d; |
| 86 | if (test) { |
| 87 | d = 1.5; |
| 88 | } else { |
| 89 | d = o[i]; |
| 90 | } |
| 91 | if (test2) { |
| 92 | d += 1; |
| 93 | } |
| 94 | if (test3) { |
| 95 | d = d|0; |
| 96 | } |
| 97 | a[d] = 1; |
| 98 | assertEquals(1, a[d]); |
| 99 | return d; |
| 100 | } |
| 101 | |
| 102 | var a2 = new Int32Array(10); |
| 103 | f_external(true, false, true, a2, 0); |
| 104 | f_external(true, true, true, a2, 0); |
| 105 | f_external(false, false, true, a2, 1); |
| 106 | f_external(false, true, true, a2, 1); |
| 107 | %OptimizeFunctionOnNextCall(f_external); |
| 108 | f_external(false, false, false, a2, 2); |
| 109 | assertEquals(1, a2[undefined]); |