Bug 51661 - js errors in navigator.js when clicking Leak Detector menuitems [leakDetector.* is not a function]; (Cv1) Hide the menu; r+sr=neil
authorSerge Gautherie <sgautherie.bz@free.fr>
Wed, 15 Oct 2008 18:44:22 +0200
changeset 618 1f6bcd26cf4565d29a00c67ca08eedab20a04ce3
parent 617 62876a69cb3540cdacc60667480dd56e4faedfc6
child 619 60900dd0303bcc12115ab3bbd14e75296971f007
push idunknown
push userunknown
push dateunknown
bugs51661
Bug 51661 - js errors in navigator.js when clicking Leak Detector menuitems [leakDetector.* is not a function]; (Cv1) Hide the menu; r+sr=neil
suite/debugQA/content/debugQAMenuOverlay.js
suite/debugQA/content/debugQAMenuOverlay.xul
--- a/suite/debugQA/content/debugQAMenuOverlay.js
+++ b/suite/debugQA/content/debugQAMenuOverlay.js
@@ -34,55 +34,57 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-// Initialize the LeakDetector class.
-function LeakDetector(verbose)
-{
-  this.verbose = verbose;
-}
+var gLeakDetector = null;
+var gLeakDetectorVerbose = false;
 
-const NS_LEAKDETECTOR_CONTRACTID = "@mozilla.org/xpcom/leakdetector;1";
+// The Leak Detector (class) can be undefined in a given (application) build.
+if ("@mozilla.org/xpcom/leakdetector;1" in Components.classes)
+  window.addEventListener("load", onLoadLeakDetector, false);
 
-if (NS_LEAKDETECTOR_CONTRACTID in Components.classes) {
-  try {
-    LeakDetector.prototype = Components.classes[NS_LEAKDETECTOR_CONTRACTID]
-                                       .createInstance(Components.interfaces.nsILeakDetector);
-  } catch (err) {
-    LeakDetector.prototype = Object.prototype;
-  }
-} else {
-  LeakDetector.prototype = Object.prototype;
+// Initialize the Leak Detector,
+// and unhide its menu and its associated separator.
+function onLoadLeakDetector()
+{
+  window.removeEventListener("load", onLoadLeakDetector, false);
+
+  gLeakDetector = Components.classes["@mozilla.org/xpcom/leakdetector;1"]
+                            .createInstance(Components.interfaces.nsILeakDetector);
+
+  document.getElementById("leakSeparator").hidden = false;
+  document.getElementById("leakMenu").hidden = false;
 }
 
-var leakDetector = new LeakDetector(false);
-
 // Dumps current set of memory leaks.
 function dumpMemoryLeaks()
 {
-  leakDetector.dumpLeaks();
+  gLeakDetector.dumpLeaks();
 }
 
 // Traces all objects reachable from the chrome document.
 function traceChrome()
 {
-  leakDetector.traceObject(document, leakDetector.verbose);
+  gLeakDetector.traceObject(document, gLeakDetectorVerbose);
 }
 
 // Traces all objects reachable from the content document.
 function traceDocument()
 {
   // keep the chrome document out of the dump.
-  leakDetector.markObject(document, true);
-  leakDetector.traceObject(content, leakDetector.verbose);
-  leakDetector.markObject(document, false);
+  gLeakDetector.markObject(document, true);
+  gLeakDetector.traceObject(content, gLeakDetectorVerbose);
+  gLeakDetector.markObject(document, false);
 }
 
-// Controls whether or not we do verbose tracing.
+/**
+ * Controls whether or not we do verbose tracing.
+ * @param verbose Either |"true"| or |""|.
+ */
 function traceVerbose(verbose)
 {
-  leakDetector.verbose = (verbose == "true");
+  gLeakDetectorVerbose = (verbose == "true");
 }
--- a/suite/debugQA/content/debugQAMenuOverlay.xul
+++ b/suite/debugQA/content/debugQAMenuOverlay.xul
@@ -39,17 +39,17 @@
    - the terms of any one of the MPL, the GPL or the LGPL.
    -
    - ***** END LICENSE BLOCK ***** -->
 
 <overlay id="debugQAMenuOverlay"
          xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
          xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
-<script type="application/x-javascript"
+<script type="application/javascript"
         src="chrome://debugQA/content/debugQAMenuOverlay.js"/>
 
   <!-- Menu -->
   <menubar id="main-menubar">
     <!-- Menu for testing. -->
     <menu id="debugMenu" accesskey="U" label="Debug" insertafter="menu_Help">
       <menupopup id="menu_Debug_Popup">
         <menu label="Verification">
@@ -179,19 +179,19 @@
                   oncommand="openTopWin('resource:/res/strres-test.xul');"/>
         <menuitem label="Bloat: Dump New Stats"
                   oncommand="openTopWin('about:bloat?new');"/>
         <menuitem label="Bloat: Dump All Stats"
                   oncommand="openTopWin('about:bloat');"/>
         <menuitem label="Bloat: Clear Stats"
                   oncommand="openTopWin('about:bloat?clear');"/>
 
-        <menuseparator/>
+        <menuseparator id="leakSeparator" hidden="true"/>
 
-        <menu label="Leak Detector">
+        <menu id="leakMenu" label="Leak Detector" hidden="true">
           <menupopup>
             <menuitem label="Dump Memory Leaks" oncommand="dumpMemoryLeaks();"/>
             <menuitem label="Trace Chrome" oncommand="traceChrome();"/>
             <menuitem label="Trace Document" oncommand="traceDocument();"/>
             <menuitem label="Verbose" checked="false" type="checkbox"
                       oncommand="traceVerbose(this.getAttribute('checked'))"/>
           </menupopup>
         </menu>