OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 --use-escape-analysis | 28 // Flags: --allow-natives-syntax --use-escape-analysis --expose-gc |
29 | 29 |
30 | 30 |
31 // Test stores on a join path. | 31 // Test stores on a join path. |
32 (function testJoin() { | 32 (function testJoin() { |
33 function constructor() { | 33 function constructor() { |
34 this.a = 0; | 34 this.a = 0; |
35 } | 35 } |
36 function join(mode, expected) { | 36 function join(mode, expected) { |
37 var object = new constructor(); | 37 var object = new constructor(); |
38 if (mode) { | 38 if (mode) { |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 } | 234 } |
235 function test(closure) { | 235 function test(closure) { |
236 assertEquals(45, closure(10)); | 236 assertEquals(45, closure(10)); |
237 assertEquals(45, closure(10)); | 237 assertEquals(45, closure(10)); |
238 assertEquals(10, closure(50000)); | 238 assertEquals(10, closure(50000)); |
239 } | 239 } |
240 test(osr1); | 240 test(osr1); |
241 test(osr2); | 241 test(osr2); |
242 test(osr3); | 242 test(osr3); |
243 })(); | 243 })(); |
| 244 |
| 245 |
| 246 // Test out-of-bounds access on captured objects. |
| 247 (function testOOB() { |
| 248 function cons1() { |
| 249 this.x = 1; |
| 250 this.y = 2; |
| 251 this.z = 3; |
| 252 } |
| 253 function cons2() { |
| 254 this.a = 7; |
| 255 } |
| 256 function oob(constructor, branch) { |
| 257 var o = new constructor(); |
| 258 if (branch) { |
| 259 return o.a; |
| 260 } else { |
| 261 return o.z; |
| 262 } |
| 263 } |
| 264 assertEquals(3, oob(cons1, false)); |
| 265 assertEquals(3, oob(cons1, false)); |
| 266 assertEquals(7, oob(cons2, true)); |
| 267 assertEquals(7, oob(cons2, true)); |
| 268 gc(); // Clears type feedback of constructor call. |
| 269 assertEquals(7, oob(cons2, true)); |
| 270 assertEquals(7, oob(cons2, true)); |
| 271 %OptimizeFunctionOnNextCall(oob); |
| 272 assertEquals(7, oob(cons2, true)); |
| 273 })(); |
OLD | NEW |