Bug 571517 [SeaMonkey] Don't pass strings to setTimeout. Part 2. r=Neil
authorPhilip Chee <philip.chee@gmail.com>
Mon, 28 Jun 2010 18:30:07 +0800
changeset 5904 b016d4eabd861b33412843e348868da117a2f852
parent 5903 bfd54c7dbd8c395c085cbfe8da6600d582bd1b3b
child 5905 74ccec25e4a9a7c5817b368657ec18c208a5df9a
push idunknown
push userunknown
push dateunknown
reviewersNeil
bugs571517
Bug 571517 [SeaMonkey] Don't pass strings to setTimeout. Part 2. r=Neil
suite/browser/navigator.js
suite/common/directory/directory.js
suite/common/search/search-panel.js
suite/common/sidebar/customize.js
suite/common/sidebar/sidebarOverlay.js
suite/profile/migration.js
--- a/suite/browser/navigator.js
+++ b/suite/browser/navigator.js
@@ -591,17 +591,17 @@ function Startup()
   // the focus should be in the content area.
   var navBar = document.getElementById("nav-bar");
   if ("arguments" in window && uriToLoad == "about:blank" && isElementVisible(gURLBar))
     setTimeout(WindowFocusTimerCallback, 0, gURLBar);
   else
     setTimeout(WindowFocusTimerCallback, 0, content);
 
   // Perform default browser checking (after window opens).
-  setTimeout( checkForDefaultBrowser, 0 );
+  setTimeout(checkForDefaultBrowser, 0);
 
   // hook up browser access support
   window.browserDOMWindow = new nsBrowserAccess();
 
   // hook up remote support
   if (REMOTESERVICE_CONTRACTID in Components.classes) {
     var remoteService =
       Components.classes[REMOTESERVICE_CONTRACTID]
@@ -682,17 +682,18 @@ function InitSessionStoreCallback()
     ss.init(window);
   } catch(ex) {
     dump("nsSessionStore could not be initialized: " + ex + "\n");
   }
 }
 
 function WindowFocusTimerCallback(element)
 {
-  // This fuction is a redo of the fix for jag bug 91884
+  // This function is a redo of the fix for jag bug 91884.
+  // See Bug 97067 and Bug 89214 for details.
   if (window == Services.ww.activeWindow) {
     element.focus();
   } else {
     // set the element in command dispatcher so focus will restore properly
     // when the window does become active
 
     if (element instanceof Components.interfaces.nsIDOMWindow) {
       document.commandDispatcher.focusedWindow = element;
@@ -1243,19 +1244,19 @@ function BrowserOpenTab()
     // Open a new window if someone requests a new tab when no browser window is open
     if (!gBrowser) {
       openDialog(getBrowserURL(), "_blank", "chrome,all,dialog=no", uriToLoad);
       return;
     }
 
     gBrowser.selectedTab = gBrowser.addTab(uriToLoad);
     if (uriToLoad == "about:blank" && isElementVisible(gURLBar))
-      setTimeout("gURLBar.focus();", 0);
+      setTimeout(WindowFocusTimerCallback, 0, gURLBar);
     else
-      setTimeout("content.focus();", 0);
+      setTimeout(WindowFocusTimerCallback, 0, content);
   }
 }
 
 /* Show file picker dialog configured for opening a file, and return 
  * the selected nsIFileURL instance. */
 function selectFileToOpen(label, prefRoot)
 {
   var fileURL = null;
--- a/suite/common/directory/directory.js
+++ b/suite/common/directory/directory.js
@@ -124,20 +124,20 @@ SetBusyCursor(window, enable)
 }
 
 // We need this hack because we've completely circumvented the onload() logic.
 function Boot()
 {
   if (document.getElementById('tree'))
     Init();
   else
-    setTimeout("Boot()", 500);
+    setTimeout(Boot, 500);
 }
 
-setTimeout("Boot()", 0);
+setTimeout(Boot, 0);
 
 function Init()
 {
   debug("directory.js: Init()\n");
 
   var tree = document.getElementById('tree');
 
   // Initialize the tree's base URL to whatever the HTTPIndex is rooted at
--- a/suite/common/search/search-panel.js
+++ b/suite/common/search/search-panel.js
@@ -780,17 +780,17 @@ function checkSearchProgress()
         catch (ex) {
           activeSearchFlag = false;
         }
       }
     }
   }
 
   if (activeSearchFlag)
-    setTimeout("checkSearchProgress()", 1000);
+    setTimeout(checkSearchProgress, 1000);
   else
     doStop();
 
   return activeSearchFlag;
 }
 
 function sidebarOpenURL(listitem)
 {
@@ -884,17 +884,17 @@ function OpenSearch(aSearchStr, engineUR
       gURL = searchURL;
       loadURLInContent(encodeURI("chrome://communicator/content/search/internetresults.xul?" + searchURL));
     }
   }
   catch (ex) {
     debug("Exception: " + ex);
   }
 
-  setTimeout("checkSearchProgress()", 1000);
+  setTimeout(checkSearchProgress, 1000);
 }
 
 function saveSearch()
 {
   var ds = document.getElementById("resultList").database;
   if (!ds)
     return;
 
--- a/suite/common/sidebar/customize.js
+++ b/suite/common/sidebar/customize.js
@@ -136,18 +136,17 @@ function sidebar_customize_destruct()
 //////////////////////////////////////////////////////////////////
 // Panels' RDF Datasource Observer
 //////////////////////////////////////////////////////////////////
 var panels_observer = {
   onAssert : function(ds,src,prop,target) {
     //debug ("observer: assert");
     // "refresh" is asserted by select menu and by customize.js.
     if (prop == RDF.GetResource(NC + "link")) {
-      setTimeout("fixup_remote_container('"+src.Value+"')",100);
-      //fixup_remote_container(src.Value);
+      setTimeout(fixup_remote_container, 100, src.Value);
     }
   },
   onUnassert : function(ds,src,prop,target) {
     //debug ("observer: unassert");
   },
   onChange : function(ds,src,prop,old_target,new_target) {
     //debug ("observer: change");
   },
@@ -229,17 +228,17 @@ function ClickOnOtherPanels(event)
     if (treeitem.getAttribute('open') == 'true') {
       var link = treeitem.getAttribute('link');
       var loaded_link = treeitem.getAttribute('loaded_link');
       if (link != '' && !loaded_link) {
         debug("Has remote datasource: "+link);
         add_datasource_to_other_panels(link);
         treeitem.setAttribute('loaded_link', 'true');
       } else {
-        setTimeout('fixup_children("'+ treeitem.getAttribute('id') +'")', 100);
+        setTimeout(fixup_children, 100, treeitem.getAttribute('id'));
       }
     }
   }
 
   // Remove the selection in the "current" panels list
   var current_panels = document.getElementById('current-panels');
   current_panels.view.selection.clearSelection();
   enable_buttons_for_current_panels();
--- a/suite/common/sidebar/sidebarOverlay.js
+++ b/suite/common/sidebar/sidebarOverlay.js
@@ -441,17 +441,17 @@ function (force_reload)
           if (force_reload || (saved_src != src)) {
             debug("    set src="+saved_src);
             iframe.setAttribute('src', saved_src);
 
             if (gTimeoutID != null)
               clearTimeout(gTimeoutID);
 
             gCurFrame = iframe;
-            gTimeoutID = setTimeout (setBlank, 20000);
+            gTimeoutID = setTimeout(setBlank, 20000);
           }
         }
 
         load_state = content.getAttribute('loadstate');
         if (load_state == 'stopped') {
           load_state = 'never loaded';
           toggleLoadarea(content);
         }
@@ -830,17 +830,17 @@ function sidebar_open_default_panel(wait
     debug("Adding observer to database.");
     panels.database.AddObserver(panel_observer);
 
     // XXX This is a hack to force re-display
     panels.builder.rebuild();
   } else {
     if (tries < 3) {
       // No children yet, try again later
-      setTimeout('sidebar_open_default_panel(' + (wait*2) + ',' + (tries+1) + ')',wait);
+      setTimeout(sidebar_open_default_panel, wait, wait*2, ++tries);
       gBusyOpeningDefault = false;
       return;
     } else {
       sidebar_fixup_datasource();
     }
   }
 
   sidebarObj.panels.refresh();
@@ -1228,17 +1228,17 @@ function SidebarShowHide() {
     title_box.setAttribute('hidden', 'true');
     sidebar_panels_splitter_box.setAttribute('collapsed', 'true');
     sidebar_menu_item.setAttribute('checked', 'false');
     tabs_menu.setAttribute('hidden', 'true');
     SidebarSetButtonOpen(false);
   }
   // Immediately save persistent values
   document.persist('sidebar-title-box', 'hidden');
-  persist_width();
+  PersistWidth();
   window.content.focus();
 }
 
 function SidebarBuildPickerPopup() {
   var menu = document.getElementById('sidebar-panel-picker-popup');
   menu.database.AddDataSource(RDF.GetDataSource(sidebarObj.datasource_uri));
   menu.builder.rebuild();
 
@@ -1490,45 +1490,44 @@ function SidebarNavigate(aDirection)
 function SidebarCleanUpExpandCollapse() {
   // XXX Mini hack. Persist isn't working too well. Force the persist,
   // but wait until the change has commited.
   if (gMustInit) {
     gAboutToUncollapse = true;
     sidebar_overlay_init();
   }
 
-  setTimeout("document.persist('sidebar-box', 'collapsed');",100);
-  setTimeout("sidebarObj.panels.refresh();",100);
+  setTimeout(Persist, 100, "sidebar-box", "collapsed");
+  setTimeout(function() sidebarObj.panels.refresh(), 100);
 }
 
 function PersistHeight() {
   // XXX Mini hack. Persist isn't working too well. Force the persist,
   // but wait until the last drag has been committed.
   // May want to do something smarter here like only force it if the
   // height has really changed.
-  setTimeout("document.persist('sidebar-panels-splitter-box','height');",100);
+  setTimeout(Persist, 100, "sidebar-panels-splitter-box", "height");
 }
 
-function persist_width() {
+function PersistWidth() {
   // XXX Mini hack. Persist isn't working too well. Force the persist,
-  // but wait until the width change has commited.
-  setTimeout("document.persist('sidebar-box', 'width');",100);
+  // but wait until the width change has commited. Also see bug 16516.
+  setTimeout(Persist, 100, "sidebar-box", "width");
 
-  var is_collapsed = document.getElementById('sidebar-box').
-                       getAttribute('collapsed') == 'true';
+  var is_collapsed = document.getElementById("sidebar-box")
+                             .getAttribute("collapsed") == "true";
   SidebarSetButtonOpen(!is_collapsed);
 }
 
-function SidebarFinishClick() {
+function Persist(aAttribute, aValue) {
+  document.persist(aAttribute, aValue);
+}
 
-  // XXX Semi-hack for bug #16516.
-  // If we had the proper drag event listener, we would not need this
-  // timeout. The timeout makes sure the width is written to disk after
-  // the sidebar-box gets the newly dragged width.
-  setTimeout("persist_width()",100);
+function SidebarFinishClick() {
+  PersistWidth();
 
   var is_collapsed = document.getElementById('sidebar-box').getAttribute('collapsed') == 'true';
   debug("collapsed: " + is_collapsed);
   if (is_collapsed != sidebarObj.collapsed) {
     if (gMustInit)
       sidebar_overlay_init();
   }
 }
--- a/suite/profile/migration.js
+++ b/suite/profile/migration.js
@@ -413,17 +413,17 @@ var MigrationWizard = {
         label.setAttribute("class", "migration-finished");
       break;
     case "Migration:Ended":
       // We're done now.
       this._wiz.canAdvance = true;
       this._wiz.advance();
 
       if (this._autoMigrate)
-        setTimeout(function() {window.close();}, 5000);
+        setTimeout(close, 5000);
 
       break;
     }
   },
 
   onDonePageShow: function() {
     this._wiz.getButton("cancel").disabled = true;
     this._wiz.canRewind = false;