@@ -350,14 +350,12 @@ function qFactory(nextTick, exceptionHandler) {
350350 } ,
351351
352352 $$resolve : function ( val ) {
353- var then ;
354353 var that = this ;
355354 var done = false ;
356355 try {
357- if ( ( isObject ( val ) || isFunction ( val ) ) ) then = val && val . then ;
358- if ( isFunction ( then ) ) {
356+ if ( isPromiseLike ( val ) ) {
359357 this . promise . $$state . status = - 1 ;
360- then . call ( val , resolvePromise , rejectPromise , simpleBind ( this , this . notify ) ) ;
358+ val . then ( resolvePromise , rejectPromise , simpleBind ( this , this . notify ) ) ;
361359 } else {
362360 this . promise . $$state . value = val ;
363361 this . promise . $$state . status = 1 ;
@@ -561,6 +559,22 @@ function qFactory(nextTick, exceptionHandler) {
561559 return deferred . promise ;
562560 }
563561
562+ /**
563+ * @ngdoc method
564+ * @name $q#isPromiseLike
565+ * @kind function
566+ *
567+ * @description
568+ * Determines whether object or function is like a promise
569+ *
570+ * @param {* } value Reference to check
571+ * @returns {boolean } True if `value` is promise-like
572+ */
573+
574+ function isPromiseLike ( obj ) {
575+ return ( isObject ( obj ) || isFunction ( obj ) ) && isFunction ( obj . then ) ;
576+ }
577+
564578 var $Q = function Q ( resolver ) {
565579 if ( ! isFunction ( resolver ) ) {
566580 throw $qMinErr ( 'norslvr' , "Expected resolverFn, got '{0}'" , resolver ) ;
@@ -590,6 +604,7 @@ function qFactory(nextTick, exceptionHandler) {
590604 $Q . when = when ;
591605 $Q . resolve = resolve ;
592606 $Q . all = all ;
607+ $Q . isPromiseLike = isPromiseLike ;
593608
594609 return $Q ;
595610}
0 commit comments