1// Copyright 2011 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 30function A() { 31} 32 33A.prototype.X = function (a, b, c) { 34 assertTrue(this instanceof A); 35 assertEquals(1, a); 36 assertEquals(2, b); 37 assertEquals(3, c); 38}; 39 40A.prototype.Y = function () { 41 this.X.apply(this, arguments); 42}; 43 44A.prototype.Z = function () { 45 this.Y(1,2,3); 46}; 47 48var a = new A(); 49a.Z(4,5,6); 50a.Z(4,5,6); 51%OptimizeFunctionOnNextCall(a.Z); 52a.Z(4,5,6); 53A.prototype.X.apply = function (receiver, args) { 54 return Function.prototype.apply.call(this, receiver, args); 55}; 56a.Z(4,5,6); 57 58 59// Ensure that HArgumentsObject is inserted in a correct place 60// and dominates all uses. 61function F1() { } 62function F2() { F1.apply(this, arguments); } 63function F3(x, y) { 64 if (x) { 65 F2(y); 66 } 67} 68 69function F31() { 70 return F1.apply(this, arguments); 71} 72 73function F4() { 74 F3(true, false); 75 return F31(1); 76} 77 78F4(1); 79F4(1); 80F4(1); 81%OptimizeFunctionOnNextCall(F4); 82F4(1); 83 84 85// Test correct adapation of arguments. 86// Strict mode prevents arguments object from shadowing parameters. 87(function () { 88 "use strict"; 89 90 function G2() { 91 assertArrayEquals([1,2], arguments); 92 } 93 94 function G4() { 95 assertArrayEquals([1,2,3,4], arguments); 96 } 97 98 function adapt2to4(a, b, c, d) { 99 G2.apply(this, arguments); 100 } 101 102 function adapt4to2(a, b) { 103 G4.apply(this, arguments); 104 } 105 106 function test_adaptation() { 107 adapt2to4(1, 2); 108 adapt4to2(1, 2, 3, 4); 109 } 110 111 test_adaptation(); 112 test_adaptation(); 113 %OptimizeFunctionOnNextCall(test_adaptation); 114 test_adaptation(); 115})(); 116