Bug 655583 - In about:memory, only remove the observer if it's been added, in order to avoid an assertion and/or exception. r=bz.

This commit is contained in:
Nicholas Nethercote 2011-05-11 16:09:50 -07:00
Родитель 78b6523bdc
Коммит 3521a4dc64
1 изменённых файлов: 11 добавлений и 3 удалений

Просмотреть файл

@ -46,6 +46,8 @@ const Cu = Components.utils;
// non-standard URL.
var gVerbose = (location.href.split(/[\?,]/).indexOf("verbose") !== -1);
var gAddedObserver = false;
function onLoad()
{
var os = Cc["@mozilla.org/observer-service;1"].
@ -53,15 +55,21 @@ function onLoad()
os.notifyObservers(null, "child-memory-reporter-request", null);
os.addObserver(ChildMemoryListener, "child-memory-reporter-update", false);
gAddedObserver = true;
update();
}
function onUnload()
{
var os = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
os.removeObserver(ChildMemoryListener, "child-memory-reporter-update");
// We need to check if the observer has been added before removing; in some
// circumstances (eg. reloading the page quickly) it might not have because
// onLoad might not fire.
if (gAddedObserver) {
var os = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
os.removeObserver(ChildMemoryListener, "child-memory-reporter-update");
}
}
function ChildMemoryListener(aSubject, aTopic, aData)