@@ -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
@@ -362,23 +350,34 @@ function qFactory(nextTick, exceptionHandler) {
362
350
} ,
363
351
364
352
$$resolve : function ( val ) {
365
- var then , fns ;
366
-
367
- fns = callOnce ( this , this . $$resolve , this . $$reject ) ;
353
+ var then ;
354
+ var that = this ;
355
+ var done = false ;
368
356
try {
369
357
if ( ( isObject ( val ) || isFunction ( val ) ) ) then = val && val . then ;
370
358
if ( isFunction ( then ) ) {
371
359
this . promise . $$state . status = - 1 ;
372
- then . call ( val , fns [ 0 ] , fns [ 1 ] , simpleBind ( this , this . notify ) ) ;
360
+ then . call ( val , resolvePromise , rejectPromise , simpleBind ( this , this . notify ) ) ;
373
361
} else {
374
362
this . promise . $$state . value = val ;
375
363
this . promise . $$state . status = 1 ;
376
364
scheduleProcessQueue ( this . promise . $$state ) ;
377
365
}
378
366
} catch ( e ) {
379
- fns [ 1 ] ( e ) ;
367
+ rejectPromise ( e ) ;
380
368
exceptionHandler ( e ) ;
381
369
}
370
+
371
+ function resolvePromise ( val ) {
372
+ if ( done ) return ;
373
+ done = true ;
374
+ that . $$resolve ( val ) ;
375
+ }
376
+ function rejectPromise ( val ) {
377
+ if ( done ) return ;
378
+ done = true ;
379
+ that . $$reject ( val ) ;
380
+ }
382
381
} ,
383
382
384
383
reject : function ( reason ) {
0 commit comments