| 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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 throw (yield (1 + (yield 2) + 3)) | 317 throw (yield (1 + (yield 2) + 3)) |
| 318 } catch (e) { | 318 } catch (e) { |
| 319 if (typeof e == 'object') throw e; | 319 if (typeof e == 'object') throw e; |
| 320 return e + (yield (4 + (yield 5) + 6)); | 320 return e + (yield (4 + (yield 5) + 6)); |
| 321 } | 321 } |
| 322 }, | 322 }, |
| 323 [2, NaN, 5, NaN, NaN], | 323 [2, NaN, 5, NaN, NaN], |
| 324 "foo", | 324 "foo", |
| 325 [2, "1foo3", 5, "4foo6", "foofoo"]); | 325 [2, "1foo3", 5, "4foo6", "foofoo"]); |
| 326 | 326 |
| 327 // Generator function instances. |
| 328 TestGenerator(GeneratorFunction(), |
| 329 [undefined], |
| 330 "foo", |
| 331 [undefined]); |
| 332 |
| 333 TestGenerator(new GeneratorFunction(), |
| 334 [undefined], |
| 335 "foo", |
| 336 [undefined]); |
| 337 |
| 338 TestGenerator(GeneratorFunction('yield 1;'), |
| 339 [1, undefined], |
| 340 "foo", |
| 341 [1, undefined]); |
| 342 |
| 343 TestGenerator( |
| 344 function() { return GeneratorFunction('x', 'y', 'yield x + y;')(1, 2) }, |
| 345 [3, undefined], |
| 346 "foo", |
| 347 [3, undefined]); |
| 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 |
| 327 function TestTryCatch(instantiate) { | 379 function TestTryCatch(instantiate) { |
| 328 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; } |
| 329 function Sentinel() {} | 381 function Sentinel() {} |
| 330 | 382 |
| 331 function Test1(iter) { | 383 function Test1(iter) { |
| 332 assertIteratorResult(1, false, iter.next()); | 384 assertIteratorResult(1, false, iter.next()); |
| 333 assertIteratorResult(2, false, iter.next()); | 385 assertIteratorResult(2, false, iter.next()); |
| 334 assertIteratorResult(3, false, iter.next()); | 386 assertIteratorResult(3, false, iter.next()); |
| 335 assertIteratorResult(undefined, true, iter.next()); | 387 assertIteratorResult(undefined, true, iter.next()); |
| 336 assertThrows(function() { iter.next(); }, Error); | 388 assertThrows(function() { iter.next(); }, Error); |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 function TestThrowRecursion() { | 631 function TestThrowRecursion() { |
| 580 function* g() { yield iter.throw(1); } | 632 function* g() { yield iter.throw(1); } |
| 581 var iter = g(); | 633 var iter = g(); |
| 582 return iter.next(); | 634 return iter.next(); |
| 583 } | 635 } |
| 584 assertThrows(TestNextRecursion, Error); | 636 assertThrows(TestNextRecursion, Error); |
| 585 assertThrows(TestSendRecursion, Error); | 637 assertThrows(TestSendRecursion, Error); |
| 586 assertThrows(TestThrowRecursion, Error); | 638 assertThrows(TestThrowRecursion, Error); |
| 587 } | 639 } |
| 588 TestRecursion(); | 640 TestRecursion(); |
| OLD | NEW |