Chromium Code Reviews| 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 collect_results(iter) { | |
| 359 var ret = []; | |
| 360 var result; | |
| 361 do { | |
| 362 result = iter.next(); | |
| 363 ret.push(result); | |
| 364 } while (!result.done); | |
| 365 return ret; | |
| 366 } | |
| 367 // We have to put a full result for the end, because the return will re-box. | |
| 368 var expected = [{value: 1}, 13, "foo", {value: 34, done: true}]; | |
| 369 | |
| 370 // Sanity check. | |
| 371 assertEquals(expected, collect_results(results(expected))); | |
| 372 assertEquals(expected, | |
| 373 collect_results((function*(){return yield* results(expected);})())); | |
|
rossberg
2013/06/13 09:53:18
Nit: spacing
| |
| 374 } | |
| 375 TestDelegatingYield(); | |
| 376 | |
| 349 function TestTryCatch(instantiate) { | 377 function TestTryCatch(instantiate) { |
| 350 function* g() { yield 1; try { yield 2; } catch (e) { yield e; } yield 3; } | 378 function* g() { yield 1; try { yield 2; } catch (e) { yield e; } yield 3; } |
| 351 function Sentinel() {} | 379 function Sentinel() {} |
| 352 | 380 |
| 353 function Test1(iter) { | 381 function Test1(iter) { |
| 354 assertIteratorResult(1, false, iter.next()); | 382 assertIteratorResult(1, false, iter.next()); |
| 355 assertIteratorResult(2, false, iter.next()); | 383 assertIteratorResult(2, false, iter.next()); |
| 356 assertIteratorResult(3, false, iter.next()); | 384 assertIteratorResult(3, false, iter.next()); |
| 357 assertIteratorResult(undefined, true, iter.next()); | 385 assertIteratorResult(undefined, true, iter.next()); |
| 358 assertThrows(function() { iter.next(); }, Error); | 386 assertThrows(function() { iter.next(); }, Error); |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 601 function TestThrowRecursion() { | 629 function TestThrowRecursion() { |
| 602 function* g() { yield iter.throw(1); } | 630 function* g() { yield iter.throw(1); } |
| 603 var iter = g(); | 631 var iter = g(); |
| 604 return iter.next(); | 632 return iter.next(); |
| 605 } | 633 } |
| 606 assertThrows(TestNextRecursion, Error); | 634 assertThrows(TestNextRecursion, Error); |
| 607 assertThrows(TestSendRecursion, Error); | 635 assertThrows(TestSendRecursion, Error); |
| 608 assertThrows(TestThrowRecursion, Error); | 636 assertThrows(TestThrowRecursion, Error); |
| 609 } | 637 } |
| 610 TestRecursion(); | 638 TestRecursion(); |
| OLD | NEW |