Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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: --harmony-scoping --allow-natives-syntax | 28 // Flags: --harmony-scoping --allow-natives-syntax --trace-bailout |
|
Jakob Kummerow
2011/12/05 16:40:36
I think you should remove --trace-bailout before l
| |
| 29 | 29 |
| 30 // TODO(ES6): properly activate extended mode | 30 // TODO(ES6): properly activate extended mode |
| 31 "use strict"; | 31 "use strict"; |
| 32 | 32 |
| 33 // Check that the following functions are optimizable. | |
| 34 var functions = [f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12]; | |
| 35 | |
| 36 for (var i = 0; i < functions.length; ++i) { | |
| 37 var func = functions[i]; | |
| 38 print("Testing:"); | |
| 39 print(func); | |
| 40 for (var j = 0; j < 10; ++j) { | |
| 41 func(12); | |
| 42 } | |
| 43 %OptimizeFunctionOnNextCall(func); | |
| 44 func(12); | |
| 45 assertTrue(%GetOptimizationStatus(func) != 2); | |
| 46 } | |
| 47 | |
| 48 function f1() { } | |
| 49 | |
| 50 function f2(x) { } | |
| 51 | |
| 52 function f3() { | |
| 53 let x; | |
| 54 } | |
| 55 | |
| 56 function f4() { | |
| 57 function foo() { | |
| 58 } | |
| 59 } | |
| 60 | |
| 61 function f5() { | |
| 62 let x = 1; | |
| 63 } | |
| 64 | |
| 65 function f6() { | |
| 66 const x = 1; | |
| 67 } | |
| 68 | |
| 69 function f7(x) { | |
| 70 return x; | |
| 71 } | |
| 72 | |
| 73 function f8() { | |
| 74 let x; | |
| 75 return x; | |
| 76 } | |
| 77 | |
| 78 function f9() { | |
| 79 function x() { | |
| 80 } | |
| 81 return x; | |
| 82 } | |
| 83 | |
| 84 function f10(x) { | |
| 85 x = 1; | |
| 86 } | |
| 87 | |
| 88 function f11() { | |
| 89 let x; | |
| 90 x = 1; | |
| 91 } | |
| 92 | |
| 93 function f12() { | |
| 94 function x() {}; | |
| 95 x = 1; | |
| 96 } | |
| 97 | |
| 98 | |
| 33 // Test that temporal dead zone semantics for function and block scoped | 99 // Test that temporal dead zone semantics for function and block scoped |
| 34 // ket bindings are handled by the optimizing compiler. | 100 // let bindings are handled by the optimizing compiler. |
| 101 | |
| 102 function TestFunctionLocal(s) { | |
| 103 'use strict'; | |
| 104 var func = eval("(function baz(){" + s + "; })"); | |
| 105 print("Testing:"); | |
| 106 print(func); | |
| 107 for (var i = 0; i < 5; ++i) { | |
| 108 try { | |
| 109 func(); | |
| 110 assertUnreachable(); | |
| 111 } catch (e) { | |
| 112 assertInstanceof(e, ReferenceError); | |
| 113 } | |
| 114 } | |
| 115 %OptimizeFunctionOnNextCall(func); | |
| 116 try { | |
| 117 func(); | |
| 118 assertUnreachable(); | |
| 119 } catch (e) { | |
| 120 assertInstanceof(e, ReferenceError); | |
| 121 } | |
| 122 } | |
| 123 | |
| 124 function TestAll(s) { | |
| 125 TestFunctionLocal(s); | |
| 126 } | |
| 127 | |
| 128 // Use before initialization in declaration statement. | |
| 129 TestAll('let x = x + 1'); | |
| 130 TestAll('let x = x += 1'); | |
| 131 TestAll('let x = x++'); | |
| 132 TestAll('let x = ++x'); | |
| 133 TestAll('const x = x + 1'); | |
| 134 | |
| 135 // Use before initialization in prior statement. | |
| 136 TestAll('x + 1; let x;'); | |
| 137 TestAll('x = 1; let x;'); | |
| 138 TestAll('x += 1; let x;'); | |
| 139 TestAll('++x; let x;'); | |
| 140 TestAll('x++; let x;'); | |
| 141 TestAll('let y = x; const x = 1;'); | |
| 142 | |
| 35 | 143 |
| 36 function f(x, b) { | 144 function f(x, b) { |
| 37 let y = (b ? y : x) + 42; | 145 let y = (b ? y : x) + 42; |
| 38 return y; | 146 return y; |
| 39 } | 147 } |
| 40 | 148 |
| 41 function g(x, b) { | 149 function g(x, b) { |
| 42 { | 150 { |
| 43 let y = (b ? y : x) + 42; | 151 let y = (b ? y : x) + 42; |
| 44 return y; | 152 return y; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 57 f(42, true); | 165 f(42, true); |
| 58 } catch (e) { | 166 } catch (e) { |
| 59 assertInstanceof(e, ReferenceError); | 167 assertInstanceof(e, ReferenceError); |
| 60 } | 168 } |
| 61 | 169 |
| 62 try { | 170 try { |
| 63 g(42, true); | 171 g(42, true); |
| 64 } catch (e) { | 172 } catch (e) { |
| 65 assertInstanceof(e, ReferenceError); | 173 assertInstanceof(e, ReferenceError); |
| 66 } | 174 } |
| OLD | NEW |