OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --harmony-iterator-close | 5 // Flags: --harmony-iterator-close |
6 | 6 |
7 | 7 |
8 function* g() { yield 42; return 88 }; | 8 function* g() { yield 42; return 88 }; |
9 | 9 |
10 | 10 |
(...skipping 1280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1291 for (let x of g1()) { | 1291 for (let x of g1()) { |
1292 try { | 1292 try { |
1293 for (let y of g2()) { | 1293 for (let y of g2()) { |
1294 } | 1294 } |
1295 } catch (_) {} | 1295 } catch (_) {} |
1296 if (x == 2) break; | 1296 if (x == 2) break; |
1297 } | 1297 } |
1298 }, 5); | 1298 }, 5); |
1299 assertEquals([1], log); | 1299 assertEquals([1], log); |
1300 } | 1300 } |
| 1301 |
| 1302 |
| 1303 // yield*, argument's return method is "undefined". |
| 1304 function TestYieldStarWithoutReturn(get_iterable) { |
| 1305 assertTrue(get_iterable().return == undefined); |
| 1306 |
| 1307 function* g() { yield* get_iterable() } |
| 1308 |
| 1309 { |
| 1310 let gen = g(); |
| 1311 assertEquals({value: 1, done: false}, gen.next()); |
| 1312 assertEquals({value: undefined, done: true}, gen.return()); |
| 1313 } |
| 1314 |
| 1315 assertEquals(42, (() => { |
| 1316 for (let x of g()) break; |
| 1317 return 42; |
| 1318 })()); |
| 1319 |
| 1320 assertEquals(42, (() => { |
| 1321 for (let x of g()) return 42; |
| 1322 })()); |
| 1323 |
| 1324 assertThrowsEquals(() => { |
| 1325 for (let x of g()) throw 42; |
| 1326 }, 42); |
| 1327 } |
| 1328 { |
| 1329 let get_iterable1 = () => [1, 2]; |
| 1330 let get_iterable2 = function*() { yield 1; yield 2 }; |
| 1331 get_iterable2.prototype.return = null; |
| 1332 TestYieldStarWithoutReturn(get_iterable1); |
| 1333 TestYieldStarWithoutReturn(get_iterable2); |
| 1334 } |
| 1335 |
| 1336 |
| 1337 // yield*, argument's return method is defined. |
| 1338 { |
| 1339 let get_iterable = function*() { yield 1; yield 2 }; |
| 1340 const obj = {}; |
| 1341 get_iterable.prototype.return = (...args) => obj; |
| 1342 |
| 1343 function* g() { yield* get_iterable() } |
| 1344 |
| 1345 { |
| 1346 let gen = g(); |
| 1347 assertEquals({value: 1, done: false}, gen.next()); |
| 1348 assertSame(obj, gen.return()); |
| 1349 assertSame(obj, gen.return()); |
| 1350 assertSame(obj, gen.return()); |
| 1351 assertEquals({value: 2, done: false}, gen.next()); |
| 1352 assertSame(obj, gen.return()); |
| 1353 assertSame(obj, gen.return()); |
| 1354 assertSame(obj, gen.return()); |
| 1355 assertEquals({value: undefined, done: true}, gen.next()); |
| 1356 assertEquals({value: undefined, done: true}, gen.return()); |
| 1357 assertEquals({value: undefined, done: true}, gen.return()); |
| 1358 } |
| 1359 |
| 1360 assertEquals(42, (() => { |
| 1361 for (let x of g()) break; |
| 1362 return 42; |
| 1363 })()); |
| 1364 |
| 1365 assertEquals(42, (() => { |
| 1366 for (let x of g()) return 42; |
| 1367 })()); |
| 1368 |
| 1369 assertThrowsEquals(() => { |
| 1370 for (let x of g()) throw 42; |
| 1371 }, 42); |
| 1372 } |
OLD | NEW |