| 3120 | } |
| 3121 | |
| 3122 | function adoptValue( value, resolve, reject, noValue ) { |
| 3123 | var method; |
| 3124 | |
| 3125 | try { |
| 3126 | |
| 3127 | // Check for promise aspect first to privilege synchronous behavior |
| 3128 | if ( value && typeof( method = value.promise ) === "function" ) { |
| 3129 | method.call( value ).done( resolve ).fail( reject ); |
| 3130 | |
| 3131 | // Other thenables |
| 3132 | } else if ( value && typeof( method = value.then ) === "function" ) { |
| 3133 | method.call( value, resolve, reject ); |
| 3134 | |
| 3135 | // Other non-thenables |
| 3136 | } else { |
| 3137 | |
| 3138 | // Control `resolve` arguments by letting Array#slice cast boolean `noValue` to integer: |
| 3139 | // * false: [ value ].slice( 0 ) => resolve( value ) |
| 3140 | // * true: [ value ].slice( 1 ) => resolve() |
| 3141 | resolve.apply( undefined, [ value ].slice( noValue ) ); |
| 3142 | } |
| 3143 | |
| 3144 | // For Promises/A+, convert exceptions into rejections |
| 3145 | // Since jQuery.when doesn't unwrap thenables, we can skip the extra checks appearing in |
| 3146 | // Deferred#then to conditionally suppress rejection. |
| 3147 | } catch ( value ) { |
| 3148 | reject( value ); |
| 3149 | } |
| 3150 | } |
| 3151 | |
| 3152 | jQuery.extend( { |
| 3153 | |