| 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 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 closure_in_for_init(); | 140 closure_in_for_init(); |
| 141 | 141 |
| 142 | 142 |
| 143 function closure_in_for_cond() { | 143 function closure_in_for_cond() { |
| 144 let a = []; | 144 let a = []; |
| 145 for (let i = 0; a.push(function () { return i; }), i < 5; ++i) { } | 145 for (let i = 0; a.push(function () { return i; }), i < 5; ++i) { } |
| 146 for (let k = 0; k < 5; ++k) { | 146 for (let k = 0; k < 5; ++k) { |
| 147 assertEquals(k, a[k]()); | 147 assertEquals(k, a[k]()); |
| 148 } | 148 } |
| 149 } | 149 } |
| 150 closure_in_for_next(); | 150 closure_in_for_cond(); |
| 151 | 151 |
| 152 | 152 |
| 153 function closure_in_for_next() { | 153 function closure_in_for_next() { |
| 154 let a = []; | 154 let a = []; |
| 155 for (let i = 0; i < 5; a.push(function () { return i; }), ++i) { } | 155 for (let i = 0; i < 5; a.push(function () { return i; }), ++i) { } |
| 156 for (let k = 0; k < 5; ++k) { | 156 for (let k = 0; k < 5; ++k) { |
| 157 assertEquals(k + 1, a[k]()); | 157 assertEquals(k + 1, a[k]()); |
| 158 } | 158 } |
| 159 } | 159 } |
| 160 closure_in_for_next(); | 160 closure_in_for_next(); |
| 161 | 161 |
| 162 | 162 |
| 163 // In a for-in statement the iteration variable is fresh | 163 // In a for-in statement the iteration variable is fresh |
| 164 // for earch iteration. | 164 // for earch iteration. |
| 165 function closures3(x) { | 165 function closures3(x) { |
| 166 let a = []; | 166 let a = []; |
| 167 for (let p in x) { | 167 for (let p in x) { |
| 168 a.push(function () { return p; }); | 168 a.push(function () { return p; }); |
| 169 } | 169 } |
| 170 let k = 0; | 170 let k = 0; |
| 171 for (let q in x) { | 171 for (let q in x) { |
| 172 assertEquals(q, a[k]()); | 172 assertEquals(q, a[k]()); |
| 173 ++k; | 173 ++k; |
| 174 } | 174 } |
| 175 } | 175 } |
| 176 closures3({a : [0], b : 1, c : {v : 1}, get d() {}, set e(x) {}}); | 176 closures3({a : [0], b : 1, c : {v : 1}, get d() {}, set e(x) {}}); |
| OLD | NEW |