Last Comment Bug 595738 - Warning: assignment to undeclared variable index (in msgHdrViewOverlay.js)
: Warning: assignment to undeclared variable index (in msgHdrViewOverlay.js)
Status: RESOLVED FIXED
:
Product: SeaMonkey
Classification: Client Software
Component: MailNews: Message Display (show other bugs)
: Trunk
: All All
: -- normal (vote)
: seamonkey2.1b1
Assigned To: Philip Chee
:
Mentors:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-09-12 17:06 PDT by Stefan [:stefanh] (away until May 28)
Modified: 2010-10-05 10:16 PDT (History)
4 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---


Attachments
Patch v1.0 Sprinkle some let's. (14.13 KB, patch)
2010-10-02 10:45 PDT, Philip Chee
iann_bugzilla: review+
neil: superreview+
Details | Diff | Review

Description Stefan [:stefanh] (away until May 28) 2010-09-12 17:06:46 PDT
Seems that we use "for (index in something)" without actually declare 'index' in a few places.
Comment 1 Philip Chee 2010-10-02 10:45:47 PDT
Created attachment 480407 [details] [diff] [review]
Patch v1.0 Sprinkle some let's.

> Seems that we use "for (index in something)" without actually declare 'index'
> in a few places.

I've added let to the index of various for loops. I may have gone a bit overboard with some extra s/for/let/ inside if and for blocks.
Comment 2 Philip Chee 2010-10-02 10:47:39 PDT
Also I keep getting these errors. I don't know why because as far as I can tell msgWindow.msgHeaderSink is defined in InitWindow()

Warning: reference to undefined property msgWindow.msgHeaderSink
Source file: chrome://messenger/content/mailWindowOverlay.js
Line: 2861
 ----------
Warning: reference to undefined property msgWindow.msgHeaderSink
Source file: chrome://messenger-smime/content/msgHdrViewSMIMEOverlay.js
Line: 216
Comment 3 Ian Neal 2010-10-03 06:01:13 PDT
(In reply to comment #2)
> Also I keep getting these errors. I don't know why because as far as I can tell
> msgWindow.msgHeaderSink is defined in InitWindow()
> 
> Warning: reference to undefined property msgWindow.msgHeaderSink
> Source file: chrome://messenger/content/mailWindowOverlay.js
> Line: 2861
>  ----------
> Warning: reference to undefined property msgWindow.msgHeaderSink
> Source file: chrome://messenger-smime/content/msgHdrViewSMIMEOverlay.js
> Line: 216

Do they appear only on certain activities?
Comment 4 Philip Chee 2010-10-03 09:02:44 PDT
> Do they appear only on certain activities?
AFAIK, only when I open a new 3pane window or a standalone message window.
Comment 5 Ian Neal 2010-10-04 16:10:24 PDT
Comment on attachment 480407 [details] [diff] [review]
Patch v1.0 Sprinkle some let's.

r=me for the drive-by-letting
Comment 6 Philip Chee 2010-10-04 22:17:05 PDT
Comment on attachment 480407 [details] [diff] [review]
Patch v1.0 Sprinkle some let's.

># HG changeset patch
># User Philip Chee <philip.chee@gmail.com>
># Date 1286041038 -28800
># Node ID 97a770c6d8d80300257427c33728da89ba87555c
># Parent  51fbb624b47a91db0a9c1f4f99932561e8322b56
>Bug 595738 Warning: assignment to undeclared variable index (in msgHdrViewOverlay.js)
>
>diff --git a/suite/mailnews/msgHdrViewOverlay.js b/suite/mailnews/msgHdrViewOverlay.js
>--- a/suite/mailnews/msgHdrViewOverlay.js
>+++ b/suite/mailnews/msgHdrViewOverlay.js
>@@ -194,53 +194,52 @@ function createHeaderEntry(prefix, heade
>   else
>     this.outputFunction = updateHeaderValue;
> }
> 
> function initializeHeaderViewTables()
> {
>   // iterate over each header in our header list arrays and create header entries
>   // for each one. These header entries are then stored in the appropriate header table
>-  var index;
>-  for (index = 0; index < gCollapsedHeaderList.length; index++)
>+  for (let index = 0; index < gCollapsedHeaderList.length; index++)
>   {
>     gCollapsedHeaderView[gCollapsedHeaderList[index].name] = 
>       new createHeaderEntry('collapsed', gCollapsedHeaderList[index]);
>   }
> 
>-  for (index = 0; index < gExpandedHeaderList.length; index++)
>+  for (let index = 0; index < gExpandedHeaderList.length; index++)
>   {
>     var headerName = gExpandedHeaderList[index].name;
>     gExpandedHeaderView[headerName] = new createHeaderEntry('expanded', gExpandedHeaderList[index]);
>   }
> 
>   var extraHeaders = gExtraExpandedHeaders.match(/[^ ]+/g);
>   if (extraHeaders) {
>-    for (index = 0; index < extraHeaders.length; index++)
>+    for (let index = 0; index < extraHeaders.length; index++)
>     {
>-      var extraHeader = extraHeaders[index];
>+      let extraHeader = extraHeaders[index];
>       gExpandedHeaderView[extraHeader.toLowerCase()] = new createNewHeaderView(extraHeader, extraHeader + ':');
>     }
>   }
> 
>   if (gShowOrganization)
>   {
>-    var organizationEntry = {name:"organization", outputFunction:updateHeaderValue};
>+    let organizationEntry = {name:"organization", outputFunction:updateHeaderValue};
>     gExpandedHeaderView[organizationEntry.name] = new createHeaderEntry('expanded', organizationEntry);
>   }
> 
>   if (gShowUserAgent)
>   {
>-    var userAgentEntry = {name:"user-agent", outputFunction:updateHeaderValue};
>+    let userAgentEntry = {name:"user-agent", outputFunction:updateHeaderValue};
>     gExpandedHeaderView[userAgentEntry.name] = new createHeaderEntry('expanded', userAgentEntry);
>   }
> 
>   if (gShowMessageId)
>   {
>-    var messageIdEntry = {name:"message-id", outputFunction:OutputMessageIds};
>+    let messageIdEntry = {name:"message-id", outputFunction:OutputMessageIds};
>     gExpandedHeaderView[messageIdEntry.name] = new createHeaderEntry('expanded', messageIdEntry);
>   }
> }
> 
> function OnLoadMsgHeaderPane()
> {
>   // HACK...force our XBL bindings file to be load before we try to create our first xbl widget....
>   // otherwise we have problems.
>@@ -499,17 +498,17 @@ var messageHeaderSink = {
>     onEndAllAttachments: function()
>     {
>       // AddSaveAllAttachmentsMenu();
>       if (gCollapsedHeaderViewMode)
>         displayAttachmentsForCollapsedView();
>       else
>         displayAttachmentsForExpandedView();
> 
>-      for (index in gMessageListeners) {
>+      for (let index in gMessageListeners) {
>         if ("onEndAttachments" in gMessageListeners[index])
>           gMessageListeners[index].onEndAttachments();
>       }
>     },
> 
>     onEndMsgDownload: function(url)
>     {
>       // if we don't have any attachments, turn off the attachments flag
>@@ -601,17 +600,17 @@ function SetTagHeader()
>     var labelKey = "$label" + label;
>     if (msgKeyArray.indexOf(labelKey) < 0)
>       msgKeyArray.unshift(labelKey);
>   }
> 
>   // Rebuild the keywords string with just the keys that are actual tags or
>   // legacy labels and not other keywords like Junk and NonJunk.
>   // Retain their order, though, with the label as oldest element.
>-  for (var i = msgKeyArray.length - 1; i >= 0; --i)
>+  for (let i = msgKeyArray.length - 1; i >= 0; --i)
>     if (!(msgKeyArray[i] in tagKeys))
>       msgKeyArray.splice(i, 1); // remove non-tag key
>   var msgKeys = msgKeyArray.join(" ");
> 
>   if (msgKeys)
>     currentHeaderData.tags = {headerName: "tags", headerValue: msgKeys};
>   else // no more tags, so clear out the header field
>     delete currentHeaderData.tags;
>@@ -663,45 +662,44 @@ function OnTagsChange()
>     }
>   }
> }
> 
> // flush out any local state being held by a header entry for a given
> // table
> function ClearHeaderView(headerTable)
> {
>-  for (index in headerTable)
>+  for (let index in headerTable)
>   {
>-     var headerEntry = headerTable[index];
>+     let headerEntry = headerTable[index];
>      if (headerEntry.useToggle)
>      {
>        headerEntry.enclosingBox.clearHeaderValues();
>      }
> 
>      headerEntry.valid = false;
>   }
> }
> 
> // make sure that any valid header entry in the table is collapsed
> function hideHeaderView(headerTable)
> {
>-  for (index in headerTable)
>+  for (let index in headerTable)
>   {
>     headerTable[index].enclosingBox.collapsed = true;
>   }
> }
> 
> // make sure that any valid header entry in the table specified is
> // visible
> function showHeaderView(headerTable)
> {
>-  var headerEntry;
>-  for (index in headerTable)
>+  for (let index in headerTable)
>   {
>-    headerEntry = headerTable[index];
>+    let headerEntry = headerTable[index];
>     if (headerEntry.valid)
>     {
>       headerEntry.enclosingBox.collapsed = false;
>     }
>     else // if the entry is invalid, always make sure it's collapsed
>       headerEntry.enclosingBox.collapsed = true;
>   }
> }
>@@ -795,45 +793,44 @@ function createNewHeaderView(headerName,
> 
> /**
>  * Removes all non-predefined header nodes from the view.
>  *
>  * @param aHeaderTable Table of header entries.
>  */
> function RemoveNewHeaderViews(aHeaderTable)
> {
>-  for (var index in aHeaderTable)
>+  for (let index in aHeaderTable)
>   {
>-    var headerEntry = aHeaderTable[index];
>+    let headerEntry = aHeaderTable[index];
>     if (headerEntry.isNewHeader)
>       headerEntry.enclosingBox.parentNode
>                  .removeChild(headerEntry.enclosingBox);
>   }
> }
> 
> // UpdateMessageHeaders: Iterate through all the current header data we received from mime for this message
> // for each header entry table, see if we have a corresponding entry for that header. i.e. does the particular
> // view care about this header value. if it does then call updateHeaderEntry
> function UpdateMessageHeaders()
> {
>   // iterate over each header we received and see if we have a matching entry in each
>   // header view table...
> 
>-  var headerName;
>-  for (headerName in currentHeaderData)
>+  for (let headerName in currentHeaderData)
>   {
>-    var headerField = currentHeaderData[headerName];
>-    var headerEntry = null;
>+    let headerField = currentHeaderData[headerName];
>+    let headerEntry = null;
> 
>     if (headerName == "subject")
>     {
>       try {
>         if (gDBView.keyForFirstSelectedMessage == nsMsgKey_None)
>         {
>-          var folder = null;
>+          let folder = null;
>           if (gCurrentFolderUri)
>             folder = GetMsgFolderFromUri(gCurrentFolderUri);
>           setTitleFromFolder(folder, headerField.headerValue);
>         }
>       } catch (ex) {}
>     }
>     
>     if (gCollapsedHeaderViewMode && !gBuiltCollapsedView)
>@@ -847,17 +844,17 @@ function UpdateMessageHeaders()
>         headerEntry = gExpandedHeaderView[headerName];
> 
>       if (!headerEntry && gViewAllHeaders)
>       {
>         // for view all headers, if we don't have a header field for this value....cheat and create one....then
>         // fill in a headerEntry
>         if (headerName == "message-id" || headerName == "in-reply-to")
>         {
>-          var messageIdEntry = {name:headerName, outputFunction:OutputMessageIds};
>+          let messageIdEntry = {name:headerName, outputFunction:OutputMessageIds};
>           gExpandedHeaderView[headerName] = new createHeaderEntry('expanded', messageIdEntry);
>         }
>         else
>         {
>           gExpandedHeaderView[headerName] = new createNewHeaderView(headerName,
>                                                                     currentHeaderData[headerName].headerName + ':');
>         }
> 
>@@ -948,17 +945,17 @@ function OutputNewsgroups(headerEntry, h
> // take string of message-ids separated by whitespace, split it
> // into message-ids and send them together with the index number
> // to the corresponding mail-messageids-headerfield element
> function OutputMessageIds(headerEntry, headerValue)
> {
>   var messageIdArray = headerValue.split(/\s+/);
> 
>   headerEntry.enclosingBox.clearHeaderValues();
>-  for (var i = 0; i < messageIdArray.length; i++)
>+  for (let i = 0; i < messageIdArray.length; i++)
>     headerEntry.enclosingBox.addMessageIdView(messageIdArray[i]);
> 
>   headerEntry.enclosingBox.fillMessageIdNodes();
> }
> 
> // OutputEmailAddresses --> knows how to take a comma separated list of email addresses,
> // extracts them one by one, linkifying each email address into a mailto url.
> // Then we add the link-ified email address to the parentDiv passed in.
>@@ -1250,30 +1247,30 @@ function onShowAttachmentContextMenu()
> 
>   var canDetach = CanDetachAttachments();
>   var deletedAmongSelected = false;
>   var detachedAmongSelected = false;
>   var anyDeleted = false; // at least one deleted attachment in the list
>   var anyDetached = false; // at least one detached attachment in the list
> 
>   // Check if one or more of the selected attachments are deleted.
>-  for (var i = 0; i < selectedAttachments.length && !deletedAmongSelected; i++)
>+  for (let i = 0; i < selectedAttachments.length && !deletedAmongSelected; i++)
>     deletedAmongSelected =
>       (selectedAttachments[i].attachment.contentType == 'text/x-moz-deleted');
> 
>   // Check if one or more of the selected attachments are detached.
>-  for (var i = 0; i < selectedAttachments.length && !detachedAmongSelected; i++)
>+  for (let i = 0; i < selectedAttachments.length && !detachedAmongSelected; i++)
>     detachedAmongSelected = selectedAttachments[i].attachment.isExternalAttachment;
> 
>   // Check if any attachments are deleted.
>-  for (var i = 0; i < currentAttachments.length && !anyDeleted; i++)
>+  for (let i = 0; i < currentAttachments.length && !anyDeleted; i++)
>     anyDeleted = (currentAttachments[i].contentType == 'text/x-moz-deleted');
> 
>   // Check if any attachments are detached.
>-  for (var i = 0; i < currentAttachments.length && !anyDetached; i++)
>+  for (let i = 0; i < currentAttachments.length && !anyDetached; i++)
>     anyDetached = currentAttachments[i].isExternalAttachment;
> 
>   if (!deletedAmongSelected && selectedAttachments.length == 1)
>   {
>     openMenu.removeAttribute('disabled');
>     viewMenu.removeAttribute('disabled');
>   }
>   else
>@@ -1340,25 +1337,25 @@ function createAttachmentDisplayName(aAt
>   return aAttachment.displayName.trimRight();
> }
> 
> function displayAttachmentsForExpandedView()
> {
>   var numAttachments = currentAttachments.length;
>   if (numAttachments > 0 && !gBuildAttachmentsForCurrentMsg)
>   {
>-    var attachmentList = document.getElementById('attachmentList');
>+    let attachmentList = document.getElementById('attachmentList');
> 
>-    for (index in currentAttachments)
>+    for (let index in currentAttachments)
>     {
>-      var attachment = currentAttachments[index];
>+      let attachment = currentAttachments[index];
> 
>       // create a listitem for the attachment listbox
>-      var displayName = createAttachmentDisplayName(attachment);
>-      var item = attachmentList.appendItem(displayName, "");
>+      let displayName = createAttachmentDisplayName(attachment);
>+      let item = attachmentList.appendItem(displayName, "");
>       item.setAttribute("crop", "center");
>       item.setAttribute("class", "listitem-iconic attachment-item"); 
>       item.setAttribute("tooltiptext", attachment.displayName);
>       item.attachment = attachment;
>       item.setAttribute("attachmentUrl", attachment.url);
>       item.setAttribute("attachmentContentType", attachment.contentType);
>       item.setAttribute("attachmentUri", attachment.uri);
>       if (attachment.contentType == "text/x-moz-deleted")
>@@ -1400,17 +1397,17 @@ function FillAttachmentListPopup(popup)
>   var attachmentIndex = 0;
> 
>   // otherwise we need to build the attachment view...
>   // First clear out the old view...
>   ClearAttachmentMenu(popup);
> 
>   var canDetachOrDeleteAll = CanDetachAttachments();
> 
>-  for (index in currentAttachments)
>+  for (let index in currentAttachments)
>   {
>     ++attachmentIndex;
>     addAttachmentToPopup(popup, currentAttachments[index], attachmentIndex);
>     if (canDetachOrDeleteAll &&
>         (currentAttachments[index].isExternalAttachment ||
>         currentAttachments[index].contentType == 'text/x-moz-deleted'))
>       canDetachOrDeleteAll = false;
>   }
>@@ -1517,17 +1514,17 @@ function HandleMultipleAttachments(comma
>    var attachmentContentTypeArray = new Array();
>    var attachmentUrlArray = new Array();
>    var attachmentDisplayNameArray = new Array();
>    var attachmentMessageUriArray = new Array();
> 
>    // populate these arrays..
>    for (let index in selectedAttachments)
>    {
>-     var attachment = selectedAttachments[index].attachment;
>+     let attachment = selectedAttachments[index].attachment;
>      attachmentContentTypeArray[index] = attachment.contentType;
>      attachmentUrlArray[index] = attachment.url;
>      attachmentDisplayNameArray[index] = encodeURI(attachment.displayName);
>      attachmentMessageUriArray[index] = attachment.uri;
>    }
> 
>    // okay the list has been built... now call our action code...
>    switch (commandPrefix)
>@@ -1677,17 +1674,17 @@ nsFlavorDataProvider.prototype =
>       aTransferable.getTransferData("application/x-moz-file-promise-dir", dirPrimitive, dataSize);
>       var destDirectory = dirPrimitive.value.QueryInterface(Components.interfaces.nsILocalFile);
> 
>       // now save the attachment to the specified location
>       // XXX: we need more information than just the attachment url to save it, fortunately, we have an array
>       // of all the current attachments so we can cheat and scan through them
> 
>       var attachment = null;
>-      for (index in currentAttachments)
>+      for (let index in currentAttachments)
>       {
>         attachment = currentAttachments[index];
>         if (attachment.url == srcUrlPrimitive)
>           break;
>       }
> 
>       // call our code for saving attachments
>       if (attachment)
Comment 7 neil@parkwaycc.co.uk 2010-10-05 01:44:15 PDT
Comment on attachment 480407 [details] [diff] [review]
Patch v1.0 Sprinkle some let's.

Yes, you have gone overboard.

And try clearing your cache.
Comment 8 Philip Chee 2010-10-05 03:43:00 PDT
Pushed to comm-central
http://hg.mozilla.org/comm-central/rev/e194b244323c

Note You need to log in before you can comment on or make changes to this bug.