fix($http): should not read statusText on IE<10 when request is aborted

Commit 1d2414c introduced a regression by retrieving the statusText
of an aborted xhr request. This breaks IE9, which throws a c00c023f
error when accessing properties of an aborted xhr request. The fix
is similar to the one in commit 6f1050d.
This commit is contained in:
Kristian Hellang
2014-06-27 13:51:42 +02:00
committed by Igor Minar
parent 3141dbf179
commit 0c80df21b6
2 changed files with 28 additions and 2 deletions

View File

@@ -81,7 +81,8 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc
// Safari respectively.
if (xhr && xhr.readyState == 4) {
var responseHeaders = null,
response = null;
response = null,
statusText = '';
if(status !== ABORTED) {
responseHeaders = xhr.getAllResponseHeaders();
@@ -91,11 +92,17 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc
response = ('response' in xhr) ? xhr.response : xhr.responseText;
}
// Accessing statusText on an aborted xhr object will
// throw an 'c00c023f error' in IE9 and lower, don't touch it.
if (!(status === ABORTED && msie < 10)) {
statusText = xhr.statusText;
}
completeRequest(callback,
status || xhr.status,
response,
responseHeaders,
xhr.statusText || '');
statusText);
}
};

View File

@@ -98,6 +98,25 @@ describe('$httpBackend', function() {
expect(callback).toHaveBeenCalledOnce();
});
it('should not touch xhr.statusText when request is aborted on IE9 or lower', function() {
callback.andCallFake(function(status, response, headers, statusText) {
expect(statusText).toBe((!msie || msie >= 10) ? 'OK' : '');
});
$backend('GET', '/url', null, callback, {}, 2000);
xhr = MockXhr.$$lastInstance;
spyOn(xhr, 'abort');
fakeTimeout.flush();
expect(xhr.abort).toHaveBeenCalledOnce();
xhr.status = 0;
xhr.readyState = 4;
xhr.statusText = 'OK';
xhr.onreadystatechange();
expect(callback).toHaveBeenCalledOnce();
});
it('should call completion function with empty string if not present', function() {
callback.andCallFake(function(status, response, headers, statusText) {
expect(statusText).toBe('');