Bug 1253891 - "prefStrBundle.getFormattedString is not a function" exceptions in in-content/advanced.js. r?gijs
Guards were added to both async calls as it is likely that either of them could fire after the tab has been closed.
MozReview-Commit-ID: 9pKKNKXtxaP
--- a/browser/components/preferences/in-content/advanced.js
+++ b/browser/components/preferences/in-content/advanced.js
@@ -352,16 +352,21 @@ var gAdvancedPane = {
{
var actualSizeLabel = document.getElementById("actualDiskCacheSize");
var prefStrBundle = document.getElementById("bundlePreferences");
// Needs to root the observer since cache service keeps only a weak reference.
this.observer = {
onNetworkCacheDiskConsumption: function(consumption) {
var size = DownloadUtils.convertByteUnits(consumption);
+ // The XBL binding for the string bundle may have been destroyed if
+ // the page was closed before this callback was executed.
+ if (!prefStrBundle || !prefStrBundle.getFormattedString) {
+ return;
+ }
actualSizeLabel.value = prefStrBundle.getFormattedString("actualDiskCacheSize", size);
},
QueryInterface: XPCOMUtils.generateQI([
Components.interfaces.nsICacheStorageConsumptionObserver,
Components.interfaces.nsISupportsWeakReference
])
};
@@ -380,16 +385,21 @@ var gAdvancedPane = {
updateActualAppCacheSize: function ()
{
var visitor = {
onCacheStorageInfo: function (aEntryCount, aConsumption, aCapacity, aDiskDirectory)
{
var actualSizeLabel = document.getElementById("actualAppCacheSize");
var sizeStrings = DownloadUtils.convertByteUnits(aConsumption);
var prefStrBundle = document.getElementById("bundlePreferences");
+ // The XBL binding for the string bundle may have been destroyed if
+ // the page was closed before this callback was executed.
+ if (!prefStrBundle || !prefStrBundle.getFormattedString) {
+ return;
+ }
var sizeStr = prefStrBundle.getFormattedString("actualAppCacheSize", sizeStrings);
actualSizeLabel.value = sizeStr;
}
};
try {
var cacheService =
Components.classes["@mozilla.org/netwerk/cache-storage-service;1"]