Permalink
Browse files

Bug 942795 - [email] autoconfig XHR callbacks seem to be firing multi…

…ple times on nightly, may produce duplicate accounts; investigate XHR event changes, switch to promises
  • Loading branch information...
1 parent 567dcc0 commit d3209db3cd8e9094388722f2dac2c5771836f932 @mcav mcav committed Dec 12, 2013
Showing with 20 additions and 2 deletions.
  1. +5 −1 data/lib/mailapi/accountcommon.js
  2. +15 −1 test/unit/resources/fake_xhr.js
View
6 data/lib/mailapi/accountcommon.js
@@ -306,11 +306,15 @@ Autoconfigurator.prototype = {
});
};
- xhr.ontimeout = xhr.onerror = function() {
+ // Caution: don't overwrite ".onerror" twice here. Just be careful
+ // to only assign that once until <http://bugzil.la/949722> is fixed.
+
+ xhr.ontimeout = function() {
// The effective result is a failure to get configuration info, but make
// sure the status conveys that a timeout occurred.
callback('no-config-info', null, { status: 'timeout' });
};
+
xhr.onerror = function() {
// The effective result is a failure to get configuration info, but make
// sure the status conveys that a timeout occurred.
View
16 test/unit/resources/fake_xhr.js
@@ -17,7 +17,6 @@ function FakeXHR() {
};
this.onload = null;
- this.onerror = null;
this.ontimeout = null;
this.timeout = null;
@@ -37,6 +36,21 @@ FakeXHR.prototype = {
this._args.async = async;
},
+ // To prevent regressions related to <https://bugzil.la/949722> in
+ // which XHRs treat .onerror like .addEventListener('error'), ensure
+ // that we only assign to this property once for safety:
+
+ get onerror() {
+ return this._onerror;
+ },
+
+ set onerror(fn) {
+ if (fn && this._onerror) {
+ throw new Error("onerror already set on XHR! Don't. See bug 949722.");
+ }
+ this._onerror = fn;
+ },
+
send: function() {
this._args.timeout = this.timeout;
if (window.gFakeXHRListener) {

0 comments on commit d3209db

Please sign in to comment.