blob: c913bd952136204256988321fc326a79971f03e9 [file] [log] [blame]
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001// Copyright 2012 the V8 project authors. All rights reserved.
Ben Murdochb0fe1622011-05-05 13:52:32 +01002// 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
Ben Murdoch3ef787d2012-04-12 10:51:47 +010028// Flags: --allow-natives-syntax
29
Ben Murdochb0fe1622011-05-05 13:52:32 +010030// Test function.arguments.
31
32function A() {}
33function B() {}
34
35function fee(x, y) {
36 if (x == 1) return fee["arg" + "uments"];
37 if (x == 2) return gee["arg" + "uments"];
38 return 42;
39}
40
41function gee(x) { return this.f(2 - x, "f"); }
42
43function foo(x, y) {
44 if (x == 0) return foo["arg" + "uments"];
45 if (x == 1) return goo["arg" + "uments"];
46 return 42;
47}
48
49function goo(x) { return this.f(x, "f"); }
50
51A.prototype.f = fee;
52A.prototype.g = gee;
53
54B.prototype.f = foo;
55B.prototype.g = goo;
56
57var o = new A();
58
59function hej(x) {
60 if (x == 0) return o.g(x, "h");
61 if (x == 1) return o.g(x, "h");
62 return o.g(x, "z");
63}
64
Ben Murdoch3ef787d2012-04-12 10:51:47 +010065function opt() {
66 for (var k=0; k<2; k++) {
67 for (var i=0; i<5; i++) o.g(i, "g");
68 for (var j=0; j<5; j++) hej(j);
69 }
70 %OptimizeFunctionOnNextCall(o.g);
71 %OptimizeFunctionOnNextCall(hej);
Ben Murdochb0fe1622011-05-05 13:52:32 +010072}
73
Ben Murdoch3ef787d2012-04-12 10:51:47 +010074opt();
Ben Murdochb0fe1622011-05-05 13:52:32 +010075assertArrayEquals([0, "g"], o.g(0, "g"));
76assertArrayEquals([1, "f"], o.g(1, "g"));
77assertArrayEquals([0, "h"], hej(0));
78assertArrayEquals([1, "f"], hej(1));
79
80o = new B();
81
Ben Murdoch3ef787d2012-04-12 10:51:47 +010082opt();
Ben Murdochb0fe1622011-05-05 13:52:32 +010083assertArrayEquals([0, "f"], o.g(0, "g"));
84assertArrayEquals([1, "g"], o.g(1, "g"));
85assertArrayEquals([0, "f"], hej(0));
86assertArrayEquals([1, "h"], hej(1));