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
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.
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.
28 // Flags: --allow-natives-syntax --noalways-opt
33 Array.prototype.fun = function() {
36 assertEquals(0, arguments.length);
39 Array.prototype.funStrict = function() {
43 assertEquals(0, arguments.length);
46 Array.prototype.manyArgs = function() {
48 assertEquals(5, arguments.length);
49 assertEquals(0, this);
50 assertEquals(5, arguments[4]);
54 Array.prototype.manyArgsSloppy = function() {
55 assertEquals(global, this);
56 assertEquals(5, arguments.length);
57 assertEquals(5, arguments[4]);
62 for (var i = 0; i < 100; ++i) {
66 var copy = array.slice();
68 function unshiftsArray(num) {
69 [].unshift.call(array, num);
74 %OptimizeFunctionOnNextCall(unshiftsArray);
85 assertOptimized(unshiftsArray);
86 assertArrayEquals(array, copy);
92 function callNoArgs() {
98 assertEquals(this, funRecv);
99 %OptimizeFunctionOnNextCall(callNoArgs);
101 assertEquals(this, funRecv);
102 assertEquals(3, called);
103 assertOptimized(callNoArgs);
108 function callStrictNoArgs() {
114 assertEquals(undefined, funStrictRecv);
115 %OptimizeFunctionOnNextCall(callStrictNoArgs);
117 assertEquals(undefined, funStrictRecv);
118 assertEquals(3, called);
119 assertOptimized(callStrictNoArgs);
124 function callManyArgs() {
125 [].manyArgs.call(0, 1, 2, 3, 4, 5);
130 %OptimizeFunctionOnNextCall(callManyArgs);
132 assertOptimized(callManyArgs);
133 assertEquals(called, 3);
138 function callManyArgsSloppy() {
139 [].manyArgsSloppy.call(null, 1, 2, 3, 4, 5);
142 callManyArgsSloppy();
143 callManyArgsSloppy();
144 %OptimizeFunctionOnNextCall(callManyArgsSloppy);
145 callManyArgsSloppy();
146 assertOptimized(callManyArgsSloppy);
147 assertEquals(called, 3);
150 var code = str.charCodeAt(3);
152 function callBuiltinIndirectly() {
154 return "".charCodeAt.call(str, 3);
157 callBuiltinIndirectly();
158 callBuiltinIndirectly();
159 %OptimizeFunctionOnNextCall(callBuiltinIndirectly);
160 assertEquals(code, callBuiltinIndirectly());
161 assertOptimized(callBuiltinIndirectly);
162 assertEquals(3, called);
164 this.array = [1,2,3,4,5,6,7,8,9];
165 var copy = this.array.slice();
168 function callInlineableBuiltinIndirectlyWhileInlined() {
170 return [].push.apply(array, arguments);
173 function callInlined(num) {
174 return callInlineableBuiltinIndirectlyWhileInlined(num);
177 callInlineableBuiltinIndirectlyWhileInlined(1);
178 callInlineableBuiltinIndirectlyWhileInlined(2);
179 %OptimizeFunctionOnNextCall(callInlineableBuiltinIndirectlyWhileInlined);
180 callInlineableBuiltinIndirectlyWhileInlined(3);
181 assertOptimized(callInlineableBuiltinIndirectlyWhileInlined);
185 %OptimizeFunctionOnNextCall(callInlined);
187 copy.push(1, 2, 3, 1, 2, 3);
188 assertOptimized(callInlined);
189 assertArrayEquals(copy, this.array);
190 assertEquals(6, called);