Skip to content

Commit

Permalink
fix angular#569, request will cause updateTaskCount failed if we call…
Browse files Browse the repository at this point in the history
… abort 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 7eb10fd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/browser/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ 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.
// Fix #569, call abort multiple times before done will cause
// macroTask task count be negative number
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 7eb10fd

Please sign in to comment.