Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: test/mjsunit/es6/promises.js

Issue 1488783002: Clean up promises and fix an edge case bug (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Minor code cleanup; disable some soon-to-be-obsolete mjsunit tests Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/js/promise.js ('k') | test/mjsunit/mjsunit.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 assertUnreachable, 186 assertUnreachable,
187 function(r) { assertAsync(r === 6, "rejected/then-nohandler-null") } 187 function(r) { assertAsync(r === 6, "rejected/then-nohandler-null") }
188 ) 188 )
189 assertAsyncRan() 189 assertAsyncRan()
190 })(); 190 })();
191 191
192 (function() { 192 (function() {
193 var p1 = Promise.accept(5) 193 var p1 = Promise.accept(5)
194 var p2 = Promise.accept(p1) 194 var p2 = Promise.accept(p1)
195 var p3 = Promise.accept(p2) 195 var p3 = Promise.accept(p2)
196 // Note: Chain now has then-style semantics, here and in future tests.
196 p3.chain( 197 p3.chain(
197 function(x) { assertAsync(x === p2, "resolved/chain") }, 198 function(x) { assertAsync(x === 5, "resolved/chain") },
198 assertUnreachable 199 assertUnreachable
199 ) 200 )
200 assertAsyncRan() 201 assertAsyncRan()
201 })(); 202 })();
202 203
203 (function() { 204 (function() {
204 var p1 = Promise.accept(5) 205 var p1 = Promise.accept(5)
205 var p2 = Promise.accept(p1) 206 var p2 = Promise.accept(p1)
206 var p3 = Promise.accept(p2) 207 var p3 = Promise.accept(p2)
207 p3.then( 208 p3.then(
208 function(x) { assertAsync(x === 5, "resolved/then") }, 209 function(x) { assertAsync(x === 5, "resolved/then") },
209 assertUnreachable 210 assertUnreachable
210 ) 211 )
211 assertAsyncRan() 212 assertAsyncRan()
212 })(); 213 })();
213 214
214 (function() { 215 (function() {
215 var p1 = Promise.reject(5) 216 var p1 = Promise.reject(5)
216 var p2 = Promise.accept(p1) 217 var p2 = Promise.accept(p1)
217 var p3 = Promise.accept(p2) 218 var p3 = Promise.accept(p2)
218 p3.chain( 219 p3.chain(
219 function(x) { assertAsync(x === p2, "rejected/chain") }, 220 assertUnreachable,
220 assertUnreachable 221 function(x) { assertAsync(x === 5, "rejected/chain") }
221 ) 222 )
222 assertAsyncRan() 223 assertAsyncRan()
223 })(); 224 })();
224 225
225 (function() { 226 (function() {
226 var p1 = Promise.reject(5) 227 var p1 = Promise.reject(5)
227 var p2 = Promise.accept(p1) 228 var p2 = Promise.accept(p1)
228 var p3 = Promise.accept(p2) 229 var p3 = Promise.accept(p2)
229 p3.then( 230 p3.then(
230 assertUnreachable, 231 assertUnreachable,
231 function(x) { assertAsync(x === 5, "rejected/then") } 232 function(x) { assertAsync(x === 5, "rejected/then") }
232 ) 233 )
233 assertAsyncRan() 234 assertAsyncRan()
234 })(); 235 })();
235 236
236 /* TODO(caitp): remove tests once PromiseChain is removed, per bug 3237
237 (function() { 237 (function() {
238 var p1 = Promise.accept(5) 238 var p1 = Promise.accept(5)
239 var p2 = Promise.accept(p1) 239 var p2 = Promise.accept(p1)
240 var p3 = Promise.accept(p2) 240 var p3 = Promise.accept(p2)
241 p3.chain(function(x) { return x }, assertUnreachable).chain( 241 p3.chain(function(x) { return x }, assertUnreachable).chain(
242 function(x) { assertAsync(x === p1, "resolved/chain/chain") }, 242 function(x) { assertAsync(x === 5, "resolved/chain/chain") },
243 assertUnreachable 243 assertUnreachable
244 ) 244 )
245 assertAsyncRan() 245 assertAsyncRan()
246 })();*/ 246 })();
247 247
248 (function() { 248 (function() {
249 var p1 = Promise.accept(5) 249 var p1 = Promise.accept(5)
250 var p2 = Promise.accept(p1) 250 var p2 = Promise.accept(p1)
251 var p3 = Promise.accept(p2) 251 var p3 = Promise.accept(p2)
252 p3.chain(function(x) { return x }, assertUnreachable).then( 252 p3.chain(function(x) { return x }, assertUnreachable).then(
253 function(x) { assertAsync(x === 5, "resolved/chain/then") }, 253 function(x) { assertAsync(x === 5, "resolved/chain/then") },
254 assertUnreachable 254 assertUnreachable
255 ) 255 )
256 assertAsyncRan() 256 assertAsyncRan()
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 function(x) { assertAsync(x === 6, "resolved/then-throw/then") } 364 function(x) { assertAsync(x === 6, "resolved/then-throw/then") }
365 ) 365 )
366 assertAsyncRan() 366 assertAsyncRan()
367 })(); 367 })();
368 368
369 (function() { 369 (function() {
370 var p1 = Promise.accept(5) 370 var p1 = Promise.accept(5)
371 var p2 = {then: function(onResolve, onReject) { onResolve(p1) }} 371 var p2 = {then: function(onResolve, onReject) { onResolve(p1) }}
372 var p3 = Promise.accept(p2) 372 var p3 = Promise.accept(p2)
373 p3.chain( 373 p3.chain(
374 function(x) { assertAsync(x === p2, "resolved/thenable/chain") }, 374 function(x) { assertAsync(x === 5, "resolved/thenable/chain") },
375 assertUnreachable 375 assertUnreachable
376 ) 376 )
377 assertAsyncRan() 377 assertAsyncRan()
378 })(); 378 })();
379 379
380 (function() { 380 (function() {
381 var p1 = Promise.accept(5) 381 var p1 = Promise.accept(5)
382 var p2 = {then: function(onResolve, onReject) { onResolve(p1) }} 382 var p2 = {then: function(onResolve, onReject) { onResolve(p1) }}
383 var p3 = Promise.accept(p2) 383 var p3 = Promise.accept(p2)
384 p3.then( 384 p3.then(
385 function(x) { assertAsync(x === 5, "resolved/thenable/then") }, 385 function(x) { assertAsync(x === 5, "resolved/thenable/then") },
386 assertUnreachable 386 assertUnreachable
387 ) 387 )
388 assertAsyncRan() 388 assertAsyncRan()
389 })(); 389 })();
390 390
391 (function() { 391 (function() {
392 var p1 = Promise.reject(5) 392 var p1 = Promise.reject(5)
393 var p2 = {then: function(onResolve, onReject) { onResolve(p1) }} 393 var p2 = {then: function(onResolve, onReject) { onResolve(p1) }}
394 var p3 = Promise.accept(p2) 394 var p3 = Promise.accept(p2)
395 p3.chain( 395 p3.chain(
396 function(x) { assertAsync(x === p2, "rejected/thenable/chain") }, 396 assertUnreachable,
397 assertUnreachable 397 function(x) { assertAsync(x === 5, "rejected/thenable/chain") }
398 ) 398 )
399 assertAsyncRan() 399 assertAsyncRan()
400 })(); 400 })();
401 401
402 (function() { 402 (function() {
403 var p1 = Promise.reject(5) 403 var p1 = Promise.reject(5)
404 var p2 = {then: function(onResolve, onReject) { onResolve(p1) }} 404 var p2 = {then: function(onResolve, onReject) { onResolve(p1) }}
405 var p3 = Promise.accept(p2) 405 var p3 = Promise.accept(p2)
406 p3.then( 406 p3.then(
407 assertUnreachable, 407 assertUnreachable,
408 function(x) { assertAsync(x === 5, "rejected/thenable/then") } 408 function(x) { assertAsync(x === 5, "rejected/thenable/then") }
409 ) 409 )
410 assertAsyncRan() 410 assertAsyncRan()
411 })(); 411 })();
412 412
413 (function() { 413 (function() {
414 var deferred = Promise.defer() 414 var deferred = Promise.defer()
415 var p1 = deferred.promise 415 var p1 = deferred.promise
416 var p2 = Promise.accept(p1) 416 var p2 = Promise.accept(p1)
417 var p3 = Promise.accept(p2) 417 var p3 = Promise.accept(p2)
418 p3.chain( 418 p3.chain(
419 function(x) { assertAsync(x === p2, "chain/resolve") }, 419 function(x) { assertAsync(x === 5, "chain/resolve") },
420 assertUnreachable 420 assertUnreachable
421 ) 421 )
422 deferred.resolve(5) 422 deferred.resolve(5)
423 assertAsyncRan() 423 assertAsyncRan()
424 })(); 424 })();
425 425
426 (function() { 426 (function() {
427 var deferred = Promise.defer() 427 var deferred = Promise.defer()
428 var p1 = deferred.promise 428 var p1 = deferred.promise
429 var p2 = Promise.accept(p1) 429 var p2 = Promise.resolve(p1)
430 var p3 = Promise.accept(p2) 430 var p3 = Promise.resolve(p2)
431 p3.then( 431 p3.then(
432 function(x) { assertAsync(x === 5, "then/resolve") }, 432 function(x) { assertAsync(x === 5, "then/resolve") },
433 assertUnreachable 433 assertUnreachable
434 ) 434 )
435 deferred.resolve(5) 435 deferred.resolve(5)
436 assertAsyncRan() 436 assertAsyncRan()
437 })(); 437 })();
438 438
439 (function() { 439 (function() {
440 var deferred = Promise.defer() 440 var deferred = Promise.defer()
441 var p1 = deferred.promise 441 var p1 = deferred.promise
442 var p2 = Promise.accept(p1) 442 var p2 = Promise.accept(p1)
443 var p3 = Promise.accept(p2) 443 var p3 = Promise.accept(p2)
444 p3.chain( 444 p3.chain(
445 function(x) { assertAsync(x === p2, "chain/reject") }, 445 assertUnreachable,
446 assertUnreachable 446 function(x) { assertAsync(x === 5, "chain/reject") }
447 ) 447 )
448 deferred.reject(5) 448 deferred.reject(5)
449 assertAsyncRan() 449 assertAsyncRan()
450 })(); 450 })();
451 451
452 (function() { 452 (function() {
453 var deferred = Promise.defer() 453 var deferred = Promise.defer()
454 var p1 = deferred.promise 454 var p1 = deferred.promise
455 var p2 = Promise.accept(p1) 455 var p2 = Promise.accept(p1)
456 var p3 = Promise.accept(p2) 456 var p3 = Promise.accept(p2)
(...skipping 28 matching lines...) Expand all
485 deferred.reject(5) 485 deferred.reject(5)
486 assertAsyncRan() 486 assertAsyncRan()
487 })(); 487 })();
488 488
489 (function() { 489 (function() {
490 var deferred = Promise.defer() 490 var deferred = Promise.defer()
491 var p1 = deferred.promise 491 var p1 = deferred.promise
492 var p2 = {then: function(onResolve, onReject) { onResolve(p1) }} 492 var p2 = {then: function(onResolve, onReject) { onResolve(p1) }}
493 var p3 = Promise.accept(p2) 493 var p3 = Promise.accept(p2)
494 p3.chain( 494 p3.chain(
495 function(x) { assertAsync(x === p2, "chain/resolve/thenable") }, 495 function(x) { assertAsync(x === 5, "chain/resolve/thenable") },
496 assertUnreachable 496 assertUnreachable
497 ) 497 )
498 deferred.resolve(5) 498 deferred.resolve(5)
499 assertAsyncRan() 499 assertAsyncRan()
500 })(); 500 })();
501 501
502 (function() { 502 (function() {
503 var deferred = Promise.defer() 503 var deferred = Promise.defer()
504 var p1 = deferred.promise 504 var p1 = deferred.promise
505 var p2 = {then: function(onResolve, onReject) { onResolve(p1) }} 505 var p2 = {then: function(onResolve, onReject) { onResolve(p1) }}
506 var p3 = Promise.accept(p2) 506 var p3 = Promise.accept(p2)
507 p3.then( 507 p3.then(
508 function(x) { assertAsync(x === 5, "then/resolve/thenable") }, 508 function(x) { assertAsync(x === 5, "then/resolve/thenable") },
509 assertUnreachable 509 assertUnreachable
510 ) 510 )
511 deferred.resolve(5) 511 deferred.resolve(5)
512 assertAsyncRan() 512 assertAsyncRan()
513 })(); 513 })();
514 514
515 (function() { 515 (function() {
516 var deferred = Promise.defer() 516 var deferred = Promise.defer()
517 var p1 = deferred.promise 517 var p1 = deferred.promise
518 var p2 = {then: function(onResolve, onReject) { onResolve(p1) }} 518 var p2 = {then: function(onResolve, onReject) { onResolve(p1) }}
519 var p3 = Promise.accept(p2) 519 var p3 = Promise.accept(p2)
520 p3.chain( 520 p3.chain(
521 function(x) { assertAsync(x === p2, "chain/reject/thenable") }, 521 assertUnreachable,
522 assertUnreachable 522 function(x) { assertAsync(x === 5, "chain/reject/thenable") }
523 ) 523 )
524 deferred.reject(5) 524 deferred.reject(5)
525 assertAsyncRan() 525 assertAsyncRan()
526 })(); 526 })();
527 527
528 (function() { 528 (function() {
529 var deferred = Promise.defer() 529 var deferred = Promise.defer()
530 var p1 = deferred.promise 530 var p1 = deferred.promise
531 var p2 = {then: function(onResolve, onReject) { onResolve(p1) }} 531 var p2 = {then: function(onResolve, onReject) { onResolve(p1) }}
532 var p3 = Promise.accept(p2) 532 var p3 = Promise.accept(p2)
533 p3.then( 533 p3.then(
534 assertUnreachable, 534 assertUnreachable,
535 function(x) { assertAsync(x === 5, "then/reject/thenable") } 535 function(x) { assertAsync(x === 5, "then/reject/thenable") }
536 ) 536 )
537 deferred.reject(5) 537 deferred.reject(5)
538 assertAsyncRan() 538 assertAsyncRan()
539 })(); 539 })();
540 540
541 /* TODO(caitp): remove tests once PromiseChain is removed, per bug v8:3237
542 (function() { 541 (function() {
543 var p1 = Promise.accept(5) 542 var p1 = Promise.accept(5)
544 var p2 = Promise.accept(p1) 543 var p2 = Promise.accept(p1)
545 var deferred = Promise.defer() 544 var deferred = Promise.defer()
546 var p3 = deferred.promise 545 var p3 = deferred.promise
547 p3.chain( 546 p3.chain(
548 function(x) { assertAsync(x === p2, "chain/resolve2") }, 547 function(x) { assertAsync(x === 5, "chain/resolve2") },
549 assertUnreachable 548 assertUnreachable
550 ) 549 )
551 deferred.resolve(p2) 550 deferred.resolve(p2)
552 assertAsyncRan() 551 assertAsyncRan()
553 })(); */ 552 })();
554 553
555 (function() { 554 (function() {
556 var p1 = Promise.accept(5) 555 var p1 = Promise.accept(5)
557 var p2 = Promise.accept(p1) 556 var p2 = Promise.accept(p1)
558 var deferred = Promise.defer() 557 var deferred = Promise.defer()
559 var p3 = deferred.promise 558 var p3 = deferred.promise
560 p3.then( 559 p3.then(
561 function(x) { assertAsync(x === 5, "then/resolve2") }, 560 function(x) { assertAsync(x === 5, "then/resolve2") },
562 assertUnreachable 561 assertUnreachable
563 ) 562 )
(...skipping 20 matching lines...) Expand all
584 var deferred = Promise.defer() 583 var deferred = Promise.defer()
585 var p3 = deferred.promise 584 var p3 = deferred.promise
586 p3.then( 585 p3.then(
587 assertUnreachable, 586 assertUnreachable,
588 function(x) { assertAsync(x === 5, "then/reject2") } 587 function(x) { assertAsync(x === 5, "then/reject2") }
589 ) 588 )
590 deferred.reject(5) 589 deferred.reject(5)
591 assertAsyncRan() 590 assertAsyncRan()
592 })(); 591 })();
593 592
594 /* TODO(caitp): remove tests once PromiseChain is removed, per bug v8:3237
595 (function() { 593 (function() {
596 var p1 = Promise.accept(5) 594 var p1 = Promise.accept(5)
597 var p2 = {then: function(onResolve, onReject) { onResolve(p1) }} 595 var p2 = {then: function(onResolve, onReject) { onResolve(p1) }}
598 var deferred = Promise.defer() 596 var deferred = Promise.defer()
599 var p3 = deferred.promise 597 var p3 = deferred.promise
600 p3.chain( 598 p3.chain(
601 function(x) { assertAsync(x === p2, "chain/resolve/thenable2") }, 599 function(x) { assertAsync(x === 5, "chain/resolve/thenable2") },
602 assertUnreachable 600 assertUnreachable
603 ) 601 )
604 deferred.resolve(p2) 602 deferred.resolve(p2)
605 assertAsyncRan() 603 assertAsyncRan()
606 })(); */ 604 })();
607 605
608 (function() { 606 (function() {
609 var p1 = Promise.accept(5) 607 var p1 = Promise.accept(5)
610 var p2 = {then: function(onResolve, onReject) { onResolve(p1) }} 608 var p2 = {then: function(onResolve, onReject) { onResolve(p1) }}
611 var deferred = Promise.defer() 609 var deferred = Promise.defer()
612 var p3 = deferred.promise 610 var p3 = deferred.promise
613 p3.then( 611 p3.then(
614 function(x) { assertAsync(x === 5, "then/resolve/thenable2") }, 612 function(x) { assertAsync(x === 5, "then/resolve/thenable2") },
615 assertUnreachable 613 assertUnreachable
616 ) 614 )
(...skipping 14 matching lines...) Expand all
631 (function() { 629 (function() {
632 var p1 = Promise.accept(0) 630 var p1 = Promise.accept(0)
633 var p2 = p1.then(function(x) { return p2 }, assertUnreachable) 631 var p2 = p1.then(function(x) { return p2 }, assertUnreachable)
634 p2.chain( 632 p2.chain(
635 assertUnreachable, 633 assertUnreachable,
636 function(r) { assertAsync(r instanceof TypeError, "cyclic/then") } 634 function(r) { assertAsync(r instanceof TypeError, "cyclic/then") }
637 ) 635 )
638 assertAsyncRan() 636 assertAsyncRan()
639 })(); 637 })();
640 638
641 /* TODO(caitp): remove tests once PromiseChain is removed, per bug v8:3237
642 (function() { 639 (function() {
643 var deferred = Promise.defer() 640 var deferred = Promise.defer()
644 var p = deferred.promise 641 var p = deferred.promise
645 deferred.resolve(p) 642 deferred.resolve(p)
646 p.chain( 643 p.chain(
647 function(x) { assertAsync(x === p, "cyclic/deferred/chain") }, 644 assertUnreachable,
648 assertUnreachable 645 function(r) { assertAsync(r instanceof TypeError, "cyclic/deferred/then") }
649 ) 646 )
650 assertAsyncRan() 647 assertAsyncRan()
651 })();*/ 648 })();
652 649
653 /* TODO(caitp): remove tests once PromiseChain is removed, per bug v8:3237
654 (function() { 650 (function() {
655 var deferred = Promise.defer() 651 var deferred = Promise.defer()
656 var p = deferred.promise 652 var p = deferred.promise
657 deferred.resolve(p) 653 deferred.resolve(p)
658 p.then( 654 p.then(
659 assertUnreachable, 655 assertUnreachable,
660 function(r) { assertAsync(r instanceof TypeError, "cyclic/deferred/then") } 656 function(r) { assertAsync(r instanceof TypeError, "cyclic/deferred/then") }
661 ) 657 )
662 assertAsyncRan() 658 assertAsyncRan()
663 })();*/ 659 })();
664 660
665 (function() { 661 (function() {
666 Promise.all([]).chain( 662 Promise.all([]).chain(
667 function(x) { assertAsync(x.length === 0, "all/resolve/empty") }, 663 function(x) { assertAsync(x.length === 0, "all/resolve/empty") },
668 assertUnreachable 664 assertUnreachable
669 ) 665 )
670 assertAsyncRan() 666 assertAsyncRan()
671 })(); 667 })();
672 668
673 (function() { 669 (function() {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 Promise.all([p1, p2, p3]).chain( 752 Promise.all([p1, p2, p3]).chain(
757 assertUnreachable, 753 assertUnreachable,
758 function(x) { assertAsync(x === 2, "all/reject") } 754 function(x) { assertAsync(x === 2, "all/reject") }
759 ) 755 )
760 deferred1.resolve(1) 756 deferred1.resolve(1)
761 deferred3.resolve(3) 757 deferred3.resolve(3)
762 deferred2.reject(2) 758 deferred2.reject(2)
763 assertAsyncRan() 759 assertAsyncRan()
764 })(); 760 })();
765 761
766
767 (function() { 762 (function() {
768 'use strict'; 763 'use strict';
769 var getCalls = 0; 764 var getCalls = 0;
770 var funcCalls = 0; 765 var funcCalls = 0;
771 var nextCalls = 0; 766 var nextCalls = 0;
772 defineProperty(numberPrototype, symbolIterator, { 767 defineProperty(numberPrototype, symbolIterator, {
773 get: function() { 768 get: function() {
774 assertEquals('number', typeof this); 769 assertEquals('number', typeof this);
775 getCalls++; 770 getCalls++;
776 return function() { 771 return function() {
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
1110 var p = Promise.resolve(); 1105 var p = Promise.resolve();
1111 var callCount = 0; 1106 var callCount = 0;
1112 defineProperty(p, "constructor", { 1107 defineProperty(p, "constructor", {
1113 get: function() { ++callCount; return Promise; } 1108 get: function() { ++callCount; return Promise; }
1114 }); 1109 });
1115 p.then(); 1110 p.then();
1116 assertEquals(1, callCount); 1111 assertEquals(1, callCount);
1117 })(); 1112 })();
1118 1113
1119 assertAsyncDone() 1114 assertAsyncDone()
OLDNEW
« no previous file with comments | « src/js/promise.js ('k') | test/mjsunit/mjsunit.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698