aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Minar2014-01-03 09:23:51 -0800
committerIgor Minar2014-01-03 09:51:05 -0800
commit3d38fff8b4ea2fd60fadef2028ea4dcddfccb1a4 (patch)
tree87847091cda5ac376aa8d7c6bfc5eff7b107082b
parentbc492c0fc17257ddf2bc5964e205379aa766b3d8 (diff)
downloadangular.js-3d38fff8b4ea2fd60fadef2028ea4dcddfccb1a4.tar.bz2
fix($httpBackend): don't delete xhr.onreadystatechange otherwise Safari :-O
-rw-r--r--src/ng/httpBackend.js16
-rw-r--r--test/ng/httpBackendSpec.js6
2 files changed, 12 insertions, 10 deletions
diff --git a/src/ng/httpBackend.js b/src/ng/httpBackend.js
index ffc51abf..29a28cee 100644
--- a/src/ng/httpBackend.js
+++ b/src/ng/httpBackend.js
@@ -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
// always async
xhr.onreadystatechange = function() {
- if (xhr.readyState == 4) {
- // onreadystatechange might by called multiple times
- // with readyState === 4 on mobile webkit caused by
- // xhrs that are resolved while the app is in the background (see #5426).
- //
- // we must delete the property instead of setting it to undefined/null to make IE8 happy.
- delete xhr.onreadystatechange;
-
+ // onreadystatechange might by called multiple times with readyState === 4 on mobile webkit caused by
+ // xhrs that are resolved while the app is in the background (see #5426).
+ // since calling completeRequest sets the `xhr` variable to null, we just check if it's not null before
+ // continuing
+ //
+ // we can't set xhr.onreadystatechange to undefined or delete it because that breaks IE8 (method=PATCH) and
+ // Safari respectively.
+ if (xhr && xhr.readyState == 4) {
var responseHeaders = null,
response = null;
diff --git a/test/ng/httpBackendSpec.js b/test/ng/httpBackendSpec.js
index 7302de00..1be31984 100644
--- a/test/ng/httpBackendSpec.js
+++ b/test/ng/httpBackendSpec.js
@@ -93,14 +93,16 @@ describe('$httpBackend', function() {
// onreadystatechange might by called multiple times
// with readyState === 4 on mobile webkit caused by
// 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);
xhr = MockXhr.$$lastInstance;
xhr.status = 200;
xhr.readyState = 4;
xhr.onreadystatechange();
- expect(xhr.onreadystatechange).toBeUndefined();
+ xhr.onreadystatechange();
+
+ expect(callback).toHaveBeenCalledOnce();
});
it('should set only the requested headers', function() {