Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
});
});
});
});