| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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. |
| 12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
| 15 // | 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 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 |
| 29 |
| 28 // Check that constants and computed properties are overwriting each other | 30 // Check that constants and computed properties are overwriting each other |
| 29 // correctly, i.e., the last initializer for any name is stored in the object. | 31 // correctly, i.e., the last initializer for any name is stored in the object. |
| 30 | 32 |
| 31 | 33 |
| 32 // Tests for the full code generator (if active). | 34 // Tests for the full code generator (if active). |
| 33 | 35 |
| 34 var foo1 = { | 36 var foo1 = { |
| 35 bar: 6, | 37 bar: 6, |
| 36 bar: 7 | 38 bar: 7 |
| 37 }; | 39 }; |
| 38 | 40 |
| 39 var foo2 = { | 41 var foo2 = { |
| 40 bar: function(a){}, | 42 bar: function(a){}, |
| 41 bar: 7 | 43 bar: 7 |
| 42 }; | 44 }; |
| 43 | 45 |
| 44 var foo3 = { | 46 var foo3 = { |
| 45 bar: function(a){}, | 47 bar: function(a){}, |
| 46 bar: function(b){}, | 48 bar: function(b){}, |
| 47 bar: 7 | 49 bar: 7 |
| 48 }; | 50 }; |
| 49 | 51 |
| 50 var foo4 = { | 52 var foo4 = { |
| 51 bar: function(b){}, | 53 bar: function(b){}, |
| 52 bar: 7, | 54 bar: 4, |
| 53 bar: function(){return 7}, | 55 bar: function(){return 7}, |
| 54 }; | 56 }; |
| 55 | 57 |
| 56 var foo5 = { | 58 var foo5 = { |
| 57 13: function(a){}, | 59 13: function(a){}, |
| 58 13: 7 | 60 13: 7 |
| 59 } | 61 } |
| 60 | 62 |
| 61 var foo6 = { | 63 var foo6 = { |
| 62 14.31: function(a){}, | 64 14.31: function(a){}, |
| 63 14.31: 7 | 65 14.31: 7 |
| 64 } | 66 } |
| 65 | 67 |
| 66 var foo7 = { | 68 var foo7 = { |
| 67 15: 6, | 69 15: 6, |
| 68 15: 7 | 70 15: 7 |
| 69 } | 71 } |
| 70 | 72 |
| 73 function foo8(i) { |
| 74 var obj = { |
| 75 x: {a: i}, |
| 76 x: 7 |
| 77 }; |
| 78 return obj.x; |
| 79 }; |
| 80 |
| 71 assertEquals(7, foo1.bar); | 81 assertEquals(7, foo1.bar); |
| 72 assertEquals(7, foo2.bar); | 82 assertEquals(7, foo2.bar); |
| 73 assertEquals(7, foo3.bar); | 83 assertEquals(7, foo3.bar); |
| 74 assertEquals(7, foo4.bar()); | 84 assertEquals(7, foo4.bar()); |
| 75 assertEquals(7, foo5[13]); | 85 assertEquals(7, foo5[13]); |
| 76 assertEquals(7, foo6[14.31]); | 86 assertEquals(7, foo6[14.31]); |
| 77 assertEquals(7, foo7[15]); | 87 assertEquals(7, foo7[15]); |
| 78 | 88 |
| 89 assertEquals(7, foo8(1)); |
| 90 assertEquals(7, foo8(1)); |
| 91 %OptimizeFunctionOnNextCall(foo8); |
| 92 assertEquals(7, foo8(1)); |
| 93 |
| 94 |
| 79 // Test for the classic code generator. | 95 // Test for the classic code generator. |
| 80 | 96 |
| 81 function fun(x) { | 97 function fun(x) { |
| 82 var inner = { j: function(x) { return x; }, j: 7 }; | 98 var inner = { j: function(x) { return x; }, j: 7 }; |
| 83 return inner.j; | 99 return inner.j; |
| 84 } | 100 } |
| 85 | 101 |
| 86 assertEquals(7, fun(7) ); | 102 assertEquals(7, fun(7) ); |
| 87 | 103 |
| 88 // Check that the initializers of computed properties are executed, even if | 104 // Check that the initializers of computed properties are executed, even if |
| (...skipping 20 matching lines...) Expand all Loading... |
| 109 var glob3 = 0; | 125 var glob3 = 0; |
| 110 | 126 |
| 111 function fun3() { | 127 function fun3() { |
| 112 var r = { 113: glob3++, 113: glob3++, 113: glob3++, 113: 7}; | 128 var r = { 113: glob3++, 113: glob3++, 113: glob3++, 113: 7}; |
| 113 return r[113]; | 129 return r[113]; |
| 114 } | 130 } |
| 115 | 131 |
| 116 var y = fun3(); | 132 var y = fun3(); |
| 117 assertEquals(7, y); | 133 assertEquals(7, y); |
| 118 assertEquals(3, glob3); | 134 assertEquals(3, glob3); |
| OLD | NEW |