diff --git a/dom/settings/SettingsManager.js b/dom/settings/SettingsManager.js index 0a3854f38a1..9de0953c44a 100644 --- a/dom/settings/SettingsManager.js +++ b/dom/settings/SettingsManager.js @@ -39,6 +39,8 @@ XPCOMUtils.defineLazyServiceGetter(this, "uuidgen", "@mozilla.org/uuid-generator;1", "nsIUUIDGenerator"); +const kObserverSoftLimit = 10; + /** * In order to make SettingsManager work with Privileged Apps, we need the lock * to be OOP. However, the lock state needs to be managed on the child process, @@ -363,14 +365,26 @@ SettingsManager.prototype = { addObserver: function addObserver(aName, aCallback) { if (VERBOSE) debug("addObserver " + aName); + if (!this._callbacks) { this._callbacks = {}; } + if (!this._callbacks[aName]) { this._callbacks[aName] = [aCallback]; } else { this._callbacks[aName].push(aCallback); } + + let length = this._callbacks[aName].length; + if (length >= kObserverSoftLimit) { + debug("WARNING: MORE THAN " + kObserverSoftLimit + " OBSERVERS FOR " + + aName + ": " + length + " FROM" + (new Error).stack); +#ifdef DEBUG + throw Components.results.NS_ERROR_ABORT; +#endif + } + this.checkMessageRegistration(); }, @@ -421,7 +435,7 @@ SettingsManager.prototype = { } let path; - if (length < 20) { + if (length < kObserverSoftLimit) { path = "settings-observers"; } else { path = "settings-observers-suspect/referent(topic=" + diff --git a/dom/settings/moz.build b/dom/settings/moz.build index 10a6055ba12..0588a22419d 100644 --- a/dom/settings/moz.build +++ b/dom/settings/moz.build @@ -5,8 +5,11 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. EXTRA_COMPONENTS += [ - 'SettingsManager.js', - 'SettingsManager.manifest', + 'SettingsManager.manifest' +] + +EXTRA_PP_COMPONENTS += [ + 'SettingsManager.js' ] if CONFIG['MOZ_B2G']: diff --git a/dom/settings/tests/mochitest.ini b/dom/settings/tests/mochitest.ini index 87e3c3be926..b57f821d93f 100644 --- a/dom/settings/tests/mochitest.ini +++ b/dom/settings/tests/mochitest.ini @@ -12,4 +12,6 @@ support-files = [test_settings_navigator_object.html] [test_settings_onsettingchange.html] [test_settings_bug1110872.html] -skip-if = !e10s \ No newline at end of file +skip-if = !e10s +[test_settings_observer_killer.html] +skip-if = !debug diff --git a/dom/settings/tests/test_settings_observer_killer.html b/dom/settings/tests/test_settings_observer_killer.html new file mode 100644 index 00000000000..462515b10aa --- /dev/null +++ b/dom/settings/tests/test_settings_observer_killer.html @@ -0,0 +1,68 @@ + + + + + Test for Bug 1193469 Settings API + + + + + + +Mozilla Bug 1193469 +

+ +
+
+
+ +