Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1 | // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 | // Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. |
| 3 | // |
| 4 | // Redistribution and use in source and binary forms, with or without |
| 5 | // modification, are permitted provided that the following conditions |
| 6 | // are met: |
| 7 | // 1. Redistributions of source code must retain the above copyright |
| 8 | // notice, this list of conditions and the following disclaimer. |
| 9 | // 2. Redistributions in binary form must reproduce the above copyright |
| 10 | // notice, this list of conditions and the following disclaimer in the |
| 11 | // documentation and/or other materials provided with the distribution. |
| 12 | // |
| 13 | // THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY |
| 14 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 15 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 16 | // DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 17 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 18 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 19 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
| 20 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 21 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 22 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 | |
| 24 | description('Test that we properly fill in missing args with "undefined" in JIT code.'); |
| 25 | |
| 26 | // Regression test for <rdar://problem/10763509> |
| 27 | |
| 28 | |
| 29 | function callee(a1, a2, a3, a4, a5, a6, a7, a8) |
| 30 | { |
| 31 | // We expect that the unused actual parameters will be filled |
| 32 | // with undefined. |
| 33 | if (a1 !== undefined) |
| 34 | return "Arg1 is wrong"; |
| 35 | if (a2 !== undefined) |
| 36 | return "Arg2 is wrong"; |
| 37 | if (a3 !== undefined) |
| 38 | return "Arg3 is wrong"; |
| 39 | if (a4 !== undefined) |
| 40 | return "Arg4 is wrong"; |
| 41 | if (a5 !== undefined) |
| 42 | return "Arg5 is wrong"; |
| 43 | if (a6 !== undefined) |
| 44 | return "Arg6 is wrong"; |
| 45 | if (a7 !== undefined) |
| 46 | return "Arg7 is wrong"; |
| 47 | if (a8 !== undefined) |
| 48 | return "Arg8 is wrong"; |
| 49 | |
| 50 | return undefined; |
| 51 | } |
| 52 | |
| 53 | function dummy(a1, a2, a3, a4, a5, a6, a7, a8) |
| 54 | { |
| 55 | } |
| 56 | |
| 57 | function BaseObj() |
| 58 | { |
| 59 | } |
| 60 | |
| 61 | function caller(testArgCount) |
| 62 | { |
| 63 | var baseObj = new BaseObj(); |
| 64 | |
| 65 | var allArgs = [0, "String", callee, true, null, 2.5, [1, 2, 3], {'a': 1, 'b' : 2}]; |
| 66 | argCounts = [8, testArgCount]; |
| 67 | |
| 68 | for (argCountIndex = 0; argCountIndex < argCounts.length; argCountIndex++) { |
| 69 | argCount = argCounts[argCountIndex]; |
| 70 | |
| 71 | var varArgs = []; |
| 72 | for (i = 0; i < argCount; i++) |
| 73 | varArgs[i] = undefined; |
| 74 | |
| 75 | for (numCalls = 0; numCalls < 10; numCalls++) { |
| 76 | // Run multiple times so that the JIT kicks in |
| 77 | dummy.apply(baseObj, allArgs); |
| 78 | var result = callee.apply(baseObj, varArgs); |
| 79 | if (result != undefined) |
| 80 | return result; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | return undefined; |
| 85 | } |
| 86 | |
| 87 | shouldBe("caller(0)", 'undefined'); |
| 88 | shouldBe("caller(1)", 'undefined'); |
| 89 | shouldBe("caller(2)", 'undefined'); |
| 90 | shouldBe("caller(3)", 'undefined'); |
| 91 | shouldBe("caller(4)", 'undefined'); |
| 92 | shouldBe("caller(5)", 'undefined'); |
| 93 | shouldBe("caller(6)", 'undefined'); |
| 94 | shouldBe("caller(7)", 'undefined'); |
| 95 | shouldBe("caller(8)", 'undefined'); |
| 96 | |
| 97 | var successfullyParsed = true; |