Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2012 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 --inline-construct | |
| 29 | |
| 30 // Test inlining of constructor calls. | |
| 31 | |
| 32 function c1(a, b) { | |
| 33 this.x = a + b; | |
| 34 } | |
| 35 | |
| 36 function c2(a, b) { | |
| 37 var obj = new Object(); | |
| 38 obj.y = a + b; | |
| 39 return obj; | |
|
Vyacheslav Egorov (Chromium)
2012/02/13 15:01:39
it might be also interesting to check non-object r
Michael Starzinger
2012/02/27 14:16:32
Done.
| |
| 40 } | |
| 41 | |
| 42 function f1(a, b) { | |
| 43 var obj = new c1(a, b); | |
|
Vyacheslav Egorov (Chromium)
2012/02/13 15:01:39
please extend this test to test inlining in all th
Michael Starzinger
2012/02/27 14:16:32
Done.
| |
| 44 return obj.x; | |
| 45 } | |
| 46 | |
| 47 function f2(a, b) { | |
| 48 var obj = new c2(a, b); | |
| 49 return obj.y; | |
| 50 } | |
| 51 | |
| 52 assertEquals(23, f1(11, 12)); | |
| 53 assertEquals(42, f1(23, 19)); | |
| 54 %OptimizeFunctionOnNextCall(f1); | |
| 55 assertEquals(43, f1(1, 42)); | |
| 56 assertEquals("foobar", f1("foo", "bar")) | |
| 57 | |
| 58 assertEquals(23, f2(11, 12)); | |
| 59 assertEquals(42, f2(23, 19)); | |
| 60 %OptimizeFunctionOnNextCall(f2); | |
| 61 assertEquals(43, f2(1, 42)); | |
| 62 assertEquals("foobar", f2("foo", "bar")) | |
| 63 | |
| 64 function c_too_many(a, b) { | |
| 65 this.x = a + b; | |
| 66 } | |
| 67 | |
| 68 function c_too_few(a, b) { | |
| 69 assertSame(undefined, b); | |
| 70 this.x = a + 1; | |
| 71 } | |
| 72 | |
| 73 function f_too_many(a, b, c) { | |
| 74 var obj = new c_too_many(a, b, c); | |
| 75 return obj.x; | |
| 76 } | |
| 77 | |
| 78 function f_too_few(a) { | |
| 79 var obj = new c_too_few(a); | |
| 80 return obj.x; | |
| 81 } | |
| 82 | |
| 83 assertEquals(23, f_too_many(11, 12, 1)); | |
| 84 assertEquals(42, f_too_many(23, 19, 1)); | |
| 85 %OptimizeFunctionOnNextCall(f_too_many); | |
| 86 assertEquals(43, f_too_many(1, 42, 1)); | |
| 87 assertEquals("foobar", f_too_many("foo", "bar", "baz")) | |
| 88 | |
| 89 assertEquals(12, f_too_few(11)); | |
| 90 assertEquals(24, f_too_few(23)); | |
| 91 %OptimizeFunctionOnNextCall(f_too_few); | |
| 92 assertEquals(2, f_too_few(1)); | |
| 93 assertEquals("foo1", f_too_few("foo")) | |
| OLD | NEW |