mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-04-20 06:41:00 +00:00
fix($httpBackend): don't delete xhr.onreadystatechange otherwise Safari :-O
This commit is contained in:
parent
bc492c0fc1
commit
3d38fff8b4
2 changed files with 12 additions and 10 deletions
|
|
@ -71,14 +71,14 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc
|
||||||
// response is in the cache. the promise api will ensure that to the app code the api is
|
// response is in the cache. the promise api will ensure that to the app code the api is
|
||||||
// always async
|
// always async
|
||||||
xhr.onreadystatechange = function() {
|
xhr.onreadystatechange = function() {
|
||||||
if (xhr.readyState == 4) {
|
// onreadystatechange might by called multiple times with readyState === 4 on mobile webkit caused by
|
||||||
// onreadystatechange might by called multiple times
|
// xhrs that are resolved while the app is in the background (see #5426).
|
||||||
// with readyState === 4 on mobile webkit caused by
|
// since calling completeRequest sets the `xhr` variable to null, we just check if it's not null before
|
||||||
// xhrs that are resolved while the app is in the background (see #5426).
|
// continuing
|
||||||
//
|
//
|
||||||
// we must delete the property instead of setting it to undefined/null to make IE8 happy.
|
// we can't set xhr.onreadystatechange to undefined or delete it because that breaks IE8 (method=PATCH) and
|
||||||
delete xhr.onreadystatechange;
|
// Safari respectively.
|
||||||
|
if (xhr && xhr.readyState == 4) {
|
||||||
var responseHeaders = null,
|
var responseHeaders = null,
|
||||||
response = null;
|
response = null;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -93,14 +93,16 @@ describe('$httpBackend', function() {
|
||||||
// onreadystatechange might by called multiple times
|
// onreadystatechange might by called multiple times
|
||||||
// with readyState === 4 on mobile webkit caused by
|
// with readyState === 4 on mobile webkit caused by
|
||||||
// xhrs that are resolved while the app is in the background (see #5426).
|
// xhrs that are resolved while the app is in the background (see #5426).
|
||||||
it('should remove onreadystatechange when it is called with readyState=4 to ignore multiple calls', function() {
|
it('should not process onreadystatechange callback with readyState == 4 more than once', function() {
|
||||||
$backend('GET', 'URL', null, callback);
|
$backend('GET', 'URL', null, callback);
|
||||||
xhr = MockXhr.$$lastInstance;
|
xhr = MockXhr.$$lastInstance;
|
||||||
|
|
||||||
xhr.status = 200;
|
xhr.status = 200;
|
||||||
xhr.readyState = 4;
|
xhr.readyState = 4;
|
||||||
xhr.onreadystatechange();
|
xhr.onreadystatechange();
|
||||||
expect(xhr.onreadystatechange).toBeUndefined();
|
xhr.onreadystatechange();
|
||||||
|
|
||||||
|
expect(callback).toHaveBeenCalledOnce();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set only the requested headers', function() {
|
it('should set only the requested headers', function() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue