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 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 var p2 = {then: function(onResolve, onReject) { onResolve(p1) }} | 384 var p2 = {then: function(onResolve, onReject) { onResolve(p1) }} |
385 var p3 = Promise.accept(p2) | 385 var p3 = Promise.accept(p2) |
386 p3.then( | 386 p3.then( |
387 assertUnreachable, | 387 assertUnreachable, |
388 function(x) { assertAsync(x === 5, "rejected/thenable/then") } | 388 function(x) { assertAsync(x === 5, "rejected/thenable/then") } |
389 ) | 389 ) |
390 assertAsyncRan() | 390 assertAsyncRan() |
391 })(); | 391 })(); |
392 | 392 |
393 (function() { | 393 (function() { |
394 var p1 = Promise.accept(5) | |
395 var p2 = Promise.accept(p1) | |
396 var called = false | |
397 p2.then = function(onResolve, onReject) { | |
398 called = true; | |
399 return call(Promise.prototype.then, p2, onResolve, onReject) | |
400 } | |
401 var p3 = Promise.accept(p2) | |
402 p3.chain( | |
403 function(x) { | |
404 assertAsync(x === p2 && !called, "resolved/thenable-promise/chain") | |
405 }, | |
406 assertUnreachable) | |
407 assertAsyncRan() | |
408 })(); | |
409 | |
410 (function() { | |
411 var p1 = Promise.accept(5) | |
412 var p2 = Promise.accept(p1) | |
413 var called = false | |
414 p2.then = function(onResolve, onReject) { | |
415 called = true | |
416 return call(Promise.prototype.then, p2, onResolve, onReject) | |
417 } | |
418 var p3 = Promise.accept(p2) | |
419 p3.then( | |
420 function(x) { | |
421 assertAsync(x === 5 && called, "resolved/thenable-promise/then") | |
422 }, | |
423 assertUnreachable) | |
424 assertAsyncRan() | |
425 })(); | |
426 | |
427 (function() { | |
428 var p1 = Promise.accept(5) | |
429 var called = false | |
430 var p3 = p1.then(function(x) { | |
431 var p2 = Promise.accept(5) | |
432 p2.then = function(onResolve, onReject) { | |
433 called = true | |
434 throw 25 | |
435 } | |
436 return p2 | |
437 }); | |
438 p3.then( | |
439 assertUnreachable, | |
440 function(x) { | |
441 assertAsync(called && x === 25, "thenable-promise/then-call-throw") | |
442 }) | |
443 assertAsyncRan() | |
444 })(); | |
445 | |
446 (function() { | |
447 var deferred = Promise.defer() | 394 var deferred = Promise.defer() |
448 var p1 = deferred.promise | 395 var p1 = deferred.promise |
449 var p2 = Promise.accept(p1) | 396 var p2 = Promise.accept(p1) |
450 var p3 = Promise.accept(p2) | 397 var p3 = Promise.accept(p2) |
451 p3.chain( | 398 p3.chain( |
452 function(x) { assertAsync(x === p2, "chain/resolve") }, | 399 function(x) { assertAsync(x === p2, "chain/resolve") }, |
453 assertUnreachable | 400 assertUnreachable |
454 ) | 401 ) |
455 deferred.resolve(5) | 402 deferred.resolve(5) |
456 assertAsyncRan() | 403 assertAsyncRan() |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 var p1 = deferred.promise | 510 var p1 = deferred.promise |
564 var p2 = {then: function(onResolve, onReject) { onResolve(p1) }} | 511 var p2 = {then: function(onResolve, onReject) { onResolve(p1) }} |
565 var p3 = Promise.accept(p2) | 512 var p3 = Promise.accept(p2) |
566 p3.then( | 513 p3.then( |
567 assertUnreachable, | 514 assertUnreachable, |
568 function(x) { assertAsync(x === 5, "then/reject/thenable") } | 515 function(x) { assertAsync(x === 5, "then/reject/thenable") } |
569 ) | 516 ) |
570 deferred.reject(5) | 517 deferred.reject(5) |
571 assertAsyncRan() | 518 assertAsyncRan() |
572 })(); | 519 })(); |
573 | |
574 (function() { | |
575 var deferred = Promise.defer() | |
576 var deferred2 = Promise.defer() | |
577 var deferred3 = Promise.defer() | |
578 | |
579 var p1 = deferred.promise | |
580 var p2 = deferred2.promise | |
581 var p3 = deferred3.promise | |
582 | |
583 var called = false | |
584 p2.then = function(onResolve, onReject) { | |
585 called = true | |
586 return call(Promise.prototype.then, p2, onResolve, onReject) | |
587 } | |
588 p3.chain( | |
589 function(x) { assertAsync(x === p2 && !called, | |
590 "chain/resolve/thenable-promise") }, | |
591 assertUnreachable | |
592 ) | |
593 deferred3.resolve(p2) | |
594 deferred2.resolve(p1) | |
595 deferred.resolve(5) | |
596 assertAsyncRan() | |
597 })(); | |
598 | |
599 (function() { | |
600 var deferred = Promise.defer() | |
601 var deferred2 = Promise.defer() | |
602 var deferred3 = Promise.defer() | |
603 | |
604 var p1 = deferred.promise | |
605 var p2 = deferred2.promise | |
606 var p3 = deferred3.promise | |
607 | |
608 var called = false | |
609 p2.then = function(onResolve, onReject) { | |
610 called = true | |
611 return call(Promise.prototype.then, p2, onResolve, onReject) | |
612 } | |
613 p3.then( | |
614 function(x) { assertAsync(x === 5 && called, | |
615 "then/resolve/thenable-promise") }, | |
616 assertUnreachable | |
617 ) | |
618 deferred3.resolve(p2) | |
619 deferred2.resolve(p1) | |
620 deferred.resolve(5) | |
621 assertAsyncRan() | |
622 })(); | |
623 | |
624 (function() { | |
625 var deferred = Promise.defer() | |
626 var deferred2 = Promise.defer() | |
627 var deferred3 = Promise.defer() | |
628 | |
629 var p1 = deferred.promise | |
630 var p2 = deferred2.promise | |
631 var p3 = deferred3.promise | |
632 | |
633 var called = false | |
634 p2.then = function(onResolve, onReject) { | |
635 called = true | |
636 return call(Promise.prototype.then, p2, onResolve, onReject) | |
637 } | |
638 p3.chain( | |
639 function(x) { assertAsync(x === p2 && !called, | |
640 "chain/reject/thenable-promise") }, | |
641 assertUnreachable | |
642 ) | |
643 deferred3.resolve(p2) | |
644 deferred2.resolve(p1) | |
645 deferred.reject(5) | |
646 assertAsyncRan() | |
647 })(); | |
648 | |
649 (function() { | |
650 var deferred = Promise.defer() | |
651 var deferred2 = Promise.defer() | |
652 var deferred3 = Promise.defer() | |
653 | |
654 var p1 = deferred.promise | |
655 var p2 = deferred2.promise | |
656 var p3 = deferred3.promise | |
657 | |
658 var called = false | |
659 p2.then = function(onResolve, onReject) { | |
660 called = true | |
661 return call(Promise.prototype.then, p2, onResolve, onReject) | |
662 } | |
663 p3.then( | |
664 assertUnreachable, | |
665 function(x) { assertAsync(x === 5 && called, | |
666 "then/reject/thenable-promise") } | |
667 ) | |
668 deferred3.resolve(p2) | |
669 deferred2.resolve(p1) | |
670 deferred.reject(5) | |
671 assertAsyncRan() | |
672 })(); | |
673 | 520 |
674 (function() { | 521 (function() { |
675 var p1 = Promise.accept(5) | 522 var p1 = Promise.accept(5) |
676 var p2 = Promise.accept(p1) | 523 var p2 = Promise.accept(p1) |
677 var deferred = Promise.defer() | 524 var deferred = Promise.defer() |
678 var p3 = deferred.promise | 525 var p3 = deferred.promise |
679 p3.chain( | 526 p3.chain( |
680 function(x) { assertAsync(x === p2, "chain/resolve2") }, | 527 function(x) { assertAsync(x === p2, "chain/resolve2") }, |
681 assertUnreachable | 528 assertUnreachable |
682 ) | 529 ) |
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1181 Promise.all([11, Promise.accept(12), 13, MyPromise.accept(14), 15, 16]) | 1028 Promise.all([11, Promise.accept(12), 13, MyPromise.accept(14), 15, 16]) |
1182 assertTrue(log === "nx14n", "subclass/all/arg") | 1029 assertTrue(log === "nx14n", "subclass/all/arg") |
1183 | 1030 |
1184 log = "" | 1031 log = "" |
1185 MyPromise.all([21, Promise.accept(22), 23, MyPromise.accept(24), 25, 26]) | 1032 MyPromise.all([21, Promise.accept(22), 23, MyPromise.accept(24), 25, 26]) |
1186 assertTrue(log === "nx24nnx21nnx23nnnx25nnx26n", "subclass/all/self") | 1033 assertTrue(log === "nx24nnx21nnx23nnnx25nnx26n", "subclass/all/self") |
1187 })(); | 1034 })(); |
1188 | 1035 |
1189 | 1036 |
1190 assertAsyncDone() | 1037 assertAsyncDone() |
OLD | NEW |