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 |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 [1, undefined], | 339 [1, undefined], |
340 "foo", | 340 "foo", |
341 [1, undefined]); | 341 [1, undefined]); |
342 | 342 |
343 TestGenerator( | 343 TestGenerator( |
344 function() { return GeneratorFunction('x', 'y', 'yield x + y;')(1, 2) }, | 344 function() { return GeneratorFunction('x', 'y', 'yield x + y;')(1, 2) }, |
345 [3, undefined], | 345 [3, undefined], |
346 "foo", | 346 "foo", |
347 [3, undefined]); | 347 [3, undefined]); |
348 | 348 |
| 349 // Test that yield* re-yields received results without re-boxing. |
| 350 function TestDelegatingYield() { |
| 351 function results(results) { |
| 352 var i = 0; |
| 353 function next() { |
| 354 return results[i++]; |
| 355 } |
| 356 return { next: next } |
| 357 } |
| 358 function* yield_results(expected) { |
| 359 return yield* results(expected); |
| 360 } |
| 361 function collect_results(iter) { |
| 362 var ret = []; |
| 363 var result; |
| 364 do { |
| 365 result = iter.next(); |
| 366 ret.push(result); |
| 367 } while (!result.done); |
| 368 return ret; |
| 369 } |
| 370 // We have to put a full result for the end, because the return will re-box. |
| 371 var expected = [{value: 1}, 13, "foo", {value: 34, done: true}]; |
| 372 |
| 373 // Sanity check. |
| 374 assertEquals(expected, collect_results(results(expected))); |
| 375 assertEquals(expected, collect_results(yield_results(expected))); |
| 376 } |
| 377 TestDelegatingYield(); |
| 378 |
349 function TestTryCatch(instantiate) { | 379 function TestTryCatch(instantiate) { |
350 function* g() { yield 1; try { yield 2; } catch (e) { yield e; } yield 3; } | 380 function* g() { yield 1; try { yield 2; } catch (e) { yield e; } yield 3; } |
351 function Sentinel() {} | 381 function Sentinel() {} |
352 | 382 |
353 function Test1(iter) { | 383 function Test1(iter) { |
354 assertIteratorResult(1, false, iter.next()); | 384 assertIteratorResult(1, false, iter.next()); |
355 assertIteratorResult(2, false, iter.next()); | 385 assertIteratorResult(2, false, iter.next()); |
356 assertIteratorResult(3, false, iter.next()); | 386 assertIteratorResult(3, false, iter.next()); |
357 assertIteratorResult(undefined, true, iter.next()); | 387 assertIteratorResult(undefined, true, iter.next()); |
358 assertThrows(function() { iter.next(); }, Error); | 388 assertThrows(function() { iter.next(); }, Error); |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 function TestThrowRecursion() { | 631 function TestThrowRecursion() { |
602 function* g() { yield iter.throw(1); } | 632 function* g() { yield iter.throw(1); } |
603 var iter = g(); | 633 var iter = g(); |
604 return iter.next(); | 634 return iter.next(); |
605 } | 635 } |
606 assertThrows(TestNextRecursion, Error); | 636 assertThrows(TestNextRecursion, Error); |
607 assertThrows(TestSendRecursion, Error); | 637 assertThrows(TestSendRecursion, Error); |
608 assertThrows(TestThrowRecursion, Error); | 638 assertThrows(TestThrowRecursion, Error); |
609 } | 639 } |
610 TestRecursion(); | 640 TestRecursion(); |
OLD | NEW |