<?xml version="1.0"?>

<!DOCTYPE window SYSTEM "chrome://chatzilla/locale/chatzilla.dtd">
<?xul-overlay href="chrome://global/content/globalOverlay.xul"?>

<window
  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  id="main-window" orient="vertical" onclose="onClose();">

  <script>
    <![CDATA[
      var scriptHook = {
          onScriptCreated: function scripthook (script) {
              dump ("script created\n");
          },
          onScriptDestroyed: function scripthook (script) {
              dump ("script destroyed\n");
          }
      };

      netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
      const JSD_CTRID = "@mozilla.org/js/jsd/debugger-service;1";
      const jsdIDebuggerService = Components.interfaces.jsdIDebuggerService;

      var jsds = Components.classes[JSD_CTRID].getService(jsdIDebuggerService);
      jsds.scriptHook = scriptHook;
      jsds.on();

      function onClose ()
      {
        netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
        jsds.off();
      }

      function onKeyPress (e)
      {
         if (e.keyCode == 13)
            doEval();
      }

      function doEval()
      {
         var ex;
         try {
           var rv = eval(document.getElementById("input-box").value);
           document.getElementById("output-box").value = rv;
         } catch (ex) {
           document.getElementById("output-box").value = 
             "Caught exception: " + String(ex);
         }
         finally
         {
           document.getElementById("input-box").value = "";
         }
      }
    ]]>
  </script>

  <textbox id="input-box" style="width:100%" onkeypress="onKeyPress(event);"/>
  <textbox id="output-box" style="width:100%" readonly="true"/>

</window>

