Commit 79f2dc0a authored by Nicholas Nethercote's avatar Nicholas Nethercote
Browse files

Bug 655583 - In about:memory, only remove the observer if it's been added, in...

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.
parent d2396da9
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -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,16 +55,22 @@ function onLoad()
  os.notifyObservers(null, "child-memory-reporter-request", null);

  os.addObserver(ChildMemoryListener, "child-memory-reporter-update", false);
  gAddedObserver = true;

  update();
}

function onUnload()
{
  // 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)
{