@@ -243,18 +243,6 @@ function $$QProvider() {
243
243
*/
244
244
function qFactory ( nextTick , exceptionHandler ) {
245
245
var $qMinErr = minErr ( '$q' , TypeError ) ;
246
- function callOnce ( self , resolveFn , rejectFn ) {
247
- var called = false ;
248
- function wrap ( fn ) {
249
- return function ( value ) {
250
- if ( called ) return ;
251
- called = true ;
252
- fn . call ( self , value ) ;
253
- } ;
254
- }
255
-
256
- return [ wrap ( resolveFn ) , wrap ( rejectFn ) ] ;
257
- }
258
246
259
247
/**
260
248
* @ngdoc method
@@ -361,23 +349,34 @@ function qFactory(nextTick, exceptionHandler) {
361
349
} ,
362
350
363
351
$$resolve : function ( val ) {
364
- var then , fns ;
365
-
366
- fns = callOnce ( this , this . $$resolve , this . $$reject ) ;
352
+ var then ;
353
+ var that = this ;
354
+ var done = false ;
367
355
try {
368
356
if ( ( isObject ( val ) || isFunction ( val ) ) ) then = val && val . then ;
369
357
if ( isFunction ( then ) ) {
370
358
this . promise . $$state . status = - 1 ;
371
- then . call ( val , fns [ 0 ] , fns [ 1 ] , this . notify ) ;
359
+ then . call ( val , resolvePromise , rejectPromise , simpleBind ( this , this . notify ) ) ;
372
360
} else {
373
361
this . promise . $$state . value = val ;
374
362
this . promise . $$state . status = 1 ;
375
363
scheduleProcessQueue ( this . promise . $$state ) ;
376
364
}
377
365
} catch ( e ) {
378
- fns [ 1 ] ( e ) ;
366
+ rejectPromise ( e ) ;
379
367
exceptionHandler ( e ) ;
380
368
}
369
+
370
+ function resolvePromise ( val ) {
371
+ if ( done ) return ;
372
+ done = true ;
373
+ that . $$resolve ( val ) ;
374
+ }
375
+ function rejectPromise ( val ) {
376
+ if ( done ) return ;
377
+ done = true ;
378
+ that . $$reject ( val ) ;
379
+ }
381
380
} ,
382
381
383
382
reject : function ( reason ) {
0 commit comments