Permalink
Browse files

fix($timeout): allow calling $timeout.cancel() with undefined

This is how it worked in rc9, before refactoring $defer into $timeout.
  • Loading branch information...
Ali Mills authored and vojtajina committed Jun 1, 2012
1 parent 2214338 commit 1904596e0c2330299e92f092bd7a6ceca8e97c30
Showing with 7 additions and 2 deletions.
  1. +2 −2 src/ng/timeout.js
  2. +5 −0 test/ng/timeoutSpec.js
View
@@ -70,12 +70,12 @@ function $TimeoutProvider() {
* Cancels a task associated with the `promise`. As a result of this the promise will be
* resolved with a rejection.
*
* @param {Promise} promise Promise returned by the `$timeout` function.
* @param {Promise=} promise Promise returned by the `$timeout` function.
* @returns {boolean} Returns `true` if the task hasn't executed yet and was successfully
* canceled.
*/
timeout.cancel = function(promise) {
if (promise.$$timeoutId in deferreds) {
if (promise && promise.$$timeoutId in deferreds) {
deferreds[promise.$$timeoutId].reject('canceled');
return $browser.defer.cancel(promise.$$timeoutId);
}
View
@@ -142,5 +142,10 @@ describe('$timeout', function() {
expect($timeout.cancel(promise1)).toBe(false);
expect($timeout.cancel(promise2)).toBe(true);
}));
it('should not throw a runtime exception when given an undefined promise', inject(function($timeout) {
expect($timeout.cancel()).toBe(false);
}));
});
});

0 comments on commit 1904596

Please sign in to comment.