1 // Copyright 2013 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 --use-escape-analysis --expose-gc
31 // Simple test of capture
32 (function testCapturedArguments() {
34 return g.arguments[0];
42 var l = { y : { z : 4 }, x : 2 }
48 // Test that the arguments object is properly
52 assertEquals(5, r.y.z);
56 %OptimizeFunctionOnNextCall(f);
61 // Get the arguments object twice, test aliasing
62 (function testTwoCapturedArguments() {
64 return g.arguments[0];
68 return g.arguments[0];
72 return {h : h() , i : i()};
76 var l = { y : { z : 4 }, x : 2 }
78 assertEquals(2, r.h.x)
80 assertEquals(3, r.h.y.z);
81 assertEquals(3, r.i.y.z);
85 %OptimizeFunctionOnNextCall(f);
90 // Nested arguments object test
91 (function testTwoCapturedArgumentsNested() {
93 return { gx : g.arguments[0], hx : h.arguments[0] };
105 var l = { y : { z : 4 }, x : 2 }
107 assertEquals(2, r.gx.x)
108 assertEquals(4, r.gx.y.z)
109 assertEquals(4, r.hx.z)
111 assertEquals(3, r.gx.y.z)
112 assertEquals(3, r.hx.z)
113 assertEquals(3, l.y.z)
117 %OptimizeFunctionOnNextCall(f);
119 %OptimizeFunctionOnNextCall(f);
124 // Nested arguments object test with different inlining
125 (function testTwoCapturedArgumentsNested2() {
127 return { gx : g.arguments[0], hx : h.arguments[0] };
139 var l = { y : { z : 4 }, x : 2 }
141 assertEquals(2, r.gx.x)
142 assertEquals(4, r.gx.y.z)
143 assertEquals(4, r.hx.z)
145 assertEquals(3, r.gx.y.z)
146 assertEquals(3, r.hx.z)
147 assertEquals(3, l.y.z)
150 %NeverOptimizeFunction(i);
152 %OptimizeFunctionOnNextCall(f);
154 %OptimizeFunctionOnNextCall(f);
159 // Multiple captured argument test
160 (function testTwoArgumentsCapture() {
162 return { a : g.arguments[1], b : g.arguments[0] };
170 var l = { y : { z : 4 }, x : 2 }
171 var k = { t : { u : 3 } };
173 assertEquals(2, r.a.x)
174 assertEquals(4, r.a.y.z)
175 assertEquals(3, r.b.t.u)
178 assertEquals(6, r.a.y.z)
179 assertEquals(7, k.t.u)
183 %OptimizeFunctionOnNextCall(f);
185 %OptimizeFunctionOnNextCall(f);