Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
fix #569, request will cause updateTaskCount failed if we call abort …
Browse files Browse the repository at this point in the history
…multipletimes

the fix is check whether the xhr has been aborted before abort the request
  • Loading branch information
JiaLiPassion committed Dec 30, 2016
1 parent c03acda commit 50ac4fd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/browser/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ function patchXHR(window: any) {
const task: Task = findPendingTask(self);
if (task && typeof task.type == 'string') {
// If the XHR has already completed, do nothing.
if (task.cancelFn == null) {
// If the XHR has already been aborted, do nothing.
if (task.cancelFn == null || (task.data && (<XHROptions>task.data).aborted)) {
return;
}
task.zone.cancelTask(task);
Expand Down
14 changes: 14 additions & 0 deletions test/browser/XMLHttpRequest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,18 @@ describe('XMLHttpRequest', function() {
};
});
});

it('should keep taskcount correctly when abort was called multiple times before request is done',
function() {
testZone.run(function() {
const req = new XMLHttpRequest();
req.open('get', '/', true);
req.send();
req.addEventListener('readystatechange', function(ev) {
if (req.readyState >= 2) {
req.abort();
}
});
});
});
});

0 comments on commit 50ac4fd

Please sign in to comment.