OLD | NEW |
(Empty) | |
| 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 --noalways-opt |
| 29 |
| 30 var array = []; |
| 31 for (var i = 0; i < 100; ++i) { |
| 32 array[i] = i; |
| 33 } |
| 34 |
| 35 var copy = array.slice(); |
| 36 |
| 37 function unshiftsArray(num) { |
| 38 [].unshift.call(array, num); |
| 39 } |
| 40 |
| 41 unshiftsArray(50); |
| 42 unshiftsArray(60); |
| 43 %OptimizeFunctionOnNextCall(unshiftsArray); |
| 44 unshiftsArray(80); |
| 45 unshiftsArray(50); |
| 46 unshiftsArray(60); |
| 47 |
| 48 copy.unshift(50); |
| 49 copy.unshift(60); |
| 50 copy.unshift(80); |
| 51 copy.unshift(50); |
| 52 copy.unshift(60); |
| 53 |
| 54 assertOptimized(unshiftsArray); |
| 55 assertArrayEquals(array, copy); |
| 56 |
| 57 |
| 58 var called = 0; |
| 59 var funRecv; |
| 60 // For the HConstant |
| 61 Array.prototype.fun = function() { |
| 62 funRecv = this; |
| 63 called++; |
| 64 assertEquals(0, arguments.length); |
| 65 }; |
| 66 |
| 67 function callNoArgs() { |
| 68 [].fun.call(); |
| 69 } |
| 70 |
| 71 callNoArgs(); |
| 72 callNoArgs(); |
| 73 assertEquals(this, funRecv); |
| 74 %OptimizeFunctionOnNextCall(callNoArgs); |
| 75 callNoArgs(); |
| 76 assertEquals(this, funRecv); |
| 77 assertEquals(3, called); |
| 78 assertOptimized(callNoArgs); |
| 79 |
| 80 var funStrictRecv; |
| 81 Array.prototype.funStrict = function() { |
| 82 "use strict"; |
| 83 funStrictRecv = this; |
| 84 called++; |
| 85 assertEquals(0, arguments.length); |
| 86 }; |
| 87 |
| 88 function callStrictNoArgs() { |
| 89 [].fun.call(); |
| 90 } |
| 91 |
| 92 callStrictNoArgs(); |
| 93 callStrictNoArgs(); |
| 94 assertEquals(void 0, funStrictRecv); |
| 95 %OptimizeFunctionOnNextCall(callStrictNoArgs); |
| 96 callStrictNoArgs(); |
| 97 assertEquals(void 0, funStrictRecv); |
| 98 assertEquals(6, called); |
| 99 assertOptimized(callStrictNoArgs); |
| 100 |
| 101 |
| 102 Array.prototype.manyArgs = function() { |
| 103 "use strict"; |
| 104 assertEquals(5, arguments.length); |
| 105 assertEquals(0, this); |
| 106 assertEquals(5, arguments[4]); |
| 107 } |
| 108 |
| 109 function callManyArgs() { |
| 110 [].manyArgs.call(0, 1, 2, 3, 4, 5); |
| 111 } |
| 112 |
| 113 callManyArgs(); |
| 114 callManyArgs(); |
| 115 %OptimizeFunctionOnNextCall(callManyArgs); |
| 116 callManyArgs(); |
| 117 assertOptimized(callManyArgs); |
| 118 |
| 119 Array.prototype.manyArgsSloppy = function() { |
| 120 assertTrue(this instanceof Number); |
| 121 assertEquals(5, arguments.length); |
| 122 assertEquals(0, this.valueOf()); |
| 123 assertEquals(5, arguments[4]); |
| 124 } |
| 125 |
| 126 function callManyArgsSloppy() { |
| 127 [].manyArgs.call(0, 1, 2, 3, 4, 5); |
| 128 } |
| 129 |
| 130 callManyArgsSloppy(); |
| 131 callManyArgsSloppy(); |
| 132 %OptimizeFunctionOnNextCall(callManyArgsSloppy); |
| 133 callManyArgsSloppy(); |
| 134 assertOptimized(callManyArgsSloppy); |
| 135 |
| 136 var str = "hello"; |
| 137 var code = str.charCodeAt(3) |
| 138 function callBuiltinIndirectly() { |
| 139 return "".charCodeAt.call(str, 3); |
| 140 } |
| 141 |
| 142 callBuiltinIndirectly(); |
| 143 callBuiltinIndirectly(); |
| 144 %OptimizeFunctionOnNextCall(callBuiltinIndirectly); |
| 145 assertEquals(code, callBuiltinIndirectly()); |
| 146 assertOptimized(callBuiltinIndirectly); |
| 147 |
| 148 this.array = [1,2,3,4,5,6,7,8,9]; |
| 149 var copy = this.array.slice(); |
| 150 |
| 151 function callInlineableBuiltinIndirectlyWhileInlined() { |
| 152 return [].push.apply(array, arguments); |
| 153 } |
| 154 |
| 155 function callInlined(num) { |
| 156 return callInlineableBuiltinIndirectlyWhileInlined(num); |
| 157 } |
| 158 |
| 159 callInlined(1); |
| 160 callInlined(2); |
| 161 %OptimizeFunctionOnNextCall(callInlineableBuiltinIndirectlyWhileInlined); |
| 162 %OptimizeFunctionOnNextCall(callInlined); |
| 163 callInlined(3); |
| 164 copy.push(1, 2, 3); |
| 165 assertOptimized(callInlined); |
| 166 assertOptimized(callInlineableBuiltinIndirectlyWhileInlined); |
| 167 assertArrayEquals(copy, this.array); |
OLD | NEW |