OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
11 // with the distribution. | 11 // with the distribution. |
(...skipping 10 matching lines...) Expand all Loading... |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 // Flags: --allow-natives-syntax | 28 // Flags: --allow-natives-syntax |
29 | 29 |
30 // Check that %NewObjectFromBound works correctly when called from optimized | 30 // Check that %NewObjectFromBound works correctly when called from optimized |
31 // frame. | 31 // frame. |
32 function foo(x, y, z) { | 32 function foo1(x, y, z) { |
33 assertEquals(1, x); | 33 assertEquals(1, x); |
34 assertEquals(2, y); | 34 assertEquals(2, y); |
35 assertEquals(3, z); | 35 assertEquals(3, z); |
36 } | 36 } |
37 | 37 |
38 var foob = foo.bind({}, 1); | 38 function foo2(x, y, z) { |
| 39 assertEquals(1, x); |
| 40 assertEquals(2, y); |
| 41 assertEquals(undefined, z); |
| 42 } |
39 | 43 |
40 function f(y, z) { | 44 function foo3(x, y, z) { |
41 return %NewObjectFromBound(foob); | 45 assertEquals(1, x); |
| 46 assertEquals(2, y); |
| 47 assertEquals(3, z); |
| 48 } |
| 49 |
| 50 |
| 51 var foob1 = foo1.bind({}, 1); |
| 52 var foob2 = foo2.bind({}, 1); |
| 53 var foob3 = foo3.bind({}, 1); |
| 54 |
| 55 |
| 56 function f1(y, z) { |
| 57 return %NewObjectFromBound(foob1); |
| 58 } |
| 59 |
| 60 function f2(y, z) { |
| 61 return %NewObjectFromBound(foob2); |
| 62 } |
| 63 |
| 64 function f3(y, z) { |
| 65 return %NewObjectFromBound(foob3); |
42 } | 66 } |
43 | 67 |
44 // Check that %NewObjectFromBound looks at correct frame for inlined function. | 68 // Check that %NewObjectFromBound looks at correct frame for inlined function. |
45 function g(z, y) { | 69 function g1(z, y) { |
46 return f(y, z); /* f should be inlined into g, note rotated arguments */ | 70 return f1(y, z); /* f should be inlined into g, note rotated arguments */ |
| 71 } |
| 72 |
| 73 function g2(z, y, x) { |
| 74 return f2(y); /* f should be inlined into g, note argument count mismatch */ |
| 75 } |
| 76 |
| 77 function g3(z, y, x) { |
| 78 return f3(x, y, z); /* f should be inlined into g, note argument count mismatc
h */ |
47 } | 79 } |
48 | 80 |
49 // Check that %NewObjectFromBound looks at correct frame for inlined function. | 81 // Check that %NewObjectFromBound looks at correct frame for inlined function. |
50 function ff(x) { } | 82 function ff(x) { } |
51 function h(z2, y2) { | 83 function h1(z2, y2) { |
52 var local_z = z2 >> 1; | 84 var local_z = z2 >> 1; |
53 ff(local_z); | 85 ff(local_z); |
54 var local_y = y2 >> 1; | 86 var local_y = y2 >> 1; |
55 ff(local_y); | 87 ff(local_y); |
56 return f(local_y, local_z); /* f should be inlined into h */ | 88 return f1(local_y, local_z); /* f should be inlined into h */ |
57 } | 89 } |
58 | 90 |
59 for (var i = 0; i < 5; i++) f(2, 3); | 91 function h2(z2, y2, x2) { |
60 %OptimizeFunctionOnNextCall(f); | 92 var local_z = z2 >> 1; |
61 f(2, 3); | 93 ff(local_z); |
| 94 var local_y = y2 >> 1; |
| 95 ff(local_y); |
| 96 return f2(local_y); /* f should be inlined into h */ |
| 97 } |
62 | 98 |
63 for (var i = 0; i < 5; i++) g(3, 2); | 99 function h3(z2, y2, x2) { |
64 %OptimizeFunctionOnNextCall(g); | 100 var local_z = z2 >> 1; |
65 g(3, 2); | 101 ff(local_z); |
| 102 var local_y = y2 >> 1; |
| 103 ff(local_y); |
| 104 var local_x = x2 >> 1; |
| 105 ff(local_x); |
| 106 return f3(local_x, local_y, local_z); /* f should be inlined into h */ |
| 107 } |
66 | 108 |
67 for (var i = 0; i < 5; i++) h(6, 4); | 109 |
68 %OptimizeFunctionOnNextCall(h); | 110 function invoke(f, args) { |
69 h(6, 4); | 111 for (var i = 0; i < 5; i++) f.apply(this, args); |
| 112 %OptimizeFunctionOnNextCall(f); |
| 113 f.apply(this, args); |
| 114 } |
| 115 |
| 116 invoke(f1, [2, 3]); |
| 117 invoke(f2, [2]); |
| 118 invoke(f3, [2, 3, 4]); |
| 119 invoke(g1, [3, 2]); |
| 120 invoke(g2, [3, 2, 4]); |
| 121 invoke(g3, [4, 3, 2]); |
| 122 invoke(h1, [6, 4]); |
| 123 invoke(h2, [6, 4, 8]); |
| 124 invoke(h3, [8, 6, 4]); |
70 | 125 |
71 // Check that %_IsConstructCall returns correct value when inlined | 126 // Check that %_IsConstructCall returns correct value when inlined |
72 var NON_CONSTRUCT_MARKER = {}; | 127 var NON_CONSTRUCT_MARKER = {}; |
73 var CONSTRUCT_MARKER = {}; | 128 var CONSTRUCT_MARKER = {}; |
74 function baz() { | 129 function baz(x) { |
75 return (!%_IsConstructCall()) ? NON_CONSTRUCT_MARKER : CONSTRUCT_MARKER; | 130 return (!%_IsConstructCall()) ? NON_CONSTRUCT_MARKER : CONSTRUCT_MARKER; |
76 } | 131 } |
77 | 132 |
78 function bar(x, y, z) { | 133 function bar(x, y, z) { |
| 134 var non_construct = baz(0); /* baz should be inlined */ |
| 135 assertEquals(non_construct, NON_CONSTRUCT_MARKER); |
79 var non_construct = baz(); /* baz should be inlined */ | 136 var non_construct = baz(); /* baz should be inlined */ |
80 assertEquals(non_construct, NON_CONSTRUCT_MARKER); | 137 assertEquals(non_construct, NON_CONSTRUCT_MARKER); |
81 var construct = new baz(); | 138 var non_construct = baz(0, 0); /* baz should be inlined */ |
| 139 assertEquals(non_construct, NON_CONSTRUCT_MARKER); |
| 140 var construct = new baz(0); |
82 assertEquals(construct, CONSTRUCT_MARKER); | 141 assertEquals(construct, CONSTRUCT_MARKER); |
83 } | 142 } |
84 | 143 |
85 for (var i = 0; i < 5; i++) new bar(1, 2, 3); | 144 invoke(bar, [1, 2, 3]); |
86 %OptimizeFunctionOnNextCall(bar); | |
87 bar(1, 2, 3); | |
OLD | NEW |