mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-25 14:23:43 +00:00
fix($timeout): allow calling $timeout.cancel() with undefined
This is how it worked in rc9, before refactoring $defer into $timeout.
This commit is contained in:
parent
22143381d8
commit
1904596e0c
2 changed files with 7 additions and 2 deletions
|
|
@ -70,12 +70,12 @@ function $TimeoutProvider() {
|
||||||
* Cancels a task associated with the `promise`. As a result of this the promise will be
|
* Cancels a task associated with the `promise`. As a result of this the promise will be
|
||||||
* resolved with a rejection.
|
* 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
|
* @returns {boolean} Returns `true` if the task hasn't executed yet and was successfully
|
||||||
* canceled.
|
* canceled.
|
||||||
*/
|
*/
|
||||||
timeout.cancel = function(promise) {
|
timeout.cancel = function(promise) {
|
||||||
if (promise.$$timeoutId in deferreds) {
|
if (promise && promise.$$timeoutId in deferreds) {
|
||||||
deferreds[promise.$$timeoutId].reject('canceled');
|
deferreds[promise.$$timeoutId].reject('canceled');
|
||||||
return $browser.defer.cancel(promise.$$timeoutId);
|
return $browser.defer.cancel(promise.$$timeoutId);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -142,5 +142,10 @@ describe('$timeout', function() {
|
||||||
expect($timeout.cancel(promise1)).toBe(false);
|
expect($timeout.cancel(promise1)).toBe(false);
|
||||||
expect($timeout.cancel(promise2)).toBe(true);
|
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);
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue