( depth, deferred, handler, special )
| 3473 | then: function( onFulfilled, onRejected, onProgress ) { |
| 3474 | var maxDepth = 0; |
| 3475 | function resolve( depth, deferred, handler, special ) { |
| 3476 | return function() { |
| 3477 | var that = this, |
| 3478 | args = arguments, |
| 3479 | mightThrow = function() { |
| 3480 | var returned, then; |
| 3481 | |
| 3482 | // Support: Promises/A+ section 2.3.3.3.3 |
| 3483 | // https://promisesaplus.com/#point-59 |
| 3484 | // Ignore double-resolution attempts |
| 3485 | if ( depth < maxDepth ) { |
| 3486 | return; |
| 3487 | } |
| 3488 | |
| 3489 | returned = handler.apply( that, args ); |
| 3490 | |
| 3491 | // Support: Promises/A+ section 2.3.1 |
| 3492 | // https://promisesaplus.com/#point-48 |
| 3493 | if ( returned === deferred.promise() ) { |
| 3494 | throw new TypeError( "Thenable self-resolution" ); |
| 3495 | } |
| 3496 | |
| 3497 | // Support: Promises/A+ sections 2.3.3.1, 3.5 |
| 3498 | // https://promisesaplus.com/#point-54 |
| 3499 | // https://promisesaplus.com/#point-75 |
| 3500 | // Retrieve `then` only once |
| 3501 | then = returned && |
| 3502 | |
| 3503 | // Support: Promises/A+ section 2.3.4 |
| 3504 | // https://promisesaplus.com/#point-64 |
| 3505 | // Only check objects and functions for thenability |
| 3506 | ( typeof returned === "object" || |
| 3507 | typeof returned === "function" ) && |
| 3508 | returned.then; |
| 3509 | |
| 3510 | // Handle a returned thenable |
| 3511 | if ( isFunction( then ) ) { |
| 3512 | |
| 3513 | // Special processors (notify) just wait for resolution |
| 3514 | if ( special ) { |
| 3515 | then.call( |
| 3516 | returned, |
| 3517 | resolve( maxDepth, deferred, Identity, special ), |
| 3518 | resolve( maxDepth, deferred, Thrower, special ) |
| 3519 | ); |
| 3520 | |
| 3521 | // Normal processors (resolve) also hook into progress |
| 3522 | } else { |
| 3523 | |
| 3524 | // ...and disregard older resolution values |
| 3525 | maxDepth++; |
| 3526 | |
| 3527 | then.call( |
| 3528 | returned, |
| 3529 | resolve( maxDepth, deferred, Identity, special ), |
| 3530 | resolve( maxDepth, deferred, Thrower, special ), |
| 3531 | resolve( maxDepth, deferred, Identity, |
| 3532 | deferred.notifyWith ) |
no test coverage detected