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 | 28 // Flags: --allow-natives-syntax |
29 | 29 |
30 function f(test, test2, a, i) { | 30 function f_store(test, test2, a, i) { |
31 var o = [0.5,1,,3]; | 31 var o = [0.5,1,,3]; |
32 var d; | 32 var d; |
33 if (test) { | 33 if (test) { |
34 d = 1.5; | 34 d = 1.5; |
35 } else { | 35 } else { |
36 d = o[i]; | 36 d = o[i]; |
37 } | 37 } |
38 if (test2) { | 38 if (test2) { |
39 d += 1; | 39 d += 1; |
40 } | 40 } |
41 a[i] = d; | 41 a[i] = d; |
42 return d; | 42 return d; |
43 } | 43 } |
44 | 44 |
45 var a = [0, 0, 0, {}]; | 45 var a1 = [0, 0, 0, {}]; |
46 f(true, false, a, 0); | 46 f_store(true, false, a1, 0); |
47 f(true, true, a, 0); | 47 f_store(true, true, a1, 0); |
48 f(false, false, a, 1); | 48 f_store(false, false, a1, 1); |
49 f(false, true, a, 1); | 49 f_store(false, true, a1, 1); |
50 %OptimizeFunctionOnNextCall(f); | 50 %OptimizeFunctionOnNextCall(f_store); |
51 f(false, false, a, 2); | 51 f_store(false, false, a1, 2); |
52 assertEquals(undefined, a[2]); | 52 assertEquals(undefined, a1[2]); |
| 53 |
| 54 function test_arg(expected) { |
| 55 return function(v) { |
| 56 assertEquals(expected, v); |
| 57 } |
| 58 } |
| 59 |
| 60 function f_call(f, test, test2, i) { |
| 61 var o = [0.5,1,,3]; |
| 62 var d; |
| 63 if (test) { |
| 64 d = 1.5; |
| 65 } else { |
| 66 d = o[i]; |
| 67 } |
| 68 if (test2) { |
| 69 d += 1; |
| 70 } |
| 71 f(d); |
| 72 return d; |
| 73 } |
| 74 |
| 75 f_call(test_arg(1.5), true, false, 0); |
| 76 f_call(test_arg(2.5), true, true, 0); |
| 77 f_call(test_arg(1), false, false, 1); |
| 78 f_call(test_arg(2), false, true, 1); |
| 79 %OptimizeFunctionOnNextCall(f_call); |
| 80 f_call(test_arg(undefined), false, false, 2); |
| 81 |
| 82 |
| 83 function f_external(test, test2, test3, a, i) { |
| 84 var o = [0.5,1,,3]; |
| 85 var d; |
| 86 if (test) { |
| 87 d = 1.5; |
| 88 } else { |
| 89 d = o[i]; |
| 90 } |
| 91 if (test2) { |
| 92 d += 1; |
| 93 } |
| 94 if (test3) { |
| 95 d = d|0; |
| 96 } |
| 97 a[d] = 1; |
| 98 return d; |
| 99 } |
| 100 |
| 101 var a2 = new Int32Array(10); |
| 102 f_external(true, false, true, a2, 0); |
| 103 f_external(true, true, true, a2, 0); |
| 104 f_external(false, false, true, a2, 1); |
| 105 f_external(false, true, true, a2, 1); |
| 106 %OptimizeFunctionOnNextCall(f_external); |
| 107 f_external(false, false, false, a2, 2); |
| 108 assertEquals(1, a2[undefined]); |
OLD | NEW |