Last Comment Bug 787794 - fix some JS strict mode warnings that appear at Thunderbird startup
: fix some JS strict mode warnings that appear at Thunderbird startup
Status: RESOLVED FIXED
:
Product: Thunderbird
Classification: Client Software
Component: Mail Window Front End (show other bugs)
: Trunk
: All All
: -- normal (vote)
: Thunderbird 19.0
Assigned To: :aceman
:
:
Mentors:
Depends on:
Blocks: 303545
  Show dependency treegraph
 
Reported: 2012-09-02 06:42 PDT by :aceman
Modified: 2012-11-19 11:22 PST (History)
8 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---


Attachments
patch (18.57 KB, patch)
2012-09-02 08:11 PDT, :aceman
mconley: review+
Details | Diff | Splinter Review
patch v2 (12.20 KB, patch)
2012-09-10 13:01 PDT, :aceman
no flags Details | Diff | Splinter Review
patch v3 (12.21 KB, patch)
2012-09-12 11:02 PDT, :aceman
no flags Details | Diff | Splinter Review
patch v4 (12.62 KB, patch)
2012-10-30 14:59 PDT, :aceman
neil: review+
Details | Diff | Splinter Review

Description :aceman 2012-09-02 06:42:10 PDT
There are many warnings at TB startup (in debug mode) like this:

Warning: SyntaxError: in strict mode code, functions may be declared only at top level or immediately within another function
Source file: chrome://messenger/content/mail3PaneWindowCommands.js
Line: 511, Column: 17
Source code:
        function canCompact(folder) { 

or

Warning: ReferenceError: reference to undefined property node.id
Source file: chrome://messenger/content/folderWidgets.xml
Line: 23

I try to fix some of them, to ease spotting new warnings by developers when creating new code. I fix only those produced by comm-central code and only those that I understand how to fix :)
Comment 1 :aceman 2012-09-02 08:11:39 PDT
Created attachment 657677 [details] [diff] [review]
patch

This fixes the warnings I have seen.

I could not fix these as they are too involved:
Warning: ReferenceError: reference to undefined property aTabType.panelId
Source file: chrome://messenger/content/tabmail.xml
Line: 352

and 

Warning: Use of Mutation Events is deprecated. Use MutationObserver instead.
Source file: chrome://messenger/content/msgMail3PaneWindow.js
Line: 945

If anybody hints me how to rework the code there I can add it.

Also if anybody sees some other fixable warnings at startup, just post them here.
Comment 2 Philip Chee 2012-09-02 11:08:20 PDT
> Warning: Use of Mutation Events is deprecated. Use MutationObserver instead.
> Source file: chrome://messenger/content/msgMail3PaneWindow.js
> Line: 945
See Attachment 655455 [details] [diff] in SeaMonkey Bug 785745 (Stop using DOMAttrModified events) for an example
Comment 3 :aceman 2012-09-02 12:58:21 PDT
Thanks, but I still do not understand how that observing works, so I'll not do it in this patch.
Comment 4 Nomis101 2012-09-08 01:45:47 PDT
(In reply to :aceman from comment #1)
> Also if anybody sees some other fixable warnings at startup, just post them
> here.

I see this warning five times in my error console:

Timestamp: 08.09.12 10:42:42
Warning: XUL box for _moz_generated_content_before element contained an inline #text child, forcing all its children to be wrapped in a block.
Source File: chrome://global/content/bindings/toolbar.xml
Line: 276
Comment 5 Jim Porter (:squib) 2012-09-08 02:04:06 PDT
Comment on attachment 657677 [details] [diff] [review]
patch

Review of attachment 657677 [details] [diff] [review]:
-----------------------------------------------------------------

Just a quick drive-by because I can't sleep. :)

::: mail/base/content/folderPane.js
@@ -846,5 @@
>  
>        // Note that these children may have been open when we were last closed,
>        // and if they are, we also have to add those grandchildren to the map
>        let oldCount = this._rowMap.length;
> -      function recursivelyAddToMap(aChild, aNewIndex, tree) {

To minimize the size of the diff and to eliminate the chance that we don't mess up any variable closures here, I think it would be better to simply change this line to:

  let recursivelyAddToMap = function recursivelyAddToMap(aChild, aNewIndex, tree);

Do please keep the function name after the equals sign like so, since otherwise the function will show up as having no name during debugging.
Comment 6 Jim Porter (:squib) 2012-09-08 02:04:56 PDT
The above, of course, applies to other similar locations.
Comment 7 Philip Chee 2012-09-08 04:19:05 PDT
> I see this warning five times in my error console:
> 
> Timestamp: 08.09.12 10:42:42
> Warning: XUL box for _moz_generated_content_before element contained an inline #text child, forcing all its children to be wrapped in a block.
> Source File: chrome://global/content/bindings/toolbar.xml
> Line: 276

Possibly caused by some extensions with gnarly custom toolbar buttons. Do you see this in Thunderbird safe mode?
Comment 8 Nomis101 2012-09-08 05:27:38 PDT
(In reply to Philip Chee from comment #7)
> > I see this warning five times in my error console:
> > 
> > Timestamp: 08.09.12 10:42:42
> > Warning: XUL box for _moz_generated_content_before element contained an inline #text child, forcing all its children to be wrapped in a block.
> > Source File: chrome://global/content/bindings/toolbar.xml
> > Line: 276
> 
> Possibly caused by some extensions with gnarly custom toolbar buttons. Do
> you see this in Thunderbird safe mode?
I don't have any extensions installed. And yes, I also see this in safe mode. The first time I've seen this in the console was around the time TB on Mac switched to the monochrom toolbar buttons. I found some bugs which have seen this in Firefox as well (636367, 715293).
Comment 9 Mike Conley (:mconley) 2012-09-09 04:54:49 PDT
Comment on attachment 657677 [details] [diff] [review]
patch

Review of attachment 657677 [details] [diff] [review]:
-----------------------------------------------------------------

r=me with the changes below applied. Thanks!

::: mail/base/content/folderPane.js
@@ -846,5 @@
>  
>        // Note that these children may have been open when we were last closed,
>        // and if they are, we also have to add those grandchildren to the map
>        let oldCount = this._rowMap.length;
> -      function recursivelyAddToMap(aChild, aNewIndex, tree) {

Sure, that sounds fine to me.

::: mailnews/base/content/jsTreeView.js
@@ +124,5 @@
>     * Opens or closes a container with children.  The logic here is a bit hairy, so
>     * be very careful about changing anything.
>     */
>    toggleOpenState: function jstv_toggleOpenState(aIndex) {
> +    function recursivelyAddToMap(aChild, aNewIndex, tree) {

I think squib's comment before can apply here as well.
Comment 10 :aceman 2012-09-10 00:01:31 PDT
(In reply to Nomis101 from comment #4)
> I see this warning five times in my error console:
> 
> Timestamp: 08.09.12 10:42:42
> Warning: XUL box for _moz_generated_content_before element contained an
> inline #text child, forcing all its children to be wrapped in a block.
> Source File: chrome://global/content/bindings/toolbar.xml
> Line: 276

Thanks for coming in, but this warning seems emitted from Gecko core and I said I will not touch that in this bug.
Comment 11 :aceman 2012-09-10 13:01:15 PDT
Created attachment 659828 [details] [diff] [review]
patch v2

Thanks guys.
There are some /mailnews parts so I'll try Neil too.
I move the whole accountCompare function in mailnews/base/content/folderWidgets.xml, but I have already adapted patch for bug 749200 to that so please leave it so.
Comment 12 neil@parkwaycc.co.uk 2012-09-11 08:48:04 PDT
Comment on attachment 659828 [details] [diff] [review]
patch v2

I haven't looked too closely at any of the /mail/ files.

>         while (node) {
>-          if (/wrapper-.*/.test(node.id)) {
>+          if (("id" in node) && /wrapper-.*/.test(node.id)) {
I'd prefer to use while (node instanceof XULElement) as that's the interface that supplies the id property.

>+          function accountCompare(a, b) {
Weren't you changing this code? In which case, why move the old version?

>-      function recursivelyAddToMap(aChild, aNewIndex, tree) {
>+      let recursivelyAddToMap = function recursivelyAddToMap(aChild, aNewIndex, tree) {
I wonder whether this should be a single-invocation function expression i.e.

(function recursivelyAddToMap(aChild, aNewIndex, tree) {
  ...
})(this._rowMap[aIndex], aIndex, this);
Comment 13 :aceman 2012-09-11 08:54:45 PDT
(In reply to neil@parkwaycc.co.uk from comment #12)
> Comment on attachment 659828 [details] [diff] [review]
> patch v2
> 
> I haven't looked too closely at any of the /mail/ files.
That's fine, I wanted you to look at /mailnews per comment 11.

> 
> >         while (node) {
> >-          if (/wrapper-.*/.test(node.id)) {
> >+          if (("id" in node) && /wrapper-.*/.test(node.id)) {
> I'd prefer to use while (node instanceof XULElement) as that's the interface
> that supplies the id property.
OK, I will try that.

> 
> >+          function accountCompare(a, b) {
> Weren't you changing this code? In which case, why move the old version?

I tried to change it but that bug has stalled so far. So this is working on the old code as it is so far.

> >-      function recursivelyAddToMap(aChild, aNewIndex, tree) {
> >+      let recursivelyAddToMap = function recursivelyAddToMap(aChild, aNewIndex, tree) {
> I wonder whether this should be a single-invocation function expression i.e.
> 
> (function recursivelyAddToMap(aChild, aNewIndex, tree) {
>   ...
> })(this._rowMap[aIndex], aIndex, this);

I do not know such JS plays so can't answer that:)
Comment 14 :aceman 2012-09-12 11:02:19 PDT
Created attachment 660518 [details] [diff] [review]
patch v3
Comment 15 neil@parkwaycc.co.uk 2012-09-12 14:19:16 PDT
(In reply to aceman from comment #13)
> (In reply to comment #12)
> > (From update of attachment 659828 [details] [diff] [review])
> > >+          function accountCompare(a, b) {
> > Weren't you changing this code? In which case, why move the old version?
> I tried to change it but that bug has stalled so far. So this is working on
> the old code as it is so far.
Sure, but won't bitrotting yourself slow that bug down even further?

> > >-      function recursivelyAddToMap(aChild, aNewIndex, tree) {
> > >+      let recursivelyAddToMap = function recursivelyAddToMap(aChild, aNewIndex, tree) {
> > I wonder whether this should be a single-invocation function expression i.e.
> > 
> > (function recursivelyAddToMap(aChild, aNewIndex, tree) {
> >   ...
> > })(this._rowMap[aIndex], aIndex, this);
> I do not know such JS plays so can't answer that:)
I was hoping squib or maybe mconley might comment...
Comment 16 :aceman 2012-09-13 00:02:08 PDT
(In reply to neil@parkwaycc.co.uk from comment #15)
> (In reply to aceman from comment #13)
> > (In reply to comment #12)
> > > (From update of attachment 659828 [details] [diff] [review])
> > > >+          function accountCompare(a, b) {
> > > Weren't you changing this code? In which case, why move the old version?
> > I tried to change it but that bug has stalled so far. So this is working on
> > the old code as it is so far.
> Sure, but won't bitrotting yourself slow that bug down even further?
I have said in comment 11 that I have already adapted (not yet attached) the patch in bug 749200 to the changes in this patch. The whole function is removed there so it's position is not very relevant. What is slowing me down is waiting on standard8's review :)

> > > >-      function recursivelyAddToMap(aChild, aNewIndex, tree) {
> > > >+      let recursivelyAddToMap = function recursivelyAddToMap(aChild, aNewIndex, tree) {
> > > I wonder whether this should be a single-invocation function expression i.e.
> > > 
> > > (function recursivelyAddToMap(aChild, aNewIndex, tree) {
> > >   ...
> > > })(this._rowMap[aIndex], aIndex, this);
> > I do not know such JS plays so can't answer that:)
> I was hoping squib or maybe mconley might comment...
So let's ask them.
Comment 17 Mike Conley (:mconley) 2012-09-13 07:00:05 PDT
(In reply to :aceman from comment #16)
> (In reply to neil@parkwaycc.co.uk from comment #15)
> > (In reply to aceman from comment #13)
> > > (In reply to comment #12)
> > > > (From update of attachment 659828 [details] [diff] [review])
> > > > >+          function accountCompare(a, b) {
> > > > Weren't you changing this code? In which case, why move the old version?
> > > I tried to change it but that bug has stalled so far. So this is working on
> > > the old code as it is so far.
> > Sure, but won't bitrotting yourself slow that bug down even further?
> I have said in comment 11 that I have already adapted (not yet attached) the
> patch in bug 749200 to the changes in this patch. The whole function is
> removed there so it's position is not very relevant. What is slowing me down
> is waiting on standard8's review :)
> 
> > > > >-      function recursivelyAddToMap(aChild, aNewIndex, tree) {
> > > > >+      let recursivelyAddToMap = function recursivelyAddToMap(aChild, aNewIndex, tree) {
> > > > I wonder whether this should be a single-invocation function expression i.e.
> > > > 
> > > > (function recursivelyAddToMap(aChild, aNewIndex, tree) {
> > > >   ...
> > > > })(this._rowMap[aIndex], aIndex, this);
> > > I do not know such JS plays so can't answer that:)
> > I was hoping squib or maybe mconley might comment...
> So let's ask them.

It's neat, but I don't think it adds much. In fact, I think it detracts a little from readability. So, in my opinion, the original correction is acceptable.
Comment 18 :aceman 2012-09-13 07:07:27 PDT
I agree with mconley. If I stumbled upon code like that I would not know what it actually does and would skip it in sweeping bugs like these even if it contained something to fix.
Comment 19 :aceman 2012-10-19 01:21:06 PDT
Neil?
Comment 20 neil@parkwaycc.co.uk 2012-10-30 09:00:11 PDT
Comment on attachment 660518 [details] [diff] [review]
patch v3

>-      function recursivelyAddToMap(aChild, aNewIndex, tree) {
So, I stumbled across bug 682096. That bug switched from using a scoped variable (let tree = this;) to using an additional parameter. At this point, the function doesn't use its scope, so it could be made global.

Alternatively, there is another way to pass "this" to the function, and that is to put it on the prototype, where you can call it using this._recursivelyAddToMap(child, index);

But I quite understand you not wanting to use a function expression.
Comment 21 neil@parkwaycc.co.uk 2012-10-30 09:02:20 PDT
Comment on attachment 660518 [details] [diff] [review]
patch v3

>-      function checkUnsent() {
>+      let checkUnsent = function checkUnsent() {
>         if (MailOfflineMgr.shouldSendUnsentMessages())
>           SendUnsentMessages();
>       }
>       setTimeout(checkUnsent, 0);
On the other hand, this function is small enough that I would still suggest using a function expression, although obviously I'm not a peer of this code so you are quite within your rights to completely ignore me.
setTimeout(function checkUnsent() {
  if (MailOfflineMgr.shouldSendUnsentMessages())
    SendUnsentMessages();
}, 0);
Comment 22 :aceman 2012-10-30 09:07:26 PDT
I think that is OK, it is understandable.
Comment 23 :aceman 2012-10-30 14:59:40 PDT
Created attachment 676794 [details] [diff] [review]
patch v4

Do you mean it like this?
Comment 24 neil@parkwaycc.co.uk 2012-11-18 14:19:10 PST
Comment on attachment 676794 [details] [diff] [review]
patch v4

Thanks, this looks good. Sorry for the delayed review though.
Comment 25 Mike Conley (:mconley) 2012-11-19 11:22:04 PST
https://hg.mozilla.org/comm-central/rev/7b25c50ce213

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